Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
One liner 3 loops solution in Speedy category for Long Repeat Inside by zgoldstein
def repeat_inside(line):
"""
first the longest repeating substring
"""
return max([
line[i:j] * k
for i in range(len(line))
for j in range(i+1, len(line))
for k in range(2, len(line) + 1)
if line[i:j] * k in line
] or [""], key=len)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert repeat_inside('aaaaa') == 'aaaaa', "First"
assert repeat_inside('aabbff') == 'aa', "Second"
assert repeat_inside('aababcc') == 'abab', "Third"
assert repeat_inside('abc') == '', "Forth"
assert repeat_inside('abcabcabab') == 'abcabc', "Fifth"
print('"Run" is good. How is "Check"?')
Feb. 1, 2018
Comments: