Saturday, June 17, 2006

Google Puzzle Solver (1-14 in shape of a G)

Wei-Hwa's latest puzzle follows, along with - once again - a solver written in Perl.
The puzzle is as follows:


The image on the right shows 18 available positions for placement of the numbers from 1 to 14. Of course, 4 positions will remain unused. The trick is to place the numbers incrementally such that the distance between each successive increasing pair is larger than its predecessor.

ie, the distance between 1 and 2 must be smaller than the distance between 2 and 3, which must be smaller than the distance between 3 and 4, and so on, until you've used up all the numbers.

I won't give the solution out here (unless you ask for it), but I will attach a piece of code I wrote in Perl (as always? :) ) that solves the puzzle through recursive brute-force attempts. A puzzle like this is perfectly suited for using recursion, and lets face it - these days so few people even remember recursive programming (LISP / Scheme, anyone? :) ).

Download my code here

Have fun!!!

0 Comments:

Post a Comment

<< Home