Different combinations of an array (C#)

后端 未结 2 1218
遇见更好的自我
遇见更好的自我 2020-12-22 15:31

how can we find out different combination of the elements of an array using c# code. are there any inbuilt library function for this.?

for eg: suppose an array has e

2条回答
  •  北海茫月
    2020-12-22 16:05

    Seemed logic is not absolutely correct as:

    var cnk = comb(new[] { 1, 2, 3, 4 }, 3);
    

    This gives 3 variants, but as a matter of fact it is 4:

    1 2 3
    1 2 4
    1 3 4
    2 3 4
    

    I guess comb is better to be implemented in recursive way.

提交回复
热议问题