Bones
This commit is contained in:
@@ -14,6 +14,6 @@ module Inputs =
|
||||
if isNull dir then
|
||||
failwith "reached root of filesystem without finding inputs dir"
|
||||
|
||||
Array.init 15 (fun day -> Path.Combine (dir.FullName, "inputs", $"day%i{day + 1}.txt") |> File.ReadAllText)
|
||||
Array.init 16 (fun day -> Path.Combine (dir.FullName, "inputs", $"day%i{day + 1}.txt") |> File.ReadAllText)
|
||||
|
||||
let inline day (i : int) = days.[i - 1]
|
||||
|
@@ -57,6 +57,23 @@ module Benchmarks =
|
||||
[<GlobalCleanup>]
|
||||
member _.Cleanup () = Run.shouldWrite <- true
|
||||
|
||||
type Benchmark16To20 () =
|
||||
[<GlobalSetup>]
|
||||
member _.Setup () = Run.shouldWrite <- false
|
||||
|
||||
[<Params(16)>]
|
||||
member val Day = 0 with get, set
|
||||
|
||||
[<Params(false, true)>]
|
||||
member val IsPartOne = false with get, set
|
||||
|
||||
[<Benchmark>]
|
||||
member this.Benchmark () : unit =
|
||||
Run.allRuns.[this.Day - 1] (not this.IsPartOne) (Inputs.day this.Day)
|
||||
|
||||
[<GlobalCleanup>]
|
||||
member _.Cleanup () = Run.shouldWrite <- true
|
||||
|
||||
module Program =
|
||||
|
||||
[<EntryPoint>]
|
||||
|
@@ -209,6 +209,18 @@ module Run =
|
||||
if shouldWrite then
|
||||
Console.WriteLine output
|
||||
|
||||
let day16 (partTwo : bool) (input : string) =
|
||||
if not partTwo then
|
||||
let output = Day16.part1 input
|
||||
|
||||
if shouldWrite then
|
||||
Console.WriteLine output
|
||||
else
|
||||
let output = Day16.part2 input
|
||||
|
||||
if shouldWrite then
|
||||
Console.WriteLine output
|
||||
|
||||
let allRuns =
|
||||
[|
|
||||
day1
|
||||
@@ -226,4 +238,5 @@ module Run =
|
||||
day13
|
||||
day14
|
||||
day15
|
||||
day16
|
||||
|]
|
||||
|
@@ -26,6 +26,7 @@
|
||||
<Compile Include="Day13.fs" />
|
||||
<Compile Include="Day14.fs" />
|
||||
<Compile Include="Day15.fs" />
|
||||
<Compile Include="Day16.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
15
AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/Day16.fs
Normal file
15
AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/Day16.fs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace AdventOfCode2023
|
||||
|
||||
open System
|
||||
open System.Globalization
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Day16 =
|
||||
|
||||
let part1 (s : string) =
|
||||
use lines = StringSplitEnumerator.make '\n' s
|
||||
answer
|
||||
|
||||
let part2 (s : string) =
|
||||
use lines = StringSplitEnumerator.make '\n' s
|
||||
answer
|
@@ -300,6 +300,22 @@ module Program =
|
||||
Console.WriteLine (part2.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
|
||||
Console.WriteLine "=====Day 16====="
|
||||
|
||||
do
|
||||
let input = Path.Combine (dir.FullName, "day16.txt") |> File.ReadAllText
|
||||
|
||||
sw.Restart ()
|
||||
let part1 = Day16.part1 input
|
||||
sw.Stop ()
|
||||
Console.WriteLine (part1.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
sw.Restart ()
|
||||
let part2 = Day16.part2 input
|
||||
sw.Stop ()
|
||||
Console.WriteLine (part2.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
|
||||
endToEnd.Stop ()
|
||||
|
||||
Console.Error.WriteLine (
|
||||
|
@@ -24,6 +24,7 @@
|
||||
<Compile Include="TestDay13.fs" />
|
||||
<Compile Include="TestDay14.fs" />
|
||||
<Compile Include="TestDay15.fs" />
|
||||
<Compile Include="TestDay16.fs" />
|
||||
<EmbeddedResource Include="samples\day1.txt"/>
|
||||
<EmbeddedResource Include="samples\day1part1.txt"/>
|
||||
<EmbeddedResource Include="samples\day2.txt"/>
|
||||
@@ -42,6 +43,7 @@
|
||||
<EmbeddedResource Include="samples\day13.txt" />
|
||||
<EmbeddedResource Include="samples\day14.txt" />
|
||||
<EmbeddedResource Include="samples\day15.txt" />
|
||||
<EmbeddedResource Include="samples\day16.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
46
AdventOfCode2023.FSharp/Test/TestDay16.fs
Normal file
46
AdventOfCode2023.FSharp/Test/TestDay16.fs
Normal file
@@ -0,0 +1,46 @@
|
||||
namespace AdventOfCode2023.Test
|
||||
|
||||
open AdventOfCode2023
|
||||
open NUnit.Framework
|
||||
open FsUnitTyped
|
||||
open System.IO
|
||||
|
||||
[<TestFixture>]
|
||||
module TestDay16 =
|
||||
|
||||
[<Test>]
|
||||
let sample = Assembly.getEmbeddedResource typeof<Dummy>.Assembly "day16.txt"
|
||||
|
||||
[<Test>]
|
||||
let part1Sample () =
|
||||
sample |> Day16.part1 |> shouldEqual 1320
|
||||
|
||||
[<Test>]
|
||||
let part2Sample () =
|
||||
sample |> Day16.part2 |> shouldEqual 145ul
|
||||
|
||||
[<Test>]
|
||||
let part1Actual () =
|
||||
let s =
|
||||
try
|
||||
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day16.txt"))
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
Day16.part1 s |> shouldEqual 521434
|
||||
|
||||
[<Test>]
|
||||
let part2Actual () =
|
||||
let s =
|
||||
try
|
||||
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day16.txt"))
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
Day16.part2 s |> shouldEqual 248279ul
|
0
AdventOfCode2023.FSharp/Test/samples/day16.txt
Normal file
0
AdventOfCode2023.FSharp/Test/samples/day16.txt
Normal file
Reference in New Issue
Block a user