Skip to main content
I forgot one instruction/line in the explanation of the code :facepalm:
Source Link
cnamejj
  • 2.8k
  • 10
  • 11
0sp                                - init backup cell to "0"
   ir                              - read input as codepoints and reverse stack
     [                           ] - loops once for each input char
      ';=                          - is it a ";"?
         [    ]p                   - then clause if true
          l                        - load the accumulate value
           +                       - increment by 1 ("if" result is on stack)
            s                      - update backup cell
             !                     - change top of stack to "0" to exit loop
               p                   - delete "if" result
                "#"=               - is is a "#"?
                    [        ]     - then clause if true
                     l             - load backup cell
                      '~`          - generate the number "127"
                         %         - calculate modulo w/ 127
                          o        - print top of stack as char
                           !       - convert to "0" (1)
                            s      - reset backup cell to "0"
                               p   - delete "if" result
                                p  - delete character we just processed
0sp                               - init backup cell to "0"
   ir                             - read input as codepoints and reverse stack
     [                          ] - loops once for each input char
      ';=                         - is it a ";"?
         [    ]p                  - then clause if true
          l                       - load the accumulate value
           +                      - increment by 1 ("if" result is on stack)
            s                     - update backup cell
             !                    - change top of stack to "0" to exit loop
               p                  - delete "if" result
                "#"=              - is is a "#"?
                    [        ]    - then clause if true
                     l            - load backup cell
                      '~`         - generate the number "127"
                         %        - calculate modulo w/ 127
                          !       - convert to "0" (1)
                           s      - reset backup cell to "0"
                              p   - delete "if" result
                               p  - delete character we just processed
0sp                                - init backup cell to "0"
   ir                              - read input as codepoints and reverse stack
     [                           ] - loops once for each input char
      ';=                          - is it a ";"?
         [    ]p                   - then clause if true
          l                        - load the accumulate value
           +                       - increment by 1 ("if" result is on stack)
            s                      - update backup cell
             !                     - change top of stack to "0" to exit loop
               p                   - delete "if" result
                "#"=               - is is a "#"?
                    [        ]     - then clause if true
                     l             - load backup cell
                      '~`          - generate the number "127"
                         %         - calculate modulo w/ 127
                          o        - print top of stack as char
                           !       - convert to "0" (1)
                            s      - reset backup cell to "0"
                               p   - delete "if" result
                                p  - delete character we just processed
Source Link
cnamejj
  • 2.8k
  • 10
  • 11

Ly, 33 bytes

0spir[';=[l+s!]p"#"=[l'~`%o!s]pp]

Try it online!

A different take using Ly

0sp                               - init backup cell to "0"
   ir                             - read input as codepoints and reverse stack
     [                          ] - loops once for each input char
      ';=                         - is it a ";"?
         [    ]p                  - then clause if true
          l                       - load the accumulate value
           +                      - increment by 1 ("if" result is on stack)
            s                     - update backup cell
             !                    - change top of stack to "0" to exit loop
               p                  - delete "if" result
                "#"=              - is is a "#"?
                    [        ]    - then clause if true
                     l            - load backup cell
                      '~`         - generate the number "127"
                         %        - calculate modulo w/ 127
                          !       - convert to "0" (1)
                           s      - reset backup cell to "0"
                              p   - delete "if" result
                               p  - delete character we just processed

Note(1): If the input tries to print a null (meaning x'00') the code will fail. If that's a requirement I can tweak the code to harden it against that. I think it would just add one more character... Printing nulls sounds like a mistake though, so I'm not sure it's necessary?