-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay8.hs
35 lines (30 loc) · 778 Bytes
/
Day8.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
module Day8
( part1
, part2
) where
import Data.Char (digitToInt)
import Data.List (group, minimumBy, sort)
import Data.List.Split (chunksOf)
render :: [Int] -> [Int] -> [Int]
render =
zipWith
(\x y ->
if x == 2
then y
else x)
stringify :: [Int] -> String
stringify = unlines . chunksOf 25 . map charify
where
charify 1 = '#'
charify 0 = ' '
part1 :: Bool -> String -> String
part1 _ =
show .
product .
map length .
tail .
minimumBy (\a b -> compare (length . head $ a) (length . head $ b)) .
map (group . sort) . chunksOf 150 . map digitToInt . init
part2 :: Bool -> String -> String
part2 _ =
stringify . foldl render (repeat 2) . chunksOf 150 . map digitToInt . init