Happy Saturday
Thursday night at dinner, one of Stephanie’s colleagues gave me a puzzle to play with.

The idea is to twist and turn the little blocks until they form a 3x3x3 cube. This morning, after messing with it for a few minutes, I decided I didn’t want to brute-force it manually. So I wrote a little script.

And that, my friends, is just about a perfect Saturday morning.

(The script is here.)
Markus on 8 November 2008 at 7:29 am
Would you mind sharing the script?
nat on 8 November 2008 at 7:58 am
It’s nothing special, but sure:
http://nat.org/puzzle.rb
Markus on 8 November 2008 at 8:00 am
thanks!
nat on 8 November 2008 at 8:04 am
No problem; I added a link to the post, in case other people ask.
fatal on 8 November 2008 at 8:07 am
You should get one of these for a v2.0
http://www.amazon.com/Winning-Moves-5002-Rubiks-Twist/dp/B00005BY2A
nat on 8 November 2008 at 8:16 am
By the way, this script only works because I chose the right end of the snake to start with. To make it really generalized you’d have to vary the starting positions.
Hans on 8 November 2008 at 8:16 am
The only thing missing now is to create a robot to do all the twisting for you.
Pavol Rusnak on 8 November 2008 at 11:17 am
My girlfriend bought me similar puzzle. When I compared it to yours, it seems that they are not the same. Here’s the photo of mine: http://img526.imageshack.us/img526/8053/dsc0056te8.jpg
nat on 8 November 2008 at 12:07 pm
@Pavol, here’s the specification of your puzzle:
@snake = [ STRAIGHT, STRAIGHT, TURN, TURN, TURN, TURN,
STRAIGHT, TURN, TURN, TURN, TURN, TURN, TURN,
TURN, TURN, STRAIGHT, TURN, STRAIGHT, TURN,
STRAIGHT, TURN, STRAIGHT, TURN, TURN, TURN,
STRAIGHT, nil ]
And here’s the output of the solver:
% ruby puzzle.rb
Solution: Right, Right, Forward, Up, Back, Left, Left, Forward, Down, Forward, Up, Right, Up, Left, Back, Back, Right, Right, Forward, Forward, Down, Down, Left, Back, Up, Up
Solution: Right, Right, Forward, Up, Back, Left, Left, Forward, Down, Forward, Up, Right, Down, Right, Up, Up, Left, Left, Back, Back, Right, Right, Forward, Left, Down, Down
Solution: Right, Right, Forward, Up, Back, Left, Left, Forward, Down, Forward, Up, Right, Down, Right, Up, Up, Back, Back, Left, Left, Forward, Forward, Right, Back, Down, Down
Solution: Right, Right, Up, Forward, Down, Left, Left, Up, Back, Up, Forward, Right, Forward, Left, Down, Down, Right, Right, Up, Up, Back, Back, Left, Down, Forward, Forward
Solution: Right, Right, Up, Forward, Down, Left, Left, Up, Back, Up, Forward, Right, Back, Right, Forward, Forward, Left, Left, Down, Down, Right, Right, Up, Left, Back, Back
Solution: Right, Right, Up, Forward, Down, Left, Left, Up, Back, Up, Forward, Right, Back, Right, Forward, Forward, Down, Down, Left, Left, Up, Up, Right, Down, Back, Back
Found 6 solutions, 2382 deadends
Yours seems to be about 6 times harder (6x lower solution density), assuming I typed it in correctly.
(By the way I started in the lower-right-hand corner of your picture.)
Hib on 8 November 2008 at 12:42 pm
Hi Nat,
I noticed your interesting keyboard in two pieces in the picture. Can you tell which brand and/or model it is? I would like to buy one myself.
nat on 8 November 2008 at 12:47 pm
@Hib – it’s the Kinesis Freestyle:
http://www.kinesis-ergo.com/freestyle_pc.htm
I’ve been using it for about a week and I really like it. Typing at a traditional keyboard forces you to collapse your shoulders and tighten your chest muscles the entire day. With a split keyboard your posture is a lot more natural (as natural as sitting for hours and hours at a computer can be, anyway).
I have the 8″ separation model right now, but I’m tall so I’ve ordered the 20″ to give that a try. It’s a bit of a rip-off that they charge $40 for another 12 inches of cable…
Jamie Zawinski on 8 November 2008 at 1:52 pm
This is useless until presented in the form of a screen saver.
fsu on 8 November 2008 at 2:08 pm
Nice work!
I had this kind of puzzle to solve:
http://images.google.fi/images?q=Lucifers+Friend+Puzzle
I managed to create script to solve it(using bruteforce) but running that script would take ages.. So, then I searched and found found burrtools:
http://burrtools.sourceforge.net/
(I also packaged it in obs, so you can find it using package search)
Not sure, if it can solve yours one but amazing software.. Solves many kind of puzzles in seconds.
Cat The Marauder on 8 November 2008 at 5:57 pm
You’re a Linux developer, so could you please explain to me why I spot a Mac keyboard in the background?
nat on 8 November 2008 at 6:41 pm
I’m a computer geek first, a Linux geek second
. I use Linux most of the time, but I have a lot of different computers and gadgets.
Rich on 9 November 2008 at 6:26 am
Glad to see you’re blogging again Nat, and that you’re using ruby. Good stuff!
Tony on 9 November 2008 at 8:36 am
Hi Nat,
does that keyboard ship with the wrist rest part we see in the picture?
michael on 9 November 2008 at 9:28 am
The script isn’t useless at all Nat. It’s an excellent intro to Ruby and a good demonstration of problem abstraction.
Good job!
nat on 9 November 2008 at 10:49 am
@Tony – yes, the plastic wrist rests come with the keyboard.
@fsu – Wow, burrtools looks really neat.
kbob on 9 November 2008 at 12:04 pm
Hah! I did exactly the same thing. My script has a timestamp of Dec 10, 2006, and my wife got the puzzle in the summer of 2006.
Pingback from tecosystems » links for 2008-11-09 on 9 November 2008 at 8:06 pm
Chris Cunningham on 10 November 2008 at 7:31 am
It boggles the mind that you would choose a language other than Python for this. Not least because it’s solving a bleedin’ snake…
– Chris
bombart on 5 January 2009 at 8:06 am
Hey what font do you use in your Emacs? I like the curly brackets
& by the way cool puzzle.
F2 on 21 January 2009 at 9:59 pm
Spiffy!
Deverill on 6 April 2009 at 12:07 am
Wow, nice solution. It is great to see programmers go to great lengths to solve things with programs rather than just figuring it out. Of course, we have to figure it out to solve it in a way.
It reminds me of my high school days writing a program on a TRS-80 in BASIC to balance chemistry equations. It was fun to program but it didn’t make chemistry any better. lol
frank206 on 6 April 2009 at 12:07 am
I used to have the same puzzle as a kid, I think. It could make several different shapes and you had to figure them out. I never had the patience for it. I love that you went outside of the box and wrote the script – GENIUS! I don’t think I would have the patience to write that either. What a great Saturday!
Lisa on 6 April 2009 at 12:41 am
Wow. Its amazing what programming can do these days. I think the puzzle would have been much more difficult if the tiles were all the same color, rather than different colors.