Repository navigation
Expand file tree
/
Copy pathday1.py
More file actions
52 lines (42 loc) · 1.35 KB
/
Copy pathday1.py
File metadata and controls
52 lines (42 loc) · 1.35 KB
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
42
43
44
45
46
47
48
49
50
51
52
def solve_day1_part1(actions):
start_degree = 50
res = 0
for ac in actions:
step = (int(ac[1:])) % 100
match ac[0]:
case 'L':
start_degree -= step
if start_degree < 0:
start_degree = 100 + start_degree
case 'R':
start_degree += step
if start_degree >= 100:
start_degree = start_degree-100
res += 1 if start_degree == 0 else 0
return res
def solve_day1_part2(actions):
start_degree = 50
res = 0
for ac in actions:
step = (int(ac[1:]))
res += step//100
step = step % 100
start_degree = start_degree % 100
if step == 0:
continue
initial_start = start_degree
match ac[0]:
case 'L':
start_degree -= step
if start_degree <= 0:
start_degree = 100 + start_degree
if initial_start != 0 and start_degree != 0:
res += 1
case 'R':
start_degree += step
if start_degree >= 100:
start_degree = start_degree-100
if initial_start != 0 and start_degree != 0:
res += 1
res += 1 if start_degree == 0 else 0
return res