Skip to content

Instantly share code, notes, and snippets.

@CheolhoJeon
Created May 8, 2021 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CheolhoJeon/195fede4e530a7957c32e7f2d8d3814e to your computer and use it in GitHub Desktop.
Save CheolhoJeon/195fede4e530a7957c32e7f2d8d3814e to your computer and use it in GitHub Desktop.
package chap4.Recursion.iteration
import atomictest.eq
fun sum(n: Long): Long {
var accumulator = 0L
for (i in 1..n) {
accumulator += i
}
return accumulator
}
fun main() {
sum(10000) eq 50005000
sum(100000) eq 5000050000
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment