-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Guillaume Petit submission, and result.txt file. Ran with Ruby …
…1.9.1
- Loading branch information
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Author : Guillaume Petit | ||
|
||
class Array | ||
|
||
def sum | ||
inject(0.0) { |memo, value| memo + value } | ||
end | ||
|
||
end | ||
|
||
class FairDistribution | ||
|
||
attr_reader :distribution | ||
|
||
def initialize(jobs, nb_of_presses) | ||
@jobs = jobs.sort { |a, b| b <=> a } | ||
@nb_of_presses = nb_of_presses | ||
|
||
@ideal_balance = @jobs.sum / @nb_of_presses | ||
|
||
balance # the real deal | ||
end | ||
|
||
def time_required | ||
@distribution.map { |distrib| distrib.sum }.max | ||
end | ||
|
||
private | ||
|
||
def balance | ||
@distribution = (1..@nb_of_presses).map { [] } | ||
|
||
@jobs.each do |job| | ||
@distribution[find_place_for(job)] << job | ||
end | ||
end | ||
|
||
# try to find a place (distribution) by first looking for an "ideal" place | ||
# and if not found, use the smallest simulated time | ||
def find_place_for(job) | ||
simulated_times = @distribution.map { |distrib| distrib.sum + job } | ||
simulated_times.index(@ideal_balance) || simulated_times.each_with_index.min.last | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
***** FULL TEST REQUESTED ***** | ||
Loaded suite test_solution_acceptance | ||
Started | ||
..... | ||
Finished in 0.000000 seconds. | ||
|
||
5 tests, 8 assertions, 0 failures, 0 errors, 0 skips |