<TargetFramework>netcoreapp2.1</TargetFramework>\r
</PropertyGroup>\r
<ItemGroup>\r
+ <Compile Include="Day04.fs" />\r
<Compile Include="Day03.fs" />\r
<Compile Include="Day02.fs" />\r
<Compile Include="Day01.fs" />\r
<Compile Include="Program.fs" />\r
+ <Content Include="Data/day04.input">\r
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>\r
+ </Content>\r
<Content Include="Data/day03.input">\r
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>\r
</Content>\r
--- /dev/null
+module AdventOfCode2018.Day04\r
+\r
+open System\r
+\r
+let parseInput (str : string) : string =\r
+ let shifts : int list array = Array.create 60 []\r
+\r
+ let addShift (id : int) (date1 : DateTime) (date2 : DateTime) =\r
+\r
+ let min1 = if date1.Hour > 0 then 0 else date1.Minute\r
+ let min2 = if date2.Hour > 0 then 59 else date2.Minute\r
+\r
+ for m = min1 to min2 - 1 do\r
+ shifts.[m] <- id :: shifts.[m]\r
+\r
+ let lines =\r
+ str.Split ([| '\r'; '\n'; |], StringSplitOptions.RemoveEmptyEntries)\r
+ |> Array.choose (\r
+ fun line ->\r
+ let trimmed = line.Trim ()\r
+ if trimmed = "" then None else Some (DateTime.Parse (trimmed.Substring (1, 16)), trimmed)\r
+ )\r
+ |> Array.sortBy fst\r
+ (*\r
+ |> Array.fold (\r
+ fun id (dateTime, line) ->\r
+ match line.IndexOf '#' with\r
+ | i when i <> -1 -> line.Substring (i + 1, line.IndexOf (' ', i) - i - 1) |> int\r
+ | _ ->\r
+ ) 0*)\r
+\r
+ let mutable id = 0\r
+\r
+ for i = 0 to lines.Length - 1 do\r
+ let dateTime, line = lines.[i]\r
+ match line.IndexOf '#' with\r
+ | i when i <> -1 -> id <- line.Substring (i + 1, line.IndexOf (' ', i) - i - 1) |> int\r
+ | _ ->\r
+ if line.Contains "wakes up" then\r
+ addShift id (fst lines.[i-1]) dateTime\r
+\r
+ sprintf "%A" shifts\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+ //Map<int, int>.\r
+\r
+\r
+ //
\ No newline at end of file
let surface, claimId = Day03.overlappingSurface claims\r
sprintf "part1 = %A, part2 = %A" surface claimId\r
\r
+let day04 () =\r
+ // sprintf "part1 = %A, part2 = %A" surface claimId\r
+ ""\r
+\r
let days : Map<int, unit -> string> =\r
[\r
1, day01\r
2, day02\r
3, day03\r
+ 4, day04\r
] |> Map.ofList\r
\r
let doDay (n : int) =\r
else\r
for day in days do\r
doDay day.Key\r
-\r
- Console.Read () |> ignore\r
0\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 ``Day04 tests`` (output : ITestOutputHelper) =\r
+\r
+ [<Fact>]\r
+ let ``(Part1) From web page`` () =\r
+ let input =\r
+ """\r
+ [1518-11-01 00:00] Guard #10 begins shift\r
+ [1518-11-01 00:05] falls asleep\r
+ [1518-11-01 00:25] wakes up\r
+ [1518-11-01 00:30] falls asleep\r
+ [1518-11-01 00:55] wakes up\r
+ [1518-11-01 23:58] Guard #99 begins shift\r
+ [1518-11-02 00:40] falls asleep\r
+ [1518-11-02 00:50] wakes up\r
+ [1518-11-03 00:05] Guard #10 begins shift\r
+ [1518-11-03 00:24] falls asleep\r
+ [1518-11-03 00:29] wakes up\r
+ [1518-11-04 00:02] Guard #99 begins shift\r
+ [1518-11-04 00:36] falls asleep\r
+ [1518-11-04 00:46] wakes up\r
+ [1518-11-05 00:03] Guard #99 begins shift\r
+ [1518-11-05 00:45] falls asleep\r
+ [1518-11-05 00:55] wakes up\r
+ """\r
+\r
+ output.WriteLine (Day04.parseInput input)\r
+\r
+ 1 =! 2\r
+ ()\r
+\r
+ [<Fact>]\r
+ let ``(Part2) From web page`` () =\r
+ ()\r
+\r
<ProjectReference Include="..\AdventOfCode2018.fsproj" />\r
</ItemGroup>\r
<ItemGroup>\r
+ <Compile Include="Day04 tests.fs" />\r
<Compile Include="Day03 tests.fs" />\r
<Compile Include="Day02 tests.fs" />\r
<Compile Include="Day01 tests.fs" />\r