λ¬Έμ 1
νΌλ³΄λμΉ μλ F(0) = 0, F(1) = 1μΌ λ, 2 μ΄μμ nμ λνμ¬ F(n) = F(n-1) + F(n-2) κ° μ μ©λλ μ νμμ
λλ€. 2 μ΄μμ nμ΄ μ
λ ₯λμμ λ, fibonacci ν¨μλ₯Ό μ μνμ¬ nλ²μ§Έ νΌλ³΄λμΉ μλ₯Ό λ°νν΄ μ£ΌμΈμ. μλ₯Ό λ€μ΄ n = 3μ΄λΌλ©΄ 2λ₯Ό λ°νν΄μ£Όλ©΄ λ©λλ€.
ex_ F(4)μΈ κ²½μ° 0 1 1 2 '3' μ΄λ―λ‘ F(4) = 3 μ
λλ€.
Plain Text
볡μ¬
function fibonacci(number) {
if(number < 2 && number >= 0) return number;
return fibonacci(number-1) + fibonacci(number-2)
}
JavaScript
볡μ¬
λ¬Έμ 2
waterMelonν¨μλ μ μ nμ 맀κ°λ³μλ‘ μ
λ ₯λ°μ΅λλ€.
κΈΈμ΄κ° nμ΄κ³ , μλ°μλ°μβ¦μ κ°μ ν¨ν΄μ μ μ§νλ λ¬Έμμ΄μ 리ν΄νλλ‘ ν¨μλ₯Ό μμ±νμΈμ.
ex_ waterMelon(4)μ΄ 4μ΄λ©΄ βμλ°μλ°βμ 리ν΄νκ³ waterMelon(3)μ΄λΌλ©΄ βμλ°μβλ₯Ό 리ν΄νλ©΄ λ©λλ€.
Plain Text
볡μ¬
function waterMelon(n){
let answer = [];
for (let i = 1; i < n + 1; i ++) {
(i%2 === 0) ? answer.push("μ") : answer.push("λ°")
}
return answer.join();
}
JavaScript
볡μ¬
function waterMelon(n){
let answer = "";
const waterMelonString = "μλ°";
if(n%2 === 0) answer = waterMelonString.repeat(n/2)
else answer = waterMelonString.repeat(n/2) + "μ"
return answer;
}
JavaScript
볡μ¬