# 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 / 4 CLEAR O # a: % 4 == 0 # b: % 4 == 1 # c: % 4 == 2 # d: % 4 == 3 INCREASE A REPEAT X TIMES ( REPEAT D TIMES ( CLEAR D INCREASE T INCREASE O ) 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 ) ) # x % 4 == 0 REPEAT A TIMES ( CLEAR A # o is already 0.5x! # x % 4 == 0, we need to print x/2 and store x/4 in O CLEAR X REPEAT O TIMES ( INCREASE O INCREASE X ) PRINT O # x/2 (2o) PRINT X # x/4 (1o) # check x/2 > 1 (for next iteration) CLEAR S # s <= (x > 0) CLEAR L # L is set to 2 after the loop, cannot assume empty #CLEAR M assume empty, if not empty then we shouldnt be inside the loop # Better x > 1 alg! INCREASE M REPEAT X TIMES ( REPEAT M TIMES ( REPEAT L TIMES ( CLEAR M INCREASE S ) INCREASE L ) ) ) # x % 4 == 1 REPEAT B TIMES ( CLEAR B # x = 12o + 4 = x + (2x+1) REPEAT X TIMES ( INCREASE X INCREASE X ) INCREASE X PRINT X CLEAR X # O = 6o + 2; X = 3o + 1 REPEAT O TIMES ( INCREASE O INCREASE O INCREASE O INCREASE O INCREASE O INCREASE X INCREASE X INCREASE X ) INCREASE O INCREASE O INCREASE X PRINT O PRINT X # O != 0? #CLEAR S # idk why, unneeded check? #REPEAT O TIMES ( CLEAR S INCREASE S ) ) # x % 4 == 2 REPEAT C TIMES ( CLEAR C CLEAR Z # 2o + 1 REPEAT O TIMES ( INCREASE Z INCREASE Z ) INCREASE Z PRINT Z # 2o + 1 # O != 0? CLEAR S INCREASE T REPEAT O TIMES ( REPEAT T TIMES ( CLEAR T CLEAR S INCREASE S ) ) REPEAT S TIMES ( REPEAT Z TIMES ( INCREASE X ) INCREASE X PRINT X # 6o + 4 CLEAR X REPEAT O TIMES ( INCREASE X INCREASE X INCREASE X ) INCREASE X INCREASE X PRINT X # 3o + 2 ) ) # x % 4 == 3 REPEAT D TIMES ( CLEAR D # Z = 3x+1 = 12o + 10 CLEAR Z REPEAT X TIMES ( INCREASE Z INCREASE Z INCREASE Z ) INCREASE Z PRINT Z # 3x + 1 # X = 3x+1 / 2 = x + 2o + 1 REPEAT O TIMES ( INCREASE X INCREASE X ) INCREASE X INCREASE X PRINT X # (3x + 1) / 2 # Z = 12o + 10 + (6o + 6) REPEAT O TIMES ( INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z ) INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z INCREASE Z PRINT Z # 18o + 16 # X = 6o + 5 + (3o + 3) REPEAT O TIMES ( INCREASE X INCREASE X INCREASE X ) INCREASE X INCREASE X INCREASE X PRINT X # 9o + 8 ) ) ) ) ) ) )