Boss: The FizzBuzz Gauntlet
Prove your foundations. Complete every task.
Print the classic FizzBuzz sequence for every integer from 1 through 20 (both inclusive), one value per line, in order.
Rules for each number n:
- If n is divisible by both 3 and 5 → print exactly
FizzBuzz - Else if n is divisible by 3 → print exactly
Fizz - Else if n is divisible by 5 → print exactly
Buzz - Otherwise → print n as a decimal number
Use fmt.Println so each entry ends with a newline. Do not print any header, prefix, or trailing blank line. Case matters: the labels are Fizz, Buzz, FizzBuzz — nothing else.
- prints the full sequencepending
Hint
Loop 1..20 and branch on n%15, then n%3, then n%5, otherwise print the number.
Implement factorial(n int) int with 0! = 1 and negative n returning 0. A hidden test suite exercises 0, 1, 6, and 10.
- TestFactorialZeropending
- TestFactorialSmallpending
- TestFactorialLargepending
- TestFactorialNegativepending
Hint
Handle negative input first, then iterate for i := 2; i <= n; i++ multiplying into a running product seeded at 1.
Implement isPrime(n int) bool: primes are integers > 1 with no divisors other than 1 and themselves. A hidden test suite includes edge cases (0, 1, 2, negatives) and larger primes.
- TestIsPrimeSmallpending
- TestIsPrimeLargerpending
Hint
Reject n < 2 first. Then trial-divide from 2 up to √n — no need to test beyond that.