# J = 4 INCREASE J INCREASE J INCREASE J INCREASE J # I = 174 (maximum needed is 178) REPEAT J TIMES ( INCREASE J REPEAT J TIMES ( REPEAT J TIMES ( INCREASE I ) ) ) # add the remaining 4 INCREASE I INCREASE I INCREASE I INCREASE I PRINT X REPEAT I TIMES ( # Set Q to 1 to enable calculating CLEAR Q INCREASE Q REPEAT P TIMES ( CLEAR Q ) # Stop calculating if Q = 0 REPEAT Q TIMES ( REPEAT B TIMES # If even print normal halved ( PRINT X ) REPEAT A TIMES # If odd, print 1.5x halved ( PRINT Z CLEAR X REPEAT Z TIMES ( INCREASE X ) ) # Clear variables for calculation CLEAR A CLEAR T CLEAR C CLEAR Z # Parity check loop determines if X is even or odd # After X iterations: # A = 1 if X is odd, 0 if even # T = A (Helper variable) # C = X // 2 # Z = X REPEAT X TIMES ( INCREASE T # Increase C if A = 1 and set T to 0 REPEAT A TIMES ( CLEAR T CLEAR A INCREASE C ) # Increase A if T = 1 REPEAT T TIMES ( INCREASE Z INCREASE A ) ) # Only check if X = 1 if X is odd CLEAR E REPEAT A TIMES ( INCREASE E REPEAT C TIMES ( CLEAR E ) # If X = 1, C = 0 so E = 1 | If X > 1, C > 0 so E = 0 REPEAT E TIMES ( INCREASE P ) # If X = 1, set P = 1 to stop future calculation ) # Decide whether to update X: Q = 1 unless X = 1 CLEAR Q INCREASE Q REPEAT E TIMES ( CLEAR Q ) # Decide whether to update X: Q = 1 unless X = 1 # if Q = 1 update X to next Collatz number REPEAT Q TIMES ( CLEAR B INCREASE B # odd X: 3 * X + 1 REPEAT A TIMES ( REPEAT X TIMES ( INCREASE Z INCREASE X INCREASE X ) INCREASE X PRINT X CLEAR B ) ) #___________________ REPEAT Q TIMES ( REPEAT B TIMES # If even print normal halved ( PRINT C ) REPEAT A TIMES # If odd, print 1.5x halved ( PRINT Z CLEAR C REPEAT Z TIMES ( INCREASE C ) ) # Clear variables for calculation CLEAR A CLEAR T CLEAR X CLEAR Z # Parity check loop determines if X is even or odd # After X iterations: # A = 1 if X is odd, 0 if even # T = A (Helper variable) # X = C // 2 # Z = C REPEAT C TIMES ( INCREASE T #INCREASE Z # Increase X if A = 1 and set T to 0 REPEAT A TIMES ( CLEAR T CLEAR A INCREASE X ) # Increase A if T = 1 REPEAT T TIMES ( INCREASE Z INCREASE A ) ) # Check if C = 1, E = 1 CLEAR E # Only check if C = 1 if C is odd REPEAT A TIMES ( INCREASE E REPEAT X TIMES ( CLEAR E ) # For C = 1, X = 0 so E = 1 | for C > 1, X > 0 so E = 0 REPEAT E TIMES ( INCREASE P ) # If C = 1, set P = 1 to stop future calculation ) # Decide whether to update X: Q = 1 unless C = 1 CLEAR Q INCREASE Q REPEAT E TIMES ( CLEAR Q ) # Decide whether to update X: Q = 1 unless C = 1 # if Q = 1 update C to next Collatz number REPEAT Q TIMES ( CLEAR B INCREASE B # odd C: 3 * C + 1 REPEAT A TIMES ( REPEAT C TIMES ( INCREASE Z INCREASE C INCREASE C ) INCREASE C PRINT C CLEAR B ) ) ) ) )