From 19247f31ec0483c0ea687cb36333d0c5d8b0facd Mon Sep 17 00:00:00 2001 From: Seongbeom Park Date: Sat, 7 May 2022 18:54:52 +0000 Subject: [PATCH] finish extra/bunny-worker-locations --- README.md | 3 ++ extra/bunny-worker-locations/constraints.txt | 21 ++++++++ extra/bunny-worker-locations/readme.txt | 52 ++++++++++++++++++++ extra/bunny-worker-locations/solution.py | 13 +++++ 4 files changed, 89 insertions(+) create mode 100644 extra/bunny-worker-locations/constraints.txt create mode 100644 extra/bunny-worker-locations/readme.txt create mode 100644 extra/bunny-worker-locations/solution.py diff --git a/README.md b/README.md index 2efbb04..39dce6e 100644 --- a/README.md +++ b/README.md @@ -88,3 +88,6 @@ CFcSBwgCCBoHRhkKU1cGAA4AGU5YQR5THBwNFwoGGAxTQQMQVBUSBg4EAAwQRhUQVBUHFAQTGRpT QQM ### power-hungry * Completed in: 16 mins, 49 secs. + +### bunny-worker-locations +* Completed in: 6 mins, 49 secs. diff --git a/extra/bunny-worker-locations/constraints.txt b/extra/bunny-worker-locations/constraints.txt new file mode 100644 index 0000000..f201987 --- /dev/null +++ b/extra/bunny-worker-locations/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/bunny-worker-locations/readme.txt b/extra/bunny-worker-locations/readme.txt new file mode 100644 index 0000000..246a1df --- /dev/null +++ b/extra/bunny-worker-locations/readme.txt @@ -0,0 +1,52 @@ +Bunny Worker Locations +====================== + +Keeping track of Commander Lambda's many bunny workers is starting to get tricky. You've been tasked with writing a program to match bunny worker IDs to cell locations. + +The LAMBCHOP doomsday device takes up much of the interior of Commander Lambda's space station, and as a result the work areas have an unusual layout. They are stacked in a triangular shape, and the bunny workers are given numerical IDs starting from the corner, as follows: + +| 7 +| 4 8 +| 2 5 9 +| 1 3 6 10 + +Each cell can be represented as points (x, y), with x being the distance from the vertical wall, and y being the height from the ground. + +For example, the bunny worker at (1, 1) has ID 1, the bunny worker at (3, 2) has ID 9, and the bunny worker at (2,3) has ID 8. This pattern of numbering continues indefinitely (Commander Lambda has been adding a LOT of workers). + +Write a function solution(x, y) which returns the worker ID of the bunny at location (x, y). Each value of x and y will be at least 1 and no greater than 100,000. Since the worker ID can be very large, return your solution as a string representation of the number. + +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(3, 2) +Output: + 9 + +Input: +Solution.solution(5, 10) +Output: + 96 + +-- Python cases -- +Input: +solution.solution(5, 10) +Output: + 96 + +Input: +solution.solution(3, 2) +Output: + 9 + +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/extra/bunny-worker-locations/solution.py b/extra/bunny-worker-locations/solution.py new file mode 100644 index 0000000..afab071 --- /dev/null +++ b/extra/bunny-worker-locations/solution.py @@ -0,0 +1,13 @@ +def solution(x, y): + return str(((x + y - 1) * (x + y) / 2) - (y - 1)) + +tests = [ + ([1, 1], "1"), + ([3, 2], "9"), + ([5, 10], "96"), + ([2, 3], "8") + ] + +for i, o in tests: + result = solution(*i) + print (i, result == o, result, o)