Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Replace 0s In a String With Their Consecutive Counts

Challenge

Given a string of any length which contains only digits from 0 to 9, replace each consecutive run of the digit 0 with its length.

Test Cases

  1. 12345003620004401234523623441
  2. 123450036200044123452362344
  3. 00000000000012
  4. 01234567891123456789
  5. 12345678901234567891
  6. 123456789123456789
  7. 01020300405011121324151

Note

The shortest answer in bytes wins as per rules

Answer*

Draft saved
Draft discarded
Cancel
2
  • \$\begingroup\$ Oh, I see you had already posted your answer while I was writing mine. Sorry to outgolf you like that. \$\endgroup\$ Commented Dec 21, 2022 at 13:49
  • \$\begingroup\$ @Neil No problem at all, and great answer! \$\endgroup\$ Commented Dec 21, 2022 at 14:13

AltStyle によって変換されたページ (->オリジナル) /