Exemple #1
0
        private KeyValuePair <int, KeyValuePair <int, List <int> > > InitSleepiestGuardInfo()
        {
            return(this.GuardsInfo.Dict
                   .Select(pair =>
            {
                int sleepStart = 0;
                List <int> sleepAmounts = new List <int>();
                List <int> sleepTimes = new List <int>();
                foreach (string sleepString in pair.Value)
                {
                    int sleepNumber = SleepTimeRegex.GetValue(sleepString);
                    if (sleepString.Contains("falls asleep"))
                    {
                        sleepStart = sleepNumber;
                    }
                    else
                    {
                        sleepAmounts.Add(sleepNumber - sleepStart);
                    }
                    sleepTimes.Add(sleepNumber);
                }
                int sleepTotal = sleepAmounts.Sum();

                return new KeyValuePair <int, KeyValuePair <int, List <int> > >(pair.Key, new KeyValuePair <int, List <int> >(sleepTotal, sleepTimes));
            })
                   .OrderByDescending(pair => pair.Value.Key)
                   .ToDictionary(pair => pair.Key, pair => pair.Value)
                   .First());
        }
Exemple #2
0
        private KeyValuePair<int, int> InitSleepiestGuardInfo()
        {
            return this.GuardsInfo.Dict
                .Select(pair =>
                {
                    List<int> sleepTimes = new List<int>();
                    foreach (string sleepString in pair.Value)
                    {
                        sleepTimes.Add(SleepTimeRegex.GetValue(sleepString));
                    }
                    Tuple<int, int> sleepiestMinute = this.SleepiestMinute(sleepTimes);

                    return new KeyValuePair<int, Tuple<int,int>>(pair.Key, sleepiestMinute);
                })
                .OrderByDescending(pair => pair.Value.Item1)
                .ToDictionary(pair => pair.Key, pair => pair.Value.Item2)
                .First();
        }