2022-12-17 11:57:30 +01:00
|
|
|
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)
|
|
|
|
{
|
2022-12-17 12:31:21 +01:00
|
|
|
field.markNumber("1");
|
2022-12-17 11:57:30 +01:00
|
|
|
field.printField();
|
2022-12-17 12:31:21 +01:00
|
|
|
field.checkBingo();
|
|
|
|
|
2022-12-17 11:57:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void part2()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-17 09:22:51 +01:00
|
|
|
class Field{
|
|
|
|
|
|
|
|
string[,] bingoField = new string[5,5];
|
|
|
|
|
|
|
|
public Field(string[,] bingoField){
|
|
|
|
this.bingoField = bingoField;
|
|
|
|
}
|
|
|
|
public void markNumber(string markNumber){
|
2022-12-17 11:57:30 +01:00
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
for (int j = 0; j < 5; j++)
|
|
|
|
{
|
|
|
|
if (bingoField[i, j].Contains(markNumber))
|
|
|
|
{
|
2022-12-17 12:31:21 +01:00
|
|
|
bingoField[i, j] = $"[X{markNumber}]";
|
2022-12-17 11:57:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-17 12:31:21 +01:00
|
|
|
public bool checkBingo()
|
2022-12-17 11:57:30 +01:00
|
|
|
{
|
|
|
|
bool bingo = false;
|
2022-12-17 12:31:21 +01:00
|
|
|
int counter = 0;
|
|
|
|
int rowNr = 0;
|
|
|
|
int columnNr = 0;
|
|
|
|
|
|
|
|
while( rowNr < 5) {
|
|
|
|
for(int i = 0; i < 5;i++)
|
|
|
|
{
|
|
|
|
if (bingoField[rowNr, i].Contains("X"))
|
|
|
|
{
|
|
|
|
counter++;
|
|
|
|
if (counter == 5)
|
|
|
|
{
|
|
|
|
bingo = true;
|
|
|
|
Console.WriteLine("Bingo");
|
|
|
|
return bingo;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
counter = 0;
|
|
|
|
rowNr++;
|
|
|
|
}
|
|
|
|
while (columnNr < 5)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
if (bingoField[i, columnNr].Contains("X"))
|
|
|
|
{
|
|
|
|
counter++;
|
|
|
|
if (counter == 5)
|
|
|
|
{
|
|
|
|
bingo = true;
|
|
|
|
Console.WriteLine("Bingo");
|
|
|
|
return bingo;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
counter = 0;
|
|
|
|
columnNr++;
|
|
|
|
}
|
|
|
|
return bingo;
|
2022-12-17 11:57:30 +01:00
|
|
|
}
|
|
|
|
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");
|
|
|
|
|
|
|
|
|
2022-12-17 09:22:51 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|