CodeWars 코딩 문제 2021/01/26 - A disguised sequence (I)

이호현·2021년 1월 26일
0

Algorithm

목록 보기
66/138

[문제]

Given u0 = 1, u1 = 2 and the relation 6unun+1-5unun+2+un+1un+2 = 0 calculate un for any integer n >= 0.

Examples:
Call fcn the function such as fcn(n) = un.

fcn(17) -> 131072; fcn(21) -> 2097152

Remark:
You can take two points of view to do this kata:

  • the first one purely algorithmic from the definition of un

  • the second one - not at all mandatory, but as a complement - is to get a bit your head around and find which sequence is hidden behind un.

(요약) 2n제곱을 return.

[풀이]

function fcn (n) {
  return Math.pow(2, n);
}

주어진 방정식에 1, 2번 째 값을 대입해보니 4가 나옴.
혹시나 싶어서 한 번 더 해보니 8이 나옴.
2n제곱을 구하는 거겠구나 싶어서 바로 함.

profile
평생 개발자로 살고싶습니다

0개의 댓글