AoC 2022 D1: Calorie Counting

Haskell | Problem statement | Source code | Tags: Brute force

Back to AoC Index Next →

Part 1

Yes, yes, I know that finding the kkth largest number in a list can be done in linear time with the Quickselect algorithm, but given that the input has fewer than 300 elves, I decided to just sort the list and pick the first element.

getTops :: [Text] -> [Int]
getTops input = sortOn Down tops
where
tops = map (sumMap (read . T.unpack) . T.lines) $ splitT "\n\n" $ T.unlines input
hs

Part 2

The same function as above, just picking the first three elements instead of just the first. Again, if I used Quickselect, this would be O(n)\mathcal{O}(n) instead of O(nlogn)\mathcal{O}(n \log n).

Back to AoC Index Next →