svmartin
12/6/2016 - 3:46 PM

combination_vs_permutation.rb

list = [50, 55, 56, 57, 58]
list.combination(3).to_a

# => [[50, 55, 56], [50, 55, 57], [50, 55, 58], [50, 56, 57], 
#   [50, 56, 58], [50, 57, 58], [55, 56, 57], [55, 56, 58], 
#   [55, 57, 58], [56, 57, 58]] 

list2 = [50, 55, 56, 57, 58]
list.permutation(3).to_a

# => [[50, 55, 56], [50, 55, 57], [50, 55, 58], [50, 56, 55], [50, 56, 57], 
#    [50, 56, 58], [50, 57, 55], [50, 57, 56], [50, 57, 58], [50, 58, 55], 
#    [50, 58, 56], [50, 58, 57], [55, 50, 56], [55, 50, 57], [55, 50, 58], 
#    [55, 56, 50], [55, 56, 57], [55, 56, 58], [55, 57, 50], [55, 57, 56], 
#    [55, 57, 58], [55, 58, 50], [55, 58, 56], [55, 58, 57], [56, 50, 55], 
#    [56, 50, 57], [56, 50, 58], [56, 55, 50], [56, 55, 57], [56, 55, 58], 
#    [56, 57, 50], [56, 57, 55], [56, 57, 58], [56, 58, 50], [56, 58, 55], 
#    [56, 58, 57], [57, 50, 55], [57, 50, 56], [57, 50, 58], [57, 55, 50], 
#    [57, 55, 56], [57, 55, 58], [57, 56, 50], [57, 56, 55], [57, 56, 58], 
#    [57, 58, 50], [57, 58, 55], [57, 58, 56], [58, 50, 55], [58, 50, 56], 
#    [58, 50, 57], [58, 55, 50], [58, 55, 56], [58, 55, 57], [58, 56, 50], 
#    [58, 56, 55], [58, 56, 57], [58, 57, 50], [58, 57, 55], [58, 57, 56]]