Syscall 2: Firmware, home

ShuffleChapter 12: Shared buses

S47HAILSTORM

The task

The hailstone counter, swapped about. Swaps stay inside a core.

A step halves an even number and takes an odd one to 3 times it plus 1.

X is from 1 to 28. P must receive the steps X takes to reach 1.

The board

The board of HAILSTORM2 cores: t and c. Inputs X; outputs P.tSC-2L 15 LINEScSC-2 15 LINESP0P1P2P3P0P1XP
The board as the puzzle screen lays it out. Cyan pins read, lemon pins write, violet pins go both ways. On a narrow screen, scroll the board sideways to see all of it.

Key idea

Par is 9 swaps. Core t needs 1 instruction swap and 1 operand swap; core c needs 3 instruction swaps and 4 operand swaps. 8 of them trade two tiles that hold each other's places; look for those first, since one swap mends both.

Hints

Each hint goes a step further than the one before. Open them one at a time.

Hint 1Show

t looks for 1 before each step, keeps the count in B, and sends each number to c.

Hint 2Show

c keeps the number in B, since MOD 2 leaves only 0 or 1 in A.

Hint 3Show

SUB 1 then JZ finds the 1, and ADD 1 puts the number back when it is not.

Solution

Reveal the Full SolutionThe complete program for HAILSTORM. Open it only when you want the answer.

The board as dealt

This is the arrangement the game deals. Framed tiles are the ones out of place.

tSC-2L low power

S: IN P0
L: SUB 1
JZ F
ADD 1
OUT P1
XCH A, B
ADD 1
MOV B, A
JMP P2
IN B
F: XCH A, L
OUT P3

cSC-2 standard

S: JMP S
MOV B, A
MOD 2
MUL P1
MOV A, B
JZ 3
OUT 1
OUT P1
IN P0
E: MOV B, 2
DIV A
ADD E

9 swaps back

Make these swaps in order. Lines are numbered from 1 in each core.

  1. In core t, swap the operand B on line 10 with L on line 11.
  2. In core t, swap the instruction JMP on line 9 with IN on line 10.
  3. In core c, swap the operand S on line 1 with P0 on line 9.
  4. In core c, swap the operand P1 on line 4 with E on line 12.
  5. In core c, swap the operand B on line 10 with A on line 11.
  6. In core c, swap the operand 2 on line 10 with B on line 11.
  7. In core c, swap the instruction JMP on line 1 with IN on line 9.
  8. In core c, swap the instruction MUL on line 4 with JZ on line 6.
  9. In core c, swap the instruction OUT on line 7 with ADD on line 12.

The finished program

Every tile back in place: the reference solution, which scores exactly par on every benchmark.

tSC-2L low power

S: IN P0
L: SUB 1
JZ F
ADD 1
OUT P1
XCH A, B
ADD 1
MOV B, A
IN P2
JMP L
F: XCH A, B
OUT P3

cSC-2 standard

S: IN P0
MOV B, A
MOD 2
JZ E
MOV A, B
MUL 3
ADD 1
OUT P1
JMP S
E: MOV A, B
DIV 2
OUT P1
CYCLES
3178
at par
ENERGY
10528
at par
NODES
2
at par
INSTRUCTIONS
24
at par
SWAPS
9
at par