solveGame: Solve a Sudoku Game

Description Usage Arguments Details Value Author(s) Examples

View source: R/sudokuAlt.R

Description

Solve a Sudoku Game

Usage

1
solveGame(game)

Arguments

game

The game to be solved

Details

Given a sudoku game to be solved, find the solution. IMPORTANT: games are represented as n^2 x n^2 character matrices, using 1-9 for n=2 or 3, and LETTERS[1:(n^2)] for n = 4 or 5.

Value

A solved sudoku game object if one found, or NULL if no solution exists. The original game is attached as an attribute if the game is solved.

Author(s)

Bill Venables

Examples

1
2
3
4
5
6
7
8
set.seed(1234)
makeGame(3, gaps = 60) %>% solve %>% plot -> sg
(g <- originalGame(sg))

g <- emptyGame(4)  # construct a patterned game
diag(g) <- LETTERS[1:16]
sg <- solve(g)
plot(sg)

Example output

                          
 + - - - + - - - + - - - +
 | 7     |       |       |
 |       |       |       |
 | 9   5 | 3     |       |
 + - - - + - - - + - - - +
 |     6 | 7 8   |       |
 |       |   9   |       |
 |       |   4 5 |       |
 + - - - + - - - + - - - +
 |   5   | 8 3 6 |     4 |
 |       | 5     |       |
 | 6 8   |   2   | 5 3   |
 + - - - + - - - + - - - +

sudokuAlt documentation built on Dec. 16, 2019, 1:23 a.m.