INCREASE F # F = 1 to print 1 once at the end
INCREASE L
INCREASE L
INCREASE K INCREASE K INCREASE K INCREASE K INCREASE K
INCREASE K INCREASE K INCREASE K INCREASE K INCREASE K
# Iterations to fake recursion
# max odd values = 66
# max length of even sequences = 10
# 66 = 2 * 3 * 11
REPEAT L TIMES ( # 2
REPEAT L TIMES ( # 2
REPEAT K TIMES ( # 10
INCREASE I
)
INCREASE I
INCREASE I
INCREASE I
)
INCREASE L
)
INCREASE I
# I = 180 (179 is max length)
# PRINT I
# PRINT K
REPEAT I TIMES (
# Repeat enough times for X to reach 1, but not too many
# Goal: Execute the following part only when X > 1
REPEAT F TIMES (
CLEAR B INCREASE B # B = 1
CLEAR C # C = 0
REPEAT K TIMES ( # 10 times max even sequence length
REPEAT B TIMES ( # keep going while the previous number was even)
PRINT X # Print current X
CLEAR A # Pre-clear A - new X
CLEAR D INCREASE D # D = 1
# Parse once, collect knowledge odd/even and calculate X / 2
REPEAT X TIMES (
REPEAT C TIMES (
CLEAR D # X != 1 and we set D = 0
INCREASE T # Increasing T instead of B to skip next block
INCREASE A # Pre-calculate A = X / 2
CLEAR C # Skip this block next turn
)
REPEAT B TIMES (
INCREASE C
CLEAR B # Skip this block next turn
)
REPEAT T TIMES (
INCREASE B # Now we increase B we postponed earlier
CLEAR T # Skip this block next turn
)
)
# Now: D = 1 if X = 1
# B = 1 if X is even, else B = 0
# C = 1 if X is odd, else C = 0
REPEAT B TIMES ( # this run was even too, new X is in A we us X as temp
PRINT A # Print current X
CLEAR X # Pre-clear A - new X
CLEAR D INCREASE D # D = 1
# Parse once, collect knowledge odd/even and calculate X / 2
REPEAT A TIMES (
REPEAT C TIMES (
CLEAR D # X != 1 and we set D = 0
INCREASE T # Increasing T instead of B to skip next block
INCREASE X # Pre-calculate A = X / 2
CLEAR C # Skip this block next turn
)
REPEAT B TIMES (
INCREASE C
CLEAR B # Skip this block next turn
)
REPEAT T TIMES (
INCREASE B # Now we increase B we postponed earlier
CLEAR T # Skip this block next turn
)
)
# Now: D = 1 if X = 1
# B = 1 if X is even, else B = 0
# C = 1 if X is odd, else C = 0
REPEAT C TIMES ( # result tested odd, need to bring X to A (X = X + X + 1)
REPEAT X TIMES (
INCREASE X
)
INCREASE X
)
)
)
)
REPEAT D TIMES (
CLEAR F # Clear when we're done (X = 1)
CLEAR B # And skip next block
CLEAR C # And skip next block
)
# goal: X = A * 6 + 4; when C = 1 (odd)
REPEAT C TIMES (
# knowledge: X = 0, A = X / 2
REPEAT X TIMES (
INCREASE X
INCREASE X
)
INCREASE X
)
)
)