private static int GetTotalSumDoubling(NumberPosition position, int[] ccNumbers)
        {
            int totalSum = 0;

            for (int currentIndex = 0; currentIndex < ccNumbers.Length; currentIndex++)
            {
                if (currentIndex % 2 == (int)position)
                {
                    var currentNum = ccNumbers[currentIndex];
                    var doubledNum = currentNum * 2;

                    if (doubledNum > 9)
                    {
                        int firstInt  = doubledNum / 10;
                        int secondInt = doubledNum % 10;
                        totalSum += (firstInt + secondInt);
                    }
                    else
                    {
                        totalSum += doubledNum;
                    }
                }
                else
                {
                    totalSum += ccNumbers[currentIndex];
                }
            }
            return(totalSum);
        }
예제 #2
0
        private NumberPosition LoadNumberPositionFromXml(SecurityElement element)
        {
            NumberPosition position = new NumberPosition {
                NumberPositionType = TypeNameContainer <_NumberPositionType> .Parse(element.Attribute("NumberPositionType"), 0),
                NeedLevel          = StrParser.ParseDecInt(element.Attribute("NeedLevel"), 0)
            };

            if (element.Children != null)
            {
                foreach (SecurityElement element2 in element.Children)
                {
                    string str;
                    if (((str = element2.Tag) != null) && (str == "NumberWeight"))
                    {
                        NumberWeight item = new NumberWeight {
                            Number = StrParser.ParseDecInt(element2.Attribute("Number"), 0),
                            Weight = StrParser.ParseDecInt(element2.Attribute("Weight"), 0)
                        };
                        position.NumberWeights.Add(item);
                    }
                }
            }
            return(position);
        }