Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Lone ​​​​​​ones

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...

posted 6mo ago by Ray‭  ·  edited 6mo ago by Ray‭

Answer
#2: Post edited by user avatar Ray‭ · 2026-03-12T22:07:23Z (6 months ago)
  • # 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 by user avatar Ray‭ · 2026-03-12T22:04:32Z (6 months ago)
# 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"