コード例 #1
0
        public Dictionary <int, int> GetAdapterArrayDifferences()
        {
            //< Instantiate the result map with the 'built-in' difference of +3 pre-populated
            var resMap = new Dictionary <int, int>()
            {
                { 3, 1 },
            };

            JoltageAdapter curr = ChargingOutlet;

            for (int i = 0; i < Adapters.Count; i++)
            {
                if (Adapters[i].ConnectsTo(curr))
                {
                    int dJ = Adapters[i].Rating - curr.Rating;
                    if (!resMap.ContainsKey(dJ))
                    {
                        resMap.Add(dJ, 0);
                    }
                    resMap[dJ]++;
                    curr = Adapters[i];
                }
            }

            return(resMap);
        }
コード例 #2
0
        public bool ConnectsTo(JoltageAdapter other)
        {
            int diff = (this.Rating - other.Rating);

            return(diff > 0 && diff <= 3);
        }