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 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: compute 3X+1, print, then divide # If F=0 (I even): X≡1(mod 4), so divide by 4; skip 2 iterations # If F=1 (I odd): X≡3(mod 4), so divide by 2; skip 1 iteration REPEAT S TIMES ( # Compute and print 3X+1 = 6I+4 CLEAR X REPEAT I TIMES ( INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X ) INCREASE X INCREASE X INCREASE X INCREASE X PRINT X # If F=0 (I even): X := X/4 CLEAR H INCREASE H REPEAT F TIMES ( CLEAR H ) REPEAT H TIMES ( # Divide X by 2 CLEAR J 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 J ) CLEAR U CLEAR T ) CLEAR X REPEAT J TIMES ( INCREASE X ) # Divide X by 2 again CLEAR J 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 J ) CLEAR U CLEAR T ) CLEAR X REPEAT J TIMES ( INCREASE X ) ) # If F=1 (I odd): X := X/2 REPEAT F TIMES ( CLEAR J 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 J ) CLEAR U CLEAR T ) CLEAR X REPEAT J TIMES ( 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 CLEAR D REPEAT R TIMES ( INCREASE D ) ) ) ) )