summaryrefslogtreecommitdiff
path: root/lang/prolog/1.8.7/src/sum
blob: e1b6b1324a5e16aef9a4d9717c4636cbbc61c26a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
suc (0, 1). suc (1, 2). suc (2, 3). suc (3, 4). suc (4, 5). 
suc (5, 6). suc (6, 7). suc (7, 8). suc (8, 9). 
sum (0, X, X). 
sum (X, Y, Z):-  suc (V, X), sum (V, Y, W), suc (W, Z). 
plus (X, [0,0], X):-  !. 
plus (X, Y, Z):-  plus one (V, Y), plus (X, V, W), !, plus one (W, Z). 
plus one ([X, Y], [V, W]):-  suc (Y, W), X = V, !; 
                             Y = 9, suc (X, V), W = 0. 
treereverse (X,Y):-  rev (X,Y), !; rev (Y,X), !. 
rev ([], []). 
rev ([X|Y], Z):-  X <> [H|T], rev (Y, W), !, append (W, [X], Z); 
                  rev (X, V), rev (Y, W), !, append (W, [V], Z).