Skip to content

Instantly share code, notes, and snippets.

@degree
Last active December 21, 2015 22:28
Show Gist options
  • Save degree/6375323 to your computer and use it in GitHub Desktop.
Save degree/6375323 to your computer and use it in GitHub Desktop.
import scala.annotation.tailrec
@tailrec def sumrec(sum: Int, current: Int, end: Int):Int = if (current > end) sum else sumrec(sum + current, current + 1, end)
def sum(start: Int, end: Int) = sumrec(0, start, end)
println(sum(1, 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment