Tamnica
Brave Sir Robin has been thrown in the dungeon by the evil king. The dungeon consists of an infinite number of cubeshaped rooms with big stone walls. Rooms are connected by passages so that the entire dungeon, when viewed from above, looks like a spiral. The rooms are numbered as follows:

After a big earthquake some of the walls collapsed, and new passages were formed between adjacent rooms.Sir Robin is initially in room 1. Sir Robin knows that the exit from the dungeon is located in room N, and wants to escape while everyone is distracted by the earthquake. Because the evil dragon is guarding the dungeon, Sir Robin wants to use the fastest way out of the dungeon. Write a program that, given the location of the exit N and the list of new passages, determines the smallest number of passages that Sir Robin must go through before he can exit the dungeon.
31
9
15
25
30
6
9
19
24
27
4 Output:
6Submit solution
Sign in to submit a solution.