Ad
Code
Diff
  • is_prime = lambda n: n in (2,3) or n%2 * n%3 * n > 1
    • is_prime=lambda n:n in(2,3)or n%2*n%3*n>1!=0
    • is_prime = lambda n: n in (2,3) or n%2 * n%3 * n > 1
Code
Diff
  • def is_prime(n):
        return bool(n>1 and n%2 and n%3 or n in (2,3))
    • def is_prime(number):
    • if (number % 1 != 0) or (number < 2) or (number != 2 and number % 2 == 0) or (number != 3 and number % 3 == 0): return False
    • return True
    • def is_prime(n):
    • return bool(n>1 and n%2 and n%3 or n in (2,3))
Variables
Basic Language Features
Fundamentals
Conditional Statements
Control Flow
Loops
Arrays
Data Types
Code
Diff
  • def is_prime(num):
        if not num&1 and num != 2:
            return False
        for i in range(3, int(num ** 0.5) + 1, 2):
            if not num % i:
                return False
        return True
    
    def get_primes(max_num):
        return [i for i in range(2, max_num) if is_prime(i)]
    • import math
    • def is_prime(num):
    • if(not (num&1) and num != 2):
    • if not num&1 and num != 2:
    • return False
    • for i in range(3, int(math.sqrt(num)) + 1, 2):
    • if (num % i) == 0:
    • for i in range(3, int(num ** 0.5) + 1, 2):
    • if not num % i:
    • return False
    • return True
    • def get_primes(max_num):
    • return [i for i in range(2, max_num) if is_prime(i)]
Code
Diff
  • import random
    
    def rubegoldberg():
        find = "codewars"
        total = 1 - len(find)
    
        for x, y in enumerate(find):
            if x % 2:
                total -= ord(y) - 97
            else:
                total += ord(y) - 97        
    
        for n in random.sample([i for i in range(10)], 10):
            if n:
                a = 1 / n
            else:
                return total
    • import string
    • import random
    • def rubegoldberg():
    • alpha = string.ascii_lowercase
    • find, total = "codewars", 1
    • find = "codewars"
    • total = 1 - len(find)
    • for x, y in enumerate(find):
    • if x % 2 == 0:
    • total += alpha.index(y)
    • if x % 2:
    • total -= ord(y) - 97
    • else:
    • total -= alpha.index(y)
    • total -= len(find)
    • nums = []
    • for i in range(0, 10):
    • nums.append(i)
    • random.shuffle(nums)
    • try:
    • for n in nums:
    • total += ord(y) - 97
    • for n in random.sample([i for i in range(10)], 10):
    • if n:
    • a = 1 / n
    • except ZeroDivisionError:
    • return total
    • else:
    • return total
Code
Diff
  • decr = lambda a: sum(int(h, 16) for h in a.split(':'))
    • decr = lambda a: sum([int(h,16) for h in a.split(':')])
    • decr = lambda a: sum(int(h, 16) for h in a.split(':'))
Fundamentals
Numbers
Data Types
Mathematics
Algorithms
Logic
Code
Diff
  • def temperature_convert(temperature):
        value, a, b = temperature
    
        if a == b:
            return value
        
        converter = {'ck': value + 273.15,
                     'cr': (value * 1.8) + 491.67,
                     'cf': (value * 1.8) + 32,
                     'rc': (value - 491.67) * (5/9),
                     'rk': value * (5/9),
                     'rf': value - 459.67,
                     'kc': value - 273.15,
                     'kr': value * 1.8,
                     'kf': ((value - 273.15) * 1.8) + 32,
                     'fc': (value - 32) * (5/9),
                     'fk': ((value - 32) * (5/9)) + 273.15,
                     'fr': value + 459.67}
        
        return int(converter[str(a + b)])
    • def temperature_convert(temperature):
    • value, a, b = temperature
    • if a == b:
    • return value
    • if temperature[1] == temperature[2]:
    • return temperature[0]
    • converter = {'ck': value + 273.15,
    • 'cr': (value * 1.8) + 491.67,
    • 'cf': (value * 1.8) + 32,
    • 'rc': (value - 491.67) * (5/9),
    • 'rk': value * (5/9),
    • 'rf': value - 459.67,
    • 'kc': value - 273.15,
    • 'kr': value * 1.8,
    • 'kf': ((value - 273.15) * 1.8) + 32,
    • 'fc': (value - 32) * (5/9),
    • 'fk': ((value - 32) * (5/9)) + 273.15,
    • 'fr': value + 459.67}
    • converter = {'ck': '{} + 273.15',
    • 'cr': '({} * 1.8) + 491.67',
    • 'cf': '({} * 1.8) + 32',
    • 'rc': '({} - 491.67) * (5/9)',
    • 'rk': '{} * (5/9)',
    • 'rf': '{} - 459.67',
    • 'kc': '{} - 273.15',
    • 'kr': '{} * 1.8',
    • 'kf': '(({} - 273.15) * 1.8) + 32',
    • 'fc': '({} - 32) * (5/9)',
    • 'fk': '(({} - 32) * (5/9)) + 273.15',
    • 'fr': '{} + 459.67'}
    • value = temperature[0]
    • formula = converter[str(temperature[1] + temperature[2])]
    • return int(eval(formula.format(value)))
    • return int(converter[str(a + b)])
Variables
Basic Language Features
Fundamentals
Conditional Statements
Control Flow
Loops
Arrays
Data Types
Code
Diff
  • def is_prime(num):
        for i in range(2, num):
            if (num % i) == 0:
                return False
        return True
    
    def get_primes(max_num):
        return [i for i in range(2, max_num) if is_prime(i)]
    • def is_prime(num):
    • for i in range(2,num):
    • for i in range(2, num):
    • if (num % i) == 0:
    • return False
    • return True
    • def get_primes(max_num):
    • list_primes = []
    • for num1 in range(2,max_num):
    • if is_prime(num1):
    • list_primes.append(num1)
    • return list_primes
    • return [i for i in range(2, max_num) if is_prime(i)]
Code
Diff
  • pin_validator = lambda pin : len(str(pin)) == 5
    • def pin_validator(pin):
    • return len(str(pin)) == 5 and str(pin).isdigit()
    • pin_validator = lambda pin : len(str(pin)) == 5