123456789101112131415161718192021222324252627282930 |
- module Day3.Part1 (
- splitContents,
- itemsInBoth,
- itemPriority,
- priority,
- rearrangementPriority,
- )
- where
-
- import qualified Data.Set as Set
- import Day3.Shared
-
-
- splitContents :: Contents -> (Contents, Contents)
- splitContents c = splitAt middle c
- where
- middle = length c `div` 2
-
- itemsInBoth :: Contents -> Contents
- itemsInBoth cs = Set.toList $ leftSet `Set.intersection` rightSet
- where
- (left, right) = splitContents cs
- leftSet = Set.fromList left
- rightSet = Set.fromList right
-
- rearrangementPriority :: String -> Int
- rearrangementPriority input = sum priorities
- where
- contents = lines input
- priorities = map (priority . itemsInBoth) contents
|