Last active
September 9, 2015 19:20
-
-
Save dtenenba/6611dfdeea4f7e3878a1 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
require 'pp' | |
if ARGV.length != 1 | |
puts "usage: #{$0} manifest_file" | |
exit | |
end | |
lines = File.readlines(ARGV.first) | |
lines = lines.find_all{|i| i =~ /^Package: /} | |
lines = lines.map{|i| i.strip.sub /^Package: /, ""} | |
pkgs = lines.sort_by{|word| word.downcase} | |
people = %w(Brian Dan Herve JimH JimJ Martin Val) | |
# puts "There are #{people.length} people." | |
# puts "There are #{pkgs.length} packages." | |
# puts "Each person should get #{pkgs.length / people.length} packages." | |
# puts "With #{pkgs.length % people.length} left over." | |
slices = pkgs.each_slice(pkgs.length / people.length).to_a | |
rem = pkgs.length % people.length | |
if rem > 0 | |
last = slices.pop | |
for item in last | |
slices.last.push item | |
end | |
end | |
# for slice in slices | |
# puts "slice has #{slice.length} elements" | |
# end | |
people.each_with_index do |person, i| | |
slice = slices[i] | |
puts "#{person}: #{slice.first} - #{slice.last}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment