INCREASE F # F = 1 to print 1 once at the end INCREASE K INCREASE K INCREASE K # Iterations to fake recursion # 180 = two times 3 * 3 * 5 * 2 REPEAT K TIMES ( # 3 REPEAT K TIMES ( # 3 INCREASE I INCREASE I INCREASE I INCREASE I INCREASE I INCREASE I INCREASE I INCREASE I INCREASE I INCREASE I ) ) # I = 180 (179 is max length) # PRINT I 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 ( PRINT X # Print current X CLEAR A # Pre-clear A - new X CLEAR B INCREASE B # B = 1 CLEAR C # C = 0 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 D TIMES ( CLEAR F # Clear when we're done (X = 1) 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 A TIMES ( INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A ) INCREASE A INCREASE A INCREASE A INCREASE A ) ) # Now test A and put result back in X, execute only until we reach 1 REPEAT F TIMES ( PRINT A # Print current X CLEAR X # Pre-clear A - new X CLEAR B INCREASE B # B = 1 CLEAR C # C = 0 CLEAR D INCREASE D # D = 1 # Parse once, collect knowledge odd/even and calculate A / 2 REPEAT A TIMES ( REPEAT C TIMES ( CLEAR D # A (aka X) != 1 and we set D = 0 INCREASE T # Increasing T instead of B to skip next block INCREASE X # Pre-calculate X as A / 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 D TIMES ( CLEAR F # Clear when we're done (X = 1) CLEAR C # To skip next block ) # goal: X = X + X * 5 + 4 REPEAT C TIMES ( # knowledge: X = 0, A = X / 2 REPEAT X TIMES ( INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X ) INCREASE X INCREASE X INCREASE X INCREASE X ) ) )