-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathday5.py
41 lines (31 loc) · 941 Bytes
/
day5.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
37
38
39
40
41
from typing import List
def parse_input(filename: str) -> List[int]:
return [int(line.strip()) for line in open(filename).readlines()]
def part1(instructions: List[int]) -> int:
in_ptr = 0
steps = 0
while in_ptr < len(instructions):
steps += 1
jump = instructions[in_ptr]
instructions[in_ptr] += 1
in_ptr += jump
return steps
def part2(instructions: List[int]) -> int:
in_ptr = 0
steps = 0
while in_ptr < len(instructions):
steps += 1
jump = instructions[in_ptr]
if jump >= 3:
instructions[in_ptr] -= 1
else:
instructions[in_ptr] += 1
in_ptr += jump
return steps
def main():
instructions = parse_input('input/day5.txt')
print(f'Part 1: {part1(instructions)}')
instructions = parse_input('input/day5.txt')
print(f'Part 2: {part2(instructions)}')
if __name__ == "__main__":
main()