@@ -8,9 +8,16 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="Util.fs" />
|
||||
<Compile Include="TestDay1.fs" />
|
||||
<Compile Include="TestDay2.fs" />
|
||||
<Compile Include="TestDay3.fs" />
|
||||
<Compile Include="TestDay4.fs" />
|
||||
<EmbeddedResource Include="samples\day1.txt" />
|
||||
<EmbeddedResource Include="samples\day1part1.txt" />
|
||||
<EmbeddedResource Include="samples\day2.txt" />
|
||||
<EmbeddedResource Include="samples\day3.txt" />
|
||||
<EmbeddedResource Include="samples\day4.txt" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@@ -8,26 +8,13 @@ open System.IO
|
||||
[<TestFixture>]
|
||||
module TestDay1 =
|
||||
|
||||
let sample1 =
|
||||
"""1abc2
|
||||
pqr3stu8vwx
|
||||
a1b2c3d4e5f
|
||||
treb7uchet
|
||||
"""
|
||||
let sample1 = Assembly.getEmbeddedResource typeof<Dummy>.Assembly "day1part1.txt"
|
||||
|
||||
[<Test>]
|
||||
let part1Sample () =
|
||||
sample1 |> Day1.part1 |> shouldEqual 142
|
||||
|
||||
let sample2 =
|
||||
"""two1nine
|
||||
eightwothree
|
||||
abcone2threexyz
|
||||
xtwone3four
|
||||
4nineeightseven2
|
||||
zoneight234
|
||||
7pqrstsixteen
|
||||
"""
|
||||
let sample2 = Assembly.getEmbeddedResource typeof<Dummy>.Assembly "day1.txt"
|
||||
|
||||
[<Test>]
|
||||
let part2Sample () =
|
||||
@@ -38,7 +25,9 @@ zoneight234
|
||||
let s =
|
||||
try
|
||||
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day1.txt"))
|
||||
with :? FileNotFoundException ->
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
@@ -49,7 +38,9 @@ zoneight234
|
||||
let s =
|
||||
try
|
||||
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day1.txt"))
|
||||
with :? FileNotFoundException ->
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
|
@@ -8,13 +8,7 @@ open System.IO
|
||||
[<TestFixture>]
|
||||
module TestDay2 =
|
||||
|
||||
let sample =
|
||||
"""Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
||||
"""
|
||||
let sample = Assembly.getEmbeddedResource typeof<Dummy>.Assembly "day2.txt"
|
||||
|
||||
[<Test>]
|
||||
let part1Sample () = sample |> Day2.part1 |> shouldEqual 8
|
||||
@@ -28,7 +22,9 @@ Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
||||
let s =
|
||||
try
|
||||
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day2.txt"))
|
||||
with :? FileNotFoundException ->
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
@@ -39,7 +35,9 @@ Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
||||
let s =
|
||||
try
|
||||
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day2.txt"))
|
||||
with :? FileNotFoundException ->
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
|
@@ -13,18 +13,7 @@ open System.IO
|
||||
[<TestFixture>]
|
||||
module TestDay3 =
|
||||
|
||||
let sample =
|
||||
"""467..114..
|
||||
...*......
|
||||
..35..633.
|
||||
......#...
|
||||
617*......
|
||||
.....+.58.
|
||||
..592.....
|
||||
......755.
|
||||
...$.*....
|
||||
.664.598..
|
||||
"""
|
||||
let sample = Assembly.getEmbeddedResource typeof<Dummy>.Assembly "day3.txt"
|
||||
|
||||
[<Test>]
|
||||
let part1Sample () =
|
||||
@@ -77,7 +66,9 @@ module TestDay3 =
|
||||
let bytes =
|
||||
try
|
||||
File.ReadAllBytes (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day3.txt"))
|
||||
with :? FileNotFoundException ->
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
@@ -107,7 +98,9 @@ module TestDay3 =
|
||||
let bytes =
|
||||
try
|
||||
File.ReadAllBytes (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day3.txt"))
|
||||
with :? FileNotFoundException ->
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
|
43
AdventOfCode2023.FSharp/Test/TestDay4.fs
Normal file
43
AdventOfCode2023.FSharp/Test/TestDay4.fs
Normal file
@@ -0,0 +1,43 @@
|
||||
namespace AdventOfCode2023.Test
|
||||
|
||||
open AdventOfCode2023
|
||||
open NUnit.Framework
|
||||
open FsUnitTyped
|
||||
open System.IO
|
||||
|
||||
[<TestFixture>]
|
||||
module TestDay4 =
|
||||
|
||||
let sample = Assembly.getEmbeddedResource typeof<Dummy>.Assembly "day4.txt"
|
||||
|
||||
[<Test>]
|
||||
let part1Sample () = sample |> Day4.part1 |> shouldEqual 13
|
||||
|
||||
[<Test>]
|
||||
let part2Sample () = sample |> Day4.part2 |> shouldEqual 30
|
||||
|
||||
[<Test>]
|
||||
let part1Actual () =
|
||||
let s =
|
||||
try
|
||||
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day4.txt"))
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
Day4.part1 s |> shouldEqual 27454
|
||||
|
||||
[<Test>]
|
||||
let part2Actual () =
|
||||
let s =
|
||||
try
|
||||
File.ReadAllText (Path.Combine (__SOURCE_DIRECTORY__, "../../inputs/day4.txt"))
|
||||
with
|
||||
| :? DirectoryNotFoundException
|
||||
| :? FileNotFoundException ->
|
||||
Assert.Inconclusive ()
|
||||
failwith "unreachable"
|
||||
|
||||
Day4.part2 s |> shouldEqual 6857330
|
22
AdventOfCode2023.FSharp/Test/Util.fs
Normal file
22
AdventOfCode2023.FSharp/Test/Util.fs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace AdventOfCode2023.Test
|
||||
|
||||
open System.IO
|
||||
open System.Reflection
|
||||
|
||||
type Dummy =
|
||||
class
|
||||
end
|
||||
|
||||
[<RequireQualifiedAccess>]
|
||||
module Assembly =
|
||||
let getEmbeddedResource (assembly : Assembly) (name : string) : string =
|
||||
let names = assembly.GetManifestResourceNames ()
|
||||
let names = names |> Seq.filter (fun s -> s.EndsWith name)
|
||||
|
||||
use s =
|
||||
names
|
||||
|> Seq.exactlyOne
|
||||
|> assembly.GetManifestResourceStream
|
||||
|> fun s -> new StreamReader (s)
|
||||
|
||||
s.ReadToEnd ()
|
7
AdventOfCode2023.FSharp/Test/samples/day1.txt
Normal file
7
AdventOfCode2023.FSharp/Test/samples/day1.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
two1nine
|
||||
eightwothree
|
||||
abcone2threexyz
|
||||
xtwone3four
|
||||
4nineeightseven2
|
||||
zoneight234
|
||||
7pqrstsixteen
|
4
AdventOfCode2023.FSharp/Test/samples/day1part1.txt
Normal file
4
AdventOfCode2023.FSharp/Test/samples/day1part1.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
1abc2
|
||||
pqr3stu8vwx
|
||||
a1b2c3d4e5f
|
||||
treb7uchet
|
5
AdventOfCode2023.FSharp/Test/samples/day2.txt
Normal file
5
AdventOfCode2023.FSharp/Test/samples/day2.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green
|
||||
Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue
|
||||
Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red
|
||||
Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red
|
||||
Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green
|
10
AdventOfCode2023.FSharp/Test/samples/day3.txt
Normal file
10
AdventOfCode2023.FSharp/Test/samples/day3.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
467..114..
|
||||
...*......
|
||||
..35..633.
|
||||
......#...
|
||||
617*......
|
||||
.....+.58.
|
||||
..592.....
|
||||
......755.
|
||||
...$.*....
|
||||
.664.598..
|
6
AdventOfCode2023.FSharp/Test/samples/day4.txt
Normal file
6
AdventOfCode2023.FSharp/Test/samples/day4.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
|
||||
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
|
||||
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
|
||||
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
|
||||
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
|
||||
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11
|
Reference in New Issue
Block a user