summaryrefslogtreecommitdiff
path: root/prolog/problems/trees/maxt_2/common.py
blob: b1cdb392e6316f1186e68358c70a2704383a0a79 (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
# coding=utf-8

id = 143
number = 50
visible = False
facts = None

solution = '''\
max143([X], X).
max143([H|T], Max):-
  max143(T, Max1),
  ( H > Max1, Max is H
    ;
    H =< Max1, Max is Max1 ).

maxT(t(E), E) :- !.
maxT(Tree, Max) :-
  Tree =.. [t, E|SubTrees],
  getMaxElems(SubTrees, MaxElems),
  max143([E|MaxElems], Max).

getMaxElems([], []).
getMaxElems([SubTree|SubTrees], [MaxElem|MaxElems]) :-
  maxT(SubTree, MaxElem),
  getMaxElems(SubTrees, MaxElems).
'''