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 51 52 53 54 55 56 57
| :- use_module(library(lambda)).
petit_groupe(1, 5).
petit_groupe(2, 2).
petit_groupe(3, 3).
petit_groupe(4, 4).
petit_groupe(5, 5).
petit_groupe(6, 8).
petit_groupe(7, 2).
petit_groupe(8, 6).
petit_groupe(9, 5).
petit_groupe(10, 6).
petit_groupe(11, 4).
petit_groupe(12, 3).
petit_groupe(13, 5).
petit_groupe(14, 7).
petit_groupe(15, 5).
petit_groupe(16, 4).
petit_groupe(17, 3).
petit_groupe(18, 7).
petit_groupe(19, 3).
petit_groupe(20, 4).
petit_groupe(21, 7).
petit_groupe(22, 5).
petit_groupe(23, 4).
petit_groupe(24, 3).
petit_groupe(25, 7).
petit_groupe(26, 3).
sylvaner :-
numlist(1, 26, NL),
cree_sous_liste(15, 8, NL, [], Lst),
maplist(affiche_sous_liste, Lst).
affiche_sous_liste(L) :-
forall(member(X, L), format('~w ', [X])),
foldl(\X^Y^Z^(petit_groupe(X, V),
Z is Y+V),
L, 0, TT),
format(': ~w ~n', [TT]).
cree_sous_liste(_, 0, [], SL, SL).
cree_sous_liste(Mid, N, NL, CSL, SL) :-
cree_une_liste(Mid, NL, NL1, 0, [], Lst),
N1 is N - 1,
cree_sous_liste(Mid, N1, NL1, [Lst | CSL], SL).
cree_une_liste(Mid, NL, NL1, CTT, CLst, Lst) :-
select(V, NL, NL2),
petit_groupe(V, Nb),
TT is Nb + CTT,
( (TT >= Mid - 1, TT =< Mid + 1)
-> NL1 = NL2,
Lst = [V | CLst]
; TT =< Mid - 1,
cree_une_liste(Mid, NL2, NL1, TT, [V | CLst], Lst)). |
Partager