### Nested Dictionary

Dictionary
Data Structures
Code
Diff
• ``````def nested_dic(*args):
a = list(args)
r = a.pop()
for x in reversed(a):
r = [{y: z} for y, z in zip(x, r)]
return r``````
•  1 − 2 − 3 − ```def nested_dic(*args, i0 = None, i1 = None): ``` 4 − ``` if i0 != None: ``` 5 − ``` if i0 < len(args) - 1: ``` 6 − ``` return {args[i0][i1]: nested_dic(*args, i0 = i0 + 1, i1 = i1)} ``` 7 − ``` else: ``` 8 − ``` return args[len(args) - 1][i1] ``` 9 − ``` return [{args[0][i1]: nested_dic(*args, i0 = 1, i1 = i1)} for i1 in range(len(args[0]))] ``` 1 + ```def nested_dic(*args): ``` 2 + ``` a = list(args) ``` 3 + ``` r = a.pop() ``` 4 + ``` for x in reversed(a): ``` 5 + ``` r = [{y: z} for y, z in zip(x, r)] ``` 6 + ``` return r ```

### Split list by variable chunk length

Algorithms
Lists
Data Structures
Code
Diff
• ``````from math import ceil

def variable_chunks(a):
n = 0
return [a[n:(n := n + i)] for i in range(1, ceil(((1 + 8 * len(a))**0.5 + 1) / 2))]``````
•  1 − ```def variable_chunks(given): ``` 2 − ``` i, chunks = 0, [] ``` 3 − ``` while given := given[i:]: ``` 4 − ``` chunks.append(given[:(i := i + 1)]) ``` 5 − ``` return chunks ``` 1 + ```from math import ceil ``` 2 + 3 + ```def variable_chunks(a): ``` 4 + ``` n = 0 ``` 5 + ``` return [a[n:(n := n + i)] for i in range(1, ceil(((1 + 8 * len(a))**0.5 + 1) / 2))] ```

### Bioinformatics - The Reverse Compliment

Code
Diff
• ``````t = str.maketrans("ACGTacgt", "TGCATGCA")

reverse_compliment = lambda dna: "".join(chr(t[ord(x)]) for x in reversed(dna))``````
•  1 − ```reverse_compliment = lambda dna: dna[::-1].translate(str.maketrans("ACGTacgt", "TGCATGCA")) ``` 1 + ```t = str.maketrans("ACGTacgt", "TGCATGCA") ``` 2 + 3 + ```reverse_compliment = lambda dna: "".join(chr(t[ord(x)]) for x in reversed(dna)) ```

### Get all primes up to a given number

Variables
Basic Language Features
Fundamentals
Conditional Statements
Control Flow
Loops
Arrays
Code
Diff
• ``````def get_primes(n):
a = [1] * n
a[0] = a[1] = 0
for i in range(2, n):
if a[i]:
x, y = divmod(n - i**2, i)
a[i**2:n:i] = [0] * (x + bool(y))
return [i for i, x in enumerate(a) if x]``````
•  1 − ```from math import sqrt ``` 2 − 3 − ```def is_prime(num): ``` 4 − ``` for newnum in range(2, int(sqrt(num)) + 1): ``` 5 − ``` if num % newnum == 0: ``` 6 − ``` return False ``` 7 − ``` return True ``` 8 − 9 − ```def get_primes(num): ``` 10 − ``` return [n for n in range(2, num + 1) if is_prime(n)] ``` 11 − ``` ``` 1 + ```def get_primes(n): ``` 2 + ``` a = [1] * n ``` 3 + ``` a[0] = a[1] = 0 ``` 4 + ``` for i in range(2, n): ``` 5 + ``` if a[i]: ``` 6 + ``` x, y = divmod(n - i**2, i) ``` 7 + ``` a[i**2:n:i] = [0] * (x + bool(y)) ``` 8 + ``` return [i for i, x in enumerate(a) if x] ```

### List of divisors of number

Performance
Code
Diff
• ``divisors=lambda n,r=[]:r.clear()or[d-n//d and r.append(n//d)or d for d in range(1,int(n**.5+1))if n%d<1]+r[::-1]``
•  1 − ```divisors=lambda n,r=[]:r.clear()or[d for d in range(1,int(n**.5+1))if n%d<1 and(d-n//d and r.append(n//d)or 1)]+r[::-1] ``` 1 + ```divisors=lambda n,r=[]:r.clear()or[d-n//d and r.append(n//d)or d for d in range(1,int(n**.5+1))if n%d<1]+r[::-1] ```
Failed Tests

### Manual data comparison with actual/expected tables displayed

``-- code which does not return anything``

### Get number days in a specified month

Code
Diff
• ``````int nbDaysInMonth(int n, bool m) {
return n == 2 ? 28 + m : 30 + (n + (n > 7) & 1);
}``````
•  1 − ```int nbDaysInMonth(int month, bool leap) { ``` 2 − ``` int days[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; ``` 3 − ``` return days[month - 1] + (month == 2 && leap); ``` 1 + ```int nbDaysInMonth(int n, bool m) { ``` 2 + ``` return n == 2 ? 28 + m : 30 + (n + (n > 7) & 1); ``` 4 4 ```} ```

### MAD - Mean Average Distribution

Algorithms
Arrays
Mathematics
Numbers
Statistics
Data
Code
Diff
• ``````function mad(a) {
if (!a.length) return null;
let n = a.reduce((x, y) => x + y, 0) / a.length;
return a.reduce((x, y) => x + Math.abs(y - n), 0) / a.length;
}``````
•  1 − ```function mad(array) { ``` 2 − ```if(array.length === 0){return null} ``` 3 − ```if(array.length === 1){return 0} ``` 4 − 5 − ```let average = (array.reduce((acc, cV) => acc + cV))/array.length ``` 6 − ```let array2 = array.map((item,index,arr)=> Math.abs(item-average)) ``` 7 − ```return (array2.reduce((acc, cV) => acc + cV))/array2.length; ``` 1 + ```function mad(a) { ``` 2 + ``` if (!a.length) return null; ``` 3 + ``` let n = a.reduce((x, y) => x + y, 0) / a.length; ``` 4 + ``` return a.reduce((x, y) => x + Math.abs(y - n), 0) / a.length; ``` 8 8 ```} ```

### C++ Simple Calculator

Code
Diff
• ``````#include <functional>
#include <string>

std::string calculator(int op, int x, int y) {
static std::array<std::function<int(int, int)>, 5> ops{
std::plus<int>(),
std::minus<int>(),
std::multiplies<int>(),
std::divides<int>(),
std::modulus<int>(),
};
if (op < 1 || op > 5 || (!y && (op == 4 || op == 5))) return "Invalid Input!";
return std::to_string(ops[op-1](x, y));
}``````
•  1 − ```#include ``` 2 − ```using namespace std; ``` 1 + ```#include ``` 2 + ```#include ``` 3 3 4 − ```string die() { ``` 5 − ``` return "Invalid Input!"; ``` 6 − ```} ``` 7 − 8 − ```string Calculator(int choice, int x, int y) { ``` 9 − ``` string answer; ``` 10 − ``` if (choice == 1 || choice == 2 || choice == 3 || choice == 4 || choice == 5){ ``` 11 − ``` switch (choice) { ``` 12 − ``` case 1: ``` 13 − ``` answer = std::to_string(x + y); ``` 14 − ``` break; ``` 15 − ``` case 2: ``` 16 − ``` answer = std::to_string(x - y); ``` 17 − ``` break; ``` 18 − ``` case 3: ``` 19 − ``` answer = std::to_string(x * y); ``` 20 − ``` break; ``` 21 − ``` case 4: ``` 22 − ``` answer = std::to_string(x / y); ``` 23 − ``` break; ``` 24 − ``` case 5: ``` 25 − ``` answer = std::to_string(x % y); ``` 26 − ``` break; ``` 27 − ``` } ``` 28 − ``` } ``` 29 − ``` else { return die(); } ``` 30 − ```return answer; ``` 4 + ```std::string calculator(int op, int x, int y) { ``` 5 + ``` static std::array, 5> ops{ ``` 6 + ``` std::plus(), ``` 7 + ``` std::minus(), ``` 8 + ``` std::multiplies(), ``` 9 + ``` std::divides(), ``` 10 + ``` std::modulus(), ``` 11 + ``` }; ``` 12 + ``` if (op < 1 || op > 5 || (!y && (op == 4 || op == 5))) return "Invalid Input!"; ``` 13 + ``` return std::to_string(ops[op-1](x, y)); ``` 31 31 ```} ```

### HeLlOwOrLddddd

Code
Diff
• ``````def convert(s):
return "".join(x.lower() if i & 1 else x.upper() for i, x in enumerate(filter(str.isalpha, s)))``````
•  1 − ```import string ``` 2 − 3 − ```def HeLlOwOrLddddd(strng): ``` 4 − ``` strng = [x for x in strng if x in string.ascii_letters] ``` 5 − ``` return "".join([strng[x].upper() if x % 2 == 0 else strng[x].lower() for x in range(len(strng))]) ``` 1 + ```def convert(s): ``` 2 + ``` return "".join(x.lower() if i & 1 else x.upper() for i, x in enumerate(filter(str.isalpha, s))) ```

### HeLlOwOrLddddd

Code
Diff
• ``````public class HeLlOwOrLddddd {
public static String convert(String s) {
StringBuilder sb = new StringBuilder();
boolean f = false;
for (char x : s.toCharArray())
if (Character.isLetter(x))
sb.append((f = !f) ? Character.toUpperCase(x) : Character.toLowerCase(x));
return sb.toString();
}
}``````
•  1 1 ```public class HeLlOwOrLddddd { ``` 2 − ``` public static String convert(String input) { ``` 3 − ``` String salida = ""; ``` 4 − ``` boolean mayus = true; ``` 5 − ``` for (int i=0;i

### Find Array indices from center to border

Code
Diff
• ``````def generate_order(n):
a, m = [*range(n)], (n + 1) // 2
return [y for x in zip(a[:m][::-1], a[m:]) for y in x] + ([0] if n & 1 else [])``````
•  1 − ```def generateOrder(n): ``` 2 − ``` if n == 0: ``` 3 − ``` return [] ``` 4 − ``` ``` 5 − ``` r = [] ``` 6 − ``` ``` 7 − ``` if n % 2 == 0 : ``` 8 − ``` r = generateOrder(n-1) ``` 9 − ``` r.append(n-1) ``` 10 − ``` else: ``` 11 − ``` middle = round((n / 2) - 0.01) ``` 12 − ``` r = [middle] ``` 13 − ``` for i in range(middle): ``` 14 − ``` r.append(middle + i + 1) ``` 15 − ``` r.append(middle - i - 1) ``` 16 − ``` ``` 17 − ``` return r ``` 1 + ```def generate_order(n): ``` 2 + ``` a, m = [*range(n)], (n + 1) // 2 ``` 3 + ``` return [y for x in zip(a[:m][::-1], a[m:]) for y in x] + ([0] if n & 1 else []) ```

### Shorter Code - If Statement

Code
Diff
• ``larger_than_5=(5).__lt__``
•  1 − ```larger_than_5=lambda a:a>5 ``` 1 + ```larger_than_5=(5).__lt__ ```

### Invert Pitch Set

Fundamentals
Code
Diff
• ``````from itertools import accumulate

def invert(a):
return [*accumulate((x - y for x, y in zip([a[0] * 2] + a, a)), lambda x, y: (x + y) % 12)]``````
•  1 − ```def invert(tone_row): ``` 2 − ``` inversion = [tone_row[0]] ``` 3 − ``` for i in range(0, 11): ``` 4 − ``` inversion.append((inversion[i] + tone_row[i] - tone_row[i + 1]) % 12) ``` 5 − ``` return inversion ``` 1 + ```from itertools import accumulate ``` 2 + 3 + ```def invert(a): ``` 4 + ``` return [*accumulate((x - y for x, y in zip([a[0] * 2] + a, a)), lambda x, y: (x + y) % 12)] ```

### Series of Calculators - Easy

Code
Diff
• ``````def calculator(a, o, b):
return eval(f"{a}{o}{b}")``````
•  1 − ```def calculator(a, operator, b): ``` 2 − ``` return eval(str(a) + operator + str(b)) ``` 1 + ```def calculator(a, o, b): ``` 2 + ``` return eval(f"{a}{o}{b}") ```