<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
- <StartArguments>18</StartArguments>
+ <StartArguments>19</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
- <StartArguments>16</StartArguments>
+ <StartArguments>19</StartArguments>
</PropertyGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
<Compile Include="Day17.fs" />
<Compile Include="Day18Part1.fs" />
<Compile Include="Day18Part2.fs" />
+ <Compile Include="Day19.fs" />
<Compile Include="Program.fs" />
<None Include="App.config" />
<Content Include="Data\day01.input">
<Content Include="Data\day18.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
+ <Content Include="Data\day19.input">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
--- /dev/null
+module AdventOfCode2017.Day19
+
+open System
+
+let followThePath (lines : string[]) : string * int =
+ let rec next (i, j) (di, dj) (str : string) (n : int) =
+ let i', j' = i + di, j + dj
+ let c = lines.[i'].[j']
+ if c = '+' then
+ let pos =
+ [ '-', 0, 1; '|', -1, 0; '-', 0, -1; '|', 1, 0 ]
+ |> List.pick (
+ fun (c', ndi, ndj) ->
+ let ni, nj = i' + ndi, j' + ndj
+ if (ni, nj) <> (i, j) && (Char.IsLetter lines.[ni].[nj] || lines.[ni].[nj] = c') then Some (ndi, ndj) else None
+ )
+ next (i', j') pos str (n + 1)
+ elif Char.IsWhiteSpace c |> not then
+ next (i', j') (di, dj) (if Char.IsLetter c then str + string c else str) (n + 1)
+ else
+ str, n
+ next (0, lines.[0].IndexOf '|') (1, 0) "" 1
let input = File.ReadAllLines "Data/day18.input"
sprintf "part1 = %A, part2 = %A" (Day18Part1.run (Day18Part1.parseInput input)) (Day18Part2.run (Day18Part2.parseInput input))
+let day19 () =
+ let input = File.ReadAllLines "Data/day19.input"
+ let word, length = Day19.followThePath input
+ sprintf "part1 = %A, part2 = %A" word length
+
let doDay (n : int) =
let sw = Diagnostics.Stopwatch ()
sw.Start ()
| 16 -> day16 ()
| 17 -> day17 ()
| 18 -> day18 ()
+ | 19 -> day19 ()
| _ -> 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 ``Day19 tests`` (output : ITestOutputHelper) =
+
+ [<Fact>]
+ let ``(Part1) From web page`` () =
+ let input =
+ [|
+ " | "
+ " | +--+ "
+ " A | C "
+ " F---|----E|--+ "
+ " | | | D "
+ " +B-+ +--+ "
+ " "
+ |]
+
+ Day19.followThePath input |> fst =! "ABCDEF"
+
+ [<Fact>]
+ let ``(Part2) From web page`` () =
+ let input =
+ [|
+ " | "
+ " | +--+ "
+ " A | C "
+ " F---|----E|--+ "
+ " | | | D "
+ " +B-+ +--+ "
+ " "
+ |]
+
+ Day19.followThePath input |> snd =! 38
\ No newline at end of file
<Compile Include="Day16 tests.fs" />
<Compile Include="Day17 tests.fs" />
<Compile Include="Day18 tests.fs" />
- <Content Include="packages.config" />
+ <Compile Include="Day19 tests.fs" />
<Content Include="App.config" />
+ <Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="FSharp.Core">