-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (31 loc) · 936 Bytes
/
Copy pathmain.py
File metadata and controls
36 lines (31 loc) · 936 Bytes
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
def get_pos(pos, steps, right=True):
# steps can be bigger than 100 use modulo to get remaining steps below 100
steps = modulo(steps, 100)
if (right == False):
if (pos - steps < 0):
pos = num_steps + pos - steps
# 100 + 4 - 15 = 89
else:
pos -= steps
elif(right == True):
if (pos + steps > 99):
pos = (pos + steps) - num_steps
# 15 + 89 - 100 = 4
else:
pos += steps
# 89 + 15 - 100 = 4
return pos
def modulo(a, b):
return a - (a // b) * b
pos = 50
num_steps = 100
count_zero = 0
with open("input.txt") as f:
for line in f:
direction = line[0]
steps = int(line[1:])
pos = get_pos(pos, steps, right=(direction == "R"))
print("Neue Position:", pos)
if (pos == 0):
count_zero += 1
print("Die Position war insgesamt", count_zero, "Mal bei 0.")