Exemple #1
0
 public bool Equals(House h2)
 {
     return (this.X == h2.X) && (this.Y == h2.Y);
 }
Exemple #2
0
        public List<House> Run(string commands)
        {
            List<House> visited = new List<House>();

            visited.Add(new House(0, 0));
            House currentHouse = new House(0, 0);

            foreach (char command in commands)
            {
                if (command == '<')
                {
                    currentHouse.X--;
                }
                else if (command == '>')
                {
                    currentHouse.X++;
                }
                else if (command == '^')
                {
                    currentHouse.Y++;
                }
                else if (command == 'v')
                {
                    currentHouse.Y--;
                }
                else
                {
                    throw new Exception(String.Format("Santa didn't know how to {0}. In his confusion the sleigh exploded. Congratulations you killed Santa, you monster.", command));
                }

                if (!visited.Contains(currentHouse))
                {
                    visited.Add(new House(currentHouse.X, currentHouse.Y));
                }
            }

            return visited;
        }