Advent of Code 2015 day 2 part2: solved

This commit is contained in:
Fabian Tessmer 2025-03-22 07:45:20 +01:00
parent a226fd04ec
commit c87b09cf85
2 changed files with 27 additions and 4 deletions

View File

@ -11,8 +11,6 @@ All numbers in the elves' list are in feet. How many total square feet of wrappi
Your puzzle answer was 1586300.
The first half of this puzzle is complete! It provides one gold star: *
--- Part Two ---
The elves are also running low on ribbon. Ribbon is all the same width, so they only have to worry about the length they need to order, which they would again like to be exact.
@ -23,3 +21,7 @@ For example:
A present with dimensions 2x3x4 requires 2+2+3+3 = 10 feet of ribbon to wrap the present plus 2*3*4 = 24 feet of ribbon for the bow, for a total of 34 feet.
A present with dimensions 1x1x10 requires 1+1+1+1 = 4 feet of ribbon to wrap the present plus 1*1*10 = 10 feet of ribbon for the bow, for a total of 14 feet.
How many total feet of ribbon should they order?
Your puzzle answer was 3737498.
Both parts of this puzzle are complete! They provide two gold stars: **

View File

@ -16,11 +16,32 @@ def calculate_all_packages(x: list) -> int:
return whole_size
def get_package_ribbon(x: str) -> int:
l, w, h = map(int, x.split("x"))
bow = l * w * h
lw, wh, hl = l*2 + w*2, w*2 + h*2, h*2 + l*2
smallest_perimeter = min(lw, wh, hl)
return smallest_perimeter + bow
def calculate_all_packages_ribbon(x: list) -> int:
whole_ribbon = 0
for box in x:
whole_ribbon += get_package_ribbon(box)
return whole_ribbon
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"
assert get_package_ribbon("2x3x4") == 34, "Error: Part2: Example 1 couldn't be solved"
assert get_package_ribbon("1x1x10") == 14, "Error: Part2: 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))
print("Part 2:")
print("solution: ", calculate_all_packages_ribbon(puzzle_input))