Advertisement
Evoid-null

Advent of code 2021 day 12 part 2

Dec 12th, 2021 (edited)
479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. def path(connected,visited = ['start']): return 1 if visited[-1] == 'end' else sum([path(connected,visited+[p]) for p in [route for route in [i[0] for i in connected if i[1] == visited[-1]]+[i[1] for i in connected if i[0] == visited[-1]] if not route == "start" and ((not route in visited) or (not len(set([a for a in visited if a == a.lower()])) < len([a for a in visited if a == a.lower()])) or (route == route.upper()))]])
  2. print(path([a.split("-") for a in open('input12.txt').read().split("\n")]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement