mirror of
https://github.com/Smaug123/AdventOfCode2022
synced 2025-10-05 17:48:40 +00:00
Day 25 (#41)
This commit is contained in:
@@ -34,6 +34,7 @@
|
||||
<EmbeddedResource Include="..\AdventOfCode2022.Test\Inputs\Day22.txt" />
|
||||
<EmbeddedResource Include="..\AdventOfCode2022.Test\Inputs\Day23.txt" />
|
||||
<EmbeddedResource Include="..\AdventOfCode2022.Test\Inputs\Day24.txt" />
|
||||
<EmbeddedResource Include="..\AdventOfCode2022.Test\Inputs\Day25.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@@ -2,5 +2,5 @@ namespace AdventOfCode2022.App
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Inputs =
|
||||
let days = Array.init 24 (fun day -> Assembly.readResource $"Day%i{day + 1}.txt")
|
||||
let days = Array.init 25 (fun day -> Assembly.readResource $"Day%i{day + 1}.txt")
|
||||
let inline day (i : int) = days.[i - 1]
|
||||
|
@@ -5,92 +5,95 @@ open BenchmarkDotNet.Attributes
|
||||
open BenchmarkDotNet.Configs
|
||||
open BenchmarkDotNet.Running
|
||||
|
||||
type Benchmark1To5 () =
|
||||
[<GlobalSetup>]
|
||||
member _.Setup () = Run.shouldWrite <- false
|
||||
module Benchmarks =
|
||||
type Benchmark1To5 () =
|
||||
[<GlobalSetup>]
|
||||
member _.Setup () = Run.shouldWrite <- false
|
||||
|
||||
[<Params(1, 2, 3, 4, 5)>]
|
||||
member val Day = 0 with get, set
|
||||
[<Params(1, 2, 3, 4, 5)>]
|
||||
member val Day = 0 with get, set
|
||||
|
||||
[<Params(false, true)>]
|
||||
member val IsPartOne = false 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)
|
||||
[<Benchmark>]
|
||||
member this.Benchmark () : unit =
|
||||
Run.allRuns.[this.Day - 1] (not this.IsPartOne) (Inputs.day this.Day)
|
||||
|
||||
[<GlobalCleanup>]
|
||||
member _.Cleanup () = Run.shouldWrite <- true
|
||||
[<GlobalCleanup>]
|
||||
member _.Cleanup () = Run.shouldWrite <- true
|
||||
|
||||
|
||||
type Benchmark6To10 () =
|
||||
[<GlobalSetup>]
|
||||
member _.Setup () = Run.shouldWrite <- false
|
||||
type Benchmark6To10 () =
|
||||
[<GlobalSetup>]
|
||||
member _.Setup () = Run.shouldWrite <- false
|
||||
|
||||
[<Params(6, 7, 8, 9, 10)>]
|
||||
member val Day = 0 with get, set
|
||||
[<Params(6, 7, 8, 9, 10)>]
|
||||
member val Day = 0 with get, set
|
||||
|
||||
[<Params(false, true)>]
|
||||
member val IsPartOne = false 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)
|
||||
[<Benchmark>]
|
||||
member this.Benchmark () : unit =
|
||||
Run.allRuns.[this.Day - 1] (not this.IsPartOne) (Inputs.day this.Day)
|
||||
|
||||
[<GlobalCleanup>]
|
||||
member _.Cleanup () = Run.shouldWrite <- true
|
||||
[<GlobalCleanup>]
|
||||
member _.Cleanup () = Run.shouldWrite <- true
|
||||
|
||||
type Benchmark11To15 () =
|
||||
[<GlobalSetup>]
|
||||
member _.Setup () = Run.shouldWrite <- false
|
||||
type Benchmark11To15 () =
|
||||
[<GlobalSetup>]
|
||||
member _.Setup () = Run.shouldWrite <- false
|
||||
|
||||
[<Params(11, 12, 13, 14, 15)>]
|
||||
member val Day = 0 with get, set
|
||||
[<Params(11, 12, 13, 14, 15)>]
|
||||
member val Day = 0 with get, set
|
||||
|
||||
[<Params(false, true)>]
|
||||
member val IsPartOne = false 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)
|
||||
[<Benchmark>]
|
||||
member this.Benchmark () : unit =
|
||||
Run.allRuns.[this.Day - 1] (not this.IsPartOne) (Inputs.day this.Day)
|
||||
|
||||
[<GlobalCleanup>]
|
||||
member _.Cleanup () = Run.shouldWrite <- true
|
||||
[<GlobalCleanup>]
|
||||
member _.Cleanup () = Run.shouldWrite <- true
|
||||
|
||||
type Benchmark16To20 () =
|
||||
[<GlobalSetup>]
|
||||
member _.Setup () = Run.shouldWrite <- false
|
||||
type Benchmark16To20 () =
|
||||
[<GlobalSetup>]
|
||||
member _.Setup () = Run.shouldWrite <- false
|
||||
|
||||
[<Params(16, 17, 18, 19, 20)>]
|
||||
member val Day = 0 with get, set
|
||||
[<Params(16, 17, 18, 19, 20)>]
|
||||
member val Day = 0 with get, set
|
||||
|
||||
[<Params(false, true)>]
|
||||
member val IsPartOne = false 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)
|
||||
[<Benchmark>]
|
||||
member this.Benchmark () : unit =
|
||||
Run.allRuns.[this.Day - 1] (not this.IsPartOne) (Inputs.day this.Day)
|
||||
|
||||
[<GlobalCleanup>]
|
||||
member _.Cleanup () = Run.shouldWrite <- true
|
||||
[<GlobalCleanup>]
|
||||
member _.Cleanup () = Run.shouldWrite <- true
|
||||
|
||||
let finalBenchmarkArgs = (25, false) :: List.allPairs [ 21..24 ] [ false ; true ]
|
||||
|
||||
type Benchmark21To25 () =
|
||||
[<GlobalSetup>]
|
||||
member _.Setup () = Run.shouldWrite <- false
|
||||
type Benchmark21To25 () =
|
||||
[<GlobalSetup>]
|
||||
member _.Setup () = Run.shouldWrite <- false
|
||||
|
||||
[<Params(21, 22, 23, 24)>]
|
||||
member val Day = 0 with get, set
|
||||
[<Params(21, 22, 23, 24)>]
|
||||
member val Day = 0 with get, set
|
||||
|
||||
[<Params(false, true)>]
|
||||
member val IsPartOne = false 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)
|
||||
[<Benchmark>]
|
||||
[<ArgumentsSource(nameof (finalBenchmarkArgs))>]
|
||||
member this.Benchmark () : unit =
|
||||
Run.allRuns.[this.Day - 1] (not this.IsPartOne) (Inputs.day this.Day)
|
||||
|
||||
[<GlobalCleanup>]
|
||||
member _.Cleanup () = Run.shouldWrite <- true
|
||||
[<GlobalCleanup>]
|
||||
member _.Cleanup () = Run.shouldWrite <- true
|
||||
|
||||
module Program =
|
||||
|
||||
@@ -103,11 +106,11 @@ module Program =
|
||||
.Create(DefaultConfig.Instance)
|
||||
.WithOptions ConfigOptions.DisableOptimizationsValidator
|
||||
|
||||
let _summary = BenchmarkRunner.Run<Benchmark1To5> config
|
||||
let _summary = BenchmarkRunner.Run<Benchmark6To10> config
|
||||
let _summary = BenchmarkRunner.Run<Benchmark11To15> config
|
||||
let _summary = BenchmarkRunner.Run<Benchmark16To20> config
|
||||
let _summary = BenchmarkRunner.Run<Benchmark21To25> config
|
||||
let _summary = BenchmarkRunner.Run<Benchmarks.Benchmark1To5> config
|
||||
let _summary = BenchmarkRunner.Run<Benchmarks.Benchmark6To10> config
|
||||
let _summary = BenchmarkRunner.Run<Benchmarks.Benchmark11To15> config
|
||||
let _summary = BenchmarkRunner.Run<Benchmarks.Benchmark16To20> config
|
||||
let _summary = BenchmarkRunner.Run<Benchmarks.Benchmark21To25> config
|
||||
0
|
||||
| _ ->
|
||||
|
||||
@@ -118,6 +121,8 @@ module Program =
|
||||
Run.allRuns.[day - 1] false (Inputs.day day)
|
||||
Run.allRuns.[day - 1] true (Inputs.day day)
|
||||
|
||||
Run.day25 (Inputs.day 25)
|
||||
|
||||
time.Stop ()
|
||||
printfn $"Took %i{time.ElapsedMilliseconds}ms"
|
||||
0
|
||||
|
@@ -346,6 +346,14 @@ module Run =
|
||||
if shouldWrite then
|
||||
printfn "%i" output
|
||||
|
||||
let day25 (input : string) =
|
||||
let day25 = StringSplitEnumerator.make '\n' input
|
||||
|
||||
let output = Day25.part1 day25
|
||||
|
||||
if shouldWrite then
|
||||
printfn "%s" output
|
||||
|
||||
let allRuns =
|
||||
[|
|
||||
day1
|
||||
|
Reference in New Issue
Block a user