Created
August 29, 2021 08:33
-
-
Save viebel/d9320214d88352533d3f81d3ff960312 to your computer and use it in GitHub Desktop.
factorial.go
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
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