87
11
Sixteen piles of cheese are put on a 4x4 square. They're labeled from \$1\$ to \$16\$. The smallest pile is \$1\$ and the biggest one is \$16\$.
The Hungry Mouse is so hungry that it always goes straight to the biggest pile (i.e. \$16\$) and eats it right away.
After that, it goes to the biggest neighboring pile and quickly eats that one as well. (Yeah ... It's really hungry.) And so on until there's no neighboring pile anymore.
A pile may have up to 8 neighbors (horizontally, vertically and diagonally). There's no wrap-around.
Example
We start with the following piles of cheese:
$$\begin{matrix} 3&7&10&5\\ 6&8&12&13\\ 15&9&11&4\\ 14&1&16&2 \end{matrix}$$
The Hungry Mouse first eats \$16\$, and then its biggest neighbor pile, which is \$11\$.
$$\begin{matrix} 3&7&10&5\\ 6&8&12&13\\ 15&9&&4\\ 14&1&\color{grey}\uparrow&2 \end{matrix}$$
Its next moves are \$13\$, \$12\$, \$10\$, \$8\$, \$15\$, \$14\$, \$9\$, \$6\$, \$7\$ and \$3\$ in this exact order.
$$\begin{matrix} &\color{grey}\leftarrow&\small\color{grey}\swarrow&5\\ \small\color{grey}\nearrow&\small\color{grey}\swarrow&\color{grey}\uparrow&\color{grey}\leftarrow\\ \color{grey}\downarrow&\small\color{grey}\nwarrow&\small\color{grey}\nearrow&4\\ \small\color{grey}\nearrow&1&\color{grey}\uparrow&2 \end{matrix}$$
There's no cheese anymore around the Hungry Mouse, so it stops there.
The challenge
Given the initial cheese configuration, your code must print or return the sum of the remaining piles once the Hungry Mouse has stopped eating them.
For the above example, the expected answer is \$12\$.
Rules
- Because the size of the input matrix is fixed, you may take it as either a 2D array or a one-dimensional array.
- Each value from \$1\$ to \$16\$ is guaranteed to appear exactly once.
- This is code-golf.
Test cases
[ [ 4, 3, 2, 1], [ 5, 6, 7, 8], [12, 11, 10, 9], [13, 14, 15, 16] ] --> 0
[ [ 8, 1, 9, 14], [11, 6, 5, 16], [13, 15, 2, 7], [10, 3, 12, 4] ] --> 0
[ [ 1, 2, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12], [13, 14, 15, 16] ] --> 1
[ [10, 15, 14, 11], [ 9, 3, 1, 7], [13, 5, 12, 6], [ 2, 8, 4, 16] ] --> 3
[ [ 3, 7, 10, 5], [ 6, 8, 12, 13], [15, 9, 11, 4], [14, 1, 16, 2] ] --> 12
[ [ 8, 9, 3, 6], [13, 11, 7, 15], [12, 10, 16, 2], [ 4, 14, 1, 5] ] --> 34
[ [ 8, 11, 12, 9], [14, 5, 10, 16], [ 7, 3, 1, 6], [13, 4, 2, 15] ] --> 51
[ [13, 14, 1, 2], [16, 15, 3, 4], [ 5, 6, 7, 8], [ 9, 10, 11, 12] ] --> 78
[ [ 9, 10, 11, 12], [ 1, 2, 4, 13], [ 7, 8, 5, 14], [ 3, 16, 6, 15] ] --> 102
[ [ 9, 10, 11, 12], [ 1, 2, 7, 13], [ 6, 16, 4, 14], [ 3, 8, 5, 15] ] --> 103
33+1 for that mouse character – Luis Mendo – 2018-11-19T21:59:10.507
78? You can be meaner than that! I think 102 is as mean as one can get though (e.g.
[[9, 10, 11, 12], [1, 2, 4, 13], [7, 8, 5, 14], [3, 16, 6, 15]]
) - hmm[0, 0, 19, 102, ...]
– Jonathan Allan – 2018-11-19T23:21:30.6872...make that 103:
[[9, 10, 11, 12], [1, 2, 7, 13], [6, 16, 4, 14], [3, 8, 5, 15]]
– Jonathan Allan – 2018-11-19T23:32:34.1879What a nicely written challenge! I'll keep it in mind for the best-of nominations. – xnor – 2018-11-20T02:22:44.387
9After misreading I was a little sad that this was not a hungry moose. – akozi – 2018-11-20T13:17:46.223
1This challenge reminds me of the mouse in the maze program for the txo computer. This game was written way back in the 1950s, and the txo was the first transistorized computer in the world, according to legend. Yes, believe it or not, somebody was writing video games in your grandfather's day. – Walter Mitty – 2018-11-20T19:05:07.263
1
@akozi Sandboxed challenge "The Hungry Moose": https://codegolf.meta.stackexchange.com/a/17123/39328
– lirtosiast – 2018-11-20T22:03:23.790