Created
April 12, 2017 02:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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