From 73a017862ad87065ade3a84e125f512a998b1267 Mon Sep 17 00:00:00 2001 From: Smaug123 Date: Mon, 11 Dec 2023 22:39:56 +0000 Subject: [PATCH] Bones --- .../AdventOfCode2023.FSharp.Lib.fsproj | 1 + .../AdventOfCode2023.FSharp.Lib/Day12.fs | 14 ++++++ .../AdventOfCode2023.FSharp/Program.fs | 19 ++++++++ AdventOfCode2023.FSharp/Test/Test.fsproj | 2 + AdventOfCode2023.FSharp/Test/TestDay12.fs | 47 +++++++++++++++++++ .../Test/samples/day12.txt | 0 6 files changed, 83 insertions(+) create mode 100644 AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/Day12.fs create mode 100644 AdventOfCode2023.FSharp/Test/TestDay12.fs create mode 100644 AdventOfCode2023.FSharp/Test/samples/day12.txt diff --git a/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/AdventOfCode2023.FSharp.Lib.fsproj b/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/AdventOfCode2023.FSharp.Lib.fsproj index 7c5ca68..faa1752 100644 --- a/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/AdventOfCode2023.FSharp.Lib.fsproj +++ b/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/AdventOfCode2023.FSharp.Lib.fsproj @@ -22,6 +22,7 @@ + diff --git a/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/Day12.fs b/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/Day12.fs new file mode 100644 index 0000000..88ffe27 --- /dev/null +++ b/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.Lib/Day12.fs @@ -0,0 +1,14 @@ +namespace AdventOfCode2023 + +[] +module Day12 = + + let part1 (s : string) = + use mutable lines = StringSplitEnumerator.make '\n' s + + -1 + + let part2 (s : string) = + use mutable lines = StringSplitEnumerator.make '\n' s + + -1 diff --git a/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/Program.fs b/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/Program.fs index 9f2d599..9e656f8 100644 --- a/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/Program.fs +++ b/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/Program.fs @@ -232,6 +232,25 @@ module Program = Console.WriteLine (part2.ToString ()) Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms") + Console.WriteLine "=====Day 12=====" + + do + let input = Path.Combine (dir.FullName, "day12.txt") |> File.ReadAllText + + sw.Restart () + let part1 = Day12.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 = Day12.part2 input + sw.Stop () + Console.WriteLine (part2.ToString ()) + Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms") + + Console.WriteLine "=====Day 11=====" + + endToEnd.Stop () Console.Error.WriteLine ( diff --git a/AdventOfCode2023.FSharp/Test/Test.fsproj b/AdventOfCode2023.FSharp/Test/Test.fsproj index 9fe6516..5af2d07 100644 --- a/AdventOfCode2023.FSharp/Test/Test.fsproj +++ b/AdventOfCode2023.FSharp/Test/Test.fsproj @@ -20,6 +20,7 @@ + @@ -34,6 +35,7 @@ + diff --git a/AdventOfCode2023.FSharp/Test/TestDay12.fs b/AdventOfCode2023.FSharp/Test/TestDay12.fs new file mode 100644 index 0000000..75d84fb --- /dev/null +++ b/AdventOfCode2023.FSharp/Test/TestDay12.fs @@ -0,0 +1,47 @@ +namespace AdventOfCode2023.Test + +open AdventOfCode2023 +open NUnit.Framework +open FsUnitTyped +open System.IO + +[] +module TestDay12 = + + let sample = Assembly.getEmbeddedResource typeof.Assembly "day12.txt" + + [] + let part1Sample () = + sample |> Day12.part1 |> shouldEqual 0 + + [] + let part2Sample () = + sample + |> Day12.part2 + |> shouldEqual 0 + + [] + let part1Actual () = + let s = + try + File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day12.txt")) + with + | :? DirectoryNotFoundException + | :? FileNotFoundException -> + Assert.Inconclusive () + failwith "unreachable" + + Day12.part1 s |> shouldEqual 0 + + [] + let part2Actual () = + let s = + try + File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day12.txt")) + with + | :? DirectoryNotFoundException + | :? FileNotFoundException -> + Assert.Inconclusive () + failwith "unreachable" + + Day12.part2 s |> shouldEqual 0 diff --git a/AdventOfCode2023.FSharp/Test/samples/day12.txt b/AdventOfCode2023.FSharp/Test/samples/day12.txt new file mode 100644 index 0000000..e69de29