Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Feed Pigeons by juestr
from itertools import accumulate, count, islice
def checkio(number):
doves_at_minute = lambda n: (n*n + n) // 2
max_total_food_used_series = accumulate(map(doves_at_minute, count(0)))
minute, max_total_food_used = \
next(islice(((n, mtfu) for n, mtfu in enumerate(max_total_food_used_series) if mtfu >= number), 1))
# unique doves fed is either all doves from previous minute, or partial doves fed this minute
return max(doves_at_minute(minute-1), number - max_total_food_used + doves_at_minute(minute))
April 19, 2019
Comments: