Last active
February 14, 2017 18:52
-
-
Save Hygens/d7e068b5c6683d1687af9ae02bf25804 to your computer and use it in GitHub Desktop.
FizzBuzz for Software, Product, and Embedded Engineering Candidates
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" | |
"math/big" | |
) | |
//Limit is the precision for test if isPrime for that number major the | |
//precision is major | |
var LIMIT = 1000000 | |
func main() { | |
// t is number of test cases and x is the number for each test | |
var t int | |
var x int64 | |
fmt.Scanf("%d", &t) | |
for i := 0; i < t; i++ { | |
fmt.Scanf("%d", &x) | |
switch { | |
case x%15 == 0: | |
fmt.Println("FizzBuzz") | |
case x%3 == 0: | |
fmt.Println("Fizz") | |
case x%5 == 0: | |
fmt.Println("Buzz") | |
case big.NewInt(x).ProbablyPrime(LIMIT): | |
fmt.Println("BuzzFizz") | |
default: | |
fmt.Println(x) | |
} | |
} | |
} |
Used switch for more readability.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That implementation is more simple possible and not need any comments. I would be developed on C/C++/Java/Python(2 or 3 lines)/Ruby(between 3 and 4 lines)/Haskell/CLisp/Lua/Scala/PHP/Shell Script/Perl more Go is a good option for simplicity and readability.