Trying to implement fizzbuzz with goroutines

This commit is contained in:
Raul 2024-03-08 12:03:16 +00:00
parent 569b255bfa
commit 43e9f4c6c4
2 changed files with 42 additions and 0 deletions

3
fizzbuzz-threads/go.mod Normal file
View File

@ -0,0 +1,3 @@
module fizzbuzz-threads
go 1.22.1

39
fizzbuzz-threads/main.go Normal file
View File

@ -0,0 +1,39 @@
package main
import (
"fmt"
)
func fizz(c chan int) {
num := <-c
if num%3 == 0 {
//str := "FIZZ"
c <- 1000
}
c <- 0
}
func buzz(c chan int) {
}
func fizzbuzz(c chan int) {
}
func main() {
fiz := make(chan int)
buz := make(chan int)
fizbuz := make(chan int)
go fizz(fiz)
go buzz(buz)
go fizzbuzz(fizbuz)
for i := 0; i < 100; i++ {
fiz <- i
fizzed := <-fiz
println(fizzed)
}
}