#!/usr/bin/awk -f # a backtracking sudoku solver - marcus fritzsch http://fritschy.de 20070120 # # ./sudoku.awk < puzzle.txt # where puzzle is a file of 9 lines a nine characters in range # [0..9] where 0 stands for empty cells BEGIN { for (a=0; a<9; a++) for (b=0; b<9; b++) puzzle[a*9+b]=0 FS=""; cr=0; ctr=0 } { gsub(/-\. \*/,"0") for (b=0; b<9; b++) puzzle[cr*9+b-1]=int($b) cr++ } function IsValid () { for (i=0; i<9; i++) # check row and col if (puzzle[r*9+i]==s || puzzle[i*9+c]==s) return 0 for (a=int(r/3)*3; a