https://github.com/coolbutuseless/nonogram
Nonogram solver in rstats
https://github.com/coolbutuseless/nonogram
Last synced: 4 months ago
JSON representation
Nonogram solver in rstats
- Host: GitHub
- URL: https://github.com/coolbutuseless/nonogram
- Owner: coolbutuseless
- License: mit
- Created: 2018-09-26T05:14:24.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-28T21:57:12.000Z (over 6 years ago)
- Last Synced: 2024-08-13T07:11:37.348Z (10 months ago)
- Language: R
- Size: 528 KB
- Stars: 15
- Watchers: 4
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- Changelog: NEWS.md
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - coolbutuseless/nonogram - Nonogram solver in rstats (R)
README
---
output: github_document
---```{r, echo = FALSE}
suppressPackageStartupMessages({
library(dplyr)
library(ggplot2)
library(nonogram)
})knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "figures/"
)
```Nonograms
------------------------------------------------------------------------------[](https://ci.appveyor.com/project/coolbutuseless/nonogram)
[](https://travis-ci.org/coolbutuseless/nonogram)
[](https://codecov.io/github/coolbutuseless/nonogram?branch=master)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:
```{r gh-installation, eval = FALSE}
# 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
```{r example}
puzzle_string <- puzzle_string_examples[['duck']]
puzzle <- convert_puzzle_string_to_puzzle(puzzle_string)
```### Puzzle and Puzzle String representation
```{r echo=FALSE, comment=NA}
cat('> puzzle_string')
strwrap(puzzle_string, width = 60) %>% catcat("\n> puzzle")
deparse(puzzle) %>% paste(collapse="\n") %>% cat()
```### Plot the unsolved puzzle
```{r duck-unsolved}
create_puzzle_plot(puzzle, title="Duck")
```### Solve the puzzle
```{r}
solution_matrix <- solve_puzzle(puzzle)
solution_matrix
```### Plot the solved puzzle
```{r duck-solution}
create_puzzle_plot(puzzle, solution_matrix, title="Duck")
```### An all-in-one example
```{r all-in-one}
puzzle <- puzzle_string_examples[['R']]
puzzlepuzzle %>%
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:
* the numbers for each clue are separated by a comma
* each clue is separated by a colon
* the clues for the rows come first, then a dash, then the clues for the columns
* row clues are read from left to right
* column clues are read from top to bottom```{r create-your-own}
puzzle_string <- "3:1:1,1-3:1:1,1"
solution <- solve_puzzle(puzzle_string)
create_puzzle_plot(puzzle_string, solution)
```