Last active
December 3, 2022 15:04
-
-
Save hovsater/b542f03028cf54e487dcb1b889a165ce to your computer and use it in GitHub Desktop.
Solution to Advent of Code 2022, Day 1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Day01 exposing (partOne, partTwo) | |
decreasingOrder : comparable -> comparable -> Order | |
decreasingOrder a b = | |
case compare a b of | |
LT -> | |
GT | |
EQ -> | |
EQ | |
GT -> | |
LT | |
type alias CalorieCount = | |
Int | |
type alias ElfInventory = | |
List CalorieCount | |
parseList : String -> List ElfInventory | |
parseList list = | |
list | |
|> String.split "\n\n" | |
|> List.map (String.split "\n" >> List.filterMap String.toInt) | |
partOne : String -> Int | |
partOne input = | |
input | |
|> parseList | |
|> List.map List.sum | |
|> List.maximum | |
|> Maybe.withDefault 0 | |
partTwo : String -> Int | |
partTwo input = | |
input | |
|> parseList | |
|> List.map List.sum | |
|> List.sortWith decreasingOrder | |
|> List.take 3 | |
|> List.sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment