Skip to content

Instantly share code, notes, and snippets.

@javarouka
Created March 26, 2019 08:38
Show Gist options
  • Save javarouka/b8c3ec555d2080d6f77d9410e5e64719 to your computer and use it in GitHub Desktop.
Save javarouka/b8c3ec555d2080d6f77d9410e5e64719 to your computer and use it in GitHub Desktop.
Kotlin fiobnachi
fun fiboRecursive(v:Int): Int =
if(v <= 2) 1
else fiboRecursive(v-1) + fiboRecursive(v-2)
fun fiboLoop(v:Int): Int {
if(v <= 2) return 1
var result = 0
var prev1 = 1
var prev2 = 1
// 전 루프의 두 수의 합이 현재 루프의 값이다.
for (index in 2 until v) {
result = prev1 + prev2
prev2 = prev1
prev1 = result
println("$index > $result")
}
return result
}
fun main() {
println(fiboRecursive(10))
println(fiboLoop(10))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment