Skip to content

Commit

Permalink
Fix build errors, warnings, messages
Browse files Browse the repository at this point in the history
  • Loading branch information
premun committed Dec 2, 2024
1 parent 170dde2 commit b524472
Show file tree
Hide file tree
Showing 36 changed files with 102 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<PropertyGroup>
<LangVersion>latest</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UseArtifactsOutput>true</UseArtifactsOutput>
Expand Down
2 changes: 1 addition & 1 deletion src/2020/16/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
while (fieldMapping.Count < myTicket.Length)
{
var unmappedFields = Enumerable.Range(0, myTicket.Length)
.Except(fieldMapping.Keys.ToList())
.Except([.. fieldMapping.Keys])
.ToList();

foreach (var unmappedField in unmappedFields)
Expand Down
2 changes: 1 addition & 1 deletion src/2021/08/SegmentMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public int MapDigits(string[] digits)
foreach (var digit in digits)
{
// Map to our digit
var mappedDigit = new string(digit.Select(x => _segmentMapping[x]).OrderBy(x => x).ToArray());
var mappedDigit = new string([.. digit.Select(x => _segmentMapping[x]).OrderBy(x => x)]);

var value = s_digits.First(x => x.Value == mappedDigit).Key;

Expand Down
6 changes: 3 additions & 3 deletions src/2021/20/ImageEnhancer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace AdventOfCode._2021_20;

class ImageEnhancer(ReadOnlyCollection<bool> algorithm)
{
private static readonly IEnumerable<Coor> s_arounds = new Coor[]
{
private static readonly IEnumerable<Coor> s_arounds =
[
new (-1, -1),
new (-1, 0),
new (-1, 1),
Expand All @@ -18,7 +18,7 @@ class ImageEnhancer(ReadOnlyCollection<bool> algorithm)
new (1, -1),
new (1, 0),
new (1, 1),
};
];

private readonly ReadOnlyCollection<bool> _algorithm = algorithm;

Expand Down
11 changes: 2 additions & 9 deletions src/2021/21/DiracDiceGame.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
namespace AdventOfCode._2021_21;

abstract class DiracDiceGame
abstract class DiracDiceGame(int maxPosition)
{
private readonly int _maxPosition;

protected DiracDiceGame(int maxPosition)
{
_maxPosition = maxPosition;
}

protected (int Position, int Points) MovePlayer(int position, int points, int diceRoll)
{
var nextPosition = (position + diceRoll) % _maxPosition;
var nextPosition = (position + diceRoll) % maxPosition;
return (nextPosition, points + nextPosition + 1);
}
}
3 changes: 2 additions & 1 deletion src/2021/21/SimpleDiracDiceGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class Player
public int Points { get; set; }
}

class SimpleDiracDiceGame(IDice dice, int maxPosition, int winningPoints) : DiracDiceGame(maxPosition)
class SimpleDiracDiceGame(IDice dice, int maxPosition, int winningPoints)
: DiracDiceGame(maxPosition)
{
private readonly IDice _dice = dice;
private readonly int _winningPoints = winningPoints;
Expand Down
24 changes: 12 additions & 12 deletions src/2021/23/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,47 +69,47 @@ static int FindLowestEnergyCost(AmphipodWorld startWorld, AmphipodWorld finished
return result;
}

var startWorld = new AmphipodWorld(new[]
{
var startWorld = new AmphipodWorld(
[
"#############",
"#...........#",
"###B#A#B#C###",
" #C#D#D#A#",
" #########"
});
]);

var endWorld = new AmphipodWorld(new[]
{
var endWorld = new AmphipodWorld(
[
"#############",
"#...........#",
"###A#B#C#D###",
" #A#B#C#D#",
" #########"
});
]);

Console.WriteLine($"Part 1: " + FindLowestEnergyCost(startWorld, endWorld));
Console.WriteLine();

startWorld = new AmphipodWorld(new[]
{
startWorld = new AmphipodWorld(
[
"#############",
"#...........#",
"###B#A#B#C###",
" #D#C#B#A#",
" #D#B#A#C#",
" #C#D#D#A#",
" #########",
});
]);

endWorld = new AmphipodWorld(new[]
{
endWorld = new AmphipodWorld(
[
"#############",
"#...........#",
"###A#B#C#D###",
" #A#B#C#D#",
" #A#B#C#D#",
" #A#B#C#D#",
" #########"
});
]);

Console.WriteLine($"Part 2: " + FindLowestEnergyCost(startWorld, endWorld));
2 changes: 1 addition & 1 deletion src/2022/10/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using AdventOfCode.Common;

var commands = Resources.GetInputFileLines();
var system = new CommunicationSystem(40, new[] { 20, 60, 100, 140, 180, 220 });
var system = new CommunicationSystem(40, [20, 60, 100, 140, 180, 220]);
system.RunCommands(commands);

Console.WriteLine($"Part 1: {system.Signal}");
Expand Down
4 changes: 2 additions & 2 deletions src/2022/13/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public int CompareTo(object? other)
}

// If exactly one value is an integer, convert the integer to a list which contains that integer as its only value
List l1 = p1 is Number n ? new List(new[] { n }) : (List)p1;
List l2 = p2 is Number m ? new List(new[] { m }) : (List)p2;
List l1 = p1 is Number n ? new List([n]) : (List)p1;
List l2 = p2 is Number m ? new List([m]) : (List)p2;

// If both values are lists, compare the first value of each list, then the second value, and so on
for (int i = 0;; i++)
Expand Down
30 changes: 15 additions & 15 deletions src/2022/17/Rocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,53 +12,53 @@ abstract class Rock(IReadOnlyCollection<Coor> positions)

class RowRock : Rock
{
public RowRock() : base(new[]
{
public RowRock() : base(
[
new Coor(0, 2), new Coor(0, 3), new Coor(0, 4), new Coor(0, 5),
})
])
{ }
}

class CrossRock : Rock
{
public CrossRock() : base(new[]
{
public CrossRock() : base(
[
new Coor(0, 3),
new Coor(1, 2), new Coor(1, 3), new Coor(1, 4),
new Coor(2, 3),
})
])
{ }
}

class LRock : Rock
{
public LRock() : base(new[]
{
public LRock() : base(
[
new Coor(0, 4),
new Coor(1, 4),
new Coor(2, 2), new Coor(2, 3), new Coor(2, 4),
})
])
{ }
}

class ColumnRock : Rock
{
public ColumnRock() : base(new[]
{
public ColumnRock() : base(
[
new Coor(0, 2),
new Coor(1, 2),
new Coor(2, 2),
new Coor(3, 2),
})
])
{ }
}

class BoxRock : Rock
{
public BoxRock() : base(new[]
{
public BoxRock() : base(
[
new Coor(0, 2), new Coor(0, 3),
new Coor(1, 2), new Coor(1, 3),
})
])
{ }
}
6 changes: 3 additions & 3 deletions src/2023/04/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AdventOfCode.Common;

IReadOnlyCollection<Card> cards = Resources.GetInputFileLines()
Card[] cards = Resources.GetInputFileLines()
.Select(Card.Parse)
.ToArray();

Expand All @@ -9,10 +9,10 @@
.Select(card => Math.Pow(2, card.MatchingNumbers - 1));

var wonCards = cards.ToDictionary(c => c.Id, c => 1L);
for (int i = 0; i < cards.Count; i++)
for (int i = 0; i < cards.Length; i++)
{
var card = cards.ElementAt(i);
for (int j = 1; j <= card.MatchingNumbers && j + card.Id <= cards.Count; j++)
for (int j = 1; j <= card.MatchingNumbers && j + card.Id <= cards.Length; j++)
{
wonCards[card.Id + j] += wonCards[card.Id];
}
Expand Down
4 changes: 2 additions & 2 deletions src/2023/18/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

record Instruction(Coor Direction, int Distance, string Color)
{
private static readonly Regex Regex = new(@"(?<direction>R|D|L|U) (?<distance>[0-9]+) \(#(?<color>[0-9a-h]{6})\)");
private static readonly Regex s_regex = new(@"(?<direction>R|D|L|U) (?<distance>[0-9]+) \(#(?<color>[0-9a-h]{6})\)");

public Instruction Invert() => new(
Color.Last() switch
Expand All @@ -28,7 +28,7 @@ record Instruction(Coor Direction, int Distance, string Color)

public static Instruction Parse(string s)
{
var match = Regex.Match(s);
var match = s_regex.Match(s);
return new Instruction(
match.Groups["direction"].Value[0] switch
{
Expand Down
8 changes: 4 additions & 4 deletions src/2023/23/LongestPathResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public override int FindLongestPath()

// :(((( Brute force :(((
// Need to find a longest path algorithm for cyclic directed graphs
private int FindLongestPathRecursive(Junction start, Junction end, List<Junction> currentPath, int distance)
private static int FindLongestPathRecursive(Junction start, Junction end, List<Junction> currentPath, int distance)
{
var current = currentPath.Last();
if (current == end)
Expand Down Expand Up @@ -95,7 +95,7 @@ protected override void ConnectAllJunctions()

internal abstract class LongestPathResolver
{
private static readonly Dictionary<char, Coor> Directions = new()
private static readonly Dictionary<char, Coor> s_directions = new()
{
{ '<', Coor.Left },
{ '>', Coor.Right },
Expand Down Expand Up @@ -124,8 +124,8 @@ public LongestPathResolver(char[,] map)
.Single();

Slopes = map.AllCoordinates()
.Where(coor => Directions.ContainsKey(map.Get(coor)))
.ToDictionary(c => c, c => new Slope(Directions[map.Get(c)]));
.Where(coor => s_directions.ContainsKey(map.Get(coor)))
.ToDictionary(c => c, c => new Slope(s_directions[map.Get(c)]));

Junctions = new()
{
Expand Down
3 changes: 2 additions & 1 deletion src/2024/04/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/05/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/06/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/07/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/08/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/09/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/10/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/11/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/12/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/13/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/14/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/15/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/16/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/17/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
3 changes: 2 additions & 1 deletion src/2024/18/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

using AdventOfCode.Common;

var lines = Resources.GetInputFileLines("input.txt");

Console.WriteLine($"Part 1: {""}");
Expand Down
Loading

0 comments on commit b524472

Please sign in to comment.