### Tutorial 2 of Artificial Intelligence

1.     Write program to display digits 1 to 9 also in reverse order using recursion to understand winding down.

predicates
count(integer)
go

clauses
go:-
write("Winding Down"),nl,
count(1),
write("1"),nl.

count(9):-
write("9"),nl,
write("Now unwinding"),nl.

count(N):-
write(N),nl,
A = N+1,
count(A),
write(A),nl.

2.    Write a program to perform login operation using:
i.                   Recursion
ii.                 repeat predicate

i.using Recursion

predicates
getip(symbol,symbol)
go

clauses
getip(U,P):-

go:-
getip(_,_),

go:-

Repeat predicate

predicates
getip(symbol,symbol)
go
repeat

clauses
repeat:-
go.

getip(U,P):-

go:-
getip(_,_),

go:-
repeat.

3.     Write a program to perform  such that user is allowed to input   username and password maximum three times.

predicates
getip(symbol,symbol)
count(integer)

clauses
count(3).

count(N):-
getip(_,_),

count(N):-
A = N+1,
count(A).

getip(U,P):-

4.     Define predicate location(City,State). Write a program such that it displays all the locations except city “Delhi”. Using:
i.                   not predicate
ii.                 Combination of cut and fail.
predicates
find
checkcity(string)
location(string,string)

clauses
location("Jaypur","Rajsthan").
location("Delhi","UP").
location("Rajkot","Gujarat").
location("Bhopal","MP").

find:-
writef("%-10%6","CITY","STATE"),nl,
writef("----------------"),nl,
fail.

find:-
location(C,S),
checkcity(C),
writef("%-10%5",C,S),nl,
fail.
find.
checkcity("Delhi"):-
!,fail.
checkcity(_).