Skip to content

Instantly share code, notes, and snippets.

@Hygens
Last active February 14, 2017 18:52
Show Gist options
  • Save Hygens/d7e068b5c6683d1687af9ae02bf25804 to your computer and use it in GitHub Desktop.
Save Hygens/d7e068b5c6683d1687af9ae02bf25804 to your computer and use it in GitHub Desktop.
FizzBuzz for Software, Product, and Embedded Engineering Candidates
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)
}
}
}
@Hygens
Copy link
Author

Hygens commented Feb 14, 2017

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.

@Hygens
Copy link
Author

Hygens commented Feb 14, 2017

Used switch for more readability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment