Hello all,
I'm new to this prolog business, and it's giving me real grief!
This is the predicate I would like to write:
Given a number X, find all possible lists of three integers that add up to X, ie
addsTo(+X,-L).
example: X = 3.
i need to generate
[0,0,3]
[0,1,2]
[1,1,1]
I've written some predicates I think might be useful...I have one that will count from 0 to X, so I can generate a list of possible values for each of the three elements in the final list. i've written one that will sum the elements of a list. I just don't know how to get through all the possibilities.
Any help would be greatly appreciated
thanks
~G
I'm new to this prolog business, and it's giving me real grief!
This is the predicate I would like to write:
Given a number X, find all possible lists of three integers that add up to X, ie
addsTo(+X,-L).
example: X = 3.
i need to generate
[0,0,3]
[0,1,2]
[1,1,1]
I've written some predicates I think might be useful...I have one that will count from 0 to X, so I can generate a list of possible values for each of the three elements in the final list. i've written one that will sum the elements of a list. I just don't know how to get through all the possibilities.
Any help would be greatly appreciated
thanks
~G