From bdfcff1d846014cd4f12249aa0e4d30f9f91b50f Mon Sep 17 00:00:00 2001 From: "marcus@weifer.de" Date: Sat, 17 Dec 2022 12:31:21 +0100 Subject: [PATCH] near soltuion for part 1 --- day4.cs | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) 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() {