Created
September 20, 2013 19:58
-
-
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.
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" | |
sfb "simplefizzbuzz" | |
) | |
func main() { | |
for i := 0; i < 100; i++ { | |
fmt.Printf("\n%v",sfb.GetFizzBuzzResult(i)) | |
} | |
} |
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 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