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