[Wellington-pm] SEND + MORE = MONEY

Douglas Bagnall douglas at paradise.net.nz
Tue Mar 1 18:04:10 PST 2005


To halve the number of evals:

  foreach my $i (1..$ITERATIONS){
      my ($digits, $score);
      foreach $digits (keys %candidates) {
+        next if ($candidates{$digits} ne $INF);
          $_ = $equation;
          eval "tr/$letters/$digits/";

(there's no need to reevaluate when the conditions aren't changing. 
Whether the known failing candidates should be kept at all is another 
question).

I'm sure there must be a better way to do this:

         my $pos = int(rand($len));
         my $new_n = int(rand(10));
         my $old_n = substr($digits, $pos,1);
         $digits =~ s/$old_n/x/;
         $digits =~ s/$new_n/$old_n/;
         $digits =~ s/x/$new_n/;


that is, randomly replace one of a short string of unique digits, 
without creating duplicates.

Anyway, I the best solution will recognise the letters as representing 
powers of ten, and use some kind of modulus and division trickery.

cheers,

douglas


> Grant McLean wrote:
> 
>>   SEND
>>  +MORE
>>  =====
>>  MONEY
> 





More information about the Wellington-pm mailing list