0

Guys, Lets consider i hava two elements like (1,2), then I need to find the number of ways of arrangement of those two elements.

Such as ( 1,1 ) ( 1, 2 ) ( 2, 1 ) ( 2, 2 ) for this kind of output, can any one of help me to write code for it

5th Sep 2022, 1:52 PM
S GOUSE BASHA
S GOUSE BASHA - avatar
5 Answers
+ 4
if youre asking for number of ways then .. if you have only 2 elements then you can just use a straight forward method (thera only 4 possibilities) but if thera n elements array and you want to check all possible combinations . then it will be like 1elem : n 2elem : n² 3eme : n³ ...... so total possibilities n+n²+n³+...+n^n which is a GP . = n(1-n^n)/(1-n)
5th Sep 2022, 2:02 PM
Prashanth Kumar
Prashanth Kumar - avatar
+ 3
you can use itertools, no need to reinvent the wheel. from itertools import product x = (1,2) print(list(product(x, repeat=len(x))))
5th Sep 2022, 5:57 PM
Bob_Li
Bob_Li - avatar
+ 2
S GOUSE BASHA , please show us your try that you have done so far.
5th Sep 2022, 6:20 PM
Lothar
Lothar - avatar
+ 1
I don't know exact logic for that, that's why I haven't try it
9th Sep 2022, 8:01 AM
S GOUSE BASHA
S GOUSE BASHA - avatar
0
Could you tell me how I can implement this concept in Code
5th Sep 2022, 2:12 PM
S GOUSE BASHA
S GOUSE BASHA - avatar