Who hasn't played the Snake game when they were little? It's quite hard to finish this simple game; nonetheless Chuck Norris has accomplished the task in the most difficult level, naturally. Now, since the game was too easy for him, he did it with the highest number of turns possible. We shall now inspect Chuck Norris' solution.
Suppose you have a 2ª×2ª matrix M (with an integer a ≥ 0). The path of the snake is denoted with consecutive numbers 1÷4ª. The matrix M must obey the following conditions:
hungry_snake(0) ans = 1
hungry_snake(1) ans = 1 2 4 3
hungry_snake(2) ans = 1 4 5 6 2 3 8 7 15 14 9 10 16 13 12 11
The usual cheats are not allowed!
MATLAB and Simulink resources for Arduino, LEGO, and Raspberry PiLearn more
Opportunities for recent engineering grads.Apply Today
New to MATLAB?Learn MATLAB today!
Play games and win prizes!Learn more