day3: update - avoid using unecessary helpers
Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
17
day3.hs
17
day3.hs
@@ -1,27 +1,24 @@
|
||||
import Data.Char (isAsciiLower, isAsciiUpper)
|
||||
import Data.List (intersect)
|
||||
import Lib (chunks)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
input <- readFile "day3.in"
|
||||
input <- lines <$> readFile "day3.in"
|
||||
putStr "Q1: "
|
||||
print $ q1 input
|
||||
putStr "Q2: "
|
||||
print $ q2 input
|
||||
|
||||
q1 :: String -> Int
|
||||
q1 :: [String] -> Int
|
||||
q1 =
|
||||
sum
|
||||
. map (\x -> val . head . uncurry intersect $ splitAt (div (length x) 2) x)
|
||||
. lines
|
||||
|
||||
q2 :: String -> Int
|
||||
q2 =
|
||||
sum
|
||||
. map (val . head . foldr1 intersect)
|
||||
. chunks 3
|
||||
. lines
|
||||
q2 :: [String] -> Int
|
||||
q2 [] = 0
|
||||
q2 input =
|
||||
let (cur, rest) = splitAt 3 input
|
||||
in (val . head . foldr1 intersect) cur + q2 rest
|
||||
|
||||
val :: Char -> Int
|
||||
val c
|
||||
|
Reference in New Issue
Block a user