Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jonbodner
Created July 1, 2014 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonbodner/467f761dc5d7894b33b8 to your computer and use it in GitHub Desktop.
Save jonbodner/467f761dc5d7894b33b8 to your computer and use it in GitHub Desktop.
Very silly FizzBuzz in Go
package main
import "fmt"
type data struct {
i int
s string
}
func (d data) String() string {
if len(d.s) != 0 {
return d.s
}
return fmt.Sprintf("%d",d.i)
}
func test(i int, s string, inChan <-chan data) chan data {
outChan := make(chan data)
go func() {
for {
v := <- inChan
if v.i%i == 0 {
v.s += s
}
outChan <- v
}
}()
return outChan
}
func main() {
start := make(chan data)
three := test(3, "Fizz", start)
five := test(5, "Buzz", three)
for i := 1; i<=100;i++ {
start <- data{i:i}
result := <- five
fmt.Println(result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment