-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathqueens_comb.dats
42 lines (39 loc) · 1.04 KB
/
queens_comb.dats
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
(*
//
// HX-2016-07-02
// A program to solve the 8-queens problem
// based on lazy evaluation
//
*)
(* ****** ****** *)
//
(*
##myatsccdef=\
patsopt --constraint-ignore --dynamic $1 | \
tcc -run -DATS_MEMALLOC_LIBC -I${PATSHOME} -I${PATSHOME}/ccomp/runtime -
*)
//
(* ****** ****** *)
//
#include
"share/atspre_define.hats"
#include
"share/atspre_staload.hats"
//
#include
"share/HATS/atspre_staload_libats_ML.hats"
//
(* ****** ****** *)
macdef sing = stream_vt_make_sing
macdef intrange = list_make_intrange
overload * with cross_stream_vt_list_vt
(* ****** ****** *)
//
#define N 8
//
implement
main0((*void*)) =
((fix f(n:int):stream_vt(list0(int))=>if(n)>0then((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(TYPE{list0(int)})(lam(xsy)=>let val (xs,y)=xsy 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!()))
//
(* ****** ****** *)
(* end of [queens_comb] *)