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

Return to Question

🍎
Source Link
iBug
  • 2.7k
  • 18
  • 37

Challenge

Given a strings 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. string = '1234500362000440' output = '1234523623441'
2. string = '123450036200044' output = '123452362344'
3. string = '000000000000' output = '12'
4. string = '0123456789' output = '1123456789'
5. string = '1234567890' output = '1234567891'
6. string = '123456789' output = '123456789'
7. string = '010203004050' output = '11121324151'
  1. 12345003620004401234523623441
  2. 123450036200044123452362344
  3. 00000000000012
  4. 01234567891123456789
  5. 12345678901234567891
  6. 123456789123456789
  7. 01020300405011121324151

Note

The shortest answer in bytes wins as per rules

Challenge

Given a strings 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. string = '1234500362000440' output = '1234523623441'
2. string = '123450036200044' output = '123452362344'
3. string = '000000000000' output = '12'
4. string = '0123456789' output = '1123456789'
5. string = '1234567890' output = '1234567891'
6. string = '123456789' output = '123456789'
7. string = '010203004050' output = '11121324151'

Note

The shortest answer in bytes wins as per rules

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

Tweeted twitter.com/StackCodeGolf/status/1605941247197208579
Became Hot Network Question
deleted 75 characters in body; edited title
Source Link
Shaggy
  • 45k
  • 4
  • 39
  • 95

Replace 0 with the consecutive counts in an string0s In a String With Their Consecutive Counts

Challenge

Challenge

Given a string s of any length which contains only digits from 0 to 9. You have to replace each consecutive run of the digit 0 with its consecutive count.Assuming all the character of the given string contains digits from0 to 9 onlylength.

Test Cases

Test Cases

1. string = '1234500362000440' output = '1234523623441'
2. string = '123450036200044' output = '123452362344'
3. string = '000000000000' output = '12'
4. string = '0123456789' output = '1123456789'
5. string = '1234567890' output = '1234567891'
6. string = '123456789' output = '123456789'
7. string = '010203004050' output = '11121324151'

Note

Note

The shortest answer in bytes wins as per code-golf rules

Replace 0 with the consecutive counts in an string

Challenge

Given a string s of any length which contains only digits from 0 to 9. You have to replace the 0 with its consecutive count.Assuming all the character of the given string contains digits from0 to 9 only.

Test Cases

1. string = '1234500362000440' output = '1234523623441'
2. string = '123450036200044' output = '123452362344'
3. string = '000000000000' output = '12'
4. string = '0123456789' output = '1123456789'
5. string = '1234567890' output = '1234567891'
6. string = '123456789' output = '123456789'
7. string = '010203004050' output = '11121324151'

Note

The shortest answer in bytes wins as per code-golf rules

Replace 0s In a String With Their Consecutive Counts

Challenge

Given a string s 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. string = '1234500362000440' output = '1234523623441'
2. string = '123450036200044' output = '123452362344'
3. string = '000000000000' output = '12'
4. string = '0123456789' output = '1123456789'
5. string = '1234567890' output = '1234567891'
6. string = '123456789' output = '123456789'
7. string = '010203004050' output = '11121324151'

Note

The shortest answer in bytes wins as per rules

Source Link
user113990
user113990

Replace 0 with the consecutive counts in an string

Challenge

Given a string s of any length which contains only digits from 0 to 9. You have to replace the 0 with its consecutive count.Assuming all the character of the given string contains digits from0 to 9 only.

Test Cases

1. string = '1234500362000440' output = '1234523623441'
2. string = '123450036200044' output = '123452362344'
3. string = '000000000000' output = '12'
4. string = '0123456789' output = '1123456789'
5. string = '1234567890' output = '1234567891'
6. string = '123456789' output = '123456789'
7. string = '010203004050' output = '11121324151'

Note

The shortest answer in bytes wins as per code-golf rules

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