Skip to content

Commit a5b2558

Browse files
committed
Stub out day 17 in C#
1 parent c1a5980 commit a5b2558

File tree

8 files changed

+130
-0
lines changed

8 files changed

+130
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ My solutions to the [Advent of Code 2024](https://adventofcode.com/2024), writte
2222
- [x] [**Day 14**](day14): [Haskell](day14/src/Day14.hs)
2323
- [x] [**Day 15**](day15): [C++](day15/src/day15.cpp)
2424
- [x] [**Day 16**](day16): [Kotlin](day16/src/day16.kts)
25+
- [ ] [**Day 17**](day17): [C#](day17/src/day17.cs)
2526

2627
## Development
2728

day17/derivation.nix

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{ stdenv, dotnet-runtime, dotnet-sdk }:
2+
stdenv.mkDerivation {
3+
name = "advent-of-code-2024-day17";
4+
src = ./src;
5+
6+
nativeBuildInputs = [
7+
dotnet-sdk
8+
];
9+
10+
buildInputs = [
11+
dotnet-runtime
12+
];
13+
14+
# https://stackoverflow.com/questions/46065777/is-it-possible-to-compile-a-single-c-sharp-code-file-with-the-net-core-roslyn-c
15+
16+
buildPhase = ''
17+
sdk="$(echo "${dotnet-sdk.outPath}"/sdk/*)"
18+
shared="$(echo "${dotnet-runtime.outPath}"/shared/Microsoft.NETCore.App/*)"
19+
dotnet "$sdk/Roslyn/bincore/csc.dll" \
20+
-r:"$shared/System.Private.CoreLib.dll" \
21+
-r:"$shared/System.Runtime.dll" \
22+
-r:"$shared/System.Collections.dll" \
23+
-r:"$shared/System.Console.dll" \
24+
-r:"$shared/System.IO.dll" \
25+
-r:"$shared/System.Linq.dll" \
26+
day17.cs
27+
'';
28+
29+
installPhase = ''
30+
mkdir -p $out/{bin,lib}
31+
cp day17.exe $out/lib
32+
33+
cat <<EOF > $out/lib/day17.runtimeconfig.json
34+
{
35+
"runtimeOptions": {
36+
"framework": {
37+
"name": "Microsoft.NETCore.App",
38+
"version": "$(ls ${dotnet-runtime.outPath}/shared/Microsoft.NETCore.App)"
39+
}
40+
}
41+
}
42+
EOF
43+
44+
cat <<EOF > $out/bin/day17
45+
#!/bin/bash
46+
exec "${dotnet-runtime.outPath}/bin/dotnet" "\$(dirname "\$0")/../lib/day17.exe" "\$@"
47+
EOF
48+
49+
chmod +x $out/bin/day17
50+
'';
51+
}

day17/flake.lock

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

day17/flake.nix

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
description = "Advent of Code 2024 - Day 17 solution";
3+
4+
inputs = {
5+
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
6+
};
7+
8+
outputs = { self, nixpkgs }:
9+
let
10+
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
11+
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
12+
in {
13+
packages = forAllSystems (system:
14+
let
15+
pkgs = import nixpkgs { inherit system; };
16+
in {
17+
default = pkgs.callPackage ./derivation.nix {};
18+
}
19+
);
20+
21+
apps = forAllSystems (system: {
22+
default = {
23+
type = "app";
24+
program = "${self.packages.${system}.default}/bin/day17";
25+
};
26+
});
27+
};
28+
}

day17/resources/demo.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123

day17/resources/input.txt

Whitespace-only changes.

day17/src/day17.cs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.IO;
3+
4+
if (args.Length == 0)
5+
{
6+
Console.WriteLine("usage: day17 <path to input>");
7+
return 1;
8+
}
9+
10+
string input = File.ReadAllText(args[0]);
11+
// TODO
12+
13+
Console.WriteLine($"Input: {input}");
14+
15+
return 0;

paths.json

+7
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,12 @@
126126
},
127127
"path": "day16/src/day16.kts",
128128
"completed": true
129+
},
130+
{
131+
"lang": {
132+
"codemirror": "csharp",
133+
"name": "C#"
134+
},
135+
"path": "day17/src/day17.cs"
129136
}
130137
]

0 commit comments

Comments
 (0)