<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
- <StartArguments>10</StartArguments>
+ <StartArguments>11</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Compile Include="Day8.fs" />
<Compile Include="Day9.fs" />
<Compile Include="Day10.fs" />
+ <Compile Include="Day11.fs" />
<Compile Include="Program.fs" />
<None Include="App.config" />
<None Include="Data\day1.input">
<None Include="Data\day9.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
- <None Include="Data\day10.input">
+ <None Include="Data\day11.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Content Include="packages.config" />
--- /dev/null
+module AdventOfCode2017.Day11
+
+let parseInput (input : string) : string list = input.Split ',' |> List.ofArray
+
+let distanceInHex (moves : string list) =
+ let distance (x, y) =
+ let x, y = abs x, abs y
+ if y >= x then y + (x - y) / 2 else x
+
+ let rec next (x, y) further (moves : string list) =
+ let further' = distance (x, y) |> max further
+ match moves with
+ | "n" :: xs -> next (x, y + 2) further' xs
+ | "ne" :: xs -> next (x + 1, y + 1) further' xs
+ | "se" :: xs -> next (x + 1, y - 1) further' xs
+ | "s" :: xs -> next (x, y - 2) further' xs
+ | "sw" :: xs -> next (x - 1, y - 1) further' xs
+ | "nw" :: xs -> next (x - 1, y + 1) further' xs
+ | _ -> (x, y), further'
+
+ let destination, further = next (0, 0) 0 moves
+ distance destination, further
+
+
let input = "83,0,193,1,254,237,187,40,88,27,2,255,149,29,42,100"
sprintf "part1 = %A, part2 = %A" (Day10.knotHash1 input 256) (Day10.knotHash2 input)
+let day11 () =
+ let input = File.ReadAllText "Data/day11.input" |> Day11.parseInput
+ let part1, part2 = Day11.distanceInHex input
+ sprintf "part1 = %A, part2 = %A" part1 part2
+
let doDay (n : int) =
let sw = Diagnostics.Stopwatch ()
sw.Start ()
| 8 -> day8 ()
| 9 -> day9 ()
| 10 -> day10 ()
+ | 11 -> day11 ()
| _ -> raise <| NotImplementedException ()
printfn "Result of day %i: %s (time : %i ms)" n result sw.ElapsedMilliseconds
--- /dev/null
+namespace AdventOfCode2017.Tests
+
+open Xunit
+open Xunit.Abstractions
+open Swensen.Unquote
+
+open AdventOfCode2017
+
+type ``Day11 tests`` (output : ITestOutputHelper) =
+
+ [<Fact>]
+ let ``(Part1) From web page`` () =
+ Day11.distanceInHex (Day11.parseInput "ne,ne,ne") |> fst =! 3
+ Day11.distanceInHex (Day11.parseInput "ne,ne,sw,sw") |> fst =! 0
+ Day11.distanceInHex (Day11.parseInput "ne,ne,s,s") |> fst =! 2
+ Day11.distanceInHex (Day11.parseInput "se,sw,se,sw,sw") |> fst =! 3
+
+ [<Fact>]
+ let ``(Part2) From web page`` () =
+ Day11.distanceInHex (Day11.parseInput "ne,ne,ne") |> snd =! 3
+ Day11.distanceInHex (Day11.parseInput "ne,ne,sw,sw") |> snd =! 2
+ Day11.distanceInHex (Day11.parseInput "ne,ne,s,s") |> snd =! 2
+ Day11.distanceInHex (Day11.parseInput "se,sw,se,sw,sw") |> snd =! 3
\ No newline at end of file
<Compile Include="Day8 tests.fs" />
<Compile Include="Day9 tests.fs" />
<Compile Include="Day10 tests.fs" />
+ <Compile Include="Day11 tests.fs" />
<Content Include="packages.config" />
<Content Include="App.config" />
</ItemGroup>