From 43e9f4c6c4e485ed476e75e7a5f3b56a7753f540 Mon Sep 17 00:00:00 2001 From: Raul Date: Fri, 8 Mar 2024 12:03:16 +0000 Subject: [PATCH] Trying to implement fizzbuzz with goroutines --- fizzbuzz-threads/go.mod | 3 +++ fizzbuzz-threads/main.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 fizzbuzz-threads/go.mod create mode 100644 fizzbuzz-threads/main.go diff --git a/fizzbuzz-threads/go.mod b/fizzbuzz-threads/go.mod new file mode 100644 index 0000000..29cd418 --- /dev/null +++ b/fizzbuzz-threads/go.mod @@ -0,0 +1,3 @@ +module fizzbuzz-threads + +go 1.22.1 diff --git a/fizzbuzz-threads/main.go b/fizzbuzz-threads/main.go new file mode 100644 index 0000000..10aed3b --- /dev/null +++ b/fizzbuzz-threads/main.go @@ -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) + } +}