From 9e378a9f80260c2f729daaf83d8e74f7bad70b16 Mon Sep 17 00:00:00 2001 From: Tomasz Chojnacki Date: Wed, 21 Dec 2022 11:45:04 +0100 Subject: Finish day 17 --- aoc-2022-dotnet/Common/Util.fs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'aoc-2022-dotnet/Common/Util.fs') diff --git a/aoc-2022-dotnet/Common/Util.fs b/aoc-2022-dotnet/Common/Util.fs index acf89af..568f2c2 100644 --- a/aoc-2022-dotnet/Common/Util.fs +++ b/aoc-2022-dotnet/Common/Util.fs @@ -38,7 +38,11 @@ module Util = let mAt matrix (Vec2 (col, row)) = Array2D.get matrix row col - let composition n f = List.replicate n f |> List.reduce (>>) + let rec composition n f x = + if n = 0 then + x + else + composition (n - 1) f (f x) let notIn set element = not <| Set.contains element set @@ -51,6 +55,16 @@ module Util = | h :: t -> min h x :: (insertSorted (max h x) t) | [] -> [ x ] + let liftList xs = + match List.forall Option.isSome xs with + | true -> Some(List.map Option.get xs) + | false -> None + + let cycle = + function + | h :: t -> h, t @ [ h ] + | [] -> failwith "Empty list!" + let topN n xs = Seq.fold (fun acc x -> -- cgit v1.2.3