Problem 50629. Solve the snake puzzle

My son received this puzzle toy from grandma for his 7th birthday, but he's having a bit of trouble solving it. Can you help?
The toy is a "twisting snake" puzzle made of 27 blocks connected by hidden strings into sixteen segments, each either two or three blocks long. The snake's path must make a 90-degree turn at the end of each segment.
The object is to arrange the puzzle's blocks into a 3-by-3-by-3 cube.
These pictures show the puzzle's configuration when laid out two-dimensionally and its final state when solved.
Your code should return a 27x3 array containing the path traversed by the snake when the puzzle is solved. Each row corresponds to one position, with [1 1 1] representing the back left lower corner of the cube and [3 3 3] representing the front right upper corner. For example, if the path begins in the front left lower corner and the first segment proceeds to the right, the first three rows of the array would be [3 1 1; 3 2 1; 3 3 1].

Solution Stats

40.0% Correct | 60.0% Incorrect
Last Solution submitted on May 03, 2021

Solution Comments

Show comments

Problem Recent Solvers2

Suggested Problems

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!