Created
January 26, 2020 21:20
-
-
Save potocpav/889dc01d162f22dbb8eb6791e442e756 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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