46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
namespace AdventOfCodeLibrary._2022
|
|
{
|
|
using AdventOfCodeLibrary._2022.Day_11;
|
|
using AdventOfCodeLibrary.Shared;
|
|
|
|
public class Day11Part1 : Answerable
|
|
{
|
|
public override int Year { get; set; } = 2022;
|
|
public override int Day { get; set; } = 11;
|
|
public override int Part { get; set; } = 1;
|
|
|
|
public override string GetAnswer(byte[] data)
|
|
{
|
|
string[] monkeyString = GetAsString(data).Split(NewLine + NewLine);
|
|
|
|
Monkey[] monkeys = new Monkey[monkeyString.Length];
|
|
|
|
for (int monkeyIndex = 0; monkeyIndex < monkeys.Length; monkeyIndex++)
|
|
{
|
|
monkeys[monkeyIndex] = new(monkeyIndex, 3, monkeyString[monkeyIndex].Split(NewLine));
|
|
}
|
|
|
|
for (int monkeyIndex = 0; monkeyIndex < monkeys.Length; monkeyIndex++)
|
|
{
|
|
string[] monkey = monkeyString[monkeyIndex].Split(NewLine);
|
|
int trueMonkey = Convert.ToInt32(monkey[4].Split(' ')[^1]);
|
|
int falseMonkey = Convert.ToInt32(monkey[5].Split(' ')[^1]);
|
|
|
|
monkeys[monkeyIndex].SetThrowTargets(monkeys[trueMonkey], monkeys[falseMonkey]);
|
|
}
|
|
|
|
for(int round = 0; round < 20; round++)
|
|
{
|
|
for (int monkey = 0; monkey < monkeys.Length; monkey++)
|
|
{
|
|
monkeys[monkey].DoTurn();
|
|
}
|
|
}
|
|
|
|
long[] mostInspects = monkeys.Select(m => m.TotalInspections).OrderByDescending(i => i).Take(2).ToArray();
|
|
|
|
return $"{mostInspects[0] * mostInspects[1]}";
|
|
}
|
|
}
|
|
}
|