diff --git a/math/factorial/go/fact_conc.go b/math/factorial/go/fact_conc.go new file mode 100644 index 0000000000..82200e40ee --- /dev/null +++ b/math/factorial/go/fact_conc.go @@ -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 +}