diff options
| author | n1c00o <git.n1c00o@gmail.com> | 2021-10-09 13:37:31 +0200 |
|---|---|---|
| committer | n1c00o <git.n1c00o@gmail.com> | 2021-10-09 13:37:31 +0200 |
| commit | d86675528b7609b97a579bc1b5ce7d6b408a008f (patch) | |
| tree | 010656cb45a3446f8a54617f51a747c4947b1f36 | |
| parent | 74ae1e903684c50587c61b3ccde06b77641b7a2c (diff) | |
| parent | 7361e0d778e4066c62015b705ad715464deae5fe (diff) | |
Merge branch 'main' of github.com:n1c00o/skipping-work into main
| -rw-r--r-- | boom-baby/Solution.java | 5 | ||||
| -rw-r--r-- | boom-baby/constraints.txt | 21 | ||||
| -rw-r--r-- | boom-baby/readme.txt | 51 | ||||
| -rw-r--r-- | boom-baby/solution.py | 2 | ||||
| -rw-r--r-- | gearing-up-for-destruction/constraints.txt | 21 | ||||
| -rw-r--r-- | gearing-up-for-destruction/matthieu/solution.py | 62 | ||||
| -rw-r--r-- | gearing-up-for-destruction/readme.txt | 48 | ||||
| -rw-r--r-- | gearing-up-for-destruction/solution.py | 0 |
8 files changed, 210 insertions, 0 deletions
diff --git a/boom-baby/Solution.java b/boom-baby/Solution.java new file mode 100644 index 0000000..882206a --- /dev/null +++ b/boom-baby/Solution.java @@ -0,0 +1,5 @@ +public class Solution { + public static String solution(String x, String y) { + // Your code here + } +}
\ No newline at end of file diff --git a/boom-baby/constraints.txt b/boom-baby/constraints.txt new file mode 100644 index 0000000..492c4f1 --- /dev/null +++ b/boom-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.
\ No newline at end of file diff --git a/boom-baby/readme.txt b/boom-baby/readme.txt new file mode 100644 index 0000000..ddebdaa --- /dev/null +++ b/boom-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.
\ No newline at end of file diff --git a/boom-baby/solution.py b/boom-baby/solution.py new file mode 100644 index 0000000..e2b7f8b --- /dev/null +++ b/boom-baby/solution.py @@ -0,0 +1,2 @@ +def solution(x, y): + # Your code here
\ No newline at end of file diff --git a/gearing-up-for-destruction/constraints.txt b/gearing-up-for-destruction/constraints.txt new file mode 100644 index 0000000..f201987 --- /dev/null +++ b/gearing-up-for-destruction/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/gearing-up-for-destruction/matthieu/solution.py b/gearing-up-for-destruction/matthieu/solution.py new file mode 100644 index 0000000..6d4eee3 --- /dev/null +++ b/gearing-up-for-destruction/matthieu/solution.py @@ -0,0 +1,62 @@ +# coding=utf-8 +from fractions import Fraction + +def solution(pegs): + # This function is based on the formulat I figured out on paper + # using what I could find online about gears, I used the + # (number of gears entraining one other) / (number of gears entraned by one other) + # Using the distances, I can express the sizes of all gears from the first one + # and then, using the formula, I can find x + + # The developed formula shows that the signs + / - are present half of the time + # However, the x present in the last part changes if the number is event/pair + # (because of the signs, when n is pair, it adds up to the one present in the other branch + # of the equation, if n is impair, it removes 2x from the single x on the other branch, resulting + # in a negative x in the other branch + + sm = 0 + # Avoid .append by creating a sized array + distances = [pegs[0]] + [0] * (len(pegs) - 1) + + # We calculate the points between the pegs, (except the first one) + for i, v in enumerate(pegs): + if i != 0: + distances[i] = pegs[i] - pegs[i - 1] + + # Derived from the formula + for i, v in enumerate(distances[1:]): + sm += (-1) ** (i) * (2 * v) + + denom = 1 + + # If the number of pegs is pair, we divide by 3 + if len(pegs) % 2 == 0: + denom = 3 + + # Avoid .append by creating a sized array + sizes = [sm / denom] + [0] * (len(pegs) - 1) + + # calculate all the gear sizes + for i, v in enumerate(distances): + if v == distances[0]: + continue + + size = v - sizes[i - 1] + sizes[i] = size + + # all gears must be >= + if size < 1: + return [-1, -1] + + # used to simplify the fraction + f = Fraction(sm, denom) + + # the first gear must be >= 1 + if f < 1: + return [-1, -1] + + return [f.numerator, f.denominator] + + +assert solution([4, 17, 50]) == [-1, -1], "invalid" +assert solution([4, 30, 50]) == [12, 1], "invalid" diff --git a/gearing-up-for-destruction/readme.txt b/gearing-up-for-destruction/readme.txt new file mode 100644 index 0000000..1f57c1d --- /dev/null +++ b/gearing-up-for-destruction/readme.txt @@ -0,0 +1,48 @@ +Gearing Up for Destruction +========================== + +As Commander Lambda's personal assistant, you've been assigned the task of configuring the LAMBCHOP doomsday device's axial orientation gears. It should be pretty simple -- just add gears to create the appropriate rotation ratio. But the problem is, due to the layout of the LAMBCHOP and the complicated system of beams and pipes supporting it, the pegs that will support the gears are fixed in place. + +The LAMBCHOP's engineers have given you lists identifying the placement of groups of pegs along various support beams. You need to place a gear on each peg (otherwise the gears will collide with unoccupied pegs). The engineers have plenty of gears in all different sizes stocked up, so you can choose gears of any size, from a radius of 1 on up. Your goal is to build a system where the last gear rotates at twice the rate (in revolutions per minute, or rpm) of the first gear, no matter the direction. Each gear (except the last) touches and turns the gear on the next peg to the right. + +Given a list of distinct positive integers named pegs representing the location of each peg along the support beam, write a function solution(pegs) which, if there is a solution, returns a list of two positive integers a and b representing the numerator and denominator of the first gear's radius in its simplest form in order to achieve the goal above, such that radius = a/b. The ratio a/b should be greater than or equal to 1. Not all support configurations will necessarily be capable of creating the proper rotation ratio, so if the task is impossible, the function solution(pegs) should return the list [-1, -1]. + +For example, if the pegs are placed at [4, 30, 50], then the first gear could have a radius of 12, the second gear could have a radius of 14, and the last one a radius of 6. Thus, the last gear would rotate twice as fast as the first one. In this case, pegs would be [4, 30, 50] and solution(pegs) should return [12, 1]. + +The list pegs will be given sorted in ascending order and will contain at least 2 and no more than 20 distinct positive integers, all between 1 and 10000 inclusive. + +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({4, 17, 50}) +Output: + -1,-1 + +Input: +Solution.solution({4, 30, 50}) +Output: + 12,1 + +-- Python cases -- +Input: +solution.solution([4, 30, 50]) +Output: + 12,1 + +Input: +solution.solution([4, 17, 50]) +Output: + -1,-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. +
\ No newline at end of file diff --git a/gearing-up-for-destruction/solution.py b/gearing-up-for-destruction/solution.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/gearing-up-for-destruction/solution.py |
