Skip to content

Instantly share code, notes, and snippets.

@inossidabile
Created January 7, 2013 20:47
Show Gist options
  • Save inossidabile/4478244 to your computer and use it in GitHub Desktop.
Save inossidabile/4478244 to your computer and use it in GitHub Desktop.
create_shortage = ->
shortage = 0
percents.each (x, i) ->
if x < 15
percents[i] = 15
shortage += 15 - x
shortage
spread_shortage = (bigs, shortage) ->
filler = bigs.sum()
percents.each (x, i) ->
return unless x > 15
percents[i] = x - x/filler*shortage
while (bigs = percents.findAll (x) -> x > 15).length > 0 && (shortage = create_shortage()) > 0
spread_shortage(bigs, shortage)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment