0
Ruby - What exactly "combination" does?
c = [1,2,3,4].combination(4) puts c.to_a
3 Answers
+ 11
Paolo De Nictolis
Have you ever heard about permutation and combination in mathematics. Same that combination is used here which create combination of defined side as you have defines 4 as size here and all 4 elements can make one combination so for understanding the concept try to create combination of size 2 or 3 like this way.
a = [1, 2, 3, 4]
puts "combination a : #{a.combination(2).to_a}\n\n"
b = [1, 2, 3, 4]
puts "combination b : #{b. combination(3).to_a}\n\n"
c = [1,2,3,4].combination(4)
puts c.to_a
d = [1, 2, 3, 4].combination(3)
puts d.to_a
https://code.sololearn.com/c2y8wS8w559K/?ref=app
+ 9
Paolo De Nictolis what you are assuming is permutations not combination. Here is an example of permutations which are 24 for 4 length list. Which is factorial (n!) Where n is the length or size of list
https://code.sololearn.com/cbCY86XcFJ7C/?ref=app
0
Just about I heard about.... There are 24 combinations of four elements!