# logicpuzzle

A LaTeX style file for typesetting logic puzzles

kendoku

# Kendoku

## The puzzle

Fill the cells with the numbers from 1 to SIZE of the puzzle. In the top left corner of a framed area, you will find the result of the specified arithmetic function, which is applied on the entered numbers. The numbers may occur only once in each row and column. The numbers of an area may not necessarily be different when they are in different rows or columns. Here’s a little self-explanatory example:

\begin{center}
\begin{kendoku}
\framearea{black}{\tikzpath{1}{1}{8,8,6,2,6,2,4,4}}
\framearea{black}{\tikzpath{1}{3}{8,6,2,4}}
\framearea{black}{\tikzpath{1}{4}{8,8,6,2,2,4}}
\framearea{black}{\tikzpath{2}{2}{8,8,6,6,2,4,2,4}}
\framearea{black}{\tikzpath{2}{4}{8,8,6,2,2,4}}
\framearea{black}{\tikzpath{3}{1}{8,8,6,2,2,4}}
\framearea{black}{\tikzpath{3}{4}{8,8,6,6,2,4,2,4}}
\framearea{black}{\tikzpath{4}{1}{8,6,6,2,4,4}}
\framearea{black}{\tikzpath{4}{2}{8,6,6,2,4,4}}
\framearea{black}{\tikzpath{4}{3}{8,8,6,2,2,4}}
\framearea{black}{\tikzpath{5}{3}{8,6,2,4}}
\framearea{black}{\tikzpath{5}{4}{8,6,2,4}}
\framearea{black}{\tikzpath{5}{5}{8,6,2,4}}
\setrule{1}{2}{8\times}
\setrule{1}{3}{5}
\setrule{1}{5}{4+}
\setrule{2}{3}{60\times}
\setrule{2}{5}{2\div}
\setrule{3}{2}{2-}
\setrule{3}{5}{75\times}
\setrule{4}{1}{8+}
\setrule{4}{2}{1-}
\setrule{4}{4}{2\times}
\setrule{5}{3}{1}
\setrule{5}{5}{2}
\end{kendoku}
\hspace{1.5cm}
\begin{kendoku}
\framearea{black}{\tikzpath{1}{1}{8,8,6,2,6,2,4,4}}
\framearea{black}{\tikzpath{1}{3}{8,6,2,4}}
\framearea{black}{\tikzpath{1}{4}{8,8,6,2,2,4}}
\framearea{black}{\tikzpath{2}{2}{8,8,6,6,2,4,2,4}}
\framearea{black}{\tikzpath{2}{4}{8,8,6,2,2,4}}
\framearea{black}{\tikzpath{3}{1}{8,8,6,2,2,4}}
\framearea{black}{\tikzpath{3}{4}{8,8,6,6,2,4,2,4}}
\framearea{black}{\tikzpath{4}{1}{8,6,6,2,4,4}}
\framearea{black}{\tikzpath{4}{2}{8,6,6,2,4,4}}
\framearea{black}{\tikzpath{4}{3}{8,8,6,2,2,4}}
\framearea{black}{\tikzpath{5}{3}{8,6,2,4}}
\framearea{black}{\tikzpath{5}{4}{8,6,2,4}}
\framearea{black}{\tikzpath{5}{5}{8,6,2,4}}
\setrule{1}{2}{8\times}
\setrule{1}{3}{5}
\setrule{1}{5}{4+}
\setrule{2}{3}{60\times}
\setrule{2}{5}{2\div}
\setrule{3}{2}{2-}
\setrule{3}{5}{75\times}
\setrule{4}{1}{8+}
\setrule{4}{2}{1-}
\setrule{4}{4}{2\times}
\setrule{5}{3}{1}
\setrule{5}{5}{2}
\setrow{5}{1,4,3,5,2}
\setrow{4}{3,2,5,1,4}
\setrow{3}{5,3,4,2,1}
\setrow{2}{2,5,1,4,3}
\setrow{1}{4,1,2,3,5}
\end{kendoku}
\end{center}


## Options

• rows (5) defines the number of rows in the grid

• columns (5) specifies the number of columns in the grid

• width (5.1cm) sets the width of the minipage, in which the grid is typeset

• scale (1) scales the size of the grid in the minipage

• fontsize (Large) specifies the size of the numbers next to the grid. Here, the usual LaTeX sizes are used. Possible values: tiny, scriptsize, footnotesize, small, normalsize, large, Large, LARGE, huge, Huge

• title () sets the title of a puzzle

• titleindent (0cm) defines the indent of the title

• titlewidth (5.1cm) specifies the width of the box the title is set in

• bgcolor () sets the background color of the grid

• counterstyle (none) defines the counter style. Predefined styles: none, left, right

• cvoffset (-22pt) sets the vertical offset of the counters in the margin

## Environments

### kendoku

\begin{kendoku}

\end{kendoku}


The environment kendoku is the central core of the style file. With the optional argument of the environment, you can reset the options with local scope. Here, a blank grid is created.

## Commands

### In the grid and around

#### kendokucell

\kendokucell{column}{row}{number}

The command sets the {number} of the grid cell {column}{row}.

#### setrow

\setrow{row}{csv list}

The command sets the contents of {row}. It expects a comma-separated list.

#### setcolumn

\setcolumn{column}{csv list}

The command sets the contents of {column}.

#### setrule

\setrule{column}{row}{rule}

With the \setrule command, you can set a calculation rule into the top left corner of cell . The rule is typeset in inline math mode. You might consider using the \times and \div  commands.

#### framearea

\framearea{color}{\tikz path}

The command frames the area given by {\tikz path} with color {color}. The reference for coordinates is the bottom left corner of the cell.

\framearea{green}{(2,2)--(2,3)--(3,3)--(3,2)--(2,2)}

This command will color the frame of the grid cell (2,2) green. You should consider using this command in the puzzleforeground environment.

#### tikzpath

\tikzpath{column}{row}{csv list}

With the \tikzpath command, you can easily construct a \tikz path. You just need to define a starting point (bottom left corner) and a csv list with direction indicators relative to the current position.

7: up left       8: up            9: up right
4: left          5: no change     6: right
1: down left     2: down          3: down right


\framearea{green}{\tikzpath{2}{2}{8,6,2,4}}


This command will frame grid cell (2,2) green.

### Presentation

#### definecounterstyle

The command allows you to define your own styles. For example, the style left is defined as follows:

\definecounterstyle{left}{
\begingroup\reversemarginpar\marginnote{
\tikz\node[shape=rectangle,fill=yellow!40,inner sep=7pt,
draw,rounded corners=3pt,thick]
{\Huge\puzzlecounter};}[\LP@cvoffset]\endgroup}
}


To typeset the counter into the margin we use the command \marginnote. We need to use the command \reversemarginpar to set the counter into the left margin. Of course, we must use this command in a group for local scope. Finally we use \puzzlecounter in a \tikz node with a vertical offset set with the option cvoffset.

#### puzzlecounter

\puzzlecounter

The command provides the counter in textual form to use it for example in \definecounterstyle.

#### titleformat

\titleformat{format}

With the command \titleformat, you can define the format of the title. By default, the definition is as follows:

\titleformat{\centering\Large\color{blue}}

### Miscellaneous

#### kendokusetup

\kendokusetup{options}

With the command kendokusetup you can reset the options with global scope.

#### setpuzzlecounter

\setpuzzlecounter{number}

With the command \setpuzzlecounter, you can reset the puzzle counter, for example before the solutions.

## Examples & Solutions

You can download application examples and their solutions from the project page. The puzzles are originally licensed under CC-BY-NC-SA.