I would say that the first thing to notice is that you can constrain the numbers from the right hand end, for example if you have defined D to be 3 and S to be 4 you know that T must be 7. In fact we know that (D+S)%10 == T, (ND+ES)%100 == NT and so on. So if we had some code that assigns values in that order and checks constraints at the earliest moment it would solve the problem. To show you what I mean suppose we had some code:
# Note the digits that are not yet assigned $un0 = "0123456789"; foreach $d (split(//,$un0)) { my $un1 = $un0; $un1 =~ s/$d//; foreach $s (split(//,$un1)) { my $un2 = $un1; $un2 =~ s/$s//; foreach $t (split(//,$un2)) { # Now we can check the first constraint next unless(($d + $s)%10 == $t); my $un3 = $un2; $un3 =~ s/$t//; foreach $n (split(//,$un3)) { my $un4 = $un3; $un4 =~ s/$n//; foreach $e (split(//,$un4)) { next unless(($n.$d + $e.$s)%100 == $n.$t); . . . # Having assigned everything see if # we have the correct answer if(($j.$a.$m.$e.$s + $b.$o.$n.$d) \ == ($a.$g.$e.$n.$t)) { print "B=$b A=$a ... goto success; } } } } } } print "Failed\n"; exit(0); success: print "Solved\n"; # Warning code not checked in any way!
Of course the next step is is to convert the problem into a similar piece of text (without the comments and strange indentation). Once we have the text we can evaluate it and get the answer. (I'll leave the fine details to you)
In reply to Re: Words that equal numbers
by hawtin
in thread Words that equal numbers
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |