Skip to content

Instantly share code, notes, and snippets.

@lancatlin
Created November 8, 2018 10:38
Show Gist options
  • Save lancatlin/9492d0689e59b5a80f3d4516e5587c0a to your computer and use it in GitHub Desktop.
Save lancatlin/9492d0689e59b5a80f3d4516e5587c0a to your computer and use it in GitHub Desktop.
[Kata] Number of integer partitions
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