본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 69

반응형

Q>

I start to feed one of the pigeons.

(나는 비둘기 중 하나를 먹이기 시작한다.)

A minute later two more fly by and a minute after that another 3.

(1 분 후 2 분이 지나면 3 분이 지나고 1 분 후에 다시 날아간다.)

Then 4, and so on (Ex: 1+2+3+4+...).

(그 다음 4 분 (예 : 1 + 2 + 3 + 4 + ...).)

One portion of food lasts a pigeon for a minute, but in case there's not enough food for all the birds, the pigeons who arrived first ate first.

(음식의 일부분은 1 분 동안 비둘기를 계속합니다. 그러나 모든 새들을위한 음식이 충분하지 않은 경우 먼저 도착한 비둘기가 먼저 먹었습니다.)

Pigeons are hungry animals and eat without knowing when to stop.

(비둘기는 배고픈 동물이며 언제 멈출 지 모릅니다.)

If I have Nportions of bird feed, how many pigeons will be fed with at least one portion of wheat?

(내가 새끼 사료를 ​​N 개 가지고 있다면 밀의 적어도 일부분을 얼마나 많은 비둘기에 먹일 수 있을까요?)

 

Input: A quantity of portions wheat as a positive integer.

         (밀의 양을 양의 정수로 나타냅니다.)

 

Output: The number of fed pigeons as an integer.

           (비둘기 수를 정수로 나타냅니다.)

 

Example:

checkio(1) == 1
checkio(2) == 1
checkio(5) == 3
checkio(10) == 6

 

How it is used: This task illustrates how we can model various situations.

                     (이 작업은 다양한 상황을 모델링 할 수있는 방법을 보여줍니다.)

                     Of course, the model has a limited approximation, but often-times we don't need a perfect model.

                     (물론 모델에는 근사값이 제한되어 있지만 종종 완벽한 모델이 필요하지 않습니다.)

 

Precondition: 0 < N < 105.

 

A>

def checkio(number):
    pidgeons=0    
    i=1
    while True:
        if number<=pidgeons:
            return pidgeons
        pidgeons+=i
        if number<pidgeons:
            return number     
        number-=pidgeons
        i+=1
        
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"

 

O>


Process finished with exit code 0

 

S>

https://py.checkio.org/

반응형

'Python_Matter > Solve' 카테고리의 다른 글

Python Learn the basics Quiz 71  (0) 2019.06.17
Python Learn the basics Quiz 70  (0) 2019.06.15
Python Learn the basics Quiz 68  (0) 2019.06.15
Python Learn the basics Quiz 67  (0) 2019.06.14
Python Learn the basics Quiz 66  (0) 2019.06.14