AI All Practical
AI All Practical
Bhargav Likes
Node JS . Bhargav Likes Java.
Question : Bargar is a Food. Sandwich is Food. Food is Pizza. Sandwich is Lunch. Pizza is Lunch.
Question : Dhruv Teach IS. Charli Studies Java. Aliva Studies Java. Jeck Studies AI. Kirtan
Studies DC.Kirtan Teach Java. Akshar Teach AI. Akshar Teach DC.
Condition: X is a Professor of Y. If X teaches C and Y studies C. What does Charli Studies? Who
are the Student of Kirtan ?
Maximum-Minimum Number:
Cut :
Fail:
Arithmetic Operators :
Grade :
Tower of Hanoi :
Arithmetic Operator
Practical:-4
- Program to define the relation list(item, list) so that the item is the last element of thelist
using concatenate.
PRACTICAL-6
- Code for Prolog program to check whether a given word is a palindrome or not in
Artificial Intelligence.
- Code for Prolog program to check whether a given list is palindrome or not in Artificial
Intelligence.
- Code for Prolog program to compare characters, strings and also reverse string in
Artificial Intelligence.
PRACTICAL-7
predicates
male(symbol)
female(symbol)
father(symbol, symbol)
husband(symbol, symbol)
brother(symbol, symbol)
sister(symbol, symbol)
listbrothers(symbol)
listsisters(symbol)
mother(symbol, symbol)
grandfather(symbol)
grandmother(symbol)
uncle(symbol)
aunt(symbol)
cousin(symbol)
listgrandsons(symbol)
listgranddaughters(symbol)
printmenu
action(integer)
repeat
clauses
male(dashrath).
male(ram).
male(laxman).
male(bharat).
male(luv).
male(kush).
male(son_of_laxman).
female(kaushalya).
female(sita).
female(urmila).
female(daughter_of_dashrath).
father(dashrath, ram).
father(dashrath, laxman).
father(dashrath, bharat).
father(ram, luv).
father(ram, kush).
father(laxman, son_of_laxman).
father(dashrath, daughter_of_dashrath).
husband(dashrath, kaushalya).
husband(ram, sita).
husband(laxman, urmila).
mother(X, Y) :-
husband(Z, X),
father(Z, Y).
brother(X, Y) :-
father(Z, X),
father(Z, Y),
X \== Y,
male(X).
sister(X, Y) :-
father(Z, X),
father(Z, Y),
X \== Y,
female(X).
listbrothers(X) :-
brother(Z, X),
write(Z), nl,
fail.
listsisters(X) :-
sister(Z, X),
write(Z), nl,
fail.
grandfather(X) :-
father(Y, Z),
father(Z, X),
fail.
grandmother(X) :-
husband(Z, X),
father(Z, V),
father(V, Y),
fail.
listgrandsons(X) :-
father(X, Z),
father(Z, Y),
male(Y),
write(Y), nl,
fail.
listgrandsons(X) :-
husband(Y, X),
father(Y, V),
father(V, Z),
male(Z),
write(Z), nl,
fail.
listgranddaughters(X) :-
father(X, Z),
father(Z, Y),
female(Y),
write(Y), nl,
fail.
listgranddaughters(X) :-
husband(Y, X),
father(Y, V),
father(V, Z),
female(Z),
write(Z), nl,
fail.
uncle(X) :-
brother(Z, Y),
father(Z, X),
male(Y),
write(Y), nl,
fail.
aunt(X) :-
husband(Z, Y),
brother(Z, V),
father(V, X),
write(Y), nl,
fail.
cousin(X) :-
father(Z, X),
father(V, Y),
Z \== V,
brother(V, Z),
write(Y), nl.
repeat.
repeat :- repeat.
action(1) :-
readln(X),
father(Z, X),
write(Z), nl,
fail.
action(2) :-
readln(X),
action(3) :-
readln(X),
action(4) :-
readln(X),
action(5) :-
readln(X),
action(6) :-
readln(X),
action(7) :-
readln(X),
action(8) :-
readln(X),
aunt(X), nl , fail.
action(9) :-
readln(X),
write("\nCousins of "), write(X), write(" are:\n"),
action(0).
printmenu :-
repeat,
write("0. Exit\n"),
readInt(Choice),
goal
printmenu.
Output –
-Family Tree
¦0. exit¦
¦¦
¦¦
¦¦
¦0. exit¦
¦¦
¦¦
¦laxman ¦
¦bharat ¦
¦¦
¦0. exit¦
¦¦
¦Enter name of person whose grandsons are to be found : dashrath ¦
¦¦
¦luv ¦
¦kush ¦
¦son_of_laxman ¦
¦¦
¦0. exit¦
¦¦
¦¦
¦laxman ¦
¦bharat ¦
¦¦
¦0. exit¦
¦¦
¦¦
Write a program to implement BFS (for 8 puzzle problem or Water Jug problem
or any AI search problem).
domains
predicates
member(Node, ExtendedPath)
goal(Node)
clauses
conc([], L, L).
goal(Node) :-
Output –
PRACTICAL-9
Write a program to implement DFS (for 8 puzzle problem or Water Jug problem
or any AI search problem).
PRACTICAL-10
%%%
%%%
function(State,D,F) :- h_function(State,H), F is D + H.
insert_all(R,Open2,Open3).
insert_all([],Open,Open).
insert(B,Open,Open) :- repeat_node(B,Open), !.
insert(B,[C|R],[B,C|R]) :- cheaper(B,C), ! .
insert(B,[B1|R],[B1|S]) :- insert(B,R,S),!.
insert(B,[],[B]).repeat_node(P#_#_#_, [P#_#_#_|_]).
Predicates
startup(integer)
Database
unsortedDatabase(string,integer)
sortedDatabase(string)
Clauses
startup(0).
readln(Name),
str_len(Name,Len),
asserta(unsortedDatabase(Name,Len)),
TempNum = Num - 1,
startup(TempNum).
writing:-sortedDatabase(Name),
write(Name),nl,fail. writing.
find(Index):- unsortedDatabase(Name,Index),
assertz(sortedDatabase(Name)),
retract(unsortedDatabase(Name,Index)),
find(Index).
startup(NumRead).
Goal
Clearwindow,
makewindow(1,2,3,"String Operations",0,0,25,80),
reading,!,find(1),
writing,delete.
Output –