English 中文(简体)
前言
原标题:Prolog powerset predicate [closed]
问题回答

既然你使用SICStus Prolog,你可以使用图书馆的次数(+Sequence, ?SubSequence),“当SubSequence is a subsequence of Sequence, but may be Sequence”,(摘自手册

      ?- setof(X, subseq0([a,b,c],X), Xs).
      Xs = [[],[a],[a,b],[a,b,c],[a,c],[b],[b,c],[c]]

如果不允许你使用图书馆,那么你可以执行(<>gusbro)。

powerset([], []).
powerset([H|T], P) :- powerset(T,P).
powerset([H|T], [H|P]) :- powerset(T,P).




相关问题
Prolog : Learning by example

I am trying to learn a little bit about swi-prolog (beyond the basic, useless programs). Can anyone explain (perhaps in pseudocode) what this sudoku solver and the related functions are doing? If ...

Working with lists in Prolog

First off let me state that this is part of a class exercise given as homework. But, the entire assignment is much more involved than the subject of this question. So.. I am searching through two ...

SWI-Prolog conditional statements

I m trying to write a function that will test to see if the word hello is contained in a list. If it is contained, i don t want it to say "true", i want it to say : "yes, the word hello is contained ...

prolog cut off in method

I have a question I would like to ask you something about a code snippet: insert_pq(State, [], [State]) :- !. insert_pq(State, [H|Tail], [State, H|Tail]) :- precedes(State, H). insert_pq(State, [...

Max out of values defined by prolog clauses

I know how to iterate over lists in Prolog to find the maximum, but what if each thing is a separate clause? For example if I had a bunch of felines and their ages, how would I find the oldest kitty? ...

热门标签