aboutsummaryrefslogtreecommitdiff
path: root/aoc-2022-dotnet/Day01/Program.fs
blob: 3a06ef1c32f3d9ba624843e93b21215b7a56e9b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
module Day01

open System.IO
open FSharpPlus
open Common

let parseLine =
    function
    | "" -> -1
    | l -> int l

let caloriesPerElf = Seq.split [ [ -1 ] ] >> Seq.map Seq.sum

let solution n =
    Seq.map parseLine
    >> caloriesPerElf
    >> Util.topN n
    >> List.sum

let test = File.ReadLines "test.txt"
assert (solution 1 test = 24000)
assert (solution 3 test = 45000)

let input = File.ReadLines "input.txt"
printfn "%d" <| solution 1 input
printfn "%d" <| solution 3 input