Skip to content

Instantly share code, notes, and snippets.

@polynomialspace
Last active October 8, 2019 20:20
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 polynomialspace/f40283373f2ddf2e90606996ba9a9868 to your computer and use it in GitHub Desktop.
Save polynomialspace/f40283373f2ddf2e90606996ba9a9868 to your computer and use it in GitHub Desktop.
Attempts to write the most inane but readable form of fizzbuzz in go
package main
import (
"fmt"
)
func main() {
fbarr := []string { "%[2]sFizzBuzz", "%[1]d", "%[1]d",
"%[2]sFizz" , "%[1]d", "%[2]sBuzz",
"%[2]sFizz" , "%[1]d", "%[1]d",
"%[2]sFizz" , "%[1]d", "%[2]sBuzz",
"%[2]sFizz" , "%[1]d", "%[1]d",
}
for i := 1; i < 100; i++ {
fmt.Printf(fbarr[i%15] + "\n", i, "")
}
}
package main
import (
"fmt"
)
func zzer (ci chan int, cs chan string, modulo int, response string) {
var i int
for {
i = <-ci
if i % modulo == 0 {
cs <- response
} else {
cs <- ""
}
}
}
func main() {
var s string
var ci = []chan int {
make(chan int),
make(chan int),
}
/* Separate channels or we may end up with 'FuzzBizz's */
var cs = []chan string {
make(chan string),
make(chan string),
}
go zzer(ci[0], cs[0], 3, "Fizz")
go zzer(ci[1], cs[1], 5, "Buzz")
for i := 1; i < 100; i++ {
ci[0] <- i
ci[1] <- i
s = <-cs[0] + <-cs[1]
if s == "" {
fmt.Println(i)
} else {
fmt.Println(s)
}
}
}
package main
import (
"fmt"
)
type fbint int
func (i fbint) String() string {
s := ""
if i % 3 == 0 {
s += "Fizz"
}
if i % 5 == 0 {
s += "Buzz"
}
if s == "" {
return fmt.Sprintf("%d", i)
}
return fmt.Sprintf(s)
}
func main() {
var i fbint
for i = 1; i < 1000000; i++ {
fmt.Println(i)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment