Alright, my second attempt at a code golf, let's see how this goes.
Pretend you have an array of 9 values. Now imagine that array in a 3x3 grid.
You need to return neighbors that number has as indexes of the array.
0 | 1 | 2
3 | 4 | 5
6 | 7 | 8
- It's code golf, so shortest answer wins.
- The pretend array's index can start at 0 or 1. (all examples use 0 though)
- Just returning values values is frowned upon (like
if 3: return 046)
- The submission can be just a procedure/function/method, but an example would be nice
- The returned value can be in any order(like if input is 0 it could be 13 or 31)
- if you want, the output can be a list of numbers, e.g.
- diagonals don't count, as seen by the examples.