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

@@ -51,9 +51,9 @@ public class Monkey
// Divide worry level by 3 before test
if (divideWorry)
{
newValue = newValue / 3;
newValue = newValue / 3;
}
// Even using this simplification, it's still needed to use longs because
// they sometime overflow before being simplified in part 2
newValue = newValue % (2*3*5*7*11*13*17*19);
@@ -77,7 +77,7 @@ public class Day11 : Day
{
public override int Number => 11;
public override string Name => "Monkey in the Middle";
public override void RunPart1()
public override void RunPart1(bool display = true)
{
const int roundsCount = 20;
@@ -95,10 +95,13 @@ public class Day11 : Day
var topMonkeys = monkeys.OrderByDescending(m => m.InspectionCount).Take(2).ToList();
AnsiConsole.MarkupLine($"[green]Monkey business: [yellow]{topMonkeys[0].InspectionCount * topMonkeys[1].InspectionCount}[/][/]");
if (display)
{
AnsiConsole.MarkupLine($"[green]Monkey business: [yellow]{topMonkeys[0].InspectionCount * topMonkeys[1].InspectionCount}[/][/]");
}
}
public override void RunPart2()
public override void RunPart2(bool display = true)
{
const int roundsCount = 10_000;
@@ -116,7 +119,10 @@ public class Day11 : Day
var topMonkeys = monkeys.OrderByDescending(m => m.InspectionCount).Take(2).ToList();
AnsiConsole.MarkupLine($"[green]Monkey business: [yellow]{topMonkeys[0].InspectionCount * topMonkeys[1].InspectionCount}[/][/]");
if (display)
{
AnsiConsole.MarkupLine($"[green]Monkey business: [yellow]{topMonkeys[0].InspectionCount * topMonkeys[1].InspectionCount}[/][/]");
}
}
private static IImmutableList<Monkey> ParseMonkeys()