Hi,

i have an array declared as {1,2,3,4,5,6,7,8,9};

Now i need to get the all possible Subsets of Array in UIPATH…

TIA

Hi,

i have an array declared as {1,2,3,4,5,6,7,8,9};

Now i need to get the all possible Subsets of Array in UIPATH…

TIA

You can create Invoke Code activity with below code and arguments:

```
Dim n As Int32
Dim i As Int32
Dim j As Int32
Dim counter As Int32
Dim binary As Int32
Dim skipCount As Int32
n = CInt(InputArray.Length)
Dim tempArr(n,CInt(Math.Pow(CDbl(2),CDbl(n)))) as Int32
Dim tempList As System.Collections.Generic.List(Of int32)
OutpuList = New System.Collections.Generic.List(of System.Collections.Generic.List(Of int32))
skipCount = CInt(Math.Pow(CDbl(2),CDbl(n)))
For j=0 To n-1
skipcount=CInt(skipCount/2)
binary = 1
counter = 0
For i=0 To CInt(Math.Pow(CDbl(2),CDbl(n)))-1
temparr(j,i)=binary
counter=(counter + 1) Mod skipCount
If counter = 0 Then
binary = (binary + 1) Mod 2
End If
Next i
Next j
For i=0 To CInt(Math.Pow(CDbl(2),CDbl(n)))-1
tempList = New System.Collections.Generic.List(Of int32)
For j=0 To n-1
If tempArr(j,i)=1 Then
templist.Add(InputArray(j))
End If
Next j
OutpuList.Add(tempList)
Next i
```

Example workflow attached: Main.xaml (7.6 KB)

1 Like

Thanks for the reply,it worked,but i want to know how we do it in uipath(not by invoking the code but using the activities.)and how we get the sum of each subset that’s created?

Invoke Code is an activity

You can translate provided code to activities (loops, if statements and assigns) but it will be unreadable.

Add to for each loop in attached xaml Write line activity to print sum.

1 Like

Hi heynow,

actually i need to Find the sum of subsets from array should equal to input sum

(if i declared an array with {1,2,3,4,5} and input sum as 10,then i need to get (1,2,3,4),(2,3,5),(1,4,5)…), and i am not able to get the output of sum of each subset by using for each activity

Add in for each loop something like this:

If you add it to workflow from my first post then it should work.

1 Like

Thanks, it worked ,

i am trying to translate each and every activity to uipath other activities from ur invoke code…i am stuck at this lines…

**Dim tempArr(n,CInt(Math.Pow(CDbl(2),CDbl(n)))) as Int32**

**skipCount = CInt(Math.Pow(CDbl(2),CDbl(n)))**

how to translate it to uipath activities?

TIA

Its showing error, if u can, please upload the full workflow

TIA