day 1 part 2
This commit is contained in:
parent
97bbeebeb0
commit
2e6bf3a11d
12
day01/sol.py
12
day01/sol.py
@ -1,13 +1,23 @@
|
||||
input = open("input")
|
||||
|
||||
t = 0
|
||||
t2 = 0
|
||||
dial = 50
|
||||
for line in input:
|
||||
line = line.strip().replace("L","-").replace("R","")
|
||||
n = int(line)
|
||||
dial += n
|
||||
sgn = n/abs(n)
|
||||
# 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:
|
||||
t += 1
|
||||
|
||||
print(t)
|
||||
print(t2)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user