DEV Community

loading...

Discussion on: Advent of Code 2020: Python Solution Day 10

Collapse
thetalent profile image
thetalent • Edited
data = sorted([int(i) for i in  puzzle.input_data.split(lf)])

 #heads of paths counted over all paths.
resb={0:1}
for i in range(len(data)-1):
    # sum of all paths so far
    value = sum(resb.values()) 
   # next number differs by3 ? all paths apply n
    if data[i+1]-data[i]==3:
       resb={data[i]:value}
  else:
    try:
        # applying is a must for a path with head 3 lower than n
        # as we know from part 1 - a diff of 2 is not there
        resb[data[i]-3]=0
    except:
        pass
  resb[data[i]]=value
Enter fullscreen mode Exit fullscreen mode

print(sum(resb.values()))

Forem Open with the Forem app