Solve logic puzzle in Prolog!

281 views
Skip to first unread message

Lisa Huang

unread,
Apr 23, 2015, 11:16:44 AM4/23/15
to swi-p...@googlegroups.com
So I need to solve this logic puzzle by writing a program in Prolog. I am not familiar with this language at all, I've only used Matlab R and some Java. If someone could please help me out with the code and help me solve this problem it would be greatly appreciated! help a sista out

Here's a link to the problem:


The problem is written out below: we have to write out a code in Prolog in order to solve this logic puzzle, not simply print out the answer

With spring in the air, everyone's starting to think about spring clean-up so Jeff spent all week after school and all weekend doing odd jobs around the neighborhood to earn some spending money. He tilled gardens, raked leaves, cleaned up tree limbs, pruned hedges, and even spent one afternoon babysitting! Each day he worked for a different neighbor on a different chore. He charged each neighbor a reasonable rate for his work, but sometimes he got tips too. By the end of the week, he was quite pleased with the amount that he'd earned and each of the neighbors was pleased with the quality of work that he'd done. Determine the last name of each neighbor, what chore Jeff completed for each neighbor, what day of the week Jeff worked for each neighbor, how long each task took him (2 to 4 hours), and how much he earned for each task ($20 to $36).


1. Jeff helped Mrs. Agnew till her garden but it didn't take him 4 hours. Mr. Summer didn't need help on Thursday.


2. He spent an extra hour working on Thursday than he did on Wednesday but he wasn't pruning hedges on either day.


3. On Sunday, he earned $8 more than he did when the day he was babysitting, which earned him $4 more than he earned from Mr. Compton.


4. Jeff made $20 from the job he spent 2 hours doing, which wasn’t removing tree limbs.


5. Mr. Numen, who didn't ask him to rake leaves, paid him $32 but it didn't take him 3 hours. The job on Friday for Mrs. Fields took less time than the garden tilling job.


6. The hedge pruning job took him 3-1/2 hours to complete, a half hour longer than the job he did on Thursday. Jeff made $36 from the job he spent 4 hours doing, which was on Saturday.

Jan Wielemaker

unread,
Apr 23, 2015, 11:45:29 AM4/23/15
to Lisa Huang, swi-p...@googlegroups.com
On 04/23/2015 05:16 PM, Lisa Huang wrote:
> So I need to solve this logic puzzle by writing a program in Prolog. I
> am not familiar with this language at all, I've only used Matlab R and
> some Java. If someone could please help me out with the code and help me
> solve this problem it would be greatly appreciated! help a sista out

As many students discovered, it is quite rare that someone solves your
homework as most people think that the educational value of that is
rather low. I hope I don't give away too much by point at this
puzzle: http://swish.swi-prolog.org/example/houses_puzzle.pl

Study the puzzle, study how it is solved and then try do do yours.
You'll discover that the trick is mostly in finding a suitable
representation for the world described in the puzzle. Prolog does
the rest.

Success --- Jan
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages