summaryrefslogtreecommitdiff
path: root/prolog/problems/trees/maxt_2/common.py
blob: 280cb255a59bec0d3ea3ea2ccabc1a4c7b0c102d (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 = True
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).
'''