# Q = 128 # 548 successful iterations INCREASE Q INCREASE Q INCREASE Q INCREASE Q # 4^3 = 64 #CLEAR S # s <= (x > 0) assume empty #CLEAR L assume empty #CLEAR M assume empty INCREASE M REPEAT X TIMES ( REPEAT M TIMES ( REPEAT L TIMES ( CLEAR M INCREASE S ) INCREASE L ) ) PRINT X REPEAT Q TIMES ( REPEAT S TIMES ( # skips iterations a lot faster if there are a lot to skip REPEAT Q TIMES ( REPEAT S TIMES ( REPEAT Q TIMES ( # repeat 4 times 4 times 4 times: 64 times # if x > 1 REPEAT S TIMES ( # o: store x / 8 CLEAR O # ea: % 8 == 0 # eb: % 8 == 1 # ec: % 8 == 2 # ed: % 8 == 3 # fa: % 8 == 4 # fb: % 8 == 5 # fc: % 8 == 6 # fd: % 8 == 7 INCREASE A # e-f flip-flop INCREASE E REPEAT X TIMES ( REPEAT D TIMES ( CLEAR D INCREASE T REPEAT F TIMES ( CLEAR F INCREASE H INCREASE O ) REPEAT E TIMES ( CLEAR E INCREASE F ) REPEAT H TIMES ( CLEAR H INCREASE E ) ) REPEAT C TIMES ( CLEAR C INCREASE D ) REPEAT B TIMES ( CLEAR B INCREASE C ) REPEAT A TIMES ( CLEAR A INCREASE B ) REPEAT T TIMES ( CLEAR T INCREASE A ) ) REPEAT E TIMES ( CLEAR E # % 8 == 0 REPEAT A TIMES ( CLEAR A # o > 0 CLEAR X CLEAR Y REPEAT O TIMES ( INCREASE O INCREASE O INCREASE O INCREASE Y INCREASE Y INCREASE X ) PRINT O # 4o PRINT Y # 2o PRINT X # o ) # % 8 == 1 REPEAT B TIMES ( CLEAR B # TODO: maybe unneeded check? CLEAR S # o > 0? REPEAT O TIMES ( CLEAR S INCREASE S ) REPEAT S TIMES ( # X = 8n + 1; X = 24n + 4 (3x+1); X = 0; X = 6n + 1; X = 9n + 2 # Y = 12n + 2; Y = 18n + 4 REPEAT X TIMES ( INCREASE X INCREASE X ) INCREASE X PRINT X # 3x + 1 CLEAR X # X = 0; X <= 6n + 1 CLEAR Y # Y = 12n + 2 REPEAT O TIMES ( INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X ) INCREASE Y INCREASE Y PRINT Y # 12n + 2 INCREASE X PRINT X # 6n + 1 REPEAT O TIMES ( INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE X INCREASE X INCREASE X ) INCREASE Y INCREASE Y PRINT Y # Y = 18n + 4 INCREASE X PRINT X # X = 9n + 2 ) ) # % 8 == 2 REPEAT C TIMES ( CLEAR C CLEAR S # o > 0? REPEAT O TIMES ( CLEAR S INCREASE S ) INCREASE T # o == 0? REPEAT S TIMES ( CLEAR T ) REPEAT T TIMES ( # (2) 1 PRINT T # 1 ) REPEAT S TIMES ( # x <= 12n + 4 CLEAR Y # 4n + 1 REPEAT O TIMES ( INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE X INCREASE X INCREASE X INCREASE X ) INCREASE Y PRINT Y # 4n + 1 INCREASE X INCREASE X PRINT X # 12n + 4 # Y <= 6n + 2 CLEAR X # <= 3n + 1 REPEAT O TIMES ( INCREASE Y INCREASE Y INCREASE X INCREASE X INCREASE X ) INCREASE Y PRINT Y # 6n + 2 INCREASE X PRINT X # 3n + 1 ) ) # % 8 == 3 REPEAT D TIMES ( CLEAR D # x = 24n + 10 REPEAT X TIMES ( INCREASE X INCREASE X ) INCREASE X PRINT X # 24n + 10 (3x + 1) # Y = 12n + 5 CLEAR Y REPEAT O TIMES ( INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y ) INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y PRINT Y # 12n + 5 # x <= 24n+10 + 12n+5 = 36n + 15 REPEAT Y TIMES ( INCREASE X ) INCREASE X PRINT X # 36n + 16 CLEAR X # x <= 9n + 4 # y = 12n+5 + 6n + 3 REPEAT O TIMES ( INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X ) INCREASE Y INCREASE Y INCREASE Y PRINT Y # 18n + 8 INCREASE X INCREASE X INCREASE X INCREASE X PRINT X # 9n + 4 ) ) REPEAT F TIMES ( CLEAR F # % 8 == 4 REPEAT A TIMES ( CLEAR A CLEAR S # o > 0? REPEAT O TIMES ( CLEAR S INCREASE S ) INCREASE T # o == 0? REPEAT S TIMES ( CLEAR T ) REPEAT T TIMES ( # (4) 2 1 CLEAR Z INCREASE Z INCREASE Z PRINT Z # 2 PRINT T # 1 ) REPEAT S TIMES ( CLEAR X # X <= 2n + 1; X <= 3n + 2 CLEAR Y # Y <= 4n + 2; Y <= 6n + 4 REPEAT O TIMES ( INCREASE X INCREASE X INCREASE Y INCREASE Y INCREASE Y INCREASE Y ) INCREASE Y INCREASE Y PRINT Y # 4n + 2 INCREASE X PRINT X # 2n + 1 REPEAT O TIMES ( INCREASE X INCREASE Y INCREASE Y ) INCREASE Y INCREASE Y PRINT Y # 6n + 4 INCREASE X PRINT X # 3n + 2 ) ) # % 8 == 5 REPEAT B TIMES ( CLEAR B # X <= 24n + 16 (3x + 1) REPEAT X TIMES ( INCREASE X INCREASE X ) INCREASE X PRINT X # 24n + 16 CLEAR Y # 12n + 8 # O <= 6n + 4 CLEAR X # 3n + 2 REPEAT O TIMES ( INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE O INCREASE O INCREASE O INCREASE O INCREASE O INCREASE X INCREASE X INCREASE X ) INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y PRINT Y # 12n + 8 INCREASE O INCREASE O INCREASE O INCREASE O PRINT O # 6n + 4 INCREASE X INCREASE X PRINT X # 3n + 2 ) # % 8 == 6 REPEAT C TIMES ( CLEAR C CLEAR Y CLEAR Z # X = 9n + 8 # Y = 4n + 3; Y = 6n + 5 # Z = 12n + 10; Z = 18n + 16 REPEAT O TIMES ( INCREASE X INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z ) INCREASE Y INCREASE Y INCREASE Y PRINT Y # 4n + 3 INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z PRINT Z # 12n + 10 REPEAT O TIMES ( INCREASE Y INCREASE Y INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z ) INCREASE Y INCREASE Y PRINT Y # 6n + 5 INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z PRINT Z # 18n + 16 INCREASE X INCREASE X PRINT X # 9n + 8 ) # % 8 == 7 REPEAT D TIMES ( CLEAR D # Y = 24n + 22 (3x + 1); Y = 36n + 34; Y = 54n + 52; # X = 8n + 7; X = 12n + 11; X = 18n + 17; X = 27n + 26 CLEAR Y # 3x + 1 REPEAT X TIMES ( INCREASE Y INCREASE Y INCREASE Y ) INCREASE Y PRINT Y # 24n + 22 REPEAT O TIMES ( INCREASE X INCREASE X INCREASE X INCREASE X INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y ) INCREASE X INCREASE X INCREASE X INCREASE X PRINT X # 12n + 11 INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y PRINT Y # 36n + 34 REPEAT O TIMES ( INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y ) INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X PRINT X # 18n + 17 INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y INCREASE Y PRINT Y # 54n + 52 REPEAT O TIMES ( INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X ) INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X PRINT X # 27n + 26 ) ) ) ) ) ) ) )