Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

need to make this into a recursive function

i need to convert this over to a recursive function. the program basically prints out all variations of a string.

def comb(L):          
    for i in range(3):
        for j in range(3):
            for k in range(3):
                  
                # check if the indexes are not
                # same
                if (i!=j and j!=k and i!=k):
                    print(L[i], L[j], L[k])
                      
# Driver Code
comb([1, 2, 3])

output:

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This might get you started:

  • Every permutation of a list can be made by picking a value from the list & putting it at the front of every permutation of what is left in the list after taking that value out. (Note that the "what is left" part is a smaller list than what you started with.)
  • When your list is small enough, it is the only permutation.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading