static void PartTwo(string input) { var usedSquares = new List <UsedGridCell>(); for (int j = 0; j < 128; j++) { var ba = KnotHash.HashAsBoolArr(input + "-" + j); for (int i = 0; i < 128; i++) { if (ba[i]) { usedSquares.Add(new UsedGridCell(j, i)); } } } int groupId = 0; while (usedSquares.Any(s => !s.Visited)) { usedSquares.First(s => !s.Visited).VisitAdjacent(usedSquares, groupId++); } Console.WriteLine("There are " + groupId + " regions present."); }
static void PartOne(string input) { //for (int j = 0; j < 8; j++) //{ // var ba = KnotHash.HashAsBoolArr(input + "-" + j); // for (int i = 0; i < 8; i++) // { // Console.Write(ba[i] ? '#' : '.'); // } // Console.WriteLine(); //} int numUsed = 0; for (int j = 0; j < 128; j++) { var ba = KnotHash.HashAsBoolArr(input + "-" + j); // Count number of trues, and add to total numUsed += ba.Count(b => b); } Console.WriteLine(numUsed + " squares are used"); }