Go-sudoku - Sudoku generator and solver implementation in GoLang

go-sudoku

Build Status

An implementation of Sudoku generators and solvers in GoLang.

Usage

Help

$ ./go-sudoku --help
go-sudoku: A GoLang based Sudoku generator and solver.

Usage: go-sudoku [flags] <action>

Actions:
--------
  * generate: Generate a Sudoku Grid and apply the specified difficulty on it
  * solve: Solve a Sudoku puzzle provided in a text (CSV) file

Examples:
---------
  * ./go-sudoku
  * ./go-sudoku -algorithm back-tracking -theme green -seed 42 generate
  * ./go-sudoku -format csv generate
  * ./go-sudoku -input puzzle.csv solve
  * ./go-sudoku -difficulty hard -format csv generate | ./go-sudoku solve

Optional Flags:
---------------
  -algorithm string
    	Algorithm (back-tracking/brute-force) (default "back-tracking")
  -debug
    	Enable Debug Logging?
  -difficulty string
    	Difficulty (none/easy/medium/hard/insane) (default "medium")
  -format string
    	Rendering Format (csv/table) (default "table")
  -help
    	Display this usage and help text
  -input string
    	File containing a Sudoku Puzzle in CSV format
  -no-color
    	Disable colors in rendering? [$NO_COLOR]
  -pattern string
    	Pattern to use instead of Difficulty (diamond/octagon/square/star/target/triangle)
  -progress
    	Show progress in real-time with an artificial delay?
  -seed int
    	RNG Seed (0 => random number based on time) [$SEED]
  -theme string
    	Table formatting theme (none/blue/cyan/green/magenta/red/yellow) (default "none")
  -type string
    	Sudoku Type (default/jigsaw/samurai) (default "default")

Generator

Note: all the commands below were run with SEED=42 to keep the results reproducible.

$ ./go-sudoku generate
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃     8  5 │    6    │ 2     1  ┃
┃        7 │ 9  2    │          ┃
┃  6  3    │    5  1 │       4  ┃
┃ ─────────┼─────────┼───────── ┃
┃  2       │       8 │ 6  7     ┃
┃          │       2 │       9  ┃
┃     5    │    3  9 │          ┃
┃ ─────────┼─────────┼───────── ┃
┃  1  2  8 │       6 │ 9  5     ┃
┃  3  7  4 │ 2  9    │          ┃
┃  5       │ 1     7 │          ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃          Medium [42]          ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

## custom difficulty
$ ./go-sudoku -difficulty insane generate
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃     8    │    6    │ 2        ┃
┃          │         │          ┃
┃          │         │          ┃
┃ ─────────┼─────────┼───────── ┃
┃  2       │       8 │    7     ┃
┃          │       2 │          ┃
┃          │       9 │          ┃
┃ ─────────┼─────────┼───────── ┃
┃        8 │         │    5     ┃
┃  3     4 │         │          ┃
┃          │ 1       │          ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃          Insane [42]          ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

## custom pattern
$ ./go-sudoku -pattern diamond generate
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃          │    6    │          ┃
┃          │ 9  2  3 │          ┃
┃        2 │ 8     1 │ 7        ┃
┃ ─────────┼─────────┼───────── ┃
┃     4  9 │         │ 6  7     ┃
┃  8  6    │         │    1  9  ┃
┃     5  1 │         │ 4  2     ┃
┃ ─────────┼─────────┼───────── ┃
┃        8 │ 3     6 │ 9        ┃
┃          │ 2  9  5 │          ┃
┃          │    8    │          ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃          Diamond [42]         ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

## samurai sudoku
$ ./go-sudoku -type samurai generate
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃     1    │    2  8 │ 5     6 │         │ 4  8    │    2  1 │          ┃
┃  5       │         │         │         │       9 │ 8  4  7 │    6  3  ┃
┃  6       │ 5       │    2    │         │    1    │    9    │       8  ┃
┃ ─────────┼─────────┼─────────┤         ├─────────┼─────────┼───────── ┃
┃     4    │    8  5 │ 3  6  9 │         │       8 │         │ 6        ┃
┃          │ 3       │ 2     4 │         │    4  6 │ 2       │    9     ┃
┃  2  5  3 │ 9       │    7  8 │         │ 9       │         │ 8        ┃
┃ ─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼───────── ┃
┃     3  7 │ 4  6    │ 9     5 │ 7  6    │    3  1 │ 7  6    │ 4  5     ┃
┃     6  2 │         │    1    │ 9  2    │         │    3    │    1  2  ┃
┃  4     5 │         │       2 │         │         │ 5     2 │    8  6  ┃
┃ ─────────┴─────────┼─────────┼─────────┼─────────┼─────────┴───────── ┃
┃                    │                   │    7  3 │                    ┃
┃                    │         │ 4     2 │ 5       │                    ┃
┃                    │ 7       │    3  9 │    2  8 │                    ┃
┃ ─────────┬─────────┼─────────┼─────────┼─────────┼─────────┬───────── ┃
┃     7  6 │ 5  9    │       8 │ 3  4    │ 9  5    │ 1     4 │    3     ┃
┃  2     5 │       6 │    7    │ 2  9    │ 1       │    3  2 │       5  ┃
┃     4  1 │         │ 5  9    │ 1  8  7 │ 3     2 │ 5  7  6 │    8  1  ┃
┃ ─────────┼─────────┼─────────┼─────────┼─────────┼─────────┼───────── ┃
┃     1    │ 3  4    │       5 │         │ 7     9 │ 4  6    │    2  3  ┃
┃          │       7 │ 4  3  2 │         │    2    │    1    │          ┃
┃     3  2 │         │       7 │         │ 6  3  4 │ 2       │    1     ┃
┃ ─────────┼─────────┼─────────┤         ├─────────┼─────────┼───────── ┃
┃  6     7 │ 4  3  9 │         │         │         │ 7       │ 1        ┃
┃        4 │       1 │ 7  8    │         │ 4       │ 8     3 │ 6        ┃
┃     2    │    7    │    4    │         │ 2       │       1 │ 3        ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃                          Samurai Medium [42]                          ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

