diff options
Diffstat (limited to 'aoc-2022-dotnet/Day01/Program.fs')
-rw-r--r-- | aoc-2022-dotnet/Day01/Program.fs | 20 |
1 files changed, 2 insertions, 18 deletions
diff --git a/aoc-2022-dotnet/Day01/Program.fs b/aoc-2022-dotnet/Day01/Program.fs index 71faaae..3a06ef1 100644 --- a/aoc-2022-dotnet/Day01/Program.fs +++ b/aoc-2022-dotnet/Day01/Program.fs @@ -2,6 +2,7 @@ open System.IO open FSharpPlus +open Common let parseLine = function @@ -10,27 +11,10 @@ let parseLine = let caloriesPerElf = Seq.split [ [ -1 ] ] >> Seq.map Seq.sum -let topN n xs = - let rec insertSorted x = - function - | h :: t -> min h x :: (insertSorted (max h x) t) - | _ -> [ x ] - - Seq.fold - (fun acc x -> - if List.length acc < n then - insertSorted x acc - elif List.head acc < x then - insertSorted x <| List.tail acc - else - acc) - List.empty - xs - let solution n = Seq.map parseLine >> caloriesPerElf - >> topN n + >> Util.topN n >> List.sum let test = File.ReadLines "test.txt" |