PRINT X #----------------------------------------------------------------------------- # Base 2 103 # X == 1 37 # Z = 180 18 # Base 10 274 # 3x + 1 389 # x /= 2 52 # Misc 23 # Total 933 #----------------------------------------------------------------------------- #----------------------------------------------------------------------------- # Convert X to base 2 # The value of X is preserved by using S instead #----------------------------------------------------------------------------- REPEAT X TIMES ( INCREASE S REPEAT A TIMES ( REPEAT B TIMES ( REPEAT C TIMES ( REPEAT D TIMES ( REPEAT E TIMES ( REPEAT F TIMES ( REPEAT G TIMES ( REPEAT H TIMES ( REPEAT I TIMES ( REPEAT J TIMES ( CLEAR I CLEAR J ) REPEAT I TIMES ( CLEAR I INCREASE J ) CLEAR H ) REPEAT H TIMES ( CLEAR H INCREASE I ) CLEAR G ) REPEAT G TIMES ( CLEAR G INCREASE H ) CLEAR F ) REPEAT F TIMES ( CLEAR F INCREASE G ) CLEAR E ) REPEAT E TIMES ( CLEAR E INCREASE F ) CLEAR D ) REPEAT D TIMES ( CLEAR D INCREASE E ) CLEAR C ) REPEAT C TIMES ( CLEAR C INCREASE D ) CLEAR B ) REPEAT B TIMES ( CLEAR B INCREASE C ) CLEAR A ) REPEAT A TIMES ( CLEAR A INCREASE B ) CLEAR S ) REPEAT S TIMES ( INCREASE A ) ) CLEAR S #----------------------------------------------------------------------------- # Check if X = 1 #----------------------------------------------------------------------------- INCREASE S REPEAT B TIMES ( CLEAR S ) REPEAT C TIMES ( CLEAR S ) REPEAT D TIMES ( CLEAR S ) REPEAT E TIMES ( CLEAR S ) REPEAT F TIMES ( CLEAR S ) REPEAT G TIMES ( CLEAR S ) REPEAT H TIMES ( CLEAR S ) REPEAT I TIMES ( CLEAR S ) REPEAT J TIMES ( CLEAR S ) INCREASE W REPEAT S TIMES ( CLEAR S CLEAR W ) #----------------------------------------------------------------------------- # Z = 180 #----------------------------------------------------------------------------- INCREASE Z INCREASE S INCREASE S REPEAT Z TIMES ( REPEAT S TIMES ( INCREASE Z ) ) REPEAT Z TIMES ( REPEAT S TIMES ( INCREASE Z ) ) INCREASE S REPEAT Z TIMES ( REPEAT S TIMES ( INCREASE Z ) ) INCREASE S REPEAT Z TIMES ( REPEAT S TIMES ( INCREASE Z ) ) CLEAR S REPEAT Z TIMES ( REPEAT W TIMES ( INCREASE Y REPEAT A TIMES ( CLEAR Y #----------------------------------------------------------------------------- # X = 3X + 1 #----------------------------------------------------------------------------- INCREASE T REPEAT A TIMES ( CLEAR A CLEAR T INCREASE S ) REPEAT B TIMES ( INCREASE V ) REPEAT T TIMES ( CLEAR T INCREASE A ) REPEAT S TIMES ( CLEAR S INCREASE T ) REPEAT B TIMES ( CLEAR B INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) REPEAT C TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T CLEAR U ) ) REPEAT V TIMES ( CLEAR V INCREASE B ) REPEAT S TIMES ( CLEAR S INCREASE V ) REPEAT C TIMES ( CLEAR C INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) REPEAT D TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V CLEAR U ) ) REPEAT T TIMES ( CLEAR T INCREASE C ) REPEAT S TIMES ( CLEAR S INCREASE T ) REPEAT D TIMES ( CLEAR D INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) REPEAT E TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) REPEAT V TIMES ( CLEAR V INCREASE D ) REPEAT S TIMES ( CLEAR S INCREASE V ) CLEAR U REPEAT E TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) REPEAT F TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) CLEAR E REPEAT T TIMES ( CLEAR T INCREASE E ) REPEAT S TIMES ( CLEAR S INCREASE T ) CLEAR U REPEAT F TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) REPEAT G TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) CLEAR F REPEAT V TIMES ( CLEAR V INCREASE F ) REPEAT S TIMES ( CLEAR S INCREASE V ) CLEAR U REPEAT G TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) REPEAT H TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) CLEAR G REPEAT T TIMES ( CLEAR T INCREASE G ) REPEAT S TIMES ( CLEAR S INCREASE T ) CLEAR U REPEAT H TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) REPEAT I TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) CLEAR H REPEAT V TIMES ( CLEAR V INCREASE H ) REPEAT S TIMES ( CLEAR S INCREASE V ) CLEAR U REPEAT I TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) REPEAT J TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) CLEAR I REPEAT T TIMES ( CLEAR T INCREASE I ) REPEAT S TIMES ( CLEAR S INCREASE T ) CLEAR U REPEAT J TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) REPEAT K TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) CLEAR J REPEAT V TIMES ( CLEAR V INCREASE J ) REPEAT S TIMES ( CLEAR S INCREASE V ) CLEAR U REPEAT K TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) REPEAT L TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) CLEAR K REPEAT T TIMES ( CLEAR T INCREASE K ) REPEAT S TIMES ( CLEAR S INCREASE T ) CLEAR U REPEAT L TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) REPEAT M TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) CLEAR L REPEAT V TIMES ( CLEAR V INCREASE L ) REPEAT S TIMES ( CLEAR S INCREASE V ) CLEAR U REPEAT M TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) REPEAT N TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) CLEAR M REPEAT T TIMES ( CLEAR T INCREASE M ) REPEAT S TIMES ( CLEAR S INCREASE T ) CLEAR U REPEAT N TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) REPEAT O TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) CLEAR N REPEAT V TIMES ( CLEAR V INCREASE N ) REPEAT S TIMES ( CLEAR S INCREASE V ) CLEAR U REPEAT O TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) REPEAT P TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V INCREASE S ) REPEAT U TIMES ( INCREASE V ) ) CLEAR O REPEAT T TIMES ( CLEAR T INCREASE O ) REPEAT S TIMES ( CLEAR S INCREASE T ) CLEAR U REPEAT P TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) REPEAT Q TIMES ( INCREASE U REPEAT T TIMES ( CLEAR U CLEAR T INCREASE S ) REPEAT U TIMES ( INCREASE T ) ) CLEAR P REPEAT V TIMES ( CLEAR V INCREASE P ) REPEAT S TIMES ( CLEAR S INCREASE V ) CLEAR U REPEAT Q TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V ) REPEAT U TIMES ( INCREASE V ) ) REPEAT R TIMES ( INCREASE U REPEAT V TIMES ( CLEAR U CLEAR V ) REPEAT U TIMES ( INCREASE V CLEAR U ) ) CLEAR Q REPEAT T TIMES ( CLEAR T INCREASE Q ) CLEAR R REPEAT V TIMES ( CLEAR V INCREASE R ) REPEAT X TIMES ( INCREASE X INCREASE X ) INCREASE X PRINT X ) REPEAT Y TIMES ( #----------------------------------------------------------------------------- # X /= 2, ensure X > 1, and find largest exponent - 6 #----------------------------------------------------------------------------- CLEAR A INCREASE U REPEAT B TIMES ( CLEAR B INCREASE A ) REPEAT C TIMES ( CLEAR C CLEAR U INCREASE B ) REPEAT D TIMES ( CLEAR D CLEAR U INCREASE C ) REPEAT E TIMES ( CLEAR E CLEAR U INCREASE D ) REPEAT F TIMES ( CLEAR F CLEAR U INCREASE E ) REPEAT G TIMES ( CLEAR G CLEAR U INCREASE F ) INCREASE T REPEAT H TIMES ( CLEAR H CLEAR U INCREASE G INCREASE S ) INCREASE T REPEAT I TIMES ( CLEAR I CLEAR U INCREASE H CLEAR S INCREASE S INCREASE S ) INCREASE T REPEAT J TIMES ( CLEAR J CLEAR U INCREASE I CLEAR S REPEAT T TIMES ( INCREASE S ) ) INCREASE T REPEAT K TIMES ( CLEAR K CLEAR U INCREASE J CLEAR S REPEAT T TIMES ( INCREASE S ) ) INCREASE T REPEAT L TIMES ( CLEAR L CLEAR U INCREASE K CLEAR S REPEAT T TIMES ( INCREASE S ) ) INCREASE T REPEAT M TIMES ( CLEAR M CLEAR U INCREASE L CLEAR S REPEAT T TIMES ( INCREASE S ) ) INCREASE T REPEAT N TIMES ( CLEAR N CLEAR U INCREASE M CLEAR S REPEAT T TIMES ( INCREASE S ) ) INCREASE T REPEAT O TIMES ( CLEAR O CLEAR U INCREASE N CLEAR S REPEAT T TIMES ( INCREASE S ) ) INCREASE T REPEAT P TIMES ( CLEAR P CLEAR U INCREASE O CLEAR S REPEAT T TIMES ( INCREASE S ) ) INCREASE T REPEAT Q TIMES ( CLEAR Q CLEAR U INCREASE P CLEAR S REPEAT T TIMES ( INCREASE S ) ) INCREASE T REPEAT R TIMES ( CLEAR R CLEAR U INCREASE Q CLEAR S REPEAT T TIMES ( INCREASE S ) ) REPEAT U TIMES ( CLEAR W CLEAR U ) CLEAR T #----------------------------------------------------------------------------- # Sum of first 6 bits #----------------------------------------------------------------------------- CLEAR X REPEAT A TIMES ( INCREASE X ) INCREASE T INCREASE T REPEAT B TIMES ( REPEAT T TIMES ( INCREASE X ) ) REPEAT T TIMES ( INCREASE T ) REPEAT C TIMES ( REPEAT T TIMES ( INCREASE X ) ) REPEAT T TIMES ( INCREASE T ) REPEAT D TIMES ( REPEAT T TIMES ( INCREASE X ) ) REPEAT T TIMES ( INCREASE T ) REPEAT E TIMES ( REPEAT T TIMES ( INCREASE X ) ) REPEAT T TIMES ( INCREASE T ) REPEAT F TIMES ( REPEAT T TIMES ( INCREASE X ) ) #----------------------------------------------------------------------------- # Sum of last 11 bits #----------------------------------------------------------------------------- # Check if S > 0 CLEAR U REPEAT S TIMES ( CLEAR U INCREASE U ) # If S > 0, double T and increase X bX T if G REPEAT U TIMES ( INCREASE Y REPEAT G TIMES ( REPEAT Y TIMES ( REPEAT T TIMES ( INCREASE X ) ) ) # V = S - 1 CLEAR U CLEAR V REPEAT S TIMES ( REPEAT U TIMES ( INCREASE V ) CLEAR U INCREASE U ) # Check if V > 0 CLEAR U REPEAT V TIMES ( CLEAR U INCREASE U ) # If V > 0, double T and increase X by T if H REPEAT U TIMES ( REPEAT Y TIMES ( INCREASE Y ) REPEAT H TIMES ( REPEAT Y TIMES ( REPEAT T TIMES ( INCREASE X ) ) ) # S = V - 1 CLEAR S CLEAR U REPEAT V TIMES ( REPEAT U TIMES ( INCREASE S ) CLEAR U INCREASE U ) # Check if S > 0 CLEAR U REPEAT S TIMES ( CLEAR U INCREASE U ) # If S > 0, double T and increase X by T if I REPEAT U TIMES ( REPEAT Y TIMES ( INCREASE Y ) REPEAT I TIMES ( REPEAT Y TIMES ( REPEAT T TIMES ( INCREASE X ) ) ) # V = S - 1 CLEAR U CLEAR V REPEAT S TIMES ( REPEAT U TIMES ( INCREASE V ) CLEAR U INCREASE U ) # Check if V > 0 CLEAR U REPEAT V TIMES ( CLEAR U INCREASE U ) # If V > 0, double T and increase X by T if J REPEAT U TIMES ( REPEAT Y TIMES ( INCREASE Y ) REPEAT J TIMES ( REPEAT Y TIMES ( REPEAT T TIMES ( INCREASE X ) ) ) # S = V - 1 CLEAR S CLEAR U REPEAT V TIMES ( REPEAT U TIMES ( INCREASE S ) CLEAR U INCREASE U ) # Check if S > 0 CLEAR U REPEAT S TIMES ( CLEAR U INCREASE U ) # If S > 0, double T and increase X by T if K REPEAT U TIMES ( REPEAT Y TIMES ( INCREASE Y ) REPEAT K TIMES ( REPEAT Y TIMES ( REPEAT T TIMES ( INCREASE X ) ) ) # V = S - 1 CLEAR U CLEAR V REPEAT S TIMES ( REPEAT U TIMES ( INCREASE V ) CLEAR U INCREASE U ) # Check if V > 0 CLEAR U REPEAT V TIMES ( CLEAR U INCREASE U ) # If V > 0, double T and increase X by T if L REPEAT U TIMES ( REPEAT T TIMES ( INCREASE T ) REPEAT L TIMES ( REPEAT Y TIMES ( REPEAT T TIMES ( INCREASE X ) ) ) # S = V - 1 CLEAR S CLEAR U REPEAT V TIMES ( REPEAT U TIMES ( INCREASE S ) CLEAR U INCREASE U ) # Check if S > 0 CLEAR U REPEAT S TIMES ( CLEAR U INCREASE U ) # If S > 0, double T and increase X by T if M REPEAT U TIMES ( REPEAT Y TIMES ( INCREASE Y ) REPEAT M TIMES ( REPEAT Y TIMES ( REPEAT T TIMES ( INCREASE X ) ) ) # V = S - 1 CLEAR U CLEAR V REPEAT S TIMES ( REPEAT U TIMES ( INCREASE V ) CLEAR U INCREASE U ) # Check if V > 0 CLEAR U REPEAT V TIMES ( CLEAR U INCREASE U ) # If V > 0, double T and increase X by T if N REPEAT U TIMES ( REPEAT T TIMES ( INCREASE T ) REPEAT N TIMES ( REPEAT Y TIMES ( REPEAT T TIMES ( INCREASE X ) ) ) # S = V - 1 CLEAR S CLEAR U REPEAT V TIMES ( REPEAT U TIMES ( INCREASE S ) CLEAR U INCREASE U ) # Check if S > 0 CLEAR U REPEAT S TIMES ( CLEAR U INCREASE U ) # If S > 0, double T and increase X by T if O REPEAT U TIMES ( REPEAT Y TIMES ( INCREASE Y ) REPEAT O TIMES ( REPEAT Y TIMES ( REPEAT T TIMES ( INCREASE X ) ) ) # V = S - 1 CLEAR U CLEAR V REPEAT S TIMES ( REPEAT U TIMES ( INCREASE V ) CLEAR U INCREASE U ) # Check if V > 0 CLEAR U REPEAT V TIMES ( CLEAR U INCREASE U ) # If V > 0, double T and increase X by T if P REPEAT U TIMES ( REPEAT T TIMES ( INCREASE T ) REPEAT P TIMES ( REPEAT Y TIMES ( REPEAT T TIMES ( INCREASE X ) ) ) # S = V - 1 CLEAR S CLEAR U REPEAT V TIMES ( REPEAT U TIMES ( INCREASE S ) CLEAR U INCREASE U ) # Check if S > 0 CLEAR U REPEAT S TIMES ( CLEAR U INCREASE U ) # If S > 0, double T and increase X by T if Q REPEAT U TIMES ( REPEAT Y TIMES ( INCREASE Y ) REPEAT Q TIMES ( REPEAT Y TIMES ( REPEAT T TIMES ( INCREASE X ) ) ) ) ) ) ) ) ) ) ) ) ) ) #----------------------------------------------------------------------------- # S can be non zero # T is a power of two # U and V are 0 or 1 #----------------------------------------------------------------------------- CLEAR S CLEAR T CLEAR U CLEAR V CLEAR Y PRINT X ) ) )