suppressPackageStartupMessages({
  library(dplyr)
  library(ggplot2)

  library(nonogram)
})



knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "figures/"
)

Nonograms

AppVeyor build status Travis build status Coverage status

Nonograms are picture logic puzzles in which cells in a grid must be colored or left blank according to numbers at the side of the grid to reveal a hidden picture.

The nonogram package contains a solver and methods for plotting and manipulating nonogram puzzles.

Installation

You can install nonogram from github with:

# install.packages("devtools")
devtools::install_github("coolbutuseless/nonogram")

Example

This is a basic example which shows you how to plot and solve a simple puzzle.

Use one of the puzzle strings in the package

puzzle_string <- puzzle_string_examples[['duck']] 
puzzle        <- convert_puzzle_string_to_puzzle(puzzle_string)

Puzzle and Puzzle String representation

cat('> puzzle_string')
strwrap(puzzle_string, width = 60) %>% cat


cat("\n> puzzle")
deparse(puzzle) %>% paste(collapse="\n") %>% cat()

Plot the unsolved puzzle

create_puzzle_plot(puzzle, title="Duck")

Solve the puzzle

solution_matrix <- solve_puzzle(puzzle) 
solution_matrix

Plot the solved puzzle

create_puzzle_plot(puzzle, solution_matrix, title="Duck")

An all-in-one example

puzzle <- puzzle_string_examples[['R']]
puzzle

puzzle %>%
  solve_puzzle(verbose=TRUE) %>%
  create_puzzle_plot(puzzle, ., show_clues=TRUE)

Create your own puzzles

To make, print and solve your own nonograms, you just need to create a puzzle string.

The puzzle string format used to define puzzles is quite simple:

puzzle_string <- "3:1:1,1-3:1:1,1"
solution      <- solve_puzzle(puzzle_string)
create_puzzle_plot(puzzle_string, solution)


coolbutuseless/nonogram documentation built on May 5, 2019, 3:45 a.m.