Skip to content

Instantly share code, notes, and snippets.

@sudarshang
Created November 20, 2018 17:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudarshang/70b315e45f68e20c1a5ccd4c6cec16d8 to your computer and use it in GitHub Desktop.
Save sudarshang/70b315e45f68e20c1a5ccd4c6cec16d8 to your computer and use it in GitHub Desktop.
INTERSECTIONS = ["A 2", "A 3", "A 6", "B 4", "B 5", "C 1", "C 3", "D 1", "D 2", "D 4"]
def Letter(intersection):
return intersection.split()[0]
def Number(intersection):
return intersection.split()[1]
def tell(part, possible_intersections=INTERSECTIONS):
return [
intersection for intersection in possible_intersections if part in intersection
]
def know(possible_intersections):
return len(list(possible_intersections)) == 1
def collision_intersection(possible_intersections=INTERSECTIONS):
return list(filter(statement1to3, possible_intersections))
def statement1(intersection):
possible_intersections = tell(Letter(intersection))
return not know(possible_intersections) and all(
not know(tell(Number(intersection))) for intersection in possible_intersections
)
def statement2(intersection):
at_first = tell(Number(intersection))
return not know(at_first) and know(filter(statement1, at_first))
def statement3(intersection):
return know(filter(statement2, tell(Letter(intersection))))
def statement1to3(intersection):
return (
statement1(intersection)
and statement2(intersection)
and statement3(intersection)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment