From: Greg Burri Date: Sun, 3 Dec 2017 21:33:37 +0000 (+0100) Subject: Little cleaning X-Git-Url: https://git.euphorik.ch/index.cgi?a=commitdiff_plain;h=645efa775d754aa8d5a431b4911589e1e2d7d44b;p=advent_of_code_2017.git Little cleaning --- diff --git a/AdventOfCode2017/Day3.fs b/AdventOfCode2017/Day3.fs index c34aebc..df96b61 100644 --- a/AdventOfCode2017/Day3.fs +++ b/AdventOfCode2017/Day3.fs @@ -6,11 +6,11 @@ let spiral = Seq.unfold ( fun (pos, dir, n, i) -> let x, y = directions.[dir] - let pos_ = fst pos + x, snd pos + y + let pos' = fst pos + x, snd pos + y let nMax = (i + 1) * 2 - 1 - let i_, n_ = if n = nMax then i + 1, 0 else i, n + 1 - let dir_ = if i <> i_ || n_ = nMax / 2 + 1 then (dir + 1) % 4 else dir - Some (pos, (pos_, dir_, n_, i_)) + let i', n' = if n = nMax then i + 1, 0 else i, n + 1 + let dir' = if i <> i' || n' = nMax / 2 + 1 then (dir + 1) % 4 else dir + Some (pos, (pos', dir', n', i')) ) ((0, 0), 0, 0, 0) let spiralManhattanDistanceSum (n : int) = @@ -21,7 +21,7 @@ let spiralAdjacentSumBiggerThan (n : int) = let neighborsSum (dic : Map) (pos : int * int) = let x, y = pos [ x + 1, y; x + 1, y + 1; x, y + 1; x - 1, y + 1; x - 1, y; x - 1, y - 1; x, y - 1; x + 1, y - 1] - |> List.map (fun (x, y) -> match dic |> Map.tryFind (x, y) with Some v -> v | None -> 0) + |> List.map (fun (x, y) -> match dic |> Map.tryFind (x, y) with Some v -> v | None -> 0) |> List.sum spiral