Skip to content

Commit

Permalink
Revert changes
Browse files Browse the repository at this point in the history
Revert changes which don't appear to have a positive effect in practice.
  • Loading branch information
martincostello committed Sep 19, 2024
1 parent 172c4b1 commit bc82af8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/AdventOfCode/Puzzles/Y2022/Day02.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public static int GetTotalScore(ICollection<string> moves, bool containsDesiredO
{
int total = 0;

Func<ReadOnlySpan<char>, Move, Move> moveSelector =
Func<string, Move, Move> moveSelector =
containsDesiredOutcome ?
(value, opponent) => GetMove(ParseOutcome(value), opponent) :
(value, _) => ParseMove(value);

foreach (string move in moves)
{
move.AsSpan().AsPair(' ', out var opponent, out var player);
(string opponent, string player) = move.AsPair(' ');

Check failure on line 55 in src/AdventOfCode/Puzzles/Y2022/Day02.cs

View workflow job for this annotation

GitHub Actions / windows-latest

'string' does not contain a definition for 'AsPair' and the best extension method overload 'StringExtensions.AsPair(ReadOnlySpan<char>, char)' requires a receiver of type 'System.ReadOnlySpan<char>'

Check failure on line 55 in src/AdventOfCode/Puzzles/Y2022/Day02.cs

View workflow job for this annotation

GitHub Actions / windows-latest

'string' does not contain a definition for 'AsPair' and the best extension method overload 'StringExtensions.AsPair(ReadOnlySpan<char>, char)' requires a receiver of type 'System.ReadOnlySpan<char>'

Move opponentMove = ParseMove(opponent);
Move playerMove = moveSelector(player, opponentMove);
Expand Down Expand Up @@ -87,20 +87,20 @@ public static int GetTotalScore(ICollection<string> moves, bool containsDesiredO
_ => player == opponent ? Outcome.Draw : throw new InvalidOperationException("Invalid move combination."),
};

static Move ParseMove(ReadOnlySpan<char> value) => value switch
static Move ParseMove(string value) => value switch
{
"A" or "X" => Move.Rock,
"B" or "Y" => Move.Paper,
"C" or "Z" => Move.Scissors,
_ => throw new ArgumentOutOfRangeException(nameof(value), value.ToString(), "Invalid move."),
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Invalid move."),
};

static Outcome ParseOutcome(ReadOnlySpan<char> value) => value switch
static Outcome ParseOutcome(string value) => value switch
{
"X" => Outcome.Lose,
"Y" => Outcome.Draw,
"Z" => Outcome.Win,
_ => throw new ArgumentOutOfRangeException(nameof(value), value.ToString(), "Invalid outcome."),
_ => throw new ArgumentOutOfRangeException(nameof(value), value, "Invalid outcome."),
};
}

Expand Down
7 changes: 3 additions & 4 deletions src/AdventOfCode/Puzzles/Y2022/Day04.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ public static int GetOverlappingAssignments(IList<string> assignments, bool part

foreach (string assignment in assignments)
{
assignment.AsSpan().Bifurcate(',', out var firstSpan, out var secondSpan);

Range first = AsRange(firstSpan.AsNumberPair<int>('-'));
Range second = AsRange(secondSpan.AsNumberPair<int>('-'));
string[] split = assignment.Split(',');
Range first = AsRange(split[0].AsNumberPair<int>('-'));
Range second = AsRange(split[1].AsNumberPair<int>('-'));

if (partial)
{
Expand Down

0 comments on commit bc82af8

Please sign in to comment.