Generating Crosswords from Word Lists

Generate crosswords from a list of words.


Status

lines of R code: 397, lines of test code: 50

Youtube video of Hamburg UseR Meetup presentation

https://youtu.be/56qrwa4bzK8

Development version

0.3.6 - 2019-01-18 / 20:55:43

Description

Generate crosswords from a list of words.

License

MIT + file LICENSE
Peter Meissner

Citation

citation("crossword.r")

BibTex for citing

toBibtex(citation("crossword.r"))

Installation

Stable version from CRAN:

install.packages("crossword.r")

Latest development version from Github:

devtools::install_github("petermeissner/crossword.r")

Help wanted

Usage

# load the library
library(crossword.r)
 
# set seed for pseudo random number generator
set.seed(123)
 
# create a new 4 by 4 crossword
cw       <- Crossword$new(rows = 10, columns = 10)
cw_words <- cw_wordlist_animal_en[sample(nrow(cw_wordlist_animal_en)),]
 
cw$add_words(
  words = cw_words$words,
  clues = cw_words$clues
)
# use the default print method to have a look
cw
## . . 1 2 3 4 5 6 7 8 9 0 1
## . # # # # # # # # # # # #
## 1 # E E L # . # B . # S #
## 2 # T E R M I T E # G K #
## 3 # H A R E # O E W I U #
## 4 # O X # . G R # O R N #
## 5 # . . # A N T # M A K #
## 6 # F L Y # U O B B F # #
## 7 # # F O X # I A A F # #
## 8 # D U C K # S T T E D #
## 9 # # S N A K E # # # O #
## 0 # C O D # . # F R O G #
## 1 # # # # # # # # # # # #
# access to letters on the grid
cw$letters
##       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
##  [1,] "#"  "#"  "#"  "#"  "#"  "#"  "#"  "#"  "#"  "#"   "#"   "#"  
##  [2,] "#"  "E"  "E"  "L"  "#"  "."  "#"  "B"  "."  "#"   "S"   "#"  
##  [3,] "#"  "T"  "E"  "R"  "M"  "I"  "T"  "E"  "#"  "G"   "K"   "#"  
##  [4,] "#"  "H"  "A"  "R"  "E"  "#"  "O"  "E"  "W"  "I"   "U"   "#"  
##  [5,] "#"  "O"  "X"  "#"  "."  "G"  "R"  "#"  "O"  "R"   "N"   "#"  
##  [6,] "#"  "."  "."  "#"  "A"  "N"  "T"  "#"  "M"  "A"   "K"   "#"  
##  [7,] "#"  "F"  "L"  "Y"  "#"  "U"  "O"  "B"  "B"  "F"   "#"   "#"  
##  [8,] "#"  "#"  "F"  "O"  "X"  "#"  "I"  "A"  "A"  "F"   "#"   "#"  
##  [9,] "#"  "D"  "U"  "C"  "K"  "#"  "S"  "T"  "T"  "E"   "D"   "#"  
## [10,] "#"  "#"  "S"  "N"  "A"  "K"  "E"  "#"  "#"  "#"   "O"   "#"  
## [11,] "#"  "C"  "O"  "D"  "#"  "."  "#"  "F"  "R"  "O"   "G"   "#"  
## [12,] "#"  "#"  "#"  "#"  "#"  "#"  "#"  "#"  "#"  "#"   "#"   "#"
 
# access to words placed on the grid, their co-ordinates and so on
cw$words
##    row col length direction     word
## 1   10   1      3     right      COD
## 2    1  10      5      down    SKUNK
## 3    1   1      3     right      EEL
## 4    2   1      7     right  TERMITE
## 5    2   6      8      down TORTOISE
## 6    5   4      3     right      ANT
## 7    2   9      7      down  GIRAFFE
## 8    9   2      5     right    SNAKE
## 9    4   5      3      down      GNU
## 10   3   8      6      down   WOMBAT
## 11   8   1      4     right     DUCK
## 12   3   1      4     right     HARE
## 13  10   7      4     right     FROG
## 14   1   7      3      down      BEE
## 15   4   1      2     right       OX
## 16   6   1      3     right      FLY
## 17   7   2      3     right      FOX
## 18   6   7      3      down      BAT
## 19   8  10      3      down      DOG
##                                                                                  clue
## 1              Popular food fish with a mild flavour and a dense, flaky, white flesh.
## 2                     Animals known for its ability to spray strong unpleasant liquid
## 3                                                                      Elongated fish
## 4                                                                  Living in colonies
## 5                                                                     Armored reptile
## 6                                                    Small with mandibles and antenna
## 7                                                             One of the big africans
## 8                                             Elongated, legless, carnivorous reptile
## 9                                                                      Also a licence
## 10                                                           Australian burrow digger
## 11                                                                         Water bird
## 12                                                         Fast runner with long ears
## 13                                                                 Tailless amphibian
## 14                                                            Striped but no predator
## 15                                                        Castrated adult male cattle
## 16                                                                       Small insect
## 17 Upright triangular ears, a pointed, slightly upturned snout, and a long bushy tail
## 18                                                                      Flying mammal
## 19                                                               A man's best friend.
# get some statistics
cw$density()
## $word_character
## [1] 79
## 
## $grid_width
## [1] 10
## 
## $grid_height
## [1] 10
## 
## $grid_letters
## [1] 73
# export to JSON
cw$to_json(pretty=TRUE)
## {
##   "grid": [
##     ["E", "E", "L", "", "", "", "B", "", "", "S"],
##     ["T", "E", "R", "M", "I", "T", "E", "", "G", "K"],
##     ["H", "A", "R", "E", "", "O", "E", "W", "I", "U"],
##     ["O", "X", "", "", "G", "R", "", "O", "R", "N"],
##     ["", "", "", "A", "N", "T", "", "M", "A", "K"],
##     ["F", "L", "Y", "", "U", "O", "B", "B", "F", ""],
##     ["", "F", "O", "X", "", "I", "A", "A", "F", ""],
##     ["D", "U", "C", "K", "", "S", "T", "T", "E", "D"],
##     ["", "S", "N", "A", "K", "E", "", "", "", "O"],
##     ["C", "O", "D", "", "", "", "F", "R", "O", "G"]
##   ],
##   "words": [
##     {
##       "row": 10,
##       "col": 1,
##       "length": 3,
##       "direction": "right",
##       "word": "COD",
##       "clue": "Popular food fish with a mild flavour and a dense, flaky, white flesh."
##     },
##  }
## 
## [...]

News

crossword 0.3.6 -- 2019-01-20

  • copyright holder was missing

crossword 0.3.5 -- 2018-01-18

  • make package CRAN compliant via improving documentation

crossword 0.3.4 -- 2018-01-13

  • fix: coordinates were off by one
  • adding tests
  • general cleanup

crossword 0.3.3 -- 2018-01-07

  • changed print method -- fixes #3

crossword 0.3.2 -- 2018-01-04

  • added to_json() method
  • Added a NEWS.md file to track changes to the package.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("crossword.r")

0.3.6 by Peter Meissner, 5 months ago


Browse source code at https://github.com/cran/crossword.r


Authors: Peter Meissner


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports R6, dplyr, stringr, magrittr, jsonlite, r6extended

Suggests covr, testthat


See at CRAN