Git Product home page Git Product logo

ba6tati / wolfsheepcabbagesolver Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 4 KB

WolfSheepCabbageSolver is a Java application that solves the classic river-crossing puzzle where a farmer must transport a wolf, a sheep, and a cabbage across a river without leaving the wolf alone with the sheep or the sheep alone with the cabbage. The boat can only carry the farmer and one item at a time.

Java 100.00%

wolfsheepcabbagesolver's Introduction

WolfSheepCabbageSolver

Overview

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.

Problem Description

The rules of the puzzle are as follows:

  1. The wolf cannot be left alone with the sheep (the wolf will eat the sheep).
  2. The sheep cannot be left alone with the cabbage (the sheep will eat the cabbage).
  3. 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.

Solution

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:

  1. Take the sheep across the river.
  2. Return alone to the original side.
  3. Take the wolf across the river.
  4. Bring the sheep back to the original side.
  5. Take the cabbage across the river.
  6. Return alone to the original side.
  7. Take the sheep across the river again.

Implementation

The application is implemented in Java and includes a main class, Main.java, which contains the logic for solving the puzzle.

Files

  • Main.java: The main class containing the puzzle-solving logic.

Usage

  1. Clone the repository:
    git clone https://github.com/ba6tati/WolfSheepCabbageSolver.git
  2. Navigate to the project directory:
    cd WolfSheepCabbageSolver/src
  3. Compile the Java file:
    javac Main.java
  4. Run the application:
    java Main

wolfsheepcabbagesolver's People

Contributors

ba6tati avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.