コード例 #1
0
        static void Main(string[] args)
        {
            var idsFile     = args[0];
            var inputStream = new StreamReader(idsFile);
            var checkSum    = IDSummer.CalculateSumOfIds(inputStream);

            System.Console.WriteLine($"Checksum: {checkSum}");

            inputStream = new StreamReader(idsFile);
            string letters = null;

            if (!IDFinder.FindSimilar(inputStream, out letters))
            {
                System.Console.Error.WriteLine("Error: Could not find similar IDs");
            }
            System.Console.WriteLine($"Common characters: {letters}");
        }
コード例 #2
0
        public static uint CalculateSumOfIds(TextReader inputStream)
        {
            uint doubles = 0;
            uint triples = 0;

            while (true)
            {
                var line = inputStream.ReadLine();
                if (line == null)
                {
                    break;
                }
                var rowSum = IDSummer.IDSum(line);
                if (rowSum.hasDoubles)
                {
                    doubles += 1;
                }
                if (rowSum.hasTriples)
                {
                    triples += 1;
                }
            }
            return(doubles * triples);
        }