# Search results

0

## JS Quick sort

Daniel Ge

function chSort(list) {
var max = list[0],
min = list[0],
asc = !0;
for (i in list) list[i] > max ? max = list[i] : list[i] < min && (min = list[i]), list[i - 1] > list[i] && (asc = !1);
if (asc) return list;
var minList = [],
maxList = [],
pivot = min + (max - min) / 2;
for (i in list) (list[i] > pivot ? maxList : minList).push(list[i]);
return [].concat(chSort(minList), chSort(maxList));
};

A tiny implementation of quick sort in JS (http://www.reddit.com/r/tinycode/c...
created over 8 years ago

Tags: javascript quick-sort

2

## Tiny sudoku solver

Daniel Ge

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
}

A tiny sudoku solver written in JS (https://gist.github.com/1230481/95f6facb7...
created over 8 years ago

Tags: javascript sudoku

0

## Sudoku solver (even tinier!)

Daniel Ge

function R(a,i,j,m,g){for(i=80;a[i];i--||+a);for(m=10;g=a[i]=--m;g&&R(a))for(j in a)g*=a[j^i==j]^m||i/9^j/9&&i%9^j%9&&i/27^j/27|i%9/3^j%9/3}

Even tinier js sudoku solver
created over 8 years ago

Tags: javascript sudoku