Added day 11, created monkey parser
This commit is contained in:
parent
43c01b9db7
commit
389a85869b
@ -3,18 +3,37 @@
|
||||
using AdventOfCodeLibrary._2022;
|
||||
using AdventOfCodeLibrary.Shared;
|
||||
|
||||
string _demoData = @"R 4
|
||||
U 4
|
||||
L 3
|
||||
D 1
|
||||
R 4
|
||||
D 1
|
||||
L 5
|
||||
R 2";
|
||||
string _demoData = @"Monkey 0:
|
||||
Starting items: 79, 98
|
||||
Operation: new = old * 19
|
||||
Test: divisible by 23
|
||||
If true: throw to monkey 2
|
||||
If false: throw to monkey 3
|
||||
|
||||
Answerable answerable = new Day09Part2();
|
||||
Monkey 1:
|
||||
Starting items: 54, 65, 75, 74
|
||||
Operation: new = old + 6
|
||||
Test: divisible by 19
|
||||
If true: throw to monkey 2
|
||||
If false: throw to monkey 0
|
||||
|
||||
Monkey 2:
|
||||
Starting items: 79, 60, 97
|
||||
Operation: new = old * old
|
||||
Test: divisible by 13
|
||||
If true: throw to monkey 1
|
||||
If false: throw to monkey 3
|
||||
|
||||
Monkey 3:
|
||||
Starting items: 74
|
||||
Operation: new = old + 3
|
||||
Test: divisible by 17
|
||||
If true: throw to monkey 0
|
||||
If false: throw to monkey 1";
|
||||
|
||||
Answerable answerable = new Day11Part1();
|
||||
byte[] dataArray = File.ReadAllBytes(answerable.DefaultInputFile);
|
||||
//dataArray = Encoding.UTF8.GetBytes(_demoData);
|
||||
dataArray = Encoding.UTF8.GetBytes(_demoData);
|
||||
|
||||
Console.WriteLine($"Answer: {answerable.GetAnswer(dataArray)}");
|
||||
Console.ReadKey(true);
|
||||
@ -1,5 +1,6 @@
|
||||
namespace AdventOfCodeLibrary._2022
|
||||
{
|
||||
using AdventOfCodeLibrary._2022.Day_11;
|
||||
using AdventOfCodeLibrary.Shared;
|
||||
|
||||
public class Day11Part1 : Answerable
|
||||
@ -10,6 +11,32 @@
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
{
|
||||
internal class Monkey
|
||||
{
|
||||
internal int MonkeyId;
|
||||
|
||||
internal List<int> Items;
|
||||
|
||||
private int TestDevision;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user