advent-of-code/app/three.hs

23 lines
565 B
Haskell
Raw Normal View History

2022-12-17 14:50:06 +01:00
import Data.Char
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 []
toPriority :: Char -> Int
toPriority char = ordNum - (substract ordNum)
where
ordNum = (ord char)
substract n
| n < 97 = 38
| otherwise = 96
main = do
input <- readFile "three-input.txt"
print $sum $ map (toPriority . head . inBoth . splitlist ) $ lines input