Esempio n. 1
0
        static void Test()
        {
            var test = "turn off 660,55 through 986,197";

            var range = LightInstruction.Parse(test);

            Debug.Assert(range.Mode == Mode.Off);
            Debug.Assert(range.From.X == 660);
            Debug.Assert(range.From.Y == 55);
            Debug.Assert(range.To.X == 986);
            Debug.Assert(range.To.Y == 197);
        }
Esempio n. 2
0
        public void Parse(IEnumerable <string> commands)
        {
            foreach (var line in commands)
            {
                var lightInstruction = LightInstruction.Parse(line);

                for (int y = lightInstruction.From.Y; y <= lightInstruction.To.Y; y++)
                {
                    for (int x = lightInstruction.From.X; x <= lightInstruction.To.X; x++)
                    {
                        ChangeLight(x, y, lightInstruction.Mode);
                    }
                }
            }
        }
Esempio n. 3
0
        public void ParseSlowlyUsingLinq(IEnumerable <string> commands)
        {
            foreach (var line in commands)
            {
                var lightInstruction = LightInstruction.Parse(line);

                // NOTE: slower than the array version in Parse()
                this.Where(lightInstruction.Contains)
                .ToList()
                .ForEach(light => light.ChangeLight(lightInstruction.Mode));

                // NOTE: slower than the ToList() version
                // .AsParallel()
                // .ForAll(l => l.ChangeLight(lightInstruction.Mode));
            }
        }