%% %% This is file `printsudoku.sty', %% generated with the docstrip utility. %% %% The original source files were: %% %% sudokubundle.dtx (with options: `print') %% %% ----------------------------------------------------------------- %% Author: Peter Wilson (herries dot press at earthlink dot net) %% Herries Press %% Copyright 2006 Peter R. Wilson %% %% This work may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either %% version 1.3 of this license or (at your option) any %% later version. %% The latest version of the license is in %% http://www.latex-project.org/lppl.txt %% and version 1.3 or later is part of all distributions of %% LaTeX version 2003/06/01 or later. %% %% This work has the LPPL maintenance status "author-maintained". %% %% This work consists of the files listed in the README file. %% ----------------------------------------------------------------- %% %%%% solvethem.tex Solve Sudoku files %%%% Peter Wilson \NeedsTeXFormat{LaTeX2e} \ProvidesPackage{printsudoku}[2006/02/16 v1.0 typeset sudoku puzzles] \newread\s@dread \newwrite\s@dwrite %%%% open game file \newcommand*{\reads@dgame}[1]{% \closein\s@dread \openin\s@dread=#1} %%% set size of a game cell \newlength\halfs@dcell \newcommand*{\cellsize}[1]{% \halfs@dcell=#1\relax \halfs@dcell=0.5\halfs@dcell} \cellsize{2.5\baselineskip} %% set font for the numbers \newcommand*{\cluefont}[1]{\def\s@dfont{#1}} \cluefont{\Huge} %% counts for looping and cell positions \newcount\s@dncol \newcount\s@dnrow \newcount\s@dcolpos \newcount\s@drowpos %% insert the clues into the game array \newcommand*{\adds@dclues}{% \firsts@dcluetrue \s@dnrow\@ne \loop \ifnum\s@dnrow<10\relax \read\s@dread to \s@dline \firsts@dcluetrue \s@drowpos=\s@dnrow \multiply\s@drowpos\tw@ \advance\s@drowpos\m@ne \s@dncol\@ne \dos@dcols \advance\s@dnrow\@ne \repeat \closein\s@dread} %% insert a row of clues \newcommand*{\dos@dcols}{% \bgroup \loop \ifnum\s@dncol<10\relax \s@dcolpos=\s@dncol \multiply\s@dcolpos\tw@ \advance\s@dcolpos\m@ne \put(\s@dcolpos,-\s@drowpos){\makebox(0,0){\s@dfont\gets@dclue}}% \advance\s@dncol\@ne \repeat \egroup} %% get the next character in a string \def\gettwo#1#2\nowt{% \gdef\istchar{#1}\gdef\restchars{#2}} \def\splitoff#1{\gettwo#1\nowt} %% a full stop (period) \gdef\s@dfstop{.} %% get the next clue in the line \newif\iffirsts@dclue \firsts@dcluetrue \newcommand*{\gets@dclue}{% \iffirsts@dclue \expandafter\splitoff\expandafter{\s@dline}% \global\firsts@dcluefalse \else \expandafter\splitoff\expandafter{\restchars}% \fi \ifx\s@dfstop\istchar \else \istchar \fi} %% typeset the grid, then add the clues \newcommand*{\s@dgame}{% \setlength\unitlength\halfs@dcell \begin{picture}(18,18)(0,-18) \thinlines \multiput(0,0)(2,0){10}{\line(0,-1){18}} \multiput(0,0)(0,-2){10}{\line(1,0){18}} \thicklines \linethickness{1pt} \multiput(0,0)(6,0){4}{\line(0,-1){18}} \multiput(0,0)(0,-6){4}{\line(1,0){18}} \adds@dclues \end{picture}} %% the whole shebang, where #1 is the name of the game file \newcommand*{\sudoku}[1]{% \reads@dgame{#1}% \s@dgame} \newcommand*{\puzzlefile}{puzz.sud} \newcommand*{\writepuzzle}[9]{% \immediate\closeout\s@dwrite \immediate\openout\s@dwrite=\puzzlefile \immediate\write\s@dwrite{#1}% \immediate\write\s@dwrite{#2}% \immediate\write\s@dwrite{#3}% \immediate\write\s@dwrite{#4}% \immediate\write\s@dwrite{#5}% \immediate\write\s@dwrite{#6}% \immediate\write\s@dwrite{#7}% \immediate\write\s@dwrite{#8}% \immediate\write\s@dwrite{#9}% \writes@dpuzzend} \newcommand*{\writes@dpuzzend}[1][\@empty]{ \ifx\@empty #1\else \immediate\write\s@dwrite{ }% \immediate\write\s@dwrite{#1}% \fi \immediate\closeout\s@dwrite} \newcommand*{\sudpuzznewline}{^^J} \endinput %% %% End of file `printsudoku.sty'.