near soltuion for part 1

This commit is contained in:
marcus@weifer.de 2022-12-17 12:31:21 +01:00
parent 98a749ba8d
commit bdfcff1d84

53
day4.cs
View File

@ -48,8 +48,10 @@ class day4
foreach(Field field in fields) foreach(Field field in fields)
{ {
field.markNumber("13"); field.markNumber("1");
field.printField(); field.printField();
field.checkBingo();
} }
@ -76,19 +78,56 @@ class Field{
{ {
if (bingoField[i, j].Contains(markNumber)) if (bingoField[i, j].Contains(markNumber))
{ {
bingoField[i, j] = $"[-{markNumber}-]"; bingoField[i, j] = $"[X{markNumber}]";
} }
} }
} }
} }
public void checkBingo() public bool checkBingo()
{ {
bool bingo = false; bool bingo = false;
int checkCounter = 0; int counter = 0;
for(int i = 0; i < 5; i++) 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;
} }
public void printField() public void printField()
{ {