Compare commits

13 Commits

Author SHA1 Message Date
Smaug123
337d11e0e6 Fix
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/all-checks-complete unknown status
2023-12-03 22:19:42 +00:00
Smaug123
a401d8cf5c Info
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/all-checks-complete unknown status
2023-12-03 22:17:19 +00:00
Smaug123
61f15726a1 More minimal
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/all-checks-complete unknown status
2023-12-03 22:12:06 +00:00
Smaug123
d50618676f Minimal
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/pr/all-checks-complete unknown status
2023-12-03 22:07:12 +00:00
Smaug123
ad28718b3e Does the formatting at least work
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/all-checks-complete unknown status
2023-12-03 21:56:57 +00:00
Smaug123
8c244330b7 Format tests
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/all-checks-complete unknown status
2023-12-03 19:16:18 +00:00
Smaug123
3cd5ae8635 Format 2023-12-03 19:16:02 +00:00
Smaug123
aa2ace9bf9 Add test
Some checks failed
ci/woodpecker/push/all-checks-complete Pipeline is pending
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/pr/all-checks-complete unknown status
2023-12-03 19:15:52 +00:00
Smaug123
e64b9f7cf2 Fix
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/all-checks-complete unknown status
2023-12-03 17:50:30 +00:00
Smaug123
4efbddd9d2 And try a publish
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/all-checks-complete unknown status
2023-12-03 17:44:53 +00:00
Smaug123
56d0b0c44e Merge branch 'main' into woodpecker
Some checks failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
ci/woodpecker/pr/build Pipeline failed
ci/woodpecker/pr/all-checks-complete unknown status
2023-12-03 17:42:49 +00:00
Smaug123
331092ff44 Try this
All checks were successful
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/all-checks-complete Pipeline was successful
2023-12-03 17:42:08 +00:00
Smaug123
89958b0fa0 Woodpecker
All checks were successful
ci/woodpecker/manual/build Pipeline was successful
ci/woodpecker/manual/all-checks-complete Pipeline was successful
2023-12-03 17:25:37 +00:00
13 changed files with 121 additions and 169 deletions

View File

@@ -3,11 +3,9 @@ steps:
image: nixos/nix
commands:
- echo 'experimental-features = flakes nix-command' >> /etc/nix/nix.conf
# Lint
- "nix flake check"
# Test
- nix develop --command dotnet test
- nix develop --command dotnet test --configuration Release
- nix develop --command dotnet --info
- nix develop --command dotnet publish AdventOfCode2023.FSharp/AdventOfCode2023.FSharp/AdventOfCode2023.FSharp.fsproj --configuration Release
- nix develop --command sh -c "$(find . -type f -name AdventOfCode2023.FSharp | grep Release | grep publish) AdventOfCode2023.FSharp/Test/samples"
when:
- event: "push"

View File

@@ -1,28 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<PublishAot>true</PublishAot>
<InvariantGlobalization>true</InvariantGlobalization>
<UseSystemResourceKeys>true</UseSystemResourceKeys>
<IlcOptimizationPreference>Speed</IlcOptimizationPreference>
<IlcGenerateStackTraceData>false</IlcGenerateStackTraceData>
<DebuggerSupport>false</DebuggerSupport>
<EnableUnsafeBinaryFormatterSerialization>false</EnableUnsafeBinaryFormatterSerialization>
<EventSourceSupport>false</EventSourceSupport>
<HttpActivityPropagationSupport>false</HttpActivityPropagationSupport>
<MetadataUpdaterSupport>false</MetadataUpdaterSupport>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AdventOfCode2023.FSharp.Lib\AdventOfCode2023.FSharp.Lib.fsproj" />
</ItemGroup>
</Project>

View File

