Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
0 of .
Results for:
P. 1
Prolog Programming

# Prolog Programming

Ratings: (0)|Views: 320 |Likes:
Check out on
garrybtech1@blogspot.com
Check out on
garrybtech1@blogspot.com

Categories:Types, School Work

### Availability:

See more
See less

10/01/2014

pdf

text

original

.........most common prolog programs are on.......... % PROGRAM TO REVERSE A NUMBER IN PROLOGgurpreet:- write('Enter number'),nl,read(X),Z is X mod 10, X1 is X/10, R is (Z*10)+(X1),write(R),!.% PARSER IN PROLOGsentence(A,C):-nounphrase(A,B),verbphrase(B,C).nounphrase(A,C):-article(A,B),noun(B,C).verbphrase(A,C):-verb(A,B),prepositionphrase(B,C).prepositionphrase(A,C):-preposition(A,B),nounphrase(B,C).preposition([atX],X).article([aX],X).article([theX],X).noun([dogX],X).noun([cowX],X).noun([moonX],X).verb([barkedX],X).verb([wrinkedX],X).% FIBONACCI SERIES IN PROLOGfibonacci(0,1).fibonacci(1,1).fibonacci(A,B) :- A > 1, A1 is A - 1, A2 is A - 2, fibonacci(A1,B1), fibonacciA2,B2), B is B1 + B2% PROGRAM FOR THE INTERSECTION OF TWO LISTSint([XY],Z,[XD]):-member(X,Z),int(Y,Z,D).int([XY],Z,D):- \+member(X,Z),int(Y,Z,D).int([],Z,[]).% TOWER OF HANOI PROLOG IMPLEMENTATIONtowerofhanoi(1,X,Y,_):- write(' move the disk from'),write(X),write('TO') ,write(Y),nl.towerofhanoi(N,X,Y,Z):- N >1, M is N-1, towerofhanoi(M , X, Z,Y),towerofhanoi(1,X,Y,_),towerofhanoi(M,Z,Y,X).

% PROGRAM TO REVERSE THE LISTreverse_garry([],A,A).reverse_garry([AB],Z,W):- reverse_garry(B,[AZ],W).% PROGRAM TO FIND THE PRODUCT OF ALL THE ELEMENTS IN LISTpro([],1).pro([HT],P):- pro(T,HT), P is H*HT.% PROGRAM TO SEE THE PERMUTATIONS IN LIST ENTEREDgarry(X,[XR],R).garry(X,[CR],[CS]):- garry(X,R,S).permu_garry([],[]).permu_garry(Z,[AB]):- perm(B,W), garry(A,Z,W).% A PROLOG PROGRAM TO CALCULATE MAXIMUM AND MINIMUM IN LISTmaxlist([A],A).maxlist([ALIST],MAX):- maxlist(LIST,MAX0),(A>=MAX0, MAX=A ; A<MAX0, MAX=MAX0).minlist([A],A).minlist([ALIST],MIN):- minlist(LIST,MIN0),(A=<MIN0, MIN=A ; A>MIN0, MIN=MIN0).% PROGRAM TO CALCULATE ELEMENTS IN LISTcallist([],0).callist([_T],X):- callist(T,X1), X is X1+1.% PROGRAM TO CALCULATE UNION OF 2 LISTSgurpreet_union([XY],Z,W) :- member(X,Z), gurpreet_union(Y,Z,W).gurpreet_union([XY],Z,[XW]) :- \+ member(X,Z), gurpreet_union(Y,Z,W).gurpreet_union([],Z,Z).% PROGRAM TO PRINT Kth ELEMENT FROM LISTextractk(X,[X_],1).extractk(X,[_T],K):- K>1,K1 is K-1, extractk(T,X,K1).% PROGRAM TO PRINT NUMBERS IN DESCENDING ORDERprint1(0):-write('0'),!.print1(X):-write(X),nl,N is X-1,print1(N).% PROGRAM TO ADD 10 ELEMENTS OF LIST% IT WILL WORK FOR 10 ELEMNTS AND TO MAKE IT WORK FOR ANY NUMBER PLACE A %NUMBERIN PLACE OF 10 WHATR U WANT.addlist(_,0,0).