Skip to content

Instantly share code, notes, and snippets.

@potocpav
Created January 26, 2020 21:20
Show Gist options
  • Save potocpav/889dc01d162f22dbb8eb6791e442e756 to your computer and use it in GitHub Desktop.
Save potocpav/889dc01d162f22dbb8eb6791e442e756 to your computer and use it in GitHub Desktop.
from more_itertools import iterate, locate
def neighbours(a, b):
raise NotImplementedError # Same as before
def steps_iter(start):
# infinite iterator with 0-step, 1-step, 2-step, etc. neighbor lists
return iterate(lambda l: set(sum([neighbours(*p) for p in l], [])), [start])
def solution(start, end):
# get the ID of the first list which contains `end`
return next(locate(steps_iter(start), lambda l: end in l))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment