advent-of-code/three.hs

23 lines
565 B
Haskell
Raw Normal View History

2022-12-11 13:04:30 +01:00
import Data.Char
2022-12-10 18:50:02 +01:00
splitlist :: [a] -> ([a],[a])
splitlist list = (take n list,drop n list)
where n = (length list) `div` 2
inBoth :: (Eq a) => ([a],[a]) -> [a]
inBoth (first,second) = do
inFirst <- first
if (inFirst `elem` second) then return inFirst else []
2022-12-11 13:04:30 +01:00
toPriority :: Char -> Int
toPriority char = ordNum - (substract ordNum)
where
ordNum = (ord char)
substract n
| n < 97 = 38
| otherwise = 96
2022-12-10 18:50:02 +01:00
main = do
input <- readFile "three-input.txt"
2022-12-11 13:04:30 +01:00
print $sum $ map (toPriority . head . inBoth . splitlist ) $ lines input