I modified the one-liner solution a bit as follows.

The output of calling qsolve(1000000) can be seen at

http://myflask-tutoriats.rhcloud.com/QueenPuzzle

//       
macdef sing = stream_make_sing
macdef intrange = list0_make_intrange
//              
fun qsolve(nsol: Nat): void =
(((fix qsolve(n: int): stream(list0(int)) => if(n > 0)then((qsolve(n-1)*
intrange(0,N)).map(TYPE{list0(int)})(lam($tup(xs,x))=>cons0(x,xs))).filter
()(lam(xs)=>let val-cons0(x0,xs) = xs in xs.iforall()(lam(i, x)=>((x0)!=x
)&&(abs(x0-x)!=i+1)) end)else(sing(nil0())))(N)).takeLte(nsol)).iforeach()(
lam(i,xs)=>(gprintln!("Solution#", i+1, ":"); xs.rforeach()(lam(x) => ((N).
foreach()(lam(i)=>(gprint_string(ifval(i=x," Q", "."))));gprintln!()));
gprintln!()))
//


On Sunday, July 3, 2016 at 3:30:18 AM UTC-4, gmhwxi wrote:
>
> Here it is:
>
> ((fix f(n:int):stream_vt(list0(int))=>if(n > 0)then((f(n-1)*intrange(0,N
> )).filter()(lam(xsy)=>let val(xs,y)=xsy in $effmask_all(xs.iforall()(lam(i
> ,x)=>(x != y && abs(x-y) != i+1)))end)).map()(lam(xs_y)=>let val (xs, y)=xs_y 
> in cons0(y,xs) end)else(sing(nil0())))(N)).foreach()(lam(xs)=>((xs).
> rforeach()(lam(x)=>((N).foreach()(lam(i)=>print_string(ifval(i=x," Q"," ."
> )));println!()));println!()))
>
> I wrote it mainly for testing the support for overloading in ATS.
>
> Here is the source file:
>
>
> https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/MISC/queens_comb.dats
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"ats-lang-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ats-lang-users/ca41ffb8-228c-4358-946f-d060d5617ed1%40googlegroups.com.

Reply via email to