Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Farmer Goat Wolf Cabbage Problem

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So im sure everybody knows this problem. The goal is to move the farmer from the East side to the West side with either the goat, wolf, or cabbage one by one until everyone is on the WEST. However certain things cannot be left alone (ie leaving the goat and wolf on one side or goat and cabbage). Basically I have to use different Search functions: Depth First Search, Breadth First Searh, and Best Fit Search. For now Im just trying to figure out how to test my code so far before I implement a solution.

Here's my my class so far.
--
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a solution?
if move wolf first, that leaves goat with cabbage.
if move cabbage first, that leaves wolf with goat.
if move goat first, then have to move either wolf or cabbage next and leave it with goat to go back for the last item.

on second thought it doesn't say he has to do it in 3 trips.
take goat across.
take wolf across and bring back goat.
take cabbage across.
take goat across.

a more practical solution is to kill the wolf first.
 
Saloon Keeper
Posts: 6522
160
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Randall Twede wrote:is there a solution?


Hint: the farmer can take something into his boat in both directions.
 
Ranch Hand
Posts: 198
Oracle Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Solution is:
1. Move the Goat first.
2. Now take the wolf.
3. while dropping the wolf on other side take the goat back on the boat.
4. deboard the goat and take the cabbage
5. now come back and take the cabbage..
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Won't the wolf eat the farmer first? :p
 
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or the farmer could simplify the problem by eating the cabbage.
 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you mean the farmer could simply eat the goat.
 
Paul Clapham
Marshal
Posts: 25682
69
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that would make the problem even simpler.
 
Steve Fahlbusch
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Getting back to the OP....

I am just a bit confused here.......

This is a classic state transition problem.

There are 2 unique solutions to this problem (do we bring cabbage or wolf over first, after we took the goat at the first step)...... what will depth first, breadth first or best fit show anything different?

to Paul,

if we are going to make it simple, we might as well make it trivial.

farmer ate a stew of goat and cabbage and then got fid of the wolf. farmer crossed the river in one pass :-)
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic