Skip to content

Instantly share code, notes, and snippets.

@mytja
Created January 5, 2021 12:04
Show Gist options
  • Save mytja/cb005c1aba6423801621b82f0d5eebe1 to your computer and use it in GitHub Desktop.
Save mytja/cb005c1aba6423801621b82f0d5eebe1 to your computer and use it in GitHub Desktop.
Solution for The Cake Is Not A Lie (Google Foobar)
def substring_check(length, sub_str):
for i in range(0, length-1):
if(sub_str[i] == sub_str[i+1]):
if(i == length-2):
return length
else:
continue
else:
return 1
def solution(s):
parts = 1 #Initially, Let's just assume that cake can be divided into just one piece
for i in range(1, len(s)):
sub_str = []
if(len(s) % i == 0):
for j in range(0, len(s), i):
sub_str.append(s[j:j+i])
parts = substring_check(len(sub_str), sub_str)
if(parts != 1):
return parts
return parts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment