25 lines
660 B
Python
25 lines
660 B
Python
file = "input.txt"
|
|
|
|
def main():
|
|
current, count = 50, 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
|
|
pre = current
|
|
current += scalar * magnitude
|
|
if current <= 0 and pre != 0: count += 1
|
|
count += abs(current) // 100
|
|
current = normalize(current)
|
|
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()
|