On 9/18/07, Dan Bron <[EMAIL PROTECTED]> wrote:
> In the following formulae each letter represents a distinct digit:
>
>         ONE     FOUR
>            *  4     +ONE
>            ----     ----
>        FOUR     FIVE

Here's a J program to solve these kinds of problems:

require'stats strings'
sub=: ~.@(#~ e.&(a.{~,65 97+/i.26))
dig=: '0123456789' {~ (perm ,/@({"1/) comb&10)@#
pos=: (,/@,."1 dig)@sub charsub"1 ]
ans=: ("."1 # ])@pos

This is rather slow -- it constructs a sentence for
every possibility, then evaluates each of those
sentences to determine which are true.  Evaluating
all those sentences takes a while.

Note that approach this would propose as solutions
numbers with leading zeros, but that turns out to not
be an issue for these puzzles.

That said,
   #four=: ans 'four = 4 * one'
11
   #five=: ans 'five = one + four'
1200

-- 
Raul
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to