GithubHelp home page GithubHelp logo

rgbz / mexican-train-domino-solver Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 85 KB

Finds the longest possible chain for a list of dominoes

License: MIT License

JavaScript 10.07% TypeScript 89.93%
dominoes

mexican-train-domino-solver's Introduction

Mexican Train Dominoes Solver

Playing Mexican Train Dominoes and want to find the optimal chain to start with?

Well here you go.

Quick Start

# install the dependencies (mainly TypeScript to build the code)
npm i

# Type in your dominoes and the side you need to connect them to
npm start 1x2,2x3,5x6,7x8,11x12,10x1,9x8,3x4,5x4,8x4,9x7,5x7 10

Details

  • Dominoes are represented with the numbered sides separated by an 'x'. e.g.: 1x2 or 10x11
  • The first argument to the program must be a comma separated list of dominoes
  • The second argument must be the number for the side you're trying to connect to

How's it work?

This program uses a lazy algorithm to traverse all possible chains given a sequence of dominoes starting from the specified side.

The algorithm has three phases:

  1. Find all possible "graphs" for the chain of dominoes. A "graph" in this case is a directed graph from each domino to every other possible domino it could be paired to.
  2. Traverse all possible paths for each generated graph starting from the specified side.
  3. Return the longest path found from all the paths we've generated.

The graph is represented as a map of side values to all the dominoes that contain that side.

mexican-train-domino-solver's People

Contributors

rgbz avatar

Stargazers

 avatar  avatar  avatar  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.