Advertisement
Woobinda

Feed Pigeons

Jul 15th, 2016
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.46 KB | None | 0 0
  1. """
  2. Я начал кормить одного из голубей. Через минуту прилетело еще два, и еще через минуту прилетело еще три голубя. Затем 4 и так далее (Пр: 1+2+3+4+...). Одной порции корма хватает одному голубю на минуту. В случае если еды не хватает на всех птиц, то сначала едят те голуби, что прилетели ранее. Голуби - это вечно голодные птицы и они будут есть и есть без остановки. Если у меня есть N порций корма, то сколько голубей я смогу покормить хотя бы по разу?
  3. """
  4.  
  5. def checkio(feed):
  6.     bird_count = 1
  7.     new_birds = 1
  8.     while feed > 0:
  9.         feed -= bird_count
  10.         new_birds += 1
  11.         if feed < bird_count + new_birds:
  12.             if feed > bird_count:
  13.                 bird_count += feed - bird_count
  14.             return bird_count
  15.         bird_count += new_birds
  16.     return bird_count
  17.  
  18.  
  19. if __name__ == '__main__':
  20.     #These "asserts" using only for self-checking and not necessary for auto-testing
  21.     assert checkio(1) == 1, "1st example"
  22.     assert checkio(2) == 1, "2nd example"
  23.     assert checkio(5) == 3, "3rd example"
  24.     assert checkio(10) == 6, "4th example"
  25.     assert checkio(10000) == 741, "control test"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement