Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Elegant solution in Clear category for Feed Pigeons by FlorisLambrechts
def checkio(wheat):
pigeons = new_pigeons = max_fed = 0
while wheat > 0:
new_pigeons += 1
pigeons += new_pigeons
# throw wheat
fed = min(wheat, pigeons)
wheat -= fed
# bookkeeping
max_fed = max(fed, max_fed)
return max_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"
Feb. 20, 2015
Comments: