day02
This commit is contained in:
parent
abe1fc1532
commit
a0b4513d31
37
day02.py
Normal file
37
day02.py
Normal file
@ -0,0 +1,37 @@
|
||||
from aoc import AOCDay
|
||||
from typing import Any
|
||||
|
||||
|
||||
class Day(AOCDay):
|
||||
test_solutions_p1 = [150]
|
||||
test_solutions_p2 = [900]
|
||||
|
||||
def part1(self) -> Any:
|
||||
path = self.getInputAsArraySplit(" ", [str, int])
|
||||
pos = 0
|
||||
depth = 0
|
||||
for direction in path:
|
||||
if direction[0] == 'forward':
|
||||
pos += direction[1]
|
||||
elif direction[0] == 'down':
|
||||
depth += direction[1]
|
||||
elif direction[0] == 'up':
|
||||
depth -= direction[1]
|
||||
|
||||
return pos * depth
|
||||
|
||||
def part2(self) -> Any:
|
||||
path = self.getInputAsArraySplit(" ", [str, int])
|
||||
pos = 0
|
||||
depth = 0
|
||||
aim = 0
|
||||
for direction in path:
|
||||
if direction[0] == 'forward':
|
||||
pos += direction[1]
|
||||
depth += aim * direction[1]
|
||||
elif direction[0] == 'down':
|
||||
aim += direction[1]
|
||||
elif direction[0] == 'up':
|
||||
aim -= direction[1]
|
||||
|
||||
return pos * depth
|
||||
1000
inputs/input02
Normal file
1000
inputs/input02
Normal file
File diff suppressed because it is too large
Load Diff
6
inputs/test_input02_1_0
Normal file
6
inputs/test_input02_1_0
Normal file
@ -0,0 +1,6 @@
|
||||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
||||
6
inputs/test_input02_2_0
Normal file
6
inputs/test_input02_2_0
Normal file
@ -0,0 +1,6 @@
|
||||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
||||
Loading…
Reference in New Issue
Block a user