On 17-Sep-1999, Jan-Willem Maessen <[EMAIL PROTECTED]> wrote:
> I couldn't help but notice that the Haskell program to solve the given
> cryptarithm is very different indeed from the C++ or Mercury
> implementations.  It selects from a set represented by a list (and
> does repeated list difference using \\) rather than generating and
> testing permutations.

Before I send that mail comparing Haskell/Mercury/C++, I tried a version of
the Haskell code that was much more closely analagous to the Mercury code.
But it actually ran slightly slower, so in my mail I only mentioned the
time for the original Haskell version.

Cheers,
        Fergus.

P.S.  Here's the Haskell code that is analagous to the Mercury code that
I posted.

        import List

        main = print answer

        expand a b c d e f = f + e*10 + d*100 + c*1000 + b*10000 + a*100000

        xs = [0,1..9]  -- all the digits

        answer = head [ list | list@[t,h,i,r,y,w,e,l,v,n] <- perm xs,
          expand t h i r t y + 5 * expand t w e l v e == expand n i n e t y]

        perm :: [t] -> [[t]]
        perm [] = [[]]
        perm (x:xs) = [(y:zs) | (y,ys) <- del (x:xs), zs <- perm ys]

        del :: [t] -> [(t,[t])]
        del [] = []
        del (x:xs) = ((x,xs) : [ (y,(x:ys)) | (y,ys) <- del xs ])

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.


Reply via email to