public async Task <DigitsListData> GetNumbersList(int number) { DigitsListData digitsSum = null; try { digitsSum = new DigitsListData(); int[] chars = GetIndividualDigits(number); int result = AddDigits(chars); while ((result.ToString()).Length > 1) { int[] resultChar = GetIndividualDigits(result); result = AddDigits(resultChar); } digitsSum = new DigitsListData { Digits = number, DigitsSum = result }; } catch (Exception ex) { var msg = ex.Message + "\n" + ex.StackTrace; System.Diagnostics.Debug.WriteLine(msg); } return(digitsSum); }
DigitsListData CheckSumOfDigitsEqualsList(DigitsListData _result, int[] sumShouldBeEquals) { DigitsListData result = null;//new DigitsListData(); if (sumShouldBeEquals != null) { if (sumShouldBeEquals.Length > 0) { foreach (var item in sumShouldBeEquals) { if (_result.DigitsSum == item) { result = _result; } } } else { result = _result; } } else { result = _result; } return(result); }
async Task <List <DigitsListData> > CheckSumOfDigits(int startIndex, int endIndex, int[] sumShouldBeEquals, DigitsOrder digitsOrder = DigitsOrder.Normal, bool isSingleValue = false) { List <DigitsListData> resultsList; resultsList = CheckSumOfDigits(startIndex, endIndex); List <DigitsListData> _resultsList = new List <DigitsListData>(); foreach (var result in resultsList) { /* * if(sumShouldBeEquals != null) * { * _result = (sumShouldBeEquals != null) ? ((sumShouldBeEquals.Count() > 0 ) ? CheckSumOfDigitsEqualsList(result, sumShouldBeEquals) : null) : null; * } * if(_result != null) * { * DigitsListData __result = SettingDigitsInOrder(_result, digitsOrder); * if(__result != null) * { * _resultsList.Add(__result); * } * } */ DigitsListData _result = CheckSumOfDigitsEqualsList(result, sumShouldBeEquals); if (_result != null) { DigitsListData __result = SettingDigitsInOrder(_result, digitsOrder); if (__result != null) { _resultsList.Add(__result); } } } foreach (var item in _resultsList) { System.Diagnostics.Debug.WriteLine("\n Number : " + item.Digits.ToString() + " Final Result : " + item.DigitsSum + "\n"); // Console.WriteLine("\n Number : " + item.Digits.ToString() + " Final Result : " + item.DigitsSum + "\n"); //Console.WriteLine("Number : " + item.Digits.ToString() + " Final Result : " + item.DigitsSum); } Console.WriteLine("Count : " + _resultsList.Count.ToString()); return(_resultsList); }
DigitsListData SettingDigitsInOrder(DigitsListData _result, DigitsOrder digitsOrder) { DigitsListData result = null; if (digitsOrder == DigitsOrder.Normal) { result = _result; } else if (digitsOrder == DigitsOrder.Ascending) { var itemDigits = GetIndividualDigits(_result.Digits); bool isValid = false; for (int i = 0; i < itemDigits.Length; i++) { if (i + 1 <= itemDigits.Length - 1) { if (itemDigits[i] < itemDigits[i + 1]) { isValid = true; } else { isValid = false; } } } if (isValid) { result = _result; } } else if (digitsOrder == DigitsOrder.ExactAscending) { var itemDigits = GetIndividualDigits(_result.Digits); bool isValid = true; for (int i = 0; i < itemDigits.Length; i++) { if (i + 1 <= itemDigits.Length - 1) { if (itemDigits[i] < itemDigits[i + 1]) { //isValid = true; } else { isValid = false; } } } if (isValid) { result = _result; } } else if (digitsOrder == DigitsOrder.ExactAscendingWihAdjacentRepitition) { var itemDigits = GetIndividualDigits(_result.Digits); bool isValid = true; for (int i = 0; i < itemDigits.Length; i++) { if (i + 1 <= itemDigits.Length - 1) { if (itemDigits[i] > itemDigits[i + 1]) { isValid = false; } else { //isValid = true; } } } if (isValid) { result = _result; } } else { result = _result; } return(result); }