35 lines
656 B
Python
35 lines
656 B
Python
input = open("input")
|
|
t = 0
|
|
for line in input:
|
|
cells = list(line.strip())
|
|
cells.reverse()
|
|
b = cells[0]
|
|
max = 0
|
|
for c in cells[1:]:
|
|
j = int(c+b)
|
|
if j > max:
|
|
max = j
|
|
if c > b:
|
|
b = c
|
|
#print(max)
|
|
t += max
|
|
print(t)
|
|
|
|
|
|
# Part 2
|
|
|
|
input = open("input")
|
|
t = 0
|
|
for line in input:
|
|
cells = list(line.strip())
|
|
cells.reverse()
|
|
max = ["0"*i for i in range(12+1)]
|
|
for (k,c) in enumerate(cells):
|
|
for i in reversed(range(1,min(k+2,len(max)))):
|
|
j = c+max[i-1]
|
|
if j > max[i]:
|
|
max[i] = j
|
|
print(max[12])
|
|
t += int(max[12])
|
|
print(t)
|