Skip to content

Commit b16f04b

Browse files
committed
migrated 2016 c# to framework
1 parent 1843b98 commit b16f04b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1569
-1436
lines changed

Diff for: .config/dotnet-tools.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"version": 1,
3+
"isRoot": true,
4+
"tools": {
5+
"jetbrains.resharper.globaltools": {
6+
"version": "2024.3.3",
7+
"commands": ["jb"],
8+
"rollForward": false
9+
}
10+
}
11+
}

Diff for: .editorconfig

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ root = true
22

33
[*]
44
charset = utf-8
5-
end_of_line = lf
5+
end_of_line = lf
6+
indent_style = space
7+
indent_size = 2
8+
insert_final_newline = false
9+
trim_trailing_whitespace = true

Diff for: .lintstagedrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"*.cs": ["dotnet jb cleanupcode"],
23
"*.json": ["prettier --write"],
34
"*.py": ["python -m black"],
45
"*.ts": ["prettier --write"]

Diff for: 2016/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Formatting
2+
3+
```
4+
dotnet tool install JetBrains.ReSharper.GlobalTools
5+
```

Diff for: 2016/Util/Aoc/Aoc.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ namespace Util.Aoc;
22

33
public class Aoc
44
{
5-
public static readonly string RootDirectory = Path.Combine(
6-
Path.GetDirectoryName(AppContext.BaseDirectory) ?? string.Empty,
7-
"../../../../../"
8-
);
5+
public static readonly string RootDirectory = Path.Combine(
6+
Path.GetDirectoryName(AppContext.BaseDirectory) ?? string.Empty,
7+
"../../../../../"
8+
);
99
}

Diff for: 2016/Util/Aoc/Printer.cs

+18-18
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,41 @@ namespace Util.Aoc;
33
internal class Printer
44
{
55
private static string BuildString<TResult>(
6-
string type,
7-
string label,
8-
string part,
9-
TResult result,
10-
double durationInMs
6+
string type,
7+
string label,
8+
string part,
9+
TResult result,
10+
double durationInMs
1111
)
1212
{
13-
return $"{type} {label,-10} {part} {result,-45} {durationInMs:F4}ms";
13+
return $"{type} {label,-10} {part} {result,-45} {durationInMs:F4}ms";
1414
}
1515

1616
public static void ExamplePart1<TResult>(TResult result, string testFileName, double durationInMs)
1717
{
18-
Console.ForegroundColor = ConsoleColor.Yellow;
19-
Console.WriteLine(BuildString("[EXM]", $"({testFileName})", "Part 1:", result, durationInMs));
20-
Console.ResetColor();
18+
Console.ForegroundColor = ConsoleColor.Yellow;
19+
Console.WriteLine(BuildString("[EXM]", $"({testFileName})", "Part 1:", result, durationInMs));
20+
Console.ResetColor();
2121
}
2222

2323
public static void ExamplePart2<TResult>(TResult result, string testFileName, double durationInMs)
2424
{
25-
Console.ForegroundColor = ConsoleColor.Red;
26-
Console.WriteLine(BuildString("[EXM]", $"({testFileName})", "Part 2:", result, durationInMs));
27-
Console.ResetColor();
25+
Console.ForegroundColor = ConsoleColor.Red;
26+
Console.WriteLine(BuildString("[EXM]", $"({testFileName})", "Part 2:", result, durationInMs));
27+
Console.ResetColor();
2828
}
2929

3030
public static void SolutionPart1<TResult>(TResult result, double durationInMs)
3131
{
32-
Console.ForegroundColor = ConsoleColor.Green;
33-
Console.WriteLine(BuildString("[SLN]", string.Empty, "Part 1:", result, durationInMs));
34-
Console.ResetColor();
32+
Console.ForegroundColor = ConsoleColor.Green;
33+
Console.WriteLine(BuildString("[SLN]", string.Empty, "Part 1:", result, durationInMs));
34+
Console.ResetColor();
3535
}
3636

3737
public static void SolutionPart2<TResult>(TResult result, double durationInMs)
3838
{
39-
Console.ForegroundColor = ConsoleColor.Blue;
40-
Console.WriteLine(BuildString("[SLN]", string.Empty, "Part 2:", result, durationInMs));
41-
Console.ResetColor();
39+
Console.ForegroundColor = ConsoleColor.Blue;
40+
Console.WriteLine(BuildString("[SLN]", string.Empty, "Part 2:", result, durationInMs));
41+
Console.ResetColor();
4242
}
4343
}

