SkillAgentSearch skills...

Dlx

A Go implementation of Knuth's algorithm DLX (algorithm X implemented in terms of dancing links)

Install / Use

/learn @dimchansky/Dlx
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

dlx Build Status Coverage Status Godoc

dlx is a Go implementation of Knuth's algorithm DLX (algorithm X implemented in terms of dancing links)

A fantastic explanation of dancing links algorithm can be found here (PDF).

Installation

go get github.com/dimchansky/dlx

Examples

There is sudoku solver included. The solver code provides an example of using dlx library to solve Sudoku.

Consider the exact cover problem specified by the matrix:

| 0 | 1 | 2 | 3 | 4 | 5 | 6 | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | | 1 | 0 | 0 | 1 | 0 | 0 | 1 | | 1 | 0 | 0 | 1 | 0 | 0 | 0 | | 0 | 0 | 0 | 1 | 1 | 0 | 1 | | 0 | 0 | 1 | 0 | 1 | 1 | 0 | | 0 | 1 | 1 | 0 | 0 | 1 | 1 | | 0 | 1 | 0 | 0 | 0 | 0 | 1 |

The following code finds all solutions to the exact cover problem:

m := dlx.NewMatrix(7)
m.AddRow(0, 3, 6)
m.AddRow(0, 3)
m.AddRow(3, 4, 6)
m.AddRow(2, 4, 5)
m.AddRow(1, 2, 5, 6)
m.AddRow(1, 6)

m.Solve(dlx.SolutionAccepterFunc(func(exactCover [][]int) bool {
	fmt.Println("Solution found:")
	for _, row := range exactCover {
		fmt.Println(row)
	}
	return false
}))

The code output:

Solution found:
[0 3]
[2 4 5]
[1 6]
View on GitHub
GitHub Stars10
CategoryDevelopment
Updated1y ago
Forks4

Languages

Go

Security Score

60/100

Audited on Sep 13, 2024

No findings