summaryrefslogtreecommitdiff
path: root/prolog/problems/dcg/number_3/common.py
blob: 253c59c6d139a256d14157de560850c02fcffaf5 (plain)
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
id = 167
number = 74
visible = False
facts = None

solution = '''\
number(Num) --> dig167(N), { l2n167(N,Num) }.
number(Num) --> nonzero167([N]), numb_next167(N1), { l2n167([N|N1],Num) }.

zero167([0]) --> [0].
nonzero167([N]) --> [N], {memb167(N, [1,2,3,4,5,6,7,8,9])}.

dig167(N) --> zero167(N).
dig167(N) --> nonzero167(N).
numb_next167(N) --> dig167(N).
numb_next167([N|N1]) --> dig167([N]), numb_next167(N1).

memb167(X, [X|_]).
memb167(X, [_|T]) :-
    memb167(X, T).

l2n167(L, N) :-
    l2n167(L, 0, N).
l2n167([N], S, R) :-
    R is S*10+N.
l2n167([H|T], S, N) :-
    S1 is S*10+H,
    l2n167(T, S1, N).
'''