Diff for: 2016/Util/Aoc/Solver.cs

+61-60
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,61 @@
1-
using System.Diagnostics;
2-
3-
namespace Util.Aoc;
4-
5-
public class Solver
6-
{
7-
public delegate TInput Reader<TInput>(string file);
8-
9-
public delegate TResult Part1<TInput, TResult>(TInput data);
10-
11-
public delegate TResult Part2<TInput, TResult>(TInput data);
12-
13-
public static void RunExamples<TInput, TPart1Result, TPart2Result>(
14-
int year,
15-
string day,
16-
Reader<TInput> reader,
17-
Part1<TInput, TPart1Result> part1,
18-
Part2<TInput, TPart2Result> part2
19-
) {
20-
string dirPath = Path.Combine(Aoc.RootDirectory, $"{year}/d{day}/test-runs");
21-
22-
if (Directory.Exists(dirPath))
23-
{
24-
var testFiles = Directory.GetFiles(dirPath);
25-
26-
foreach (var file in testFiles)
27-
{
28-
TInput testData = reader(file);
29-
30-
var stopwatch = Stopwatch.StartNew();
31-
TPart1Result valuePart1 = part1(testData);
32-
stopwatch.Stop();
33-
Printer.ExamplePart1(valuePart1, Path.GetFileName(file), stopwatch.Elapsed.TotalMilliseconds);
34-
35-
stopwatch.Restart();
36-
TPart2Result valuePart2 = part2(testData);
37-
stopwatch.Stop();
38-
Printer.ExamplePart2(valuePart2, Path.GetFileName(file), stopwatch.Elapsed.TotalMilliseconds);
39-
}
40-
}
41-
}
42-
43-
public static void RunSolution<TInput, TPart1Result, TPart2Result>(
44-
int year, string day, Reader<TInput> reader, Part1<TInput, TPart1Result> part1, Part2<TInput, TPart2Result> part2
45-
)
46-
{
47-
string filePath = Path.Combine(Aoc.RootDirectory, $"{year}/d{day}/input.txt");
48-
TInput data = reader(filePath);
49-
50-
var stopwatch = Stopwatch.StartNew();
51-
TPart1Result valuePart1 = part1(data);
52-
stopwatch.Stop();
53-
Printer.SolutionPart1(valuePart1, stopwatch.Elapsed.TotalMilliseconds);
54-
55-
stopwatch.Restart();
56-
TPart2Result valuePart2 = part2(data);
57-
stopwatch.Stop();
58-
Printer.SolutionPart2(valuePart2, stopwatch.Elapsed.TotalMilliseconds);
59-
}
60-
}
1+
using System.Diagnostics;
2+
3+
namespace Util.Aoc;
4+
5+
public class Solver
6+
{
7+
public delegate TInput Reader<TInput>(string file);
8+
9+
public delegate TResult Part1<TInput, TResult>(TInput data);
10+
11+
public delegate TResult Part2<TInput, TResult>(TInput data);
12+
13+
public static void RunExamples<TInput, TPart1Result, TPart2Result>(
14+
int year,
15+
string day,
16+
Reader<TInput> reader,
17+
Part1<TInput, TPart1Result> part1,
18+
Part2<TInput, TPart2Result> part2
19+
)
20+
{
21+
string dirPath = Path.Combine(Aoc.RootDirectory, $"{year}/d{day}/test-runs");
22+
23+
if (Directory.Exists(dirPath))
24+
{
25+
var testFiles = Directory.GetFiles(dirPath);
26+
27+
foreach (var file in testFiles)
28+
{
29+
TInput testData = reader(file);
30+
31+
var stopwatch = Stopwatch.StartNew();
32+
TPart1Result valuePart1 = part1(testData);
33+
stopwatch.Stop();
34+
Printer.ExamplePart1(valuePart1, Path.GetFileName(file), stopwatch.Elapsed.TotalMilliseconds);
35+
36+
stopwatch.Restart();
37+
TPart2Result valuePart2 = part2(testData);
38+
stopwatch.Stop();
39+
Printer.ExamplePart2(valuePart2, Path.GetFileName(file), stopwatch.Elapsed.TotalMilliseconds);
40+
}
41+
}
42+
}
43+
44+
public static void RunSolution<TInput, TPart1Result, TPart2Result>(
45+
int year, string day, Reader<TInput> reader, Part1<TInput, TPart1Result> part1, Part2<TInput, TPart2Result> part2
46+
)
47+
{
48+
string filePath = Path.Combine(Aoc.RootDirectory, $"{year}/d{day}/input.txt");
49+
TInput data = reader(filePath);
50+
51+
var stopwatch = Stopwatch.StartNew();
52+
TPart1Result valuePart1 = part1(data);
53+
stopwatch.Stop();
54+
Printer.SolutionPart1(valuePart1, stopwatch.Elapsed.TotalMilliseconds);
55+
56+
stopwatch.Restart();
57+
TPart2Result valuePart2 = part2(data);
58+
stopwatch.Stop();
59+
Printer.SolutionPart2(valuePart2, stopwatch.Elapsed.TotalMilliseconds);
60+
}
61+
}

