Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using recursion solution in Clear category for Long Repeat by levi-rs
def count_chars(line, char=''):
""" Recursive function to count sequential characters """
if not line:
return char
new_char, *new_line = line
if new_char == char or char == '':
return char + count_chars(new_line, new_char)
else:
return char
def long_repeat(line):
return max([len(count_chars(line[x:])) for x in range(0, len(line))], default=0)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert long_repeat('sdsffffse') == 4, "First"
assert long_repeat('ddvvrwwwrggg') == 3, "Second"
print('"Run" is good. How is "Check"?')
Dec. 4, 2017
Comments: