-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.hs
More file actions
38 lines (31 loc) · 690 Bytes
/
run.hs
File metadata and controls
38 lines (31 loc) · 690 Bytes
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
import Data.List (elemIndex, intersect, nub)
import Data.List.Split (chunksOf)
score :: Char -> Int
score x =
(+ 1)
. sum
. elemIndex x
$ ['a'..'z'] ++ ['A'..'Z']
evenSplit :: [a] -> ([a], [a])
evenSplit x =
let l = length x
in
splitAt (l `div` 2) x
parseAll :: String -> [String]
parseAll = lines
part1 :: [String] -> Int
part1 =
sum
. map (score . head . nub . uncurry intersect . evenSplit)
part2 :: [String] -> Int
part2 =
sum
. map (score . head . nub . foldl1 intersect)
. chunksOf 3
main :: IO ()
main = main' "input.txt"
main' :: FilePath -> IO ()
main' file = do
input <- parseAll <$> readFile file
print (part1 input)
print (part2 input)