Skip to content

Instantly share code, notes, and snippets.

@wingyplus
Created June 14, 2011 18:20
Show Gist options
  • Save wingyplus/1025504 to your computer and use it in GitHub Desktop.
Save wingyplus/1025504 to your computer and use it in GitHub Desktop.
Pascal's Triangle
package main
import "fmt"
func Factorial (n int) int {
if n == 0 {
return 1
}
return n * Factorial (n - 1)
}
func Combination (row, column int) int {
return Factorial (row) / (Factorial (column) * Factorial (row - column))
}
func main () {
for i := 0; i < 4; i++ {
for j := 0; j <= i; j++ { // column j row i
fmt.Printf ("%d ", Combination (i, j))
}
}
fmt.Println ()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment