Jump to content


Need Help with a little Prolog Exercise


2 replies to this topic

#1 polimerizar

    New Member

  • Members
  • Pip
  • 2 posts

Posted 24 March 2010 - 06:40 AM

Hi everybody!

I recently started learning the Prolog Language in my college.
I really like it, but there are some things our teacher hasn't explained to us.
Actually, he told us to find out how this exercise could be done
(I must say my knowledge in Prolog is very poor ;) )

"A student of System Engineering has forgotten his class schedule.
However, he can remember a few things about it:
-The name of his teachers: Mary, Jesus, Phil.
-The name of the courses: Logic, Programming, Maths.
-The class days: Monday, Wednesday,Thursday

And some other things:
-Programming class, taught by Mary, is after the Logic class
-Phil does not like to work on Monday, and Monday is a day that Logic is not taught
-He also knows that each teacher teaches a single course and classes are held on different days

Would you help this stupid student relate each teacher with their subject and the weekday class it is taught?
First answer: (NO, I DONT WANT TO HELP THIS MF)

Second answer: WOULD YOU HELP ME TO HELP THIS GUY??"


Haha, well, I dont want to make this post too long, but here I'll post the things I tried, but without any result :(

#2 polimerizar

    New Member

  • Members
  • Pip
  • 2 posts

Posted 24 March 2010 - 06:41 AM

The file on HotShare:
http://www.hotshare....9526735812.html


Code:
% Teachers
% Mary, jesus, Phil

% Subjects
% Logic, Programming, Maths

% Days
% Monday, Wednesday, Thursday

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% FACTS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% another way to do it maybe??
%teachers(mary,jesus,phil).
%subjects(logic,programming,maths).
%days(monday,wednesday,thursday).

teacher(mary).
teacher(jesus).
teacher(phil).

subject(logic).
subject(programming).
subject(maths).

day(monday).
day(wednesday).
day(thursday).

works_1(P,D) :- teacher(P), day(D).
is_taught_on_1(C,D) :- subject©, day(D).
teaches_1(P,C) :- teacher(P), subject©.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% day1 is_before_than day2
% day2 is_after_than day1

% teacher works day
% teacher teaches subject

% subject is_taught_on day

%%% subject1 is_before_than subject2
%%% subject2 is_after_than subject1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% --------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

is_after_than(wednesday,monday).
is_after_than(thursday,monday).
is_after_than(thursday,wednesday).

is_before_than(monday,wednesday) :- is_after_than(wednesday,monday).
is_before_than(monday,thursday) :- is_after_than(thursday,monday).
is_before_than(wednesday,thursday) :- is_after_than(thursday,wednesday).

% IF Phil WORKS Monday THEN
% other teachers cant work on monday
% Phil cant work other days other than Monday
% other teachers can work other days
% Phil works on Monday LOL xD


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% RULES??
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%teaches(mary,programming).
%is_after_than(programming,logic).
%no_works(phil,monday).
%no_is_taught_on(logic,monday).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ---------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


works_1(P1,D1) :- works_1(P1,D1),



%works(P1,D1) :-
%es(P1,teacher), es(D1,day), es(D2,day), es(P2,teacher), es(D3,day), es(P3,teacher),
%D2\==D1, P2\==P1, P3\==P1, D3\==D1,
%\+works(P1,D2), \+works(P2,D1), works(P3,D3).

%works(P,D) :- \+no_works(P,D).
%no_works(P,D) :- \+works(P,D).

%teaches(P,C) :- es(P,teacher), es(C,subject), \+teaches(not(P),C)), \+teaches(P,not©)), teaches().
%teaches(P,C) :- \+no_teaches(P,C).
%no_teaches(P,C) :- \+teaches(P,C).

%is_taught_on(C,D) :- es(C,subject), es(D,day), \+is_taught_on(not©,D)), \+is_taught_on(C,not(D))), is_taught_on().
%is_taught_on(C,D) :- \+no_is_taught_on(C,D).
%no_is_taught_on(C,D) :- \+is_taught_on(C,D).

%is_before_than(C1,C2) :- is_taught_on(C1,D1), is_taught_on(C2,D2), (is_after_than(D2,D1)).
%is_after_than(C1,C2) :- is_before_than(C2,C1).

%final(P,C,D) :- works(P,D), teaches(P,C), is_taught_on(C,D).

#3 Reedbeta

    DevMaster Staff

  • Administrators
  • 5340 posts
  • LocationSanta Clara, CA

Posted 24 March 2010 - 04:17 PM

This isn't game development related and it's a homework question so this isn't an appropriate forum to ask in. If you don't know how to complete the assignment you should make sure you do any reading you've been given and then ask your professor or classmates for help.
reedbeta.com - developer blog, OpenGL demos, and other projects





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users