44 lines
1.7 KiB
C#
44 lines
1.7 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();
|
|
monkeys[monkeyIndex].MonkeyId = monkeyIndex;
|
|
}
|
|
|
|
for (int monkeyIndex = 0; monkeyIndex < monkeys.Length; monkeyIndex++)
|
|
{
|
|
string[] monkey = monkeyString[monkeyIndex].Split(NewLine);
|
|
int monkeyId = Convert.ToInt32(monkey[0].Remove(monkey[0].Length - 1).Split(' ')[^1]);
|
|
monkeys[monkeyId].Items = monkey[1].Split(':')[^1].Split(',').Select(s => Convert.ToInt32(s.Trim())).ToList();
|
|
string[] operation = monkey[2].Split(' ');
|
|
monkeys[monkeyIndex].SetOperation(operation[^2][0], operation[^1]);
|
|
|
|
monkeys[monkeyIndex].SetTestValue(Convert.ToInt32(monkey[3].Split(' ')[^1]));
|
|
|
|
int trueMonkey = Convert.ToInt32(monkey[4].Split(' ')[^1]);
|
|
int falseMonkey = Convert.ToInt32(monkey[5].Split(' ')[^1]);
|
|
|
|
monkeys[monkeyIndex].SetThrowTargets(monkeys[trueMonkey], monkeys[falseMonkey]);
|
|
}
|
|
|
|
return string.Empty;
|
|
}
|
|
}
|
|
}
|