As my first Prolog challenge I'm trying to solve this puzzle:
There are eight floors in an apartment building. The fifth floor has the only apartment with two bedrooms. Mrs Barber has a baby and cannot carry a pram upstairs when the lift is out of order. Mr and Mrs Elder also find climbing difficult now that they’re retired. Mr Archer likes the peace and quiet of living on the top floor. Mrs Cook and her daughter need a two bedroom flat. Mr and Mrs Hooper live just below Mr Archer. Mrs Cook lives above Mr Gardner and below Mrs Driver. Mr and Mrs Fisher live above Mr and Mrs Elder.
Essentially, I see it as a set of algebraic integer relations, so I'd like to instantiate each entity as an integer in [1..8]
and declare the known values and relationships.
floors([Archer,Barber,Cook,Driver,Elder,Fisher,Gardner,Hooper]) :-
Archer=8,
Cook=5,
Hooper is Archer-1,
Barber<4,
Elder<4,
Fisher>Elder,
Cook>Gardner,
Cook<Driver.
?- floors([A,B,C,D,E,F,G,H]).
However I get ERROR:Arguments are not sufficiently instantiated
at line 5 (the first inequality).
I tried adding
Vars = [Archer,Barber,Cook,Driver,Elder,Fisher,Gardner,Hooper],
Vars ins 1..8,
But then I get the vague ERROR: Unknown procedure: floors/1 (DWIM could not correct goal)
I'm sure I'm missing something obvious. All help appreciated.