-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathch13.pl
50 lines (39 loc) · 785 Bytes
/
ch13.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
:- use_module(library(clpfd)).
:- op(920,fy, *).
*_.
wrong_list_length([], 0).
wrong_list_length([_|Ls], N) :-
N #> 0,
N #= N0 + 2,
wrong_list_length(Ls, N0).
% ?- wrong_list_length([_], 1).
% false.
% ?- wrong_list_length([_], 2).
% true.
% wrong_list_length([], 0).
% wrong_list_length([_|Ls], N) :-
% N #> 0,
% * N #= N0 + 2,
% wrong_list_length(Ls, N0).
% % ?- wrong_list_length([_], 1).
% % true.
correct_list_length([], 0).
correct_list_length([_|Ls], N) :-
N #> 0,
N #= N0 + 1,
correct_list_length(Ls, N0).
% ?- wrong_list_length([_], 1).
% false.
% ?- correct_list_length([_], 1).
% true.
% ?- correct_list_length(Ls, L).
% Ls = [],
% L = 0 ;
% Ls = [_],
% L = 1 ;
% Ls = [_, _],
% L = 2 ;
% Ls = [_, _, _],
% L = 3 ;
% Ls = [_, _, _, _],
% L = 4 .