This repository was archived by the owner on Nov 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDay08.hs
52 lines (48 loc) · 1.6 KB
/
Day08.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
-- |
-- Module : AOC.Challenge.Day08
-- License : BSD3
--
-- Stability : experimental
-- Portability : non-portable
--
-- Day 8. See "AOC.Solver" for the types used in this module!
--
-- After completing the challenge, it is recommended to:
module AOC.Challenge.Day08 (
day08a
, day08b
) where
import AOC.Common (parseAsciiMap, countTrue)
import AOC.Solver ((:~>)(..), dyno_)
import Advent.OCR (parseLettersWith)
import Control.Monad (guard)
import Control.Lens (view)
import Data.List (transpose)
import Data.List.Split (chunksOf)
import Data.Maybe (fromMaybe)
import Data.Maybe (listToMaybe, fromJust)
import Data.Ord (comparing)
import Linear (_x, _y)
import Safe (minimumByMay)
import qualified Data.Map as M
day08a :: String :~> Int
day08a = MkSol
{ sParse = Just
, sShow = show
, sSolve = fmap answer
. minimumByMay (comparing (countTrue (== '0')))
. chunksOf (dyno_ "w" 25 * dyno_ "h" 6)
}
where
answer x = countTrue (== '1') x * countTrue (== '2') x
day08b :: [String] :~> String
day08b = MkSol
{ sParse = Just . chunksOf 150
-- , sShow = unlines . chunksOf 25 . map (\case '0' -> ' '; _ -> '#')
, sShow = fromMaybe "" . parseLettersWith (view _x) (view _y)
. M.keysSet
. parseAsciiMap (guard . (== '1'))
. unlines
. chunksOf 25
, sSolve = traverse (listToMaybe . filter (/= '2')) . transpose
}