Class: EenieMeenie::Sorters::PickAGroup
- Inherits:
-
Base
- Object
- Base
- EenieMeenie::Sorters::PickAGroup
show all
- Defined in:
- lib/eenie_meenie/sorters/pick_a_group.rb
Instance Method Summary
collapse
Methods inherited from Base
#load_option, #load_options
Constructor Details
#initialize(*args, options) ⇒ PickAGroup
4
5
6
|
# File 'lib/eenie_meenie/sorters/pick_a_group.rb', line 4
def initialize(*args, options)
load_options(:groups, :population, options)
end
|
Instance Method Details
#sort ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/eenie_meenie/sorters/pick_a_group.rb', line 8
def sort
results = {}
@groups.each { |group| results.merge!(group => 0) }
@population.times do |i|
group = @groups.sample
other_group = (@groups - [group]).first
group = other_group if results.values.any? {|v| results[group] > v + rand(10) }
results[group] += 1
end
groups = results
end
|