Skip to content

Instantly share code, notes, and snippets.

@GuillermoPena
Created May 28, 2014 11:32
Show Gist options
  • Save GuillermoPena/f591b35f8c6e8def5e6e to your computer and use it in GitHub Desktop.
Save GuillermoPena/f591b35f8c6e8def5e6e to your computer and use it in GitHub Desktop.
CheckIO - Home Challenge 7 : Feed Pingeons
# CheckIO - Home Challenge 7 : Feed Pingeons
# http://checkio.org
# I start to feed one of the pigeons.
# A minute later two more fly by and a minute after that another 3.
# Then 4, and so on (Ex: 1+2+3+4+...).
# One portion of food lasts a pigeon for a minute, but in case there's not enough food for all the birds,
# the pigeons who arrived first ate first.
# Pigeons are hungry animals and eat without knowing when to stop.
# If I have N portions of bird feed, how many pigeons will be fed with at least one portion of wheat?
# Input: A quantity of portions wheat as a positive integer.
# Output: The number of fed pigeons as an integer.
# Precondition: 0 < N < 105.
def checkio(food):
pingeons=0
increment=0
fed=0
while food>fed:
increment+=1
pingeons+=increment
fed=min(pingeons,food)
food-=pingeons
return fed
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert checkio(1) == 1, "1st example"
assert checkio(2) == 1, "2nd example"
assert checkio(5) == 3, "3rd example"
assert checkio(10) == 6, "4th example"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment