Home‎ > ‎ProgComp‎ > ‎ProgComp 2012 Sample Tasks‎ > ‎

Task 4. The Clacks



Task 4. The Clacks

Available Marks: 14

Terry Pratchett's novel Going Postal features a sempahore-based communication system called "The Clacks". It consists of a series of towers each with eight shuttered lamps in a 2 by 4 array. Each lamp can be shuttered (light off) or unshuttered (light on), and the patterns of lights can carry information.

Pratchett didn't elaborate on the design of the coding system, but to avoid ambiguity on dark and stormy nights certain combinations are not used. For example, if the top row of lights was on and the rest were off, the receiver couldn't be sure which row was showing since they can't see the tower itself. The rules (so far as this task is concerned) are these:

  • Each of the four rows must have at least one light on.
  • Each of the two columns must have at least one light on.
  • The all-lights-on configuration is a special LOCKOUT code that causes communication to shut down (a similar idea was exploited in the novel by a group of hackers who called themselves The Smoking Gnu).

If you analyse the situation you will find that 78 valid codes (light combinations) are available to carry a data symbol each (34 less 2 prohibited by the second rule and one by the third). The codes are assigned consistently and progressively, that is, with the top row changing first and then the second row and so on, but you'll have to work out what the algorithm is from the example below. The encoded symbols are, in order, upper-case letters, lower-case letters, decimal digits, a space and these 15 punctuation characters

!"$%&'()*,-.:?@

A message sent by the Clacks system is given by a list of 8-character sequences, each representing a symbol encoded by the 4 rows of shutter pairs, from top to bottom. The symbol X indicates a shutter (light OFF) and a dot indicates a light that's ON. Each code is on a separate line, and the message is preceded by the number of symbols in the message (maximum 100).

For example, the following data represents the encoded message Clacks!, use it to deduce the coding scheme.

7
X..XX.X.
..X..X.X
X.X.X..X
..X.X..X
.XX..X.X
.XX....X
..X..X..

Write a program that decodes a message sent on the Clacks communication system. If your program encounters an invalid combination it should emit a # character and continue decoding, and if it sees the LOCKOUT code it must display the message so far, then display LOCKOUT and stop.

Test Data

You should test your program on the following three data sets. If your program is working the results will make sense.Resist the temptation to edit the output. Part marks are awarded for reasonable attempts, and fraud will result in disqualification.
Test 1
13
X..X..X.
...X.XX.
.XX...X.
...X..X.
.XX..X..
.X...XX.
X.X...X.
X....XX.
.X..X.X.
X..XX.X.
X....XX.
.X.X.XX.
.X...XX.
 Test 2
43
.X...XX.
X.X....X
X.X.X..X
..X....X
..X.X..X
.X..X..X
.X.XX..X
..X....X
..X....X
.X...X..
.XX....X
.XX..X..
X..X.X..
.X.XX.X.
....X..X
.XX....X
..X.X..X
...X...X
X....X.X
X.X....X
..X..X.X
X..XX..X
X..X.X..
.XX..X..
.XX....X
.X.XX..X
X.X....X
....X..X
.X.XX..X
.XX....X
.XX..X..
.....X..
.XX.X...
X.X..X..
....X...
X..XX...
X..X....
..X.X...
X.X.X...
X.X.X...
X...X...
X.X.....
.X.X....
 Test 3
78
.XX.X...
...X....
.XX..X..
.X.X.XX.
X....X.X
....X..X
.XX....X
..X....X
.XX..X..
.X.X...X
X....X.X
...X.X.X
.XX..X..
X..X.XX.
....X..X
.X...X.X
...X...X
....X..X
X...X..X
..X.....
.XX..X..
X.X.X.X.
..X.X...
...X....
.XX..X..
X.X...X.
.X.XX..X
X.X.X..X
..X.X..X
.X..X..X
.X.XX..X
X.X....X
.XX..X..
.X..X.X.
....X..X
..X..X.X
..X....X
..X.....
.XX..X..
X..XXX..
X..XX...
...X....
.XX..X..
..X...X.
X....X.X
..X..X.X
..X..X.X
....X..X
.X.X...X
.X.XX..X
X.X....X
.XX..X..
.X..X.X.
X.X....X
X....X.X
X.X.X..X
..X....X
..X.....
.XX..X..
.X.X.X.X
.X.XX...
........
.....X..
..X....X
.X..X..X
.X.XX..X
X.X....X
.X.XX..X
.XX..X..
....X..X
.XX....X
.XX..X..
...X.X.X
X....X.X
.XX..X..
.X.XX...
..X..X..
X.X.....














Comments