<PlatformTarget>AnyCPU</PlatformTarget>
<DocumentationFile>bin\$(Configuration)\$(AssemblyName).XML</DocumentationFile>
<Prefer32Bit>true</Prefer32Bit>
- <StartArguments>8</StartArguments>
+ <StartArguments>9</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Compile Include="Day6.fs" />
<Compile Include="Day7.fs" />
<Compile Include="Day8.fs" />
+ <Compile Include="Day9.fs" />
<Compile Include="Program.fs" />
<None Include="App.config" />
<None Include="Data\day1.input">
<None Include="Data\day8.input">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
+ <None Include="Data\day9.input">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
<Content Include="packages.config" />
</ItemGroup>
<ItemGroup>
--- /dev/null
+module AdventOfCode2017.Day9
+
+let score (input : string) =
+ let rec next (l : int) (lSum : int) (gb : bool) (gbSize : int) =
+ function
+ | '{' :: tail when not gb -> next (l + 1) (lSum + l) gb gbSize tail
+ | '}' :: tail when not gb -> next (l - 1) lSum gb gbSize tail
+ | '<' :: tail when not gb -> next l lSum true gbSize tail
+ | '!' :: _ :: tail when gb -> next l lSum gb gbSize tail
+ | '>' :: tail when gb -> next l lSum false gbSize tail
+ | a :: tail -> next l lSum gb (gbSize + if gb then 1 else 0) tail
+ | [] -> lSum, gbSize
+ List.ofSeq input |> next 1 0 false 0
\ No newline at end of file
let part1, part2 = Day8.execute input
sprintf "part1 = %A, part2 = %A" part1 part2
+let day9 () =
+ let input = File.ReadAllText "Data/day9.input"
+ let part1, part2 = Day9.score input
+ sprintf "part1 = %A, part2 = %A" part1 part2
+
let doDay (n : int) =
let sw = Diagnostics.Stopwatch ()
sw.Start ()
| 6 -> day6 ()
| 7 -> day7 ()
| 8 -> day8 ()
+ | 9 -> day9 ()
| _ -> 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 ``Day9 tests`` (output : ITestOutputHelper) =
+
+ [<Fact>]
+ let ``(Part1) From web page`` () =
+ Day9.score "{}" |> fst =! 1
+ Day9.score "{{{}}}" |> fst =! 6
+ Day9.score "{{},{}}" |> fst =! 5
+ Day9.score "{{{},{},{{}}}}" |> fst =! 16
+ Day9.score "{<a>,<a>,<a>,<a>}" |> fst =! 1
+ Day9.score "{{<ab>},{<ab>},{<ab>},{<ab>}}" |> fst =! 9
+ Day9.score "{{<!!>},{<!!>},{<!!>},{<!!>}}" |> fst =! 9
+ Day9.score "{{<a!>},{<a!>},{<a!>},{<ab>}}" |> fst =! 3
+
+ [<Fact>]
+ let ``(Part2) From web page`` () =
+ Day9.score "<>" |> snd =! 0
+ Day9.score "<random characters>" |> snd =! 17
+ Day9.score "<<<<>" |> snd =! 3
+ Day9.score "<{!>}>" |> snd =! 2
+ Day9.score "<!!>" |> snd =! 0
+ Day9.score "<!!!>>" |> snd =! 0
+ Day9.score """<{o"i!a,<{i<a>""" |> snd =! 10
\ No newline at end of file
<Compile Include="Day6 tests.fs" />
<Compile Include="Day7 tests.fs" />
<Compile Include="Day8 tests.fs" />
+ <Compile Include="Day9 tests.fs" />
<Content Include="packages.config" />
<Content Include="App.config" />
</ItemGroup>