WolfSheepCabbageSolver is a Java application that solves the classic river-crossing puzzle known as the "Sheep, Wolf, and Cabbage" problem. In this puzzle, a farmer must transport a wolf, a sheep, and a cabbage across a river using a boat that can only carry one item at a time, without leaving the wolf alone with the sheep or the sheep alone with the cabbage.
The rules of the puzzle are as follows:
- The wolf cannot be left alone with the sheep (the wolf will eat the sheep).
- The sheep cannot be left alone with the cabbage (the sheep will eat the cabbage).
- The farmer can only carry one item (the wolf, the sheep, or the cabbage) at a time in the boat.
The goal is to get all three items across the river safely.
The solution to the puzzle involves a series of steps where the farmer carefully transports the items across the river. The steps are as follows:
- Take the sheep across the river.
- Return alone to the original side.
- Take the wolf across the river.
- Bring the sheep back to the original side.
- Take the cabbage across the river.
- Return alone to the original side.
- Take the sheep across the river again.
The application is implemented in Java and includes a main class, Main.java
, which contains the logic for solving the puzzle.
Main.java
: The main class containing the puzzle-solving logic.
- Clone the repository:
git clone https://github.com/ba6tati/WolfSheepCabbageSolver.git
- Navigate to the project directory:
cd WolfSheepCabbageSolver/src
- Compile the Java file:
javac Main.java
- Run the application:
java Main