How to print permutations without itertools and recursive calls ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to print permutations without itertools and recursive calls ?

to achieve this my friend suggested me this logic.. rotate the string and then print it and swap the characters with another.. example : input is "abc" rotating : cab bca abc now swapping the first character with second so now our new string becomes 'bac' again rotating cba acb bac like this i got permutations! but what if the length of the input is greater than 3 ? I tried to achive my goal with 4 length of string with the same logic.. but I am getting 4 duplicate values as output instead of real permutations. how to solve this problem? my attempt : https://code.sololearn.com/cw44n4fGvSWu/?ref=app

10th Sep 2021, 6:38 PM
Ratnapal Shende
Ratnapal Shende - avatar
4 Answers
+ 2
Nick I want all possible permutations...like I described in description.. for "abcd" their are 24 possible permutations (non repeated) nPr=n! ------ (n-r)!
10th Sep 2021, 7:28 PM
Ratnapal Shende
Ratnapal Shende - avatar
11th Sep 2021, 1:23 AM
Slick
Slick - avatar
0
Do you want all the possible combinations or there's certain rules to it?
10th Sep 2021, 7:16 PM
Tim
Tim - avatar