Advent of Code 2015 day 2 part 1: solved

This commit is contained in:
Fabian Tessmer 2025-03-21 22:45:45 +01:00
parent 325e726451
commit 00463f4bf6
2 changed files with 1026 additions and 0 deletions

1000
2015/day2/input.txt Normal file

File diff suppressed because it is too large Load Diff

26
2015/day2/solution.py Normal file
View File

@ -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))