Skip to content

Instantly share code, notes, and snippets.

@mahmoud-eskandari
Last active June 13, 2019 19:42
Show Gist options
  • Save mahmoud-eskandari/f05e013dc0c65bd50ef6109abd25d641 to your computer and use it in GitHub Desktop.
Save mahmoud-eskandari/f05e013dc0c65bd50ef6109abd25d641 to your computer and use it in GitHub Desktop.
Recursive factorial calculator without if
package main
import "fmt"
func main() {
fmt.Println(Factorial(65))
}
func Factorial(n uint64) uint64 {
factorialOp(&n, 1, n)
return n
}
func factorialOp(n *uint64, current uint64, On uint64) bool {
*n *= current
current++
return current >= On || factorialOp(n, current, On)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment