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 3×3x3 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.)

Posted on 8 November 2008

27 comments

  1. Markus’s avatar

    Would you mind sharing the script?

    Reply

  2. nat’s avatar

    It’s nothing special, but sure:

    http://nat.org/puzzle.rb

    Reply

  3. Markus’s avatar

    thanks!

    Reply

  4. nat’s avatar

    No problem; I added a link to the post, in case other people ask.

    Reply

  5. nat’s avatar

    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.

    Reply

  6. Hans’s avatar

    The only thing missing now is to create a robot to do all the twisting for you.

    Reply

  7. Pavol Rusnak’s avatar

    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

    Reply

  8. nat’s avatar

    @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.)

    Reply

  9. Hib’s avatar

    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.

    Reply

  10. nat’s avatar

    @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…

    Reply

  11. Jamie Zawinski’s avatar

    This is useless until presented in the form of a screen saver.

    Reply

  12. fsu’s avatar

    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.

    Reply

  13. Cat The Marauder’s avatar

    You’re a Linux developer, so could you please explain to me why I spot a Mac keyboard in the background? :)

    Reply

  14. nat’s avatar

    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.

    Reply

  15. Rich’s avatar

    Glad to see you’re blogging again Nat, and that you’re using ruby. Good stuff!

    Reply

  16. Tony’s avatar

    Hi Nat,

    does that keyboard ship with the wrist rest part we see in the picture?

    Reply

  17. michael’s avatar

    The script isn’t useless at all Nat. It’s an excellent intro to Ruby and a good demonstration of problem abstraction.

    Good job!

    Reply

  18. nat’s avatar

    @Tony – yes, the plastic wrist rests come with the keyboard.

    @fsu – Wow, burrtools looks really neat.

    Reply

  19. kbob’s avatar

    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.

    Reply

  20. Chris Cunningham’s avatar

    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

    Reply

  21. bombart’s avatar

    Hey what font do you use in your Emacs? I like the curly brackets :-) & by the way cool puzzle.

    Reply

  22. Deverill’s avatar

    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

    Reply

  23. frank206’s avatar

    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!

    Reply

  24. Lisa’s avatar

    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.

    Reply