Пример #1
0
        private static int[] GetSum(string onlyNumbersValue)
        {
            int[] sums = new int[] { 0, 0 };
            int   value;

            for (int i = 0; i < 9; i++)
            {
                value    = int.Parse(onlyNumbersValue[i].ToString());
                sums[0] += value * CpfRule.CalculateBeforeLastDigitWeight(i);
                sums[1] += value * CpfRule.CalculateLastDigitWeight(i);
            }

            sums[1] += GetTenthDigit(onlyNumbersValue) * 2;

            return(sums);
        }
Пример #2
0
        private static int[] GenerateNumbers(State state)
        {
            List <int> generatedNumbers = new List <int>();

            int totalBeforeLastDigit = 0;
            int totalLastDigit       = 0;

            for (int i = 0; i < 9; i++)
            {
                generatedNumbers.Add(i < 8 ? _random.Next(10) : (int)state);
                totalBeforeLastDigit += generatedNumbers[generatedNumbers.Count - 1] * CpfRule.CalculateBeforeLastDigitWeight(i);
                totalLastDigit       += generatedNumbers[generatedNumbers.Count - 1] * CpfRule.CalculateLastDigitWeight(i);
            }

            generatedNumbers.Add(CalculateDigitValue(totalBeforeLastDigit));
            totalLastDigit += generatedNumbers[generatedNumbers.Count - 1] * 2;

            generatedNumbers.Add(CalculateDigitValue(totalLastDigit));

            return(generatedNumbers.ToArray());
        }