Ad
  • Fixed "green-only" tests
  • Increase signal/noise ratio by removing fluff
  • Minor tweaks & formatting for readability
Code
Diff
  • def is_prime(n: int):
        return n > 1 and all(n % f for f in range(2, int(n ** 0.5) + 1))
    
    
    def fizz(n: int):
        return n % 3 == 0
    
    
    def buzz(n: int):
        return n % 5 == 0
    
    
    def fizzbuzz(n: int):
        return fizz(n) and buzz(n)
    
    
    def fizzbuzz_prime(n: int):
        return (
            'Prime'    if is_prime(n) else
            'FizzBuzz' if fizzbuzz(n) else
            'Fizz'     if fizz(n) else
            'Buzz'     if buzz(n) else
            n
        )
    
    
    CodeWarKata776 = fizzbuzz_prime
    • class IsPrimeNumber:
    • """Returns True if n is a prime number, False otherwise"""
    • def is_prime(n: int):
    • return n > 1 and all(n % f for f in range(2, int(n ** 0.5) + 1))
    • def __init__(self, n):
    • self.n = n
    • def calculate(self):
    • if self.n > 1:
    • for i in range(2, int(self.n ** 0.5) + 1):
    • if self.n % i == 0:
    • return False
    • return True # If no divisors found, it's prime
    • else:
    • return False
    • def fizz(n: int):
    • return n % 3 == 0
    • class Fizz:
    • """Returns True if n is divisible by 3, False otherwise"""
    • def buzz(n: int):
    • return n % 5 == 0
    • def __init__(self, n):
    • self.n = n
    • def calculate(self):
    • return self.n % 3 == 0
    • def fizzbuzz(n: int):
    • return fizz(n) and buzz(n)
    • class Buzz:
    • """Returns True if n is divisible by 5, False otherwise"""
    • def fizzbuzz_prime(n: int):
    • return (
    • 'Prime' if is_prime(n) else
    • 'FizzBuzz' if fizzbuzz(n) else
    • 'Fizz' if fizz(n) else
    • 'Buzz' if buzz(n) else
    • n
    • )
    • def __init__(self, n):
    • self.n = n
    • def calculate(self):
    • return self.n % 5 == 0
    • class FizzBuzz:
    • """Returns True if n is divisible by 3 and 5, False otherwise"""
    • def __init__(self, n):
    • self.n = n
    • def calculate(self):
    • return Fizz(self.n).calculate() and Buzz(self.n).calculate()
    • class CodeWarKata776:
    • """Executes the Fizz, Bizz, FizzBuzz Prime sequence."""
    • def __init__(self, n):
    • self.n = n
    • def calculate_prime(self):
    • return IsPrimeNumber(self.n).calculate()
    • def calculate_fizz(self):
    • return Fizz(self.n).calculate()
    • def calculate_buzz(self):
    • return Buzz(self.n).calculate()
    • def calculate_fizzbuzz(self):
    • return FizzBuzz(self.n).calculate()
    • def execute(self):
    • if IsPrimeNumber(self.n).calculate():
    • return 'Prime'
    • if FizzBuzz(self.n).calculate():
    • return 'FizzBuzz'
    • elif Fizz(self.n).calculate():
    • return 'Fizz'
    • elif Buzz(self.n).calculate():
    • return 'Buzz'
    • else:
    • return self.n
    • CodeWarKata776 = fizzbuzz_prime

Original seems to do unnecessary computation before ultimately returning True

Code
Diff
  • def above_two(_):
        return True
    • #If it is not true currently, I shall make it true
    • def above_two(arg):
    • return abs(arg)+3>2
    • def above_two(_):
    • return True