Skip to content

Instantly share code, notes, and snippets.

@umisama
Last active February 8, 2017 06:52
Show Gist options
  • Save umisama/6a0c09d3b3c5b7816b4c5806542b1f5a to your computer and use it in GitHub Desktop.
Save umisama/6a0c09d3b3c5b7816b4c5806542b1f5a to your computer and use it in GitHub Desktop.
Fizz Buzz
package main
import (
"fmt"
)
const MAX = 100
func fb(num int) {
out := ""
if num%3 == 0 {
out += "fizz"
}
if num%5 == 0 {
out += "buzz"
}
if len(out) == 0 {
out = fmt.Sprintf("%d", num)
}
fmt.Printf("%s,", out)
if num < MAX {
fb(num + 1)
}
}
func main() {
fb(1)
}
package main
import (
"fmt"
)
func main() {
for f, b, c := 1, 1, 1; c <= 100; f, b, c = f+1, b+1, c+1 {
out := ""
if f == 3 {
out = "fizz"
f = 0
}
if b == 5 {
out += "buzz"
b = 0
}
if out != "" {
fmt.Printf("%s,", out)
} else {
fmt.Printf("%d,", c)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment