2015 day 1 & 2.
This commit is contained in:
parent
52cb793d06
commit
ea0c9e7812
0
src/holt59/aoc/2015/__init__.py
Normal file
0
src/holt59/aoc/2015/__init__.py
Normal file
10
src/holt59/aoc/2015/day1.py
Normal file
10
src/holt59/aoc/2015/day1.py
Normal file
@ -0,0 +1,10 @@
|
||||
import sys
|
||||
|
||||
line = sys.stdin.read().strip()
|
||||
|
||||
floor = 0
|
||||
floors = [(floor := floor + (1 if c == "(" else -1)) for c in line]
|
||||
|
||||
|
||||
print(f"answer 1 is {floors[-1]}")
|
||||
print(f"answer 2 is {floors.index(-1)}")
|
15
src/holt59/aoc/2015/day2.py
Normal file
15
src/holt59/aoc/2015/day2.py
Normal file
@ -0,0 +1,15 @@
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
|
||||
lines = sys.stdin.read().splitlines()
|
||||
|
||||
l, w, h = np.array([[int(c) for c in line.split("x")] for line in lines]).T
|
||||
|
||||
lw, wh, hl = (l * w, w * h, h * l)
|
||||
|
||||
answer_1 = np.sum(2 * (lw + wh + hl) + np.min(np.stack([lw, wh, hl]), axis=0))
|
||||
print(f"answer 1 is {answer_1}")
|
||||
|
||||
answer_2 = np.sum(l * w * h + 2 * np.min(np.stack([l + w, l + h, h + w]), axis=0))
|
||||
print(f"answer 2 is {answer_2}")
|
1
src/holt59/aoc/inputs/holt59/2015/day1.txt
Normal file
1
src/holt59/aoc/inputs/holt59/2015/day1.txt
Normal file
File diff suppressed because one or more lines are too long
1000
src/holt59/aoc/inputs/holt59/2015/day2.txt
Normal file
1000
src/holt59/aoc/inputs/holt59/2015/day2.txt
Normal file
File diff suppressed because it is too large
Load Diff
2
src/holt59/aoc/inputs/tests/2015/day2.txt
Normal file
2
src/holt59/aoc/inputs/tests/2015/day2.txt
Normal file
@ -0,0 +1,2 @@
|
||||
2x3x4
|
||||
1x1x10
|
Loading…
Reference in New Issue
Block a user