HOMEWORK 1 ---

1.  Write a Prolog predicate, insert, which given an element X, and a
list L in ascending order, it will insert X in the appropriate position
to maintain the list in ascending order.

? insert(5,[3,4,7],M).
M=(3,4,5,7)

? insert(20,[6,14,20],M).
M=[6,14,20,20] 


2.  Write a Prolog predicate, orderasc(L,M), which orders the list L
in ascending order.

?orderasc([3,4,2], M).
M=[2,3,4]


--------------------------------------------------
3.
Here is an Example of a
Combinatorial problem in PROLOG:

A list of facts of the form:

guest([name, sex, age, occupation, [list_of_hobbies],
       political_affiliation, personality_type, [list_of-languages]).

Problem:
   Arrange the seating of guests in a round table, so that following 
constraints are satisfied:

1. alternate man-woman, woman-man.
2. do not seat actors next to professors.
3. do not seat shy persons next to each other.
4. do not seat liberals next to conservatives.
5. age differences of adjacently seated persons should 
   be no more than 10 years.
6.  adjacently seated persons should have at least one hobbie in 
    common, and at least 5 hobbies between them.
7.  adjacently seated persons should have at least 1 language in common.

__________________

seat_next(N1,N2):- guest([N1,S1,A1,O1,H1,P1,T1,L1]),
                   guest([N2,S2,A2,O2,H2,P2,T2,L2]),
                   not(N1=N2),not(S1=S2),
                   (((not(O1=professor),not(O2=actor));((O1=professor),
                    not(O2=actor)); (not(O2=professor),O1=actor))),
                   (((not(O1=conservative),not(O2=liberal));((O1=liberal),
                    not(O2=conservative)); (not(O2=liberal),
                    O1=conservative))),
                   (((T1=shy,not(T2=shy));(not(T1=shy),T2=shy);
                   (not(T1=shy),not(T2=shy))),
                   ((A1>A2,Diff is A1-A2);(Diff is A2-A1)),
                   Diff<10,
                   intersection(H1,H2, Hobies),not(Hobbies=[]),
                   union(H1,H2,Total_hobbies),
                   length(Total_hobbies,Y),Y>=5,
                   intersection(L1,L2,Languages), not(Languages=[]),
                   write(N2),write('can be seated next to'),write(N1),
                   write('.'), fail.


ASSIGNMENT: Run the program given above to find all pairs of persons
who can be seated next to each other (fix the errors first, if any).

-----------------------------------

4.

 This problem is a scheduling problem similar to the party guest list
   problem given above. The task is to match job applicants to a 
specific job.
   The requirements for the job are:
   
   At least three years' experience.
   A Bachelor's and a Master's degree.
   An average of two years per previous position overall to prove 
stability.
   Willingness to work overtime or to travel. Both are not necessary.
   Very good  or excellent health.
   
   Use the following data set of applicants as a test bed database:

1) Name: Jones
   Previous jobs, years on job:
                                CAT --- 5 years
                                IBM --- 4 years
                                CILCO--- 1 year
                                AIONICS---1 year
   Degrees: BS and MS
Overtime= no, Travel =yes, Health=excellent

2) Name: smith
Previous jobs, years on job:
                             BORDOM ---8 years
  Degrees: BS
  Overtime: yes, Travel: yes, Health: good

3) Name: smart_allec
   Previous jobs, years on job:
                                DELCO---1year
                                MOTOROLLA---1 year
                                LOGICON---1 year
   Degrees: BS, MS, PHD
   Overtime: no, Travel: no, Health: very good
______________________________________________________