Calorie Counting

Description: https://adventofcode.com/2022/day/1

open System.IO
open System

type Input() =
    let UpdateNewMax (topN: int, newValue: int, max: List<int>) : List<int> =
        max @ [ newValue ]
        |> Seq.sortDescending
        |> Seq.truncate topN
        |> List.ofSeq

    member _.GetMaxSum(topN: int) =
        use stream = new StreamReader "./input.txt"

        let mutable max: List<int> = []
        let mutable sum = 0
        let mutable endOfFile = false

        while (not endOfFile) do
            let line = stream.ReadLine()

            if (line = null) then
                endOfFile <- true
            else if (line = "") then
                max <- UpdateNewMax(topN, sum, max)
                sum <- 0
            else
                sum <- sum + (line |> int)

        max |> List.sum

let input = Input()
let topN = (Environment.GetCommandLineArgs()[1]) |> int

printfn "%d" (input.GetMaxSum(topN))