day 1 refactor
This commit is contained in:
parent
56f7b7d0c5
commit
c78f8ebf61
14
d01/run.py
14
d01/run.py
|
@ -4,19 +4,13 @@ D = [str(i) for i in range(1,10)]
|
|||
if sys.argv[1] == "2":
|
||||
D += ['one','two','three','four','five','six','seven','eight','nine']
|
||||
|
||||
def process_line(l):
|
||||
def process(l):
|
||||
k = list()
|
||||
p = 0
|
||||
while (p<len(l)):
|
||||
for p in range(len(l)):
|
||||
for i,d in enumerate(D):
|
||||
if l[p:p+len(d)] == d:
|
||||
k.append(i%9+1)
|
||||
break
|
||||
p += 1
|
||||
return '!'.join(map(str,k)), k[0]*10 + k[-1] if len(k)>0 else 0
|
||||
return k[0]*10 + k[-1] if len(k)>0 else 0
|
||||
|
||||
R=0
|
||||
for l in sys.stdin.readlines():
|
||||
n = process_line(l[:-1])
|
||||
R+=n[1]
|
||||
print(R)
|
||||
print(sum(process(l) for l in sys.stdin.read().splitlines()))
|
||||
|
|
Loading…
Reference in New Issue