Skip to content

Instantly share code, notes, and snippets.

@viebel
Created August 29, 2021 08:33
Show Gist options
  • Save viebel/d9320214d88352533d3f81d3ff960312 to your computer and use it in GitHub Desktop.
Save viebel/d9320214d88352533d3f81d3ff960312 to your computer and use it in GitHub Desktop.
factorial.go
import (
"fmt"
"math/big"
)
func factorial(x *big.Int) *big.Int {
n := big.NewInt(1)
if x.Cmp(big.NewInt(0)) == 0 {
return n
}
return n.Mul(x, factorial(n.Sub(x, n)))
}
func main() {
fmt.Println(factorial(big.NewInt(103)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment