Esempio n. 1
0
        private static void Day8Part1()
        {
            Console.WriteLine("Day 8, Part 1");
            var charsPerFrame = 25 * 6;
            var chars         = string.Join("", File.ReadAllLines(InputFile8)).Where(char.IsDigit).ToArray();
            var numChars      = chars.Length;
            var offset        = 0;
            List <Tuple <int, int, int> > results = new List <Tuple <int, int, int> >();
            var frame          = new Char[charsPerFrame];
            var minZeroes      = int.MaxValue;
            var indexMinZeroes = int.MaxValue;
            var index          = 0;

            while (offset < numChars)
            {
                Array.Copy(chars, offset, frame, 0, charsPerFrame);
                var zeroes = frame.Count(c => c.Equals('0'));
                var ones   = frame.Count(c => c.Equals('1'));
                var twos   = frame.Count(c => c.Equals('2'));
                var t      = new Tuple <int, int, int>(zeroes, ones, twos);
                results.Add(t);
                offset += charsPerFrame;
                if (zeroes < minZeroes)
                {
                    minZeroes      = zeroes;
                    indexMinZeroes = index;
                }

                index++;
            }

            int product;

            foreach (var result in results)
            {
                product = result.Item2 * result.Item3;
                Console.WriteLine($"Zeroes:{result.Item1}, Ones:{result.Item2}, Twos:{result.Item3}, Product:{product}");
            }

            product = results[indexMinZeroes].Item2 * results[indexMinZeroes].Item3;
            Console.WriteLine($"Minimum zeroes for index: {indexMinZeroes}, with product {product}");

            Console.WriteLine($"No chars {numChars}");
            Console.Write("Hit return to quit");
            Console.ReadLine();
        }
Esempio n. 2
0
        public int CountSafeTiles(string firstRow, int numberOfRows)
        {
            int           rowSize   = firstRow.Length;
            int           safeTiles = 0;
            List <char[]> rows      = new List <char[]>();

            //Add the first row to both the rows list and the count
            rows.Add(firstRow.ToArray());
            safeTiles += firstRow.Count(x => x == '.');

            //Determine the next row as long as the
            while (rows.Count < numberOfRows)
            {
                char[] newRow = new Char[rowSize];
                for (int i = 0; i < newRow.Length; i++)
                {
                    if (IsTrap(rows, rows.Count, i))
                    {
                        newRow[i] = '^';
                    }
                    else
                    {
                        newRow[i] = '.';
                    }
                }
                rows.Add(newRow);
                safeTiles += newRow.Count(x => x == '.');
            }
            Console.WriteLine(rowSize);

            /*foreach (char[] row in rows) {
             *  foreach (char character in row) {
             *      Console.Write(character);
             *  }
             *  Console.WriteLine();
             * }*/
            return(safeTiles);
        }