Class: Utils::ArrayUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/array_utils.rb

Class Method Summary collapse

Class Method Details

.deep_permute(input, limit) ⇒ Object



17
18
19
# File 'lib/utils/array_utils.rb', line 17

def self.deep_permute(input, limit)
  make_permutations input, limit
end

.make_permutations(list, n = 0, result = [], current = [], limit) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/utils/array_utils.rb', line 5

def self.make_permutations(list, n = 0, result = [], current = [], limit)
  if n == list.length && n == limit
    result.push current
  else
    list[n].each do |item|
      make_permutations list, n + 1, result, [*current, item], limit
    end
  end

  result
end