본문 바로가기

Python_Matter/Solve

Python Learn the basics Quiz 79

반응형

Q>

Nicola takes a moment to study the ghosts.

(니콜라는 잠시 유령을 연구합니다.)

He is trying to think up a new method to determine just how old these ghosts are.

(그는이 유령이 몇 살인지를 결정하는 새로운 방법을 생각하려고합니다.)

He knows that their age is somehow related to their opacity.

(그는 자신의 나이가 어떻게 든 불투명도와 관련이 있음을 알고 있습니다.)

To measure their opacity Nikola uses a scale of 10000 units to 0 units, where 10000 is a completely opaque newborn ghost (0 years old) and 0 is completely transparent ghost (of an unknown age).

(그들의 불투명도를 측정하기 위해 Nikola는 10000 단위를 0 단위로 사용합니다. 여기서 10000은 완전히 불투명 한 신생아 유령 (0 세)이고 0은 완전히 알려지지 않은 시대의 유령입니다.)

After some experimenting, Nikola thinks he has discovered the law of ghostly opacity.

(몇 번의 실험 끝에 니콜라는 유령 같은 불투명의 법칙을 발견했다고 생각합니다.)

On every birthday, a ghost's opacity is reduced by a number of units equal to its age when its age is a Fibonacci number (Read about this here) or increased by 1 if it is not.

(매 생일마다, 유령의 불투명도는 연령이 피보나치 수 (이 부분에 대해 읽음)이거나 그렇지 않은 경우 1 씩 증가하는 나이와 같은 수의 단위로 축소됩니다.)

For example:


A newborn ghost -- 10000 units of opacity.
1 year -- 10000 - 1 = 9999 (1 is a Fibonacci number).
2 year -- 9999 - 2 = 9997 (2 is a Fibonacci number).
3 year -- 9997 - 3 = 9994 (3 is a Fibonacci number).
4 year -- 9994 + 1 = 9995 (4 is not a Fibonacci number).
5 year -- 9995 - 5 = 9990 (5 is a Fibonacci number).

 

Help Nicola write a function which will determine the age of a ghost based on its opacity.

(Nicola가 유령의 불투명도를 기준으로 유령의 나이를 결정하는 함수를 작성하도록 도와줍니다.)

You are given opacity measurements as a number ranging from 0 to 10000 inclusively.

(0에서 10000 범위의 숫자로 불투명도 측정 값이 제공됩니다.)

The ghosts cannot be older than 5000 years as they simply disappear after such a long time (really!).

(유령은 오랜 시간이 지나면 사라지는 것처럼 5000 년이 넘을 수 없습니다 (실제로!).)

This is a Halloween task so you should try and write a "magic" or "scary" solution.

(이것은 할로윈 과제이므로 "마법"또는 "무서운"해법을 시도하고 작성해야합니다.)

Please, do not write "regular" solution.

(제발, "일반"솔루션을 작성하지 마십시오.)

 

Input: An opacity measurement as an integer.

 

 

Output: The age of the ghost as an integer.

 

 

Example:

checkio(10000) == 0
checkio(9999) == 1
checkio(9997) == 2
checkio(9994) == 3
checkio(9995) == 4
checkio(9990) == 5

 

How it is used: This task was made for some spooky fun! We hope to see your funny, tricky and creative solutions!

                     (이 작업은 재미있는 재미로 만들어졌습니다! 우리는 당신의 재밌고 까다 롭고 창의적인 솔루션을 기대합니다!)

 

Precondition:
age < 5000
0 < opacity ≤ 10000

 

A>

# 피보나치 수열
def checkio(opacity):
    a, b = 1, 1
    age = 0

    while opacity != 10000:
        age += 1
        if age == b:
            opacity += b
            a, b = b, a + b
        else:
            opacity -=1

    return age

#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
    assert checkio(10000) == 0, "Newborn"
    assert checkio(9999) == 1, "1 year"
    assert checkio(9997) == 2, "2 years"
    assert checkio(9994) == 3, "3 years"
    assert checkio(9995) == 4, "4 years"
    assert checkio(9990) == 5, "5 years"

 

O>

 

S>

https://py.checkio.org

반응형

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

Python Learn the basics Quiz 81  (0) 2019.06.20
Python Learn the basics Quiz 80  (0) 2019.06.20
Python Learn the basics Quiz 78  (0) 2019.06.20
Python Learn the basics Quiz 77  (0) 2019.06.20
Python Learn the basics Quiz 76  (0) 2019.06.20