Skip to content

Instantly share code, notes, and snippets.

@heatblazer
Created December 21, 2019 15:31
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 heatblazer/e57ae9a466e37d8b33d1e7245fb9523b to your computer and use it in GitHub Desktop.
Save heatblazer/e57ae9a466e37d8b33d1e7245fb9523b to your computer and use it in GitHub Desktop.
package main
import "fmt"
func main() {
fmt.Printf("Fact of 6 is %d\r\n", fact(6))
for n := 1; n < 7; n++ {
fmt.Printf("\r\n")
for k := 1; k < 7; k++ {
fmt.Printf("[%d]", binomcoef(n-1, k-1)+binomcoef(n-1, k))
}
}
}
func fact(val int) int {
if val <= 0 {
return 1
}
var result int = 1
for i := 1; i < val+1; i++ {
result *= i
}
return result
}
func binomcoef(n int, k int) int {
return fact(n) / (fact(k) * fact(n-k))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment