Skip to content

Given an n by m grid of vertices, draw a line between the vertices starting at a vertex v and finishing at another vertex w, visiting each exactly once.

License

Notifications You must be signed in to change notification settings

whatsacomputertho/grid-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid Solver

Given an n by m grid of vertices, draw a line between the vertices starting at a vertex v and finishing at another vertex w, visiting each exactly once.

About

CLI Usage

This utility implements algorithms for the existence & construction of a Hamiltonian path in an arbitrary grid graph.

For more details, see:

Usage

Draw a Hamiltonian path between two vertices in a grid graph G(n, m)

Usage: grid-solver.exe [OPTIONS]

Options:
      --width <WIDTH>      Width of the grid
      --height <HEIGHT>    Height of the grid
      --start-x <START_X>  Start vertex x coordinate
      --start-y <START_Y>  Start vertex y coordinate
      --end-x <END_X>      End vertex x coordinate
      --end-y <END_Y>      End vertex y coordinate
  -h, --help               Print help
  -V, --version            Print version

Motivation

At a recent IBM potluck, employees were presented with the following toy problem - draw a straight line through all points in the below grid starting at the start point and ending at the end point.

blank-grid

These instructions were vague as they did not explicitly state the validity of certain moves. Solutions were found both involving moving diagonally between points, and leaving the grid. However, these were both considered "exceptions"; the ideal solution would only utilize moves contained within the graph between immediately adjacent points in the right, left, up, and down directions. However, no such solution could be found by participants.

failed-attempt

I set off to write a program that would solve any general grid problem like this one. In the process, I discovered that the problem had been formalized and thoroughly explored in Hamilton Paths in Grid Graphs. I then decided to implement the algorithms described in this paper, and to communicate the results discussed in the paper (which I think are quite interesting) in this repository.

About

Given an n by m grid of vertices, draw a line between the vertices starting at a vertex v and finishing at another vertex w, visiting each exactly once.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages