Crosswords
Structures
Enigmistics.CrosswordWord — TypeCrosswordWordStructure for a word placed in the crossword.
Fields
word::String: the actual wordrow::Int: starting rowcol::Int: starting columndirection::Symbol: either:verticalor:horizontal
Enigmistics.CrosswordBlackCell — TypeCrosswordBlackCellStructure for a black cell placed in the crossword.
Fields
count::Float64: number of words that share that black cell (orInf64if it was manually placed)manual::Bool: if the cell was manually set by user or automatically derived based on surrounding words
Enigmistics.CrosswordPuzzle — TypeCrosswordPuzzleStructure for a crossword puzzle.
Fields
grid::Matrix{Char}: the actual crossword gridwords::Vector{CrosswordWord}: vector containing all the wordsblack_cells::Dict{Tuple{Int,Int}, CrosswordBlackCell}: dictionary storing the black cells information
Here are some useful constructors:
Enigmistics.CrosswordPuzzle — MethodCrosswordPuzzle(rows::Int, cols::Int)Construct a crossword with an empty grid of the given dimensions.
Examples
julia> cw = CrosswordPuzzle(4,5)
1 2 3 4 5
┌───────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ⋅ │
2 │ ⋅ ⋅ ⋅ ⋅ ⋅ │
3 │ ⋅ ⋅ ⋅ ⋅ ⋅ │
4 │ ⋅ ⋅ ⋅ ⋅ ⋅ │
└───────────────┘Enigmistics.CrosswordPuzzle — MethodCrosswordPuzzle(rows::Int, cols::Int, words::Vector{CrosswordWord})Construct a crossword with the given dimensions and words. Return an error if words intersections are not compatible.
Examples
julia> words = [CrosswordWord("CAT",2,2,:horizontal), CrosswordWord("MAP",1,3,:vertical),
CrosswordWord("SIR",4,4,:horizontal)];
julia> CrosswordPuzzle(5,6,words)
1 2 3 4 5 6
┌──────────────────┐
1 │ ⋅ ⋅ M ⋅ ⋅ ⋅ │
2 │ ■ C A T ■ ⋅ │
3 │ ⋅ ⋅ P ⋅ ⋅ ⋅ │
4 │ ⋅ ⋅ ■ S I R │
5 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
└──────────────────┘
julia> words = [CrosswordWord("CAT",2,2,:horizontal), CrosswordWord("MAP",1,3,:vertical),
CrosswordWord("SIR",4,4,:horizontal), CrosswordWord("DOG",1,2,:vertical)];
julia> CrosswordPuzzle(5,6,words)
┌ Warning: Cannot place word 'DOG' at (1, 2) vertically due to conflict at cell (2, 2); found when checking the inner cells.
┌ Error: Words intersections are not compatible.Enigmistics.CrosswordPuzzle — MethodCrosswordPuzzle(words::Vector{CrosswordWord})Construct a crossword with the given words (dimensions are inferred from words positions). Return an error if words intersections are not compatible.
Examples
julia> words = [CrosswordWord("CAT",2,2,:horizontal), CrosswordWord("MAP",1,3,:vertical),
CrosswordWord("SIR",4,4,:horizontal)];
julia> CrosswordPuzzle(words)
1 2 3 4 5 6
┌──────────────────┐
1 │ ⋅ ⋅ M ⋅ ⋅ ⋅ │
2 │ ■ C A T ■ ⋅ │
3 │ ⋅ ⋅ P ⋅ ⋅ ⋅ │
4 │ ⋅ ⋅ ■ S I R │
└──────────────────┘
julia> words = [CrosswordWord("CAT",2,2,:horizontal), CrosswordWord("MAP",1,3,:vertical),
CrosswordWord("SIR",4,4,:horizontal), CrosswordWord("DOG",1,2,:vertical)];
julia> CrosswordPuzzle(words)
┌ Warning: Cannot place word 'DOG' at (1, 2) vertically due to conflict at cell (2, 2); found when checking the inner cells.
┌ Error: Words intersections are not compatible.Interface
Enigmistics.show_crossword — Functionshow_crossword(cw::CrosswordPuzzle; words_details=true, black_cells_details=true)Print the crossword grid, possibly along with the words details and black cells details.
Examples
julia> cw = example_crossword(type="full") # normal output
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ O ■ A │
3 │ T ■ S O U R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ W I N D O W │
└──────────────────┘
julia> show_crossword(cw) # extended details output
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ O ■ A │
3 │ T ■ S O U R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ W I N D O W │
└──────────────────┘
Horizontal:
- 'GOLDEN' at (1, 1)
- 'AN' at (2, 1)
- 'SOUR' at (3, 3)
- 'EVER' at (4, 1)
- 'IE' at (5, 2)
- 'WINDOW' at (6, 1)
Vertical:
- 'GATE' at (1, 1)
- 'ON' at (1, 2)
- 'DOOR' at (1, 4)
- 'NARROW' at (1, 6)
- 'SEEN' at (3, 3)
- 'VII' at (4, 2)
Black cells:
- at (5, 5) was manually placed
- at (3, 2) was automatically derived (delimiting 3 words)
- at (4, 5) was automatically derived (delimiting 1 words)
- at (2, 5) was manually placed
- at (5, 1) was automatically derived (delimiting 2 words)
- at (2, 3) was automatically derived (delimiting 2 words)
- at (5, 4) was automatically derived (delimiting 2 words)Enigmistics.example_crossword — Functionexample_crossword(; type="full")Return an example crossword, useful e.g during testing. Available values for now are
- "full": a complete crossword with all words
- "partial": an incomplete crossword with some words missing
Examples
julia> cw = example_crossword(type="full")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ O ■ A │
3 │ T ■ S O U R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ W I N D O W │
└──────────────────┘
julia> example_crossword(type="partial")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘Enigmistics.enlarge! — Functionenlarge!(cw::CrosswordPuzzle, how::Symbol, times=1)Enlarge the crossword grid in the direction given by how (accepted values are :N, :S, :E, :O) by appropriately inserting times empty rows/columns.
Examples
julia> cw = example_crossword()
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ O ■ A │
3 │ T ■ S O U R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ W I N D O W │
└──────────────────┘
julia> enlarge!(cw, :O); cw
1 2 3 4 5 6 7
┌─────────────────────┐
1 │ ■ G O L D E N │
2 │ ■ A N ■ O ■ A │
3 │ ⋅ T ■ S O U R │
4 │ ■ E V E R ■ R │
5 │ ⋅ ■ I E ■ ■ O │
6 │ ■ W I N D O W │
└─────────────────────┘
julia> enlarge!(cw, :N, 2); cw
1 2 3 4 5 6 7
┌─────────────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
2 │ ⋅ ■ ■ ⋅ ■ ⋅ ■ │
3 │ ■ G O L D E N │
4 │ ■ A N ■ O ■ A │
5 │ ⋅ T ■ S O U R │
6 │ ■ E V E R ■ R │
7 │ ⋅ ■ I E ■ ■ O │
8 │ ■ W I N D O W │
└─────────────────────┘Enigmistics.shrink! — Functionshrink!(cw::CrosswordPuzzle)Reduce the crossword size to its minimal representation by removing useless rows/columns.
Examples
julia> cw
1 2 3 4 5 6 7 8 9
┌───────────────────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
2 │ ⋅ ■ ■ ⋅ ■ ⋅ ■ ⋅ ⋅ │
3 │ ■ G O L D E N ■ ⋅ │
4 │ ■ A N ■ O ■ A ⋅ ⋅ │
5 │ ⋅ T ■ S O U R ■ ⋅ │
6 │ ■ E V E R ■ R ⋅ ⋅ │
7 │ ⋅ ■ I E ■ ■ O ⋅ ⋅ │
8 │ ■ W I N D O W ■ ⋅ │
9 │ ⋅ ⋅ ■ ■ ⋅ ⋅ ■ ⋅ ⋅ │
└───────────────────────────┘
julia> shrink!(cw); cw
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ O ■ A │
3 │ T ■ S O U R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ W I N D O W │
└──────────────────┘Enigmistics.can_place_word — Functioncan_place_word(cw::CrosswordPuzzle, word::String, row, col, direction::Symbol)
can_place_word(cw::CrosswordPuzzle, cwword::CrosswordWord)Check if a word can be placed in the crossword puzzle cw at the given position and direction.
Return true if the word can be placed, false otherwise.
Examples
julia> cw = example_crossword(type="partial")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘
julia> can_place_word(cw, "PEARS", 3, 3, :h)
┌ Warning: Word 'PEARS' does not fit in the grid horizontally at (3, 3).
false
julia> can_place_word(cw, "BEAN", 3, 3, :h)
┌ Warning: Cannot place word 'BEAN' at (3, 3) horizontally due to conflict at cell (3, 6); found when checking the inner cells.
false
julia> can_place_word(cw, "TEA", 3, 3, :h)
┌ Warning: Cannot place word 'TEA' at (3, 3) horizontally due to conflict at cell (3, 6); found when checking the border cells.
false
julia> can_place_word(cw, "DEAR", 1, 4, :v)
trueEnigmistics.place_word! — Functionplace_word!(cw::CrosswordPuzzle, word::String, row, col, direction::Symbol)
place_word!(cw::CrosswordPuzzle, cword::CrosswordWord)Place a word in the crossword puzzle cw at the given position and direction, also checking if it can actually be placed.
Return true if the word was successfully placed, false otherwise.
Examples
julia> cw = example_crossword(type="partial")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘
julia> place_word!(cw, "cat", 6, 1, :h)
┌ Warning: Cannot place word 'CAT' at (6, 1) horizontally due to conflict at cell (6, 2); found when checking the inner cells.
false
julia> place_word!(cw, "pillow", 6, 1, :h)
true
julia> cw
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ P I L L O W │
└──────────────────┘Enigmistics.remove_word! — Functionremove_word!(cw::CrosswordPuzzle, word::String)
remove_word!(cw::CrosswordPuzzle, cword::CrosswordWord)
remove_word!(cw::CrosswordPuzzle, words::Vector{String})
remove_word!(cw::CrosswordPuzzle, words::Vector{CrosswordWord})Remove a word (or multiple words) from the crossword puzzle cw.
Return true if the word was found and removed, false otherwise.
Examples
julia> cw = example_crossword(type="partial")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘
julia> remove_word!(cw, "cat")
┌ Warning: Word 'CAT' not found in the crossword. No changes on the original grid.
false
julia> remove_word!(cw, "narrow")
true
julia> cw
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ ⋅ │
3 │ T ■ ⋅ ⋅ ⋅ ⋅ │
4 │ E V E R ■ ⋅ │
5 │ ■ I E ■ ■ ⋅ │
6 │ ⋅ I ⋅ ⋅ ⋅ ⋅ │
└──────────────────┘Enigmistics.place_black_cell! — Functionplace_black_cell!(cw::CrosswordPuzzle, row::Int, col::Int; symmetry=false, double_symmetry=false)Place a black cell in the crossword puzzle cw at the given position.
Return true if the black cell was successfully placed, false otherwise.
Examples
julia> cw = example_crossword(type="partial")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘
julia> place_black_cell!(cw, 6, 2)
┌ Warning: Cannot place black cell at position (6, 2) since cell is not empty. No changes on the original grid.
false
julia> place_black_cell!(cw, 6, 4)
true
julia> cw
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ■ ⋅ W │
└──────────────────┘Enigmistics.remove_black_cell! — Functionremove_black_cell!(cw::CrosswordPuzzle, row::Int, col::Int)Remove a black cell from the crossword puzzle cw at the given position.
Return true if the black cell was successfully removed, false otherwise.
Examples
julia> cw = example_crossword(type="partial"); show_crossword(cw, words_details=false)
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘
Black cells:
- at (5, 5) was manually placed
- at (4, 5) was automatically derived (delimiting 1 words)
- at (3, 2) was automatically derived (delimiting 2 words)
- at (2, 5) was manually placed
- at (5, 1) was automatically derived (delimiting 2 words)
- at (2, 3) was automatically derived (delimiting 1 words)
- at (5, 4) was automatically derived (delimiting 1 words)
julia> remove_black_cell!(cw, 3, 2)
┌ Warning: Cannot remove automatically placed black cell at position (3, 2) since it's needed as a word delimiter. No changes on the original grid.
false
julia> remove_black_cell!(cw, 5, 5)
true
julia> cw
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ⋅ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘Enigmistics.clear! — Functionclear!(cw::CrosswordPuzzle; deep=false)Clear all words, possibly preserving manually-placed black cells (with deep=false), from the crossword puzzle cw.
Examples
julia> cw = example_crossword(); show_crossword(cw, words_details=false)
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ O ■ A │
3 │ T ■ S O U R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ W I N D O W │
└──────────────────┘
Black cells:
- at (5, 5) was manually placed
- at (3, 2) was automatically derived (delimiting 3 words)
- at (4, 5) was automatically derived (delimiting 1 words)
- at (2, 5) was manually placed
- at (5, 1) was automatically derived (delimiting 2 words)
- at (2, 3) was automatically derived (delimiting 2 words)
- at (5, 4) was automatically derived (delimiting 2 words)
julia> clear!(cw)
1 2 3 4 5 6
┌──────────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
2 │ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
3 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
4 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
5 │ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
6 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
└──────────────────┘
julia> clear!(cw, deep=true)
1 2 3 4 5 6
┌──────────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
2 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
3 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
4 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
5 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
6 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
└──────────────────┘Patterns
Enigmistics.random_pattern — Functionrandom_pattern(nrows, ncols;
max_density=0.18, symmetry=true, double_symmetry=true,
seed=rand(Int))Generate a crossword puzzle with black cells placed according to a random pattern which can be totally random, symmetric, or doubly symmetric (i.e. specular).
Arguments
nrows::Int,ncols::Int: grid dimensionsmax_density::Float=0.18: maximum density of black cellssymmetry::Bool=true: whether to enforce symmetrydouble_symmetry::Bool=false: whether to enforce double symmetry (i.e. specularity)seed::Int=rand(Int): random seed for reproducibility
Examples
julia> random_pattern(12, 20, symmetry=false, seed=1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
┌────────────────────────────────────────────────────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ■ ⋅ ⋅ ■ │
2 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
3 │ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ │
4 │ ■ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ■ ⋅ │
5 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ■ ⋅ ⋅ │
6 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
7 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ■ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
8 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
9 │ ⋅ ■ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
10 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ■ ⋅ ⋅ ■ ⋅ │
11 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ■ ⋅ ⋅ ■ │
12 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
└────────────────────────────────────────────────────────────┘
julia> random_pattern(12, 20, symmetry=true, seed=1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
┌────────────────────────────────────────────────────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ │
2 │ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
3 │ ■ ⋅ ⋅ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
4 │ ■ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
5 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ■ ⋅ ⋅ │
6 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
7 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ │
8 │ ⋅ ⋅ ■ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
9 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ■ │
10 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ⋅ ⋅ ■ │
11 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ │
12 │ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
└────────────────────────────────────────────────────────────┘
julia> random_pattern(12, 20, symmetry=true, double_symmetry=true, seed=1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
┌────────────────────────────────────────────────────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
2 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
3 │ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ │
4 │ ■ ⋅ ■ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ■ ⋅ ■ │
5 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
6 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ■ ■ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
7 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ■ ■ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
8 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
9 │ ■ ⋅ ■ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ■ ⋅ ■ │
10 │ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ │
11 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
12 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
└────────────────────────────────────────────────────────────┘Enigmistics.striped_pattern — Functionstriped_pattern(nrows, ncols;
max_density = 0.18,
min_stripe_dist = 4, keep_stripe_prob = 0.9,
symmetry = true, double_symmetry = false,
seed=rand(Int))Generate a crossword puzzle with black cells placed according to a striped pattern which can be random, symmetric, or doubly symmetric (i.e. specular).
Arguments
nrows::Int,ncols::Int: grid dimensionsmax_density::Float=0.18: maximum density of black cellsmin_stripe_dist::Int=4: minimum distance allowed between stripeskeep_stripe_prob::Float=0.8: probability of continuing a stripesymmetry::Bool=true: whether to enforce symmetrydouble_symmetry::Bool=false: whether to enforce double symmetry (i.e. specularity)seed::Int=rand(Int): random seed for reproducibility
Examples
julia> striped_pattern(12, 20, symmetry=false, seed=1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
┌────────────────────────────────────────────────────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
2 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ │
3 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
4 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
5 │ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ │
6 │ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
7 │ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
8 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
9 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ │
10 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
11 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ │
12 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
└────────────────────────────────────────────────────────────┘
julia> striped_pattern(12, 20, symmetry=true, seed=1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
┌────────────────────────────────────────────────────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
2 │ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ │
3 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
4 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
5 │ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ │
6 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
7 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
8 │ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ │
9 │ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ │
10 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
11 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
12 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ │
└────────────────────────────────────────────────────────────┘
julia> striped_pattern(12, 20, symmetry=true, double_symmetry=true, seed=1)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
┌────────────────────────────────────────────────────────────┐
1 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
2 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ │
3 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
4 │ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
5 │ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ │
6 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
7 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
8 │ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ │
9 │ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
10 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
11 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ │
12 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
└────────────────────────────────────────────────────────────┘Enigmistics.famous_patterns — Functionfamous_patterns(; style=:NewYorkTimes, grid_size=nothing, seed=rand(Int))Generate a crossword puzzle according to on a famous historical or standard pattern.
Available styles are: :NewYorkTimes, :Diamond, :BritishCryptic, :Spiral. For each style, the following optional arguments are supported:
- Diamond:
grid_size=(13,13) - BritishCryptic:
grid_size=(15,15),seed=rand(Int) - Spiral:
step_size=0.1,radius_function=(θ->0.8*θ),max_theta=4π
Example
julia> cw = famous_patterns(style=:NewYorkTimes)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
┌─────────────────────────────────────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
2 │ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
3 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
4 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
5 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ■ │
6 │ ■ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ │
7 │ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
8 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
9 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
10 │ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ■ │
11 │ ■ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
12 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
13 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
14 │ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
15 │ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ │
└─────────────────────────────────────────────┘
julia> famous_patterns(style=:Diamond)
1 2 3 4 5 6 7 8 9 10 11 12 13
┌───────────────────────────────────────┐
1 │ ■ ■ ■ ■ ■ ■ ⋅ ■ ■ ■ ■ ■ ■ │
2 │ ■ ■ ■ ■ ■ ⋅ ⋅ ⋅ ■ ■ ■ ■ ■ │
3 │ ■ ■ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ■ ■ │
4 │ ■ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ■ │
5 │ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ │
6 │ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ │
7 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
8 │ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ │
9 │ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ │
10 │ ■ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ■ │
11 │ ■ ■ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ■ ■ │
12 │ ■ ■ ■ ■ ■ ⋅ ⋅ ⋅ ■ ■ ■ ■ ■ │
13 │ ■ ■ ■ ■ ■ ■ ⋅ ■ ■ ■ ■ ■ ■ │
└───────────────────────────────────────┘
julia> famous_patterns(style=:BritishCryptic, grid_size=(15,15), seed=42)
┌ Info: Using seed
└ seed = 42
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
┌─────────────────────────────────────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
2 │ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ │
3 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
4 │ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ │
5 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
6 │ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ■ │
7 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
8 │ ⋅ ■ ⋅ ■ ■ ■ ⋅ ■ ⋅ ■ ■ ■ ⋅ ■ ⋅ │
9 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
10 │ ■ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ │
11 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
12 │ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ │
13 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
14 │ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ ■ ⋅ │
15 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
└─────────────────────────────────────────────┘
julia> cw = famous_patterns(style=:Spiral)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
┌──────────────────────────────────────────────────────┐
1 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
2 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
3 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ■ ⋅ ⋅ ■ ■ ■ ⋅ ⋅ ⋅ ⋅ │
4 │ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
5 │ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ │
6 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ │
7 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
8 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
9 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
10 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
11 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
12 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ │
13 │ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ │
14 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ │
15 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ■ ■ ■ ⋅ ⋅ ⋅ ⋅ │
16 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
17 │ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
18 │ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
19 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
20 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
21 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
└──────────────────────────────────────────────────────┘IO
Enigmistics.save_crossword — Functionsave_crossword(cw::CrosswordPuzzle, filename::String)Save the crossword puzzle cw to a text file specified by filename.
The grid is saved using the following conventions:
/represents a black cell.represents an empty cell- letters represent filled cells
Examples
julia> cw = example_crossword(type="full")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ O ■ A │
3 │ T ■ S O U R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ W I N D O W │
└──────────────────┘
julia> save_crossword(cw, "ex1.txt")file ex1.txt:
GOLDEN
AN/O/A
T/SOUR
EVER/R
/IE//O
WINDOWEnigmistics.load_crossword — Functionload_crossword(path::String)Load a crossword puzzle from a text file specified by path.
The grid should be written in the file using the following conventions:
/represents a black cell.represents an empty cell- letters represent filled cells
Examples
file ex2.txt:
GOLDEN
AN/O/.
T/SOUR
EVER/.
/IE/S.
.IN.O.julia> cw = load_crossword("ex2.txt"); show_crossword(cw)
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ O ■ ⋅ │
3 │ T ■ S O U R │
4 │ E V E R ■ ⋅ │
5 │ ■ I E ■ S ⋅ │
6 │ ⋅ I N ⋅ O ⋅ │
└──────────────────┘
Horizontal:
- 'GOLDEN' at (1, 1)
- 'AN' at (2, 1)
- 'SOUR' at (3, 3)
- 'EVER' at (4, 1)
- 'IE' at (5, 2)
Vertical:
- 'GATE' at (1, 1)
- 'ON' at (1, 2)
- 'VII' at (4, 2)
- 'SEEN' at (3, 3)
- 'DOOR' at (1, 4)
- 'SO' at (5, 5)
Black cells:
- at (3, 2) was automatically derived (delimiting 3 words)
- at (4, 5) was automatically derived (delimiting 2 words)
- at (2, 5) was manually placed
- at (5, 1) was automatically derived (delimiting 2 words)
- at (2, 3) was automatically derived (delimiting 2 words)
- at (5, 4) was automatically derived (delimiting 2 words)Enigmistics.to_latex — Functionto_latex(cw::CrosswordPuzzle)Generate a string containing the LaTeX code which can be used (through the cwpuzzle package) to represent the crossword puzzle cw.
Example
# Create your crossword
julia> cw = example_crossword(type="full")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ O ■ A │
3 │ T ■ S O U R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ W I N D O W │
└──────────────────┘
julia> open("out_latex.tex", "w") do file
write(file, to_latex(cw))
endAutomation
Slots
Enigmistics.Slot — TypeSlotStructure for a crossword slot, i.e. a place where a word can be placed.
Fields
row::Int,col::Int: slot positiondirection::Symbol: slot direction (:horizontalor:vertical)length::Int: slot lengthpattern::String: slot pattern, describing letters or blank spaces in its cellsflexible_start::Bool: can this slot be potentially expanded at the start (e.g. is it at the border of the grid)?flexible_end::Bool: can this slot be potentially expanded at the end (e.g. is it at the border of the grid)?
Enigmistics.find_constrained_slots — Functionfind_constrained_slots(cw::CrosswordPuzzle)Find all slots (horizontal and vertical) in the crossword puzzle cw that are constrained, i.e. that have at least one empty cell and length at least 2 characters.
Examples
julia> cw = example_crossword(type="partial")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘
julia> find_constrained_slots(cw)
4-element Vector{Slot}:
Slot(3, 3, :horizontal, 4, "...R", false, true)
Slot(6, 1, :horizontal, 6, ".I...W", true, true)
Slot(3, 3, :vertical, 4, ".EE.", false, true)
Slot(1, 4, :vertical, 4, "D..R", true, false)Enigmistics.compute_options_simple — Functioncompute_options_simple(cw::CrosswordPuzzle, s::Slot; verbose=false)Compute the number of fitting words for a slot s of the crossword cw considering its pattern and length.
Return a tuple (n_options, candidates), where n_options is the number of fitting words and candidates is a vector containing the list of fitting words.
Examples
julia> cw = example_crossword(type="partial")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘
julia> slots = find_constrained_slots(cw); slots[2]
Slot(6, 1, :horizontal, 6, ".I...W", true, true)
julia> compute_options_simple(cw, slots[2], verbose=true)
- simple fitting, length: 6 => #options: 19
some are ["AIMLOW", "BIGWOW", "BILLOW", "JIGSAW", "KIDROW", "LIELOW", "MIDBOW", "MILDEW", "MINNOW", "PILLOW"]Enigmistics.compute_options_split — Functioncompute_options_split(cw::CrosswordPuzzle, s::Slot; verbose=false)Compute the number of fitting words for a slot s of the crossword cw by simulating the placement of black cells at each internal position of the slot, i.e. possibly splitting the original slot into two smaller slots.
Return a tuple (n_options, candidates), where n_options is a dictionary mapping the internal position of the black cell to the number of fitting words, and candidates is a dictionary mapping that same key to a tuple of two lists of fitting words (left and right sub-slots).
Examples
julia> cw = example_crossword(type="partial")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘
julia> slots = find_constrained_slots(cw); slots[2]
Slot(6, 1, :horizontal, 6, ".I...W", true, true)
julia> compute_options_split(cw, slots[2], verbose=true)
- placing a black cell at (6, 1), pattern: /I...W => #options: 13
some are ["IDRAW", "IKNEW", "IKNOW", "INDOW", "INLAW", "INLOW", "INNEW", "INTOW", "ISHOW", "ISLEW"]
- placing a black cell at (6, 3), pattern: .I/..W => #options: 23/96
some are Left: ["AI", "BI", "CI", "DI", "EI", "GI", "HI", "II", "JI", "KI"]
some are Right: ["ALW", "AWW", "BBW", "BMW", "BOW", "BTW", "CAW", "CCW", "CEW", "COW"]
- placing a black cell at (6, 4), pattern: .I./.W => #options: 341/8
some are Left: ["AIA", "AIC", "AID", "AIG", "AIL", "AIM", "AIN", "AIR", "AIS", "AIT"]
they are Right: ["AW", "BW", "EW", "IW", "KW", "NW", "OW", "SW"]
- placing a black cell at (6, 5), pattern: .I../W => #options: 1136
some are ["AIAI", "AIBO", "AIDA", "AIDE", "AIDS", "AIDY", "AIEA", "AIGU", "AIKO", "AILE"]Enigmistics.compute_options_flexible — Functioncompute_options_flexible(cw::CrosswordPuzzle, s::Slot, k::Int=1; verbose=false)Compute the number of fitting words for a slot s of the crossword cw considering its flexibility at the start and/or at the end, i.e. simulating the potential expansion of k cells in length which could happen by enlarging the grid.
Return a tuple (n_options, candidates), where n_options is a dictionary mapping the flexibility simulated (increment at the start and/or at the end) to the number of fitting words, and candidates is a dictionary mapping that same key to the list of fitting words.
Examples
julia> cw = example_crossword(type="partial")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘
julia> slots = find_constrained_slots(cw); slots[2]
Slot(6, 1, :horizontal, 6, ".I...W", true, true)
julia> compute_options_flexible(cw, slots[2], 1, verbose=true)
- flexible start/end, increment: (0, 1) => pattern .I...W., length: 7 => #options: 43
some are ["AIMDOWN", "BIGNEWS", "BIGTOWN", "BIGYAWN", "BILLOWS", "BILLOWY", "DIALTWO", "DIDNTWE", "DIEDOWN", "DIGDOWN"]
- flexible start/end, increment: (1, 0) => pattern ..I...W, length: 7 => #options: 15
some are ["AWILLOW", "BRISTOW", "DOITNOW", "EXITROW", "HAIRBOW", "LAIDLOW", "LAINLOW", "RAINBOW", "SKIDROW", "SKILSAW"]
julia> compute_options_flexible(cw, slots[2], 2, verbose=true)
- flexible start/end, increment: (0, 2) => pattern .I...W.., length: 8 => #options: 59
some are ["AIRPOWER", "AISLEWAY", "AIWEIWEI", "BIDEAWEE", "BILLOWED", "BILLOWUP", "CIVILWAR", "DIEDAWAY", "DIESAWAY", "DIRTYWAR"]
- flexible start/end, increment: (1, 1) => pattern ..I...W., length: 8 => #options: 35
some are ["BOILDOWN", "CHICHEWA", "CHIPBOWL", "CHIPPEWA", "EDITDOWN", "EXITROWS", "FAIRLAWN", "GOINDOWN", "HAILDOWN", "HAIRBOWS"]
- flexible start/end, increment: (2, 0) => pattern ...I...W, length: 8 => #options: 19
some are ["ALLIKNOW", "BASICLAW", "BUYITNOW", "BYWINDOW", "CAPITALW", "CHAINSAW", "CIVILLAW", "DAVIDLOW", "DIPITLOW", "GETITNOW"]Enigmistics.fitting_words — Functionfitting_words(pattern::Regex, min_len::Int, max_len::Int)
fitting_words(pattern::String, min_len::Int, max_len::Int)Given a pattern and a range of word lengths, return a dictionary mapping each length to the list of matching words having that pattern and length.
Examples
julia> pattern="^pe.*ce$"
"^pe.*ce$"
julia> fitting_words(pattern, 5, 8)
Dict{Int64, Vector{String}} with 4 entries:
5 => ["peace", "pence"]
6 => ["pearce"]
7 => ["penance", "pentace", "pentice"]
8 => ["perforce"]
julia> set_dictionary("it");
julia> fitting_words(pattern, 5, 8)
Dict{Int64, Vector{String}} with 4 entries:
5 => ["pence", "pesce"]
6 => ["pedace", "pedice", "penice"]
7 => ["pendice", "pennace", "perisce", "pernice"]
8 => ["pellacce", "pellicce", "pennucce", "pezzacce"]Dictionary
Enigmistics.set_dictionary — Functionset_dictionary(language="en")Load the dictionary associated to the specified language.
Current supported languages are:
- "en", english
- "it", italian
Moves
Enigmistics.Move — TypeMoveAbstract supertype for all move types in the crossword puzzle.
Enigmistics.Place — TypePlace <: MoveA move corresponding to the placement of a word in a slot.
Enigmistics.SplitAndPlace — TypeSplitAndPlace <: MoveA move corresponding to the placement of a black cell in a slot and one or two words in the resulting sub-slots.
Enigmistics.EnlargeAndPlace — TypeEnlargeAndPlace <: MoveA move corresponding to the placement of a word in a slot after having enlarged the crossword grid.
Enigmistics.apply! — Functionapply!(cw::CrosswordPuzzle, m::Place)
undo!(cw::CrosswordPuzzle, m::Place)Apply/undo a move of type Place.
Example
julia> cw = example_crossword(type="partial")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘
julia> slot = find_constrained_slots(cw)[2]
Slot(6, 1, :horizontal, 6, ".I...W", true, true)
julia> out = generate_moves(cw, slot, allow_split=true, allow_enlarge=true);
julia> out[1]
Place(Slot(6, 1, :horizontal, 6, ".I...W", true, true), "BILLOW")
julia> apply!(cw, out[1])
true
julia> cw
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ B I L L O W │
└──────────────────┘
julia> undo!(cw, out[1])
true
julia> cw
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘apply!(cw::CrosswordPuzzle, m::SplitAndPlace)
undo!(cw::CrosswordPuzzle, m::SplitAndPlace)Apply/undo a move of type SplitAndPlace.
Example
julia> cw = example_crossword(type="partial")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘
julia> slot = find_constrained_slots(cw)[2]
Slot(6, 1, :horizontal, 6, ".I...W", true, true)
julia> out = generate_moves(cw, slot, allow_split=true, allow_enlarge=true);
julia> out[1000]
SplitAndPlace(Slot(6, 1, :horizontal, 6, ".I...W", true, true), 4, "BIM", "XW")
julia> apply!(cw, out[1000])
true
julia> cw
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ B I M ■ X W │
└──────────────────┘
julia> undo!(cw, out[1000])
true
julia> cw
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘apply!(cw::CrosswordPuzzle, m::EnlargeAndPlace)
undo!(cw::CrosswordPuzzle, m::EnlargeAndPlace)Apply/undo a move of type EnlargeAndPlace.
Example
julia> cw = example_crossword(type="partial")
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘
julia> slot = find_constrained_slots(cw)[2]
Slot(6, 1, :horizontal, 6, ".I...W", true, true)
julia> out = generate_moves(cw, slot, allow_split=true, allow_enlarge=true);
julia> out[end]
EnlargeAndPlace(Slot(6, 1, :horizontal, 6, ".I...W", true, true), "WHIPSAW", 1, 0)
julia> apply!(cw, out[end])
true
julia> cw
1 2 3 4 5 6 7
┌─────────────────────┐
1 │ ■ G O L D E N │
2 │ ■ A N ■ ⋅ ■ A │
3 │ ⋅ T ■ ⋅ ⋅ ⋅ R │
4 │ ■ E V E R ■ R │
5 │ ⋅ ■ I E ■ ■ O │
6 │ W H I P S A W │
└─────────────────────┘
julia> undo!(cw, out[end])
true
julia> cw
1 2 3 4 5 6
┌──────────────────┐
1 │ G O L D E N │
2 │ A N ■ ⋅ ■ A │
3 │ T ■ ⋅ ⋅ ⋅ R │
4 │ E V E R ■ R │
5 │ ■ I E ■ ■ O │
6 │ ⋅ I ⋅ ⋅ ⋅ W │
└──────────────────┘Enigmistics.undo! — FunctionAlgorithms
Enigmistics.solve! — Functionsolve!(cw::CrosswordPuzzle; seed=rand(Int), kwargs...)Fill a crossword puzzle cw using a backtracking algorithm with Minimum Remaining Values (MRV) heuristic, considering all types of moves (simple placements, splits with black cells, enlargements).
Arguments:
max_trials_per_slot=10: maximum number of candidate words to try for each slot. It gets scaled as the completeness of the grid increases to allow more trials towards the end of the search, when the grid is almost full and therefore also more constrainedmin_options_to_allow_split=5: if a slot has more than this number of candidate words with the simple method, then we do not consider moves involving splits with black cells when filling that slotmin_options_to_allow_enlarge=0: if a slot has more than this number of candidate words with the simple method, then we do not consider moves involving enlarging the grid when filling that slotmax_enlarge=1: maximum number of cells by which to enlarge the grid when considering moves of typeEnlargeAndPlaceverbose=true: print the completeness percentage of the grid during the search (useful also for allowing interrupts through ctrl+c)see_evolution=false: display the status of the grid at each step of the algorithm, therefore allowing to see the grid filling in real time (note: this option will likely produce a slower execution time)
Example
julia> cw = random_pattern(10,14)
1 2 3 4 5 6 7 8 9 10 11 12 13 14
┌──────────────────────────────────────────┐
1 │ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ⋅ │
2 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ⋅ │
3 │ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ │
4 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
5 │ ⋅ ■ ■ ⋅ ■ ⋅ ⋅ ■ ⋅ ⋅ ■ ⋅ ⋅ ⋅ │
6 │ ⋅ ⋅ ⋅ ■ ⋅ ⋅ ■ ⋅ ⋅ ■ ⋅ ■ ■ ⋅ │
7 │ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
8 │ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ │
9 │ ⋅ ⋅ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ │
10 │ ⋅ ⋅ ■ ■ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ⋅ ■ ■ │
└──────────────────────────────────────────┘
julia> solve!(cw, min_options_to_allow_split=0)
true
julia> cw
1 2 3 4 5 6 7 8 9 10 11 12 13 14
┌──────────────────────────────────────────┐
1 │ ■ ■ C A R A C A R A ■ ■ O W │
2 │ B L U E C U R A C A O ■ S R │
3 │ L A R I D ■ E ■ ■ S W A M I │
4 │ I M N O T F E E L I N G I T │
5 │ N ■ ■ U ■ C K ■ A N ■ U N E │
6 │ D K S ■ A K ■ N R ■ A ■ ■ A │
7 │ S C R A T C H A N D C L A W │
8 │ I A I N T ■ ■ I ■ A E C I A │
9 │ D M ■ C A T A R R H A L L Y │
10 │ E P ■ ■ R E D N O S E S ■ ■ │
└──────────────────────────────────────────┘