Your best friend is getting married and asked you to be their wedding planner. You agreed, though everything you know about it is from a movie... Things were going smoothly, until you started working on the table seating.
Five guests will be attending, seated around one big, round table. Here's the guest list:
Your goal is to find a seating arrangement where everyone is happy with their neighbors. You don't know everyone quite as well as you'd like, but here's what you do know:
People who like each other can be seated next to each other, but only when they both feel that way. Chatty people intermingle easily and can be seated next to anyone.
With these details in hand, it's time to sketch out a seating arrangement!
Your task is to find the perfect table seating. You'll do this by declaring facts (things that are always true) and rules (things that are conditionally true).
Define the chatty
fact to represent the chatty people.
The chatty
fact takes a single argument: the chatty person's lowercase name.
chatty(gustavo).
true.
Define the likes
fact to represent who likes whom.
The likes
fact takes two arguments:
likes(esteban, malena).
true.
Define the pairing
rule to be true when the two people both like each other.
The pairing rule takes two arguments:
pairing(malena, esteban).
true.
Define the pairing
rule to be true when (at least) one of the two people being paired is chatty.
pairing(valeria, jaime).
true.
Define the seating
rule to be true when all five pairs are good pairings.
The pairing rule takes fives arguments:
Use the just defined facts and rules to check the seating arrangement.
seating(esteban, jaime, gustavo, malena, valeria).
false.
Sign up to Exercism to learn and master Prolog with 109 exercises, and real human mentoring, all for free.