Пример #1
0
        /// <summary>
        /// Gets the number of steps to come out from maze.
        /// </summary>
        /// <param name="steps">The steps.</param>
        /// <returns>Step count.</returns>
        public static int GetNumberOfStepsToComeOutFromMaze(int[] steps, PuzzlePart part = PuzzlePart.One)
        {
            int stepCount       = 0;
            int currentPosition = 0;

            while (currentPosition < steps.Count())
            {
                int previousLocation = currentPosition;

                currentPosition += steps[currentPosition];

                if (part == PuzzlePart.Two && steps[previousLocation] > 2)
                {
                    steps[previousLocation] = steps[previousLocation] - 1;
                }
                else
                {
                    steps[previousLocation] = steps[previousLocation] + 1;
                }

                stepCount++;
            }

            return(stepCount);
        }
Пример #2
0
        /// <summary>
        /// Gets the number of steps to come out from maze.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <returns>step count.</returns>
        public static int GetNumberOfStepsToComeOutFromMaze(string fileName, PuzzlePart part = PuzzlePart.One)
        {
            string path = ReadFromTextFile.GetFilePath(fileName);

            string[] dataString = ReadFromTextFile.GetAllLines(path);
            int[]    data       = dataString.Select(int.Parse).ToArray();

            return(GetNumberOfStepsToComeOutFromMaze(data, part));
        }
Пример #3
0
        /// <summary>
        /// The application entry point
        /// </summary>
        /// <param name="args">The command line arguments</param>
        /// <remarks>
        /// This method is used for profiling individual tests that are not performing well.
        /// </remarks>
        static void Main(string[] args)
        {
            // Set the puzzle and part to run here
            var        instance = new Puzzles.Year2020.Day22CrabCombat();
            PuzzlePart part     = instance.Part2_PuzzleInput;

            // Log what is being run and invoke it
            Console.WriteLine($"Executing {instance.GetType().FullName} {part.GetMethodInfo().Name}");
            part.Invoke();
        }
Пример #4
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);
            }
        }
Пример #5
0
        public async Task <string> SubmitAnswer(int year, int day, PuzzlePart part, string answer)
        {
            var puzzleUrl = GetPuzzleUrl(year, day);

            var content = new FormUrlEncodedContent(new []
            {
                new KeyValuePair <string, string>("level", ((int)part).ToString()),
                new KeyValuePair <string, string>("answer", answer),
            });

            var sessionId = await _sessionProvider.GetSessionToken();

            _client.DefaultRequestHeaders.Add("Cookie", $"session={sessionId}");

            var response = await _client.PostAsync($"{puzzleUrl}/answer", content);

            var body = await response.Content.ReadAsStringAsync();

            var result = _answerText.Match(body).Groups[1].Value;

            return(result);
        }