AdventOfCode2022/Kalender/day11.cs
2022-12-11 13:27:55 +01:00

83 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace Kalender
{
internal class day11
{
static string file = "../../../Kalender/files/day11.txt";
static string[] input = File.ReadAllLines(file);
static List<Monkey> monkeyList;
public static void part1()
{
var items = input[1].Substring(17).Split(',');
Monkey monkey = new Monkey(items, input[2][23], int.Parse(input[2].Substring(24)), int.Parse(input[3].Substring(input[3].Length -3)), int.Parse(input[4].Substring(input[4].Length -2)), int.Parse(input[5].Substring(input[5].Length -2)));
//Console.WriteLine($"op: {monkey.op}, opnumber: {monkey.operationNumber}, divisibleNumber: {monkey.divisiblNumber}, true:{monkey.trueCase}, false: {monkey.falseCase}");
}
}
class Monkey
{
public List<int> startItems;
public char op;
public int operationNumber;
public int divisiblNumber;
public int trueCase;
public int falseCase;
public Monkey(string[] items, char op, int operationNumber, int divisiblNumber, int trueCase, int falseCase)
{
startItems = new List<int>();
this.op = op;
this.operationNumber = operationNumber;
this.divisiblNumber = divisiblNumber;
this.trueCase = trueCase;
this.falseCase = falseCase;
foreach (var item in items)
{
startItems.Add(int.Parse(item));
}
}
public void test(List<Monkey> mokeyList)
{
foreach(int number in startItems)
{
int newNumber = 0;
switch (op)
{
case '*':
newNumber = number * operationNumber;
break;
case '+':
newNumber = number + operationNumber;
break;
}
if(newNumber % divisiblNumber == 0)
{
mokeyList[trueCase].startItems.Add(newNumber);
}
else
{
mokeyList[falseCase].startItems.Add(newNumber);
}
}
}
}
}