Created
February 22, 2014 00:31
-
-
Save emadshaaban92/9146646 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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