From c2a6981eb472c935f092d3e8e4fc0e7002c16f1f Mon Sep 17 00:00:00 2001 From: Seongbeom Park Date: Fri, 13 May 2022 01:45:12 +0900 Subject: [PATCH 1/2] request extra/the-cake-is-not-a-lie --- extra/the-cake-is-not-a-lie/constraints.txt | 21 ++++++++++ extra/the-cake-is-not-a-lie/readme.txt | 45 +++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 extra/the-cake-is-not-a-lie/constraints.txt create mode 100644 extra/the-cake-is-not-a-lie/readme.txt diff --git a/extra/the-cake-is-not-a-lie/constraints.txt b/extra/the-cake-is-not-a-lie/constraints.txt new file mode 100644 index 0000000..f201987 --- /dev/null +++ b/extra/the-cake-is-not-a-lie/constraints.txt @@ -0,0 +1,21 @@ +Java +==== +Your code will be compiled using standard Java 8. All tests will be run by calling the solution() method inside the Solution class + +Execution time is limited. + +Wildcard imports and some specific classes are restricted (e.g. java.lang.ClassLoader). You will receive an error when you verify your solution if you have used a blacklisted class. + +Third-party libraries, input/output operations, spawning threads or processes and changes to the execution environment are not allowed. + +Your solution must be under 32000 characters in length including new lines and and other non-printing characters. + +Python +====== +Your code will run inside a Python 2.7.13 sandbox. All tests will be run by calling the solution() function. + +Standard libraries are supported except for bz2, crypt, fcntl, mmap, pwd, pyexpat, select, signal, termios, thread, time, unicodedata, zipimport, zlib. + +Input/output operations are not allowed. + +Your solution must be under 32000 characters in length including new lines and and other non-printing characters. diff --git a/extra/the-cake-is-not-a-lie/readme.txt b/extra/the-cake-is-not-a-lie/readme.txt new file mode 100644 index 0000000..785e0cf --- /dev/null +++ b/extra/the-cake-is-not-a-lie/readme.txt @@ -0,0 +1,45 @@ +The cake is not a lie! +====================== + +Commander Lambda has had an incredibly successful week: the first test of the LAMBCHOP doomsday device was completed AND Lambda set a new personal high score in Tetris. To celebrate, the Commander ordered cake for everyone -- even the lowliest of minions! But competition among minions is fierce, and if you don't cut exactly equal slices of cake for everyone you'll get in big trouble. + +The cake is round, and decorated with M&Ms in a circle around the edge. But while the rest of the cake is uniform, the M&Ms are not: there are multiple colors, and every minion must get exactly the same sequence of M&Ms. Commander Lambda hates waste and will not tolerate any leftovers, so you also want to make sure you can serve the entire cake. + +To help you best cut the cake, you have turned the sequence of colors of the M&Ms on the cake into a string: each possible letter (between a and z) corresponds to a unique color, and the sequence of M&Ms is given clockwise (the decorations form a circle around the outer edge of the cake). + +Write a function called solution(s) that, given a non-empty string less than 200 characters in length describing the sequence of M&Ms, returns the maximum number of equal parts that can be cut from the cake without leaving any leftovers. + +Languages +========= + +To provide a Python solution, edit solution.py +To provide a Java solution, edit Solution.java + +Test cases +========== +Your code should pass the following test cases. +Note that it may also be run against hidden test cases not shown here. + +-- Python cases -- +Input: +solution.solution("abcabcabcabc") +Output: + 4 + +Input: +solution.solution("abccbaabccba") +Output: + 2 + +-- Java cases -- +Input: +Solution.solution("abcabcabcabc") +Output: + 4 + +Input: +Solution.solution("abccbaabccba") +Output: + 2 + +Use verify [file] to test your solution and see how it does. When you are finished editing your code, use submit [file] to submit your answer. If your solution passes the test cases, it will be removed from your home folder. -- 2.47.2 From 1203fab382ebf86aef2703778107addd905346be Mon Sep 17 00:00:00 2001 From: Seongbeom Park Date: Fri, 13 May 2022 01:55:01 +0900 Subject: [PATCH 2/2] 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) -- 2.47.2