示例#1
0
        public CircusTower BuildCircusTower()
        {
            // Each person is considered for the top position
            var towerCache = people
                             .Select((person, i) => new { person, i })
                             .ToDictionary(entry => entry.i, entry => CircusTower.With(entry.person));

            // Initially, the longest person is the longest circus tower
            var longestTower = towerCache.Last().Value;

            for (int i = 0; i < people.Count(); i++)
            {
                var person = people.ElementAt(i);

                // Find the longest tower which this person can hold on top of them
                towerCache[i] = FindLongestTowerForIndex(towerCache, i, person);

                if (towerCache[i].TotalHeight > longestTower.TotalHeight)
                {
                    longestTower = towerCache[i];
                }
            }

            return(longestTower);
        }
示例#2
0
        public static CircusTower With(Person person)
        {
            var tower = new CircusTower();

            tower.StackPerson(person);
            return(tower);
        }