I have tried to solve the Einstein puzzle - five friend edition - in prolog, but Im stuck. I can't seem to find the error in my code, or what to do to solve it. The goal is to write a Prolog program that identifies correctly what kind of puzzle each of them did, the theme of the puzzle and how long it took them to complete it - solution(Person, Kind, Time, Theme)
I also get this error:
uncaught exception: error(existence_error(procedure,members/3),clue1/0)
I think it something to do with members?
the knowledge base:
The five friends are Krystal, Angie, the one who did the Outerspace puzzle, the one who took 30 minutes to complete the puzzle, and the one who did the Word Search.
Ethan either finished the letter tiles in 90 minutes or did the winter themed puzzle in 20 minutes.
Of Dereck and the one who did the Logic Puzzle, one took 45 minutes while the other did a movies themed puzzle. Boys took the shortest and longest times to finish their puzzles.
Nick spent less than 40 minutes working on his puzzle, which was not the Visual Sudoku. Angie spent more than 40 minutes working on her Cat puzzle.
The girl who spent 60 minutes working on a sports puzzle did NOT do the Jigsaw. the jigsaw was done by a boy in less time than the one who did the Logic Puzzle but more time than the one who did the Word Search.
The Visual Sudoku either took an hour to complete or was Outerspace themed. Dereck did not do the winter themed puzzle (which was not the Word Search.)
Here is my code:
woman(krystal).
woman(angie).
man(dereck).
man(ethan).
man(nick).
kind(word).
kind(sudoku).
kind(letter).
kind(jigsaw).
kind(logic).
time(30).
time(90).
time(20).
time(45).
time(60).
theme(outerspace).
theme(winter).
theme(movies).
theme(sports).
theme(cat).
members([],_).
members([M|Ms],Xs) :- select(M,Xs,Ys),members(Ms,Ys).
clue1(Game) :- members([[krystal,_,_,_,_], [angie,_,_,_], [P,_,30,_], [P,word,_,_], [P,_,_,outerspace]], Game, man(P)).
clue2(Game) :- members([[krystal,_,_,_,_], [angie,_,_,_],[P,_,_,outerspace], [P,_,_,outerspace], [P,_,_,outerspace]], Game, man(P)).
clue3(Game) :- members([[krystal,_,_,_,_], [angie,_,_,_],[P,_,30,_], [P,_,30,_], [P,_,30,_]], Game, man(P)).
clue4(Game) :- members([[krystal,_,_,_,_], [angie,_,_,_],[P,_,_,word], [P,_,_,word], [P,_,_,word]], Game, man(P)).
clue5(Game) :- member([ethan, letter, 90,_], Game).
clue5(Game) :- member([ethan, _, 20, winter], Game).
clue6(Game) :- member([P, _, 20, _], Game, man(P)).
clue6(Game) :- member([P, _, 90, _], Game), man(P).
clue7(Game) :- member([dereck, _, 45, _], Game).
clue7(Game) :- member([dereck, _, _, movies], Game).
clue8(Game) :- member([_, logic, 45, _], Game).
clue8(Game) :- member([_, logic, _, sport], Game).
clue9(Game) :- member([nick, _, 30, _], Game).
clue9(Game) :- member([nick, _, 20, _], Game).
clue10(Game) :- member([P, sudoku, _, _], Game, \+nick(P)).
clue11(Game) :- member([angie, _, 45, cat], Game).
clue11(Game) :- member([angie, _, 60, cat], Game).
clue11(Game) :- member([angie, _, 90, cat], Game).
clue12(Game) :- member([P, Q, 60, sport], Game, girl(P), \+sport(Q)).
clue13(Game) :- member([P, jigsaw, Q, _], Game, man(P), \+time(20)).
clue13(Game) :- member([P, jigsaw, Q, _], Game, man(P), \+time(90)).
clue13(Game) :- member([P, jigsaw, 30, _], Game, man(P)), member([_, word, 20, _], Game), (member([_, logic, 40, _], Game); member([_, logic, 60, _], Game); member([_, logic, 90, _], Game)).
clue13(Game) :- member([P, jigsaw, 45, _], Game, man(P)), (member([_, word, 20, _], Game); member([_, word, 30, _], Game)), (member([_, logic, 60, _], Game); member([_, logic, 90, _], Game)).
clue13(Game) :- member([P, jigsaw, 60, _], Game, man(P)), (member([_, word, 20, _], Game); member([_, word, 30, _], Game); member([_, word, 46, _], Game)), member([_, logic, 90, _], Game).
clue14(Game) :- member([_, sudoku, 60, _], Game).
clue14(Game) :- member([_, sudoku, _, outerspace], Game).
clue15(Game) :- member([P, _, _, winter], Game, \+dereck(P)).
clue16(Game) :- member([_,word,_,P], Game, \+winter(P)).
clue17(Game, A,B,C,D) :- member([A,B,C,D], Game).
solution(A,B,C,D) :-
Game = [A,B,C,D],
clue1(Game),
clue2(Game),
clue3(Game),
clue4(Game),
clue5(Game),
clue6(Game),
clue7(Game),
clue8(Game),
clue9(Game),
clue10(Game),
clue11(Game),
clue12(Game),
clue13(Game),
clue14(Game),
clue15(Game),
clue16(Game),
clue17(Game, A,B,C,D),
members([[_,sudoku,_,_], [_,logic,_,_],[_,letter,_,_],[_,jigsaw,_,_],[_,word,_,_]],Game),
members([[krystal,_,_,_],[angie,_,_,_],[ethan,_,_,_],[dereck,_,_,_],[nick,_,_,_]],Game),
members([[_,_,60,_],[_,_,45,_],[_,_,90,_],[_,_,30,_],[_,_,20,_]],Game),
members([[_,_,_,sports],[_,_,_,cat],[_,_,_,outerspace],[_,_,_,movies],[_,_,_,winter]],Game),
write(Game),
true.
/*
1) One is named Krytal who didnt do the Outerspace puzzle, the Word search and didnt use 30 min
and One is named Angie who didnt do the Outerspace puzzle, the Word search and didnt use 30 min
2) One boy did the Outerspace puzzle
3) One boy used 30 min
4) One boy did the Word Search
5) Ethan either finished the letter tiles in 90 minutes or did the winter themed puzzle in 20 minutes.
6) Boys took the shortest and longest times to finish their puzzles.
7) Dereck either took 45 minutes or did a movies themed puzzle.
8) The one who did the logic puzzle either took 45 minutes or did a movies themed puzzle.
9) Nick spent less than 40 minutes working on his puzzle
10) Nick did not the Visual Sudoku.
11) Angie spent more than 40 minutes working on her Cat puzzle.
12) The girl who spent 60 minutes working on a sports puzzle did NOT do the Jigsaw.
13) the jigsaw was done by a boy in less time than the one who did the Logic Puzzle but more time than the one who did the Word Search.
14) The Visual Sudoku either took an hour to complete or was Outerspace themed.
15) Dereck did not do the winter themed puzzle
16) The Word Search is not winter themed
*/