First solution in Uncategorized category for Feed Pigeons by pkstarstorm05
# migrated from python 2.7
#The first bird has arrived
#bird is the birds that are already there
bird = 1
#That first bird has also eaten the first piece of food.
number -= 1
#t is the birds that are coming in on the next round
#After the first minute, more birds arrive; one more than arrived last time
t = 2
print("Starting birds: %r" % bird)
print("Starting food: %r" % number)
round = 1
#while there is enough food for the number of birds that are there plus those that are coming in the next wave:
while bird + t <= number:
print("Round %r" % round)
round += 1
#add the newcomming birds to the birds that are already there
bird += t
#Subtract the food that the birds that are already there have eaten
number -= bird
#increase the number of birds that are coming for the next round by one
t += 1
#print out the following updates, then recheck the while loop conditions. If false, skip the while loop code.
print("This is birds coming next round: %r" % t)
print("This is bird: %r" % bird)
print("This is food: %r" % number)
print("Number of birds fed: %r" % bird)
#When the amount of food isn't enough to feed all of the current and incoming birds,
#then we need to feed the birds that are already there first,
#then add on as many new birds as we have food for.
#We only need to add more birds fed IF the amount of foood left over is less than
#the birds already there plus the newcommers, AND is greater than the number of birds already
#there. Otherwise, we're not adding any new birds.
if number > bird:
bird += (number - bird)
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(1) == 1, "1st example"
assert checkio(2) == 1, "2nd example"
assert checkio(5) == 3, "3rd example"
assert checkio(10) == 6, "4th example"
Jan. 8, 2014