-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay03.hs
42 lines (38 loc) · 919 Bytes
/
Day03.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
-- |
-- Module : AOC2016.Day03
-- License : BSD3
--
-- Stability : experimental
-- Portability : non-portable
--
-- Day 3. See "AOC.Solver" for the types used in this module!
module AOC2016.Day03 (
day03a,
day03b,
) where
import AOC.Solver ((:~>) (..))
import Data.List (sortBy, transpose)
import Data.List.Split (chunksOf)
import Text.Read (readMaybe)
isTriangle :: [Int] -> Bool
isTriangle (sortBy (flip compare) -> (x : xs)) = sum xs > x
isTriangle _ = False
day03a :: [[Int]] :~> Int
day03a =
MkSol
{ sParse = traverse (traverse readMaybe . words) . lines
, sShow = show
, sSolve = Just . length . filter isTriangle
}
day03b :: [[Int]] :~> _
day03b =
MkSol
{ sParse = traverse (traverse readMaybe . words) . lines
, sShow = show
, sSolve =
Just
. length
. filter isTriangle
. concatMap transpose
. chunksOf 3
}