Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
-VisualStudioVersion = 15.0.27004.2010
+VisualStudioVersion = 15.0.27130.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "AdventOfCode2017", "AdventOfCode2017\AdventOfCode2017.fsproj", "{D3555943-8102-43D1-B3CB-570A4E4EC513}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Tests", "Tests\Tests.fsproj", "{238BFFBE-E2D4-4DC4-804C-6E43205E4701}"
EndProject
Global
+ GlobalSection(Performance) = preSolution
+ HasPerformanceSessions = true
+ EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {1DAC18E9-E52B-45B9-AB96-686277B1EB81}
EndGlobalSection
+ GlobalSection(Performance) = preSolution
+ HasPerformanceSessions = true
+ EndGlobalSection
EndGlobal
module AdventOfCode2017.Day6
open System
+open System.Linq
type Blocks = int[]
let parseInput (str : string) : int[] =
str.Split ([| '\r'; '\t'; ' ' |], StringSplitOptions.RemoveEmptyEntries) |> Array.map int
+// Custom equality: more efficient than '='.
+let inline (|=|) (a1 : 'a[]) (a2 : 'a[]) : bool =
+ if a1.Length <> a2.Length then
+ false
+ else
+ let rec result i =
+ if i = a1.Length then
+ true
+ elif a1.[i] <> a2.[i] then
+ false
+ else
+ result (i + 1)
+ result 0
+
let nbRedistribution (blocks : Blocks) =
let rec next (previous : Blocks list) =
let blocks = List.head previous |> Array.copy
let i' = offset % blocks.Length
blocks.[i'] <- blocks.[i'] + 1
- match previous |> List.tryFindIndex ((=) blocks) with
+ match previous |> List.tryFindIndex ((|=|) blocks) with
| Some i -> previous, i + 1
| None -> next (blocks :: previous)
sprintf "part1 = %A, part2 = %A" part1 part2
let doDay (n : int) =
+ let sw = Diagnostics.Stopwatch ()
+ sw.Start ()
let result =
match n with
| 1 -> day1 ()
| 5 -> day5 ()
| 6 -> day6 ()
| _ -> raise <| NotImplementedException ()
- printfn "Result of day %i: %s" n result
+ printfn "Result of day %i: %s (time : %i ms)" n result sw.ElapsedMilliseconds
[<EntryPoint>]
let main argv =