Skip to content

Instantly share code, notes, and snippets.

@nitrix
Created May 15, 2019 01:21
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 nitrix/7bd0750bc89b2ef15c9c199f05de8b56 to your computer and use it in GitHub Desktop.
Save nitrix/7bd0750bc89b2ef15c9c199f05de8b56 to your computer and use it in GitHub Desktop.
func triangularNumberOf(n int) int {
return n * (n + 1) / 2
}
func reverseTriangularNumberOf(sum int) int {
n := (math.Sqrt(8 * float64(sum) + 1) - 1) / 2
return int(math.Ceil(n))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment