Giter VIP home page Giter VIP logo

sudoku's Introduction

sudoku

When I was nearly done with this, I realised that identical_possibilities is the general case of one_possibility, in which i=1, and unique_possibilities is just the general case of only_instance in which i=1. In any possible update this will be top of my list to address, along with cleaning up box_line_intersection.

How to use

To solve a particular sudoku, type in the starting values (0 taking the place of no value) into a single line of a document, save with the extension .sdk . Should not end with a new line. Then run:

python sudoku.py <path/to/document.sdk> 

To solve multiple sudokus one after another, simply add more rows to your document. To create a new file with the completed values, run:

python sudoku.py <path_to_document.sdk> <path/to/output.sdk>

I included sample_sudoku.sdk which contains 3 sudokus so you can test it.

The Algorithm

The term subgrid will be used when talking generally about a row, column, or box.

All possibilities true for all squares which have no value


while sudoku not completed:
	for square in grid:
		for possibilities in square:
		
			if possibility is revealed in the same row, column or box:
				remove possibility from square.
				return start
				
		if only one possibility:			
			square value = possibility
			return start
			
	for subgrid in grid:
		for possibility not determined in subgrid:
		
			if possibility is only possible in one square in subgrid:
				squares value = possibility
				return start
				
	for i in range(2,9):
		for subgrid in grid:
		
			if there exist i squares with exactly i 
			identical possibilities in subgrid:
				remove these possibilities from all other
				squares in subgrid, return start
				
			if there exist i squares which share i unique
			possibilities not found anywhere else in the subgrid:
				remove all other possibilities from these
				x squares, return start
				
	for subgrid in grid:
		for possibilities not yet determined in subgrid:
		
			if this possibility is only found in squares which are
			members of the same box:
				remove this possibility from
				all other squares in this box, return start
				
	for box in boxes:
		for possibilities not yet determined in box:
		
			if this possibility is only found in squares which
			are members of the same row or column:
				remove this possibility from all other squares 
				in this row or column, return start
	brute force a solution

sudoku's People

Contributors

swiftyy-mage avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.