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? ;)