Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alvaroloes/2cba78349fabc62d0e90b704dc31600c to your computer and use it in GitHub Desktop.
Save alvaroloes/2cba78349fabc62d0e90b704dc31600c to your computer and use it in GitHub Desktop.
FizzBuzz without conditionals in Go. Simplified version
type mods struct{ mod3, mod5 bool }
var m = map[mods]string{
{false, false}: "",
{true, false}: "Fizz",
{false, true}: "Buzz",
{true, true}: "FizzBuzz",
}
func fizzbuzz(n int) string {
return m[mods{n%3 == 0, n%5 == 0}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment