Skip to content

Commit 5fe6295

Browse files
Update to net9
1 parent 4686b56 commit 5fe6295

File tree

83 files changed

+527
-323
lines changed

Some content is hidden

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

83 files changed

+527
-323
lines changed

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,18 @@ dotnet_diagnostic.IDE0059.severity = none # IDE0059: Unnecessary a
314314
dotnet_diagnostic.IDE0120.severity = none # IDE0120: Simplify LINQ expression
315315
dotnet_diagnostic.IDE0305.severity = none # IDE0305: Collection initialization can be simplified
316316

317+
dotnet_diagnostic.MA0001.severity = none
318+
dotnet_diagnostic.MA0002.severity = none
319+
dotnet_diagnostic.MA0006.severity = none
320+
dotnet_diagnostic.MA0009.severity = none
321+
dotnet_diagnostic.MA0011.severity = none
322+
dotnet_diagnostic.MA0016.severity = none
323+
dotnet_diagnostic.MA0048.severity = none
324+
dotnet_diagnostic.MA0051.severity = none
325+
dotnet_diagnostic.MA0074.severity = none
326+
dotnet_diagnostic.MA0076.severity = none
327+
dotnet_diagnostic.MA0097.severity = none
328+
317329
[**/*.ProgramArguments.cs]
318330
# Mark code as excluded and generated
319331
# NB: This disables regular analyzers by default
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
<Project Sdk="Microsoft.NET.Sdk" />
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<ItemGroup>
3+
<PackageReference Include="SuperLinq" />
4+
</ItemGroup>
5+
</Project>

AdventOfCode.Common/Extensions/SpanExtensions.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace AdventOfCode.Common.Extensions;
1+
using System.Runtime.InteropServices;
2+
3+
namespace AdventOfCode.Common.Extensions;
24

35
public static class SpanExtensions
46
{
@@ -12,6 +14,7 @@ public static class SpanExtensions
1214
/// <remarks>
1315
/// To get an instance of this type, use <see cref="MemoryExtensions.EnumerateLines(ReadOnlySpan{char})"/>.
1416
/// </remarks>
17+
[StructLayout(LayoutKind.Auto)]
1518
public ref struct SpanByteLineEnumerator
1619
{
1720
private ReadOnlySpan<byte> _remaining;
@@ -77,6 +80,7 @@ public bool MoveNext()
7780
/// <remarks>
7881
/// To get an instance of this type, use <see cref="MemoryExtensions.EnumerateLines(ReadOnlySpan{char})"/>.
7982
/// </remarks>
83+
[StructLayout(LayoutKind.Auto)]
8084
public ref struct SpanByteLineLengthEnumerator
8185
{
8286
private readonly int _length;

AdventOfCode.Common/ValueArray.cs

+57-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,72 @@
1-
using System.Runtime.CompilerServices;
1+
using System.Runtime.CompilerServices;
22

33
namespace AdventOfCode.Common;
44

55
#pragma warning disable IDE0044 // Add readonly modifier
66
#pragma warning disable IDE0051 // Remove unused private members
77

88
[InlineArray(4)]
9-
public record struct ValueArray4<T>
9+
public struct ValueArray4<T> : IEquatable<ValueArray4<T>> where T : IEquatable<T>
1010
{
1111
private T _0;
12+
13+
public override readonly bool Equals(object? obj) =>
14+
obj is ValueArray4<T> va && Equals(va);
15+
16+
public readonly bool Equals(ValueArray4<T> other) =>
17+
EqualityComparer<T>.Default.Equals(this[0], other[0])
18+
&& EqualityComparer<T>.Default.Equals(this[1], other[1])
19+
&& EqualityComparer<T>.Default.Equals(this[2], other[2])
20+
&& EqualityComparer<T>.Default.Equals(this[3], other[3]);
21+
22+
public override readonly int GetHashCode() =>
23+
HashCode.Combine(
24+
EqualityComparer<T>.Default.GetHashCode(this[0]),
25+
EqualityComparer<T>.Default.GetHashCode(this[1]),
26+
EqualityComparer<T>.Default.GetHashCode(this[2]),
27+
EqualityComparer<T>.Default.GetHashCode(this[3])
28+
);
29+
30+
public static bool operator ==(ValueArray4<T> left, ValueArray4<T> right) =>
31+
left.Equals(right);
32+
33+
public static bool operator !=(ValueArray4<T> left, ValueArray4<T> right) =>
34+
!(left == right);
1235
}
1336

1437
[InlineArray(8)]
15-
public record struct ValueArray8<T>
38+
public struct ValueArray8<T> : IEquatable<ValueArray8<T>> where T : IEquatable<T>
1639
{
1740
private T _0;
41+
42+
public override readonly bool Equals(object? obj) =>
43+
obj is ValueArray8<T> va && Equals(va);
44+
45+
public readonly bool Equals(ValueArray8<T> other) =>
46+
EqualityComparer<T>.Default.Equals(this[0], other[0])
47+
&& EqualityComparer<T>.Default.Equals(this[1], other[1])
48+
&& EqualityComparer<T>.Default.Equals(this[2], other[2])
49+
&& EqualityComparer<T>.Default.Equals(this[3], other[3])
50+
&& EqualityComparer<T>.Default.Equals(this[4], other[4])
51+
&& EqualityComparer<T>.Default.Equals(this[5], other[5])
52+
&& EqualityComparer<T>.Default.Equals(this[6], other[6])
53+
&& EqualityComparer<T>.Default.Equals(this[7], other[7]);
54+
55+
public override readonly int GetHashCode() =>
56+
HashCode.Combine(
57+
EqualityComparer<T>.Default.GetHashCode(this[0]),
58+
EqualityComparer<T>.Default.GetHashCode(this[1]),
59+
EqualityComparer<T>.Default.GetHashCode(this[2]),
60+
EqualityComparer<T>.Default.GetHashCode(this[3]),
61+
EqualityComparer<T>.Default.GetHashCode(this[4]),
62+
EqualityComparer<T>.Default.GetHashCode(this[5]),
63+
EqualityComparer<T>.Default.GetHashCode(this[6]),
64+
EqualityComparer<T>.Default.GetHashCode(this[7])
65+
);
66+
67+
public static bool operator ==(ValueArray8<T> left, ValueArray8<T> right) =>
68+
left.Equals(right);
69+
70+
public static bool operator !=(ValueArray8<T> left, ValueArray8<T> right) =>
71+
!(left == right);
1872
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<RootNamespace>AdventOfCode.Puzzles._2015</RootNamespace>
4-
<Nullable>disable</Nullable>
5-
</PropertyGroup>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<RootNamespace>AdventOfCode.Puzzles._2015</RootNamespace>
4+
<Nullable>disable</Nullable>
5+
</PropertyGroup>
66

77
<ItemGroup>
8-
<ProjectReference Include="..\..\AdventOfCode.Common\AdventOfCode.Common.csproj" />
8+
<ProjectReference Include="..\..\AdventOfCode.Common\AdventOfCode.Common.csproj" />
99
</ItemGroup>
1010
</Project>

AdventOfCode.Puzzles/2015/day02.original.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AdventOfCode.Puzzles._2015;
1+
namespace AdventOfCode.Puzzles._2015;
22

33
[Puzzle(2015, 02, CodeType.Original)]
44
public partial class Day_02_Original : IPuzzle
@@ -34,6 +34,6 @@ public partial class Day_02_Original : IPuzzle
3434
totalRibbonLength.ToString());
3535
}
3636

37-
[GeneratedRegex("(?<l>\\d+)x(?<w>\\d+)x(?<h>\\d+)", RegexOptions.Compiled)]
37+
[GeneratedRegex("(?<l>\\d+)x(?<w>\\d+)x(?<h>\\d+)", RegexOptions.ExplicitCapture)]
3838
private static partial Regex BoxRegex();
3939
}

AdventOfCode.Puzzles/2015/day03.original.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class Day_03_Original : IPuzzle
1515
if (c == 'v') current = (current.x, current.y - 1);
1616
return current;
1717
})
18-
.Concat(new[] { (0, 0) })
18+
.Concat([(0, 0)])
1919
.Distinct()
2020
.Count();
2121

@@ -32,7 +32,7 @@ public class Day_03_Original : IPuzzle
3232
current = t;
3333
return other;
3434
})
35-
.Concat(new[] { (0, 0) })
35+
.Concat([(0, 0)])
3636
.Distinct()
3737
.Count();
3838

AdventOfCode.Puzzles/2015/day06.original.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Diagnostics;
1+
using System.Diagnostics;
2+
using System.Runtime.InteropServices;
23

34
namespace AdventOfCode.Puzzles._2015;
45

@@ -12,6 +13,7 @@ private enum Command
1213
Toggle,
1314
}
1415

16+
[StructLayout(LayoutKind.Auto)]
1517
private struct Action
1618
{
1719
public Command Command { get; set; }
@@ -21,7 +23,7 @@ private struct Action
2123
public int EndY { get; set; }
2224
}
2325

24-
[GeneratedRegex("((?<on>turn on)|(?<off>turn off)|(?<toggle>toggle)) (?<startX>\\d+),(?<startY>\\d+) through (?<endX>\\d+),(?<endY>\\d+)", RegexOptions.ExplicitCapture | RegexOptions.Compiled)]
26+
[GeneratedRegex("((?<on>turn on)|(?<off>turn off)|(?<toggle>toggle)) (?<startX>\\d+),(?<startY>\\d+) through (?<endX>\\d+),(?<endY>\\d+)", RegexOptions.ExplicitCapture)]
2527
private static partial Regex InstructionRegex();
2628

2729
public (string, string) Solve(PuzzleInput input)
@@ -68,7 +70,7 @@ int ProcessActions(Func<Command, Func<int, int>> getLightProcessor)
6870
}
6971

7072
return cnt;
71-
};
73+
}
7274

7375
var partA = ProcessActions(c =>
7476
c switch
@@ -89,4 +91,4 @@ int ProcessActions(Func<Command, Func<int, int>> getLightProcessor)
8991

9092
return (partA.ToString(), partB.ToString());
9193
}
92-
}
94+
}

AdventOfCode.Puzzles/2015/day07.original.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Diagnostics;
1+
using System.Diagnostics;
22

33
namespace AdventOfCode.Puzzles._2015;
44

@@ -13,7 +13,8 @@ public partial class Day_07_Original : IPuzzle
1313
)
1414
\s*->\s*
1515
(?<dest>\w+)\s*$",
16-
RegexOptions.ExplicitCapture | RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace)]
16+
RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace
17+
)]
1718
private static partial Regex InstructionRegex();
1819

1920
public (string, string) Solve(PuzzleInput input)

AdventOfCode.Puzzles/2015/day08.original.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AdventOfCode.Puzzles._2015;
1+
namespace AdventOfCode.Puzzles._2015;
22

33
[Puzzle(2015, 08, CodeType.Original)]
44
public partial class Day_08_Original : IPuzzle
@@ -26,6 +26,6 @@ private static int GetDecodedLength(string str) =>
2626
return (partA.ToString(), partB.ToString());
2727
}
2828

29-
[GeneratedRegex(@"""(?<char>\\x.{2}|\\\\|\\\""|\w)*""", RegexOptions.Compiled)]
29+
[GeneratedRegex(@"""(?<char>\\x.{2}|\\\\|\\\""|\w)*""", RegexOptions.ExplicitCapture)]
3030
private static partial Regex DecodeRegex();
31-
}
31+
}

AdventOfCode.Puzzles/2015/day17.original.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Day_17_Original : IPuzzle
2222
while (cnt < max)
2323
{
2424
var sum = 0;
25-
var bitstream = new BitArray(new[] { cnt });
25+
var bitstream = new BitArray([cnt]);
2626
foreach (var _ in bitstream.OfType<bool>().Select((b, i) => new { b, i }))
2727
{
2828
if (_.b)

AdventOfCode.Puzzles/2015/day23.original.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AdventOfCode.Puzzles._2015;
1+
namespace AdventOfCode.Puzzles._2015;
22

33
[Puzzle(2015, 23, CodeType.Original)]
44
public partial class Day_23_Original : IPuzzle
@@ -65,7 +65,7 @@ public static Action<CPU> ParseInstruction(string instruction)
6565

6666
public partial class Half : Instruction
6767
{
68-
[GeneratedRegex(@"hlf (\w)", RegexOptions.Compiled)]
68+
[GeneratedRegex(@"hlf (\w)")]
6969
public override partial Regex Parser();
7070

7171
public override void ProcessInstruction(Match instruction, CPU cpu)
@@ -82,7 +82,7 @@ public override void ProcessInstruction(Match instruction, CPU cpu)
8282

8383
public partial class Third : Instruction
8484
{
85-
[GeneratedRegex(@"tpl (\w)", RegexOptions.Compiled)]
85+
[GeneratedRegex(@"tpl (\w)")]
8686
public override partial Regex Parser();
8787

8888
public override void ProcessInstruction(Match instruction, CPU cpu)
@@ -99,7 +99,7 @@ public override void ProcessInstruction(Match instruction, CPU cpu)
9999

100100
public partial class Increment : Instruction
101101
{
102-
[GeneratedRegex(@"inc (\w)", RegexOptions.Compiled)]
102+
[GeneratedRegex(@"inc (\w)")]
103103
public override partial Regex Parser();
104104

105105
public override void ProcessInstruction(Match instruction, CPU cpu)
@@ -116,7 +116,7 @@ public override void ProcessInstruction(Match instruction, CPU cpu)
116116

117117
public partial class Jump : Instruction
118118
{
119-
[GeneratedRegex(@"jmp ((\+|\-)\d+)", RegexOptions.Compiled)]
119+
[GeneratedRegex(@"jmp ((\+|\-)\d+)")]
120120
public override partial Regex Parser();
121121

122122
public override void ProcessInstruction(Match instruction, CPU cpu)
@@ -128,7 +128,7 @@ public override void ProcessInstruction(Match instruction, CPU cpu)
128128

129129
public partial class JumpEven : Instruction
130130
{
131-
[GeneratedRegex(@"jie (\w), ((\+|\-)\d+)", RegexOptions.Compiled)]
131+
[GeneratedRegex(@"jie (\w), ((\+|\-)\d+)")]
132132
public override partial Regex Parser();
133133

134134
public override void ProcessInstruction(Match instruction, CPU cpu)
@@ -154,7 +154,7 @@ public override void ProcessInstruction(Match instruction, CPU cpu)
154154

155155
public partial class JumpOne : Instruction
156156
{
157-
[GeneratedRegex(@"jio (\w), ((\+|\-)\d+)", RegexOptions.Compiled)]
157+
[GeneratedRegex(@"jio (\w), ((\+|\-)\d+)")]
158158
public override partial Regex Parser();
159159

160160
public override void ProcessInstruction(Match instruction, CPU cpu)
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<RootNamespace>AdventOfCode.Puzzles._2016</RootNamespace>
4-
<Nullable>disable</Nullable>
5-
</PropertyGroup>
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<RootNamespace>AdventOfCode.Puzzles._2016</RootNamespace>
4+
<Nullable>disable</Nullable>
5+
</PropertyGroup>
66

77
<ItemGroup>
8-
<ProjectReference Include="..\..\AdventOfCode.Common\AdventOfCode.Common.csproj" />
8+
<ProjectReference Include="..\..\AdventOfCode.Common\AdventOfCode.Common.csproj" />
99
</ItemGroup>
1010
</Project>

AdventOfCode.Puzzles/2016/day04.original.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
namespace AdventOfCode.Puzzles._2016;
1+
namespace AdventOfCode.Puzzles._2016;
22

33
[Puzzle(2016, 04, CodeType.Original)]
44
public partial class Day_04_Original : IPuzzle
55
{
6-
[GeneratedRegex("(?<name>[a-z-]+)-(?<id>\\d+)[[](?<checksum>\\w{5})[]]", RegexOptions.Compiled)]
6+
[GeneratedRegex("(?<name>[a-z-]+)-(?<id>\\d+)[[](?<checksum>\\w{5})[]]", RegexOptions.ExplicitCapture)]
77
private static partial Regex RoomRegex();
88

99
public (string, string) Solve(PuzzleInput input)

AdventOfCode.Puzzles/2016/day07.original.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ static bool IsABBA(string str)
4545
})
4646
.ToList();
4747

48-
var partA =
49-
splits
50-
.Where(x => x.outside.Any(IsABBA) && !x.inside.Any(IsABBA))
51-
.Count();
48+
var partA = splits.Count(x => x.outside.Exists(IsABBA) && !x.inside.Exists(IsABBA));
5249

5350
static IList<string> GetABAs(IList<string> strs)
5451
{
@@ -69,7 +66,7 @@ bool CheckBABs(IList<string> strs, IList<string> abas)
6966
{
7067
foreach (var aba in abas)
7168
{
72-
var bab = string.Join("", new[] { aba[1], aba[0], aba[1] });
69+
var bab = string.Join("", [aba[1], aba[0], aba[1]]);
7370
if (strs.Any(s => s.Contains(bab)))
7471
return true;
7572
}

AdventOfCode.Puzzles/2016/day08.original.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
namespace AdventOfCode.Puzzles._2016;
1+
namespace AdventOfCode.Puzzles._2016;
22

33
[Puzzle(2016, 08, CodeType.Original)]
44
public partial class Day_08_Original : IPuzzle
55
{
6-
[GeneratedRegex("(?:(?<rect>rect (?<rect_rows>\\d+)x(?<rect_cols>\\d+))|(?<rotate_column>rotate column x=(?<col_num>\\d+) by (?<col_amt>\\d+))|(?<rotate_row>rotate row y=(?<row_num>\\d+) by (?<row_amt>\\d+)))", RegexOptions.Compiled)]
6+
[GeneratedRegex(
7+
"(?:(?<rect>rect (?<rect_rows>\\d+)x(?<rect_cols>\\d+))|(?<rotate_column>rotate column x=(?<col_num>\\d+) by (?<col_amt>\\d+))|(?<rotate_row>rotate row y=(?<row_num>\\d+) by (?<row_amt>\\d+)))",
8+
RegexOptions.ExplicitCapture
9+
)]
710
private static partial Regex InstructionRegex();
811

912
public (string, string) Solve(PuzzleInput input)

AdventOfCode.Puzzles/2016/day10.original.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
namespace AdventOfCode.Puzzles._2016;
1+
namespace AdventOfCode.Puzzles._2016;
22

33
[Puzzle(2016, 10, CodeType.Original)]
44
public partial class Day_10_Original : IPuzzle
55
{
6-
[GeneratedRegex("(?:(?<give_away>bot (?<bot>\\d+) gives low to (?<low_type>bot|output) (?<low_num>\\d+) and high to (?<high_type>bot|output) (?<high_num>\\d+))|(?<receive_value>value (?<value>\\d+) goes to bot (?<bot>\\d+)))", RegexOptions.Compiled)]
6+
[GeneratedRegex(
7+
"(?:(?<give_away>bot (?<bot>\\d+) gives low to (?<low_type>bot|output) (?<low_num>\\d+) and high to (?<high_type>bot|output) (?<high_num>\\d+))|(?<receive_value>value (?<value>\\d+) goes to bot (?<bot>\\d+)))",
8+
RegexOptions.ExplicitCapture
9+
)]
710
private static partial Regex InstructionRegex();
811

912
public (string, string) Solve(PuzzleInput input)

0 commit comments

Comments
 (0)