From: Ummon Date: Mon, 18 Dec 2017 07:44:14 +0000 (+0100) Subject: Do not calculate the entire cycle if not necessary X-Git-Url: https://git.euphorik.ch/?a=commitdiff_plain;h=89a7dc6be51a32af69397afb4f125188e3877a71;p=advent_of_code_2017.git Do not calculate the entire cycle if not necessary --- diff --git a/AdventOfCode2017/AdventOfCode2017.fsproj b/AdventOfCode2017/AdventOfCode2017.fsproj index 57bd951..16d2ffd 100644 --- a/AdventOfCode2017/AdventOfCode2017.fsproj +++ b/AdventOfCode2017/AdventOfCode2017.fsproj @@ -25,7 +25,7 @@ AnyCPU bin\$(Configuration)\$(AssemblyName).XML true - 17 + 16 pdbonly diff --git a/AdventOfCode2017/Day16.fs b/AdventOfCode2017/Day16.fs index fbe7ee7..bc52286 100644 --- a/AdventOfCode2017/Day16.fs +++ b/AdventOfCode2017/Day16.fs @@ -34,7 +34,7 @@ let dance (size : int) (nb : int) (moves : DanceMove list) : string = for move in moves do match move with | Spin s -> - let last = danceFloor.[size - s ..] |> Array.rev + let last = danceFloor.[size - s ..] Array.Copy (danceFloor, 0, danceFloor, s, size - s) Array.Copy (last, danceFloor, s) | Exchange (p1, p2) -> @@ -50,7 +50,7 @@ let dance (size : int) (nb : int) (moves : DanceMove list) : string = applyMoves current i + 1, current ) - |> Seq.takeWhile (fun (i, state) -> i = 0 || not (state |=| initialState)) + |> Seq.takeWhile (fun (i, state) -> i = 0 || i <= nb && not (state |=| initialState)) |> Seq.map snd |> Array.ofSeq