-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch03.pl
77 lines (71 loc) · 1.86 KB
/
ch03.pl
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
:- use_module(library(clpfd)).
hailstone(N, N).
hailstone(N0, N) :-
N0 #= 2*N1,
hailstone(N1, N).
hailstone(N0, N) :-
N0 #= 2*_ + 1,
N1 #= 3*N0 + 1,
hailstone(N1, N).
% ?- hailstone(3,N).
% N = 3 ;
% N = 10 ;
% N = 5 ;
% N = 16 ;
% N = 8 ;
% N = 4 ;
% N = 2 ;
% N = 1 .
% ?- trace.
% true.
% [trace] ?- hailstone(3,N).
% Call: (10) hailstone(3, _74328) ? creep
% Exit: (10) hailstone(3, 3) ? creep
% N = 3 ;
% Redo: (10) hailstone(3, _74328) ? creep
% Call: (11) integer(3) ? creep
% Exit: (11) integer(3) ? creep
% Call: (11) _80370=3 ? creep
% Exit: (11) 3=3 ? creep
% Call: (11) clpfd:clpfd_equal(3, 2*_81996) ? creep
% Fail: (11) clpfd:clpfd_equal(3, 2*_81996) ? creep
% Redo: (10) hailstone(3, _74328) ? creep
% Call: (11) integer(3) ? creep
% Exit: (11) integer(3) ? creep
% Call: (11) _86064=3 ? creep
% Exit: (11) 3=3 ? creep
% Call: (11) clpfd:clpfd_equal(3, 2*_87696+1) ? creep
% Exit: (11) clpfd:clpfd_equal(3, 2*1+1) ? creep
% Call: (11) integer(3) ? creep
% Exit: (11) integer(3) ? creep
% Call: (11) _91384 is 3*3+1 ? creep
% Exit: (11) 10 is 3*3+1 ? creep
% Call: (11) hailstone(10, _74328) ? creep
% Exit: (11) hailstone(10, 10) ? creep
% Exit: (10) hailstone(3, 10) ? creep
% N = 10 ;
% Redo: (11) hailstone(10, _74328) ? creep
% Call: (12) integer(10) ? creep
% Exit: (12) integer(10) ? creep
% Call: (12) _99388=10 ? creep
% Exit: (12) 10=10 ? creep
% Call: (12) clpfd:clpfd_equal(10, 2*_101014) ? creep
% Exit: (12) clpfd:clpfd_equal(10, 2*5) ? creep
% Call: (12) hailstone(5, _74328) ? creep
% Exit: (12) hailstone(5, 5) ? creep
% Exit: (11) hailstone(10, 5) ? creep
% Exit: (10) hailstone(3, 5) ? creep
% N = 5 .
% [trace] ?- nodebug.
% true.
% ?- hailstone(1,N).
% N = 1 ;
% N = 4 ;
% N = 2 ;
% N = 1 ;
% N = 4 ;
% N = 2 ;
% N = 1 ;
% N = 4 ;
% N = 2 ;
% N = 1 .