Różnice

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

Odnośnik do tego porównania

pl:prolog:pllib:dutch_flag [2019/06/27 15:50]
pl:prolog:pllib:dutch_flag [2019/06/27 15:50] (aktualna)
Linia 1: Linia 1:
 +====== Dutch flag ======
 +{{tag>​problem_solving}}
 +===== Description =====
 +A solution to the Dutch flag problem
 +
 +**Source**: ​ The Art of Prolog
 +===== Download =====
 +Program source code: {{dutch_flag.pl}}
 +===== Listing =====
 +<code prolog>
 +/*
 +    dutch(Xs,​RedsWhitesBlues) :-
 + RedsWhitesBlues is a list of elements of Xs ordered
 + by color: red, then white, then blue.
 +*/
 +
 + dutch(Xs,​RedsWhitesBlues) :-
 + distribute(Xs,​Reds,​Whites,​Blues),​
 + append(Whites,​Blues,​WhitesBlues),​
 + append(Reds,​WhitesBlues,​RedsWhitesBlues).
 +
 +/*
 +    distribute(Xs,​Reds,​Whites,​Blues) :-
 + Reds, Whites, and Blues are the lists of red, white,
 + and blue elements in Xs, respectively.
 +*/
 +
 + distribute([red(X)|Xs],​[red(X)|Reds],​Whites,​Blues) :-
 + distribute(Xs,​Reds,​Whites,​Blues).
 + distribute([white(X)|Xs],​Reds,​[white(X)|Whites],​Blues) :-
 + distribute(Xs,​Reds,​Whites,​Blues).
 + distribute([blue(X)|Xs],​Reds,​Whites,​[blue(X)|Blues]) :-
 + distribute(Xs,​Reds,​Whites,​Blues).
 + distribute([],​[],​[],​[]).
 +
 +% Program 15.5: A solution to the Dutch flag problem
 +
 +</​code>​
 +===== Comments =====
  
pl/prolog/pllib/dutch_flag.txt · ostatnio zmienione: 2019/06/27 15:50 (edycja zewnętrzna)
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0