• Stars
    star
    123
  • Rank 290,145 (Top 6 %)
  • Language
    Go
  • Created about 9 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Sudoku puzzle solver and generator

suGOku

https://sugoku.onrender.com/

Go Challenge 8 solution for the month of November 2015.

Overview

Sudoku web app: solves, generates, grades, and validates sudoku puzzles.

The algorithm implements two solving functions:

  1. QuickFill - Called so because it quickly checks horizontally, vertically and in the nine grid box for possible options. If only one possible solution remains, it adds the value to the square.

  2. Guess - It fills an empty square with a possible, non-conflicting value. If the puzzle is solved (completely filled), it validates to see if it correct. If not, it goes back and fills the square with another possible value. It recursively fills in and backtracks until the puzzle is complete.

A very interesting finding was that implementing the QuickFill function before each guess did not improve the speed of the algorithm, in fact, it slowed it down. I was not expecting it. I was so surprised that I decided to keep the original name I had given the function without Quickfill: SlowSolve().

SlowSolve is the faster function and therefore the one used for the API.

Installation

go get github.com/bertoort/sugoku

Technologies

API

Get

Board - returns a puzzle board

https://sugoku.onrender.com/board

Arguments -

  • Difficulty:
    • easy
    • medium
    • hard
    • random

Example:

https://sugoku.onrender.com/board?difficulty=easy

Post

Solve - returns the solved puzzle, along with difficulty and status

https://sugoku.onrender.com/solve

Grade - returns the difficulty of the puzzle

https://sugoku.onrender.com/grade

Validate - returns the status of the puzzle

https://sugoku.onrender.com/validate

NOTE:

The request does not support content-type of application/json. It must be application/x-www-form-urlencoded

To help, here is a quick and dirty encoding functions for a board:

const encodeBoard = (board) => board.reduce((result, row, i) => result + `%5B${encodeURIComponent(row)}%5D${i === board.length -1 ? '' : '%2C'}`, '')

const encodeParams = (params) =>
  Object.keys(params)
  .map(key => key + '=' + `%5B${encodeBoard(params[key])}%5D`)
  .join('&');

Here is an example sending a board:

const data = {board:[[0,0,0,0,0,0,8,0,0],[0,0,4,0,0,8,0,0,9],[0,7,0,0,0,0,0,0,5],[0,1,0,0,7,5,0,0,8],[0,5,6,0,9,1,3,0,0],[7,8,0,0,0,0,0,0,0],[0,2,0,0,0,0,0,0,0],[0,0,0,9,3,0,0,1,0],[0,0,5,7,0,0,4,0,3]]}

fetch('https://sugoku.onrender.com/solve', {
  method: 'POST',
  body: encodeParams(data),
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
})
  .then(response => response.json())
  .then(response => console.log(response.solution))
  .catch(console.warn)
jQuery Example:
var data = {
  board: "[[0,0,1,0,0,0,0,0,0],
          [2,0,0,0,0,0,0,7,0],
          [0,7,0,0,0,0,0,0,0],
          [1,0,0,4,0,6,0,0,7],
          [0,0,0,0,0,0,0,0,0],
          [0,0,0,0,1,2,5,4,6],
          [3,0,2,7,6,0,9,8,0],
          [0,6,4,9,0,3,0,0,1],
          [9,8,0,5,2,1,0,6,0]]"
}
$.post('https://sugoku.onrender.com/solve', data)
  .done(function (response) {

    <% response = {
      difficulty: "hard",
      solution: Array[9],
      status: "solved"
    } &>

  });```

For more, check out the [api.js](https://github.com/bertoort/sugoku/blob/master/public/api.js) file

More Repositories

1

flashcards

Flashcard app for the terminal
Go
10
star
2

Go-OAuth-JWT-Demo

Go
6
star
3

fog-of-war

Rust game with GGEZ
Rust
5
star
4

terminal-countdown-timer

Set a time, it counts down from then
Haskell
4
star
5

waffles-game-theory

Web Socket Game
Go
3
star
6

yo-java-gradle

JavaScript
3
star
7

monsters-restful-api

Monsters RESTful API
TypeScript
3
star
8

spectacle-present

JavaScript
3
star
9

snek

๐Ÿ Web Assembly Snake Game ๐ŸŽ
Rust
3
star
10

donuts

Two-player puzzle game
JavaScript
3
star
11

rails-install

2
star
12

users-stickers-client

HTML
2
star
13

vango

Posts a generated image to Twitter
Go
2
star
14

canvas

JavaScript
2
star
15

dotfiles

welcome to the dark side
Vim Script
2
star
16

nyancat-chrome-extension

JavaScript
2
star
17

mountain-project

JavaScript
2
star
18

go1.8-http-talk

Go
2
star
19

time-lapse

Time Lapse client displaying S3 images uploaded by a Raspberry Pi
Go
2
star
20

vuex-demo

JavaScript
2
star
21

war

Card game simulator and analysis
JavaScript
1
star
22

s3-image-upload-demo

JavaScript
1
star
23

infinite-scrolling

Multi-directional Infinite Scrolling
JavaScript
1
star
24

mongo-server

JavaScript
1
star
25

belote

2 person Belote card game
C#
1
star
26

geopardy

CSS
1
star
27

twitch-streams

HTML
1
star
28

battleship

JavaScript
1
star
29

fun-logger

Fun, experimental project with the client console
JavaScript
1
star
30

adventofcode

Advent of Code ๐ŸŽ„
Go
1
star
31

puppy

Go
1
star
32

nqueens

Quick go solution to n queens problem through backtracking/recursion
Go
1
star
33

circleci

JavaScript
1
star
34

go-challenges

Go
1
star
35

micro-frontends

Dvldnvr talk demo app
JavaScript
1
star
36

golang-intro

Introduction to Golang resources
Go
1
star
37

travel-map

Personal map of where I've been, lived, and want to go
JavaScript
1
star
38

udraw

Command line unicode drawing tool
Shell
1
star