day 1 part 2
This commit is contained in:
parent
97bbeebeb0
commit
2e6bf3a11d
14
day01/sol.py
14
day01/sol.py
@ -1,13 +1,23 @@
|
|||||||
input = open("input")
|
input = open("input")
|
||||||
|
|
||||||
t = 0
|
t = 0
|
||||||
|
t2 = 0
|
||||||
dial = 50
|
dial = 50
|
||||||
for line in input:
|
for line in input:
|
||||||
line = line.strip().replace("L","-").replace("R","")
|
line = line.strip().replace("L","-").replace("R","")
|
||||||
n = int(line)
|
n = int(line)
|
||||||
dial += n
|
sgn = n/abs(n)
|
||||||
dial %= 100
|
# this is O(n)
|
||||||
|
# could do something fancier but
|
||||||
|
# none of the inputs are large enough
|
||||||
|
# for this to be a noticeable slowdown
|
||||||
|
for i in range(abs(n)):
|
||||||
|
dial += sgn
|
||||||
|
dial %= 100
|
||||||
|
if dial == 0:
|
||||||
|
t2 += 1
|
||||||
if dial == 0:
|
if dial == 0:
|
||||||
t += 1
|
t += 1
|
||||||
|
|
||||||
print(t)
|
print(t)
|
||||||
|
print(t2)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user