bridges-solver
TypeScript icon, indicating that this package has built-in type declarations

1.3.2 • Public • Published

Hashi Puzzle solver

This package allows you to solve the popular japanese puzzle Hashiwokakero (also known as Bridges, and Hashi). An application that implements this package is available at https://hashi-puzzles.com and the solver is available here.

Links

Solver

You can play with the solver on the Hashi Puzzles application at the following link:

Generator

Also, I have a hashi generator library that is available on

Installation

Install the package with npm.

npm install bridges-solver

Usage instructions

import { solver } from "bridges-solver";

const puzzle = [
  [0, 2, 0, 5, 0, 0, 2],
  [0, 0, 0, 0, 0, 0, 0],
  [4, 0, 2, 0, 2, 0, 4],
  [0, 0, 0, 0, 0, 0, 0],
  [0, 1, 0, 5, 0, 2, 0],
  [0, 0, 0, 0, 0, 0, 0],
  [4, 0, 0, 0, 0, 0, 3]
];

const result = solver(puzzle);

Simply import the solver and pass a matrix representing the puzzle where zeros represent empty spaces in the puzzle.

Result

The solver function returns a result object with the solved status, final solution and the intermediate puzzles (steps). The intermediate puzzles can be used to create an animation for the solving process or to help with debugging.

interface SolverResult {
  solved: boolean;
  solution: Puzzle;
  steps: Puzzle[];
}

The solution of the above puzzle:

[
  ["0", "2", "=", "5", "-", "-", "2"],
  ["0", "0", "0", "$", "0", "0", "|"],
  ["4", "=", "2", "$", "2", "=", "4"],
  ["$", "0", "0", "$", "0", "0", "|"],
  ["$", "1", "-", "5", "=", "2", "|"],
  ["$", "0", "0", "0", "0", "0", "|"],
  ["4", "=", "=", "=", "=", "=", "3"]
];

The solution contains special characters for the vertical and horizontal bridges:

Character Meaning
| one vertical bridge
$ two vertical bridges
- one horizontal bridge
= two horizontal bridges

Building

To build the package run the following script:

npm run build

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.3.24latest

Version History

VersionDownloads (Last 7 Days)Published
1.3.24
1.3.10
1.3.00
1.2.20
1.2.10
1.2.00
1.1.10
1.1.00
1.0.00
0.1.10
0.1.00

Package Sidebar

Install

npm i bridges-solver

Weekly Downloads

4

Version

1.3.2

License

MIT

Unpacked Size

37.3 kB

Total Files

6

Last publish

Collaborators

  • tonivrbic