Python Solution To A Snake Cube Puzzle

Puzzles provide many hours of applied fun beyond any perfunctory tasks that occupy our days. When your son or daughter receives a snake cube puzzle as a Christmas gift — and it turns out to be deceptively complex — you can sit there for hours to try to figure out a solution, or use the power of Python to sort out the serpentine conundrum and use brute-force to solve it.

Finding himself in such a scenario, [Randy Nuss] walks us through his solution while giving insight into how he approaches writing code — learning other methods of problem solving can be a valuable experience in itself, and thematically fitting, considering this particular case! [Nuss] includes his final code near the end of his post, but his write up instead outlines it in enough detail that would guide others along the correct path. Once it ran successfully, he was cajoled into creating a visualization of the solution since the actual code completes in less than a second.

If a hack is a means to make a given task easier to accomplish, then some fancy coding to solve a puzzle — while perhaps defeating the purpose — is arguably still a hack that simply uses a different avenue. Sometimes, the puzzle winds up being the hack itself when you are gifting something special.

[Thanks for the tip, Josh!]

11 thoughts on “Python Solution To A Snake Cube Puzzle

  1. I received one of these puzzles as a gift. All of the adults and students who tried it were unable to solve it except one. The twelve year old solved it in under two minutes.

  2. i have exactly the same one as in the picture

    that’s funny because (like 6 years ago) i wrote a piece of code (in Caml) to solve this puzzle, even did a presentation in front of a jury (it was a school project)

  3. Very nice use of VPython. Unfortunately, the development of Visual has stopped (or will soon), but the good news is that the functionality has been ported to (runs in browser, nearly but not completely compatible with vpython code). Also available on (as a glowscript plugin).

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.