From: Ummon Date: Mon, 11 Dec 2017 08:35:31 +0000 (+0100) Subject: Use coordinates system from https://www.redblobgames.com/grids/hexagons/ X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=b50b34035b885157b3268816eaad0eaf95411c78;p=advent_of_code_2017.git Use coordinates system from https://redblobgames.com/grids/hexagons/ --- diff --git a/AdventOfCode2017/Day11.fs b/AdventOfCode2017/Day11.fs index 400e0eb..df2a86e 100644 --- a/AdventOfCode2017/Day11.fs +++ b/AdventOfCode2017/Day11.fs @@ -1,21 +1,19 @@ module AdventOfCode2017.Day11 let distanceInHex (moves : string) = - let distance (x, y) = - let x, y = abs x, abs y - if y >= x then y + (x - y) / 2 else x + let distance (x, y, z) = (abs x + abs y + abs z) / 2 let destination, furthest = moves.Split ',' |> Seq.fold ( - fun ((x, y), furthest) m -> + fun ((x, y, z), furthest) m -> let next = match m with - | "n" -> (x , y + 2) - | "ne" -> (x + 1, y + 1) - | "se" -> (x + 1, y - 1) - | "s" -> (x , y - 2) - | "sw" -> (x - 1, y - 1) - | _ -> (x - 1, y + 1) + | "n" -> (x , y + 1, z - 1) + | "ne" -> (x + 1, y , z - 1) + | "se" -> (x + 1, y - 1, z ) + | "s" -> (x , y - 1, z + 1) + | "sw" -> (x - 1, y , z + 1) + | _ -> (x - 1, y + 1, z ) next, distance next |> max furthest - ) ((0, 0), 0) + ) ((0, 0, 0), 0) distance destination, furthest \ No newline at end of file