Skip to content

Instantly share code, notes, and snippets.

@nitrix
Created May 15, 2019 01:21
Show Gist options
  • Select an option

  • Save nitrix/7bd0750bc89b2ef15c9c199f05de8b56 to your computer and use it in GitHub Desktop.

Select an option

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