<TargetFramework>netcoreapp2.1</TargetFramework>\r
</PropertyGroup>\r
<ItemGroup>\r
+ <Compile Include="Day07.fs" />\r
<Compile Include="Day06.fs" />\r
<Compile Include="Day05.fs" />\r
<Compile Include="Day04.fs" />\r
<Compile Include="Day02.fs" />\r
<Compile Include="Day01.fs" />\r
<Compile Include="Program.fs" />\r
+ <Content Include="Data/day07.input">\r
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>\r
+ </Content>\r
<Content Include="Data/day06.input">\r
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>\r
</Content>\r
--- /dev/null
+module AdventOfCode2018.Day07\r
+\r
+open System\r
+\r
+type Constraint = char * char\r
+\r
+let parseInput (str : string) : Constraint array =\r
+ str.Split ([| '\r'; '\n'; |], StringSplitOptions.RemoveEmptyEntries)\r
+ |> Array.map (\r
+ fun line ->\r
+ let trimmedLine = line.Trim ()\r
+ trimmedLine.[5], trimmedLine.[36]\r
+ )\r
+\r
+let order (constraints : Constraint array) : char array =\r
+ let constraints = constraints |> Array.sortBy fst\r
+\r
+ let rec loop (constraints : Constraint array) : char list =\r
+ match constraints with\r
+ | [| (a, b) |] -> [ a; b ]\r
+ | _ ->\r
+ let next = constraints |> Array.pick (fun (a, _) -> if constraints |> Array.forall (fun (_, b) -> a <> b) then Some a else None)\r
+ let rest = constraints |> Array.filter (fst >> ((<>) next))\r
+ next :: (loop rest)\r
+\r
+ loop constraints |> Array.ofList
\ No newline at end of file
let coords = File.ReadAllText "Data/day06.input" |> Day06.parseInput\r
sprintf "part1 = %A, part2 = %A" (Day06.getLargestArea coords) (Day06.getAreaWithTotalDistanceLessThan 10000 coords)\r
\r
+let day07 () =\r
+ let constraints = File.ReadAllText "Data/day07.input" |> Day07.parseInput\r
+ sprintf "part1 = %A, part2 =" (Day07.order constraints |> String.Concat)\r
+\r
let days : Map<int, unit -> string> =\r
[\r
1, day01\r
4, day04\r
5, day05\r
6, day06\r
+ 7, day07\r
] |> Map.ofList\r
\r
let doDay (n : int) =\r
--- /dev/null
+namespace AdventOfCode2018.Tests\r
+\r
+open System\r
+\r
+open Xunit\r
+open Xunit.Abstractions\r
+open Swensen.Unquote\r
+\r
+open AdventOfCode2018\r
+\r
+type ``Day07 tests`` (output : ITestOutputHelper) =\r
+ let input =\r
+ """Step C must be finished before step A can begin.\r
+ Step C must be finished before step F can begin.\r
+ Step A must be finished before step B can begin.\r
+ Step A must be finished before step D can begin.\r
+ Step B must be finished before step E can begin.\r
+ Step D must be finished before step E can begin.\r
+ Step F must be finished before step E can begin."""\r
+\r
+ [<Fact>]\r
+ let ``(Part1) From web page`` () =\r
+ let constrains = Day07.parseInput input\r
+ Day07.order constrains |> String.Concat =! "CABDFE"\r
+\r
+ [<Fact>]\r
+ let ``(Part2) From web page`` () =\r
+ ()\r
+\r
<ProjectReference Include="..\AdventOfCode2018.fsproj" />\r
</ItemGroup>\r
<ItemGroup>\r
+ <Compile Include="Day07 tests.fs" />\r
<Compile Include="Day06 tests.fs" />\r
<Compile Include="Day05 tests.fs" />\r
<Compile Include="Day04 tests.fs" />\r