Scaffolding
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
<Compile Include="Day5.fs" />
|
||||
<Compile Include="Day6.fs" />
|
||||
<Compile Include="Day7.fs" />
|
||||
<Compile Include="Day8.fs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
30
AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/Day8.fs
Normal file
30
AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/Day8.fs
Normal file
@@ -0,0 +1,30 @@
|
||||
namespace AdventOfCode2023
|
||||
|
||||
open System
|
||||
open System.Globalization
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Day8 =
|
||||
|
||||
let parse (s : string) : ResizeArray<int> =
|
||||
use mutable lines = StringSplitEnumerator.make '\n' s
|
||||
let result = ResizeArray ()
|
||||
|
||||
while lines.MoveNext () do
|
||||
if not lines.Current.IsEmpty then
|
||||
use mutable line = StringSplitEnumerator.make' ' ' lines.Current
|
||||
line.MoveNext () |> ignore
|
||||
result.Add (3)
|
||||
|
||||
result
|
||||
|
||||
let part1 (s : string) =
|
||||
let arr = parse s
|
||||
let mutable answer = 0
|
||||
answer
|
||||
|
||||
let part2 (s : string) =
|
||||
let arr = parse s
|
||||
let mutable answer = 0
|
||||
|
||||
answer
|
@@ -158,6 +158,21 @@ module Program =
|
||||
Console.WriteLine (part2.ToString ())
|
||||
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
|
||||
|
||||
Console.WriteLine "=====Day 8====="
|
||||
|
||||
do
|
||||
let input = Path.Combine (dir.FullName, "day8.txt") |> File.ReadAllText
|
||||
sw.Restart ()
|
||||
let part1 = Day8.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 = Day8.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 (
|
||||
|
@@ -16,6 +16,7 @@
|
||||
<Compile Include="TestDay5.fs" />
|
||||
<Compile Include="TestDay6.fs" />
|
||||
<Compile Include="TestDay7.fs" />
|
||||
<Compile Include="TestDay8.fs" />
|
||||
<EmbeddedResource Include="samples\day1.txt" />
|
||||
<EmbeddedResource Include="samples\day1part1.txt" />
|
||||
<EmbeddedResource Include="samples\day2.txt" />
|
||||
@@ -24,6 +25,7 @@
|
||||
<EmbeddedResource Include="samples\day5.txt" />
|
||||
<EmbeddedResource Include="samples\day6.txt" />
|
||||
<EmbeddedResource Include="samples\day7.txt" />
|
||||
<Content Include="samples\day8.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
46
AdventOfCode2023.FSharp/Test/TestDay8.fs
Normal file
46
AdventOfCode2023.FSharp/Test/TestDay8.fs
Normal file
@@ -0,0 +1,46 @@
|
||||
namespace AdventOfCode2023.Test
|
||||
|
||||
open System
|
||||
open AdventOfCode2023
|
||||
open NUnit.Framework
|
||||
open FsUnitTyped
|
||||
open System.IO
|
||||
|
||||
[<TestFixture>]
|
||||
module TestDay8 =
|
||||
|
||||
let sample = Assembly.getEmbeddedResource typeof<Dummy>.Assembly "day8.txt"
|
||||
|
||||
[<Test>]
|
||||
let part1Sample () =
|
||||
sample |> Day8.part1 |> shouldEqual 0
|
||||
|
||||
[<Test>]
|
||||
let part2Sample () =
|
||||
sample |> Day8.part2 |> shouldEqual 0
|
||||
|
||||
[<Test>]
|
||||
let part1Actual () =
|
||||
let s =
|
||||
try
|
||||
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day8.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/day8.txt"))
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
Day8.part2 s |> shouldEqual 0
|
0
AdventOfCode2023.FSharp/Test/samples/day8.txt
Normal file
0
AdventOfCode2023.FSharp/Test/samples/day8.txt
Normal file
Reference in New Issue
Block a user