Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
DP solution in Speedy category for Feed Pigeons by spoty
def checkio(w, c=0, i=1):
while w > c:
w, c, i = w - c, c + i, i + 1
return max(c - i + 1, w)
# w - wheat
# c - pigeons at the place
# i - incoming pigeons
#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"
July 29, 2014
Comments: