Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

generate possible lists

Status
Not open for further replies.

cainiskey

Programmer
Joined
Mar 21, 2007
Messages
1
Location
CA
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

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top