Jump to content

Code Cleanliness Ante Enti


GunturGongura

Recommended Posts

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

  • GunturGongura

    12

  • chaikumar

    11

  • uncertainity

    10

  • puli_keka

    9

ok ya …..kani python lo list untundi..like[1,2,3,5]

subsets are[1],[2]….[1,2,3,5]

e {1} notation ni emantaru python lo?

these flower brackets basically are dictionaries with key and value

Link to comment
Share on other sites

ok ya …..kani python lo list untundi..like[1,2,3,5]

subsets are[1],[2]….[1,2,3,5]

e {1} notation ni emantaru python lo?

these flower brackets basically are dictionaries with key and value

Link to comment
Share on other sites

ok ya …..kani python lo list untundi..like[1,2,3,5]

subsets are[1],[2]….[1,2,3,5]

e {1} notation ni emantaru python lo?

these flower brackets basically are dictionaries with key and value


Entidi
Link to comment
Share on other sites

Entidi


I was driving and accidentally hit reply button.

He just gave an example for output, showing with curly braces.

You can use lists or sets in python to store these subsets and then print them.
Link to comment
Share on other sites

Output: 

 
1,
2,
3,
5,
1, 2,
1, 3,
1, 5,
2, 2,
2, 3,
2, 5,
3, 2,
3, 3,
3, 5,
1, 2, 3,
1, 2, 5,
1, 3, 3,
1, 3, 5,
2, 2, 3,
2, 2, 5,
2, 3, 3,
2, 3, 5,
 
problem enti ante 1,3, 3 kuda printing...aa print statement lo distinct unte ne print cheyi anali..like print[j]< print[j+1[
public void SubSetsMain()
        {
            int[] arr = new int[4]{1,2,3,5};
            int[] printarr = new int[arr.Length];
            int index =0;
            for (int i = 0; i < arr.Length; i++)
            {
                FindSubSets(arr, 0, arr.Length, i, printarr, index);
            }
            Console.ReadLine();
        }

        public void FindSubSets(int[] arr, int start, int end, int numberofelements, int[] printarr, int index)
        {
            if (numberofelements == 0)
            {
                for (int j = 0; j < index; j++)
                    Console.Write(printarr[j] + ", ");
                Console.WriteLine();
                return;
            }
            for(int i = start; i<= end - numberofelements; i++)
            {
                printarr[index] = arr[i];
                FindSubSets(arr, start + 1, end, numberofelements-1, printarr, index + 1);
            }
        }
 
 

given input : {1,2,3,5}

 

subsets are print output:

{1}{2}{3}{5}

{1,2}{1,3}{1,5}{2,3}{2,5}{2,5}{3,5}

{1,2,3}{1,2,5}{1,3,5}{2,3,5}

{1,2,3,5}

================================================

 

sum vishayaniki vosthe .. prathi dhani sum print cheyal anthe.....

 

Link to comment
Share on other sites

×
×
  • Create New...