23 lines
576 B
Python
23 lines
576 B
Python
file = "input1.txt"
|
|
|
|
def main():
|
|
current = 50
|
|
count = 0
|
|
print(f"{current} count:{count}")
|
|
for line in open(file):
|
|
direction, magnitude = line[:1], int(line[1:])
|
|
scalar = 1 if direction == "R" else -1
|
|
current = normalize(current + scalar * magnitude)
|
|
if current == 0: count += 1
|
|
print(f"{direction} {magnitude} => {current} count:{count}")
|
|
|
|
def normalize(x):
|
|
if 0 <= x <= 99: return x
|
|
if x <= 0:
|
|
return normalize(100 + x)
|
|
else:
|
|
return normalize(x - 100)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|