gurpreet:- write('Enter number'),nl,read(X),Z is X mod 10, X1 is X/10, R is (Z*10)+(X1),write(R),!.
CLOUD COMPUTING | DATA MINING | ARTIFICIAL INTELLIGENCE | APPLICATION PROGRAMMING IN C/C++/Java
Wednesday, May 4, 2011
PROGRAM TO REVERSE A NUMBER IN PROLOG
gurpreet:- write('Enter number'),nl,read(X),Z is X mod 10, X1 is X/10, R is (Z*10)+(X1),write(R),!.
PROGRAM TO REVERSE A NUMBER IN PROLOG
gurpreet:- write('Enter number'),nl,read(X),Z is X mod 10, X1 is X/10, R is (Z*10)+(X1),write(R),!.
PARSER IN PROLOG
% IT WORKS FOR THE PARTICULAR SENTENCE " The, dog, barked , at ,the,cow" (give it in list).
% you can write in your own facts to implements the rules given by me.
sentence(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).
% you can write in your own facts to implements the rules given by me.
sentence(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 PROLOG
fibonacci(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.
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 LISTS
int([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 IMPLEMENTATION
towerofhanoi(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 LIST
reverse_garry([],A,A).
reverse_garry([A|B],Z,W):- reverse_garry(B,[A|Z],W).
Subscribe to:
Posts (Atom)