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
4
  • \$\begingroup\$ if the string ends in 0s, it just removes them: Try it online! \$\endgroup\$ Commented Dec 27, 2022 at 0:29
  • \$\begingroup\$ here's 59 based on what you curerntly have though, to give you a good base: Try it online! \$\endgroup\$ Commented Dec 27, 2022 at 0:46
  • \$\begingroup\$ no it doesn't fix it, i just golfed your current code down. Try it online! that should end in a 3 \$\endgroup\$ Commented Dec 27, 2022 at 0:52
  • \$\begingroup\$ @Steffan fixed, thanks \$\endgroup\$ Commented Dec 31, 2022 at 21:02

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