Day2: Make pretty
This commit is contained in:
parent
3a4709d5b2
commit
ea7ef85958
|
@ -1,25 +1,25 @@
|
||||||
import Control.Arrow
|
|
||||||
import Control.Monad
|
|
||||||
import Data.List.Split
|
import Data.List.Split
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
input <- lines <$> readFile "input"
|
input <- lines <$> readFile "input"
|
||||||
print $ day2a input
|
print $ day2 f1 input
|
||||||
print $ day2b input
|
print $ day2 f2 input
|
||||||
|
|
||||||
predicate :: String -> Bool
|
day2 :: (String -> Int -> Int -> Char -> Bool) -> [String] -> Int
|
||||||
predicate line = (l>=a) && (l<=b)
|
day2 f = length . filter (predicate f)
|
||||||
where c = head $ words p !! 1
|
|
||||||
[a,b] = map read $ splitOn "-" $ head $ words p
|
|
||||||
l = length $ filter (==c) str
|
|
||||||
[p,str] = splitOn ": " line
|
|
||||||
|
|
||||||
day2a = length . filter predicate
|
f1 :: String -> Int -> Int -> Char -> Bool
|
||||||
day2b = length . filter predicate2
|
f1 str a b c = (l >= a) && (l <= b)
|
||||||
|
where
|
||||||
|
l = length $ filter (== c) str
|
||||||
|
|
||||||
predicate2 :: String -> Bool
|
f2 :: String -> Int -> Int -> Char -> Bool
|
||||||
predicate2 line = (str!!a==c) /= (str!!b==c)
|
f2 str a b c = (str !! pred a == c) /= (str !! pred b == c)
|
||||||
where c = head $ words p !! 1
|
|
||||||
[a,b] = map (subtract 1 . read) $ splitOn "-" $ head $ words p
|
predicate :: (String -> Int -> Int -> Char -> Bool) -> String -> Bool
|
||||||
[p,str] = splitOn ": " line
|
predicate f line = f str a b c
|
||||||
|
where
|
||||||
|
c = head $ words p !! 1
|
||||||
|
[a, b] = map read $ splitOn "-" $ head $ words p
|
||||||
|
[p, str] = splitOn ": " line
|
||||||
|
|
Loading…
Reference in New Issue
Block a user