# CLEAR B # REPEAT A TIMES ( INCREASE B ) ##B := A # CLEAR B INCREASE B # REPEAT A TIMES ( CLEAR B ) ##B := ISZERO A # CLEAR B INCREASE B # REPEAT A TIMES ( CLEAR B ) # CLEAR A # REPEAT B TIMES ( INCREASE A ) ##A := NOT A # CLEAR C # REPEAT A TIMES ( REPEAT B TIMES ( INCREASE C ) ) ## C := A*B ## Also logical AND # CLEAR B # REPEAT A TIMES ( # CLEAR C INCREASE C # REPEAT B TIMES ( CLEAR C ) # CLEAR B # REPEAT C TIMES ( INCREASE B ) # ) ##B := MOD2 A # CLEAR B # CLEAR C # REPEAT A TIMES ( # CLEAR D INCREASE D # REPEAT C TIMES ( # CLEAR D # INCREASE B # ) # CLEAR C # REPEAT D TIMES ( INCREASE C ) # ) ## B := HALF A ## C := MOD2 A INCREASE A INCREASE A INCREASE A REPEAT A TIMES ( REPEAT A TIMES ( INCREASE A INCREASE A INCREASE A ) ) # A = 192. Maximum collatz sequence has length 179. REPEAT A TIMES ( # Basically a WHILE TRUE # Check to terminate CLEAR B CLEAR C REPEAT X TIMES ( CLEAR D INCREASE D REPEAT C TIMES ( CLEAR D INCREASE B ) CLEAR C REPEAT D TIMES ( INCREASE C ) ) CLEAR D INCREASE D REPEAT B TIMES ( CLEAR D ) CLEAR E INCREASE E REPEAT D TIMES ( CLEAR E ) # B := HALF X # C := MOD2 X # D := ISZERO HALF X # E := NOT ISZERO HALF X REPEAT E TIMES ( # If we do not terminate PRINT X REPEAT C TIMES ( # If X is odd, Multiply by 3 and add 1. CLEAR D INCREASE D INCREASE D REPEAT X TIMES ( REPEAT D TIMES ( INCREASE X ) ) INCREASE X ) CLEAR D INCREASE D REPEAT C TIMES ( CLEAR D ) # D = NOT C REPEAT D TIMES ( # Otherwise X is even. Divide by 2. CLEAR X REPEAT B TIMES ( INCREASE X ) ) ) ) PRINT X