;---------------------------------------------- ; Decimal Add1 (long version) ; INPUT FORMAT: a number in base 10 ; EXAMPLE INPUT: 79 ; start at the leftmost digit s1 0 0 R s1 ; find rightmost digit s1 1 1 R s1 s1 2 2 R s1 s1 3 3 R s1 s1 4 4 R s1 s1 5 5 R s1 s1 6 6 R s1 s1 7 7 R s1 s1 8 8 R s1 s1 9 9 R s1 s1 _ _ L s2 s2 0 1 * s3 ; now at the rightmost digit s2 1 2 * s3 ; so add 1 s2 2 3 * s3 s2 3 4 * s3 s2 4 5 * s3 s2 5 6 * s3 s2 6 7 * s3 s2 7 8 * s3 s2 8 9 * s3 s2 9 0 L s2 ; add 1 and carry to left s2 _ 1 * halt ; in case we run off the front end s3 0 0 L s3 ; move back to the leftmost digit s3 1 1 L s3 s3 2 2 L s3 s3 3 3 L s3 s3 4 4 L s3 s3 5 5 L s3 s3 6 6 L s3 s3 7 7 L s3 s3 8 8 L s3 s3 9 9 L s3 s3 _ _ R halt ; halt at the leftmost digit ;---------------------------------------------- ; Decimal Add1 (short version) ; INPUT FORMAT: a number in base 10 ; EXAMPLE INPUT: 79 ; start at the leftmost digit s1 * * R s1 ; * matches any symbol s1 _ _ L s2 s2 0 1 * s3 s2 1 2 * s3 s2 2 3 * s3 s2 3 4 * s3 s2 4 5 * s3 s2 5 6 * s3 s2 6 7 * s3 s2 7 8 * s3 s2 8 9 * s3 s2 9 0 L s2 s2 _ 1 * halt s3 * * L s3 ; * matches any symbol s3 _ _ R halt ;----------------------------------------------