# Monkey-banana problem in Prolog

The monkey-banana problem: There many variations to this problem, but the basic premise is that a monkey is in a room with a banana and a chair, and the monkey cannot reach the banana until he moves the chair close to the banana (so as to reach it), then climbs the chair and gets the banana.

(Note : Often times, the chair is replaced with a box or a similar object that the monkey can climb on. Also, a stick may be added to the mix, which the monkey needs to swing at the banana in order to make it drop to the floor.)

I came up with this program to solve a simple monkey-banana problem in AI (no stick). I think it's overly simple, but I would like to know what you think.

on(floor,monkey).
on(floor,chair).
in(room,monkey).
in(room,chair).
in(room,banana).
at(ceiling,banana).

strong(monkey).
grasp(monkey).
climb(monkey,chair).

push(monkey,chair):-
strong(monkey).

under(banana,chair):-
push(monkey,chair).

canreach(banana,monkey):-
at(floor,banana);
at(ceiling,banana),
under(banana,chair),
climb(monkey,chair).

canget(banana,monkey):-
canreach(banana,monkey),grasp(monkey).


Should I add location attributes as well? I think that I have hard-coded a lot of things, or maybe having the stick included in the problem would make a better search tree?

• What is the monkey-banana problem exactly? – Simon Forsberg Oct 31 '15 at 13:55
• There many variations to that, but the basic premise is that a monkey is in a room with a banana and a chair, and the monkey cannot reach the banana until he moves the chair close to the banana (so as to reach it), then climbs the chair and gets the banana. – goelakash Oct 31 '15 at 13:57
• @goelakash Good include this in the post as comments are often deleted – Caridorc Oct 31 '15 at 14:21
• @SimonForsberg monkey-banana is a homework problem :D – Filip Bartuzi Oct 31 '15 at 15:51
• Yeah, but I did code this up. Prof took 2 classes this sem and expects intermediate proficiency. – goelakash Oct 31 '15 at 15:55