From 9ffc70cd5759c0e9081b7e79deaf81bd3525bc8f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christina=20S=C3=B8rensen?= <christina@cafkafk.com>
Date: Sun, 22 Dec 2024 16:42:31 +0100
Subject: [PATCH] feat(prolog): wedding woes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Christina Sørensen <christina@cafkafk.com>
---
 prolog/wedding-woes/.exercism/config.json   |  17 ++++
 prolog/wedding-woes/.exercism/metadata.json |   1 +
 prolog/wedding-woes/HELP.md                 |  84 ++++++++++++++++
 prolog/wedding-woes/HINTS.md                |  33 ++++++
 prolog/wedding-woes/README.md               | 105 ++++++++++++++++++++
 prolog/wedding-woes/wedding_woes.pl         |  20 ++++
 prolog/wedding-woes/wedding_woes_tests.plt  |  48 +++++++++
 7 files changed, 308 insertions(+)
 create mode 100644 prolog/wedding-woes/.exercism/config.json
 create mode 100644 prolog/wedding-woes/.exercism/metadata.json
 create mode 100644 prolog/wedding-woes/HELP.md
 create mode 100644 prolog/wedding-woes/HINTS.md
 create mode 100644 prolog/wedding-woes/README.md
 create mode 100644 prolog/wedding-woes/wedding_woes.pl
 create mode 100644 prolog/wedding-woes/wedding_woes_tests.plt

diff --git a/prolog/wedding-woes/.exercism/config.json b/prolog/wedding-woes/.exercism/config.json
new file mode 100644
index 0000000..6cd6270
--- /dev/null
+++ b/prolog/wedding-woes/.exercism/config.json
@@ -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."
+}
diff --git a/prolog/wedding-woes/.exercism/metadata.json b/prolog/wedding-woes/.exercism/metadata.json
new file mode 100644
index 0000000..cfec5b4
--- /dev/null
+++ b/prolog/wedding-woes/.exercism/metadata.json
@@ -0,0 +1 @@
+{"track":"prolog","exercise":"wedding-woes","id":"ee9221fad24f42b1be3fe4fc1eb096f5","url":"https://exercism.org/tracks/prolog/exercises/wedding-woes","handle":"cafkafk","is_requester":true,"auto_approve":false}
\ No newline at end of file
diff --git a/prolog/wedding-woes/HELP.md b/prolog/wedding-woes/HELP.md
new file mode 100644
index 0000000..5d8e499
--- /dev/null
+++ b/prolog/wedding-woes/HELP.md
@@ -0,0 +1,84 @@
+# Help
+
+## Running the tests
+
+## Command line
+
+The following command can be used to run the tests from the command line:
+
+```bash
+swipl -f <exercise>.pl -s <exercise>_tests.plt -g run_tests,halt -t 'halt(1)'
+```
+
+Replace `<exercise>` with the name of the exercise you are implementing.
+
+## Interactive
+
+To run prolog interactively first run:
+
+```bash
+swipl
+```
+
+After the prolog console starts, load your implementation and run the tests
+with:
+
+```
+?- ["<exercise>.pl"].
+?- ["<exercise>_tests.plt"].
+?- run_tests.
+```
+
+Replace `<exercise>` with the name of the exercise you are implementing.
+
+### Reloading changes
+
+Once the above files are loaded, you can apply any changes you've made
+by running:
+
+```
+?- make.
+```
+
+## Skipped tests
+
+When you first begin an exercise, only the first test will run. The rest have
+been skipped by adding `condition(pending)` to the `test` goal. Once the first
+test passes, un-skip the next test by changing `pending` in `condition(pending)`
+to `true`. Repeat for each test until they are all running and passing.
+
+### Command line
+
+Add the `-- --all` argument to the end of the command to also run any pending tests:
+
+```bash
+swipl -f <exercise>.pl -s <exercise>_tests.plt -g run_tests,halt -t 'halt(1)' -- --all
+```
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit wedding_woes.pl` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [Prolog track's documentation](https://exercism.org/docs/tracks/prolog)
+- The [Prolog track's programming category on the forum](https://forum.exercism.org/c/programming/prolog)
+- [Exercism's programming category on the forum](https://forum.exercism.org/c/programming/5)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [SWI Prolog Documentation](http://www.swi-prolog.org)
+- [Tutorials and Resources](http://www.swi-prolog.org/Links.html)
+- [/r/prolog](https://www.reddit.com/r/prolog) is the Prolog subreddit.
+- [StackOverflow](http://stackoverflow.com/questions/tagged/prolog) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
\ No newline at end of file
diff --git a/prolog/wedding-woes/HINTS.md b/prolog/wedding-woes/HINTS.md
new file mode 100644
index 0000000..7effbfe
--- /dev/null
+++ b/prolog/wedding-woes/HINTS.md
@@ -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)
\ No newline at end of file
diff --git a/prolog/wedding-woes/README.md b/prolog/wedding-woes/README.md
new file mode 100644
index 0000000..89e1d0c
--- /dev/null
+++ b/prolog/wedding-woes/README.md
@@ -0,0 +1,105 @@
+# Wedding Woes
+
+Welcome to Wedding Woes on Exercism's Prolog Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+If you get stuck on the exercise, check out `HINTS.md`, but try and solve it without using those first :)
+
+## 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
+- Gustavo likes Valeria (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!
+
+## 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.
+```
+
+## Source
+
+### Created by
+
+- @erikschierboom
\ No newline at end of file
diff --git a/prolog/wedding-woes/wedding_woes.pl b/prolog/wedding-woes/wedding_woes.pl
new file mode 100644
index 0000000..21e2f1c
--- /dev/null
+++ b/prolog/wedding-woes/wedding_woes.pl
@@ -0,0 +1,20 @@
+% Define the 'chatty' fact
+chatty(gustavo).
+chatty(valeria).
+
+% Define the 'likes' fact
+likes(esteban, malena).
+likes(malena, esteban).
+likes(gustavo, valeria).
+
+% Define the 'pairing' rule
+pairing(X, Y) :- likes(X, Y), likes(Y, X).
+pairing(X, Y) :- chatty(X); chatty(Y).
+
+% Define the 'seating' rule
+seating(A,B,C,D,E) :-
+    pairing(A,B),
+    pairing(B,C),
+    pairing(C,D),
+    pairing(D,E),
+    pairing(E,A).
diff --git a/prolog/wedding-woes/wedding_woes_tests.plt b/prolog/wedding-woes/wedding_woes_tests.plt
new file mode 100644
index 0000000..17fa5a0
--- /dev/null
+++ b/prolog/wedding-woes/wedding_woes_tests.plt
@@ -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).