반응형
Kata Task
I have a cat and a dog.
I got them at the same time as kitten/puppy. That was humanYears years ago.
Return their respective ages now as [humanYears,catYears,dogYears]
NOTES:
- humanYears >= 1
- humanYears are whole numbers only
Cat Years
- 15 cat years for first year
- +9 cat years for second year
- +4 cat years for each year after that
Dog Years
- 15 dog years for first year
- +9 dog years for second year
- +5 dog years for each year after that
Solution:
CAT_INTERVAL = 4
DOG_INTERVAL = 5
def human_years_cat_years_dog_years(years):
cat_years = _get_years(CAT_INTERVAL, years)
dog_years = _get_years(DOG_INTERVAL, years)
return [years, cat_years, dog_years]
def _get_years(interval, years):
age_table = {1: 15, 2: 24}
age_table.update({i: (i-2)*interval + 24 for i in range(3, years+1)})
return age_table[years]
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
0921. Sum without highest and lowest number (0) | 2022.09.21 |
---|---|
0920. Difference of Volumes of Cuboids (0) | 2022.09.20 |
0918. Grasshopper - Array Mean (0) | 2022.09.19 |
0917. Largest pair sum in array (0) | 2022.09.17 |
0916. Do you speak "English"? (0) | 2022.09.16 |