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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help

Status
Not open for further replies.

Knurzalfump

Technical User
Mar 5, 2003
1
DE
my problem in prolog:
need a list of all numbers, that divide another number
[1,2,3,6] for 6 and so on.
 
Hello,
i made this one for you. Works well for me.

dividers(Number,List) :- dv(number,1,List).

dv(Number,Number,[Number]).
dv(Number,Akk,[Akk|Tail]) :-
Number > Akk,
0 is NUmber mod Akk,
AkkNew is Akk+1,
dv(Number,AkkNew,Tail).
dv(Number,Akk,List) :-
Number > Akk,
not(0 is Number mod Akk).
AkkNew is Akk+1,
dv(Number,AkkNew,List).


you can run it like this

dividers(6,Result).

and u will get Result=[1,2,3,6]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top