{{ message }}

Instantly share code, notes, and snippets.

🙏
Eating Kotlin 🍰

# Cheolho Jeon CheolhoJeon

🙏
Eating Kotlin 🍰
Created May 8, 2021
View Fibonacci.kt
 package chap4.Recursion import atomictest.eq fun fibonacci(n: Int): Long { tailrec fun fibonacci( n: Int, current: Long, next: Long ): Long {
Created May 8, 2021
View fibonacci.kt
 package chap4.Recursion import atomictest.eq fun fibonacci(n: Long): Long { return when (n) { 0L -> 0 1L -> 1 else -> fibonacci(n - 1) + fibonacci(n - 2)
Created May 8, 2021
View fibonacci.kt
 package chap4.Recursion fun fibonacci(n: Long): Long { return when (n) { 0L -> 0 1L -> 1 else -> fibonacci(n - 1) + fibonacci(n - 2) } }
Created May 8, 2021
View TailRecursiveSum.kt
 package chap4.Recursion.trailrecursion import atomictest.eq private tailrec fun sum( n: Long, accumulator: Long ): Long = if (n == 0L) accumulator else sum(n - 1, accumulator + n)
Created May 8, 2021
View Iteration.kt
 package chap4.Recursion.iteration import atomictest.eq fun sum(n: Long): Long { var accumulator = 0L for (i in 1..n) { accumulator += i } return accumulator
Created May 8, 2021
View RecursionLimits.kt
 package chap4.Recursion import atomictest.eq fun sum(n: Long): Long { if (n == 0L) return 0 return n + sum(n - 1) } fun main() {
Created May 8, 2021
View InfiniteRecursion.kt
 package chap4.Recursion fun recurse(i: Int): Int = recurse(i + 1) fun main() { // println(recurse(1)) }
Created May 8, 2021
View InfiniteRecursion.kt
 package chap4.Recursion fun recurse(i: Int): Int = recurse(i + 1) fun main() { println(recurse(1)) }
Created May 8, 2021
View CallStack.kt
 package chap4.Recursion import java.lang.IllegalStateException fun illegalState() { throw IllegalStateException() } fun fail() = illegalState()
Created May 8, 2021
View Factorial.kt
 package chap4.Recursion import atomictest.eq fun factorial(n: Long): Long { if (n <= 1) return 1 return n * factorial(n - 1) } fun main() {