Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use prolog pls Albert Einstein was allegedly very fond of a particular kind of logic puzzle, now known in his honor as an Einstein Puzzle.

use prolog pls image text in transcribed
image text in transcribed
Albert Einstein was allegedly very fond of a particular kind of logic puzzle, now known in his honor as an "Einstein Puzzle. You can still find books and websites that are full of these kinds of puzzles! With Prolog, finding solutions to Einstein puzzles can be done automatically. Here's the Einstein puzzle that we'll work on There are five colleges Harvard, Yale, Princeton, brown, Upenn algird, bruno, collette, dino, and edwina are students at the colleges and each is from a different college. Those students were on a train together sitting in a row of seats numbered 1 through 5: One tant per seat Each student brought a different stack which is one of jots, chocolate, donuts, per and spain bruno and dino sat in the end seats (seats 1 and 5, but bruno could sit in 1 or S and so could dino). algird sat next to the student from Princeton collette sat next to friends with chocolate and donuts The Princeton student brought spam as a stack and sat in the middle seat. chocolate was immediately to the left of pez brumo, dino, and algird do not go to Upenn TlHarvard student sat between the persons with jots and spam. .dino did not sit next to the person with donuts. Brown student did not sit next to edwina Your task is to write a Prolog predicate to determine the seat member, college, and snack of each of the dents. You should endle the information provided above in your Prolog code but you should not add additional constraints or information that you inferred on your own since that would defeat the purpose of having Prolog solve this puzzle on its own. Plesse use the provided starter file Ad code to that file and submit that file Notice that the predicate that you will run is called solve. We've written solve and it involos pelicate called einstein that you will need write. Here's what it will look like when you run solve: jota] 9-solve. Bro Seat 1: [brune Seat 2: Seat 3 Seat 4: ... Seat 5: 88 A triple is a list of three items of the form [name, college, snack] 88 A SeatList will be a list of 5 triples, indicating a candidate to the problem 88 (e.g, ( [algird, Brown, pez], [bruno Princetop spam), ... 88 The following predicates will be used to encode the constraints in the puzzle. 88 left is true if A and 3 are triples and A is in the seat to the immediate left of B 88 in SeatList left(A, B, Seat List) :- fail. 88 next is true if A and B are triples and A and B are seated next to one another in SeatList next(A, B, SeatList) :- fail. 88 between is true if triple B sits between triples A and C in the SeatList between (A, B, C, SeatList) :- fail. 88 The permutation predicate was written and will be useful here. permutation(I), []). permutation(L, [ F R ]) :- append (BeforeF, [F AfterF), L), append (BeforeF, AfterF, Other), permutation (Other, R). 88 Here's the puzzle solver! einstein(SeatList) :- permutation([P1, P2, P3, P4, P5], [algird, bruno, collette, dino, edwina]), permutation ([c1, c2, C3, C4, C5), Harvard Yale Princeton Brown Upenn ), permutation ([S1, S2, S3, S4, S5), jots, chocolate, donuts, pez, spam]), SeatList = [[Pi, ci, si], [P2, C2, S2), [P3, C3, S3], [P4, C4, S4], [P5, C5, S5) ), 88 You'll write the rest! solve :- einstein [ H1, H2, H3, H4, H5 ) ), write('Seat 1:'), write(H1), nl, write('Seat 2:'), write(H2), nl, write('Seat 3 "), write(H3), nl, write('Seat 4: "), write(H4), nl, write('Seat 5:'), write(15), nl. Albert Einstein was allegedly very fond of a particular kind of logic puzzle, now known in his honor as an "Einstein Puzzle. You can still find books and websites that are full of these kinds of puzzles! With Prolog, finding solutions to Einstein puzzles can be done automatically. Here's the Einstein puzzle that we'll work on There are five colleges Harvard, Yale, Princeton, brown, Upenn algird, bruno, collette, dino, and edwina are students at the colleges and each is from a different college. Those students were on a train together sitting in a row of seats numbered 1 through 5: One tant per seat Each student brought a different stack which is one of jots, chocolate, donuts, per and spain bruno and dino sat in the end seats (seats 1 and 5, but bruno could sit in 1 or S and so could dino). algird sat next to the student from Princeton collette sat next to friends with chocolate and donuts The Princeton student brought spam as a stack and sat in the middle seat. chocolate was immediately to the left of pez brumo, dino, and algird do not go to Upenn TlHarvard student sat between the persons with jots and spam. .dino did not sit next to the person with donuts. Brown student did not sit next to edwina Your task is to write a Prolog predicate to determine the seat member, college, and snack of each of the dents. You should endle the information provided above in your Prolog code but you should not add additional constraints or information that you inferred on your own since that would defeat the purpose of having Prolog solve this puzzle on its own. Plesse use the provided starter file Ad code to that file and submit that file Notice that the predicate that you will run is called solve. We've written solve and it involos pelicate called einstein that you will need write. Here's what it will look like when you run solve: jota] 9-solve. Bro Seat 1: [brune Seat 2: Seat 3 Seat 4: ... Seat 5: 88 A triple is a list of three items of the form [name, college, snack] 88 A SeatList will be a list of 5 triples, indicating a candidate to the problem 88 (e.g, ( [algird, Brown, pez], [bruno Princetop spam), ... 88 The following predicates will be used to encode the constraints in the puzzle. 88 left is true if A and 3 are triples and A is in the seat to the immediate left of B 88 in SeatList left(A, B, Seat List) :- fail. 88 next is true if A and B are triples and A and B are seated next to one another in SeatList next(A, B, SeatList) :- fail. 88 between is true if triple B sits between triples A and C in the SeatList between (A, B, C, SeatList) :- fail. 88 The permutation predicate was written and will be useful here. permutation(I), []). permutation(L, [ F R ]) :- append (BeforeF, [F AfterF), L), append (BeforeF, AfterF, Other), permutation (Other, R). 88 Here's the puzzle solver! einstein(SeatList) :- permutation([P1, P2, P3, P4, P5], [algird, bruno, collette, dino, edwina]), permutation ([c1, c2, C3, C4, C5), Harvard Yale Princeton Brown Upenn ), permutation ([S1, S2, S3, S4, S5), jots, chocolate, donuts, pez, spam]), SeatList = [[Pi, ci, si], [P2, C2, S2), [P3, C3, S3], [P4, C4, S4], [P5, C5, S5) ), 88 You'll write the rest! solve :- einstein [ H1, H2, H3, H4, H5 ) ), write('Seat 1:'), write(H1), nl, write('Seat 2:'), write(H2), nl, write('Seat 3 "), write(H3), nl, write('Seat 4: "), write(H4), nl, write('Seat 5:'), write(15), nl

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions