Last active
December 21, 2015 22:28
-
-
Save degree/6375323 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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