Advent of Code 2015 day 2 part 1: solved
This commit is contained in:
parent
325e726451
commit
00463f4bf6
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,26 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def get_package_sides(x: str) -> int:
|
||||||
|
l, w, h = map(int, x.split("x")) # map( int, ...) is necessary, to cast the strings to ints
|
||||||
|
lw, wh, hl = l*w, w*h, h*l
|
||||||
|
smallest_side = min(lw, wh, hl)
|
||||||
|
all_sides = (lw + wh + hl) * 2
|
||||||
|
return smallest_side + all_sides
|
||||||
|
|
||||||
|
|
||||||
|
def calculate_all_packages(x: list) -> int:
|
||||||
|
whole_size = 0
|
||||||
|
for box in x:
|
||||||
|
whole_size += get_package_sides(box)
|
||||||
|
return whole_size
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
assert get_package_sides("2x3x4") == 58, "Error: Example 1 couldn't be solved"
|
||||||
|
assert get_package_sides("1x1x10") == 43, "Error: Example 2 couldn't be solved"
|
||||||
|
|
||||||
|
print("All tests passed!")
|
||||||
|
puzzle_input = open("input.txt", "r").read().splitlines()
|
||||||
|
print("input: ", puzzle_input)
|
||||||
|
print("solution: ", calculate_all_packages(puzzle_input))
|
||||||
Loading…
Reference in New Issue