Day 15 #17

Merged
patrick merged 4 commits from day15 into main 2023-12-15 12:43:28 +00:00
9 changed files with 93 additions and 2 deletions
Showing only changes of commit 012bbdd46d - Show all commits

View File

@@ -14,6 +14,6 @@ module Inputs =
if isNull dir then
failwith "reached root of filesystem without finding inputs dir"
Array.init 14 (fun day -> Path.Combine (dir.FullName, "inputs", $"day%i{day + 1}.txt") |> File.ReadAllText)
Array.init 15 (fun day -> Path.Combine (dir.FullName, "inputs", $"day%i{day + 1}.txt") |> File.ReadAllText)
let inline day (i : int) = days.[i - 1]

View File

@@ -44,7 +44,7 @@ module Benchmarks =
[<GlobalSetup>]
member _.Setup () = Run.shouldWrite <- false
[<Params(11, 12, 13, 14)>]
[<Params(11, 12, 13, 14, 15)>]
member val Day = 0 with get, set
[<Params(false, true)>]

View File

@@ -197,6 +197,18 @@ module Run =
if shouldWrite then
Console.WriteLine output
let day15 (partTwo : bool) (input : string) =
if not partTwo then
let output = Day15.part1 input
if shouldWrite then
Console.WriteLine output
else
let output = Day15.part2 input
if shouldWrite then
Console.WriteLine output
let allRuns =
[|
day1
@@ -213,4 +225,5 @@ module Run =
day12
day13
day14
day15
|]

View File

@@ -25,6 +25,7 @@
<Compile Include="Day12.fs" />
<Compile Include="Day13.fs" />
<Compile Include="Day14.fs" />
<Compile Include="Day15.fs" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,11 @@
namespace AdventOfCode2023
open System
[<RequireQualifiedAccess>]
module Day15 =
let part1 (s : string) =
0
let part2 (s : string) =
0

View File

@@ -284,6 +284,22 @@ module Program =
Console.WriteLine (part2.ToString ())
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
Console.WriteLine "=====Day 15====="
do
let input = Path.Combine (dir.FullName, "day15.txt") |> File.ReadAllText
sw.Restart ()
let part1 = Day15.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 = Day15.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 (

View File

@@ -23,6 +23,7 @@
<Compile Include="TestDay12.fs" />
<Compile Include="TestDay13.fs" />
<Compile Include="TestDay14.fs" />
<Compile Include="TestDay15.fs" />
<EmbeddedResource Include="samples\day1.txt"/>
<EmbeddedResource Include="samples\day1part1.txt"/>
<EmbeddedResource Include="samples\day2.txt"/>
@@ -40,6 +41,7 @@
<EmbeddedResource Include="samples\day12.txt" />
<EmbeddedResource Include="samples\day13.txt" />
<EmbeddedResource Include="samples\day14.txt" />
<EmbeddedResource Include="samples\day15.txt" />
</ItemGroup>
<ItemGroup>

View File

@@ -0,0 +1,48 @@
namespace AdventOfCode2023.Test
open System
open AdventOfCode2023
open NUnit.Framework
open FsUnitTyped
open System.IO
[<TestFixture>]
module TestDay15 =
[<Test>]
let sample = Assembly.getEmbeddedResource typeof<Dummy>.Assembly "day15.txt"
[<Test>]
let part1Sample () =
sample |> Day15.part1 |> shouldEqual -1
[<Test>]
let part2Sample () =
sample |> Day15.part2 |> shouldEqual -1
[<Test>]
let part1Actual () =
let s =
try
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day15.txt"))
with
| :? DirectoryNotFoundException
| :? FileNotFoundException ->
Assert.Inconclusive ()
failwith "unreachable"
Day15.part1 s |> shouldEqual -1
[<Test>]
let part2Actual () =
let s =
try
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day15.txt"))
with
| :? DirectoryNotFoundException
| :? FileNotFoundException ->
Assert.Inconclusive ()
failwith "unreachable"
Day15.part2 s |> shouldEqual -1