コード例 #1
0
        private async Task AskSubmit(IPuzzleSolution solution, PuzzlePart part, string answer)
        {
            Console.WriteLine("Answer:");
            Console.WriteLine(answer);
            Console.WriteLine($"Submit {part}? y/n");
            if (Console.ReadLine() == "y")
            {
                var result = await _api.SubmitAnswer(solution.Year, solution.Day, part, answer);

                Console.WriteLine(result);
            }
        }
コード例 #2
0
        public async Task Run(IPuzzleSolution solution)
        {
            Console.WriteLine($"# Testing puzzle {solution.Year} - {solution.Day}");
            var input = await _api.LoadInput(solution.Year, solution.Day);

            var inputLines = input.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            try
            {
                if (!solution.Assertions.All(x => x))
                {
                    Console.WriteLine("Assertions failed:");
                    Console.WriteLine(string.Join("\n", solution.Assertions));
                }
                else
                {
                    Console.WriteLine($"All {solution.Assertions.Count} assertions passed");
                }

                var sw = new Stopwatch();
                foreach (var part in new [] { PuzzlePart.Part1, PuzzlePart.Part2 })
                {
                    sw.Restart();
                    var output = part == PuzzlePart.Part1 ?
                                 solution.SolvePart1(inputLines) :
                                 solution.SolvePart2(inputLines);

                    Console.WriteLine(sw.Elapsed.Milliseconds + "ms");

                    await AskSubmit(solution, part, output);
                }
                Console.ReadKey();
            }
            catch (NotImplementedException e)
            {
                Console.WriteLine($"Not all parts implemented yet {e.StackTrace}");
                Console.ReadKey();
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var api    = new PuzzleApi("http://adventofcode.com", new SessionProvider());
            var runner = new SolutionRunner(api);

            var days = new IPuzzleSolution[]
            {
                new Day1(),
                new Day2(),
                new Day3(),
                new Day4(),
                new Day5(),
                new Day6(),
                new Day7(),
                new Day8(),
                new Day9(),
                new Day10(),
                new Day11(),
                new Day12(),
                new Day13(),
                new Day14(),
                new Day15(),
                new Day16(),
                //new Day17(),
                //new Day18(),
                //new Day19(),
                //new Day20(),
                //new Day21(),
                //new Day22(),
                //new Day23(),
                //new Day24(),
                //new Day25(),
            }.ToList();

            //days.ForEach(x => runner.Run(x).Wait());


            runner.Run(days.Last()).Wait();
        }