aboutsummaryrefslogtreecommitdiff
path: root/aoc-2022-dotnet/Day01/Program.fs
diff options
context:
space:
mode:
Diffstat (limited to 'aoc-2022-dotnet/Day01/Program.fs')
-rw-r--r--aoc-2022-dotnet/Day01/Program.fs22
1 files changed, 10 insertions, 12 deletions
diff --git a/aoc-2022-dotnet/Day01/Program.fs b/aoc-2022-dotnet/Day01/Program.fs
index adcb20e..bf42670 100644
--- a/aoc-2022-dotnet/Day01/Program.fs
+++ b/aoc-2022-dotnet/Day01/Program.fs
@@ -6,13 +6,12 @@ let parseLine =
| "" -> -1
| l -> int l
-let caloriesPerElf data =
- data |> Seq.split [ [ -1 ] ] |> Seq.map Seq.sum
+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)
+ | h :: t -> min h x :: (insertSorted (max h x) t)
| _ -> [ x ]
Seq.fold
@@ -20,23 +19,22 @@ let topN n xs =
if List.length acc < n then
insertSorted x acc
elif List.head acc < x then
- insertSorted x (List.tail acc)
+ insertSorted x <| List.tail acc
else
acc)
List.empty
xs
-let solution n input =
- input
- |> Seq.map parseLine
- |> caloriesPerElf
- |> topN n
- |> List.sum
+let solution n =
+ Seq.map parseLine
+ >> caloriesPerElf
+ >> 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)
+printfn "%d" <| solution 1 input
+printfn "%d" <| solution 3 input