Informatiker Board (http://www.informatikerboard.de/board/index.php)
- Themengebiete (http://www.informatikerboard.de/board/board.php?boardid=1)
--- Praktische Informatik (http://www.informatikerboard.de/board/board.php?boardid=6)
---- Algorithmen (http://www.informatikerboard.de/board/board.php?boardid=17)
----- Prolog - Listen (http://www.informatikerboard.de/board/thread.php?threadid=2563)


Geschrieben von Schattenklinge am 13.11.2015 um 14:40:

  Prolog - Listen

Hallo,

ich habe hier ein Algo für eine Listenoperation, nämlich eine Liste1 ohne Liste2. Zum Beispiel:
List1 = 8,9,10
List2 = 9
Dann kriege ich die Liste3 := 8,10 raus.

substract([],_,[]).
substract([X|Xs],Ys,[X|Zs]) :- not(member(X,Ys)), substract(Xs,Ys,Zs).
substract([_|Xs],Ys,Zs) :- substract(Xs,Ys,Zs).

Das Problem hier ist: Ich versteh diesen Code nicht. Was passiert hier genau, kann mir das jemand erklären? Bei leerer Liste ist mir das klar.

Danke schonmal


Forensoftware: Burning Board, entwickelt von WoltLab GmbH