GO using channels
Go \n\npackage main\n\nimport (\n\t"fmt"\n\t"sync"\n)\n\nfunc main() {\n\tvar wg sync.WaitGroup\n\tprintC := make(chan int, 1)\n\ttriggerOdd := make(chan struct
Go \n```\npackage main\n\nimport (\n\t"fmt"\n\t"sync"\n)\n\nfunc main() {\n\tvar wg sync.WaitGroup\n\tprintC := make(chan int, 1)\n\ttriggerOdd := make(chan struct{}, 1)\n\ttriggerEven := make(chan struct{}, 1)\n\tcount := 8\n\twg.Add(3)\n\tgo zero(&wg, printC, triggerEven, triggerOdd, count)\n\tgo odd(&wg, printC, triggerOdd, count)\n\tgo even(&wg, printC, triggerEven, count)\n\tprintC <- 2\n\twg.Wait()\n}\n\nfunc zero(wg *sync.WaitGroup, printC chan int, triggerEven chan struct{}, triggerOdd chan struct{}, count int) {\n\tfor i := 0; i < count; i++ {\n\t\tp := <-printC\n\t\tfmt.Print("0")\n\t\tif p == 2 {\n\t\t\ttriggerOdd <- struct{}{}\n\t\t} else {\n\t\t\ttriggerEven <- struct{}{}\n\t\t}\n\t}\n\twg.Done()\n}\n\nfunc odd(wg *sync.WaitGroup, printC chan int, triggerOdd chan struct{}, count int) {\n\tfor i := 1; i <= count; i += 2 {\n\t\t<-triggerOdd\n\t\tfmt.Print(i)\n\t\tprintC <- 1\n\t}\n\twg.Done()\n}\n\nfunc even(wg *sync.WaitGroup, printC chan int, triggerEven chan struct{}, count int) {\n\tfor i := 2; i <= count; i += 2 {\n\t\t<-triggerEven\n\t\tfmt.Print(i)\n\t\tprintC <- 2\n\t}\n\twg.Done()\n}\n```
[]