# --- 1. SETUP CONSTANTS --- # O = 1 INCREASE O # M = 512 ( Loop Limit ) # Constructed by doubling 1 -> 512 INCREASE M REPEAT M TIMES ( INCREASE M ) REPEAT M TIMES ( INCREASE M ) REPEAT M TIMES ( INCREASE M ) REPEAT M TIMES ( INCREASE M ) REPEAT M TIMES ( INCREASE M ) REPEAT M TIMES ( INCREASE M ) REPEAT M TIMES ( INCREASE M ) REPEAT M TIMES ( INCREASE M ) REPEAT M TIMES ( INCREASE M ) # F = 1 ( Run Flag ) CLEAR F INCREASE F # --- 2. MAIN LOOP --- REPEAT M TIMES ( # --- STEP A: PRINT --- REPEAT F TIMES ( PRINT X ) # --- STEP B: FAST DIVISION --- # We calculate Q ( Quotient ) and R (Remainder) by looping X times. # We DO NOT copy X to Y. We use X directly. REPEAT F TIMES ( CLEAR Q CLEAR R # "Logic Gate" Division # We toggle R between 0 and 1. # If R transitions 1 -> 0, we increment Q. REPEAT X TIMES ( # T is our "Toggle" Helper # Default T to 1 CLEAR T INCREASE T # If R is 1: We need to flip to 0 and increment Q. # We also clear T so the second block doesn't run. REPEAT R TIMES ( CLEAR T INCREASE Q CLEAR R ) # If R was 0: T is still 1. We flip R to 1. REPEAT T TIMES ( INCREASE R ) ) # --- STEP C: CHECK STOP CONDITION --- # If Q == 0, it means X was 1. We must Stop. # We reset F to 0, then set it back to 1 only if Q > 0. CLEAR F REPEAT Q TIMES ( CLEAR F INCREASE F ) # --- STEP D: UPDATE X --- # Only runs if F=1 ( Sequence continues ) REPEAT F TIMES ( # Rebuild "Even" Flag ( E ) # E = NOT R CLEAR E INCREASE E REPEAT R TIMES ( CLEAR E ) CLEAR X # CASE 1: Even ( X = Q ) REPEAT E TIMES ( REPEAT Q TIMES ( INCREASE X ) ) # CASE 2: Odd ( X = 6Q + 4 ) # Derived from: 3 ( 2Q + 1 ) + 1 = 6Q + 4 REPEAT R TIMES ( REPEAT Q TIMES ( INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X INCREASE X ) INCREASE X INCREASE X INCREASE X INCREASE X ) ) ) )