WORM Solution

COMMON FACTOR

WORM row 10

In-game screenshot of COMMON FACTOR
In-game view
FamilyWORM Graph0.928 Difficulty0.928 Ring05 IDw46

Prerequisites

Zig Zag

Unlocks

FOLDBACK

Reference rack program w46 solved
Active cores0, 1, 2, 3, 4, 6, 7 Program lines32 DetailWORM row 10

Walkthrough

COMMON FACTOR: OUT = gcd(A,B) by Euclid (mutual subtraction), shift-free.

c1 ECHOES its current b LEFT before touching it, so c0 always compares against

the live b (no one-round lag). c0 reads b, hands its current a back RIGHT, and

self-reduces a when a>b (else keeps a). c1, having sent the live b, subtracts

a: keeps b-a when b>a, restores b when b<a. The two cards therefore reduce the

SAME pair every round and reach a==b together: c0 reloads, c1 ships the gcd DOWN

its column (c5 -> c4 -> c8 -> output 0).

Rack Solution
# COMMON FACTOR: OUT = gcd(A,B) by Euclid (mutual subtraction), shift-free.
# c1 ECHOES its current b LEFT before touching it, so c0 always compares against
# the live b (no one-round lag). c0 reads b, hands its current a back RIGHT, and
# self-reduces a when a>b (else keeps a). c1, having sent the live b, subtracts
# a: keeps b-a when b>a, restores b when b<a. The two cards therefore reduce the
# SAME pair every round and reach a==b together: c0 reloads, c1 ships the gcd DOWN
# its column (c5 -> c4 -> c8 -> output 0).
@0
N: MOV ACC, UP
M: SAV
SUB RIGHT
XCH
MOV RIGHT, ACC
XCH
JG M
JZ N
XCH
JMP M
@1
N: MOV ACC, RIGHT
O: MOV LEFT, ACC
SAV
SUB LEFT
JG O
JZ Z
XCH
JMP O
Z: XCH
MOV DOWN, ACC
@4
MOV LEFT, UP
@3
MOV DOWN, RIGHT
@6
MOV RIGHT, UP
@2
MOV LEFT, UP
@7
MOV DOWN, LEFT