aoc2022/3-b-v2.hs

25 lines
618 B
Haskell

-- i found out that intersect exists so i redid day 3
import Data.Char
import Data.List
import GHC.Utils.Misc
getCharPriority c
| isLower c = fromEnum c - 96
| isUpper c = fromEnum c - 64 + 26
| otherwise = undefined
findDuplicate :: [String] -> Char
findDuplicate [l1, l2, l3] = only $ l1 `intersect` l2 `intersect` l3
findDuplicate _ = undefined
extractIntoGroups :: Int -> [String] -> [[String]]
extractIntoGroups s l
| s > length l = []
| otherwise = take s l : extractIntoGroups s (drop s l)
main = interact $
show . sum
. map (getCharPriority . findDuplicate)
. extractIntoGroups 3
. lines