Exemple #1
0
        private static List <Tools.Point> GetPath(string line)
        {
            var path         = new List <Tools.Point>();
            var instructions = line.Split(",");

            Tools.Point refPoint = new Tools.Point(0, 0);
            foreach (var item in instructions)
            {
                path.AddRange(GetPoints(item, refPoint));
                refPoint = path.Last();
            }
            return(path);
        }
Exemple #2
0
        private static List <Tools.Point> GetPoints(string instruction, Tools.Point refPoint)
        {
            var direction = instruction[0];
            var steps     = Int32.Parse(instruction.Substring(1));
            var res       = new List <Tools.Point>();

            switch (direction)
            {
            case 'R':
                for (int i = 1; i <= steps; i++)
                {
                    var newPoint = new Tools.Point(refPoint.X + i, refPoint.Y);
                    res.Add(newPoint);
                }
                break;

            case 'L':
                for (int i = 1; i <= steps; i++)
                {
                    var newPoint = new Tools.Point(refPoint.X - i, refPoint.Y);
                    res.Add(newPoint);
                }
                break;

            case 'U':
                for (int i = 1; i <= steps; i++)
                {
                    var newPoint = new Tools.Point(refPoint.X, refPoint.Y + i);
                    res.Add(newPoint);
                }
                break;

            case 'D':
                for (int i = 1; i <= steps; i++)
                {
                    var newPoint = new Tools.Point(refPoint.X, refPoint.Y - i);
                    res.Add(newPoint);
                }
                break;
            }
            return(res);
        }