# A = 128 CLEAR A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE A INCREASE C # init: I=floor(X/2), F=parity(I), D=parity(X) REPEAT X TIMES ( INCREASE T REPEAT R TIMES ( CLEAR T ) CLEAR R REPEAT T TIMES ( INCREASE R ) INCREASE U REPEAT R TIMES ( CLEAR U ) REPEAT U TIMES ( INCREASE I INCREASE W REPEAT F TIMES ( CLEAR W ) CLEAR F REPEAT W TIMES ( INCREASE F ) CLEAR W ) CLEAR U CLEAR T ) REPEAT R TIMES ( INCREASE D ) REPEAT A TIMES ( REPEAT C TIMES ( PRINT X # Check X==1: M = (I==0 AND D==1) CLEAR L INCREASE L REPEAT I TIMES ( CLEAR L ) CLEAR M REPEAT L TIMES ( REPEAT D TIMES ( INCREASE M ) ) # C := 1 - M (continue if X != 1) CLEAR C INCREASE C REPEAT M TIMES ( CLEAR C ) # S := D (save before processing) CLEAR S REPEAT D TIMES ( INCREASE S ) # Process only if C==1 (not terminated) REPEAT C TIMES ( # even: X := I; D := F; halve I CLEAR N INCREASE N REPEAT S TIMES ( CLEAR N ) REPEAT N TIMES ( CLEAR X REPEAT I TIMES ( INCREASE X ) CLEAR D REPEAT F TIMES ( INCREASE D ) CLEAR J CLEAR R CLEAR Y REPEAT I TIMES ( INCREASE T REPEAT R TIMES ( CLEAR T ) CLEAR R REPEAT T TIMES ( INCREASE R ) INCREASE U REPEAT R TIMES ( CLEAR U ) REPEAT U TIMES ( INCREASE J INCREASE W REPEAT Y TIMES ( CLEAR W ) CLEAR Y REPEAT W TIMES ( INCREASE Y ) CLEAR W ) CLEAR U CLEAR T ) CLEAR I REPEAT J TIMES ( INCREASE I ) CLEAR F REPEAT Y TIMES ( INCREASE F ) ) # odd: print 3X+1, then X := (3X+1)/2 (skips iteration) REPEAT S TIMES ( # Print 3X+1 = 6I+4 CLEAR K REPEAT I TIMES ( INCREASE K INCREASE K INCREASE K INCREASE K INCREASE K INCREASE K ) INCREASE K INCREASE K INCREASE K INCREASE K PRINT K # X := (3X+1)/2 = 3I+2 CLEAR X REPEAT I TIMES ( INCREASE X INCREASE X INCREASE X ) INCREASE X INCREASE X # Compute new I and F from X CLEAR I CLEAR F CLEAR R REPEAT X TIMES ( INCREASE T REPEAT R TIMES ( CLEAR T ) CLEAR R REPEAT T TIMES ( INCREASE R ) INCREASE U REPEAT R TIMES ( CLEAR U ) REPEAT U TIMES ( INCREASE I INCREASE W REPEAT F TIMES ( CLEAR W ) CLEAR F REPEAT W TIMES ( INCREASE F ) CLEAR W ) CLEAR U CLEAR T ) # D = parity of new X (R from the division loop above) CLEAR D REPEAT R TIMES ( INCREASE D ) ) ) ) )