God this is cluttered
This commit is contained in:
parent
9c415c44cc
commit
c4d8bef5f7
30
app/2.hs
30
app/2.hs
@ -0,0 +1,30 @@
|
|||||||
|
{-# LANGUAGE LambdaCase, MultiWayIf #-}
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
import Data.Functor
|
||||||
|
|
||||||
|
parse :: String -> [[Int]]
|
||||||
|
parse = ((read <$>) . words <$>) . lines
|
||||||
|
|
||||||
|
solve1 :: [[Int]] -> Int
|
||||||
|
solve1 =
|
||||||
|
let di a = all (\a' -> a' < 4 && not (a' <= 0)) a ||
|
||||||
|
all (\a' -> a' > -4 && not (a' >= 0)) a in
|
||||||
|
sum . ((\a -> if di $ zipWith (flip (-)) a (tail a) then 1 else 0) <$>)
|
||||||
|
|
||||||
|
solve2 :: [[Int]] -> Int
|
||||||
|
solve2 =
|
||||||
|
let r [] = [[]]
|
||||||
|
r (r':rs) = rs:((r':) <$> r rs)
|
||||||
|
di a = all (\a' -> a' < 4 && not (a' <= 0)) a ||
|
||||||
|
all (\a' -> a' > -4 && not (a' >= 0)) a in
|
||||||
|
sum . ((\a ->
|
||||||
|
if any (\b -> di $ zipWith (flip (-)) b (tail b)) a
|
||||||
|
then 1 else 0) .
|
||||||
|
r <$>)
|
||||||
|
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = readFile "inputs/2" <&> parse >>= \i ->
|
||||||
|
print (solve1 i) >>
|
||||||
|
print (solve2 i)
|
Loading…
Reference in New Issue
Block a user