Пример #1
0
        public static string SolvePart2(string danceMoves, int cycles, string start = "abcdefghijklmnop")
        {
            var dancers = new ArrayThatDancesWoooo(start);
            var counter = 0;

            do
            {
                foreach (var move in danceMoves.Split(','))
                {
                    dancers.Dance(move);
                }

                counter++;
            } while (dancers.ToString() != start && counter < cycles);

            // Completed cycles? We're done.
            if (counter == cycles)
            {
                return(dancers.ToString());
            }

            // Back at the beginning? The answer is in the remainder.
            var cyclesLeft = cycles % counter;

            for (var i = 0; i < cyclesLeft; i++)
            {
                foreach (var move in danceMoves.Split(','))
                {
                    dancers.Dance(move);
                }
            }

            return(dancers.ToString());
        }
Пример #2
0
        public static string SolvePart1(string danceMoves, string start = "abcdefghijklmnop")
        {
            var dancers = new ArrayThatDancesWoooo(start);

            foreach (var move in danceMoves.Split(','))
            {
                dancers.Dance(move);
            }
            return(dancers.ToString());
        }