Bones
This commit is contained in:
@@ -18,6 +18,7 @@
|
|||||||
<Compile Include="Day6.fs" />
|
<Compile Include="Day6.fs" />
|
||||||
<Compile Include="Day7.fs" />
|
<Compile Include="Day7.fs" />
|
||||||
<Compile Include="Day8.fs" />
|
<Compile Include="Day8.fs" />
|
||||||
|
<Compile Include="Day9.fs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
37
AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/Day9.fs
Normal file
37
AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/Day9.fs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
namespace AdventOfCode2023
|
||||||
|
|
||||||
|
open System
|
||||||
|
open System.Collections.Generic
|
||||||
|
|
||||||
|
[<RequireQualifiedAccess>]
|
||||||
|
module Day9 =
|
||||||
|
|
||||||
|
let parse (s : string) =
|
||||||
|
use mutable lines = StringSplitEnumerator.make '\n' s
|
||||||
|
|
||||||
|
lines.MoveNext () |> ignore
|
||||||
|
|
||||||
|
let stepsLine = lines.Current.TrimEnd ()
|
||||||
|
let steps = Array.zeroCreate stepsLine.Length
|
||||||
|
|
||||||
|
for i = 0 to stepsLine.Length - 1 do
|
||||||
|
steps.[i] <- (stepsLine.[i] = 'R')
|
||||||
|
|
||||||
|
let dict = Dictionary ()
|
||||||
|
|
||||||
|
while lines.MoveNext () do
|
||||||
|
if not lines.Current.IsEmpty then
|
||||||
|
use mutable line = StringSplitEnumerator.make' ' ' lines.Current
|
||||||
|
line.MoveNext () |> ignore
|
||||||
|
{
|
||||||
|
Steps = steps
|
||||||
|
Nodes = dict
|
||||||
|
}
|
||||||
|
|
||||||
|
let part1 (s : string) =
|
||||||
|
let data = parse s
|
||||||
|
answer
|
||||||
|
|
||||||
|
let part2 (s : string) =
|
||||||
|
let data = parse s
|
||||||
|
0
|
@@ -17,6 +17,7 @@
|
|||||||
<Compile Include="TestDay6.fs" />
|
<Compile Include="TestDay6.fs" />
|
||||||
<Compile Include="TestDay7.fs" />
|
<Compile Include="TestDay7.fs" />
|
||||||
<Compile Include="TestDay8.fs" />
|
<Compile Include="TestDay8.fs" />
|
||||||
|
<Compile Include="TestDay9.fs" />
|
||||||
<EmbeddedResource Include="samples\day1.txt" />
|
<EmbeddedResource Include="samples\day1.txt" />
|
||||||
<EmbeddedResource Include="samples\day1part1.txt" />
|
<EmbeddedResource Include="samples\day1part1.txt" />
|
||||||
<EmbeddedResource Include="samples\day2.txt" />
|
<EmbeddedResource Include="samples\day2.txt" />
|
||||||
|
49
AdventOfCode2023.FSharp/Test/TestDay9.fs
Normal file
49
AdventOfCode2023.FSharp/Test/TestDay9.fs
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
namespace AdventOfCode2023.Test
|
||||||
|
|
||||||
|
open AdventOfCode2023
|
||||||
|
open NUnit.Framework
|
||||||
|
open FsUnitTyped
|
||||||
|
open System.IO
|
||||||
|
|
||||||
|
[<TestFixture>]
|
||||||
|
module TestDay9 =
|
||||||
|
|
||||||
|
let sample = Assembly.getEmbeddedResource typeof<Dummy>.Assembly "day9.txt"
|
||||||
|
|
||||||
|
[<Test>]
|
||||||
|
let part1Sample () =
|
||||||
|
sample
|
||||||
|
|> Day9.part1
|
||||||
|
|> shouldEqual 2
|
||||||
|
|
||||||
|
[<Test>]
|
||||||
|
let part2Sample () =
|
||||||
|
Assembly.getEmbeddedResource typeof<Dummy>.Assembly "day9.txt"
|
||||||
|
|> Day9.part2
|
||||||
|
|> shouldEqual 0
|
||||||
|
|
||||||
|
[<Test>]
|
||||||
|
let part1Actual () =
|
||||||
|
let s =
|
||||||
|
try
|
||||||
|
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day9.txt"))
|
||||||
|
with
|
||||||
|
| :? DirectoryNotFoundException
|
||||||
|
| :? FileNotFoundException ->
|
||||||
|
Assert.Inconclusive ()
|
||||||
|
failwith "unreachable"
|
||||||
|
|
||||||
|
Day8.part1 s |> shouldEqual 0
|
||||||
|
|
||||||
|
[<Test>]
|
||||||
|
let part2Actual () =
|
||||||
|
let s =
|
||||||
|
try
|
||||||
|
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day9.txt"))
|
||||||
|
with
|
||||||
|
| :? DirectoryNotFoundException
|
||||||
|
| :? FileNotFoundException ->
|
||||||
|
Assert.Inconclusive ()
|
||||||
|
failwith "unreachable"
|
||||||
|
|
||||||
|
Day8.part2 s |> shouldEqual 0
|
Reference in New Issue
Block a user