# Braunson / LICENSE.txt Created September 30, 2011 — forked from p01/LICENSE.txt

### SSH clone URL

You can clone with HTTPS or SSH.

Sudoku Solver in 140bytes

 1 2 3 4 5 6 7 8 9 10 11 12 13 ``` DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE Version 2, December 2004   Copyright (C) 2011 Mathieu 'p01' Henri   Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed.   DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION   0. You just DO WHAT THE FUCK YOU WANT TO. ```

# Sudoku Solver in 140 bytes

Solve a Sudoku grid only using magic, recursion, and 140bytes of brute force.

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ```function R ( a, // the array representing the sudoko grid   // placeholder arguments i, // index of the last empty cell j, // index to check the candidates for the cell 'i' m, // candidate number for the the cell 'i' g // flag whether 'm' is a already used in the same row|col|node as 'i' ){ // phase 1: look for an empty cell for ( i=80; a[i]; // keep going if the cell isn't empty i--||+a // decrease the index and call 'a.toString()' if we went through the whole grid ); // phase 2: check all candidate numbers for the cell 'i' for ( m=10; g=a[i]=--m; // put the candidate in the cell 'i' already and set 'g' to something truthy // at the end of phase 2, the cell 'i' is reset to 0 for "higher" branches of the recursion g&&R(a) // recurse if 'm' isn't already used in the same row|col|node as 'i' ) // phase 3: check if the candidate number is used already for(j in a) // loop through the whole grid again g*= // turn 'g' falsy if a[j^i==j] // we are not on the cell 'i' ^m // and the cell 'j' is set to 'm' || // and we are in the same row|col|node as 'i' i/9^j/9&&i%9^j%9&&i/27^j/27|i%9/3^j%9/3 } ```
 1 2 3 4 5 6 7 8 9 10 11 12 ```{ "name": "sudokuSolver",   "description": "Brute force sudoku solver.",   "keywords": [ "sudoku", "solver", "recursive", "brute force" ] } ```
 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 ``` Foo