Created
June 17, 2014 20:40
-
-
Save christianvozar/848ba77ba7f462563785 to your computer and use it in GitHub Desktop.
Fizz Buzz in Go
This file contains 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
// Class Fizz Buzz Solution | |
// Christian Vozar <christianvozar@gmail.com> | |
package main | |
import ( | |
"flag" | |
"fmt" | |
"strconv" | |
) | |
func determineFizzOrBuzz(i int) string { | |
switch { | |
case (i % 15) == 0: | |
return "FizzBuzz" | |
case (i % 5) == 0: | |
return "Buzz" | |
case (i % 3) == 0: | |
return "Fizz" | |
default: | |
return strconv.Itoa(i) | |
} | |
} | |
func main() { | |
flagQuantity := flag.Int("quantity", 100, "Quantity of numbers to determine.") | |
flag.Parse() | |
for i := 1; i <= *flagQuantity; i++ { | |
fmt.Printf("%s\n", determineFizzOrBuzz(i)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment