Day 2
This commit is contained in:
parent
792f135f69
commit
1d568ddb2a
4 changed files with 2056 additions and 0 deletions
29
day2/so1.py
Normal file
29
day2/so1.py
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
base = lambda l,w: l*w
|
||||||
|
front = lambda w,h: w*h
|
||||||
|
side = lambda h,l: h*l
|
||||||
|
|
||||||
|
def paper(l: int, w: int, h: int):
|
||||||
|
base = l*w
|
||||||
|
front = w*h
|
||||||
|
side = h*l
|
||||||
|
sup = min(base, front, side)
|
||||||
|
|
||||||
|
return 2*base + 2*front + 2*side + sup
|
||||||
|
|
||||||
|
def paper_from_str(s: str):
|
||||||
|
l, w, h = map(int, s.split('x'))
|
||||||
|
return paper(l, w, h)
|
||||||
|
|
||||||
|
def test():
|
||||||
|
assert paper_from_str("2x3x4") == 58
|
||||||
|
assert paper_from_str("1x1x10") == 43
|
||||||
|
|
||||||
|
def solution():
|
||||||
|
s = 0
|
||||||
|
with open("in1") as puzzle:
|
||||||
|
for l in puzzle:
|
||||||
|
s += paper_from_str(l)
|
||||||
|
return s
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(f"Total paper: {solution()}")
|
27
day2/so2.py
Normal file
27
day2/so2.py
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
def bow(l,w,h):
|
||||||
|
base = 2*l + 2*w
|
||||||
|
front = 2*w + 2*h
|
||||||
|
side = 2*h + 2*l
|
||||||
|
|
||||||
|
rib = min([base, front, side])
|
||||||
|
rib += l*w*h
|
||||||
|
|
||||||
|
return rib
|
||||||
|
|
||||||
|
def bow_from_str(s):
|
||||||
|
l,w,h = map(int, s.split('x'))
|
||||||
|
return bow(l,w,h)
|
||||||
|
|
||||||
|
def test():
|
||||||
|
assert bow_from_str("2x3x4") == 34
|
||||||
|
assert bow_from_str("1x1x10") == 14
|
||||||
|
|
||||||
|
def solution():
|
||||||
|
s = 0
|
||||||
|
with open("in2") as puzzle:
|
||||||
|
for l in puzzle:
|
||||||
|
s += bow_from_str(l)
|
||||||
|
return s
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print(f"Bow: {solution()}")
|
Loading…
Reference in a new issue