# A Bool for if X is divisible by two # B Helper variable # C Bool for if X is not divisible by two # W While loop big number # X Current number (also input) # Y New number # Z The number 3 INCREASE Z INCREASE Z INCREASE Z # Create while loop's acting number. INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W INCREASE W PRINT X # While loop: REPEAT W TIMES ( CLEAR A CLEAR B CLEAR C CLEAR K CLEAR I CLEAR J CLEAR Y # If X == 1 INCREASE I REPEAT X TIMES ( REPEAT J TIMES ( CLEAR I ) INCREASE J ) INCREASE K REPEAT I TIMES ( CLEAR K ) # If X != 1 REPEAT K TIMES ( # If X % 2 == 0, answer is 1, otherwise 0 INCREASE A REPEAT X TIMES ( INCREASE B REPEAT A TIMES ( CLEAR B ) CLEAR A REPEAT B TIMES ( INCREASE A ) CLEAR B ) #PRINT A # If X is divisible by two: INCREASE C # Bool for if not divisible by two. REPEAT A TIMES ( CLEAR C # Clears that bool. # Halves by two (15 lines) REPEAT X TIMES ( INCREASE B REPEAT A TIMES ( CLEAR B ) CLEAR A REPEAT B TIMES ( INCREASE A ) CLEAR B REPEAT A TIMES ( INCREASE Y ) ) ) # If X is not divisible by two. REPEAT C TIMES ( # y = 3x+1 (6 lines) REPEAT X TIMES ( REPEAT Z TIMES ( INCREASE Y ) ) INCREASE Y ) PRINT Y # Print new value. # Set X to Y. O(n). CLEAR X REPEAT Y TIMES ( INCREASE X ) ) )