Add benchmark support using -b

This commit is contained in:
2022-12-17 21:48:16 +01:00
parent 147c348ee1
commit 63c866f5a0
20 changed files with 469 additions and 341 deletions

View File

@@ -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,