~shiny/sudoku

7639694d6f858ac2690f048dab003243eec54689 — Thomas Spurden 12 years ago 0b6d0e1
Modifications
1 files changed, 3 insertions(+), 3 deletions(-)

M src/small3.c
M src/small3.c => src/small3.c +3 -3
@@ 1,14 1,14 @@
#include <unistd.h>

int s(int n, int c, char* g, int* p, int l, int x, int y) {
	if(g[*p] > 48) return s(n+1, 0, g, p+1, l, x, y);
	int f = 0;
	int k = (g[*p] > 48);
	char tc = 49+c+((c>8)*7);
	for(int r = -n%l; !f && r < l-n%l; r++) f |= (g[p[r]] == tc);
	for(int c = n%l; !f && c < l*l; c += l) f |= (g[p[c-n]] == tc);
	for(int b = x*((n/x)%(l/x)); !f && b < y; b += l) for(int i = 0; i < x; f |= (g[p[b-n%y+i++]] == tc));
	return ((k || (!f && (g[*p] = tc))) && (n+1 >= l*l || s(n+1, 0, g, p+1, l, x, y)))
		|| (!k && ((g[*p] = 48) && c+1 != l && s(n, c+1, g, p, l, x, y)));
	return (!f && (g[*p] = tc) && (n+1 >= l*l || s(n+1, 0, g, p+1, l, x, y)))
		|| ((g[*p] = 48) && c+1 != l && s(n, c+1, g, p, l, x, y));
}

int main() {