Escape the labyrinth! You are trapped in this 5x5 labyrinth - each room is labelled from 1 to 25 and the exit is in room 1.



You are given as input the room you are currently in. Your task is to output the shortest sequence of moves (north, east, south, west) needed to reach room 1.

Moves can be output in any format you wish (list, string, array...) as long as you use the characters n,w,e,s.

Here are all the test cases:

1 =&gt; empty string/list
2 =&gt; w
3 =&gt; ww
4 =&gt; swwnw
5 =&gt; wswwnw
6 =&gt; seenwnw
7 =&gt; nw
8 =&gt; wnw
9 =&gt; wwnw
10 =&gt; swwnwnw
11 =&gt; eenwnw
12 =&gt; enwnw
13 =&gt; nwnw
14 =&gt; wnwnw
15 =&gt; wwnwnw
16 =&gt; enenwnw
17 =&gt; nenwnw
18 =&gt; wnenwnw
19 =&gt; nwnwnw
20 =&gt; wnwnwnw
21 =&gt; nenenwnw
22 =&gt; enwnenwnw
23 =&gt; nwnenwnw
24 =&gt; wnwnenwnw
25 =&gt; nwnwnwnw


Shortest answer in bytes wins!
Python 2, 64 bytes



def f(n):d=0x1211252b5375&gt;&gt;2*n-4&amp;3;print"nwes"[d];f(n+d*3+d%2-5)


Try it online!

A function that prints one direction per line, terminating with error. 

The constant 0x1211252b5375 encodes in base 4 the direction d we travel from each room number as a number 0 through 3. The extraction digit &gt;&gt;2*n-4&amp;3 is also designed to give a negative shift error when n=1, terminating the code. We update the room number n via an offset that's computed from the direction d as d*3+d%2-5, which maps:

d   d*3+d%2-5
0  -&gt; -5
1  -&gt; -1
2  -&gt;  1
3  -&gt;  5