Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Feed Pigeons by Franky
def checkio(number):
num_pig_eachmin = 1
pigs_eaten = []
while number:
pigs_eaten += [0]*num_pig_eachmin
num_pig_eachmin += 1
number-=len(pigs_eaten)
if number <= 0 :
for index in range(0,len(pigs_eaten) - abs(number)):
pigs_eaten[index]+=1
break
else:
pigs_eaten = [pig_eaten + 1 for pig_eaten in pigs_eaten]
return len([pig_eaten for pig_eaten in pigs_eaten if pig_eaten > 0])
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"
Dec. 13, 2015