Skip to content

๐Ÿšฃ A Python solution to the classic river crossing puzzle with wolves, goats, and cabbages ๐Ÿบ๐Ÿ๐Ÿฅฌ

Notifications You must be signed in to change notification settings

tblakex01/The-River-Problem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

2 Commits
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿšฃ The River Problem ๐ŸŒŠ

A Python implementation of the classic river crossing puzzle featuring a farmer trying to transport a wolf, a goat, and a cabbage across a river.

๐ŸŽฎ The Puzzle

A farmer needs to transport three items across a river:

  • ๐Ÿบ Wolf
  • ๐Ÿ Goat
  • ๐Ÿฅฌ Cabbage

Rules

  • ๐Ÿšฃ The boat can only carry the farmer and at most one item
  • ๐Ÿบ If left alone, the wolf will eat the goat
  • ๐Ÿ If left alone, the goat will eat the cabbage
  • ๐Ÿง‘โ€๐ŸŒพ The farmer must be present for all river crossings

๐Ÿ› ๏ธ Implementation

This solution features:

  • Object-oriented design with proper encapsulation
  • Type hints for better code clarity
  • Breadth-first search algorithm for finding the optimal solution
  • State validation to ensure no animals eat each other
  • Comprehensive move tracking

๐Ÿš€ Usage

python river_crossing.py

๐Ÿงช Output

The program will output a step-by-step solution showing how to safely transport all items across the river.

๐Ÿ—๏ธ Architecture

  • Bank: Enum representing river banks
  • AnimalType: Enum for different transportable items
  • Animal: Dataclass representing an item with its current location
  • GameState: Class managing the current state of the puzzle
  • RiverCrossing: Main solver class implementing BFS algorithm

๐Ÿ“ License

MIT License

About

๐Ÿšฃ A Python solution to the classic river crossing puzzle with wolves, goats, and cabbages ๐Ÿบ๐Ÿ๐Ÿฅฌ

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages