Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Regex FTW! solution in Clear category for Count And Say by H0r4c3
import re
def count_and_say(digits: str) -> str:
result = ''
pattern = r'(.)\1*'
digits_found = re.finditer(pattern, digits)
for groups in digits_found:
result += str(len(groups.group())) + groups.group()[0]
return result
print("Example:")
print(count_and_say("123"))
# These "asserts" are used for self-checking
assert count_and_say("333388822211177") == "4338323127"
assert count_and_say("1") == "11"
assert count_and_say("") == ""
print("The mission is done! Click 'Check Solution' to earn rewards!")
Feb. 25, 2024
Comments: