A farmer with his wolf, duck and bag of corn come to the east side of a river they wish to cross. There is a boat at the river’s edge, but of course only the farmer can row. The boat can only hold two things (including the rower) at any one time. If the wolf is ever left alone with the duck, the wolf will eat it. Similarly if the duck is ever left alone with the corn, the duck will eat it. How can the farmer get across the river so that all four arrive safely on the other side? Solve this problem using Depth First Search to find the shortest solution. Write Code in C++/Java.Its my assignment im unable to do it although have made the state space
Recommended Answers
Jump to PostMy head hurts just looking at this. I can't follow code like this. You need to format/indent. You also need to decide whether you are programming in C or C++. You're using iostream, so it must be C++. So you want to include cstdlib and cstdio, not stdlib.h and stdio.h. …
Jump to PostThere is a boat at the river's edge, but of course only the farmer can row.
I forgot to comment on this. The boat is always where the farmer is, correct? So it seems to me that you can get rid of all code keeping track of the …
Jump to Post@AssertNull running
astyle --style=allman --align-pointer=middle --max-code-length=79 farmer.cpp
does a pretty good job on formatting Builder_1's code
Jump to PostGood to know. I've never tried that program. NetBeans has a nice little formatter that I use. Formats quite well. And quickly. Far faster than it took me to write those sentences complaining about the OP not formatting his code...
But I still think it's worth writing those sentences because …
All 14 Replies
happygeek
2,411
Most Valuable Poster
Team Colleague
Featured Poster
Builder_1
-6
Junior Poster in Training
AssertNull
1,094
Practically a Posting Shark
AssertNull
1,094
Practically a Posting Shark
Gribouillis
1,391
Programming Explorer
Team Colleague
AssertNull
1,094
Practically a Posting Shark
Builder_1
-6
Junior Poster in Training
Gribouillis
1,391
Programming Explorer
Team Colleague
AssertNull
1,094
Practically a Posting Shark
Gribouillis
1,391
Programming Explorer
Team Colleague
Gribouillis
1,391
Programming Explorer
Team Colleague
AssertNull
1,094
Practically a Posting Shark
Gribouillis
1,391
Programming Explorer
Team Colleague
AssertNull
1,094
Practically a Posting Shark
Builder_1
commented:
Thanks alot
+2
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.