[Solved] Function for building all subsets


here I m showing you a method which will accept a number list and using that list, it will provide new List.

New list will take care of

  • Alphabetical order of number
  • No duplicate numbers
  • No recurring numbers

you will only need to check your rate’s part of logic to elemental those numbers who have rate less than 50

private static List<int> GetNewList(List<int> numberList)
{
    List<int> newNumList = new List<int>();
    for (int i = 0; i < numberList.Count - 1; i ++)
    {
        for(int j = i+1; j < numberList.Count; j++)
        {
            string number = "";
            foreach (char ch in numberList[j].ToString())
            {
                number = numberList[i].ToString() + ch;

                if (!IsNumRecurring(number))
                {
                    number = String.Concat(number.OrderBy(c => c));
                    int num = int.Parse(number);

                    if (!newNumList.Contains(num))
                        newNumList.Add(num);
                }
            }
        }
    }

    //Now we should check the same thing in reverse order on list.
    for (int i = numberList.Count - 1; i > 0; i--)
    {
        for (int j = i -1; j >= 0; j--)
        {
            string number = "";
            foreach (char ch in numberList[j].ToString())
            {
                number = numberList[i].ToString() + ch;

                if (!IsNumRecurring(number))
                {
                    number = String.Concat(number.OrderBy(c => c));
                    int num = int.Parse(number);

                    if (!newNumList.Contains(num))
                        newNumList.Add(num);
                }
            }
        }
    }
    return newNumList;
}

//here we will check if number is recurring
private static bool IsNumRecurring(string num)
{
    return num.Any(c => num.Where(ch => ch == c).Count() > 1);
}

10

solved Function for building all subsets