Beispiel #1
0
        private static void Run(char[] progs, string[] input, bool logToConsole)
        {
            var lineup = new Lineup(progs);
            var data   = input.Where(l => !string.IsNullOrWhiteSpace(l)).Select(l => Parse(lineup, l)).ToArray();

            _shouldLogToConsole = false;

            var       dance      = data[0];
            const int iterations = 1_000_000_000;

            for (var i = 0; i < iterations; i++)
            {
                if ((i % 1_000_000) == 0)
                {
                    System.Console.WriteLine(i);
                }
                foreach (var instruction in dance)
                {
                    instruction.Dance();
                }
            }
            var result = lineup.Dancers.OrderBy(d => d.Position).Select(d => d.Name).ToArray();

            Console.WriteLine(string.Join("", result));
        }
Beispiel #2
0
        private static IDanceInstruction[] Parse(Lineup lineup, string line)
        {
            return(line.Split(",")
                   .Select(inst =>
            {
                switch (inst[0])
                {
                case 's':
                    return (IDanceInstruction) new Spin(lineup, int.Parse(inst.Substring(1)));

                case 'x':
                    var split = inst.Substring(1).Split("/");
                    return new Exchange(lineup, int.Parse(split[0]), int.Parse(split[1]));

                case 'p':
                    return new Partner(lineup, inst[1], inst[3]);

                default:
                    throw new Exception($"I have no idea what to do with {inst}");
                }
            }).ToArray());
        }
Beispiel #3
0
 public Partner(Lineup lineup, char first, char second)
 {
     this.First  = lineup.Dancers.First(d => d.Name == first);
     this.Second = lineup.Dancers.First(d => d.Name == second);
 }
Beispiel #4
0
 public Exchange(Lineup lineup, int position1, int position2)
 {
     this.Position1 = position1;
     this.Position2 = position2;
     this.Lineup    = lineup;
 }
Beispiel #5
0
 public Spin(Lineup lineup, int steps)
 {
     this.Lineup = lineup;
     this.Steps  = steps;
 }