Solver

Note: all the commands below were run with SEED=42 to keep the results reproducible.

## generate a new puzzle and feed it to the solver to solve
$ ./go-sudoku -format csv generate | ./go-sudoku solve
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃             INPUT             ┃             OUTPUT            ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃     8  5 │    6    │ 2     1  ┃  9  8  5 │ 7  6  4 │ 2  3  1  ┃
┃        7 │ 9  2    │          ┃  4  1  7 │ 9  2  3 │ 8  6  5  ┃
┃  6  3    │    5  1 │       4  ┃  6  3  2 │ 8  5  1 │ 7  9  4  ┃
┃ ─────────┼─────────┼───────── ┃ ─────────┼─────────┼───────── ┃
┃  2       │       8 │ 6  7     ┃  2  4  9 │ 5  1  8 │ 6  7  3  ┃
┃          │       2 │       9  ┃  8  6  3 │ 4  7  2 │ 5  1  9  ┃
┃     5    │    3  9 │          ┃  7  5  1 │ 6  3  9 │ 4  2  8  ┃
┃ ─────────┼─────────┼───────── ┃ ─────────┼─────────┼───────── ┃
┃  1  2  8 │       6 │ 9  5     ┃  1  2  8 │ 3  4  6 │ 9  5  7  ┃
┃  3  7  4 │ 2  9    │          ┃  3  7  4 │ 2  9  5 │ 1  8  6  ┃
┃  5       │ 1     7 │          ┃  5  9  6 │ 1  8  7 │ 3  4  2  ┃
┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
┃       45 blocks to solve      ┃          3621 cycles          ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Owner
Similar Resources

XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator

xgen Introduction xgen is a library written in pure Go providing a set of functions that allow you to parse XSD (XML schema definition) files. This li

Jan 1, 2023

Fast and secure initramfs generator

Fast and secure initramfs generator

Booster - fast and secure initramfs generator Initramfs is a specially crafted small root filesystem that mounted at the early stages of Linux OS boot

Dec 28, 2022

Random fake data generator written in go

Random fake data generator written in go

Gofakeit Random data generator written in go Features 160+ Functions!!! Concurrent Global Rand Struct Generator Custom Functions Http Server Command L

Jan 1, 2023

Unit tests generator for Go programming language

Unit tests generator for Go programming language

GoUnit GoUnit is a commandline tool that generates tests stubs based on source function or method signature. There are plugins for Vim Emacs Atom Subl

Jan 1, 2023

GObject-introspection based bindings generator

WARNING! This project is no longer maintained. Probably doesn't even compile. GObject-introspection based bindings generator for Go. Work in progress

Jan 5, 2022

Typo/error resilient, human-readable token generator

toktok A human-friendly token generator Creates tokens which avoid characters that can be easily misinterpreted, like '1' and 'I' or '8' and 'B', as w

Sep 16, 2022

Jennifer is a code generator for Go

Jennifer Jennifer is a code generator for Go. package main import ( "fmt" . "github.com/dave/jennifer/jen" ) func main() { f := NewFile("m

Dec 25, 2022

Default godoc generator - make your first steps towards better code documentation

godoc-generate Overview godoc-generate is a simple command line tool that generates default godoc comments on all exported types, functions, consts an

Sep 14, 2022

accessor methods generator for Go programming language

accessory accessory is an accessor generator for Go programming language. What is accessory? Accessory is a tool that generates accessor methods from

Nov 15, 2022
Wordle-solver - A simple solver for Wordle puzzles that uses letter- and word-frequencies to narrow down possible guesses

Wordle Solver A simple solver for Wordle puzzles that uses letter- and word-freq

Jan 9, 2022
Wordle - Simple wordle solver with golang

wordle Simple wordle solver Lets see it in action: $ ./wordle 5914 possible rem

May 19, 2022
Solver for wordle hard mode - achieves 5 attempts or less 100% of the time

wordier Solver for wordle hard mode - achieves 5 attempts or less 100% of the time Example - Spoiler ➜ wordier git:(master) ✗ go run main.go scamp ➜

Jan 12, 2022
:guardsman: A teeny tiny and somewhat opinionated generator for your next golang project

A Yeoman Golang Generator We are very sorry Gophers, but other names for the generator where taken, so we choose go-lang. But we have gocreate as an a

Sep 27, 2022
General Golang Code Generator

gg gg is a General Golang Code Generator: A Good Game to play with Golang. package main import ( "fmt" . "github.com/Xuanwo/gg" ) func main() {

Jan 7, 2023
RinkWorks fantasy name generator in golang

RinkWorks fantasy name generator in golang

Dec 25, 2022
Go Param Generator for golang

Go Param Generator Overview Generates struct's for you. No need to write it by hands Adds Getters and Setters Adds Constructor Easy to use Usage gopar

Dec 13, 2021
Autoname - Friendly names generator with golang

autoname Friendly names generator inspired by moby's work. import "github.com/ci

Oct 16, 2022
Random fake data and struct generator for Go.

Faker Random fake data and struct generator for Go. More than 100 generator functions Struct generator Unique data generator Builtin types support Eas

Oct 3, 2022
A distributed unique ID generator of using Sonyflake and encoded by Base58

Indigo About A distributed unique ID generator of using Sonyflake and encoded by Base58. ID max length is 11 characters by unsigned int64 max value. A

Nov 24, 2022