suppressPackageStartupMessages({ library(dplyr) library(ggplot2) library(nonogram) }) knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "figures/" )
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.
You can install nonogram
from github with:
# install.packages("devtools") devtools::install_github("coolbutuseless/nonogram")
This is a basic example which shows you how to plot and solve a simple puzzle.
puzzle_string <- puzzle_string_examples[['duck']] puzzle <- convert_puzzle_string_to_puzzle(puzzle_string)
cat('> puzzle_string') strwrap(puzzle_string, width = 60) %>% cat cat("\n> puzzle") deparse(puzzle) %>% paste(collapse="\n") %>% cat()
create_puzzle_plot(puzzle, title="Duck")
solution_matrix <- solve_puzzle(puzzle) solution_matrix
create_puzzle_plot(puzzle, solution_matrix, title="Duck")
puzzle <- puzzle_string_examples[['R']] puzzle puzzle %>% solve_puzzle(verbose=TRUE) %>% create_puzzle_plot(puzzle, ., show_clues=TRUE)
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.