Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Python solution to google's foobar the cake is not a lie
from __future__ import division
from __future__ import print_function
def answer(s):
if not bool(s):
return 0
result = 0
howlong = len(s)
i = howlong
while i > 0:
n = howlong / i
if (n * i) == howlong:
valid = 1
part = s[:int(n)]
j = 1
while j < i:
if not s[int(j*n):int(j*n+n)] == part:
valid = 0
break
j = j + 1
if bool(valid):
result = i
break
i = i - 1
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment