Initial commit
This commit is contained in:
commit
b1394d905a
18 changed files with 6496 additions and 0 deletions
22
day1/2.py
Normal file
22
day1/2.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
with open(r'day1/input.txt', 'r') as input:
|
||||
lines = input.read().split('\n')[:-1]
|
||||
|
||||
|
||||
count = 0
|
||||
curr = 50
|
||||
for line in lines:
|
||||
rot,num = line[0],int(line[1:])
|
||||
tmp = curr == 0
|
||||
curr += num if rot == "R" else -num
|
||||
if curr < 0:
|
||||
timesbelow = abs(curr//100)
|
||||
count += timesbelow - (1 if tmp else 0)
|
||||
curr += timesbelow * 100
|
||||
if curr == 0:
|
||||
count += 1
|
||||
if curr > 0:
|
||||
count += curr//100
|
||||
curr = curr%100
|
||||
print(curr, count)
|
||||
|
||||
print(count)
|
||||
Loading…
Add table
Add a link
Reference in a new issue