Skip to content

Commit

Permalink
Fix editorconfig violations
Browse files Browse the repository at this point in the history
  • Loading branch information
tetsuo13 committed Dec 21, 2023
1 parent bf99809 commit a7d82de
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
10 changes: 5 additions & 5 deletions AdventOfCode/Calendar/2023/Day02/Solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace AdventOfCode.Calendar._2023.Day02;

public class Solution : BaseSolution
internal class Solution : BaseSolution
{
private readonly SetOfCubes Constraint = new()
private readonly SetOfCubes _constraint = new()
{
Red = 12,
Green = 13,
Expand Down Expand Up @@ -47,9 +47,9 @@ private async Task<int> SumGameIds()
{
var sets = SetsInGame(lines[gameId]);

if (sets.TrueForAll(x => x.Red <= Constraint.Red &&
x.Green <= Constraint.Green &&
x.Blue <= Constraint.Blue))
if (sets.TrueForAll(x => x.Red <= _constraint.Red &&
x.Green <= _constraint.Green &&
x.Blue <= _constraint.Blue))
{
sum += gameId + 1;
}
Expand Down
4 changes: 2 additions & 2 deletions AdventOfCode/Calendar/2023/Day02/SolutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private class TestSolution(string[] inputLines) : Solution
public override Task<string[]> ReadInput() => Task.FromResult(inputLines);
}

private readonly string[] Input =
private readonly string[] _input =
[
"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",
Expand All @@ -23,7 +23,7 @@ private class TestSolution(string[] inputLines) : Solution
[InlineData(RunMode.PartTwo, 2286)]
public async Task SampleRecord(RunMode runMode, int expected)
{
var solution = new TestSolution(Input);
var solution = new TestSolution(_input);
Assert.Equal(expected, await solution.Run(runMode));
}
}
51 changes: 25 additions & 26 deletions AdventOfCode/Calendar/2023/Day03/Solution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ namespace AdventOfCode.Calendar._2023.Day03;
/// than implementing algorithms from scratch [poorly] -- this really showed
/// for part 2.
/// </summary>
public partial class Solution : BaseSolution
internal partial class Solution : BaseSolution
{
private const char PeriodSymbol = '.';
private const char GearSymbol = '*';

private string[] lines = [];
private string[] _lines = [];

public override async Task<int> Run(RunMode runMode)
{
Expand All @@ -30,14 +30,14 @@ public override async Task<int> Run(RunMode runMode)

private async Task<int> SumPartNumbers()
{
lines = await ReadInput();
_lines = await ReadInput();
var sum = 0;

for (var lineNumber = 0; lineNumber < lines.Length; lineNumber++)
for (var lineNumber = 0; lineNumber < _lines.Length; lineNumber++)
{
// Draw a bounding box around every number in the row to look
// for a symbol.
foreach (var match in NumberRegex().Matches(lines[lineNumber]).Cast<Match>())
foreach (var match in NumberRegex().Matches(_lines[lineNumber]).Cast<Match>())
{
var boundingBox = GetBoundingBox(lineNumber, match.Index, match.Value);

Expand All @@ -55,27 +55,27 @@ private async Task<int> SumPartNumbers()

private async Task<int> SumGearRatios()
{
lines = await ReadInput();
_lines = await ReadInput();
var sum = 0;

for (var lineNumber = 0; lineNumber < lines.Length; lineNumber++)
for (var lineNumber = 0; lineNumber < _lines.Length; lineNumber++)
{
// Keep track of adjacent part numbers on the line to avoid
// duplicates.
var seen = new List<KeyValuePair<string, string>>();

foreach (var match in NumberRegex().Matches(lines[lineNumber]).Cast<Match>())
foreach (var match in NumberRegex().Matches(_lines[lineNumber]).Cast<Match>())
{
var boundingBox = GetBoundingBox(lineNumber, match.Index, match.Value);

// Gear to the left, first character to the left of that isn't
// a period, and this number wasn't previously seen.
if (boundingBox[(int)Direction.Left].Contains(GearSymbol) &&
lines[lineNumber][match.Index - 2] != PeriodSymbol &&
_lines[lineNumber][match.Index - 2] != PeriodSymbol &&
!seen.Exists(x => x.Value == match.Value))
{
var rl = GearRatioRLRegex();
var rlMatches = rl.Match(lines[lineNumber], match.Index);
var rlMatches = rl.Match(_lines[lineNumber], match.Index);

if (rlMatches.Success)
{
Expand All @@ -87,10 +87,10 @@ private async Task<int> SumGearRatios()
// Gear to the right and the first character next to that
// isn't a period.
if (boundingBox[(int)Direction.Right].Contains(GearSymbol) &&
lines[lineNumber][match.Index + match.Value.Length + 1] != PeriodSymbol)
_lines[lineNumber][match.Index + match.Value.Length + 1] != PeriodSymbol)
{
var lr = GearRatioLRRegex();
var rlMatches = lr.Match(lines[lineNumber], match.Index + match.Value.Length);
var rlMatches = lr.Match(_lines[lineNumber], match.Index + match.Value.Length);

if (rlMatches.Success)
{
Expand All @@ -102,18 +102,18 @@ private async Task<int> SumGearRatios()
var gearPosition = boundingBox[(int)Direction.Bottom].IndexOf(GearSymbol);

if (gearPosition != -1 &&
lineNumber + 2 < lines.Length &&
match.Index + gearPosition < lines[lineNumber + 2].Length &&
lines[lineNumber + 2][match.Index + gearPosition] != PeriodSymbol)
lineNumber + 2 < _lines.Length &&
match.Index + gearPosition < _lines[lineNumber + 2].Length &&
_lines[lineNumber + 2][match.Index + gearPosition] != PeriodSymbol)
{
// Starting at the position of the gear, find all numbers
// to the right and left of it then concatenate them to
// get the part number.

var lr = GearRatioLRRegex();
var rl = GearRatioRLRegex();
var lrMatches = lr.Match(lines[lineNumber + 2], match.Index + gearPosition);
var rlMatches = rl.Match(lines[lineNumber + 2], match.Index + gearPosition);
var lrMatches = lr.Match(_lines[lineNumber + 2], match.Index + gearPosition);
var rlMatches = rl.Match(_lines[lineNumber + 2], match.Index + gearPosition);

var partNumber = (rlMatches.Success ? rlMatches.Value : string.Empty)
+ (lrMatches.Success ? lrMatches.Value : string.Empty);
Expand Down Expand Up @@ -157,38 +157,38 @@ private string[] GetBoundingBox(int currentLine, int matchIndex, string number)
// Add left
if (!isFlushLeft)
{
boundingBox[(int)Direction.Left] = lines[currentLine][matchIndex - 1].ToString();
boundingBox[(int)Direction.Left] = _lines[currentLine][matchIndex - 1].ToString();
}

// Add right
if (matchIndex + number.Length < lines[currentLine].Length)
if (matchIndex + number.Length < _lines[currentLine].Length)
{
boundingBox[(int)Direction.Right] = lines[currentLine][matchIndex + number.Length].ToString();
boundingBox[(int)Direction.Right] = _lines[currentLine][matchIndex + number.Length].ToString();
}

var startingPos = isFlushLeft ? 0 : matchIndex - 1;
int endPadding;

if (isFlushLeft)
{
endPadding = startingPos + number.Length + 1 > lines[currentLine].Length ? 0 : 1;
endPadding = startingPos + number.Length + 1 > _lines[currentLine].Length ? 0 : 1;
}
else
{
endPadding = startingPos + number.Length + 2 > lines[currentLine].Length ? 1 : 2;
endPadding = startingPos + number.Length + 2 > _lines[currentLine].Length ? 1 : 2;
}

// Add top
if (currentLine > 0)
{
boundingBox[(int)Direction.Top] = lines[currentLine - 1]
boundingBox[(int)Direction.Top] = _lines[currentLine - 1]
.Substring(startingPos, number.Length + endPadding);
}

// Add bottom
if (currentLine < lines.Length - 1)
if (currentLine < _lines.Length - 1)
{
boundingBox[(int)Direction.Bottom] = lines[currentLine + 1]
boundingBox[(int)Direction.Bottom] = _lines[currentLine + 1]
.Substring(startingPos, number.Length + endPadding);
}

Expand All @@ -201,7 +201,6 @@ private string[] GetBoundingBox(int currentLine, int matchIndex, string number)
[GeneratedRegex(@"\d+")]
private static partial Regex GearRatioLRRegex();

//[GeneratedRegex(@"^(?!\.)\d+", RegexOptions.RightToLeft)]
[GeneratedRegex(@"\d+", RegexOptions.RightToLeft)]
private static partial Regex GearRatioRLRegex();
}

0 comments on commit a7d82de

Please sign in to comment.