Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Using sympy module. Not optimal at all. solution in 3rd party category for Feed Pigeons by quarkov
from sympy import Eq, solveset, symbols
'''
The point of this solution is to avoid loop, so it is fast for big n-s.
Sequence of the pigeons amount for the every minute is 1, 3, 6, 10, 15 ...
It's the triangular numbers sequence, which is a(i) = (i+1)*i/2
Sequence of the fed pigeons for the every minute is 1, 4, 10, 20, 35 ...
It's the tetrahedral numbers sequence, which is a(i) = i*(i+1)*(i+2)/6.
Put a(i) = n (amount of the wheat portions)
Get the cubic equation: i*(i+1)*(i+2) - 6*n = 0 which is possible to solve.
'''
def checkio(n):
number = 6*n
x = symbols('x')
minute = list(solveset(Eq(x**3+3*x**2+2*x-number), x))[0].evalf()//1+1
last_pigeons = (minute-1)*minute/2
last_feed = (minute**2 - 1)*minute / 6
if n - last_feed > last_pigeons:
last_pigeons = n - last_feed
return int(last_pigeons)
June 24, 2018
Comments: