Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I am new at Prolog, I learnt some of its concepts but still have difficulties in writing procedures
I have this issue, I need to write a porgram in prolog to solve it but I couldn't
It might be simple, but I found it hard for me as a beginner
question is this
We have a box contains red & yellow balls.
A man comes daily and gets 2 balls from the box, if he couldn't get 2 balls game finshes.
There is a heap of red balls next to the box.
If the 2 balls which the man withdrown from the box were similar , he puts red ball into the box,
while if they were different, he puts yellow ball in the box.
We suppose that the box is represented like this
initialCan([y, r, y, r, y, r, y, r, y, r]).

y represents yellow ball, r represents red ball
the man withdraw the 2 balls from the beginning of the list ,
then he puts back 1 ball also to the beginning of the list.
So what is the procedure in Prolog which gives the color of the last ball in the box whatever
was the box containing at the beginning?
Posted
Comments
Richard MacCutchan 19-Dec-14 10:41am    
This is nothing to do with prolog as such. You just need to study the algorithm for this problem (Google will probably find it) and then convert that into code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900