Skip to content

Instantly share code, notes, and snippets.

@amashigeseiji
Last active March 16, 2016 15:07
Show Gist options
  • Save amashigeseiji/15373f62d2db808a21d5 to your computer and use it in GitHub Desktop.
Save amashigeseiji/15373f62d2db808a21d5 to your computer and use it in GitHub Desktop.
fizzbuzz for golang
package main
import "fmt"
func main() {
for i := 1; i < 100; i++ {
fmt.Println(fizzbuzz(i))
}
}
func fizzbuzz(i int) string {
is_fizz := func(i int) bool {
return i % 3 == 0
}
is_buzz := func(i int) bool {
return i % 5 == 0
}
var res, fizz, buzz string = "", "FIZZ", "BUZZ"
if is_fizz(i) {
res += fizz
}
if is_buzz(i) {
res += buzz
}
if (res == "") {
res = fmt.Sprint(i)
}
return res
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment