prefer char.IsAsciiDigit over char.IsDigit
This commit is contained in:
parent
3d6b2df0d6
commit
ace7201859
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue