Prolog program for prerequisite and registration of courses

% Implement the predicate can_register(Student, Course), % where can_register(S,C) is true iff S is a student who has % passed or waived all of the prerequisites of course C. % For example, the prereqs of csc529 are csc330 and csc350. % Suppose nancy passed csc330 and csc350: she can register for 529. % Suppose dilbert […]

Read More

Prolog program to process finite state automat (2**2n)(b**m)

% The language: (a**2n)(b**m), for n>=1, m>=0. For example, % aa, aaaa, aab, aaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbb. % Define the language (a**2n)(b**m) with the predicates % final, trans, and/or silent final(s2). final(s3). trans(start,a,s1). trans(s1,a,s2). trans(s2,a,s1). trans(s2,b,s3). trans(s3,b,s2). accepts(State,[]) :- final(State). accepts(State,[X|Rest]) :- trans(State,X,State1), accepts(State1,Rest). […]

Read More

Prolog program for calculating weight of animals

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Define allweight(L, W), such that it is true iff % W is the total weight of all the animals in list L. % Assume that the weight of the animals is stored in % predicates of the form weight(X, N). weight(bird, 1). weight(dog, 20). weight(bear, 300). weight(elephant, 1000). allweight([],0). allweight([X],W):- weight(X,W). allweight([H|T],W):- allweight(T,Sum1),weight(H,Sum2),W […]

Read More