From 67f9e86db9035923a126d9606155a92420bf4b4e Mon Sep 17 00:00:00 2001 From: Seongbeom Park Date: Sun, 9 Jan 2022 14:40:12 +0900 Subject: [PATCH] finish level 1 --- level1/solar-doomsday/constraints.txt | 21 ++++++++++++++ level1/solar-doomsday/readme.tsx | 41 +++++++++++++++++++++++++++ level1/solar-doomsday/score.txt | 1 + level1/solar-doomsday/solution.py | 24 ++++++++++++++++ 4 files changed, 87 insertions(+) create mode 100644 level1/solar-doomsday/constraints.txt create mode 100644 level1/solar-doomsday/readme.tsx create mode 100644 level1/solar-doomsday/score.txt create mode 100644 level1/solar-doomsday/solution.py diff --git a/level1/solar-doomsday/constraints.txt b/level1/solar-doomsday/constraints.txt new file mode 100644 index 0000000..f201987 --- /dev/null +++ b/level1/solar-doomsday/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/level1/solar-doomsday/readme.tsx b/level1/solar-doomsday/readme.tsx new file mode 100644 index 0000000..0b7cbeb --- /dev/null +++ b/level1/solar-doomsday/readme.tsx @@ -0,0 +1,41 @@ +Solar Doomsday +============== + +Who would've guessed? Doomsday devices take a LOT of power. Commander Lambda wants to supplement the LAMBCHOP's quantum antimatter reactor core with solar arrays, and you've been tasked with setting up the solar panels. + +Due to the nature of the space station's outer paneling, all of its solar panels must be squares. Fortunately, you have one very large and flat area of solar material, a pair of industrial-strength scissors, and enough MegaCorp Solar Tape(TM) to piece together any excess panel material into more squares. For example, if you had a total area of 12 square yards of solar material, you would be able to make one 3x3 square panel (with a total area of 9). That would leave 3 square yards, so you can turn those into three 1x1 square solar panels. + +Write a function solution(area) that takes as its input a single unit of measure representing the total area of solar panels you have (between 1 and 1000000 inclusive) and returns a list of the areas of the largest squares you could make out of those panels, starting with the largest squares first. So, following the example above, solution(12) would return [9, 1, 1, 1]. + +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(15324) +Output: + 15129,169,25,1 + +Input: +solution.solution(12) +Output: + 9,1,1,1 + +-- Java cases -- +Input: +Solution.solution(12) +Output: + 9,1,1,1 + +Input: +Solution.solution(15324) +Output: + 15129,169,25,1 diff --git a/level1/solar-doomsday/score.txt b/level1/solar-doomsday/score.txt new file mode 100644 index 0000000..29d6383 --- /dev/null +++ b/level1/solar-doomsday/score.txt @@ -0,0 +1 @@ +100 diff --git a/level1/solar-doomsday/solution.py b/level1/solar-doomsday/solution.py new file mode 100644 index 0000000..e5fe51b --- /dev/null +++ b/level1/solar-doomsday/solution.py @@ -0,0 +1,24 @@ +import math +def solution(area): + return chop(area) + +def chop(area): + remain_area = area + squares = [] + while (remain_area > 0): + cutting_area = int(math.floor(remain_area ** 0.5)) ** 2 + remain_area -= cutting_area + squares.append(cutting_area) + return squares + +def chop_recursive(area): + if area == 0: + return [] + else: + cutting_area = int(math.floor(area ** 0.5)) ** 2 + return [cutting_area] + chop(area - cutting_area) + +print(solution(15324)) +print(solution(12)) +print(solution(1)) +print(solution(1000000))