)
let severity (input : (int * int)[]) =
- let inline sum delay =
- input |> Array.sumBy (fun (d, r) -> if (d + delay) % (2 * r - 2) = 0 then (d + delay) * r else 0)
+ let inline sumBy (f : int -> int -> int) delay =
+ input |> Array.sumBy (fun (d, r) -> if (d + delay) % (2 * r - 2) = 0 then f d r else 0)
- sum 0, Seq.initInfinite (fun i -> i, sum i) |> Seq.pick (fun (i, s) -> if s = 0 then Some i else None)
\ No newline at end of file
+ sumBy (*) 0, Seq.initInfinite (fun i -> i, sumBy (+) i) |> Seq.pick (fun (i, s) -> if s = 0 then Some i else None)
\ No newline at end of file
|]
Day13.severity (Day13.parseInput input) |> fst =! 24
-
[<Fact>]
let ``(Part2) From web page`` () =
let input =
"4: 4"
"6: 4"
|]
- Day13.severity (Day13.parseInput input) |> snd =! 10
\ No newline at end of file
+ Day13.severity (Day13.parseInput input) |> snd =! 10
+
+
+ [<Fact>]
+ let ``(Part2) one depth`` () =
+ let input =
+ [|
+ "0: 3"
+ |]
+ Day13.severity (Day13.parseInput input) |> snd =! 1
\ No newline at end of file