Ration your integers and feed the people It is wartime, and rationing is taking place in certain regions of your country. Your cities' region is one such region. The city chooses to give everyone the same amount, but in reality, larger people need more food. Chances are, a 200lb man is going to be eating more than that 7lb baby over there. The city, realizing that some people need more food, hires you, their best computer programmer, to solve the issue. They want you to write a program that will divvy up the food appropriately.

Being a smart programmer, you have developed a formula that gives an approximation of how much someone will eat based on their weight.

EAT = (WEIGHT - 1) / 20 + 1

For example, a 124 pound man will eat 7.125 units of food. Knowing that the food is served in packages of 1, and it would be irrational to cut them up, you can round the food units.

Each day, every person eats that many food units. If somebody goes for five days straight with less than that much food per day, they die of starvation.

You will receive population data in this form: Population*Weight, so if you receive 700*180, you know that their are 700 180lb men in the city. Your city has 100,000 units of food stored away.

For every day your city goes without anyone dying, you get one point. Whoever has the most points wins. Make sure you output how many days your city lasted before someone died.

Here is the input:

1000x90
2500x80
3000x150
2500x200

Edit: So, the rule "For every day your city goes without anyone dying, you get one point" was terribly abused. Rule change here: if anybody dies, then game over. No more counting.
Ruby, 100003 days/points (~274 years), 5 days before someone dies


  For every day your city goes without anyone dying, you get one point.


I shall abuse this rule as much as possible!


  Make sure you output how many days your city lasted before someone died.


Ok, I did. You didn't say anything about that affecting your score.

#input = STDIN.read
input = "1000x90
2500x80
3000x150
2500x200" # temporary debugging tool

food = 100000

input = input.split.map{|x| x.split('x').map &amp;:to_i }
onlyPersonToFeedWeight = input.sort_by! {|a|
  a[1] # weight of person
}.first[1] # find the lightest weighing person
foodForOnePerson =  ((onlyPersonToFeedWeight - 1) / 20.0 + 1).ceil # EAT = (WEIGHT - 1) / 20 + 1

# you can see where this is going

daysNobodyDied = 0
daysSomeoneDied = 0

# first kill off all these overweight people
daysNobodyDied += 4
food -= foodForOnePerson
daysSomeoneDied += 1 # it's only all but one person in the city, don't worry

# I have a good feeling about this now
# ... I'm evil

loop {
  daysNobodyDied += 4
  food -= foodForOnePerson
  if food &gt;= 0
    daysNobodyDied += 1
  else
    daysSomeoneDied += 1
    break
  end
}

puts "Survived for #{daysNobodyDied} days"
puts "There were #{daysSomeoneDied} days in which someone died"
puts "The first person died on day 5"


Output:

Survived for 100003 days
There were 2 days in which someone died
The first person died on day 5


I suggest you read the comments in the code first; they're quite amusing. ;) (Code is intentionally verbose.)

The strategy is simple:


On the first five days, only feed the lightest person (on the fifth day). Then everyone else dies so you don't have to worry about them.
Continue to starve this poor man with no friends or family by only feeding him once every five days until you run out of food.
The man will probably die before you run out of food since it will now last 274 years.


Does this make me evil or something?

Oh, and by the way, if he was lying down the whole time, he'd have a better than even chance that a bird would poop in his mouth. (Assuming the birds didn't starve.) Thanks for the... interesting fact, @Synthetica :-P