day 3 simplify
This commit is contained in:
parent
3698cf9c35
commit
ecbbd39af1
31
day03/sol.py
31
day03/sol.py
@ -1,25 +1,6 @@
|
|||||||
input = open("input")
|
input = open("input")
|
||||||
t = 0
|
part1 = 0
|
||||||
for line in input:
|
part2 = 0
|
||||||
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:
|
for line in input:
|
||||||
cells = list(line.strip())
|
cells = list(line.strip())
|
||||||
cells.reverse()
|
cells.reverse()
|
||||||
@ -29,6 +10,8 @@ for line in input:
|
|||||||
j = c+max[i-1]
|
j = c+max[i-1]
|
||||||
if j > max[i]:
|
if j > max[i]:
|
||||||
max[i] = j
|
max[i] = j
|
||||||
print(max[12])
|
#print(max[12])
|
||||||
t += int(max[12])
|
part1 += int(max[2])
|
||||||
print(t)
|
part2 += int(max[12])
|
||||||
|
print(part1)
|
||||||
|
print(part2)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user