advent-of-code/app/three2.hs

23 lines
568 B
Haskell
Raw Permalink Normal View History

2022-12-17 14:50:06 +01:00
import Data.Char
import Data.List.Split
inAll :: [String] -> [Char]
inAll [first,second,third] = do
eachChar <- first
if (eachChar `elem` second && eachChar `elem` third) then return eachChar 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 . inAll ) $ chunksOf 3 $ lines input
--print $map ( inAll ) $ chunksOf 3 $ lines input