Possible combinations without repetition
Write a program to accept numbers in an array and from that numbers you have to print all possible combinations ex: if there are 5 numbers as 42163 then output should be like 12346, 12364,12436 and so on. So how to solve this?
show your attempt first
Achintya Raj try to find similar codes in code section , hope you get some idea 👍
For this kind of task you can use python module "itertools", then you can use permutations (as your description is showing) from itertools import permutations lst = [1,2,3,4,6] ... # your code follows here. ...
You want to print all distinct permutations of some number or string. You can see some algorithm for it here: https://www.geeksforgeeks.org/distinct-permutations-string-set-2/ I generally use next_permutation() of C++ stl, sort the string so that you can get lexicographically smallest string and then just keep finding next_permutation() until it returns false(means no next lexicographically greater permutation possible) //see method2 here https://www.geeksforgeeks.org/permutations-of-a-given-string-using-stl/
I haven't tried yet as I am not getting the idea how the nested loops will be used
Those nos which are made using these 5 digits with no repitition
Sorry I want all the combinations I didn't read carefully that time Let me tell u with a small ex. Suppose there are three numbers 2 4 1 then possible combinations for this are : 241,214,412,421,124,142 i.e 6 combinations