Ejemplo n.º 1
0
        public void FindSolutionToPart2()
        {
            string content;

            using (var stream = new FileStream("Day5/input.txt", FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var reader = new StreamReader(stream);

                content = reader.ReadToEnd();
            }

            var optimizer = new PolymerOptimizer();
            var result    = new List <Tuple <char, int> >();

            var polymer = content.Select(c => c).Where(c => c.IsValidIsotope()).ToList();

            optimizer.Optimize(polymer);

            for (int i = 65; i < 91; i++)
            {
                var isotope           = (char)i;
                var simplifiedPolymer = polymer.Where(c => !isotope.SameType(c)).ToList();

                optimizer.Optimize(simplifiedPolymer);

                result.Add(new Tuple <char, int>(isotope, simplifiedPolymer.Count));
            }

            var min      = result.Select(x => x.Item2).Min();
            var solution = result.Where(x => x.Item2 == min).ToList();

            Assert.That(solution, Has.Count.EqualTo(1));
            Console.WriteLine($"'{solution[0].Item1}' :{solution[0].Item2}");
        }
Ejemplo n.º 2
0
        public string Test1(string polymer)
        {
            var watch     = new Stopwatch();
            var optimizer = new PolymerOptimizer();

            watch.Start();
            var result = optimizer.Optimize(polymer);

            watch.Stop();
            Console.WriteLine(watch.ElapsedTicks);

            return(result);
        }
Ejemplo n.º 3
0
        public void FindSolutionToPart1()
        {
            string content;

            using (var stream = new FileStream("Day5/input.txt", FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                var reader = new StreamReader(stream);

                content = reader.ReadToEnd();
            }

            var optimizer = new PolymerOptimizer();

            var result = optimizer.Optimize(content);

            Console.WriteLine(result.Length);
        }