summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/logicpuzzle
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2013-04-13 22:57:32 +0000
committerKarl Berry <karl@freefriends.org>2013-04-13 22:57:32 +0000
commit5cc36a171f8092e44ab898ee2e44446b5c4a2949 (patch)
tree4ee8dd508166a45c92a2eac14aea6ce9cd6989e7 /Master/texmf-dist/scripts/logicpuzzle
parent934ca9c7cea256e522389fcd652070ac2e378efa (diff)
logicpuzzle (13apr13)
git-svn-id: svn://tug.org/texlive/trunk@29897 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/scripts/logicpuzzle')
-rwxr-xr-xMaster/texmf-dist/scripts/logicpuzzle/createlpsudoku91
-rwxr-xr-xMaster/texmf-dist/scripts/logicpuzzle/lpsmag175
-rwxr-xr-xMaster/texmf-dist/scripts/logicpuzzle/simple.smc7
3 files changed, 273 insertions, 0 deletions
diff --git a/Master/texmf-dist/scripts/logicpuzzle/createlpsudoku b/Master/texmf-dist/scripts/logicpuzzle/createlpsudoku
new file mode 100755
index 00000000000..7738198e33a
--- /dev/null
+++ b/Master/texmf-dist/scripts/logicpuzzle/createlpsudoku
@@ -0,0 +1,91 @@
+#!/bin/bash
+#
+# createlpsudoku [options] [-o output] -i input
+#
+# transforms Sudokus in 81 format (-e) or Simple Sudoku format (-s)
+# into lpsudoku environments for lpsudoku.sty
+#
+# License: LPPL
+#
+FORMAT="81"
+VERSION="v1.1"
+LINEENDINGS="UNIX"
+IFILE=""
+OFILE=""
+#
+typeset -i SLBEGIN=1
+typeset -i SLEND=9
+typeset -i COUNT=9
+#
+while getopts "eshwvi:o:" FLAG
+do
+ case "$FLAG" in
+ e) FORMAT="81";;
+ s) FORMAT="ss";;
+ w) LINEENDINGS="WINDOWS";;
+ i) IFILE="$OPTARG";;
+ o) OFILE="$OPTARG";;
+ h) echo "`basename $0` [options] [-o output] -i input"; exit 0;;
+ v) echo "`basename $0` $VERSION (C) 2013 Josef Kleber"; exit 0;;
+ esac
+done
+#
+if [ -z "$IFILE" ]
+then
+ echo "no input file"
+ echo "Usage: `basename $0` [options] [-o output] -i input"
+ exit 1
+fi
+#
+if [ ! -e "$IFILE" ]
+then
+ echo "ERROR: input file $IFILE does not exist"
+ exit 1
+fi
+#
+if [ -n "$OFILE" ]
+then
+ exec 1> $OFILE
+fi
+#
+if [ "$FORMAT" = "ss" ]
+then
+ echo "\begin{lpsudoku}"
+ for SDLINE in `cat $IFILE | sed -e '1d' -e'5d' -e'9d' -e'13,200d' | sed -e 's/|//g' | sed -e's/^[[:space:]]//g'`
+ do
+ ROWARG=`echo $SDLINE | sed -e's/\./{},/g' -e's/\([[:digit:]]\)/\1,/g' | sed -e's/,$//'`
+ echo " \setrow{$COUNT}{$ROWARG}"
+ ((COUNT--))
+ done
+ echo "\end{lpsudoku}"
+ echo
+fi
+#
+if [ "$FORMAT" = "81" ]
+then
+ for SUDOKU in `cat $IFILE | sed -e's/#.*//'`
+ do
+ echo "\begin{lpsudoku}"
+ while [ $COUNT -gt 0 ]
+ do
+ SDLINE=`echo $SUDOKU | cut -c${SLBEGIN}-${SLEND}`
+ ROWARG=`echo $SDLINE | sed -e's/\./{},/g' -e's/\([[:digit:]]\)/\1,/g' | sed -e's/,$//'`
+ echo " \setrow{$COUNT}{$ROWARG}"
+ ((COUNT--))
+ ((SLBEGIN+=9))
+ ((SLEND+=9))
+ done
+ SLBEGIN=1
+ SLEND=9
+ COUNT=9
+ echo "\end{lpsudoku}"
+ echo
+ done
+fi
+#
+if [ -n "$OFILE" -a "$LINEENDINGS" = "WINDOWS" ]
+then
+ unix2dos -q $OFILE
+fi
+#
+exit 0 \ No newline at end of file
diff --git a/Master/texmf-dist/scripts/logicpuzzle/lpsmag b/Master/texmf-dist/scripts/logicpuzzle/lpsmag
new file mode 100755
index 00000000000..9e7725b1b47
--- /dev/null
+++ b/Master/texmf-dist/scripts/logicpuzzle/lpsmag
@@ -0,0 +1,175 @@
+#!/bin/bash
+#
+# lpsmag CONFIGFILE
+#
+# creates a LaTeX file for the production
+# a Sudoku magazine with lpsudoku.sty
+#
+# License: LPPL
+#
+CONFIGFILE="$1"
+TEXFILE="lpsmag.tex"
+TEXFILEBAK="${TEXFILE}.bak"
+typeset -i COUNT=0
+SUDOKUPP="6"
+SUDOKUPPD="12"
+#
+if [ -z "$CONFIGFILE" ]
+then
+ echo "no config file"
+ echo "Usage: `basename $0` configfile"
+ exit 1
+fi
+#
+exec 1> $TEXFILE
+#
+startpuzzles()
+{
+ echo "\lpsudokusetup{scale=0.75,width=6.8cm,fontsize=Large,cvoffset=-24pt}"
+ echo "\setpuzzlecounter{1}"
+}
+#
+startsolutions()
+{
+ echo "\lpsudokusetup{scale=0.5,width=4.6cm,fontsize=normalsize}"
+ echo "\setpuzzlecounter{1}"
+}
+#
+page()
+{
+ local name="$1"
+ local difficulty="$2"
+ qqwing --generate $SUDOKUPP --one-line --difficulty $difficulty >${name}.81
+ cat ${name}.81 | qqwing --solve --one-line >${name}_sol.81
+}
+#
+typesetpage()
+{
+ local name="$1"
+ local last="$2"
+ local puzzlenummer="uneven"
+ COUNT=0
+ echo "%startpage"
+ for puzzle in `cat ${name}.81`
+ do
+ ((COUNT++))
+ echo $puzzle >puzzle.81
+ createlpsudoku -i puzzle.81
+ if [ "$puzzlenummer" = "uneven" ]
+ then
+ echo "\hfill"
+ # toggle even/uneven
+ puzzlenummer="even"
+ else
+ # no \vfill after last lpsudoku
+ # environment of the page
+ if [ $COUNT -lt $SUDOKUPP ]
+ then
+ echo "\vfill"
+ else
+ if [ "$last" != "last" ]
+ then
+ echo "\clearpage"
+ fi
+ fi
+ puzzlenummer="uneven"
+ fi
+ done
+}
+#
+tspfor()
+{
+ local name="$1"
+ local last="$2"
+ local puzzlepos="one"
+ for puzzle in `cat ${name}.81`
+ do
+ ((COUNT++))
+ if [ $COUNT -eq 1 -o $COUNT -eq 7 ]
+ then
+ echo "%startpage"
+ fi
+ echo $puzzle >puzzle.81
+ createlpsudoku -i puzzle.81
+ if [ "$puzzlepos" = "one" ]
+ then
+ echo "\hfill"
+ puzzlepos="two"
+ elif [ "$puzzlepos" = "two" ]
+ then
+ echo "\hfill"
+ puzzlepos="three"
+ else
+ if [ $COUNT -lt $SUDOKUPPD ]
+ then
+ echo "\vfill"
+ puzzlepos="one"
+ else
+ if [ "$last" = "last" ]
+ then
+ puzzlepos="one"
+ else
+ echo "\clearpage"
+ puzzlepos="one"
+ fi
+ fi
+ fi
+ done
+}
+#
+typesetsolpage()
+{
+ local name1="$1_sol"
+ local name2="$2_sol"
+ local last="$3"
+ COUNT=0
+ tspfor $name1 $last
+ tspfor $name2 $last
+}
+#
+addcounterstyle()
+{
+ grep -ne'startpage' $TEXFILE | cut -d':' -f1 >csl.tmp
+ for linenumber in `cat csl.tmp`
+ do
+ COUNT="$linenumber"
+ ((COUNT++))
+ echo "$COUNT a [counterstyle=left]" >>sed.tmp
+ echo "$linenumber d" >>sed.tmp
+ done
+ sed -f sed.tmp $TEXFILE >$TEXFILEBAK
+ rm $TEXFILE
+ mv $TEXFILEBAK $TEXFILE
+}
+#
+addpercent()
+{
+ sed -e's/$/%/' $TEXFILE >$TEXFILEBAK
+ rm $TEXFILE
+ mv $TEXFILEBAK $TEXFILE
+}
+#
+deleteauxfiles()
+{
+ rm *.81
+ rm *.tmp
+}
+#
+cat >preamble.tmp <<EOF
+\documentclass[a4paper]{article}%
+\usepackage[bottom=3cm,top=3cm,left=2.7cm,right=2.7cm]{geometry}
+\usepackage[width=5cm,scale=0.55,fontsize=normalsize]{lpsudoku}%
+EOF
+#
+cat preamble.tmp
+echo "\begin{document}"
+#
+. $CONFIGFILE
+#
+echo "\end{document}"
+#
+addcounterstyle
+addpercent
+deleteauxfiles
+exit 0
+# \ No newline at end of file
diff --git a/Master/texmf-dist/scripts/logicpuzzle/simple.smc b/Master/texmf-dist/scripts/logicpuzzle/simple.smc
new file mode 100755
index 00000000000..0ec2d162199
--- /dev/null
+++ b/Master/texmf-dist/scripts/logicpuzzle/simple.smc
@@ -0,0 +1,7 @@
+page p1 easy
+page p2 easy
+startpuzzles
+typesetpage p1
+typesetpage p2
+startsolutions
+typesetsolpage p1 p2 last \ No newline at end of file