@@ -1,91 +1,7 @@
namespace AdventOfCode2023
#if DEBUG
#else
#nowarn "9"
#endif
open System
open System.Diagnostics
open System.IO
namespace AdventOfCode2023
module Program =
let inline toUs (ticks : int64) =
1_000_000.0 * float ticks / float Stopwatch.Frequency
[<EntryPoint>]
let main argv =
let endToEnd = Stopwatch.StartNew ()
endToEnd.Restart ()
let dir = DirectoryInfo argv.[0]
let sw = Stopwatch.StartNew ()
do
sw.Restart ()
let input = Path.Combine (dir.FullName, "day1.txt") |> File.ReadAllText
let part1 = Day1.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 = Day1.part2 input
sw.Stop ()
Console.WriteLine (part2.ToString ())
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
do
let input = Path.Combine (dir.FullName, "day2.txt") |> File.ReadAllText
sw.Restart ()
let part1 = Day2.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 = Day2.part2 input
sw.Stop ()
Console.WriteLine (part2.ToString ())
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
do
let input = Path.Combine (dir.FullName, "day3.txt") |> File.ReadAllBytes
sw.Restart ()
let resultArr, len, lineCount = Day3.parse input
sw.Stop ()
Console.Error.WriteLine (
(1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString ()
+ "ms parse"
)
#if DEBUG
let contents =
{
Elements = Array.take len resultArr
Width = len / lineCount
}
#else
use ptr = fixed resultArr
let contents =
{
Elements = ptr
Length = len
Width = len / lineCount
}
#endif
let part1 = Day3.part1 contents
sw.Stop ()
Console.WriteLine (part1.ToString ())
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
sw.Restart ()
let part2 = Day3.part2 contents
Console.WriteLine (part2.ToString ())
Console.Error.WriteLine ((1_000.0 * float sw.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms")
endToEnd.Stop ()
Console.Error.WriteLine ((1_000.0 * float endToEnd.ElapsedTicks / float Stopwatch.Frequency).ToString () + "ms total")
0

View File

@@ -8,9 +8,14 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Util.fs" />
<Compile Include="TestDay1.fs" />
<Compile Include="TestDay2.fs" />
<Compile Include="TestDay3.fs" />
<EmbeddedResource Include="samples\day1.txt" />
<EmbeddedResource Include="samples\day1part1.txt" />
<EmbeddedResource Include="samples\day2.txt" />
<EmbeddedResource Include="samples\day3.txt" />
</ItemGroup>
<ItemGroup>

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"

View 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 ()

View File

@@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

View File

@@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet

View 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

View File

@@ -0,0 +1,10 @@
467..114..
...*......
..35..633.
......#...
617*......
.....+.58.
..592.....
......755.
...$.*....
.664.598..

View File

@@ -1,26 +1,45 @@
{
description = "Advent of Code 2023";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
description = "Advent of Code 2023";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = {
self,
nixpkgs,
flake-utils,
}: flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
devShells = { default = pkgs.mkShell {
buildInputs = with pkgs; [
(with dotnetCorePackages;
combinePackages [
dotnet-sdk_8
dotnetPackages.Nuget
])
] ++ [pkgs.swift darwin.apple_sdk.frameworks.Foundation darwin.apple_sdk.frameworks.CryptoKit darwin.apple_sdk.frameworks.GSS pkgs.zlib pkgs.zlib.dev pkgs.openssl pkgs.icu];
};};
}
outputs = {
self,
nixpkgs,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = nixpkgs.legacyPackages.${system};
in
# Conditionally include Swift and Apple SDK for Darwin systems
let
darwinDeps =
if system == "x86_64-darwin" || system == "aarch64-darwin"
then [
pkgs.swift
pkgs.darwin.apple_sdk.frameworks.Foundation
pkgs.darwin.apple_sdk.frameworks.CryptoKit
pkgs.darwin.apple_sdk.frameworks.GSS
]
else [];
in {
devShells = {
default = pkgs.mkShell {
buildInputs = with pkgs;
[
(with dotnetCorePackages;
combinePackages [
dotnet-sdk_8
dotnetPackages.Nuget
])
]
++ darwinDeps
++ [pkgs.zlib pkgs.zlib.dev pkgs.openssl pkgs.icu pkgs.alejandra];
};
};
}
);
}