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

posted 6mo ago by Ray‭

Answer
#1: Initial revision by user avatar Ray‭ · 2026-03-13T22:18:54Z (6 months ago)
# 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"