Skip to content

Instantly share code, notes, and snippets.

@Packet-Lost
Created April 12, 2017 02:47
Show Gist options
  • Save Packet-Lost/ae6b67eabc1643ac0361882e158738c5 to your computer and use it in GitHub Desktop.
Save Packet-Lost/ae6b67eabc1643ac0361882e158738c5 to your computer and use it in GitHub Desktop.
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