From 89a7dc6be51a32af69397afb4f125188e3877a71 Mon Sep 17 00:00:00 2001 From: Ummon Date: Mon, 18 Dec 2017 08:44:14 +0100 Subject: [PATCH] Do not calculate the entire cycle if not necessary --- AdventOfCode2017/AdventOfCode2017.fsproj | 2 +- AdventOfCode2017/Day16.fs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 -- 2.45.2