Copyright | (c) Justin Le 2020 |
---|---|
License | BSD3 |
Maintainer | justin@jle.im |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Library to parse "ASCII Art" letters from <https://adventofcode.com Advent of Code> puzzles. Compatible with all puzzles from 2015 to 2019.
Synopsis
- parseLetters :: Set (Int, Int) -> Maybe String
- parseLettersWith :: (a -> Int) -> (a -> Int) -> Set a -> Maybe String
- parseLettersEither :: Set (Int, Int) -> Maybe [Either (Set (Int, Int)) Char]
- unsafeParseLetters :: Set (Int, Int) -> String
- parseAsciiMap :: Set Char -> String -> Set (Int, Int)
- asciiMapToLetters :: Set Char -> String -> Maybe String
- data LetterMap
- defaultLetterMap :: LetterMap
- parseLetters' :: LetterMap -> Set (Int, Int) -> Maybe String
- parseLettersWith' :: LetterMap -> (a -> Int) -> (a -> Int) -> Set a -> Maybe String
- parseLettersEither' :: LetterMap -> Set (Int, Int) -> Maybe [Either (Set (Int, Int)) Char]
- unsafeParseLetters' :: LetterMap -> Set (Int, Int) -> String
- asciiMapToLetters' :: Set Char -> LetterMap -> String -> Maybe String
Parse
The go-to default: given a set of point coordinates, parse it into the string it represents. Should be compatible with any Advent of Code challenge from 2015 to 2019.
parseLetters
defaultLetterMap
myPoints -- or, using Data.DefaultparseLetters
def
myPoints
A Nothing
means that there were no recognized letters found. A Just
means that least 50% of letter forms are recognized. Unrecognized
characters will be replaced with "?"; for more information, use
parseLettersEither
.
This function is robust to changes in orientation or flipping, but will be fastest if the coordinates are oriented with (0,0) on the upper left corner. However, because of this, it might return the wrong answer if your coordinates are not oriented this way and your result is symmetrical: it'll always prioritize the interpretaion against (0,0) upper-left orientation first.
A version of parseLetters
that takes a set of any type of value, as
long as you provide functions to access the X and Y coordinates.
parseLettersEither :: Set (Int, Int) -> Maybe [Either (Set (Int, Int)) Char] Source #
A version of parseLetters
returning a list of characters that were
either recognized or unrecognized; in the case of unrecognized
characters, returns the set of their coordinates but shifted to (0, 0)
as its upper left corner.
unsafeParseLetters :: Set (Int, Int) -> String Source #
A version of parseLetters
that will be undefined (error
) when no
parse is found.
Parse raw ASCII art into a set of points, usable with
parseLetters
.
Convenient all-in-one utility function combining parseAsciiMap
and
parseLetters
, to directly parse ASCII art into its letters.
Letter Map
A database associating a set of "on" points to the letter they represent.
See defaultLetterMap
for a database compatible
with Advent of Code 2015-2019.
Instances
Data LetterMap Source # | |
Defined in Advent.OCR.LetterMap gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> LetterMap -> c LetterMap # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c LetterMap # toConstr :: LetterMap -> Constr # dataTypeOf :: LetterMap -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c LetterMap) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c LetterMap) # gmapT :: (forall b. Data b => b -> b) -> LetterMap -> LetterMap # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> LetterMap -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> LetterMap -> r # gmapQ :: (forall d. Data d => d -> u) -> LetterMap -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> LetterMap -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> LetterMap -> m LetterMap # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> LetterMap -> m LetterMap # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> LetterMap -> m LetterMap # | |
Monoid LetterMap Source # | |
Semigroup LetterMap Source # | |
Generic LetterMap Source # | |
Show LetterMap Source # | |
Default LetterMap Source # | Default is compatible with all challenges in Advent of Code 2015 to 2019. |
Defined in Advent.OCR.Internal | |
Eq LetterMap Source # | |
Ord LetterMap Source # | |
Defined in Advent.OCR.LetterMap | |
Lift LetterMap Source # | |
type Rep LetterMap Source # | |
Defined in Advent.OCR.LetterMap |
defaultLetterMap :: LetterMap Source #
The default lettermap compatible all challenges in Advent of Code 2015 - 2019.
Custom Letter Map
:: LetterMap | database of letterforms |
-> Set (Int, Int) | set of points |
-> Maybe String | result, with unknown letters replaced with "?" |
A version of parseLetters'
accepting a custom LetterMap
letterform
database.
A version of parseLettersWith'
accepting a custom LetterMap
letterform database.
A version of parseLettersEither'
accepting a custom LetterMap
letterform database.
unsafeParseLetters' :: LetterMap -> Set (Int, Int) -> String Source #
A version of unsafeParseLetters'
accepting a custom LetterMap
letterform database.