Your program will get on standard input a sequence of lines each consisting of one or more numbers from 0 to 4 (0 = black, 1 = blue, 2 = red, 3 = yellow, 4 = green), each number separated by a space and within a line all numbers always presented in sorted order (with no duplicates); there is no particular ordering of lines themselves. For instance the first deck mentioned above might be presented as:
0 3
0 3
... twenty-three more times
1 3
1 3
... twenty-three more times
2 3
2 3
... twenty-three more times
3 4
3 4
... twenty-three more times
(pfc_tragic_input_1.txt contains a full input file with this example; pfc_tragic_input_2.txt contains an input file representing the other example from the problem description.)
Every input will contain at least 100 and no more than 400 cards.
(If you'd rather accept input as a file than as standard input, make your program accept a filename as its first command-line parameter and let me know about it. Also, if there are big objections to this input format I'll hold a vote and make an alternate format if there's enough interest.)
OUTPUT
Print out legal or illegal, followed by a newline. Please don't print out anything else; that will make it easier for me to write an auto-judge.
POSTING YOUR CODE
Probably the best way to post your code is to post a top-level comment announcing your code (don't describe it there, though!) and then a reply to it that contains the code itself, along with a description of the algorithm used and instructions for making the program run (remember to format your code for posting using tmoertel's code formatting program as described in How to post code to K5 -- the easy way!). Please do not post code, algorithm descriptions, or any direct hints at solving the problem as root-level comments here — it could spoil the fun for people who haven't had a chance to take a stab at the problem yet, and for this challenge in particular I expect that even little tiny hints could ruin the puzzle value of the problem entirely.
JUDGING CRITERIA
Correctness, efficiency and clarity will be the primary criteria by which I'll judge your programs. Secondarily I'll look at the generality of your solution (could it scale up to larger problems, or is it hardwired to just this one problem instance?). I care more about algorithmic efficiency than micro-efficiency, so don't feel like you've got to write in assembly or something to have a shot at winning.
AN ADDITIONAL NOTE
If it becomes necessary, I and the other entrants would appreciate you posting any interesting test cases you discover.
I'll accept entries until Wednesday, April 14, at midnight. I expect many people will have come up with clever solutions by then, but there's still
Now, good luck and get coding!
Update [2004-4-5 6:32:16 by gazbo]: Fixed link, changed deadline as per request
| < I'd work for Google on the moon... | BBC White season: 'Rivers of Blood' > |

Post to Twitter
