#! /bin/awk # TeX Sudoku Worksheet Generator # The output is a TeX source file. # # Copyright (C) 2005 John D. Ramsdell # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details at # http://www.gnu.org/copyleft/gpl.html. BEGIN { n = 10; # N is the number of pages printed print "\\nopagenumbers"; print "\\font\\tl=cmr17"; print "\\baselineskip=14pt"; print "\\newdimen\\sudokuwidth"; print "\\newdimen\\sudokuheight"; print "\\sudokuwidth=.7em"; print "\\sudokuheight=1.4ex"; print "\\def\\sudokustrut{\\hbox{\\vrule height\\sudokuheight depth0ex width0ex}}"; for (i = 0; i < n; i++) page(); print "\\end"; } function page() { print "\\sudokustrut\\vskip 2cm"; print; print "\\centerline{\\tl Sudoku Worksheet}\\bigskip\\bigskip"; print; print "\\centerline{\\offinterlineskip"; table(2); print "}"; print "\\vfil"; print "\\eject"; } function table(n, i) { if (n <= 0) tile(); else { print "\\vbox{\\hrule"; print "\\halign{\\vrule#\\tabskip=\\sudokuwidth&\\hfil#\\hfil&\\hfil#\\hfil&\\hfil#\\hfil&\\vrule#\\tabskip=0em\\cr"; for (i = 0; i < 3; i++) { print "&\\sudokustrut&\\sudokustrut&\\sudokustrut&\\cr"; printf("&"); table(n - 1); printf("&"); table(n - 1); printf("&"); table(n - 1); print "&\\cr"; } print "&\\sudokustrut&\\sudokustrut&\\sudokustrut&\\cr"; print "}\\hrule}\\relax"; } } function tile() { print "\\vbox{\\hrule"; print "\\halign{\\vrule#\\tabskip=\\sudokuwidth&\\hfil#\\hfil&\\hfil#\\hfil&\\hfil#\\hfil&\\vrule#\\tabskip=0em\\cr"; print "&\\sudokustrut&\\sudokustrut&\\sudokustrut&\\cr"; print "&1&2&3&\\cr"; print "&\\sudokustrut&\\sudokustrut&\\sudokustrut&\\cr"; print "&4&5&6&\\cr"; print "&\\sudokustrut&\\sudokustrut&\\sudokustrut&\\cr"; print "&7&8&9&\\cr"; print "&\\sudokustrut&\\sudokustrut&\\sudokustrut&\\cr"; print "}\\hrule}\\relax"; }