Start with 2021
This commit is contained in:
24
2021/d2.py
Normal file
24
2021/d2.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from lib import get_data
|
||||
from lib import ints
|
||||
|
||||
data = get_data(__file__)
|
||||
|
||||
aim, h2, d2 = 0, 0, 0
|
||||
h, d = 0, 0
|
||||
for line in data.splitlines():
|
||||
(v,) = ints(line)
|
||||
if "forward" in line:
|
||||
h2 += v
|
||||
d2 += aim * v
|
||||
h += v
|
||||
elif "down" in line:
|
||||
aim += v
|
||||
d += v
|
||||
elif "up" in line:
|
||||
aim -= v
|
||||
d -= v
|
||||
else:
|
||||
assert False
|
||||
|
||||
print(h * d)
|
||||
print(h2 * d2)
|
||||
Reference in New Issue
Block a user