From 1203fab382ebf86aef2703778107addd905346be Mon Sep 17 00:00:00 2001 From: Seongbeom Park Date: Fri, 13 May 2022 01:55:01 +0900 Subject: [PATCH] finish extra/the-cake-is-not-a-lie Submitting solution... Submission: SUCCESSFUL. Completed in: 10 mins, 5 secs. --- README.md | 3 +++ extra/the-cake-is-not-a-lie/solution.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 extra/the-cake-is-not-a-lie/solution.py diff --git a/README.md b/README.md index 9cf7eaa..255c8f9 100644 --- a/README.md +++ b/README.md @@ -122,3 +122,6 @@ CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQM * Completed in: 18 mins, 46 secs. * Reference * [The Braille Alphabet](https://www.pharmabraille.com/pharmaceutical-braille/the-braille-alphabet/) + +### the-cake-is-not-a-lie +* Completed in: 10 mins, 5 secs. diff --git a/extra/the-cake-is-not-a-lie/solution.py b/extra/the-cake-is-not-a-lie/solution.py new file mode 100644 index 0000000..0c4d037 --- /dev/null +++ b/extra/the-cake-is-not-a-lie/solution.py @@ -0,0 +1,23 @@ +def solution(s): + for i in range(len(s)): + count = i + 1 + if len(s) % count != 0: + continue + + is_equal = True + piece = s[:count] + for j in range(len(s) / count): + if piece != s[j*count:(j+1)*count]: + is_equal = False + break + if is_equal: + return len(s)/count + +tests = [ + ("abcabcabcabc", 4), + ("abccbaabccba", 2), + ] + +for i, o in tests: + result = solution(i) + print (i, result == o, result, o)