Task 1. Rank Generator

Available Marks: 8

Given a list of scores, in order,
write a program to
generate a rank for each entry.
An entry's rank is just its position in the sequence, starting at 1.
If there are equal values, however,
each of the equal values shares the same rank.
This doesn't affect subsequent ranks.
For example, here is a list of scores (in descending order)
with the corresponding ranks written underneath:

134 109 109 104 94 94 94 67 42
1 2eq 2eq 4 5eq 5eq 5eq 8 9

The input format has one score per line.
There is no formal limit to the number of values.

A score is a non-negative integer or real number.
There will be at most 3 decimal places.

The list is terminated by a line containing -1.
Don't rank this value,
it's there just to make it easy for you to tell that the list is finished.

Valid numbers in the list are in descending order
(each smaller than or equal to the previous,
except for the first).

Equal values may have a different representation,
such as 12 and 12.00.

The program's output should be a copy of the input,
with each value followed by spaces and the rank.
Non-equal ranks are positive integers; equal ranks have the
common rank with eq appended.

You can reformat the value if you like, as long as the numeric value is apparent.

If a value is out of order (greater than the preceding valid value),
show its rank as "--" and then ignore this value completely
(that is, assume it didn't exist).

You may assume that all numbers are well-formed (legal integer or real format).

Test 2 (some out of order)

Marking Scheme

Marks may be deducted for errors in the program
that are not exposed by the above tests.

Task 2: Suburb Name Abbreviations

Available Marks: 10

To squeeze address information into the phone book Telstra abbreviates suburb names.
Vowels carry less information than consonants, especially in the middle of words,
so the (simplified) rules for reducing suburb names are

Remove any vowel that occurs in the middle of a word.

Remove an 'e' at the end of a word, provided it's not preceded by another vowel.

Remove spaces between words.

All other characters are retained unchanged.

A vowel is defined as one of the 5 letters aeiou.
Although 'y' is considered a vowel in certain contexts it is not so here.

Examples:

Suburb

Abbreviation

Banksia

Bnksia

Little Bay

LttlBy

Glenorie

Glnrie

Lane Cove

LnCv

Illawong

Illwng

Write a program to abbreviate suburb names this way.
Names are provided, one per line.
The output should be the original name, one or more spaces, and the abbreviation.

Test Data

Show the output of your program when it reads this list of Sydney suburbs
(25 lines, one per initial letter of the alphabet except for X):

Task 3: Run-Length Decoding

Available Marks: 12

One of the simplest data compression schemes is called
run-length encoding (RLE).
RLE replaces a sequence of adjacent equal values with one copy
of the value, and a count of the number of times it occurred.
This works well for data representing images with regions of uniform colour, for example.

For this exercise we have applied RLE to text input only, and your task is to
write the decoder to restore the original data.

An RLE-encoded sequence must be distinguishable from ordinary text.
To do so, a special character is reserved to indicate the start
of an RLE-encoded sequence. We will use the character '#'.
An occurrence of '#' in an encoded file will be legally one of
two forms:

#dc
##

where d is a digit character ('0' to '9'),
representing how many times the character is to be repeated,
and c is the repeated character,
which can be any printable character, including '#'.

The second kind, "##", represents a single literal '#' character,
as a shorter alternative to the encoding "#1#".

If a '#' is followed by other than a digit or another '#',
display a question mark '?'.

For example, the input text

ab#3Cde###1Fg#9hh

would be decoded as

abCCCde#Fghhhhhhhhhh

Write a program that reads RLE-encoded data from its input
and writes decoded data to its output.

Test Data

Show your program's output for the following three test files.
The last one is long and has lines of up to 55 characters:
make sure you transfer it completely to your program.
You'll know your program is working
if it displays one of the classic ASCII art pictures.

Task 4: World Cup Tipping Competition Calculator

Available Marks: 14

Even if you aren't a football fan you must know the World Cup is on.
This task requires you to write a program that assigns points in a tipping competition.

In the competition, each participant (we'll call them a "tipper")
predicts the final score for a particular match.
A prediction is represented by two non-negative integers:
how many goals the first identified team
will score, and how many goals the second team will score.
When the final score is known, points are awarded to each participant
depending on how accurate their prediction was.

The points system varies according to whether or not a draw is predicted
(equal number of goals for each side).

If a draw is predicted...

Final result

points awarded

Draw occurred

5

Score was exact

+1 (so total = 6)

Draw did not occur

1

Goal difference is 1 or –1

+1 (so total = 2)

The "goal difference" is the difference between the number of goals
scored by the first and second team.
It's 0 for a draw.

For example, if a tipper predicts 1-1,
the following points would be awarded:

Final score

points awarded

1-1

6

0-0

5

0-1

2

4-2

1

2-3

2

If a win is predicted for one team...

Final result

points awarded

Win

3

Predicted goal difference differs from the actual goal difference by 1 or less

+1 (so total = 4)

Predicted goal difference is correct

+1 (so total = 5)

Exact score

+1 (so total = 6)

Loss

0

Draw

0

Draw, but predicted goal difference = 1 or –1

+1 (so total = 1)

For example, if a tipper predicts 1-2
the following points would be awarded:

Final score

points awarded

1-2 (correct score)

6

0-1 (correct goal difference)

5

2-4 (goal diff incorrect by 1)

4

0-3 (right team won)

3

1-0 (wrong team won)

0

1-1 (draw, 1 pt for goal diff = 1)

1

Your Task

Write a program that awards point to each tipper.
The first line of input is number of tippers.
The second line of input is the final score.
The remaining input consists of the tipper's name (one word only)
followed by a space and their tip.
All scores and tips are two integers separated by a dash.

The output should be the name of each tipper followed by the number of points awarded
according to the scoring system described above.

Tests

Show the output of your program for each of the following three tests.

Test 1: Australia v Japan

4
3-1
Marcus 1-2
Steve 2-1
Mei-Cheng 3-1
Geoff 2-2

Test 2: Tunisia v Saudi Arabia

7
2-2
Janet 1-0
Jimmy 0-2
Tao 1-1
Alex 4-1
Rui 2-2
Isan 3-4
Keith 0-0

Test 3: Angola v Portugal

10
0-1
Me 0-0
You 0-1
Him 1-0
Her 1-1
Them 1-2
Those 2-1
It 9-9
Another 1-10
Others 3-1
TheRest 99-100

Task 5: Magic Squares

Available Marks: 15 to 25

A magic square of order n
is an array of the integers from 1 to n2
arranged in an n by n square.
Each number is used exactly once.
What makes the squares "magic" is that
the sum of each row, column and the two diagonals is the same.

Magic squares exist for all orders except 2.
For example, an order-3 magic square is shown below.
Its row, column and diagonal sum is 15.

8

1

6

3

5

7

4

9

2

Basic Task: 15 marks

Your task is to verify whether an array of n by n
integers is a magic square.
The input starts with the value of n on a line by itself,
then n lines each containing n positive integers
separated by spaces (there may be leading and/or trailing spaces too).

For example, the magic square above could be represented as

3
8 1 6
3 5 7
4 9 2

You should be able to handle any magic square up to order 9.

The program's output is one of the following statements:

Magic square

Not a magic square

Invalid data: missing or repeated number

Invalid data: inconsistent sums

Extension: additional 10 marks

Note:
this section is likely to be a tie-breaker for the top few teams.
It is not expected that many (or possibly any)
will produce a complete solution in the time available.

Just as Sudoko puzzles are solved by inferring the contents of empty cells based
on the rules of the game, magic squares with missing numbers
can be completed using the rules above.

Given an incomplete magic square, with * symbols
where the missing numbers are,
modify your program to generate the missing values.
Only one solution is required in the event that more than one exists.

The input format is the same as above
apart from the use of the missing number symbol.
If the input contains one or more missing numbers,
output the complete magic square.
Assume that if the input contains an incomplete magic square none of the error cases
will arise.

Test Data

Tests 1 to 3 are for the basic task;
tests 4 and 5 are for the extension.
Only paste these results if you have attempted the extension.

Judges will be looking very carefully at your program to confirm that it
can generate the indicated output.
If possible, the code will be compiled and executed.
If irregularities are detected, no score is awarded
for this task and the team may also be disqualified
from the competition.