-
-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* wedding-woes: add exercise * wedding-woes: add exercise
- Loading branch information
1 parent
ce3bac5
commit c9fd901
Showing
8 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Hints | ||
|
||
## General | ||
|
||
- The [Prolog basics page](https://www.tutorialspoint.com/prolog/prolog_basics.htm) explains what facts and rules are and how to define them | ||
|
||
## 1. List the chatty people | ||
|
||
- You're defining a [fact](https://www.tutorialspoint.com/prolog/prolog_basics.htm) | ||
- You can define multiple "instances" of the same fact | ||
- Remember to use lowercase names | ||
|
||
## 2. List who likes whom | ||
|
||
- You're defining a [fact](https://www.tutorialspoint.com/prolog/prolog_basics.htm) | ||
- You can define multiple "instances" of the same fact | ||
- Remember to use lowercase names | ||
- The first argument is the person liking the other person | ||
- The second argument is the person being liked by the other person | ||
|
||
## 3. People who like each other make a good pairing | ||
|
||
- You're defining a [rule](https://www.tutorialspoint.com/prolog/prolog_basics.htm) | ||
- In Prolog, making sure that two facts/rules are both true is done via a [conjunction](https://www.tutorialspoint.com/prolog/prolog_conjunctions_and_disjunctions.htm) | ||
|
||
## 4. Chatty people pair with anyone | ||
|
||
- You're defining a [rule](https://www.tutorialspoint.com/prolog/prolog_basics.htm) | ||
- In Prolog, making sure that at least one of two facts/rules is true is done via a [disjunction](https://www.tutorialspoint.com/prolog/prolog_conjunctions_and_disjunctions.htm) | ||
|
||
## 5. Check seating arrangement | ||
|
||
- You're defining a [rule](https://www.tutorialspoint.com/prolog/prolog_basics.htm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Instructions | ||
|
||
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). | ||
|
||
## 1. List the chatty people | ||
|
||
Define the `chatty` fact to represent the chatty people. | ||
The `chatty` fact takes a single argument: the chatty person's lowercase name. | ||
|
||
```prolog | ||
chatty(gustavo). | ||
true. | ||
``` | ||
|
||
## 2. List who likes whom | ||
|
||
Define the `likes` fact to represent who likes whom. | ||
The `likes` fact takes two arguments: | ||
|
||
1. The lowercase name of the person liking the other person | ||
2. The lowercase name of the person being liked | ||
|
||
```prolog | ||
likes(esteban, malena). | ||
true. | ||
``` | ||
|
||
## 3. People who like each other make a good pairing | ||
|
||
Define the `pairing` rule to be true when the two people both like each other. | ||
The pairing rule takes two arguments: | ||
|
||
1. The lowercase name of the first person | ||
2. The lowercase name of the second person | ||
|
||
```prolog | ||
pairing(malena, esteban). | ||
true. | ||
``` | ||
|
||
## 4. Chatty people pair with anyone | ||
|
||
Define the `pairing` rule to be true when (at least) one of the two people being paired is chatty. | ||
|
||
```prolog | ||
pairing(valeria, jaime). | ||
true. | ||
``` | ||
|
||
## 5. Check seating arrangement | ||
|
||
Define the `seating` rule to be true when all five pairs are good pairings. | ||
|
||
The pairing rule takes fives arguments: | ||
|
||
1. The lowercase name of the first person | ||
2. The lowercase name of the second person | ||
3. The lowercase name of the third person | ||
4. The lowercase name of the fourth person | ||
5. The lowercase name of the fifth person | ||
|
||
Use the just defined facts and rules to check the seating arrangement. | ||
|
||
```prolog | ||
seating(esteban, jaime, gustavo, malena, valeria). | ||
false. | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Introduction | ||
|
||
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: | ||
|
||
- Esteban, Gustavo, Jaime, Malena, and Valeria. | ||
|
||
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: | ||
|
||
- Gustavo is chatty | ||
- Valeria is chatty | ||
- Esteban likes Malena | ||
- Malena likes Esteban | ||
- Rico likes Naran (but not vice versa!) | ||
|
||
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"authors": [ | ||
"erikschierboom" | ||
], | ||
"files": { | ||
"solution": [ | ||
"wedding_woes.pl" | ||
], | ||
"test": [ | ||
"wedding_woes_tests.plt" | ||
], | ||
"example": [ | ||
".meta/wedding_woes.example.pl" | ||
] | ||
}, | ||
"blurb": "Infer family relations from some basic facts." | ||
} |
10 changes: 10 additions & 0 deletions
10
exercises/practice/wedding-woes/.meta/wedding_woes.example.pl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
chatty(gustavo). | ||
chatty(valeria). | ||
|
||
likes(esteban, malena). | ||
likes(malena, esteban). | ||
likes(gustavo, valeria). | ||
|
||
pairing(First, Second) :- likes(First, Second), likes(Second, First). | ||
pairing(First, Second) :- chatty(First); chatty(Second). | ||
seating(A, B, C, D, E) :- pairing(A, B), pairing(B, C), pairing(C, D), pairing(D, E), pairing(E, A). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
% Define the 'chatty' fact | ||
|
||
% Define the 'lines' fact | ||
|
||
% Define the 'pairing' rule | ||
|
||
% Define the 'seating' rule |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
pending :- | ||
current_prolog_flag(argv, ['--all'|_]). | ||
pending :- | ||
write('\nA TEST IS PENDING!\n'), | ||
fail. | ||
|
||
:- begin_tests(wedding_woes). | ||
|
||
test(gustavo_is_chatty, condition(true)) :- | ||
chatty(gustavo). | ||
|
||
test(valeria_is_chatty, condition(pending)) :- | ||
chatty(valeria). | ||
|
||
test(jaime_is_not_chatty, [fail, condition(pending)]) :- | ||
chatty(jaime). | ||
|
||
test(esteban_likes_malena, condition(pending)) :- | ||
likes(esteban, malena). | ||
|
||
test(malena_likes_esteban, condition(pending)) :- | ||
likes(malena, esteban). | ||
|
||
test(gustavo_likes_valeria, condition(pending)) :- | ||
likes(gustavo, valeria). | ||
|
||
test(valeria_does_not_like_gustavo, [fail, condition(pending)]) :- | ||
likes(valeria, gustavo). | ||
|
||
test(people_who_like_each_other_make_a_good_pairing, condition(pending)) :- | ||
pairing(malena, esteban). | ||
|
||
test(two_chatty_people_make_a_good_pairing, condition(pending)) :- | ||
pairing(gustavo, jaime). | ||
|
||
test(one_chatty_person_make_a_good_pairing_with_anyone, condition(pending)) :- | ||
pairing(valeria, jaime). | ||
|
||
test(people_who_dont_like_each_other_and_are_not_chatty_dont_make_a_good_pairing, [fail, condition(pending)]) :- | ||
pairing(rico, naran). | ||
|
||
test(valid_seating, condition(pending)) :- | ||
seating(esteban, malena, gustavo, jaime, valeria). | ||
|
||
test(invalid_seating, [fail, condition(pending)]) :- | ||
seating(esteban, jaime, gustavo, malena, valeria). | ||
|
||
:- end_tests(wedding_woes). |