Last active
March 16, 2016 15:07
-
-
Save amashigeseiji/15373f62d2db808a21d5 to your computer and use it in GitHub Desktop.
fizzbuzz for golang
This file contains hidden or 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() { | |
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