Skip to content

Instantly share code, notes, and snippets.

@emadshaaban92
Created February 22, 2014 00:31
Show Gist options
  • Save emadshaaban92/9146646 to your computer and use it in GitHub Desktop.
Save emadshaaban92/9146646 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/big"
"time"
)
func makeNCRS(ncrs chan *big.Int, maxn int64) {
var n, r int64
var ncr, bigR *big.Int
for n = 1; n <= maxn; n++ {
ncr = big.NewInt(n)
for r = 2; r <= n; r++ {
bigR = big.NewInt(r)
ncr = ncr.Div(ncr, bigR)
ncr = ncr.Mul(ncr, big.NewInt(n-r+1))
ncrs <- ncr
}
}
close(ncrs)
}
func main() {
start := time.Now()
result := 0
ncrs := make(chan *big.Int)
go makeNCRS(ncrs, 100)
max := big.NewInt(1000000)
for ncr := range ncrs {
if ncr.Cmp(max) > 0 {
result += 1
}
}
fmt.Println(result)
elapsed := time.Since(start)
fmt.Println(elapsed.Nanoseconds())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment