Samet Kilictas’s Blog

Tag: fibonacci

Example Code #3 – Basics in Prolog

by Samet Kilictas on Dec.28, 2008, under Programming, Prolog

1- Parent relation between rex, doggie and goldie

dog(rex).
dog(X):-parent(X,Y).
parent(goldie,rex).
parent(jack,rex).

Query -> ?dog(goldie) : YES
Query -> ?dog(jack) : YES

2- Sister relation

sister(X,Y):-girl(X),girl(Y),parent(X,Z),parent(Y,Z).
parent(sara,Maria).
parent(lili,Maria).
girl(lili).
girl(maria).

Query -> ?sister(lili,maria) : NO

3- Finds factorial of numbers

1!: 1 , 2!: 2×1, 3!: 3×2x1
Here you can see that we are able to say 3!: 3×2! instead of 3!:3×2x1 . Since i know what is 1! and 0! therefore i have limitation points for my program.

fact(0,1):-!.
fact(1,1):-!.
fact(N,F,F1) :- N1 is N-1, fact(N1,F1), F is N * F1.

(continue reading…)

VN:F [1.0.6_327]
Rating: 0.0/10 (0 votes cast)
Leave a Comment :, , , , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...