finish level 1
This commit is contained in:
parent
dd1ac31ddf
commit
67f9e86db9
21
level1/solar-doomsday/constraints.txt
Normal file
21
level1/solar-doomsday/constraints.txt
Normal file
@ -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.
|
||||
41
level1/solar-doomsday/readme.tsx
Normal file
41
level1/solar-doomsday/readme.tsx
Normal file
@ -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
|
||||
1
level1/solar-doomsday/score.txt
Normal file
1
level1/solar-doomsday/score.txt
Normal file
@ -0,0 +1 @@
|
||||
100
|
||||
24
level1/solar-doomsday/solution.py
Normal file
24
level1/solar-doomsday/solution.py
Normal file
@ -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))
|
||||
Loading…
x
Reference in New Issue
Block a user