ninetynine-1.3.0: Ninety-Nine Haskell Problems
CopyrightCopyright (C) 2021 Yoo Chung
LicenseGPL-3.0-or-later
Maintainerdev@chungyc.org
Safe HaskellSafe-Inferred
LanguageGHC2021

Problems.Crosswords

Description

Supporting definitions for crossword puzzles. In particular, this supports Problems.P99.

Synopsis

Documentation

data Crossword Source #

A crossword puzzle.

A list of words to fill the puzzle with is given along the grid to fill. The crossword puzzle grid is represented with a list of sublists. Each sublist denotes a row, and each value in the sublists denotes a spot. For each value in a spot:

  • True denotes a blank spot that needs a character to be filled in.
  • False denotes a spot that cannot be filled in.
  • A character value denotes a spot pre-filled with the character.

Constructors

Crossword 

Fields

Instances

Instances details
Show Crossword Source # 
Instance details

Defined in Problems.Crosswords

Eq Crossword Source # 
Instance details

Defined in Problems.Crosswords

printCrossword :: Maybe [[Maybe Char]] -> IO () Source #

Print out a solution to a crossword puzzle.

>>> :{
printCrossword $ Just [ [ Nothing,  Nothing,  Just 'P', Nothing,  Nothing  ]
                      , [ Nothing,  Nothing,  Just 'O', Nothing,  Nothing  ]
                      , [ Just 'A', Just 'L', Just 'P', Just 'H', Just 'A' ]
                      , [ Nothing,  Nothing,  Just 'P', Nothing,  Just 'R' ]
                      , [ Nothing,  Nothing,  Just 'Y', Nothing,  Just 'E' ]
                      , [ Nothing,  Nothing,  Nothing,  Nothing,  Just 'S' ]
                      ]
:}
■ ■ P ■ ■
■ ■ O ■ ■
A L P H A
■ ■ P ■ R
■ ■ Y ■ E
■ ■ ■ ■ S

parseCrossword :: String -> Maybe Crossword Source #

Parses a crossword puzzle specification in a particular syntax.

It first lists the words in an arbitrary order, one word per line. Then, after an empty line, the crossword grid is defined. In this grid specification, a blank spot is represented by a dot (.). Spots can also contain predefined character values.

Notes

Expand

This parses the crossword specifications provided by problem 99 in the original list.

readCrossword :: FilePath -> IO (Maybe Crossword) Source #

Reads a crossword puzzle from a file, whose syntax is as specified by parseCrossword.

Notes

Expand

This parses the crossword specifications provided by problem 99 in the original list.