diff options
author | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2022-12-21 11:45:04 +0100 |
---|---|---|
committer | Tomasz Chojnacki <tomaszchojnacki2001@gmail.com> | 2022-12-21 11:45:04 +0100 |
commit | 9e378a9f80260c2f729daaf83d8e74f7bad70b16 (patch) | |
tree | db61e67a7222cd0666ea7fe4976e2fded327599a /aoc-2022-dotnet/Common/Util.fs | |
parent | a8c844a12fa2d91410fda7b37f08c58f5be34ed9 (diff) | |
download | gleam_aoc2020-9e378a9f80260c2f729daaf83d8e74f7bad70b16.tar.gz gleam_aoc2020-9e378a9f80260c2f729daaf83d8e74f7bad70b16.zip |
Finish day 17
Diffstat (limited to 'aoc-2022-dotnet/Common/Util.fs')
-rw-r--r-- | aoc-2022-dotnet/Common/Util.fs | 16 |
1 files changed, 15 insertions, 1 deletions
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 -> |