Skip to content

Instantly share code, notes, and snippets.

@genghisjahn
Created September 20, 2013 19:58
Show Gist options
  • Save genghisjahn/6642974 to your computer and use it in GitHub Desktop.
Save genghisjahn/6642974 to your computer and use it in GitHub Desktop.
This is a very simple example of the FizzBuzz problem using Go / Golang.
package main
import (
"fmt"
sfb "simplefizzbuzz"
)
func main() {
for i := 0; i < 100; i++ {
fmt.Printf("\n%v",sfb.GetFizzBuzzResult(i))
}
}
package simplefizzbuzz
import(
"strconv"
)
func GetFizzBuzzResult(x int) string{
result:=""
rem3:=x % 3
rem5:=x % 5
rem15:=x % 15
if rem15 == 0 {
result = "FizzBuzz"
} else {
if rem5==0{
result = "Buzz"
}
if rem3==0{
result = "Fizz"
}
if result==""{
result =strconv.Itoa(x)
}
}
return result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment