0

I'm trying to convert this Python function, which uses the itertools library, to VB.Net:

permutations = itertools.product('ab', repeat=3)

The above function returns all permutations:

[['a','a','a'],
 ['a','a','b'],
 ['a','b','a'],
 ['a','b','b'],
 ['b','a','a'],
 ['b','a','b'],
 ['b','b','a'],
 ['b','b','b']]

Is there a nice clean way to do this in VB.Net?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
razz
  • 9,770
  • 7
  • 50
  • 68

2 Answers2

1

The answer to your question, if I'm not mistaken. - https://stackoverflow.com/a/21090635/2319909

Community
  • 1
  • 1
Sam Makin
  • 1,526
  • 8
  • 23
0

I ended up converting the python itertools.product function to vb.net:

Function Permute (chars As List (Of Char), len As Integer) As List (Of List (Of Char))
    Dim pools As New List (Of List (Of Char))
    Dim result As New List (Of List (Of Char)) From {New List (Of Char)}
    For i = 0 To len - 1
        pools.Add (chars)
    Next
    For Each pool As List (Of Char) In pools
        Dim result2 As New List (Of List (Of Char))
        For Each x In result
            For Each y In pool
                Dim temp As New List (Of Char)(x)
                temp.Add (y)
                result2.Add (temp)
            Next
        Next
        result = New List (Of List (Of Char))(result2)
    Next
    Return result
End Function
razz
  • 9,770
  • 7
  • 50
  • 68