I'm trying to write a definite clause grammar that outputs the partitions of a number. For example ?- w(3,L,[])
should output :
[1,1,1]
[2,1]
[1,2]
[3]
My code looks as follows:
w(PosNumber) --> {partition(PosNumber,L)},L.
partition(0,[]).
partition(PosNumber,[X|List]):-
between(1,PosNumber,X),
Y is (PosNumber-X),
partition(Y,List).
My partition function seems to work fine but I'm not sure how to correctly instantiate 'w'. Sorry if this is really basic, I'm very new to prolog.