Last active
October 8, 2019 20:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, "") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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