### Is the Number Simple

Code
Diff
• ``is_prime = lambda n: n in (2,3) or n%2 * n%3 * n > 1``
•  1 − ```is_prime=lambda n:n in(2,3)or n%2*n%3*n>1!=0 ``` 1 + ```is_prime = lambda n: n in (2,3) or n%2 * n%3 * n > 1 ```

### Is the Number Simple

Code
Diff
• ``````def is_prime(n):
return bool(n>1 and n%2 and n%3 or n in (2,3))``````
•  1 − ```def is_prime(number): ``` 2 − ``` if (number % 1 != 0) or (number < 2) or (number != 2 and number % 2 == 0) or (number != 3 and number % 3 == 0): return False ``` 3 − ``` return True ``` 1 + ```def is_prime(n): ``` 2 + ``` return bool(n>1 and n%2 and n%3 or n in (2,3)) ```

### Get all primes up to a given number

Variables
Basic Language Features
Fundamentals
Conditional Statements
Control Flow
Loops
Arrays
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)]``````
•  1 − ```import math ``` 2 − 3 3 ```def is_prime(num): ``` 4 − ``` if(not (num&1) and num != 2): ``` 2 + ``` if not num&1 and num != 2: ``` 5 5 ``` return False ``` 6 − ``` for i in range(3, int(math.sqrt(num)) + 1, 2): ``` 7 − ``` if (num % i) == 0: ``` 4 + ``` for i in range(3, int(num ** 0.5) + 1, 2): ``` 5 + ``` if not num % i: ``` 8 8 ``` return False ``` 9 9 ``` return True ``` 10 10 11 11 ```def get_primes(max_num): ``` 12 12 ``` return [i for i in range(2, max_num) if is_prime(i)] ```

### Rube Goldberg Machine

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:
•  1 − ```import string ``` 2 2 ```import random ``` 3 3 4 4 ```def rubegoldberg(): ``` 5 − ``` alpha = string.ascii_lowercase ``` 6 − ``` find, total = "codewars", 1 ``` 4 + ``` find = "codewars" ``` 5 + ``` total = 1 - len(find) ``` 6 + 7 7 ``` for x, y in enumerate(find): ``` 8 − ``` if x % 2 == 0: ``` 9 − ``` total += alpha.index(y) ``` 8 + ``` if x % 2: ``` 9 + ``` total -= ord(y) - 97 ``` 10 10 ``` else: ``` 11 − ``` total -= alpha.index(y) ``` 12 − ``` total -= len(find) ``` 13 − ``` nums = [] ``` 14 − ``` for i in range(0, 10): ``` 15 − ``` nums.append(i) ``` 16 − ``` random.shuffle(nums) ``` 17 − ``` try: ``` 18 − ``` for n in nums: ``` 11 + ``` total += ord(y) - 97 ``` 12 + 13 + ``` for n in random.sample([i for i in range(10)], 10): ``` 14 + ``` if n: ``` 19 19 ``` a = 1 / n ``` 20 − ``` except ZeroDivisionError: ``` 21 − ``` return total ``` 16 + ``` else: ``` 17 + ``` return total ```

### hex to 1dec

Code
Diff
• ``decr = lambda a: sum(int(h, 16) for h in a.split(':'))``
•  1 − ```decr = lambda a: sum([int(h,16) for h in a.split(':')]) ``` 1 + ```decr = lambda a: sum(int(h, 16) for h in a.split(':')) ```

### First Kumite

Fundamentals
Numbers
Mathematics
Algorithms
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)])``````
•  1 1 ```def temperature_convert(temperature): ``` 2 + ``` value, a, b = temperature ``` 3 + 4 + ``` if a == b: ``` 5 + ``` return value ``` 2 2 ``` ``` 3 − ``` if temperature[1] == temperature[2]: ``` 4 − ``` return temperature[0] ``` 7 + ``` converter = {'ck': value + 273.15, ``` 8 + ``` 'cr': (value * 1.8) + 491.67, ``` 9 + ``` 'cf': (value * 1.8) + 32, ``` 10 + ``` 'rc': (value - 491.67) * (5/9), ``` 11 + ``` 'rk': value * (5/9), ``` 12 + ``` 'rf': value - 459.67, ``` 13 + ``` 'kc': value - 273.15, ``` 14 + ``` 'kr': value * 1.8, ``` 15 + ``` 'kf': ((value - 273.15) * 1.8) + 32, ``` 16 + ``` 'fc': (value - 32) * (5/9), ``` 17 + ``` 'fk': ((value - 32) * (5/9)) + 273.15, ``` 18 + ``` 'fr': value + 459.67} ``` 5 5 ``` ``` 6 − ``` converter = {'ck': '{} + 273.15', ``` 7 − ``` 'cr': '({} * 1.8) + 491.67', ``` 8 − ``` 'cf': '({} * 1.8) + 32', ``` 9 − ``` 'rc': '({} - 491.67) * (5/9)', ``` 10 − ``` 'rk': '{} * (5/9)', ``` 11 − ``` 'rf': '{} - 459.67', ``` 12 − ``` 'kc': '{} - 273.15', ``` 13 − ``` 'kr': '{} * 1.8', ``` 14 − ``` 'kf': '(({} - 273.15) * 1.8) + 32', ``` 15 − ``` 'fc': '({} - 32) * (5/9)', ``` 16 − ``` 'fk': '(({} - 32) * (5/9)) + 273.15', ``` 17 − ``` 'fr': '{} + 459.67'} ``` 18 − ``` ``` 19 − ``` value = temperature[0] ``` 20 − ``` formula = converter[str(temperature[1] + temperature[2])] ``` 21 − ``` ``` 22 − ``` return int(eval(formula.format(value))) ``` 20 + ``` return int(converter[str(a + b)]) ```

### Get all primes up to a given number

Variables
Basic Language Features
Fundamentals
Conditional Statements
Control Flow
Loops
Arrays
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)]``````
•  1 1 ```def is_prime(num): ``` 2 − ``` for i in range(2,num): ``` 2 + ``` for i in range(2, num): ``` 3 3 ``` if (num % i) == 0: ``` 4 4 ``` return False ``` 5 5 ``` return True ``` 6 6 7 7 ```def get_primes(max_num): ``` 8 − ``` list_primes = [] ``` 9 − 10 − ``` for num1 in range(2,max_num): ``` 11 − ``` if is_prime(num1): ``` 12 − ``` list_primes.append(num1) ``` 13 − ``` return list_primes ``` 8 + ``` return [i for i in range(2, max_num) if is_prime(i)] ```

### Mobile PIN Validator

Code
Diff
• ``pin_validator = lambda pin : len(str(pin)) == 5``
•  1 − ```def pin_validator(pin): ``` 2 − ``` return len(str(pin)) == 5 and str(pin).isdigit() ``` 1 + ```pin_validator = lambda pin : len(str(pin)) == 5 ```