Created
May 15, 2019 01:21
-
-
Save nitrix/7bd0750bc89b2ef15c9c199f05de8b56 to your computer and use it in GitHub Desktop.
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
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