-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_02.py
36 lines (27 loc) · 862 Bytes
/
day_02.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import aoc_helper
from aoc_helper import chunk, chunk_default, extract_ints, iter, range
raw = aoc_helper.fetch(2, 2021)
def parse_raw():
for line in raw.splitlines():
direction, distance = line.split()
if direction == "up":
yield 0, -int(distance)
elif direction == "down":
yield 0, int(distance)
elif direction == "forward":
yield int(distance), 0
def part_one():
sum_x, sum_y = 0, 0
for x, y in parse_raw():
sum_x += x
sum_y += y
return sum_x * sum_y
def part_two():
sum_x, sum_y, sum_aim = 0, 0, 0
for x, aim in parse_raw():
sum_aim += aim
sum_y += x * sum_aim
sum_x += x
return sum_x * sum_y
aoc_helper.lazy_submit(day=2, year=2021, solution=part_one)
aoc_helper.lazy_submit(day=2, year=2021, solution=part_two)