-
Notifications
You must be signed in to change notification settings - Fork 0
/
3b.hs
24 lines (20 loc) · 862 Bytes
/
3b.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
main = do lines <- getLines
putStrLn $ show $ sum $ map (priorities . findBadge) $ intoThrees lines
getLines :: IO ([String])
getLines = do x <- getLine
if x == ""
then return []
else do xs <- getLines
return (x:xs)
intoThrees :: [String] -> [(String,String,String)]
intoThrees [] = []
intoThrees (a:b:c:ds) = (a,b,c) : intoThrees ds
findBadge :: (String,String,String) -> Char
findBadge ([],bs,cs) = 'a'
findBadge (a:as,bs,cs) | a `elem` bs && a `elem` cs = a
| otherwise = findBadge (as,bs,cs)
priorities :: Char -> Int
priorities = char2int "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 1
where char2int :: String -> Int -> Char -> Int
char2int (x:xs) i a | a == x = i
| otherwise = char2int xs (i+1) a