There are 3 devils and 3 Priests.They all have to cross a river in a boat.Boat can only carry two people at a time.As long as there are equal number of devils and priests,then devils will not eat Priest.If the number of devils are greater than the number of priests on the same side of the river then devils will eat the priests.So how can we make all the 6 peoples to arrive to the other side safely?
To arrive all the priests and devils to the other side, 6 steps are to be followed:-
1) Firstly one devil and one priest will go to the other side. Devil will stay to the other side while priest will come back with the boat.
2) Remaining two devils will go to the other side. One devil will stay to the other side while one devil will come again with the boat.So total two devils are on the another side of river and 3 priests and 1 devil is on the one side of the river.
3) Now two priests will go. One priest will stay while 1 priest and 1 devil come back with the boat.
4) Now remaining two priests will go to the other side of the river. Total 3 priests and 1 devil is on the one side while 2 devils is on the another side of the river. 1 devil will come back with the boat.
5) 2 devils will go to the other side of the river. 1 devil will stay and 1 devil will again go back with the boat.
6) Now the remaining 2 devils will come to the other side of the river.
All the 3 priests and 3 devils arrive safely.
This article is contributed by Rakesh Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.