본문 바로가기
연습장

Sequences and Series

by anothel 2021. 11. 4.

Have a look at the following numbers.

 n | score
---+-------
 1 |  50
 2 |  150
 3 |  300
 4 |  500
 5 |  750

Can you find a pattern in it? If so, then write a function getScore(n)/get_score(n)/GetScore(n) which returns the score for any positive number n:

int getScore(1) = return 50;
int getScore(2) = return 150;
int getScore(3) = return 300;
int getScore(4) = return 500;
int getScore(5) = return 750;

 

Solution

int getScore(int n) {
  return 25 * (n + 1) * n;
}

 

후기

규칙을 찾는 건 상당히 쉬웠다. 그래도 남의 코드를 보려고 들어가 보니 대부분 나랑 비슷하게 풀었더라.

5 kyu는 너무 어렵고, 6 kyu는 너무 쉽고.. 이거 Codewars에서 난이도 조절을 잘 못하는 게 아닌가 싶다.

 

(url: https://www.codewars.com/kata/5254bd1357d59fbbe90001ec)

 

728x90