Skip to content

Instantly share code, notes, and snippets.

@betandr
Last active August 29, 2015 14:14
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 betandr/389f1e8ab4a1d38762a6 to your computer and use it in GitHub Desktop.
Save betandr/389f1e8ab4a1d38762a6 to your computer and use it in GitHub Desktop.
Calculate number of items in a pyramid from number in its base
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