D40ALTERNATING BIT
The task
Answer every frame with its sequence bit; deliver each payload only once.
The paging transmitter sends a frame again when it misses the answer, so the same frame can arrive twice or more. A sequence byte, 0 or 1, flips with every new frame and stays the same on a repeat.
A frame is the sequence byte, a length byte, and the payload, which is 1 to 8 bytes long. Answer every frame, repeat or not, by transmitting $A0 plus its sequence byte.
Deliver a frame's payload to the host only when it is new: when its sequence byte differs from the frame delivered before it. The first frame always has sequence 0.
The board
Key idea
The sender only moves on when its answer comes back, so a lost answer always means a repeat, never a skipped frame.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
Keep the sequence you expect next in D, starting at 0. A frame with any other sequence is a repeat.
Hint 2Show
A repeat still has to be read to the end, or its payload would be taken for the next frame. Read it and drop it.
Hint 3Show
IN B, IN C, MOV A, B, OR A, $A0, OUT A. If B is not D, read C bytes and drop them. If it is, XOR D, 1, then read and deliver C bytes.
Solution
Reveal the Full SolutionThe complete program for ALTERNATING BIT. Open it only when you want the answer.
The reference program
The game's own solution to this ticket. It passes every test and scores exactly par on every benchmark.
TOP: IN B
IN C
MOV A, B
OR A, $A0
OUT A
JNE B, D, DROP
XOR D, 1
KEEP: IN A
HOUT A
DJN C, KEEP
JMP TOP
DROP: IN A
DJN C, DROP- TICKS
- 403
- at par
- LINES
- 13
- at par