From: Ummon Date: Wed, 13 Dec 2017 08:39:03 +0000 (+0100) Subject: More concise X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=1997349fd08f3abefaabd3bed43ab43e88cd4b6e;p=advent_of_code_2017.git More concise --- diff --git a/AdventOfCode2017/Day13.fs b/AdventOfCode2017/Day13.fs index d1b1b2a..c4b8bf0 100644 --- a/AdventOfCode2017/Day13.fs +++ b/AdventOfCode2017/Day13.fs @@ -1,17 +1,15 @@ module AdventOfCode2017.Day13 -open System - let parseInput (lines : string[]) = lines |> Array.map ( fun line -> - let values = line.Split ([| ':'; ' ' |], StringSplitOptions.RemoveEmptyEntries) + let values = line.Split ([| ':'; ' ' |], System.StringSplitOptions.RemoveEmptyEntries) int values.[0], int values.[1] ) -let severity (input : (int * int)[]) : int * int = - let inline sumByF (f : int -> int -> int) delay = - input |> Array.sumBy (fun (depth, range) -> if (depth + delay) % (2 * range - 2) = 0 then f depth range else 0) +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) - sumByF (*) 0, Seq.initInfinite (fun i -> i, sumByF (+) i) |> Seq.pick (fun (i, s) -> if s = 0 then Some i else None) \ No newline at end of file + 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