Challenge
This coding challenge is to figure out how many rounds the cat can live.
In a \$4\times4\$ matrix, there are a number of mice and exactly 1 cat.
Example:
$$
\begin{array}
{|r|r|}\hline
🐭 & 🐭 & 🐭 & ⬜ \\
\hline
⬜ & 🐭 & ⬜ & ⬜ \\
\hline
⬜ & ⬜ & 🐱⬜ & 🐭 \\
\hline
🐭 & 🐭 & 🐭 & 🐭 \\
\hline
\end{array}
$$
But in each square of the matrix, like a house, up to 5 mice can live in it.
I indicate it with a number in front of the mouse.
There are also squares where there are no mice => Indicated with a blank square.
Example:
$$
\begin{array}
{|r|r|}\hline
1🐭 & 2🐭 & 3🐭 & ⬜ \\
\hline
⬜ & 5🐭 & ⬜ & ⬜ \\
\hline
⬜ & ⬜ & 🐱⬜ & 2🐭 \\
\hline
1🐭 & 4🐭 & 1🐭 & 1🐭 \\
\hline
\end{array}
$$
About the Cat and Mouse
The cat can, and must, move up, down, left, right and diagonal, 1 step at a time. Take into note, that the cat can only eat 1 mouse per round. The cat will always eat a mouse, because it is always hungry.
The cat prefers the house with the most mice in it, although it knows it can eat just one at a time (don't ask me why).
After the cat has eaten a mouse, the number of mice in the house will of course decrease.
After the cat has eaten a mouse, the cat lives in the home of the eaten mouse, possibly with other mice for the remainder of the round.
In the starting position, the cat can only live where there is no mice. But even after the first round, of course the cat must live in a house of the mice.
This goes on and on, till:
Game End
These are the scenarios, when the game ends:
- When there are no more mice around the cat to eat anymore.
=> The cat will starve. (Note the cat cannot eat another mouse in the current house since it must move on, so can end up starving while residing with mice - like in example 5) - When at least 2 of the houses, the cat can visit, has the highest and same number of mice.
=> The cat will die of frustration.
Rules
- The Input must be a list, or an array, or some datatype that can store the number of mice in the house, and where the cat is.
- Where there is no mice, you can indicate it with just \$0🐭\$
- If you use an array, it could be 1 dimensional, but also 2 dimensional.
- The output must be an integer, the number of rounds the cat did survive.
- Standard Loopholes apply, of course.
- This is code-golf, so the shortest code wins.
Good luck!
Note: In the above matrix I showed, the output must be \$3\$.
=> Death because: the cat can't decide in which house of mice to eat.
Example
Example 1
- Starting state: $$ \begin{array} {|r|r|}\hline 1🐭 & 2🐭 & 3🐭 & ⬜ \\ \hline ⬜ & 5🐭 & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & 🐱⬜ & 2🐭 \\ \hline 1🐭 & 4🐭 & 1🐭 & 1🐭 \\ \hline \end{array} $$
- After 1 round: $$ \begin{array} {|r|r|}\hline 1🐭 & 2🐭 & 3🐭 & ⬜ \\ \hline ⬜ & 4🐭\!\!\!\!🐱\!\!\!\! & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & 2🐭 \\ \hline 1🐭 & 4🐭 & 1🐭 & 1🐭 \\ \hline \end{array} $$
- After 2 rounds: $$ \begin{array} {|r|r|}\hline 1🐭 & 2🐭 & 2🐭\!\!\!\!🐱\!\!\!\! & ⬜ \\ \hline ⬜ & 4🐭 & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & 2🐭 \\ \hline 1🐭 & 4🐭 & 1🐭 & 1🐭 \\ \hline \end{array} $$
- After 3 rounds: $$ \begin{array} {|r|r|}\hline 1🐭 & 2🐭 & 2🐭 & ⬜ \\ \hline ⬜ & 3🐭\!\!\!\!🐱\!\!\!\! & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & 2🐭 \\ \hline 1🐭 & 4🐭 & 1🐭 & 1🐭 \\ \hline \end{array} $$
- 4th Round: Death of frustration $$ \begin{array} {|r|r|}\hline 1🐭 & \underbrace{2🐭} & \underbrace{2🐭} & ⬜ \\ \hline ⬜ & 3🐭\!\!\!\!😿\!\!\!\! & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & 2🐭 \\ \hline 1🐭 & 4🐭 & 1🐭 & 1🐭 \\ \hline \end{array} $$
So it just survived 3 rounds.
Example 2
- Starting Stage $$ \begin{array} {|r|r|}\hline 1🐭 & 5🐭 & 1🐭 & 🐱⬜ \\ \hline ⬜ & 5🐭 & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & 2🐭 \\ \hline ⬜ & ⬜ & ⬜ & 1🐭 \\ \hline \end{array} $$
- End Stage: 1 Round $$ \begin{array} {|r|r|}\hline 1🐭 & 5🐭 & ⬜😿 & ⬜ \\ \hline ⬜ & 5🐭 & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & 2🐭 \\ \hline ⬜ & ⬜ & ⬜ & 1🐭 \\ \hline \end{array} $$
Example 3
- Starting Stage $$ \begin{array} {|r|r|}\hline 1🐭 & 5🐭 & 1🐭 & ⬜ \\ \hline ⬜ & 5🐭 & ⬜ & ⬜ \\ \hline 2🐭 & 🐱⬜ & 1🐭 & 4🐭 \\ \hline ⬜ & ⬜ & 1🐭 & 1🐭 \\ \hline \end{array} $$
- End Stage: 7 Rounds $$ \begin{array} {|r|r|}\hline 1🐭 & 2🐭 & 1🐭 & ⬜ \\ \hline ⬜ & 1🐭\!\!\!\!😿\!\!\!\! & ⬜ & ⬜ \\ \hline 2🐭 & ⬜ & 1🐭 & 4🐭 \\ \hline ⬜ & ⬜ & 1🐭 & 1🐭 \\ \hline \end{array} $$
Example 4
- Starting Stage $$ \begin{array} {|r|r|}\hline ⬜ & ⬜ & ⬜ & ⬜ \\ \hline ⬜ & 1🐭 & ⬜ & ⬜ \\ \hline 🐱⬜ & ⬜ & 1🐭 & 1🐭 \\ \hline ⬜ & ⬜ & ⬜ & 2🐭 \\ \hline \end{array} $$
- End Stage: 5 Rounds $$ \begin{array} {|r|r|}\hline ⬜ & ⬜ & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & ⬜😿 \\ \hline \end{array} $$
Example 5
- Starting Stage $$ \begin{array} {|r|r|}\hline ⬜ & 3🐭 & ⬜ & ⬜ \\ \hline ⬜ & 2🐭 & ⬜ & ⬜ \\ \hline 🐱⬜ & ⬜ & 1🐭 & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & ⬜ \\ \hline \end{array} $$
- End Stage: 4 Rounds $$ \begin{array} {|r|r|}\hline ⬜ & 1🐭\!\!\!\!😿\!\!\!\! & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & ⬜ \\ \hline ⬜ & ⬜ & 1🐭 & ⬜ \\ \hline ⬜ & ⬜ & ⬜ & ⬜ \\ \hline \end{array} $$ Good luck again!