Input: You are given two numbers n
and m
.
Create the snail: Given an n >= 3
, fill an n
* n
grid with the numbers from 1
to n * n
, starting at the top left, going clockwise to the middle like this (for n
= 5):
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
Calculate the sum of the neightbours of m
: for 4*n – 4 < m <= n*n
, calculate the sum of the eight neighbour numbers in the snail. In the 5 * 5 example, for m
= 17, this would be:
1+2+3+16+18+15+24+25 = 104
Output: Only the sum
Test cases:
4,14 --> 64
5,17 --> 104
5,25 --> 164
6,24 --> 112
6,30 --> 176
6,32 --> 200
6,33 --> 234
Win by finding the shortest code for your language of choice!