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!]
While I love the hack and the idea of it, I’ve just solved the one in the picture, in my head… is that weird?!
Was really not that hard…
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.
for people interesting in solving mathematical “things” with code: https://projecteuler.net/
Neat, this is basically a 3d nesting software problem. Not sure how well this solution will scale though?
The difficulty goes up exponentially with the number of dimensions.
Four was easy, but I’m having trouble solving the 5 dimensional case in my head.
Try scaling to more parts with more possible ways to connect them.
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)
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 glowscript.org (runs in browser, nearly but not completely compatible with vpython code). Also available on trinket.io (as a glowscript plugin).
I should point out that it is the same group who maintain Visual who are maintaining Glowscript.
Solution fails if the first block must start on an edge or in the middle of one surface. Try this: ESCCCSCSCCCCCCCCCCCCCSCSCCE
with E for end, S for straight and C for Corner