Miami University Oxford Prolog Puzzle Project Worksheet
ANSWER
- Select Logic Puzzles: Visit the https://www.printable-puzzles.com/printable-logic-… website and choose two logic puzzles, one labeled as “challenging” and the other as “Very Hard.” You will need the URL of each puzzle to include in your Prolog files.
- Create Prolog Files:
- Create two Prolog files named
challenging.pl
andveryhard.pl
. - In each Prolog file, define a
url/1
fact to store the URL of the respective puzzle. For example:prologurl('URL_OF_CHALLENGING_PUZZLE').
Replace
'URL_OF_CHALLENGING_PUZZLE'
with the actual URL of the challenging puzzle. - Define a
solution/1
fact in each file to hardcode the correct solution obtained from the website. For example:prologsolution(SolutionList).
Replace
SolutionList
with the actual solution for the respective puzzle. - Implement a
solve/1
rule in each file that uses Prolog clauses to solve the puzzle. This rule should derive one, and only one, solution based on the provided clues. You will need to define the predicates and rules required to find the solution. - Define a series of
clueX/1
rules in each file, where X represents different clues. These rules should be satisfied whenever the solution inT
is consistent with clue X. You will need to convert the clues from the puzzle into Prolog clauses and use them in these rules. - Include the
check
rule in each file, as specified. This rule checks whether the solution is valid and if there is only one solution. It should print a message indicating the number of solutions found.
- Create two Prolog files named
- Solve the Puzzle: Implement the Prolog rules and clauses to solve the logic puzzle based on the clues provided in the puzzle description.
- Testing: Run the SWI-Prolog interpreter with the
check
goal to test your Prolog files for correctness. Make sure there is only one valid solution.
swipl -q -g check -g halt challenging.pl
swipl -q -g check -g halt veryhard.pl
- Refinement: If necessary, refine your Prolog code until it produces the correct solution and passes the
check
test. - Documentation: Document your Prolog files, including the URL of the puzzles, the clues used, and any other relevant information.
- Submission: Submit your
challenging.pl
andveryhard.pl
Prolog files along with the documentation as required for your assignment.
Ensure that you have a good understanding of Prolog and logic programming to effectively implement the rules and clauses needed to solve the logic puzzles. Additionally, adapt the provided examples to match the actual puzzle and solution you are working with.
QUESTION
Description
The “funnest” way I can think of to practice logic programming is to use it to solve a logic puzzle. A logic puzzle is typically presented as a mystery and list of clues that can be used to infer facts such as “who done it”.
For this assignment, we will use the https://www.printable-puzzles.com/printable-logic-… to an external site. website to find two puzzles to solve. One will be a “challenging” puzzle and the other will be a “Very Hard” puzzle.
For this assignment, you will write all of the clues as rules in a prolog program.
Your prolog file must obey the folowing format:
The name of the prolog files must be ‘challenging.pl’ and ‘veryhard.pl’
Your prolog file must provide a url/1 fact to get the URL of the puzzle being solced.
Your prolog file must also provide a solution/1 fact with the correct solution hardcoded in. You will get the correct solution from the https://www.printable-puzzles.com/printable-logic-… to an external site. website.
Your prolog file must provide a solve/1 rule that uses the clues to find one, and only one, table that is the solution.
Your puzzle must have a sereis of clueX(T) rules that are satisfied whenever the solution in T is consistent with clue X.
Your puzzle must include the check rule as follows:
check :- solution(S), solve(S), aggregate_all(count, (solve(_T)), Count), format(“Found ~w solutions~n”, [Count]), Count=1.
To receive credit, your puzzle must find one, and only one, solution to the puzzle.
Your assignment will be checked by running swipl in the docker container as follows:
swipl -q -g check -g halt challenging.pl