Last active
August 29, 2015 14:14
-
-
Save betandr/389f1e8ab4a1d38762a6 to your computer and use it in GitHub Desktop.
Calculate number of items in a pyramid from number in its base
This file contains 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
def pyramid(base: Int): Int = { | |
def p(b: Int, acc: Int): Int = { | |
if (b < 1) { | |
return acc | |
} else { | |
val n = acc + b - 1 | |
p(b - 1, n) | |
} | |
} | |
p(base, base) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment