Ad
Mathematics
Algorithms
Logic
Numbers
Code
Diff
  • function prime_checker (n) {
      if ([0,1].includes(n)) return false;
      if (n == 2) return true;
      if (n % 2 == 0) return false;
      for(let i = 3; i < n; i += 2) {
        if(n % i === 0) return false;
      }
      return true;  
    }
    • function prime_checker (n) {
    • if ([0,1].includes(n)) return false;
    • for(let i = 2; i < n; i++) {
    • if (n == 2) return true;
    • if (n % 2 == 0) return false;
    • for(let i = 3; i < n; i += 2) {
    • if(n % i === 0) return false;
    • }
    • return true;
    • }
Mathematics
Algorithms
Logic
Numbers
Code
Diff
  • def prime_checker(n):
        if n == 2: return True
        if n < 2 or n % 2 == 0: return False
        for i in range(3, n, 2):
            if n % i == 0: return False
        return True
    • def prime_checker(n):
    • a = 0
    • for i in range(2,n):
    • if n == 2:
    • return True
    • elif n%i == 0:
    • return False
    • if n == 2: return True
    • if n < 2 or n % 2 == 0: return False
    • for i in range(3, n, 2):
    • if n % i == 0: return False
    • return True
Mathematics
Algorithms
Logic
Numbers
Code
Diff
  • def prime_checker(n):
        a = 0
        for i in range(2,n):
            if n == 2:
                return True
            elif n%i == 0:
                return False
        return True
    • def prime_checker(n):
    • a = 0
    • for i in range(2,n):
    • if n == 2:
    • return True
    • break
    • elif n%i == 0:
    • return False
    • a += 1
    • break
    • if a == 0:
    • return True
    • return True