79 lines
1.8 KiB
Python
79 lines
1.8 KiB
Python
#!/bin/python3
|
|
import sys,time,re,os
|
|
from pprint import pprint
|
|
sys.path.insert(0, '../../')
|
|
from fred import list2int,get_re,nprint,lprint,loadFile
|
|
start_time = time.time()
|
|
|
|
if sys.argv[1] == 'test':
|
|
input_f = 'test'
|
|
elif sys.argv[1] == 'input':
|
|
input_f = 'input'
|
|
else:
|
|
print('No argv provided')
|
|
exit()
|
|
|
|
#########################################
|
|
# #
|
|
# Part 1 #
|
|
# #
|
|
#########################################
|
|
def part1():
|
|
|
|
arr = loadFile(input_f)
|
|
|
|
start = 50
|
|
|
|
current = start
|
|
score = 0
|
|
for x in arr:
|
|
if x[0] == 'L':
|
|
current = (current - int(x[1:]))%100
|
|
elif x[0] == 'R':
|
|
current = (current + int(x[1:]))%100
|
|
if current == 0:
|
|
score += 1
|
|
|
|
return score
|
|
|
|
|
|
start_time = time.time()
|
|
p1 = part1()
|
|
print('Part 1:',p1, '\t\t', round((time.time() - start_time)*1000), 'ms')
|
|
|
|
#########################################
|
|
# #
|
|
# Part 2 #
|
|
# #
|
|
#########################################
|
|
def part2():
|
|
|
|
|
|
arr = loadFile(input_f)
|
|
|
|
start = 50
|
|
|
|
current = start
|
|
score = 0
|
|
|
|
for x in arr:
|
|
dir = x[0]
|
|
num = int(x[1:])
|
|
if dir == 'L':
|
|
for i in range(num):
|
|
current = (current - 1)%100
|
|
if current == 0:
|
|
score += 1
|
|
|
|
elif dir == 'R':
|
|
for i in range(num):
|
|
current = (current + 1)%100
|
|
if current == 0:
|
|
score += 1
|
|
|
|
return score
|
|
|
|
start_time = time.time()
|
|
p2 = part2()
|
|
print('Part 2:',p2, '\t\t', round((time.time() - start_time)*1000), 'ms')
|