Post History
vim, 77 bytes Input is a binary string. :s/^/0 0/ yyP :s/./@a/g qa:g/010*$/s/010*$//e|0:norm<C-V><C-A> :s/111*0*$//e qGdd@"WD <C-V> is 0x16. <C-A> is 0x01 Ungolfe...
#2: Post edited
- # vim, 77 bytes
- Input is a binary string.
- ```vim
- :s/^/0 0/
- yyP
- :s/./@a/g
- qa:g/010*$/s/010*$//e|0:norm<C-V><C-A>
- :s/111*0*$//e
- qGdd@"WD
- ```
- `<C-V>` is 0x16. `<C-A>` is 0x01
- ## Ungolfed:
- ```vim
; Add a leading zero to make the regexes easier, and put "0 " at the front, to act as the count.- :s/^/0 0/
- ; Append a line of code that, when executed, will run
- ; macro `a` once per digit
- yyP
- :s/./@a/g
- ; Record macro `a`
- qa
- ; If the end of the string matches 010*,
- ; consume it and increment the counter
- :g/010*$/s/010*$//e|0:norm<C-V><C-A>
- ; If the end of the string matches 11+0*, consume it
- :s/111*0*$//e
- q
- ; Copy the @a@a@a@a...@a line into register "
- Gdd
- ; Run Macro `"`
- @"
- ; Delete any leading zeroes that remain
- WD
- ```
- [Try it online!][TIO-mmo099ty]
- [V (vim)]: https://github.com/DJMcMayhem/V
- [TIO-mmo099ty]: https://tio.run/##K/v/36pYP07fQMFAn6uyMoALyNPTd0jUT@cqTLRK1zcwNNBS0S@G0vqpNQZWeflFuWKMIIWGhoZaEGGuQveUFAelcJf//4Eq8UIA "V (vim) – Try It Online"
- # vim, 77 bytes
- Input is a binary string.
- ```vim
- :s/^/0 0/
- yyP
- :s/./@a/g
- qa:g/010*$/s/010*$//e|0:norm<C-V><C-A>
- :s/111*0*$//e
- qGdd@"WD
- ```
- `<C-V>` is 0x16. `<C-A>` is 0x01
- ## Ungolfed:
- ```vim
- ; Add a leading zero to make the regexes easier,
- ; and put "0 " at the front, to act as the count.
- :s/^/0 0/
- ; Append a line of code that, when executed, will run
- ; macro `a` once per digit
- yyP
- :s/./@a/g
- ; Record macro `a`
- qa
- ; If the end of the string matches 010*,
- ; consume it and increment the counter
- :g/010*$/s/010*$//e|0:norm<C-V><C-A>
- ; If the end of the string matches 11+0*, consume it
- :s/111*0*$//e
- q
- ; Copy the @a@a@a@a...@a line into register "
- Gdd
- ; Run Macro `"`
- @"
- ; Delete any leading zeroes that remain
- WD
- ```
- [Try it online!][TIO-mmo099ty]
- [V (vim)]: https://github.com/DJMcMayhem/V
- [TIO-mmo099ty]: https://tio.run/##K/v/36pYP07fQMFAn6uyMoALyNPTd0jUT@cqTLRK1zcwNNBS0S@G0vqpNQZWeflFuWKMIIWGhoZaEGGuQveUFAelcJf//4Eq8UIA "V (vim) – Try It Online"
#1: Initial revision
# vim, 77 bytes Input is a binary string. ```vim :s/^/0 0/ yyP :s/./@a/g qa:g/010*$/s/010*$//e|0:norm<C-V><C-A> :s/111*0*$//e qGdd@"WD ``` `<C-V>` is 0x16. `<C-A>` is 0x01 ## Ungolfed: ```vim ; Add a leading zero to make the regexes easier, and put "0 " at the front, to act as the count. :s/^/0 0/ ; Append a line of code that, when executed, will run ; macro `a` once per digit yyP :s/./@a/g ; Record macro `a` qa ; If the end of the string matches 010*, ; consume it and increment the counter :g/010*$/s/010*$//e|0:norm<C-V><C-A> ; If the end of the string matches 11+0*, consume it :s/111*0*$//e q ; Copy the @a@a@a@a...@a line into register " Gdd ; Run Macro `"` @" ; Delete any leading zeroes that remain WD ``` [Try it online!][TIO-mmo099ty] [V (vim)]: https://github.com/DJMcMayhem/V [TIO-mmo099ty]: https://tio.run/##K/v/36pYP07fQMFAn6uyMoALyNPTd0jUT@cqTLRK1zcwNNBS0S@G0vqpNQZWeflFuWKMIIWGhoZaEGGuQveUFAelcJf//4Eq8UIA "V (vim) – Try It Online"
