Skip to content

Commit

Permalink
Factorial concurent implementation in golang
Browse files Browse the repository at this point in the history
  • Loading branch information
djedlajn committed Oct 19, 2017
1 parent 5e43332 commit 560ed9d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions math/factorial/go/fact_conc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main
import (
"fmt"
)

func main() {
ch := factorial(4)
for n := range ch {
fmt.Println(n)
}
}

func factorial(n int) chan int {
out := make(chan int)
go func() {
sum := 1
for i := n; i > 0; i-- {
sum *= i
}
out <- sum
close(out)
}()
return out
}

0 comments on commit 560ed9d

Please sign in to comment.