D23KEYPAD
The task
Transmit each typed number as a 16-bit value, high byte first.
Clerks type wagon numbers on a keypad that sends each key as its character, '0' to '9', and $0D for Enter. The yard computer wants the numbers in binary.
For each line, transmit the number it spells as a 16-bit value: the high byte, then the low byte. Every line has 1 to 5 digits, leading zeros are allowed, and the value is never above 65535.
The board
Key idea
Registers hold 16 bits, so even 65535 fits, and so does every step on the way to it.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
Build the number as the digits arrive: multiply the value so far by 10, then add the new digit minus '0'.
Hint 2Show
Multiply by 10 with shifts: 10 times B is 8 times B plus 2 times B. Copy B, shift one copy left by 3 and the other by 1, and add them.
Hint 3Show
When $0D arrives: MOV A, B, SHR A, 8, OUT A, then OUT B for the low byte. Clear B for the next line.
Solution
Reveal the Full SolutionThe complete program for KEYPAD. 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.
START: MOV B, 0
NEXT: IN A
JEQ A, $0D, SEND
SUB A, '0'
MOV C, B
SHL B, 3
SHL C, 1
ADD B, C
ADD B, A
JMP NEXT
SEND: MOV A, B
SHR A, 8
OUT A
OUT B- TICKS
- 242
- at par
- LINES
- 14
- at par