Solving murder with Prolog
xmonader.github.io
xmonader.github.io
% % 3. Clue 2: Barbara was either in the study or the bathroom; Yolanda was in the other.
% % Which room was Barbara found in?
woman(Bathroom), woman(Study), \+christine=Bathroom, \+christine=Study,
\+barbara=Dining, \+barbara=Kitchen, \+barbara=Livingroom, \+barbara=Pantry,
I thought, surely there's a better way to write that, a way that closely resembles the English "either a and b, or c and d". And Prolog in fact has disjunctions. (Prolog noob here, first time I've ever run a Prolog program.) Thus: (barbara=Study, yolanda=Bathroom ; barbara=Bathroom, yolanda=Study),
I verified that the program still works with that change, and the performance seems equivalent. (Takes about 7 seconds to run on my 1.3Ghz fanless laptop.)Seems neat! Of course the narrative writing is still the bulk of the work.
https://www.amazon.com/Elementary-Chronicled-Learning-Comput...
They just don't make CS books like that any more.
Good example of the Amazon algorithm going nuts, or just a really amazing old book.
I bought it from a local used book store for $6.
It's usually something more like $400-500 for a book like this, but I guess $1000+ isn't too farfetched.
Here's my solution if anyone is interested - https://imgur.com/a/MQFDdXu
As an aside, does anyone have any good sites/links to logic puzzles like these? I really do enjoy spending time graphing them out and solving them.
https://en.wikipedia.org/wiki/Zebra_Puzzle
There's a very famous one apocryphally attributed to Einstein:
https://udel.edu/~os/riddle.html
Searching for the term "zebra puzzle" will net many results e.g.: https://www.brainzilla.com/logic/zebra/
They can be solved by hand, as you've noted, with vanilla Prolog using the technique in the article, or with constraint logic programming for which Prolog has a very powerful library (vanilla Prolog is just doing an exhaustive search.)
https://en.wikipedia.org/wiki/Constraint_logic_programming
http://www.swi-prolog.org/man/clpfd.html
Another approach is to translate them into an exact cover problem and feed them into a solver like DLX.
https://en.wikipedia.org/wiki/Exact_cover
https://www.geeksforgeeks.org/exact-cover-problem-algorithm-...
This class of problem is NP-complete so don't feel bad if larger problems are too hard to solve - no one knows how to solve them efficiently!
I'd love to see more real world examples too.