나는 이렇게 학습한다/Algorithm & SQL

0910. Quarter of the year

daco2020 2022. 9. 10. 23:41
반응형

Given a month as an integer from 1 to 12, return to which quarter of the year it belongs as an integer number.

For example: month 2 (February), is part of the first quarter; month 6 (June), is part of the second quarter; and month 11 (November), is part of the fourth quarter.



Solution:

def quarter_of(month):
    return (lambda x: x%3==0 and x//3 or x//3+1)(month)


Other Solution:

from math import ceil

def quarter_of(month):
    return ceil(month / 3)
def quarter_of(month):
    return (month + 2) // 3
def quarter_of(month):
    return (month-1) // 3 + 1 


반응형

'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글

0912. Fake Binary  (0) 2022.09.13
0911. Add Length  (0) 2022.09.11
0909. Will there be enough space?  (0) 2022.09.09
0908. Sorted? yes? no? how?  (0) 2022.09.08
0907. Count by X  (0) 2022.09.07