You've already forked advent_of_code
feat: Redo of the AoC repo starting over with 2015 and keeping up with
2025 (completed day 2 so far)
This commit is contained in:
BIN
15/2/__pycache__/main.cpython-313.pyc
Normal file
BIN
15/2/__pycache__/main.cpython-313.pyc
Normal file
Binary file not shown.
BIN
15/2/__pycache__/test_day2.cpython-313-pytest-9.0.1.pyc
Normal file
BIN
15/2/__pycache__/test_day2.cpython-313-pytest-9.0.1.pyc
Normal file
Binary file not shown.
38
15/2/main.py
Normal file
38
15/2/main.py
Normal file
@@ -0,0 +1,38 @@
|
||||
'''AoC day 2'''
|
||||
|
||||
def get_surface_area(l: int, w: int, h: int) -> int:
|
||||
'''Take the dimensions of the box and return its surface area
|
||||
|
||||
Keyword args:
|
||||
l (int) - Length
|
||||
w (int) - Width
|
||||
h (int) - Height
|
||||
'''
|
||||
return 2*l*w + 2*w*h + 2*h*l
|
||||
|
||||
def get_slack_amount(l: int, w: int, h: int) -> int:
|
||||
'''Take dimensions and return the value of the smallest'''
|
||||
return min([l*w, w*h, h*l])
|
||||
|
||||
def get_ribbon_amount(l: int, w: int, h: int) -> int:
|
||||
return min([2*h + 2*w, 2*l + 2*w, 2*h + 2*l]) + (l*w*h)
|
||||
|
||||
def main():
|
||||
'''Entrypoint'''
|
||||
# Surface area for wrapping paper
|
||||
with open('input.txt', encoding='utf-8') as fh:
|
||||
sum = 0
|
||||
r_sum = 0
|
||||
|
||||
for line in fh:
|
||||
l, w, h = [int(x) for x in line.split('x')]
|
||||
# print(f'{l} {w} {h}')
|
||||
sum += get_surface_area(l, w, h)
|
||||
sum += get_slack_amount(l, w, h)
|
||||
r_sum += get_ribbon_amount(l, w, h)
|
||||
|
||||
print(f'Part 1, sum of wrapping paper: {sum}')
|
||||
print(f'Part 2, sum of ribbon: {r_sum}')
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
27
15/2/test_day2.py
Normal file
27
15/2/test_day2.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import pytest
|
||||
|
||||
from main import get_slack_amount, get_surface_area, get_ribbon_amount
|
||||
|
||||
@pytest.mark.parametrize('l, w, h, expected',
|
||||
[
|
||||
(2, 3, 4, 52),
|
||||
(1, 1, 10, 42)
|
||||
])
|
||||
def test_surface_area(l, w, h, expected):
|
||||
assert get_surface_area(l, w, h) == expected
|
||||
|
||||
@pytest.mark.parametrize('l, w, h, expected',
|
||||
[
|
||||
(2, 3, 4, 6),
|
||||
(1, 1, 10, 1)
|
||||
])
|
||||
def test_slack_amount(l, w, h, expected):
|
||||
assert get_slack_amount(l, w, h) == expected
|
||||
|
||||
@pytest.mark.parametrize('l, w, h, expected',
|
||||
[
|
||||
(2, 3, 4, 34),
|
||||
(1, 1, 10, 14)
|
||||
])
|
||||
def test_ribbon_amount(l, w, h, expected):
|
||||
assert get_ribbon_amount(l, w, h) == expected
|
||||
Reference in New Issue
Block a user