On Fri 17 Sep, Fergus Henderson wrote:
> On a 300 MHz DEC Alpha system, I got the following times:
> 
>  Language    Compiler version Options  Time
>  Haskell     ghc 2.08  -O                   21.5 seconds
>  Mercury     rotd-1999-09-17 -O6            7.5 seconds
>  Mercury     rotd-1999-09-17 -O6 --gc none  2.2 seconds
>  C++         egcs-1.1.2  -O3                 .2 seconds

The code below takes about 5 seconds to print [1,9,4,2,5,3,0,7,6,8]
using Clean on 233 MHz (I think) G3 PowerMac. This is the closest
Clean equivalent to Marks original I could produce. I suspect it
has an advantage over the ghc version by providing greater scope
for optimisation (because it's all in 1 module).

>module Main
>
>import StdEnv
>
>Start =
> hd [ [t,h,i,r,y,w,e,l,v,n] 
>    \\ t<-xs, e<-xs--[t], h<-xs--[t,e], i<-xs--[t,e,h]
>    ,  r<-xs--[t,e,h,i], y<-xs--[t,e,h,i,r], w<-xs--[t,e,h,i,r,y]
>    ,  l<-xs--[t,e,h,i,r,y,w], v<-xs--[t,e,h,i,r,y,w,l]
>    ,  n<-xs--[t,e,h,i,r,y,w,l,v]
>    |  expand t h i r t y + 5 * expand t w e l v e == expand n i n e t y
>    ]
>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
>
>(--) infix 5
>(--) xs []     = xs
>(--) xs [y:ys] = del y xs -- ys
>
>del x []     = []
>del x [y:ys] = if (x == y) ys [y : del x ys]

P.S. Clean [x:xs] = Haskell (x:xs)

Regards
-- 
Adrian Hey



Reply via email to