Giter Club home page Giter Club logo

breadth-first-search's Introduction

Breadth-First-Search

Wolf, Goat, Cabbage and Water Jugs Puzzles

This repository contains two classic puzzle-solving programs: the Wolf, Goat, Cabbage puzzle, and the Water Jugs puzzle.

Wolf, Goat, Cabbage

The program wolfGoatCabbage.cpp solves the classic Wolf, Goat, Cabbage problem.

Problem: You are standing with a wolf, goat, and cabbage, next to a river, and you would like to transport all three of these items to the other side. However, you only have access to a small boat that can fit at most one item (besides yourself). If you leave the wolf and goat alone unattended, bad things happen to the goat. If you leave the goat and cabbage unattended, bad things happen to the cabbage.

Solution: The program performs a breadth-first search to find the solution and outputs the steps required to safely transport all items across the river.

Water Jugs

The program waterJugs.cpp solves the Water Jugs problem.

Problem: You are standing next to a river with a very content-looking wolf, a head of cabbage, and two water jugs, which have integer sizes A = 3 and B = 4. In order to boil the cabbage for your dinner, you would like to measure out exactly 5 units of water.

Solution: The program performs a breadth-first search to find the sequence of actions required to measure out exactly 5 units of water using the two jugs.

How to run the programs

  1. Compile the C++ source files using a C++ compiler (e.g., g++):
g++ -o wolfGoatCabbage wolfGoatCabbage.cpp
g++ -o waterJugs waterJugs.cpp
  1. Run the compiled programs:
./wolfGoatCabbage
./waterJugs

Both programs will output the steps required to solve their respective puzzles.

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.