ben
/
aoc
1
0
Fork 0

prefer char.IsAsciiDigit over char.IsDigit

This commit is contained in:
Ben Harris 2023-12-03 01:53:48 -05:00
parent 3d6b2df0d6
commit ace7201859
2 changed files with 6 additions and 5 deletions

View File

@ -16,11 +16,12 @@ public sealed class Day18() : Day(2020, 18, "Operation Order")
var postfixStack = new Stack<char>();
foreach (var c in expr)
if (char.IsDigit(c))
if (char.IsAsciiDigit(c))
{
postfixNotation.Append(c);
}
else switch (c)
else
switch (c)
{
case '(':
postfixStack.Push(c);
@ -49,7 +50,7 @@ public sealed class Day18() : Day(2020, 18, "Operation Order")
var expressionStack = new Stack<long>();
foreach (var c in postfixNotation.ToString())
if (char.IsDigit(c))
if (char.IsAsciiDigit(c))
{
expressionStack.Push((long)char.GetNumericValue(c));
}

View File

@ -10,7 +10,7 @@ public class Day01() : Day(2023, 1, "Trebuchet?!")
}
public override object Part1() =>
Input.Sum(line => (line.First(char.IsDigit) - '0') * 10 + (line.Last(char.IsDigit) - '0'));
Input.Sum(line => (line.First(char.IsAsciiDigit) - '0') * 10 + (line.Last(char.IsAsciiDigit) - '0'));
public override object Part2() =>
Input.Sum(line =>
@ -19,7 +19,7 @@ public class Day01() : Day(2023, 1, "Trebuchet?!")
for (var i = 0; i < line.Length; i++)
{
if (char.IsDigit(line[i]))
if (char.IsAsciiDigit(line[i]))
{
digits.Add(item: line[i] - '0');
continue;