Giter Club home page Giter Club logo

the-wall-puzzle's Introduction

The Wall Puzzle

The Wall puzzle is a maze-like game where you enter and exit rooms by moving through colored pathways. You need to alternate between blue and red pathways. That is if the last pathway you entered was blue, the next one must be red. The goal is to reach the exit room.

The goal of this repository is to show a generalized solution to the puzzle.

Example

The puzzle could have multiple rooms and pathways, though the most common puzzle I've found is below:

The Wall Puzzle

Graph Structure

The puzzle can be represented as a graph where each room is a node and each pathway is an edge with a color. A graph for the above puzzle might look like:

The Wall Puzzle Graph

Solution

Seeing the puzzle as a graph can help us reason more easily about a solution. First, since we are trying to find a path from the start to the end, we can use a graph traversal algorithm to find the path. Dijkstra's algorithm is a good choice since it can find the shortest path between two nodes and we've used the pathfinding crate before.

Next, we'll need to determine a neighbor function that we can use to pick valid neighbors. In the case of this puzzle, a valid neighbor is any room connected by a pathway of the opposite color of the last pathway we entered. Therefore, our neighbors function needs to track not only the node but also the color of the last edge traversed. We'll use a State struct to track this information.

Finally, we'll need a success function to determine if we've reached the end. This puzzle can calculate this easily as we simply need to check to see if we are at the end node T.

the-wall-puzzle's People

Contributors

icub3d avatar jhscheer avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

jhscheer

the-wall-puzzle's Issues

Line endings in `nom`

I was just watching your yt video on this puzzle here.

And while you were explaing your nom parser I stumbled about your line separating.

let (input, nodes) = separated_list0(tag("\n"), Puzzle::parse_node)(input)?;

This will break on \r\n formatted files. That should not be a problem per se but I wanted to point you to nom::character::complete::line_ending as the alternative to handle those specific endings a smidgen more robust.

Thank you for your excellent content ๐Ÿ˜„

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.