From 3a944693f0fb32da3aa4e7bd9d6c74412f9504bf Mon Sep 17 00:00:00 2001 From: Ummon Date: Wed, 13 Dec 2017 11:01:07 +0100 Subject: [PATCH] Add a new test case and correct the code accordingly --- AdventOfCode2017/Day13.fs | 6 +++--- Tests/Day13 tests.fs | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/AdventOfCode2017/Day13.fs b/AdventOfCode2017/Day13.fs index c4b8bf0..b452c04 100644 --- a/AdventOfCode2017/Day13.fs +++ b/AdventOfCode2017/Day13.fs @@ -9,7 +9,7 @@ let parseInput (lines : string[]) = ) 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 diff --git a/Tests/Day13 tests.fs b/Tests/Day13 tests.fs index 5d3437e..3848eec 100644 --- a/Tests/Day13 tests.fs +++ b/Tests/Day13 tests.fs @@ -19,7 +19,6 @@ type ``Day13 tests`` (output : ITestOutputHelper) = |] Day13.severity (Day13.parseInput input) |> fst =! 24 - [] let ``(Part2) From web page`` () = let input = @@ -29,4 +28,13 @@ type ``Day13 tests`` (output : ITestOutputHelper) = "4: 4" "6: 4" |] - Day13.severity (Day13.parseInput input) |> snd =! 10 \ No newline at end of file + Day13.severity (Day13.parseInput input) |> snd =! 10 + + + [] + let ``(Part2) one depth`` () = + let input = + [| + "0: 3" + |] + Day13.severity (Day13.parseInput input) |> snd =! 1 \ No newline at end of file -- 2.45.2