Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930
  1. module Day3.Part1 (
  2. splitContents,
  3. itemsInBoth,
  4. itemPriority,
  5. priority,
  6. rearrangementPriority,
  7. )
  8. where
  9. import qualified Data.Set as Set
  10. import Day3.Shared
  11. splitContents :: Contents -> (Contents, Contents)
  12. splitContents c = splitAt middle c
  13. where
  14. middle = length c `div` 2
  15. itemsInBoth :: Contents -> Contents
  16. itemsInBoth cs = Set.toList $ leftSet `Set.intersection` rightSet
  17. where
  18. (left, right) = splitContents cs
  19. leftSet = Set.fromList left
  20. rightSet = Set.fromList right
  21. rearrangementPriority :: String -> Int
  22. rearrangementPriority input = sum priorities
  23. where
  24. contents = lines input
  25. priorities = map (priority . itemsInBoth) contents