I'm trying to plug this really old phone into my computer but the phone seems to use a very obscure plug. Luckily I have some adapters. Unfortunately, I can't figure out which of them to use to connect my phone to my computer. Can you find the smallest number of adapters that can link my phone and computer?
A pair of strings representing the phone and the computer's port type and a list of pairs of strings where the pair
A, B transforms an input of type
A to type
("A", "D") [ ("A", "B"), ("C", "D"), ("B", "C"), ]
The first pair
("A", "D") is the desired connection. The rest are adapters.
Output the number of adapters required to connect the phone to the computer. In the above example, the answer would be 3 as all 3 adapters would be required.
Phone, Computer TypeA -> TypeB TypeC -> TypeD Output
A, D A -> B B -> C C -> D 3
A, Z A -> B B -> C C -> D D -> Z X -> Y Y -> Z 4
A, B A -> B X -> Y Y -> Z 1
A, C A -> B B -> C C -> A 2
A, C A -> A B -> B C -> C A -> B B -> C 2
- Standard loopholes disallowed
- This is code-golf, shortest code wins
- You can assume it is possible to make the connection
- The port on the phone and computer will not be of the same type
- There may be adapters of type
A -> A
- It is not guaranteed that all of the adapters will be possible to use
- You may take input in any form that is convenient