Post History
vim, 42 bytes Better approach than my previous attempt: we can do this in parallel by having our macro only increment the counter and then replace only the Lone Ones with calls to it. :s/111*//g ...
#1: Initial revision
# vim, 42 bytes Better approach than my previous attempt: we can do this in parallel by having our macro *only* increment the counter and then replace only the Lone Ones with calls to it. ```vim :s/111*//g :s/0//g :s/1/@a/g O0<ESC>qa<C-A>qjdd@"<C-X> ``` `<ESC>` is 0x1b. `<C-A>` is 0x01. `<C-X>` is 0x18. ## Ungolfed ```vim :s/111*//g ; Remove sequences of more than one 1 :s/0//g ; Remove zeroes. ; If unary representations were accepted as output, we'd be done already ; (at 19 bytes). :s/1/@a/g ; Everything that remains is a Lone One: replace with macro call O0<ESC> ; Create counter qa<C-A>q ; Record macro to increment counter jdd ; Copy our @a@a@a...@a sequence into register " @" ; Run the macro sequence <C-X> ; We incremented the counter once when recording the macro. Undo. ``` [Try it online!][TIO-mmpg553f] [TIO-mmpg553f]: https://tio.run/##K/v/36pY39DQUEtfP50LyDSA0ob6DolAlr@BdGEiY2FWSoqDksT//waG@CEA "V (vim) – Try It Online"
