<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
- <StartArguments>16</StartArguments>
+ <StartArguments>17</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Compile Include="Day14Compact.fs" />
<Compile Include="Day15.fs" />
<Compile Include="Day16.fs" />
+ <Compile Include="Day17.fs" />
<Compile Include="Program.fs" />
<None Include="App.config" />
<Content Include="Data\day01.input">
<Content Include="Data\day16.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <Content Include="Data\day17.input">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
--- /dev/null
+module AdventOfCode2017.Day17
+
+open System.Collections.Generic
+
+let spinLock1 (moves : int) =
+ let buffer = List [ 0 ]
+ let mutable pos = 0
+ for i = 1 to 2017 do
+ pos <- (pos + moves) % buffer.Count + 1
+ buffer.Insert (pos, i)
+ buffer.[(pos + 1) % buffer.Count]
+
+let spinLock2 (moves : int) =
+ let mutable valueAt1 = 0
+ let mutable pos = 0
+ for i = 1 to 50_000_000 do
+ pos <- (pos + moves) % i + 1
+ if pos = 1 then valueAt1 <- i
+ valueAt1
\ No newline at end of file
let input = File.ReadAllText "Data/day16.input" |> Day16.parseInput
sprintf "part1 = %A, part2 = %A" (Day16.dance 16 1 input) (Day16.dance 16 1_000_000_000 input)
+let day17 () =
+ let input = File.ReadAllText "Data/day17.input" |> int
+ sprintf "part1 = %A, part2 = %A" (Day17.spinLock1 input) (Day17.spinLock2 input)
+
let doDay (n : int) =
let sw = Diagnostics.Stopwatch ()
sw.Start ()
| 2 -> day02 ()
| 3 -> day03 ()
| 4 -> day04 ()
- | 5 -> day05 ()
+ | 5 -> day05 ()
| 6 -> day06 ()
| 7 -> day07 ()
| 8 -> day08 ()
| 14 -> day14 ()
| 15 -> day15 ()
| 16 -> day16 ()
+ | 17 -> day17 ()
| _ -> raise <| NotImplementedException ()
printfn "Result of day %i: %s (time : %i ms)" n result sw.ElapsedMilliseconds
--- /dev/null
+namespace AdventOfCode2017.Tests
+
+open System
+open Xunit
+open Xunit.Abstractions
+open Swensen.Unquote
+
+open AdventOfCode2017
+
+type ``Day17 tests`` (output : ITestOutputHelper) =
+
+ [<Fact>]
+ let ``(Part1) From web page`` () =
+ Day17.spinLock1 3 =! 638
+
+ [<Fact>]
+ let ``(Part2) From web page`` () =
+ Day17.spinLock2 3 =! 1222153
\ No newline at end of file
<Compile Include="Day14 tests.fs" />
<Compile Include="Day15 tests.fs" />
<Compile Include="Day16 tests.fs" />
+ <Compile Include="Day17 tests.fs" />
<Content Include="packages.config" />
<Content Include="App.config" />
</ItemGroup>