From e46af8399d5a122a3ccb8ef784f6f8a8b7b46277 Mon Sep 17 00:00:00 2001 From: Ummon Date: Thu, 14 Dec 2017 10:15:45 +0100 Subject: [PATCH] Cleaning --- AdventOfCode2017/Day14.fs | 41 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/AdventOfCode2017/Day14.fs b/AdventOfCode2017/Day14.fs index 809472f..0bf32b2 100644 --- a/AdventOfCode2017/Day14.fs +++ b/AdventOfCode2017/Day14.fs @@ -1,27 +1,26 @@ -module AdventOfCode2017.Day14 + module AdventOfCode2017.Day14 -let hash = Day10.knotHash2Encoding (fun i -> System.Convert.ToString(i, 2).PadLeft(8, '0')) + let hash = Day10.knotHash2Encoding (fun i -> System.Convert.ToString(i, 2).PadLeft(8, '0')) -let buildMatrix (input : string) : bool[,] = - let mat = Array2D.zeroCreate 128 128 - for i = 0 to 127 do - input + "-" + (string i) |> hash |> Seq.iteri (fun j c -> if c = '1' then mat.[i, j] <- true) - mat + let buildMatrix (input : string) : bool[,] = + let mat = Array2D.zeroCreate 128 128 + for i = 0 to 127 do + input + "-" + (string i) |> hash |> Seq.iteri (fun j c -> if c = '1' then mat.[i, j] <- true) + mat -let nbOfUsedSquares (input : string) = - let mutable i = 0 - buildMatrix input |> Array2D.iter (fun b -> if b then i <- i + 1) - i + let nbOfUsedSquares (input : string) = + let mutable i = 0 + buildMatrix input |> Array2D.iter (fun b -> if b then i <- i + 1) + i -let nbOfConnectedRegions (input : string) = - let m = buildMatrix input + let nbOfConnectedRegions (input : string) = + let m = buildMatrix input - let rec remove i j = - if i >= 0 && i < 128 && j >= 0 && j < 128 && m.[i, j] then - m.[i, j] <- false - (remove (i + 1) j, remove (i - 1) j, remove i (j + 1), remove i (j - 1)) |> ignore - 1 - else - 0 + let rec remove i j = + if i >= 0 && i < 128 && j >= 0 && j < 128 && m.[i, j] then + m.[i, j] <- false + 1 + remove (i + 1) j * remove (i - 1) j * remove i (j + 1) * remove i (j - 1) + else + 0 - seq { for i in 0 .. 127 do for j in 0 .. 127 -> remove i j } |> Seq.sum \ No newline at end of file + seq { for i in 0 .. 127 do for j in 0 .. 127 -> remove i j } |> Seq.sum \ No newline at end of file -- 2.45.2