Diff for: 2016/Util/Extensions/StringExtensions.cs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Security.Cryptography;
2+
using System.Text;
3+
4+
namespace Util.Extensions;
5+
6+
public static class StringExtensions
7+
{
8+
public static string CaesarCode(this string str, int cipherLength)
9+
{
10+
var shift = cipherLength % 26;
11+
var buffer = str.ToCharArray();
12+
13+
for (var i = 0; i < buffer.Length; i++)
14+
{
15+
var letter = buffer[i];
16+
letter = (char)(letter + shift);
17+
18+
if (letter > 'z')
19+
{
20+
letter = (char)(letter - 26);
21+
}
22+
else if (letter < 'a')
23+
{
24+
letter = (char)(letter + 26);
25+
}
26+
27+
buffer[i] = letter;
28+
}
29+
30+
return new string(buffer);
31+
}
32+
33+
public static string GetMD5(this string str)
34+
{
35+
var inputBytes = Encoding.ASCII.GetBytes(str);
36+
var hashBytes = MD5.HashData(inputBytes);
37+
38+
var sb = new StringBuilder();
39+
40+
foreach (var b in hashBytes)
41+
{
42+
sb.Append(b.ToString("X2"));
43+
}
44+
45+
return sb.ToString();
46+
}
47+
}

Diff for: 2016/Util/Math/Vec2.cs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace Util.Math;
2+
3+
public class Vec2(int x, int y) : IEquatable<Vec2>
4+
{
5+
public int X { get; private set; } = x;
6+
public int Y { get; private set; } = y;
7+
8+
public bool Equals(Vec2? other)
9+
{
10+
return other != null && X == other.X && Y == other.Y;
11+
}
12+
}

Diff for: 2016/Util/Util.csproj

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
5-
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>enable</Nullable>
7-
</PropertyGroup>
8-
9-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
8+
9+
</Project>

Diff for: 2016/d01/01.csproj

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>net9.0</TargetFramework>
6-
<ImplicitUsings>enable</ImplicitUsings>
7-
<Nullable>enable</Nullable>
8-
</PropertyGroup>
9-
10-
<ItemGroup>
11-
<ProjectReference Include="..\Util\Util.csproj" />
12-
</ItemGroup>
13-
14-
</Project>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\Util\Util.csproj" />
12+
</ItemGroup>
13+
14+
</Project>

Diff for: 2016/d01/Direction.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Aoc.Day01;
2+
3+
enum Direction
4+
{
5+
North = 1,
6+
East = 2,
7+
South = 3,
8+
West = 4,
9+
}

Diff for: 2016/d01/Point.cs

-6
This file was deleted.

0 commit comments

Comments
 (0)