Beispiel #1
0
        private static Direction GetNextDirection(Direction currentDirection, Point currentPoint, string[] lines)
        {
            foreach (Direction direction in Enum.GetValues(typeof(Direction)))
            {
                if (direction == DirectionHelpers.GetOppositeDirection(currentDirection))
                {
                    continue;
                }

                var upPoint  = DirectionHelpers.GetNextPoint(direction, currentPoint);
                var upLetter = DirectionHelpers.GetLetter(lines, upPoint);
                if (upLetter != ' ')
                {
                    return(direction);
                }
            }

            throw new Exception("wheeeere");
        }
Beispiel #2
0
        public static void Main(string[] args)
        {
            int    steps        = 1;
            string letterString = "";

            var lines = File.ReadAllLines("input.txt");

            Direction currentDirection = Direction.Down;

            var indexOf      = lines[0].IndexOf('|');
            var currentPoint = new Point(indexOf, 0);

            while (true)
            {
                currentPoint = DirectionHelpers.GetNextPoint(currentDirection, currentPoint);
                var letter = DirectionHelpers.GetLetter(lines, currentPoint);

                if (letter == ' ')
                {
                    break;
                }

                if (letter != '+' && letter != '-' && letter != '|')
                {
                    letterString += letter;
                }

                if (letter == '+')
                {
                    currentDirection = GetNextDirection(currentDirection, currentPoint, lines);
                }

                steps++;
            }

            Console.WriteLine(letterString);
            Console.WriteLine(steps);
        }