day 4 work hard

This commit is contained in:
marcus@weifer.de 2022-12-17 11:57:30 +01:00
parent 6160756254
commit 98a749ba8d
3 changed files with 114 additions and 4 deletions

View File

@ -1,4 +1,4 @@
 
using AdventOfCode2021; using AdventOfCode2021;
var day = new day3("day3"); var day = new day4("day4");

99
day4.cs
View File

@ -1,3 +1,67 @@
using System.Diagnostics.Metrics;
using System.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
class day4
{
string[] input;
string[] number = "7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1".Split(',');
public day4(string day)
{
input = getInput(day);
part1();
part2();
}
public string[] getInput(string day)
{
string filepath = $"../../../inputs/{day}.txt";
string[] file = File.ReadAllLines(filepath);
return file;
}
public void part1()
{
List<Field> fields = new List<Field>();
int index = 0 ;
while (index <= input.Length)
{
int rowIndex = 0;
var bingoField = new string[5, 5];
while (rowIndex < 5) {
for(int i = 0; i < 5; i++)
{
bingoField[rowIndex,i] = $"[{input[index + rowIndex].Split(' ',StringSplitOptions.RemoveEmptyEntries)[i]}]";
}
rowIndex++;
}
fields.Add(new Field(bingoField));
index += 6;
}
foreach(Field field in fields)
{
field.markNumber("13");
field.printField();
}
}
public void part2()
{
}
}
class Field{ class Field{
string[,] bingoField = new string[5,5]; string[,] bingoField = new string[5,5];
@ -6,9 +70,38 @@ class Field{
this.bingoField = bingoField; this.bingoField = bingoField;
} }
public void markNumber(string markNumber){ public void markNumber(string markNumber){
int row = 5; for (int i = 0; i < 5; i++)
int columnn = 5; {
for (int j = 0; j < 5; j++)
{
if (bingoField[i, j].Contains(markNumber))
{
bingoField[i, j] = $"[-{markNumber}-]";
}
}
}
}
public void checkBingo()
{
bool bingo = false;
int checkCounter = 0;
for(int i = 0; i < 5; i++)
{
}
}
public void printField()
{
for (int i = 0; i < 5; i++)
{
for(int j = 0; j < 5; j++) {
Console.Write(bingoField[i,j]);
}
Console.WriteLine(" ");
}
Console.WriteLine("\n");
} }
} }

17
inputs/day4.txt Normal file
View File

@ -0,0 +1,17 @@
22 13 17 11 0
8 2 23 4 24
21 9 14 16 7
6 10 3 18 5
1 12 20 15 19
3 15 0 2 22
9 18 13 17 5
19 8 7 25 23
20 11 10 24 4
14 21 16 12 6
14 21 17 24 4
10 16 15 9 19
18 8 23 26 20
22 11 13 6 5
2 0 12 3 7