12
The Challenge
Given a grid of numbers (10 <= N <= 99) Return number with the highest sum of the four numbers adjacent to it; that is the numbers above, below, right, and left of the number, but not itself.
- The number itself does not count, only its four neighbors.
- A number on the edge should be treated as though the missing number is a 0.
- I will design the test to avoid ties.
- Numbers will not repeat.
- This is code-golf.
Example
Given
56 98 32 96
12 64 45 31
94 18 83 71
Return
18
A Real Test
Given
98 95 67 66 57 16 40 94 84 37
87 14 19 34 83 99 97 78 50 36
18 44 29 47 21 86 24 15 91 61
60 41 51 26 10 58 11 62 55 71
42 85 56 12 46 81 93 65 49 77
89 13 74 39 54 76 92 33 82 90
96 88 70 79 80 28 25 20 75 68
38 63 17 72 53 48 73 30 45 69
64 35 32 31 23 43 22 52 27 59
Return
13
Given
82 43 79 81 94 36 17 64 58
24 52 13 87 70 18 28 61 69
16 99 75 21 50 44 89 90 51
49 80 63 31 54 65 41 55 38
67 91 76 78 23 86 83 14 73
46 68 62 77 34 48 20 74 10
33 35 26 97 59 66 25 37 32
12 92 84 27 85 56 22 40 45
96 15 98 53 39 30 88 71 29
60 42 11 57 95 19 93 72 47
Return
15
1"*A number on the edge can be treated as though the missing number is a 0.*" - That implies we have a choice as to how to handle numbers on an edge of the grid. Can we therefore choose to wrap around to the other side of the grid? – Shaggy – 2018-06-20T13:55:46.497
@Shaggy No. That might change the expected result. Let's all do it the same way. Text updated s/can/should/ – Umbrella – 2018-06-20T14:37:36.010
2waiting for the inevitable MATL answer – Fatalize – 2018-06-20T14:39:51.737
I notice most of the solutions mutate the input in some way. Is that conventional here? My (yet to be posted) solution includes the bytes required to mutate the input and I'm wondering why many others do not. – Umbrella – 2018-06-20T19:15:18.653
1@Umbrella We generally don't care if the input gets modified. We're interested in short code, not clean code. So long as the output is right, we tend to be pretty permissive. – None – 2018-06-21T02:37:59.487