Skip to content

Instantly share code, notes, and snippets.

@f3ath
Created June 14, 2018 05:50
Show Gist options
  • Save f3ath/3ffe8d74214501c5f653562dfab9afd2 to your computer and use it in GitHub Desktop.
Save f3ath/3ffe8d74214501c5f653562dfab9afd2 to your computer and use it in GitHub Desktop.
def substrings_exist(line, size):
max_possible_offset = len(line) - size * 2
for offset in range(0, max_possible_offset + 1):
border = offset + size
substring = line[offset:border]
the_rest_of_the_string = line[border:]
if the_rest_of_the_string.find(substring) != -1:
return True
return False
def double_substring(line):
max_possible_substring_size = len(line) // 2
for size in range(max_possible_substring_size, 0, -1):
if substrings_exist(line, size):
return size
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment