Assign 3

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

question_1(X):% checks whether the input entered by

append(['a', 'b', 'c', 'd', 'e', 'f',


', 'p', 'q', 'r', 's', 't', 'u', 'v',
append(['A', 'B', 'C', 'D', 'E', 'F',
', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
l1),
member(X, l1).

the user is an
'g', 'h', 'i',
'w', 'x', 'y',
'G', 'H', 'I',
'W', 'X', 'Y',

alphabet or not.
'j', 'k', 'l', 'm', 'n', 'o
'z'], [], l),
'J', 'K', 'L', 'M', 'N', 'O
'Z'], l,

% path in the college is ../Downloads/eats.csv.


question_2_csv_read_file:retractall(table(_,_,_)),
csv_read_file('assignments/aiml/eats.csv', Rows, [functor(table), arity(3)]),
maplist(assert, Rows).
question_2_A(X):% the people who eat dal and rice.
table(X, dal, rice).
question_2_B(N):% the people who eat pasta.
findall(X, table(X, pasta, Y); table(X, Y, pasta), L), length(L, N).
question_2_C:% checking whether burritos exist in the list.
findall(Y, table(X, Y, Z); table(X, Z, Y), L),
member('burritos', L).
%% the graph structure for execution of dfs is as follows:%%
'A'--%%
/ \ \
%%
/
\ \
%%
'B'
'C' 'E'
%%
/ \
\
\
%%
/
\
\
\
%%
'D' 'F'
'G' |
%%
^
%%
|
|
%%
-----------%% all edges are going down wards except the edge from 'E' to 'F'
%% here the assumption is that 'A' is the root.
graph(a,
graph(a,
graph(a,
graph(b,
graph(b,
graph(c,
graph(e,

b).
c).
e).
d).
f).
g).
f).

% initialization
initialization_dfs(L):append([a], [], L).
% declaring membership criterion for checking whether an element is a member of
the visited nodes.
checking_membership(A, B, C):-

member(A,C), not(member(A, B)).


splitList([H|T], H, T).
dfs(L, A):splitList(A, H, T),
write('head of the list:-'),
write(H),
write('\n'),
findall(X, graph(H, X), S),
findall(W, checking_membership(W, L, S) , Y),
write('edges of the graph unexplored:-'),
write(Y),
write('\n'),
append(Y, T, N),
append([H], L, K),
write('visited nodes after this step:- '),
write(K),
write('\n'),
write("stack's elements are:- "),
write(N),
write('\n'),
write('\n'),
dfs(K, N).
dfs(_, []).
question_3:initialization_dfs(T),
dfs([], T).

You might also like