You will finish a route finder. The reactions are stored as a map: each compound lists the compounds that can be made from it in one step.
The idea. To find the shortest route, search the map one step at a time. Start from the first compound, then take everything one step away, then two steps away, and stop when you reach the target. This is called a breadth-first search.
Your tasks.
one_step(compound) so that it returns the list of compounds reached in one step. An unknown compound has none.route(start, target) so that it returns the list of compounds from start to target, shortest first.steps_needed(start, target) so that it returns the number of steps, or None when there is no route.Have you tried it?
Do the tasks in the editor first, and run the checker after each one. Its hints help when a check fails. When you are ready, compare your code with this solution.
Log in to join the discussion.
Loading…