GridOS 1 quest 1, gapples2

No. 2 in the quest 1, part 1, rules competition was gapples2. I’d just like to gush over the code.

There are 5 heads in use.

  1. If the 1st character is an A, the 1st head (yellow) will read the rest of the line. Similar for B / 2nd head (red) and C / 3rd head (green).
  2. For the rest of the program, there are different rules depending on which character was the 1st one. Essentially, if the 1st character was an A, only the rules connected with that situation are used. Instead of 1 big general program, there are 3 small programs, and only 1 of them will be run in any given situation. This cuts down on the number of rules used in each of the cases.
  3. Similarly:
    • If the 1st head is reading, the 2nd and 3rd head will write extra P’s.
    • If the 2nd head is reading, the 3rd and 4th head will write extra P’s.
    • If the 3rd head is reading, the 1st and 2nd head will write extra P’s.
  4. If we’re in a situation, where the 1st character was a C:
    • The writing of the extra 2 P’s for the 1st C will be delayed until the program ends. Elegant, as “program ended” = “there’s empty space to write extra P’s”.
    • When a C is read, the situation is partially dealt with and then the C is replaced with a B to deal with the rest. Again, I think this is elegant, as the B related rule was probably already run.
  5. The program only uses 2 states.
  6. I’m not quite sure what the 5th head is doing, but maybe it’s just there because it will be needed in part 2.

Code . (Find gapples2 in the 2nd position and click the scroll.)

Skriv en kommentar