-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_hhprolog_node.js
57 lines (48 loc) · 1 KB
/
test_hhprolog_node.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
* test hhprolog.js in nodeJS
*
* Author: Carlo Capelli
* License: MIT
* Copyright (c) 2017,2018 Carlo Capelli
*/
var m = require('./hhprolog-es6.js')
const queens = `
place_queen I _0 _1 _2 and
_0 holds list I _3 and
_1 holds list I _4 and
_2 holds list I _5 .
place_queen I _0 _1 _2 and
_0 holds list _3 Cs and
_1 holds list _4 Us and
_2 holds list _5 Ds
if
place_queen I Cs Us Ds .
place_queens nil _0 _1 _2 .
place_queens _0 Cs Us _1 and
_0 holds list I Is and
_1 holds list _2 Ds
if
place_queens Is Cs _3 Ds and
_3 holds list _4 Us and
place_queen I Cs Us Ds .
gen_places nil nil .
gen_places _0 _1 and
_0 holds list _2 Qs and
_1 holds list _3 Ps
if
gen_places Qs Ps .
qs Qs Ps
if
gen_places Qs Ps and
place_queens Qs Ps _0 _1 .
goal Ps
if
qs _0 Ps and
_0 lists 0 1 2 3 4 5 6 7 8 9 10 11 .
`
const prog = new m.Prog(queens)
prog.ppCode()
m.trace('RUN')
const t0 = Date.now()
prog.run()
m.trace('elapsed secs', (Date.now() - t0) / 1000)