added day 11
This commit is contained in:
parent
de2ce7e9b0
commit
43c01b9db7
16
Advent Of Code Library/2022/Day 11/Day11Part1.cs
Normal file
16
Advent Of Code Library/2022/Day 11/Day11Part1.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace AdventOfCodeLibrary._2022
|
||||
{
|
||||
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)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Advent Of Code Library/2022/Day 11/Day11Part2.cs
Normal file
16
Advent Of Code Library/2022/Day 11/Day11Part2.cs
Normal file
@ -0,0 +1,16 @@
|
||||
namespace AdventOfCodeLibrary._2022
|
||||
{
|
||||
using AdventOfCodeLibrary.Shared;
|
||||
|
||||
public class Day11Part2 : Answerable
|
||||
{
|
||||
public override int Year { get; set; } = 2022;
|
||||
public override int Day { get; set; } = 11;
|
||||
public override int Part { get; set; } = 2;
|
||||
|
||||
public override string GetAnswer(byte[] data)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
108
Advent Of Code Library/2022/Day 11/Monkey.cs
Normal file
108
Advent Of Code Library/2022/Day 11/Monkey.cs
Normal file
@ -0,0 +1,108 @@
|
||||
namespace AdventOfCodeLibrary._2022.Day_11
|
||||
{
|
||||
internal class Monkey
|
||||
{
|
||||
internal List<int> Items;
|
||||
|
||||
private int TestDevision;
|
||||
|
||||
private OperationEnum Operation;
|
||||
private int? OperationValue = null;
|
||||
|
||||
private Monkey ThrowTrueMonkey;
|
||||
private Monkey ThrowFalseMonkey;
|
||||
|
||||
internal void DoTurn()
|
||||
{
|
||||
if (!Items.Any())
|
||||
return;
|
||||
|
||||
for (int worryIndex = 0; worryIndex < Items.Count; worryIndex++)
|
||||
{
|
||||
int item = Items[0];
|
||||
item = GetNewWorry(item);
|
||||
ThrowToMonkey(item);
|
||||
}
|
||||
|
||||
Items.Clear();
|
||||
}
|
||||
|
||||
internal int GetNewWorry(int oldWorry)
|
||||
{
|
||||
int secondValue = OperationValue ?? oldWorry;
|
||||
|
||||
switch (Operation)
|
||||
{
|
||||
case OperationEnum.Add:
|
||||
secondValue = oldWorry + secondValue;
|
||||
break;
|
||||
case OperationEnum.Subtract:
|
||||
secondValue = oldWorry - secondValue;
|
||||
break;
|
||||
case OperationEnum.Divide:
|
||||
secondValue = oldWorry / secondValue;
|
||||
break;
|
||||
case OperationEnum.Multiply:
|
||||
secondValue = oldWorry * secondValue;
|
||||
break;
|
||||
}
|
||||
|
||||
return secondValue / 3;
|
||||
}
|
||||
|
||||
internal void ThrowToMonkey(int worry)
|
||||
{
|
||||
if (worry % TestDevision == 0)
|
||||
{
|
||||
ThrowTrueMonkey.Items.Add(worry);
|
||||
}
|
||||
else
|
||||
{
|
||||
ThrowFalseMonkey.Items.Add(worry);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal void SetOperation(char operation, string value)
|
||||
{
|
||||
switch (operation)
|
||||
{
|
||||
case '+': Operation = OperationEnum.Add;
|
||||
break;
|
||||
case '-':
|
||||
Operation = OperationEnum.Subtract;
|
||||
break;
|
||||
case '/':
|
||||
Operation = OperationEnum.Divide;
|
||||
break;
|
||||
case '*':
|
||||
Operation = OperationEnum.Multiply;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!value.Equals("old"))
|
||||
{
|
||||
OperationValue = Convert.ToInt32(value);
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetTestValue(int value)
|
||||
{
|
||||
TestDevision = value;
|
||||
}
|
||||
|
||||
internal void SetThrowTargets(Monkey trueMonkey, Monkey falseMonkey)
|
||||
{
|
||||
ThrowTrueMonkey = trueMonkey;
|
||||
ThrowFalseMonkey = falseMonkey;
|
||||
}
|
||||
}
|
||||
|
||||
internal enum OperationEnum
|
||||
{
|
||||
Add,
|
||||
Subtract,
|
||||
Multiply,
|
||||
Divide
|
||||
}
|
||||
}
|
||||
137
Advent Of Code Library/2022/Day 11/day-11-input.txt
Normal file
137
Advent Of Code Library/2022/Day 11/day-11-input.txt
Normal file
@ -0,0 +1,137 @@
|
||||
addx 1
|
||||
noop
|
||||
addx 2
|
||||
addx 5
|
||||
addx 3
|
||||
noop
|
||||
addx -1
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
noop
|
||||
addx 3
|
||||
noop
|
||||
addx 6
|
||||
addx -4
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
noop
|
||||
addx -32
|
||||
addx 35
|
||||
addx 5
|
||||
addx -31
|
||||
addx 7
|
||||
addx -13
|
||||
addx 2
|
||||
addx 2
|
||||
addx 5
|
||||
addx 6
|
||||
addx -5
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx 2
|
||||
addx -17
|
||||
addx 18
|
||||
addx 5
|
||||
addx 2
|
||||
addx -30
|
||||
addx 31
|
||||
addx 2
|
||||
addx 2
|
||||
addx -32
|
||||
addx -1
|
||||
addx 10
|
||||
addx -8
|
||||
noop
|
||||
noop
|
||||
addx 6
|
||||
addx 16
|
||||
noop
|
||||
addx -11
|
||||
addx 3
|
||||
addx -2
|
||||
addx 3
|
||||
noop
|
||||
addx 6
|
||||
noop
|
||||
addx -2
|
||||
noop
|
||||
addx 7
|
||||
addx 3
|
||||
addx -2
|
||||
addx 4
|
||||
addx -20
|
||||
noop
|
||||
addx -14
|
||||
addx -2
|
||||
addx 6
|
||||
addx 2
|
||||
addx 3
|
||||
noop
|
||||
addx 2
|
||||
addx -1
|
||||
addx 4
|
||||
noop
|
||||
addx 5
|
||||
noop
|
||||
addx 2
|
||||
addx 3
|
||||
addx -2
|
||||
addx 3
|
||||
noop
|
||||
addx 4
|
||||
noop
|
||||
addx 5
|
||||
noop
|
||||
addx 2
|
||||
addx -24
|
||||
addx -15
|
||||
addx 17
|
||||
addx -10
|
||||
addx 2
|
||||
addx -5
|
||||
addx 6
|
||||
noop
|
||||
addx 3
|
||||
addx 2
|
||||
addx 2
|
||||
noop
|
||||
addx 3
|
||||
addx 2
|
||||
addx 5
|
||||
addx -2
|
||||
addx 3
|
||||
addx 2
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx -18
|
||||
addx -19
|
||||
noop
|
||||
addx 1
|
||||
addx 2
|
||||
addx 5
|
||||
addx 3
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx 3
|
||||
noop
|
||||
addx -8
|
||||
addx 11
|
||||
noop
|
||||
noop
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx 3
|
||||
noop
|
||||
addx -34
|
||||
noop
|
||||
Loading…
Reference in New Issue
Block a user