MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi test

Learn moreOpportunities for recent engineering grads.

Apply TodayWho 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:

- All the numbers between 1 to 4ª exist
*once*in a 2ª×2ª matrix. - These numbers form a snake; i.e., each number
*n*must be adjacent to both*n*-1 and*n*+1 (with the obvious exception of 1 and 4ª). - There
*cannot*be more than 4 consecutive numbers in a row or a column.

**Hints**

- Since Chuck Norris can draw an infinite fractal, you may want to check the Hilbert Curve or other Space-filling curves.

**Examples**

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

**Bad Solutions**

`a=1; eye(2^a)`— doesn't have all the numbers 1 to 4.`a=2; reshape(1:4^a,2^a,2^a)`— 4 and 5 aren't adjacent.`a=3; spiral(2^a)`— has 8 consecutive numbers in a row.

The usual cheats **are not** allowed!

7 correct solutions
4 incorrect solutions

Last solution submitted on May 22, 2015