The input consists of i rows with neighbors information. Each ith row contains 4 values, representing the neighbor of i to the North, East, South and West directions, respectively. So each value represents a neighbor at the given direction of the ith row, starting from row 1, and can go up to 65,535 rows. The 0 value indicates no neighbor to that direction.
For instance, if the first row is "0 2 3 10" it means that the i neighbor has three other neighbors: no one to the north, neighbor 2 to the east, neighbor 3 to the south and neighbor 10 to the west.
You need to output the array of neighbors, starting from the value which is most to the northwest. Each neighbor will be displayed only once, at its position relative to others. Let's see some examples:
Input:
0 0 0 0
No neighbors (empty case), output:
1
Input:
0 2 0 0
0 0 0 1
1 has neighbor 2 to the east. 2 has neighbor 1 to the west
Output:
1 2
Input:
0 2 0 0
0 0 3 1
2 0 0 0
1 has neighbor 2 to the east. 2 has neighbor 1 to the west and 3 to the south. 3 has neighbor 2 to the north
Output:
1 2
3
Input:
2 0 0 0
0 0 1 0
Output:
2
1
Input:
0 2 3 0
0 0 4 1
1 4 0 0
2 0 0 3
Output:
1 2
3 4
Rules:
Test cases are separated by one empty line. Output of different test cases must also be separated by one empty line.- The output graph is always connected. You are not going to have 1 neighbor to 2 only, along with 3 neighbor to 4 only (isolated from 1-2 component).
- All entries are valid. Example of invalid entries:
- Entries containing letters or any symbol different than spaces, line breaks and digits (0-9).
- the ith row containing the ith value (because one can't be its own neighbor).
- a negative value or value higher than 65,535.
- Less than four values in a row.
- More than four values in a row.
- The same neighbor pointing to two different directions (ex: 0 1 1 0).
Standard loopholes apply, and the shortest answer in bytes wins.
1,2,...
. I though they had a neighbor 2 "units" to the east, and 1 "unit" to the south and so on. Couldn't make sense of it. \$\endgroup\$