Exemplo n.º 1
0
        public static void part1()
        {
            var sum   = 0;
            var lines = Problem08.text();

            foreach (var line in lines)
            {
                sum += line.Count();
                var ptr = 1;
                while (ptr < line.Count() - 1)
                {
                    sum--;
                    if (line[ptr] == '\\')
                    {
                        switch (line[ptr + 1])
                        {
                        case '\\':
                        case '"':
                            ptr++;
                            break;

                        case 'x':
                            ptr += 3;
                            break;
                        }
                    }
                    ptr++;
                }
            }
            Console.WriteLine(sum);
        }
Exemplo n.º 2
0
        public static void part2()
        {
            var sum   = 0;
            var lines = Problem08.text();

            foreach (var line in lines)
            {
                var encodedCharCount = 2;
                foreach (var c in line)
                {
                    switch (c)
                    {
                    case '\\':
                    case '"':
                        encodedCharCount += 2;
                        break;

                    default:
                        encodedCharCount++;
                        break;
                    }
                }
                sum += encodedCharCount - line.Count();
            }
            Console.WriteLine(sum);
        }