Add benchmark support using -b
This commit is contained in:
30
Days/Day2.cs
30
Days/Day2.cs
@@ -18,10 +18,10 @@ public enum Outcome : long
|
||||
|
||||
public class Day2 : Day
|
||||
{
|
||||
public override int Number { get; } = 2;
|
||||
public override string Name { get; } = "Rock Paper Scissors";
|
||||
|
||||
public override void RunPart1()
|
||||
public override int Number => 2;
|
||||
public override string Name => "Rock Paper Scissors";
|
||||
|
||||
public override void RunPart1(bool display = true)
|
||||
{
|
||||
long score = 0;
|
||||
|
||||
@@ -33,14 +33,17 @@ public class Day2 : Day
|
||||
score += (long) selfChoice;
|
||||
score += (long) ComputeOutcome(adversaryChoice, selfChoice);
|
||||
}
|
||||
|
||||
AnsiConsole.MarkupLine($"[green]Total score: [yellow]{score}[/][/]");
|
||||
|
||||
if (display)
|
||||
{
|
||||
AnsiConsole.MarkupLine($"[green]Total score: [yellow]{score}[/][/]");
|
||||
}
|
||||
}
|
||||
|
||||
public override void RunPart2()
|
||||
|
||||
public override void RunPart2(bool display = true)
|
||||
{
|
||||
long score = 0;
|
||||
|
||||
|
||||
foreach (var line in Input.ReadAllLines())
|
||||
{
|
||||
var adversaryChoice = AdversaryInputToChoice(line[0]);
|
||||
@@ -50,8 +53,11 @@ public class Day2 : Day
|
||||
score += (long) selfChoice;
|
||||
score += (long) desiredOutcome;
|
||||
}
|
||||
|
||||
AnsiConsole.MarkupLine($"[green]Total score: [yellow]{score}[/][/]");
|
||||
|
||||
if (display)
|
||||
{
|
||||
AnsiConsole.MarkupLine($"[green]Total score: [yellow]{score}[/][/]");
|
||||
}
|
||||
}
|
||||
|
||||
private Outcome ComputeOutcome(Choice adversary, Choice self) => (adversary, self) switch
|
||||
@@ -83,7 +89,7 @@ public class Day2 : Day
|
||||
'C' => Choice.Scissors,
|
||||
_ => throw new ArgumentException("Invalid input")
|
||||
};
|
||||
|
||||
|
||||
private Choice SelfInputToChoice(char input) => input switch
|
||||
{
|
||||
'X' => Choice.Rock,
|
||||
|
||||
Reference in New Issue
Block a user