From 9900e4c4dd7a1a2c8f5ddfe14f895240857ccd02 Mon Sep 17 00:00:00 2001 From: Seongbeom Park Date: Sat, 15 Jan 2022 07:47:12 +0000 Subject: [PATCH] finish Level3/bomb baby --- README.md | 8 +++++ level3/bomb-baby/constraints.txt | 21 +++++++++++++ level3/bomb-baby/readme.txt | 51 ++++++++++++++++++++++++++++++++ level3/bomb-baby/solution.py | 23 ++++++++++++++ recruitme.txt | 8 +++++ 5 files changed, 111 insertions(+) create mode 100644 level3/bomb-baby/constraints.txt create mode 100644 level3/bomb-baby/readme.txt create mode 100644 level3/bomb-baby/solution.py create mode 100644 recruitme.txt diff --git a/README.md b/README.md index 491c87f..ce2e45c 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,11 @@ * Completed in: 2 days, 19 hrs, 36 mins, 16 secs. * Reference * L26.6 Absorption Probabilities, MIT OpenCourseWare, https://www.youtube.com/watch?v=vEsUsaK1HBk + +### the-grandest-staircase-of-them-all +* Completed in: 16 hrs, 38 mins, 52 secs. +* DP + +### bomb-baby +* Completed in: 1 hr, 46 mins, 55 secs. +* GCD diff --git a/level3/bomb-baby/constraints.txt b/level3/bomb-baby/constraints.txt new file mode 100644 index 0000000..f201987 --- /dev/null +++ b/level3/bomb-baby/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/level3/bomb-baby/readme.txt b/level3/bomb-baby/readme.txt new file mode 100644 index 0000000..18f9a62 --- /dev/null +++ b/level3/bomb-baby/readme.txt @@ -0,0 +1,51 @@ +Bomb, Baby! +=========== + +You're so close to destroying the LAMBCHOP doomsday device you can taste it! But in order to do so, you need to deploy special self-replicating bombs designed for you by the brightest scientists on Bunny Planet. There are two types: Mach bombs (M) and Facula bombs (F). The bombs, once released into the LAMBCHOP's inner workings, will automatically deploy to all the strategic points you've identified and destroy them at the same time. + +But there's a few catches. First, the bombs self-replicate via one of two distinct processes: +Every Mach bomb retrieves a sync unit from a Facula bomb; for every Mach bomb, a Facula bomb is created; +Every Facula bomb spontaneously creates a Mach bomb. + +For example, if you had 3 Mach bombs and 2 Facula bombs, they could either produce 3 Mach bombs and 5 Facula bombs, or 5 Mach bombs and 2 Facula bombs. The replication process can be changed each cycle. + +Second, you need to ensure that you have exactly the right number of Mach and Facula bombs to destroy the LAMBCHOP device. Too few, and the device might survive. Too many, and you might overload the mass capacitors and create a singularity at the heart of the space station - not good! + +And finally, you were only able to smuggle one of each type of bomb - one Mach, one Facula - aboard the ship when you arrived, so that's all you have to start with. (Thus it may be impossible to deploy the bombs to destroy the LAMBCHOP, but that's not going to stop you from trying!) + +You need to know how many replication cycles (generations) it will take to generate the correct amount of bombs to destroy the LAMBCHOP. Write a function solution(M, F) where M and F are the number of Mach and Facula bombs needed. Return the fewest number of generations (as a string) that need to pass before you'll have the exact number of bombs necessary to destroy the LAMBCHOP, or the string "impossible" if this can't be done! M and F will be string representations of positive integers no larger than 10^50. For example, if M = "2" and F = "1", one generation would need to pass, so the solution would be "1". However, if M = "2" and F = "4", it would not be possible. + +Languages +========= + +To provide a Java solution, edit Solution.java +To provide a Python solution, edit solution.py + +Test cases +========== +Your code should pass the following test cases. +Note that it may also be run against hidden test cases not shown here. + +-- Java cases -- +Input: +Solution.solution('2', '1') +Output: + 1 + +Input: +Solution.solution('4', '7') +Output: + 4 + +-- Python cases -- +Input: +solution.solution('4', '7') +Output: + 4 + +Input: +solution.solution('2', '1') +Output: + 1 + +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. diff --git a/level3/bomb-baby/solution.py b/level3/bomb-baby/solution.py new file mode 100644 index 0000000..83c80e4 --- /dev/null +++ b/level3/bomb-baby/solution.py @@ -0,0 +1,23 @@ +def solution(x, y): + return gcd(int(x), int(y)) + +def gcd(x, y): + count = 0 + while y != 0: + t = x % y + count += x//y + x, y = y, t + if x != 1: + return 'impossible' + return str(count-1) + +tests=[ + [['4', '7'], '4'], + [['2', '1'], '1'], + [['2', '4'], 'impossible'], + ] + +for test in tests: + result = solution(*test[0]) + print(test[0][0], test[0][1], result == test[1], result, test[1]) + print '' diff --git a/recruitme.txt b/recruitme.txt new file mode 100644 index 0000000..cca8bd7 --- /dev/null +++ b/recruitme.txt @@ -0,0 +1,8 @@ +Checking your permissions... +Share solutions with a Google Recruiter? +If you opt in, Google Staffing may reach out to you regarding career opportunities, events, and programs. We will use your information in accordance with our Applicant and Candidate Privacy Policy. +Applicant and Candidate Privacy Policy. +[#1] [Yes [N]o [A]sk me later:] +[Y]es [N]o [A]sk me later: A +Response: contact postponed. +To share your progress at any time, use the recruitme command.