Created
November 8, 2018 10:38
-
-
Save lancatlin/9492d0689e59b5a80f3d4516e5587c0a to your computer and use it in GitHub Desktop.
[Kata] Number of integer partitions
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
package kata | |
func Partitions(n int) int { | |
return p(n, n) | |
} | |
func p (n int, d int) int { | |
if d > n { | |
d = n | |
} | |
if d <= 1 { | |
return 1 | |
} | |
count := 0 | |
for i := d; i > 0; i-- { | |
count += p(n - i, i) | |
} | |
return count | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment