# Różnice

Różnice między wybraną wersją a wersją aktualną.

 — pl:prolog:pllib:dutch_flag_2 [2019/06/27 15:50] (aktualna) Linia 1: Linia 1: + ====== Dutch flag 2 ====== + {{tag>​problem_solving}} + ===== Description ===== + Dutch Flag with difference-lists. + + **Source**: ​ The Art of Prolog + ===== Download ===== + Program source code: {{dutch_flag_2.pl}} + ===== Listing ===== + + /​*  ​ + ​dutch(Xs,​RedsWhitesBlues) :- + RedsWhitesBlues is a list of elements of Xs ordered ​ + by color: red, then white, then blue. + */ + :- op(40,​xfx,​\). + + dutch(Xs,​RedsWhitesBlues) :- + distribute_dls(Xs,​RedsWhitesBlues\WhitesBlues,​ + WhitesBlues\Blues,​Blues\[]). + + /* + distribute_dls(Xs,​Reds,​Whites,​Blues) :- + Reds,​Whites,​Blues are difference-lists of red, white, + and blue elements in Xs, respectively. + */ + + distribute_dls([red(X)|Xs],​[red(X)|Reds]\Reds1,​Whites,​Blues) :- + distribute_dls(Xs,​Reds\Reds1,​Whites,​Blues). + distribute_dls([white(X)|Xs],​Reds,​[white(X)|Whites]\Whites1,​Blues) :- + distribute_dls(Xs,​Reds,​Whites\Whites1,​Blues). + distribute_dls([blue(X)|Xs],​Reds,​Whites,​[blue(X)|Blues]\Blues1) :- + distribute_dls(Xs,​Reds,​Whites,​Blues\Blues1). + distribute_dls([],​Reds\Reds,​Whites\Whites,​Blues\Blues). + + % Program 15.6: Dutch Flag with difference-lists. + ​ + ===== Comments =====
pl/prolog/pllib/dutch_flag_2.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)