/*-------------------------------------- File: chores1.ecl ------------------------------------- Title: Solving Logic Puzzles using Artificial Intelligence Author: Leon J. Mekly, Ph.D. Knowledge representation language: ECLiPSe CLP at https://eclipseclp.org Example: "At the farm" - rated HARD https://www.ahapuzzles.com/logic/logic-puzzles/pdf/at-the-farm.pdf Five siblings (one is Fran) live on a farm. Each must perform a chore (including milking a cow) on a specic day of the week (Mon-Fri). If each of them performs a certain task on a given day and at a specic time (either 5:00 am, 6:00 am, 7:00 am, 8:00 am, 9:00 am), from the clues provided below can you determine which sibling performed which task at which time on which day? ----------------------------------------------------------------------------------------------------*/ :- lib(ic_symbolic). :- local domain(day(mon,tue,wed,thu,fri)). :- local domain(chore(milk,market,corn,fences,eggs)). :- local domain(time('5:00am','6:00am','7:00am','8:00am','9:00am')). go :- Farm = [ ['Adam', AdamDay, AdamTime, AdamChore], ['Carl', CarlDay, CarlTime, CarlChore], ['Fran', FranDay, FranTime, FranChore], ['Nan ', NanDay , NanTime , NanChore ], ['Mike', MikeDay, MikeTime, MikeChore] ], Days = [AdamDay,CarlDay,FranDay,NanDay,MikeDay], Days &:: day, alldifferent(Days), Chores = [AdamChore,CarlChore,FranChore,NanChore,MikeChore], Chores &:: chore, alldifferent(Chores), Times = [AdamTime,CarlTime,FranTime,NanTime,MikeTime], Times &:: time, alldifferent(Times), % 1. Fran's day to mend fences is neither Tuesday nor Thursday, and is % completed earlier in the week than at least one other person. member(['Fran',FranDay,_,fences],Farm), FranDay &\= tue, FranDay &\= thu, FranDay &< fri, % 2. The one who goes to market goes later in the week than Carl, and % earlier in the morning than Nan, but later in the morning than Fran. member(['Mike',MikeDay,MikeTime,market],Farm), % Mike is the one in clue 9 MikeDay &> CarlDay, MikeTime &< NanTime, MikeTime &> FranTime, % 3. Adam does not plant the corn, or go to market, his chore is completed % before 9:00 am, but not before 6:00 am on his assigned day of Monday. AdamChore &\= corn, AdamChore &\= market, AdamTime &< '9:00am', AdamTime &> '5:00am', AdamDay &= mon, % 4. No one performs a chore on Thursday at 7:00 am. member([_,thu,ThuTime,_],Farm), ThuTime &\= '7:00am', % 5. Mike's chore is completed earlier in the day than at least 3 others, % but later in the week than at least three others. MikeTime &< '7:00am', MikeDay &> wed, % 6. One of the boys collects eggs, another boy milks Bessie, the goat. member([_,EggsDay,EggsTime,eggs],Farm), member([_,MilkDay,_,milk],Farm), % 7. The milk is collected earlier in the week than the girl who plants % the corn, which is not planted before Wednesday. member(['Nan ',CornDay,_,corn],Farm), % Nan is the girl, Fran mends fences MilkDay &< CornDay, CornDay &> tue, % 8. The eggs must be collected at 7:00 am, but never on Mondays or Fridays. EggsTime &= '7:00am', EggsDay &\= mon, EggsDay &\= fri, % 9. All the other chores must be complete before Mike goes to the market. MikeChore &= market, MikeDay &= fri, nl, (foreach(Sibling,Farm) do writeln(Sibling)). %-------------------------------------- EOF: chores1.ecl -----------------------------