I wrote a brute-force solver in Ruby for the combination-lock puzzle

I wrote a brute-force solver for the “Can you crack the lock code?” / “Can you open the lock using these clues?” puzzle.  Apparently there are a few slightly different versions:

On Puzzlebrain.com, rule 5 contains 7-8-0.

On Puzzlersworld.com, rule 5 contains 8-7-0.

In the one I saw (in a friend’s Facebook post), Rule 5 contains 3-8-0.

The puzzle states that for a 3-digit combination lock, where each
digit is a value between 0 and 9, the following clues are known
about certain combinations:

6-8-2 “One digit is right and in its place”
6-1-4 “One digit is right but in the wrong place”
2-0-6 “Two digits are right, but both are in the wrong place”
7-3-8 “All digits are wrong”
3-8-0 “One digit is right but in the wrong place”

It has been years since I last wrote Ruby code professionally, but I
really enjoyed using it, so I decided to dust off my rusty Ruby
skills today and write a concicse, fairly idiomatic program to
brute-force a solution to this puzzle.

Here it is: https://github.com/JamieFlournoy/Lock-Puzzle-Solver/blob/master/lockpuzzle.rb (There are instructions in the top of the code for how to run it on your computer or in a browser-based Ruby interpreter.)

If you’re curious about the different versions of rule 5, you can edit the code to try those different variations. In fact, why not try commenting out the code where it tests rule 5, to see what the results are when rule 5 doesn’t apply at all? ;)

MacRuby tweaks to your customized .irbrc

I started playing with MacRuby this evening. macirb wouldn’t run with my customized .irbrc and gave the following error:

Continue reading “MacRuby tweaks to your customized .irbrc”

Making Bundler 1.0.0.beta.10 install Nokogiri on Leopard with a newish libxml

Okay, now that Bundler 1.0.0.beta.10 is out, you can once again pass build-time options to gems with native extensions, such as Nokogiri. So this supercedes my older instructions for making Bundler 0.8.5 install Nokogiri on Leopard.

So now instead of making a YAML file and referring to it, pass the options like this:

The Princess and the Pea, as a Cucumber Feature

Kent Beck tweeted:

User story: “As a princess I want to confirm my royalty so I get bruised after sleeping on 40 mattresses over a pea”. Just tell real stories”

That sounded so much like a Cucumber feature that I decided to write it as one:

How to make Machinist and Autotest coexist

If you’ve tried to use Machinist and autotest (part of ZenTest) you have probably seen this exception that prevented you from using it:

It’s discussed in the machinist Google Group as well.

It’s because of a wacky hack that’s part of Machinist that overrides Module.name so you can do Sham.name, but ZenTest expects Module.name to do what it does normally.

I have a fix for this.
Continue reading “How to make Machinist and Autotest coexist”