Awaiting submission

George Boole liked to build pyramids. However, he would only build pyramids with cubes of size 1x1x1. Here are some example pyramids built by George:
Your task is to write a program that calculates the number of cubes that George would need to build a pyramid of height *n*. The input is the height *n* (1 <= n < 100) and the output is the number of cubes.

Awaiting submission

“You are missing a curly bracket,” said Ajahn Ant to the 1st year student on the Object Oriented Programming course… for the 1,000th time.
To make Ajahn Ant’s life easier, you must write a program that checks if a Java program has equal numbers of open and close curly brackets (ignore ordering). The input will be Java source code. The output will be

`Correct`

or `Too many {`

or `Too many }`

.
Awaiting submission

Ajahn Jair has started a business selling cat figures, that she prints on a 3D printer. The printer is very slow so it may be more time-efficient to first use the 3D printer to print a new printer. It takes 1 day to print 1 cat figure and it also takes 1 day to print a new printer. Each day you can choose whether to print a cat or print a new printer (which can be used the following day). You can have some printers printing cats and some printers printing printers.

If Ajahn Jair would like to print *n* cat figures then what is the minimum number of days that it will take.

Awaiting submission

Naresuan University Hospital has 3 helicopters for emergency rescue operations. In an emergency, the nearest helicopter must fly to the patient’s location.
In the above example, X is the patient and A,B,C are the 3 helicopters. By counting the number of squares, A is 7 squares from X, B is 4 squares, and C is 3 squares. Therefore, helicopter C is nearest to the patient. Note the 1 square is counted for every move to an adjacent square, and the helicopters cannot travel diagonally.

The hospital has asked you to write a program that will calculate which of the 3 helicopters is nearest to the emergency. The input to the program is a 9x9 map containing 3 helicopters (A,B,C) and a patient (X). The output should be the helicopter that is nearest (A, B or C). If there is more than one helicopter that is closest then output all of the nearest helicopters.

Awaiting submission

Ajahn Foo has collected a lot of programming books (especially about Python!). He needs your help to calculate which is the highest rated book in each category.

Write a program that prints out the name of the book with the highest rating in each category. The output should be ordered by category A-Z.

The input is a comma-separated list of the table above. First column is the book name, second column is the category, and the third column is the rating (to 1 d.p.). You can assume that no two books in the same category have the same rating.

Awaiting submission

A permutation of the numbers 1, ..., *N* is arrangement of these numbers. For example

2 4 5 1 7 6 3 8

is a permutation of 1,2, ..., 8.

Associated with each permutation of *N* is a special sequence of positive integers of length *N* called its “inversion table”. The *i*-th element of this sequence is the number of numbers that are strictly less than *i* and appear to the right of *i* in the permutation.

Inversion Table

0 1 0 2 2 1 2 0

The 2nd element of the inversion table is 1 because 1 is strictly less than 2 and it appears to the right of 2 in this permutation. Similarly, the 5th element is 2 since 1 and 3 are strictly less than 5 but appear to the right of 5 in this permutation and so on.

The permutation can be reconstructed from the inversion table. Hint: start from the last element of the inversion table (if *N* is 8, then the last element of the inversion table tells you how many numbers there are to the right of 8 which are less than 8).

Write a program that computes the permutation of a given inversion table (where *N* < 1000). The input is a sequence of integers (on one line, each separated by a space). Output the permutation (each integer separated by a space).

Awaiting submission

The Caesar cipher is one of the earliest known encryption techniques. The ciphertext is obtained by shifting each character in the plaintext by the same fixed number of positions down the alphabet. The shift value is known as the key.

Example with key 3 (letters shifted 3 positions)

A B C D E F G H I J K L M N O ... D E F G H I J K L M N O P Q R ...

Plaintext: HELLOJAMES Ciphertext: KHOORMDPHV

**Breaking the cipher**

If you know that a ciphertext is Caesar encrypted but you do not know the key, then you can perform a brute-force attack. This involves applying all 25 keys to the ciphertext and looking for a plaintext that is readable.

For example, if you are given the ciphertext `YMJWJNXRTSJDNSYMJPTYQNSHTIJ`

then the possible plaintext are:

Write a program that takes 1 line of input containing uppercase characters A-Z (the ciphertext). Perform a brute-force attack and output the plaintext of the most probable message.

You can assume that the plaintext is English and always contains the most common 3 letter prefix in English which is `THE`

. The text is always UPPERCASE and contains no spaces.

Awaiting submission

A group of CSIT students were getting bored of playing Tic Tac Toe (during a Swift class?) so they started experimenting with 4x4, 5x5, ... , *N*x*N* variations of the game. As the board gets larger, there are more combinations of winning moves. In *N*x*N* Tic Tac Toe, a winning move is the placement of an X or O that makes a line of length *N*.

Write a program that, given a board state, determines the winning move.

The 1st line of the input is the size of the grid (*N*). The 2nd line is either `X`

or `O`

which indicates whose turn it is. The remaining lines (2**N*-1) form a grid containing the current board state. Squares are separated horizontally by a bar `|`

and vertically by a dash `-`

. Empty squares are represented by a space. Filled squares contain either `O`

or `X`

(uppercase letters only).

Output the position *X,Y* of the winning move. The first square in the top left corner is position 1,1. If there is no winning move then output `NO WINNING MOVE`

. You can assume there is either ONE or NO winning moves (there will never be more than 1 winning move).