problem_id
stringlengths
32
32
name
stringclasses
1 value
problem
stringlengths
200
14k
solutions
stringlengths
12
1.12M
test_cases
stringlengths
37
74M
difficulty
stringclasses
3 values
language
stringclasses
1 value
source
stringclasses
7 values
num_solutions
int64
12
1.12M
starter_code
stringlengths
0
956
6926a7d6abd215794c191d7cb003666b
UNKNOWN
We all love the future president (or Führer or duce or sōtō as he could find them more fitting) donald trump, but we might fear that some of his many fans like John Miller or John Barron are not making him justice, sounding too much like their (and our as well, of course!) hero and thus risking to compromise him. For ...
["import re\ndef trump_detector(ts):\n x=re.findall(r'([aeiou])(\\1*)',ts,re.I)\n y=[len(i[1]) for i in x]\n return round(sum(y)/len(y),2)", "import re\n\ndef trump_detector(trump_speech):\n lst = [ len(tup[1]) for tup in re.findall(r'([aeiou])(\\1*)', trump_speech, re.I) ]\n return round(sum(lst)/len(ls...
{"fn_name": "trump_detector", "inputs": [["I will build a huge wall"], ["HUUUUUGEEEE WAAAAAALL"], ["MEXICAAAAAAAANS GOOOO HOOOMEEEE"], ["America NUUUUUKEEEE Oooobaaaamaaaaa"], ["listen migrants: IIII KIIIDD YOOOUUU NOOOOOOTTT"]], "outputs": [[0], [4], [2.5], [1.89], [1.56]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,819
def trump_detector(trump_speech):
50224bb894d1c1ce22f539ee05f6e9a0
UNKNOWN
### The Story: Bob is working as a bus driver. However, he has become extremely popular amongst the city's residents. With so many passengers wanting to get aboard his bus, he sometimes has to face the problem of not enough space left on the bus! He wants you to write a simple program telling him if he will be able to ...
["def enough(cap, on, wait):\n return max(0, wait - (cap - on))", "def enough(cap, on, wait):\n return max(0, on + wait - cap)", "def enough(cap, on, wait):\n return wait + on - cap if wait + on > cap else 0", "def enough(cap, on, wait):\n return max(on + wait - cap, 0)", "def enough(cap, on, wait):\n if...
{"fn_name": "enough", "inputs": [[10, 5, 5], [100, 60, 50], [20, 5, 5]], "outputs": [[0], [10], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
12,354
def enough(cap, on, wait):
56b3a5dd09ef40cdbf756942ab5b198d
UNKNOWN
The wide mouth frog is particularly interested in the eating habits of other creatures. He just can't stop asking the creatures he encounters what they like to eat. But then he meet the alligator who just LOVES to eat wide-mouthed frogs! When he meets the alligator, it then makes a tiny mouth. Your goal in this kata...
["def mouth_size(animal): \n return 'small' if animal.lower() == 'alligator' else 'wide'", "def mouth_size(animal): \n return 'wide' if animal.lower() != 'alligator' else 'small'", "def mouth_size(animal): \n mouth = {'alligator':'small'}\n return mouth.get(animal.lower(), 'wide')", "import re\n\ndef mouth_si...
{"fn_name": "mouth_size", "inputs": [["toucan"], ["ant bear"], ["alligator"]], "outputs": [["wide"], ["wide"], ["small"]]}
INTRODUCTORY
PYTHON3
CODEWARS
13,545
def mouth_size(animal):
38a45307700e366089ae7d9c3a12f0f0
UNKNOWN
In this Kata, you will be given a number in form of a string and an integer `k` and your task is to insert `k` commas into the string and determine which of the partitions is the largest. ``` For example: solve('1234',1) = 234 because ('1','234') or ('12','34') or ('123','4'). solve('1234',2) = 34 because ('1','2','3...
["def solve(st, k):\n length = len(st) - k\n return max(int(st[i:i + length]) for i in range(k + 1))", "def solve(st,k):\n c=len(st)-k\n return int(max(st[i:i+c] for i in range(k+1)))", "def solve(st,k):\n return max([int(st[i:i+len(st)-k]) for i in range(len(st))])", "def solve(st, k):\n n = len(st) ...
{"fn_name": "solve", "inputs": [["1234", 1], ["1234", 2], ["1234", 3], ["2020", 1]], "outputs": [[234], [34], [4], [202]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,083
def solve(st,k):
2a201b7b7170e3b0d189a607a93bb92f
UNKNOWN
Create a function that takes in the sum and age difference of two people, calculates their individual ages, and returns a pair of values (oldest age first) if those exist or `null/None` if: * `sum < 0` * `difference < 0` * Either of the calculated ages come out to be negative
["def get_ages(a,b):\n x = (a+b)/2\n y = (a-b)/2\n return None if a<0 or b<0 or x<0 or y<0 else (x,y)", "def get_ages(s, diff):\n older, younger = (s / 2) + (diff / 2), (s / 2) - (diff / 2) \n if older >= younger >= 0:\n return (older, younger)", "def get_ages(s, diff):\n older = (s / 2) + (di...
{"fn_name": "get_ages", "inputs": [[24, 4], [30, 6], [70, 10], [18, 4], [63, 14], [80, 80], [63, -14], [-22, 15]], "outputs": [[[14, 10]], [[18, 12]], [[40, 30]], [[11, 7]], [[38.5, 24.5]], [[80, 0]], [null], [null]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,540
def get_ages(sum_, difference):
3296205cc3e90a8c0e7a7756a9391f0a
UNKNOWN
Generate and return **all** possible increasing arithmetic progressions of six primes `[a, b, c, d, e, f]` between the given limits. Note: the upper and lower limits are inclusive. An arithmetic progression is a sequence where the difference between consecutive numbers is the same, such as: 2, 4, 6, 8. A prime number...
["is_prime = lambda n: all(n % d for d in range(3, int(n ** .5) + 1, 2))\n\ndef primes_a_p(lower_limit, upper_limit):\n a_p = []\n for n in range(lower_limit | 1, upper_limit, 2):\n for gap in range(30, (upper_limit - n) // 5 + 1, 30):\n sequence = [n + i * gap for i in range(6)]\n if...
{"fn_name": "primes_a_p", "inputs": [[0, 200], [90, 600], [770, 1000], [30, 305], [1000, 4000]], "outputs": [[[[7, 37, 67, 97, 127, 157]]], [[[107, 137, 167, 197, 227, 257], [359, 389, 419, 449, 479, 509]]], [[]], [[[107, 137, 167, 197, 227, 257]]], [[[1013, 1193, 1373, 1553, 1733, 1913], [1039, 1249, 1459, 1669, 1879,...
INTRODUCTORY
PYTHON3
CODEWARS
6,895
def primes_a_p(lower_limit, upper_limit):
16d0196257d2c55ec445cbdea89d5890
UNKNOWN
Given a string, turn each letter into its ASCII character code and join them together to create a number - let's call this number `total1`: ``` 'ABC' --> 'A' = 65, 'B' = 66, 'C' = 67 --> 656667 ``` Then replace any incidence of the number `7` with the number `1`, and call this number 'total2': ``` total1 = 656667 ...
["def calc(s):\n total1 = ''.join(map(lambda c: str(ord(c)), s))\n total2 = total1.replace('7', '1')\n return sum(map(int, total1)) - sum(map(int, total2))", "def calc(x):\n return ''.join(str(ord(ch)) for ch in x).count('7') * 6", "def calc(x):\n return ''.join([str(ord(x[i])) for i in range(len(x)) ])....
{"fn_name": "calc", "inputs": [["abcdef"], ["ifkhchlhfd"], ["aaaaaddddr"], ["jfmgklf8hglbe"], ["jaam"], ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"]], "outputs": [[6], [6], [30], [6], [12], [96]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,109
def calc(x):
86e50c890f825c8f67452def1219a7aa
UNKNOWN
Rule 30 is a one-dimensional binary cellular automaton. You can have some information here: * [https://en.wikipedia.org/wiki/Rule_30](https://en.wikipedia.org/wiki/Rule_30) You have to write a function that takes as input an array of 0 and 1 and a positive integer that represents the number of iterations. This func...
["def rule30(a, n):\n for _ in range(n):\n a = [int(0 < 4*x + 2*y + z < 5) for x, y, z in\n zip([0, 0] + a, [0] + a + [0], a + [0, 0])]\n return a", "def rule30(li, n):\n for i in range(n):\n li = [0] + li + [0]\n li = [(li[k-1] if k else 0)^(l or (li[k+1] if k<len(li)-1 els...
{"fn_name": "rule30", "inputs": [[[1], 1], [[1], 2], [[1], 21], [[0], 5], [[0], 0], [[1, 1, 1], 0], [[0], 3], [[1], -3], [[1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1], 1], [[1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1], 75]], "outputs": [[[1, 1, 1]], [[1, 1, 0, 0, 1]], [[1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0,...
INTRODUCTORY
PYTHON3
CODEWARS
2,802
def rule30(list_, n):
6c94816e47ed9587a18eb6da51647ddc
UNKNOWN
Sometimes, I want to quickly be able to convert miles per imperial gallon into kilometers per liter. Create an application that will display the number of kilometers per liter (output) based on the number of miles per imperial gallon (input). Make sure to round off the result to two decimal points. If the answer ends...
["def converter(mpg):\n '''Converts mpg to kpl. Rounds to two decimal places.'''\n kpl = round(mpg * 1.609344/4.54609188, 2)\n return kpl", "\ndef converter(mpg):\n #your code here\n return round(mpg / 4.54609188 * 1.609344 , 2)\n", "def converter(mpg):\n return round((mpg * 1.609344 / 4.54609188)...
{"fn_name": "converter", "inputs": [[10], [20], [30], [24], [36]], "outputs": [[3.54], [7.08], [10.62], [8.5], [12.74]]}
INTRODUCTORY
PYTHON3
CODEWARS
12,758
def converter(mpg):
e486b8bb1ebfd51b113a520e7d186016
UNKNOWN
The aim of this kata is to split a given string into different strings of equal size (note size of strings is passed to the method) Example: Split the below string into other strings of size #3 'supercalifragilisticexpialidocious' Will return a new string 'sup erc ali fra gil ist ice xpi ali doc iou...
["from textwrap import wrap\n\n\ndef split_in_parts(s, part_length): \n return \" \".join(wrap(s,part_length))", "def split_in_parts(s, n): \n return ' '.join([s[i:i+n] for i in range(0, len(s), n)])", "def split_in_parts(s, part_length): \n new = \"\"\n i = 0\n for x in s: # Recorremos...
{"fn_name": "split_in_parts", "inputs": [["supercalifragilisticexpialidocious", 3], ["HelloKata", 1], ["HelloKata", 9]], "outputs": [["sup erc ali fra gil ist ice xpi ali doc iou s"], ["H e l l o K a t a"], ["HelloKata"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,806
def split_in_parts(s, part_length):
b06aca16ec068172628ad5810fa1fcce
UNKNOWN
Return the century of the input year. The input will always be a 4 digit string, so there is no need for validation. ### Examples ``` "1999" --> "20th" "2011" --> "21st" "2154" --> "22nd" "2259" --> "23rd" "1124" --> "12th" "2000" --> "20th" ```
["def what_century(year):\n n = (int(year) - 1) // 100 + 1\n return str(n) + (\"th\" if n < 20 else {1: \"st\", 2: \"nd\", 3: \"rd\"}.get(n % 10, \"th\"))", "def what_century(year):\n year = str(year)\n st = year[:2]\n st = int(st)\n gt = st + 1\n gt = str(gt)\n if year != \"0000\" and year[1:] ...
{"fn_name": "what_century", "inputs": [["1999"]], "outputs": [["20th"]]}
INTRODUCTORY
PYTHON3
CODEWARS
9,618
def what_century(year):
8b50a65cf2f05fd5dfc8fd9725f76223
UNKNOWN
A stick is balanced horizontally on a support. Will it topple over or stay balanced? (This is a physics problem: imagine a real wooden stick balanced horizontally on someone's finger or on a narrow table, for example). The stick is represented as a list, where each entry shows the mass in that part of the stick. The...
["from math import ceil\n\ndef will_it_balance(stick, gnd):\n gravPt = sum(v*i for i,v in enumerate(stick)) / sum(stick)\n return gnd[int(gravPt)] == gnd[ceil(gravPt)] == 1", "def will_it_balance(stick, terrain):\n com = sum(i*w for i,w in enumerate(stick))/sum(stick)\n return terrain.index(1)<=com<=max(i f...
{"fn_name": "will_it_balance", "inputs": [[[2, 3, 2], [0, 1, 0]], [[5, 1, 1], [0, 1, 0]], [[3, 3, 4], [0, 1, 0]], [[9, 7, 1, 1], [1, 1, 0, 0]], [[9, 1, 1, 7], [1, 1, 0, 0]]], "outputs": [[true], [false], [false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,537
def will_it_balance(stick, terrain):
d11e05d7f81b257720322826afc03ce2
UNKNOWN
# ASC Week 1 Challenge 5 (Medium #2) Create a function that takes a 2D array as an input, and outputs another array that contains the average values for the numbers in the nested arrays at the corresponding indexes. Note: the function should also work with negative numbers and floats. ## Examples ``` [ [1, 2, 3, 4]...
["def avg_array(arrs):\n return [sum(a)/len(a) for a in zip(*arrs)]", "def avg_array(arrs):\n length = len(arrs)\n return [sum(arr)/length for arr in zip(*arrs)]", "from statistics import mean\n\ndef avg_array(arrs):\n return list(map(mean,zip(*arrs)))", "def avg_array(arrs):\n return [(sum(ar[i] for ar ...
{"fn_name": "avg_array", "inputs": [[[[1, 2, 3, 4], [5, 6, 7, 8]]], [[[2, 3, 9, 10, 7], [12, 6, 89, 45, 3], [9, 12, 56, 10, 34], [67, 23, 1, 88, 34]]], [[[2, 5, 4, 3, 19], [2, 5, 6, 7, 10]]], [[[1.2, 8.521, 0.4, 3.14, 1.9], [2, 4.5, 3.75, 0.987, 1.0]]], [[[2, 5, -4, 3, -19], [-2, -5, 6, 7, 10]]], [[[-2, -18, -45, -10],...
INTRODUCTORY
PYTHON3
CODEWARS
939
def avg_array(arrs):
8bb663d438f0c77954cb2053dcd109ee
UNKNOWN
# Task John won the championship of a TV show. He can get some bonuses. He needs to play a game to determine the amount of his bonus. Here are some cards in a row. A number is written on each card. In each turn, John can take a card, but only from the beginning or the end of the row. Then multiply the number on the...
["def calc(a):\n res = [0] * (len(a) + 1)\n for k in range(len(a)):\n res = [2 * max(a[i] + res[i+1], a[i+k] + res[i]) for i in range(len(a) - k)]\n return res[0]", "from functools import lru_cache\n\ncalc = lambda cards : get(tuple(cards))\nget = lru_cache(None) ( lambda seq, turn=1:max([2**turn*seq[0]...
{"fn_name": "calc", "inputs": [[[1, 2, 5]], [[1]], [[1, 1]], [[1, 2, 1]], [[4, 10, 2, 3, 1, 3, 1, 6, 9]]], "outputs": [[50], [2], [6], [22], [6722]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,025
def calc(cards):
d2c7bd599710de402de66afeb9bbb5b7
UNKNOWN
In input string ```word```(1 word): * replace the vowel with the nearest left consonant. * replace the consonant with the nearest right vowel. P.S. To complete this task imagine the alphabet is a circle (connect the first and last element of the array in the mind). For example, 'a' replace with 'z', 'y' with 'a', etc....
["def replace_letters(word):\n return word.translate(str.maketrans('abcdefghijklmnopqrstuvwxyz','zeeediiihooooonuuuuutaaaaa')) \n", "table = str.maketrans('abcdefghijklmnopqrstuvwxyz', 'zeeediiihooooonuuuuutaaaaa')\ndef replace_letters(word): return word.translate(table)", "from string import ascii_lowercase as al\n\n...
{"fn_name": "replace_letters", "inputs": [["cat"], ["codewars"], ["abcdtuvwxyz"]], "outputs": [["ezu"], ["enedazuu"], ["zeeeutaaaaa"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,858
def replace_letters(word):
eb082a67f0a881b1ca468b3eb3896b49
UNKNOWN
Give the summation of all even numbers in a Fibonacci sequence up to, but not including, the maximum value. The Fibonacci sequence is a series of numbers where the next value is the addition of the previous two values. The series starts with 0 and 1: 0 1 1 2 3 5 8 13 21... For example: ```python eve_fib(0)==0 eve_fi...
["def even_fib(m):\n x,y = 0, 1\n counter = 0\n while y < m:\n if y % 2 == 0:\n counter += y\n x,y = y, x+ y\n return counter", "def even_fib(m):\n a, b, total = 1, 1, 0\n \n while a < m:\n if a % 2 == 0:\n total += a\n a, b = b, a + b\n \n re...
{"fn_name": "even_fib", "inputs": [[0], [10], [5], [100], [1000], [1000000], [100000000], [1000000000], [2147483647], [-1]], "outputs": [[0], [10], [2], [44], [798], [1089154], [82790070], [350704366], [1485607536], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,982
def even_fib(m):
04d217f7a64f7579e849d2d47a1f18f4
UNKNOWN
# Task Define crossover operation over two equal-length strings A and B as follows: the result of that operation is a string of the same length as the input strings result[i] is chosen at random between A[i] and B[i]. Given array of strings `arr` and a string result, find for how many pairs of strings from `arr`...
["from itertools import combinations\ndef strings_crossover(arr, result):\n return sum(1 for s1,s2 in combinations(arr,2) if all(r in (x,y) for x,y,r in zip(s1,s2,result)))", "from collections import Counter\n\ndef strings_crossover(arr, result):\n lstBit = [ int(''.join(['01'[x==y] for x,y in zip(result, w)]), 2...
{"fn_name": "strings_crossover", "inputs": [[["abc", "aaa", "aba", "bab"], "bbb"], [["aacccc", "bbcccc"], "abdddd"], [["a", "b", "c", "d", "e"], "c"], [["aa", "ab", "ba"], "bb"], [["a", "b", "c", "d", "e"], "f"], [["aaa", "aaa"], "aaa"]], "outputs": [[2], [0], [4], [1], [0], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,594
def strings_crossover(arr, result):
e036365bf7ba100a115cea34ca73dca5
UNKNOWN
An array is defined to be `inertial`if the following conditions hold: ``` a. it contains at least one odd value b. the maximum value in the array is even c. every odd value is greater than every even value that is not the maximum value. ``` eg:- ``` So [11, 4, 20, 9, 2, 8] is inertial because a. it contains at leas...
["def is_inertial(arr):\n mx = max(arr, default=1)\n miO = min((x for x in arr if x%2==1), default=float(\"-inf\"))\n miE2 = max((x for x in arr if x%2==0 and x!=mx), default=float(\"-inf\"))\n return mx%2 == 0 and miE2 < miO", "def is_inertial(lst):\n odds = [n for n in lst if n % 2 == 1]\n evens ...
{"fn_name": "is_inertial", "inputs": [[[]], [[581, -384, 140, -287]], [[11, 4, 20, 9, 2, 8]]], "outputs": [[false], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,013
def is_inertial(arr):
5e83ab1b215abc7b745b3da6489e1f8a
UNKNOWN
## TL;DR Given a number of vertices `N` and a list of weighted directed edges in a directed acyclic graph (each edge is written as `[start, end, weight]` where `from < to`), compute the weight of the shortest path from vertex `0` to vertex `N - 1`. If there is no such path, return `-1`. ## Background A weighted DAG...
["import heapq\nfrom collections import defaultdict\n\ndef shortest(N, edge):\n ver, inf = defaultdict(list), 10**10\n for e in edge: ver[e[0]].append(e[1:])\n\n dist = {i:inf for i in range(N)}\n dist[0], pq = 0, []\n heapq.heappush(pq, [dist[0], 0])\n while pq: \n u_dis, u_node = heapq.heappo...
{"fn_name": "shortest", "inputs": [[4, [[0, 1, 1], [0, 2, 5], [0, 3, 5], [1, 3, 3], [2, 3, 1]]], [3, [[0, 1, 7], [1, 2, 5], [0, 2, 12]]], [5, [[0, 2, 1], [1, 2, 1], [0, 3, 1], [1, 4, 1]]]], "outputs": [[4], [12], [-1]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,193
def shortest(N, edgeList):
e184aac12ff45976325fde5bff16c37e
UNKNOWN
You will be given two strings `a` and `b` consisting of lower case letters, but `a` will have at most one asterix character. The asterix (if any) can be replaced with an arbitrary sequence (possibly empty) of lowercase letters. No other character of string `a` can be replaced. If it is possible to replace the asterix i...
["from fnmatch import fnmatch\n\ndef solve(a, b):\n return fnmatch(b, a)", "import re\ndef solve(a,b):\n return bool(re.fullmatch(a.replace('*', '.*'), b))", "def solve(a,b):\n if a == b: return True\n if \"*\" not in a: return False\n \n sides = a.split(\"*\")\n missing = b[len(sides[0]):len(b)-len(sides[1]...
{"fn_name": "solve", "inputs": [["code*s", "codewars"], ["codewar*s", "codewars"], ["code*warrior", "codewars"], ["c", "c"], ["*s", "codewars"], ["*s", "s"], ["s*", "s"], ["aa", "aaa"], ["aa*", "aaa"], ["aaa", "aa"], ["aaa*", "aa"], ["*", "codewars"], ["aaa*aaa", "aaa"]], "outputs": [[true], [true], [false], [true], [t...
INTRODUCTORY
PYTHON3
CODEWARS
1,430
def solve(a,b):
89caf16541b5e8e09e746961cf737c9a
UNKNOWN
Freddy has a really fat left pinky finger, and every time Freddy tries to type an ```A```, he accidentally hits the CapsLock key! Given a string that Freddy wants to type, emulate the keyboard misses where each ```A``` supposedly pressed is replaced with CapsLock, and return the string that Freddy actually types. It d...
["def fat_fingers(s):\n if not s: return s\n swap = [False]\n return ''.join( c.swapcase() if swap[0] else c for c in s \n if c not in \"aA\" or swap.__setitem__(0, not swap[0]) )", "import re\n\ndef fat_fingers(string):\n return ''.join(w.swapcase() if i%2 else w for i, w in enumerate(re.s...
{"fn_name": "fat_fingers", "inputs": [["aAaaaaAaaaAAaAa"], ["The end of the institution, maintenance, and administration of government, is to secure the existence of the body politic, to protect it, and to furnish the individuals who compose it with the power of enjoying in safety and tranquillity their natural rights,...
INTRODUCTORY
PYTHON3
CODEWARS
2,891
def fat_fingers(string):
381f33a2d533d745558ffb3867239310
UNKNOWN
In telecomunications we use information coding to detect and prevent errors while sending data. A parity bit is a bit added to a string of binary code that indicates whether the number of 1-bits in the string is even or odd. Parity bits are used as the simplest form of error detecting code, and can detect a 1 bit err...
["def parity_bit(binary):\n return ' '.join(byte[:-1] if byte.count('1') % 2 == 0 else 'error' for byte in binary.split())", "def parity_bit(binary):\n return \" \".join(\"error\" if byte.count(\"1\") & 1 else byte[:-1] for byte in binary.split())", "def decode(binary):\n *b, p = binary\n if '01'[b.count('1...
{"fn_name": "parity_bit", "inputs": [["01011001"], ["00110001"], ["11111111"], ["00000000"], ["11100111"], ["00111100 00111101"], ["00001111 11100001"], ["01011110 00011000"], ["11111111 11011100 11100011"], ["00111110 00110100 00111011"], ["01101110 01100000 01010110 10001111 01100011"], ["10100011 00111001 11001100 0...
INTRODUCTORY
PYTHON3
CODEWARS
1,860
def parity_bit(binary):
0d0d6b4b1c09c28b7393acad6bcc06be
UNKNOWN
## Overview Resistors are electrical components marked with colorful stripes/bands to indicate both their resistance value in ohms and how tight a tolerance that value has. If you did my Resistor Color Codes kata, you wrote a function which took a string containing a resistor's band colors, and returned a string identi...
["c='black brown red orange yellow green blue violet gray white'.split()\ndef encode_resistor_colors(ohms_string):\n ohms = str(int(eval(ohms_string.replace('k', '*1000').replace('M', '*1000000').split()[0])))\n return '%s %s %s gold' % (c[int(ohms[0])], c[int(ohms[1])], c[len(ohms[2:])])", "COLORS = {'0': 'bla...
{"fn_name": "encode_resistor_colors", "inputs": [["10 ohms"], ["47 ohms"], ["100 ohms"], ["220 ohms"], ["330 ohms"], ["470 ohms"], ["680 ohms"], ["1k ohms"], ["4.7k ohms"], ["10k ohms"], ["22k ohms"], ["47k ohms"], ["100k ohms"], ["330k ohms"], ["1M ohms"], ["2M ohms"]], "outputs": [["brown black black gold"], ["yellow...
INTRODUCTORY
PYTHON3
CODEWARS
6,457
def encode_resistor_colors(ohms_string):
f1d93d57e6bd92693c685ebfbe2b4efb
UNKNOWN
Your task is to determine the top 3 place finishes in a pole vault competition involving several different competitors. This is isn't always so simple, and it is often a source of confusion for people who don't know the actual rules. Here's what you need to know: As input, you will receive an array of objects. Each o...
["def score_pole_vault(vaulter_list):\n popytki = len(vaulter_list[0][\"results\"])\n temp = {}\n res = {}\n for mas in vaulter_list:\n i = popytki - 1\n while i >= 0 and mas[\"results\"][i].find('O') == -1:\n i -= 1\n if i < 0:\n n = 0\n m = ''.join(mas...
{"fn_name": "score_pole_vault", "inputs": [[[{"name": "Linda", "results": ["XXO", "O", "XXO", "O"]}, {"name": "Vickie", "results": ["O", "X", "", ""]}, {"name": "Debbie", "results": ["XXO", "O", "XO", "XXX"]}, {"name": "Michelle", "results": ["XO", "XO", "XXX", ""]}, {"name": "Carol", "results": ["XXX", "", "", ""]}]],...
INTRODUCTORY
PYTHON3
CODEWARS
14,451
def score_pole_vault(vaulter_list):
0e312a53bbcfdf05fd83869ccd3eaeba
UNKNOWN
An anagram is a word, a phrase, or a sentence formed from another by rearranging its letters. An example of this is "angel", which is an anagram of "glean". Write a function that receives an array of words, and returns the total number of distinct pairs of anagramic words inside it. Some examples: - There are 2 anag...
["from collections import Counter\n\ndef anagram_counter(words):\n return sum(n*(n-1)// 2 for n in Counter(''.join(sorted(x)) for x in words).values())", "def anagram_counter(words):\n def is_anagrams(s1, s2): return sorted(s1) == sorted(s2)\n return 0 if not words else sum([1 for x in range(len(words)-1) for ...
{"fn_name": "anagram_counter", "inputs": [[[]], [["dell", "ledl", "abc", "cba"]], [["dell", "ledl", "lled", "cba"]], [["dell", "ledl", "abc", "cba", "bca", "bac", "cab"]]], "outputs": [[0], [2], [3], [11]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,884
def anagram_counter(words):
75368dc016aca49d26409533c065e839
UNKNOWN
# RoboScript #1 - Implement Syntax Highlighting ## Disclaimer The story presented in this Kata Series is purely fictional; any resemblance to actual programming languages, products, organisations or people should be treated as purely coincidental. ## About this Kata Series This Kata Series is based on a fictional s...
["import re\ndef highlight(code):\n code = re.sub(r\"(F+)\", '<span style=\"color: pink\">\\g<1></span>', code)\n code = re.sub(r\"(L+)\", '<span style=\"color: red\">\\g<1></span>', code)\n code = re.sub(r\"(R+)\", '<span style=\"color: green\">\\g<1></span>', code)\n code = re.sub(r\"(\\d+)\", '<span styl...
{"fn_name": "highlight", "inputs": [["F3RF5LF7"], ["FFFR345F2LL"], ["RRRRRF45L3F2"], ["RRRRR(F45L3)F2"], ["FF(LF6(RF3)2)3"]], "outputs": [["<span style=\"color: pink\">F</span><span style=\"color: orange\">3</span><span style=\"color: green\">R</span><span style=\"color: pink\">F</span><span style=\"color: orange\">5</...
INTRODUCTORY
PYTHON3
CODEWARS
3,691
def highlight(code):
32b2832a6e623c1d55af0e0fa6e33bea
UNKNOWN
In this Kata, you will be given two numbers, `a` and `b`, and your task is to determine if the first number `a` is divisible by `all` the prime factors of the second number `b`. For example: `solve(15,12) = False` because `15` is not divisible by all the prime factors of `12` (which include`2`). See test cases for mor...
["import fractions\n\ndef solve(a, b):\n c = fractions.gcd(a, b)\n while c > 1:\n b //= c\n c = fractions.gcd(a, b)\n return b == 1", "from math import gcd\n\n\ndef solve(a, b):\n while 1 < gcd(a, b):\n b = b // gcd(a, b)\n return b == 1\n", "from math import gcd\n\ndef solve(a, b):\...
{"fn_name": "solve", "inputs": [[2, 256], [2, 253], [9, 243], [15, 12], [21, 2893401], [21, 2893406], [54, 2834352], [54, 2834359], [1000013, 7187761], [1000013, 7187762]], "outputs": [[true], [false], [true], [false], [true], [false], [true], [false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,321
def solve(a,b):
78d1c9ce2871c18ccd800511b4ec36f2
UNKNOWN
A strongness of an even number is the number of times we can successively divide by 2 until we reach an odd number starting with an even number n. For example, if n = 12, then * 12 / 2 = 6 * 6 / 2 = 3 So we divided successively 2 times and we reached 3, so the strongness of 12 is `2`. If n = 16 then * 16 / 2 = 8 * 8...
["\"\"\"Strongest even number in an interval kata\n\nDefines strongest_even(n, m) which returns the strongest even number in the set\nof integers on the interval [n, m].\n\nConstraints:\n 1. 1 <= n < m < MAX_INT\n\nNote:\n 1. The evenness of zero is need not be defined given the constraints.\n 2. In Python 3, ...
{"fn_name": "strongest_even", "inputs": [[1, 2], [5, 10], [48, 56], [129, 193], [2, 3], [4, 6], [3, 310], [33, 40], [456445, 678860], [324243, 897653214], [1151592177, 2129680158], [2085422641, 2128923730], [1082012216, 1876572332], [1806570867, 2067832928], [206346325, 1289058842]], "outputs": [[2], [8], [48], [192], ...
INTRODUCTORY
PYTHON3
CODEWARS
4,038
def strongest_even(n, m):
c549e62f397f9b32588884ae2508b3bf
UNKNOWN
Inspired by the development team at Vooza, write the function `howManyLightsabersDoYouOwn`/`how_many_light_sabers_do_you_own` that * accepts the name of a programmer, and * returns the number of lightsabers owned by that person. The only person who owns lightsabers is Zach, by the way. He owns 18, which is an awesom...
["def how_many_light_sabers_do_you_own(name=\"\"):\n return (18 if name==\"Zach\" else 0)", "how_many_light_sabers_do_you_own=lambda n='': 18 if n=='Zach' else 0", "def how_many_light_sabers_do_you_own(name='haha'):\n return 18 if name=='Zach' else 0", "def how_many_light_sabers_do_you_own(name=''):\n switch =...
{"fn_name": "how_many_light_sabers_do_you_own", "inputs": [["Zach"], ["zach"]], "outputs": [[18], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
9,745
def how_many_light_sabers_do_you_own(*name):
0bd7da6d86fd671133e54b43375dceac
UNKNOWN
**Getting Familiar:** LEET: (sometimes written as "1337" or "l33t"), also known as eleet or leetspeak, is another alphabet for the English language that is used mostly on the internet. It uses various combinations of ASCII characters to replace Latinate letters. For example, leet spellings of the word leet include 1337...
["def gr33k_l33t(string):\n gl = { \"a\":\"\u03b1\", \"b\":\"\u03b2\", \"d\":\"\u03b4\", \"e\":\"\u03b5\", \"i\":\"\u03b9\", \"k\":\"\u03ba\", \"n\":\"\u03b7\", \"o\":\"\u03b8\", \n \"p\":\"\u03c1\", \"r\":\"\u03c0\", \"t\":\"\u03c4\", \"u\":\"\u03bc\", \"v\":\"\u03c5\", \"w\":\"\u03c9\", \"x\":\"\u03c7\...
{"fn_name": "gr33k_l33t", "inputs": [["codewars"], ["kata"], ["kumite"], ["greekleet"], ["This Kata's Sensei is Divyansh"], ["Any reviews about CS50"], ["Man is still the most extraordinary computer of all."], ["I do not fear computers. I fear the lack of them."], ["Do you also think these quotes are conflicting each o...
INTRODUCTORY
PYTHON3
CODEWARS
2,990
def gr33k_l33t(string):
b832095f384c4fc6316716e3dc5234f5
UNKNOWN
# Task Two integer numbers are added using the column addition method. When using this method, some additions of digits produce non-zero carries to the next positions. Your task is to calculate the number of non-zero carries that will occur while adding the given numbers. The numbers are added in base 10. # Example...
["def number_of_carries(a, b):\n ans, carrie = 0, 0\n while a > 0 or b > 0:\n carrie = (a%10 + b%10 + carrie) // 10 \n ans += [0,1][carrie > 0]\n a //= 10\n b //= 10\n return ans", "def number_of_carries(a, b):\n i=1\n carry_over=0\n counter=0\n length1=len(str(a))\n ...
{"fn_name": "number_of_carries", "inputs": [[543, 3456], [1927, 6426], [9999, 1], [1234, 5678]], "outputs": [[0], [2], [4], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,841
def number_of_carries(a, b):
301e6d672e7462b9ffa1d53e1d2302ab
UNKNOWN
Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized **only** if the original word was capitalized (known as Upper Camel Case, also often referred to as Pascal case). ## Examples ```python to_camel_case("the-stealth...
["def to_camel_case(text):\n removed = text.replace('-', ' ').replace('_', ' ').split()\n if len(removed) == 0:\n return ''\n return removed[0]+ ''.join([x.capitalize() for x in removed[1:]])", "import re\ndef to_camel_case(text):\n return re.sub('[_-](.)', lambda x: x.group(1).upper(), text)", "def ...
{"fn_name": "to_camel_case", "inputs": [[""], ["the_stealth_warrior"], ["The-Stealth-Warrior"], ["A-B-C"]], "outputs": [[""], ["theStealthWarrior"], ["TheStealthWarrior"], ["ABC"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,341
def to_camel_case(text):
7120875140b74e1f3f688480aaea89b6
UNKNOWN
The number n is Evil if it has an even number of 1's in its binary representation. The first few Evil numbers: 3, 5, 6, 9, 10, 12, 15, 17, 18, 20 The number n is Odious if it has an odd number of 1's in its binary representation. The first few Odious numbers: 1, 2, 4, 7, 8, 11, 13, 14, 16, 19 You have to write a functi...
["def evil(n):\n return \"It's %s!\" % [\"Evil\",\"Odious\"][bin(n).count(\"1\")%2]", "def evil(n):\n return \"It's Evil!\" if bin(n).count('1')%2 == 0 else \"It's Odious!\"", "def evil(n):\n return 'It\\'s {}!'.format(('Evil', 'Odious')[bin(n).count('1') % 2])\n", "def evil(n):\n count = 0\n while n:\n...
{"fn_name": "evil", "inputs": [[1], [2], [3]], "outputs": [["It's Odious!"], ["It's Odious!"], ["It's Evil!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
16,920
def evil(n):
a780511a5fbd6c228cf42d5d3867028a
UNKNOWN
# Task You are given a car odometer which displays the miles traveled as an integer. The odometer has a defect, however: it proceeds from digit `3` to digit `5` always skipping the digit `4`. This defect shows up in all positions (ones, tens, hundreds, etc). For example, if the odometer displays `15339` and th...
["tr=str.maketrans('56789','45678')\n\ndef faulty_odometer(n):\n return int(str(n).translate(tr),9)", "def faulty_odometer(n):\n result = 0\n digits = len(str(n))\n nonaryTranslation = \"\".join([str(int(x)-1) if int(x) >= 5 else x for x in list(str(n))])\n for i in nonaryTranslation:\n digits -= ...
{"fn_name": "faulty_odometer", "inputs": [[13], [15], [55], [2005], [1500], [999999], [165826622]], "outputs": [[12], [13], [40], [1462], [1053], [531440], [69517865]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,516
def faulty_odometer(n):
23f0ca5cbcacfb2760d1fb6fb25b8767
UNKNOWN
Given a string, s, return a new string that orders the characters in order of frequency. The returned string should have the same number of characters as the original string. Make your transformation stable, meaning characters that compare equal should stay in their original order in the string s. ```python most_...
["from collections import Counter\n\ndef most_common(s):\n count = Counter(s)\n return ''.join(sorted(s, key=lambda c: -count[c]))", "def most_common(s):\n return ''.join(sorted(s, key = s.count, reverse = True))", "def most_common(stg):\n return \"\".join(sorted(stg, key=stg.count, reverse=True))", "def mo...
{"fn_name": "most_common", "inputs": [["Hello world"], [""], ["wubz dermatoglyphics"], ["Four score and seven years ago"], ["Hello He worldwrd"]], "outputs": [["lllooHe wrd"], [""], ["wubz dermatoglyphics"], [" eeeeorsorasarsaonnFucdvyg"], ["lllHeo He wordwrd"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,152
def most_common(s):
ce6a1fa2fc9893290c2a851866b2f67d
UNKNOWN
In this kata, you will be given a string of text and valid parentheses, such as `"h(el)lo"`. You must return the string, with only the text inside parentheses reversed, so `"h(el)lo"` becomes `"h(le)lo"`. However, if said parenthesized text contains parenthesized text itself, then that too must reversed back, so it fac...
["def reverse_in_parentheses(s):\n stack = []\n for i in s:\n stack.append(i)\n \n if i == ')':\n opening = len(stack) - stack[::-1].index('(') - 1\n stack.append(''.join([i[::-1].translate(str.maketrans('()',')(')) for i in stack[opening:][::-1]])) \n del st...
{"fn_name": "reverse_in_parentheses", "inputs": [["h(el)lo"], ["a ((d e) c b)"], ["one (two (three) four)"], ["one (ruof ((rht)ee) owt)"], [""], ["many (parens) on (top)"], ["( ( ) (()) )"]], "outputs": [["h(le)lo"], ["a (b c (d e))"], ["one (ruof (three) owt)"], ["one (two ((thr)ee) four)"], [""], ["many (snerap) on (...
INTRODUCTORY
PYTHON3
CODEWARS
4,817
def reverse_in_parentheses(string):
93a3e87100c5ace16506a9baf707eb5c
UNKNOWN
You're writing an excruciatingly detailed alternate history novel set in a world where [Daniel Gabriel Fahrenheit](https://en.wikipedia.org/wiki/Daniel_Gabriel_Fahrenheit) was never born. Since Fahrenheit never lived the world kept on using the [Rømer scale](https://en.wikipedia.org/wiki/R%C3%B8mer_scale), invented by...
["def celsius_to_romer(temp):\n # Converts temperature in degrees Celsius to degrees Romer\n return (temp * 21 / 40) + 7.5\n", "def celsius_to_romer(temp):\n return temp * 21 / 40 + 7.5\n", "def celsius_to_romer(c):\n return c * 21 / 40 + 7.5 ", "def celsius_to_romer(x):\n return x * 21 / 40 + 7.5", "def...
{"fn_name": "celsius_to_romer", "inputs": [[24], [8], [29]], "outputs": [[20.1], [11.7], [22.725]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,081
def celsius_to_romer(temp):
b576bb7d414ebf950e5cec3f71438288
UNKNOWN
You have invented a time-machine which has taken you back to ancient Rome. Caeser is impressed with your programming skills and has appointed you to be the new information security officer. Caeser has ordered you to write a Caeser cipher to prevent Asterix and Obelix from reading his emails. A Caeser cipher shifts th...
["def caeser(message, key):\n return ''.join(chr(65 + (ord(c.upper()) + key - 65) % 26) if c.isalpha() else c for c in message)", "def caeser(message, key):\n return ''.join(chr(ord(x)+key if ord(x)+key <= 122 else ord(x)+key-122 + 96).upper() if x.isalpha() else x for x in message)", "import string\n\ndef caeser...
{"fn_name": "caeser", "inputs": [["This is a message", 0], ["who are you?", 18], ["..5tyu..", 25], ["..#$%^..", 0], ["..#$%^..", 26], ["final one", 9]], "outputs": [["THIS IS A MESSAGE"], ["OZG SJW QGM?"], ["..5SXT.."], ["..#$%^.."], ["..#$%^.."], ["ORWJU XWN"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,437
def caeser(message, key):
6c639b06057f18f50b57048c5fd94b8d
UNKNOWN
### Longest Palindrome Find the length of the longest substring in the given string `s` that is the same in reverse. As an example, if the input was “I like racecars that go fast”, the substring (`racecar`) length would be `7`. If the length of the input string is `0`, the return value must be `0`. ### Ex...
["\"\"\"\n***************************************\n* O(n) time complexity solution ! *\n***************************************\n\"\"\"\n\ndef longest_palindrome (s):\n\n maxPal, tmpPal = 0, 1\n count_dct = {}\n inPal = False\n \n for i,l in enumerate(s):\n \n count_dct[l] = count_dct.get(l...
{"fn_name": "longest_palindrome", "inputs": [["a"], ["aa"], ["baa"], ["aab"], ["baabcd"], ["baablkj12345432133d"], ["I like racecars that go fast"], ["abcdefghba"], [""], ["FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalN...
INTRODUCTORY
PYTHON3
CODEWARS
1,962
def longest_palindrome (s):
ed2b3c72e6d3e111621c61487a4c45fa
UNKNOWN
>When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said # Description: Give you two number `m` and `n`(two positive integer, m < n), make a triangle pattern with number sequence `m to n`. The order is clockwise, starting from ...
["def make_triangle(m,n):\n lns, sm = 0, 0\n while sm < n - m + 1:\n lns += 1\n sm += lns\n if sm > n - m + 1: return \"\"\n matrix = [[0] * (i + 1) for i in range(lns)]\n y, x, s = 0, 0, 0\n ds = ((1, 1), (0, -1), (-1, 0))\n dy, dx = ds[s]\n for i in range(m, n + 1):\n matr...
{"fn_name": "make_triangle", "inputs": [[1, 12], [1, 100]], "outputs": [[""], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
10,366
def make_triangle(m,n):
d48cf185f76a9d37581ad934b73c537b
UNKNOWN
Consider an array containing cats and dogs. Each dog can catch only one cat, but cannot catch a cat that is more than `n` elements away. Your task will be to return the maximum number of cats that can be caught. For example: ```Haskell solve(['D','C','C','D','C'], 2) = 2, because the dog at index 0 (D0) catches C1 and...
["def solve(arr, reach):\n dogs, nCats = {i for i,x in enumerate(arr) if x=='D'}, 0\n for i,c in enumerate(arr):\n if c == 'C':\n catchingDog = next((i+id for id in range(-reach,reach+1) if i+id in dogs), None)\n if catchingDog is not None:\n nCats += 1\n ...
{"fn_name": "solve", "inputs": [[["D", "C", "C", "D", "C"], 1], [["C", "C", "D", "D", "C", "D"], 2], [["C", "C", "D", "D", "C", "D"], 1], [["D", "C", "D", "C", "C", "D"], 3], [["C", "C", "C", "D", "D"], 3], [["C", "C", "C", "D", "D"], 2], [["C", "C", "C", "D", "D"], 1], [["C", "C", "C", "D", "D", "D", "C", "D", "D", "D...
INTRODUCTORY
PYTHON3
CODEWARS
3,321
def solve(arr,n):
dddc44d246a450b28cb7274e3b81e88c
UNKNOWN
Your friend won't stop texting his girlfriend. It's all he does. All day. Seriously. The texts are so mushy too! The whole situation just makes you feel ill. Being the wonderful friend that you are, you hatch an evil plot. While he's sleeping, you take his phone and change the autocorrect options so that every time ...
["import re\n\ndef autocorrect(input):\n return re.sub(r'(?i)\\b(u|you+)\\b', \"your sister\", input)", "from re import sub, I\n\ndef autocorrect(input):\n return sub(r'\\b(you+|u)\\b', 'your sister', input, flags=I)", "import re\ndef autocorrect(input):\n return re.sub(r'(?i)\\b(you+|u)\\b', 'your sister', in...
{"fn_name": "autocorrect", "inputs": [["I miss you!"], ["u want to go to the movies?"], ["Can't wait to see youuuuu"], ["I want to film the bayou with you and put it on youtube"], ["You should come over Friday night"], ["You u youville utube you youyouyou uuu raiyou united youuuu u you"]], "outputs": [["I miss your sis...
INTRODUCTORY
PYTHON3
CODEWARS
1,571
def autocorrect(input):
27c3c26fb7478cd9b3b8de4c5794fdb5
UNKNOWN
## Task You need to implement two functions, `xor` and `or`, that replicate the behaviour of their respective operators: - `xor` = Takes 2 values and returns `true` if, and only if, one of them is truthy. - `or` = Takes 2 values and returns `true` if either one of them is truthy. When doing so, **you cannot use the o...
["def func_or(a, b):\n return not (bool(a) == bool(b) == False)\n\ndef func_xor(a, b):\n return not (bool(a) == bool(b))", "def func_or(a,b):\n return bool(a) | bool(b)\n\ndef func_xor(a,b):\n return bool(a) ^ bool(b)", "def func_or(a, b):\n return bool(a) + bool(b) > 0\n\ndef func_xor(a, b):\n return...
{"fn_name": "func_or", "inputs": [[true, true], [true, false], [false, false], [0, 11], [null, []]], "outputs": [[true], [true], [false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,176
def func_or(a,b):
8a3d3353020504d4b9dbad33666a5dca
UNKNOWN
Write a function which reduces fractions to their simplest form! Fractions will be presented as an array/tuple (depending on the language), and the reduced fraction must be returned as an array/tuple: ``` input: [numerator, denominator] output: [newNumerator, newDenominator] example: [45, 120] --> [3, 8] ``` All n...
["from fractions import Fraction\ndef reduce_fraction(fraction):\n t = Fraction(*fraction)\n return (t.numerator, t.denominator)", "def gcd(a, b):\n return a if b == 0 else gcd(b, a % b)\n \ndef reduce_fraction(fraction):\n num, denom = fraction\n gcd_num_denom = gcd(num, denom)\n return (num // gc...
{"fn_name": "reduce_fraction", "inputs": [[[60, 20]], [[80, 120]], [[4, 2]], [[45, 120]], [[1000, 1]], [[1, 1]], [[10956590, 13611876]], [[35884747, 5576447]], [[24622321, 24473455]], [[4255316, 11425973]]], "outputs": [[[3, 1]], [[2, 3]], [[2, 1]], [[3, 8]], [[1000, 1]], [[1, 1]], [[30605, 38022]], [[76841, 11941]], [...
INTRODUCTORY
PYTHON3
CODEWARS
2,077
def reduce_fraction(fraction):
c80da313e544cb90e295e8344befbfff
UNKNOWN
ASC Week 1 Challenge 4 (Medium #1) Write a function that converts any sentence into a V A P O R W A V E sentence. a V A P O R W A V E sentence converts all the letters into uppercase, and adds 2 spaces between each letter (or special character) to create this V A P O R W A V E effect. Example...
["def vaporcode(s):\n return \" \".join(s.replace(\" \", \"\").upper())", "def vaporcode(s):\n string = ''\n s = ''.join(s.split()).upper()\n for c in s:\n string += c + ' '\n return string[:-2]", "vaporcode = lambda s: \" \".join(list(s.replace(\" \", \"\").upper()))", "def vaporcode(s):\n ...
{"fn_name": "vaporcode", "inputs": [["Lets go to the movies"], ["Why isn't my code working?"]], "outputs": [["L E T S G O T O T H E M O V I E S"], ["W H Y I S N ' T M Y C O D E W O R K I N G ?"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,121
def vaporcode(s):
e0aa27a7a8cce4a9c43c0aab85bfeb31
UNKNOWN
It's March and you just can't seem to get your mind off brackets. However, it is not due to basketball. You need to extract statements within strings that are contained within brackets. You have to write a function that returns a list of statements that are contained within brackets given a string. If the value entere...
["import re\n\nREGEX = re.compile(r'\\[(.*?)\\]')\n\n\ndef bracket_buster(strng):\n try:\n return REGEX.findall(strng)\n except TypeError:\n return 'Take a seat on the bench.'\n", "from re import findall\n\ndef bracket_buster(s):\n return \"Take a seat on the bench.\" if type(s) is not str else f...
{"fn_name": "bracket_buster", "inputs": [[[1, 2, 3]], [{"3": 4}], [false], [23.45], ["arc.tic.[circle]?[?]"], ["Big [L][e][B][r][o][n]!][["], ["[][]]]][[[[[[][]"], ["logger?]?system...12.12.133333 at [12-32-1432-16]"]], "outputs": [["Take a seat on the bench."], ["Take a seat on the bench."], ["Take a seat on the bench...
INTRODUCTORY
PYTHON3
CODEWARS
1,887
def bracket_buster(string):
326f5b61a822a76d9c25bb756ac79468
UNKNOWN
The [Sharkovsky's Theorem](https://en.wikipedia.org/wiki/Sharkovskii%27s_theorem) involves the following ordering of the natural numbers: ```math 3≺5≺7≺9≺ ...\\ ≺2·3≺2·5≺2·7≺2·9≺...\\ ≺2^n·3≺2^n·5≺2^n·7≺2^n·9≺...\\ ≺2^{(n+1)}·3≺2^{(n+1)}·5≺2^{(n+1)}·7≺2^{(n+1)}·9≺...\\ ≺2^n≺2^{(n-1)}≺...\\ ≺4≺2≺1\\ ``` Your task is t...
["def sharkovsky(a, b): return f(a)<f(b)\n\ndef f(n,p=0):\n while n%2==0:\n n>>=1\n p+=1\n return n==1, p*(-1)**(n==1), n", "def analyse(x):\n n = (b := bin(x)).rstrip(\"0\")\n p = len(b) - len(n)\n return (n := int(n, 2)) == 1, p * (-1)**(n == 1), n\n\n\ndef sharkovsky(a, b):\n return ...
{"fn_name": "sharkovsky", "inputs": [[18, 12], [3, 9], [10, 16], [1, 22], [32, 1024], [17, 17]], "outputs": [[true], [true], [true], [false], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
12,641
def sharkovsky(a, b):
fb0ea44822a4a4f2c6e3233cd8401084
UNKNOWN
You will be given a string. You need to return an array of three strings by gradually pulling apart the string. You should repeat the following steps until the string length is 1: a) remove the final character from the original string, add to solution string 1. b) remove the first character from the original string...
["def pop_shift(s):\n l1 = list(s); l2 = []; l3 = []\n while len(l1) > 1:\n l2.append(l1.pop())\n l3.append(l1.pop(0))\n return [\"\".join(l2),\"\".join(l3),\"\".join(l1)]", "def pop_shift(s):\n il, ir = len(s) // 2, (len(s) + 1) // 2\n return [s[:ir-1:-1], s[:il], s[il:ir]]", "def pop_shif...
{"fn_name": "pop_shift", "inputs": [["reusetestcasesbitcointakeovertheworldmaybewhoknowsperhaps"], ["turnsoutrandomtestcasesareeasierthanwritingoutbasicones"], ["exampletesthere"], ["letstalkaboutjavascriptthebestlanguage"], ["iwanttotraveltheworldwritingcodeoneday"], ["letsallgoonholidaysomewhereverycold"]], "outputs"...
INTRODUCTORY
PYTHON3
CODEWARS
1,443
def pop_shift(s):
ad5c2060327d322dc9f675db2103f721
UNKNOWN
**Background** You most probably know, that the *kilo* used by IT-People differs from the *kilo* used by the rest of the world. Whereas *kilo* in kB is (mostly) intrepreted as 1024 Bytes (especially by operating systems) the non-IT *kilo* denotes the factor 1000 (as in "1 kg is 1000g"). The same goes for the prefixe...
["def memorysize_conversion(memorysize):\n [value, unit] = memorysize.split(\" \")\n kibis = [\"KiB\", \"MiB\", \"GiB\", \"TiB\"]\n kilos = [\"kB\", \"MB\", \"GB\", \"TB\"]\n if unit in kibis:\n return (str(round(float(value)*pow(1.024, kibis.index(unit)+1), 3))+\" \"+kilos[kibis.index(unit)])\n e...
{"fn_name": "memorysize_conversion", "inputs": [["1 KiB"]], "outputs": [["1.024 kB"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,821
def memorysize_conversion(memorysize):
33e75d0a85ace734b7d831219eafd6de
UNKNOWN
Create a function which checks a number for three different properties. - is the number prime? - is the number even? - is the number a multiple of 10? Each should return either true or false, which should be given as an array. Remark: The Haskell variant uses `data Property`. ### Examples ```python number_property(7...
["import math\n\ndef number_property(n):\n return [isPrime(n), isEven(n), isMultipleOf10(n)]\n # Return isPrime? isEven? isMultipleOf10?\n #your code here\n\ndef isPrime(n):\n if n <= 3:\n return n >= 2\n if n % 2 == 0 or n % 3 == 0:\n return False\n for i in range(5, int(n ** 0.5) + 1, ...
{"fn_name": "number_property", "inputs": [[0], [2], [5], [25], [131], [1], [100], [179424691], [179424693]], "outputs": [[[false, true, true]], [[true, true, false]], [[true, false, false]], [[false, false, false]], [[true, false, false]], [[false, false, false]], [[false, true, true]], [[true, false, false]], [[false,...
INTRODUCTORY
PYTHON3
CODEWARS
2,074
def number_property(n):
ca771be734043144f951e73b3bf080a0
UNKNOWN
There is an array of strings. All strings contains similar _letters_ except one. Try to find it! ```python find_uniq([ 'Aa', 'aaa', 'aaaaa', 'BbBb', 'Aaaa', 'AaAaAa', 'a' ]) # => 'BbBb' find_uniq([ 'abc', 'acb', 'bac', 'foo', 'bca', 'cab', 'cba' ]) # => 'foo' ``` Strings may contain spaces. Spaces is not significant,...
["from collections import defaultdict\n\ndef find_uniq(a):\n d = {}\n c = defaultdict(int)\n for e in a:\n t = frozenset(e.strip().lower())\n d[t] = e\n c[t] += 1\n \n return d[next(filter(lambda k: c[k] == 1, c))]", "def find_uniq(arr):\n if set(arr[0].lower()) == set(arr[1].lowe...
{"fn_name": "find_uniq", "inputs": [[["Aa", "aaa", "aaaaa", "BbBb", "Aaaa", "AaAaAa", "a"]], [["abc", "acb", "bac", "foo", "bca", "cab", "cba"]], [["silvia", "vasili", "victor"]], [["Tom Marvolo Riddle", "I am Lord Voldemort", "Harry Potter"]], [["", "", "", "a", "", ""]], [[" ", " ", " ", "a", " ", ""]], [["foobar...
INTRODUCTORY
PYTHON3
CODEWARS
2,075
def find_uniq(arr):
209c8983fbfa6ea1062ee82cf6a4c713
UNKNOWN
Given two integers `a` and `x`, return the minimum non-negative number to **add to** / **subtract from** `a` to make it a multiple of `x`. ```python minimum(10, 6) #= 2 10+2 = 12 which is a multiple of 6 ``` ## Note - 0 is always a multiple of `x` ## Constraints **1 <= a <= 10^(6)** **1 <= x <= 10^(5)**
["def minimum(a, x):\n return min(a % x, -a % x)", "def minimum(a, x):\n return min(x-a%x, a%x)\n", "def minimum(a, x):\n return abs(a - x*round(a/x))\n", "def minimum(a, x):\n return min(a%x, abs(x - a%x))\n", "def minimum(a, x):\n r = a % x\n return r and min(r, x - r)", "def minimum(a, x):\n ret...
{"fn_name": "minimum", "inputs": [[9, 4], [10, 6]], "outputs": [[1], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
701
def minimum(a, x):
865839a26e6217d41923f3a7f59e7f08
UNKNOWN
Your colleagues have been looking over you shoulder. When you should have been doing your boring real job, you've been using the work computers to smash in endless hours of codewars. In a team meeting, a terrible, awful person declares to the group that you aren't working. You're in trouble. You quickly have to gauge ...
["def outed(meet, boss):\n return 'Get Out Now!' if (sum(meet.values()) + meet[boss] ) / len(meet) <= 5 else 'Nice Work Champ!'", "def outed(meet, boss):\n # sum of all people plus boss value, boss counts twice\n total_score = sum(meet.values()) + meet[boss]\n happiness_rating = total_score / len(meet)\n ...
{"fn_name": "outed", "inputs": [[{"tim": 0, "jim": 2, "randy": 0, "sandy": 7, "andy": 0, "katie": 5, "laura": 1, "saajid": 2, "alex": 3, "john": 2, "mr": 0}, "laura"], [{"tim": 1, "jim": 3, "randy": 9, "sandy": 6, "andy": 7, "katie": 6, "laura": 9, "saajid": 9, "alex": 9, "john": 9, "mr": 8}, "katie"], [{"tim": 2, "jim...
INTRODUCTORY
PYTHON3
CODEWARS
1,611
def outed(meet, boss):
b7816e85276cbee75a92b335fb29cc16
UNKNOWN
You receive some random elements as a space-delimited string. Check if the elements are part of an ascending sequence of integers starting with 1, with an increment of 1 (e.g. 1, 2, 3, 4). Return: * `0` if the elements can form such a sequence, and no number is missing ("not broken", e.g. `"1 2 4 3"`) * `1` if there ...
["def find_missing_number(sequence):\n if not sequence:\n return 0\n try:\n sequence = set(int(a) for a in sequence.split())\n except ValueError:\n return 1\n for b in range(1, max(sequence) + 1):\n if b not in sequence:\n return b\n return 0\n", "def find_missing_n...
{"fn_name": "find_missing_number", "inputs": [["1 2 3 5"], ["1 5"], [""], ["1 2 3 4 5"], ["2 3 4 5"], ["2 6 4 5 3"], ["_______"], ["2 1 4 3 a"], ["1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61...
INTRODUCTORY
PYTHON3
CODEWARS
32,935
def find_missing_number(sequence):
68e8313c239c5029c7d51ba6b5a8de30
UNKNOWN
When working with color values it can sometimes be useful to extract the individual red, green, and blue (RGB) component values for a color. Implement a function that meets these requirements: + Accepts a case-insensitive hexadecimal color string as its parameter (ex. `"#FF9933"` or `"#ff9933"`) + Returns an object wi...
["def hex_string_to_RGB(s): \n return {i:int(s[j:j+2],16) for i,j in zip('rgb',[1,3,5])}", "def hex_string_to_RGB(hex): \n return {'r': int(hex[1:3],16),'g': int(hex[3:5],16), 'b': int(hex[5:7],16)}", "def hex_string_to_RGB(s): \n return {c: int(s[1+2*i:3+2*i], 16) for i,c in enumerate('rgb')}", "def hex_strin...
{"fn_name": "hex_string_to_RGB", "inputs": [["#FF9933"], ["#beaded"], ["#000000"], ["#111111"], ["#Fa3456"]], "outputs": [[{"r": 255, "g": 153, "b": 51}], [{"r": 190, "g": 173, "b": 237}], [{"r": 0, "g": 0, "b": 0}], [{"r": 17, "g": 17, "b": 17}], [{"r": 250, "g": 52, "b": 86}]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,451
def hex_string_to_RGB(hex_string):
b785a2b1bb2a6872e9428c07d851e7c3
UNKNOWN
# Task `EvilCode` is a game similar to `Codewars`. You have to solve programming tasks as quickly as possible. However, unlike `Codewars`, `EvilCode` awards you with a medal, depending on the time you took to solve the task. To get a medal, your time must be (strictly) inferior to the time corresponding to the medal. ...
["def evil_code_medal(user_time, gold, silver, bronze):\n for medal, time in [[\"Gold\", gold], [\"Silver\", silver], [\"Bronze\", bronze]]:\n if user_time < time:\n return medal\n \n return \"None\"\n", "from bisect import bisect_right as bisect\n\nMEDALS = [\"Gold\", \"Silver\", \"B...
{"fn_name": "evil_code_medal", "inputs": [["00:30:00", "00:15:00", "00:45:00", "01:15:00"], ["01:15:00", "00:15:00", "00:45:00", "01:15:00"], ["00:00:01", "00:00:10", "00:01:40", "01:00:00"], ["00:10:01", "00:00:10", "00:01:40", "01:00:00"], ["00:00:01", "00:00:02", "00:00:03", "00:00:04"], ["90:00:01", "60:00:02", "70...
INTRODUCTORY
PYTHON3
CODEWARS
1,879
def evil_code_medal(user_time, gold, silver, bronze):
02d6a2b9453f7a7d295e17da1bd1bd19
UNKNOWN
In this Kata, you will be given a number and your task will be to rearrange the number so that it is divisible by `25`, but without leading zeros. Return the minimum number of digit moves that are needed to make this possible. If impossible, return `-1` ( `Nothing` in Haskell ). For example: More examples in test cas...
["def solve(n):\n moves = []\n for a, b in [\"25\", \"75\", \"50\", \"00\"]:\n s = str(n)[::-1]\n x = s.find(a)\n y = s.find(b, x+1 if a == \"0\" else 0)\n if x == -1 or y == -1:\n continue\n moves.append(x + y - (x > y) - (a == b))\n s = s.replace(a, \"\", 1)....
{"fn_name": "solve", "inputs": [[50], [25], [52], [57], [75], [100], [521], [1], [5071], [705], [1241367], [50011117], [1002], [50011111112], [2057], [50001111312], [500111117], [64954713879], [71255535569], [72046951686], [68151901446], [3848363615], [75733989998], [87364011400], [2992127830], [98262144757], [81737102...
INTRODUCTORY
PYTHON3
CODEWARS
12,700
def solve(n):
61bfb382c1729a8868f96755e1832f91
UNKNOWN
# Kata Task Given a list of random integers, return the Three Amigos. These are 3 numbers that live next to each other in the list, and who have the **most** in common with each other by these rules: * lowest statistical range * same parity # Notes * The list will contain at least 3 numbers * If there is more than ...
["def three_amigos(numbers):\n return min(\n ([a, b, c] for a, b, c in zip(numbers, numbers[1:], numbers[2:]) if a & 1 == b & 1 == c & 1), \n key=lambda triple: max(triple) - min(triple),\n default=[])", "three_amigos = lambda a: (sorted(((max(a[i:i+3])-min(a[i:i+3]), a[i:i+3]) for i in range(le...
{"fn_name": "three_amigos", "inputs": [[[1, 2, 34, 2, 1, 5, 3, 5, 7, 234, 2, 1]], [[2, 4, 6, 8, 10, 2, 2, 2, 1, 1, 1, 5, 3]], [[2, 4, 5, 3, 6, 3, 1, 56, 7, 6, 3, 12]], [[1, 3, 5]], [[1, 3, 2]], [[1, 3, 5, 7, 9, 11, 13, 15]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 3, 5]], [[-5, -4, -2, 0, 1, 2, 3, 4, 5]], [[-8, -25, 21, -7, -5...
INTRODUCTORY
PYTHON3
CODEWARS
2,874
def three_amigos(numbers):
c5b905bd2d31fc73d96b34e345369c9e
UNKNOWN
You are given an array of `n+1` integers `1` through `n`. In addition there is a single duplicate integer. The array is unsorted. An example valid array would be `[3, 2, 5, 1, 3, 4]`. It has the integers `1` through `5` and `3` is duplicated. `[1, 2, 4, 5, 5]` would not be valid as it is missing `3`. You should retu...
["def find_dup(arr):\n return sum(arr) - len(arr)*(len(arr)-1)/2\n #your code here\n", "def find_dup(arr):\n return max([i for i in arr if arr.count(i) > 1])", "from collections import Counter\nfind_dup = lambda xs: Counter(xs).most_common(1)[0][0]", "def find_dup(arr):\n return sum(arr) - len(arr) * (len(a...
{"fn_name": "find_dup", "inputs": [[[1, 1, 2, 3]], [[1, 2, 2, 3]], [[5, 4, 3, 2, 1, 1]], [[1, 3, 2, 5, 4, 5, 7, 6]], [[8, 2, 6, 3, 7, 2, 5, 1, 4]]], "outputs": [[1], [2], [1], [5], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
802
def find_dup(arr):
37593ae874208c88e106693e763f6c90
UNKNOWN
Character recognition software is widely used to digitise printed texts. Thus the texts can be edited, searched and stored on a computer. When documents (especially pretty old ones written with a typewriter), are digitised character recognition softwares often make mistakes. Your task is correct the errors in the dig...
["def correct(string):\n return string.translate(str.maketrans(\"501\", \"SOI\"))", "def correct(string):\n return string.replace('1','I').replace('0','O').replace('5','S')", "tr=str.maketrans('015','OIS')\n\ndef correct(string):\n return string.translate(tr)", "def correct(string):\n return string.replace(...
{"fn_name": "correct", "inputs": [["1F-RUDYARD K1PL1NG"], ["R0BERT MERLE - THE DAY 0F THE D0LPH1N"], ["R1CHARD P. FEYNMAN - THE FEYNMAN LECTURE5 0N PHY51C5"], ["R1CHARD P. FEYNMAN - 5TAT15T1CAL MECHAN1C5"], ["5TEPHEN HAWK1NG - A BR1EF H15T0RY 0F T1ME"], ["5TEPHEN HAWK1NG - THE UN1VER5E 1N A NUT5HELL"], ["ERNE5T HEM1NGW...
INTRODUCTORY
PYTHON3
CODEWARS
20,357
def correct(string):
cf8980c3cd164e4308d44fbaaabe8642
UNKNOWN
Write a function `titleToNumber(title) or title_to_number(title) or titleToNb title ...` (depending on the language) that given a column title as it appears in an Excel sheet, returns its corresponding column number. All column titles will be uppercase. Examples: ``` titleTonumber('A') === 1 titleTonumber('Z') ===...
["def title_to_number(title):\n ret = 0\n for i in title:\n ret = ret*26 + ord(i) - 64\n return ret", "def title_to_number(title):\n return sum((ord(c) - 64) * 26**i for i, c in enumerate(title[::-1]))", "def title_to_number(title):\n return sum((ord(char) - 64) * 26 ** i for i, char in enumerate(...
{"fn_name": "title_to_number", "inputs": [["A"], ["Z"], ["AA"], ["AZ"], ["BA"], ["CODEWARS"], ["ZZZTOP"], ["OYAJI"], ["LONELINESS"], ["UNFORGIVABLE"]], "outputs": [[1], [26], [27], [52], [53], [28779382963], [321268054], [7294985], [68400586976949], [79089429845931757]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,471
def title_to_number(title):
e5290cc12a630eabee9abdfcbd0cffeb
UNKNOWN
## Description Peter enjoys taking risks, and this time he has decided to take it up a notch! Peter asks his local barman to pour him **n** shots, after which Peter then puts laxatives in **x** of them. He then turns around and lets the barman shuffle the shots. Peter approaches the shots and drinks **a** of them one...
["from functools import reduce\ndef get_chance(n, x, a):\n return round(reduce(lambda m, b: m * (1 - x / (n - b)), range(a), 1), 2)", "def get_chance(n, x, a):\n r = 1\n z = n-x\n while a>0:\n r *= z/n\n n-=1\n z-=1\n a-=1\n return round(r,2)", "def get_chance(shots, laxatives...
{"fn_name": "get_chance", "inputs": [[2, 1, 1], [4, 1, 3], [100, 10, 10], [1000, 150, 20], [25, 5, 5], [9, 3, 2], [4000, 200, 30], [10000, 100, 100], [1000000, 5000, 200], [1000000, 5000, 20000]], "outputs": [[0.5], [0.25], [0.33], [0.04], [0.29], [0.42], [0.21], [0.36], [0.37], [0.0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,724
def get_chance(n, x, a):
a055fcf7f36e87f0430d1379648598b5
UNKNOWN
~~~if:csharp,javascript,cfml,php Given a 2D array of size `m * n`. Your task is to find the sum of minimum value in each row. ~~~ ~~~if:cpp Given a 2D vector of size `m * n`. Your task is to find the sum of minimum value in each row. ~~~ ~~~if:python,ruby Given a 2D list of size `m * n`. Your task is to find the sum of...
["def sum_of_minimums(numbers):\n return sum(map(min, numbers))", "def sum_of_minimums(numbers):\n return sum([min(rows) for rows in numbers])", "def sum_of_minimums(numbers):\n return sum(min(xs) for xs in numbers)", "def sum_of_minimums(numbers):\n total = 0\n for nums in numbers:\n total += min...
{"fn_name": "sum_of_minimums", "inputs": [[[[7, 9, 8, 6, 2], [6, 3, 5, 4, 3], [5, 8, 7, 4, 5]]], [[[11, 12, 14, 54], [67, 89, 90, 56], [7, 9, 4, 3], [9, 8, 6, 7]]]], "outputs": [[9], [76]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,896
def sum_of_minimums(numbers):
021c8dbe44a19ef126f84a5bf52a8a38
UNKNOWN
This program tests the life of an evaporator containing a gas. We know the content of the evaporator (content in ml), the percentage of foam or gas lost every day (evap_per_day) and the threshold (threshold) in percentage beyond which the evaporator is no longer useful. All numbers are strictly positive. The program...
["def evaporator(content, evap_per_day, threshold):\n n = 0\n current = 100\n percent = 1 - evap_per_day / 100.0\n while current > threshold:\n current *= percent\n n += 1\n return n", "import math\n\ndef evaporator(content, evap_per_day, threshold):\n return math.ceil(math.log(threshold...
{"fn_name": "evaporator", "inputs": [[10, 10, 10], [10, 10, 5], [100, 5, 5], [50, 12, 1], [47.5, 8, 8], [100, 1, 1], [10, 1, 1], [100, 1, 5]], "outputs": [[22], [29], [59], [37], [31], [459], [459], [299]]}
INTRODUCTORY
PYTHON3
CODEWARS
23,245
def evaporator(content, evap_per_day, threshold):
5a130d5e88b1b671d26c8f0d2486df59
UNKNOWN
My grandfather always predicted how old people would get, and right before he passed away he revealed his secret! In honor of my grandfather's memory we will write a function using his formula! * Take a list of ages when each of your great-grandparent died. * Multiply each number by itself. * Add them all togethe...
["def predict_age(*ages):\n return sum(a*a for a in ages)**.5//2", "def predict_age(*age):\n return sum(a*a for a in age)**0.5//2", "import numpy as np\ndef predict_age(age_1, age_2, age_3, age_4, age_5, age_6, age_7, age_8):\n return np.sum(np.array([age_1, age_2, age_3, age_4, age_5, age_6, age_7, age_8]) **...
{"fn_name": "predict_age", "inputs": [[65, 60, 75, 55, 60, 63, 64, 45], [32, 54, 76, 65, 34, 63, 64, 45]], "outputs": [[86], [79]]}
INTRODUCTORY
PYTHON3
CODEWARS
21,936
def predict_age(age_1, age_2, age_3, age_4, age_5, age_6, age_7, age_8):
8687b6b66c4f2a463f1658e980894106
UNKNOWN
You have a collection of lovely poems. Unfortuantely they aren't formatted very well. They're all on one line, like this: ``` Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. ``` What you want is to present each sentence on a new line, ...
["def format_poem(poem):\n return \".\\n\".join(poem.split(\". \"))", "def format_poem(poem):\n return poem.replace(\". \", \".\\n\")\n", "def format_poem(poem):\n lines = poem.split('. ')\n return '.\\n'.join(lines)\n \n \n \n \n \n", "from re import sub\n\n# Try to solve this challenge with...
{"fn_name": "format_poem", "inputs": [["Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated."], ["Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules."], ["Altho...
INTRODUCTORY
PYTHON3
CODEWARS
1,145
def format_poem(poem):
d77369a1772e00ec5b2793da1818438c
UNKNOWN
Lexicographic permutations are ordered combinations of a set of items ordered in a specific way. For instance, the first 8 permutations of the digits 0123, in lexicographic order, are: ``` 1st 0123 2nd 0132 3rd 0213 4th 0231 5th 0312 6th 0321 7th 1023 8th 1032 ``` Your task is to write a function ```L( n, d )``` tha...
["import math\ndef nth_perm(n,d):\n digits = [str(i) for i in range(d)]\n out = ''\n for i in range(1, d):\n cycles = math.ceil(n/math.factorial(d-i))\n out += digits.pop((cycles % (d-i+1)) - 1)\n return out + digits.pop()", "def nth_perm(n,d):\n st, i, n, fc = list(map(str, range(d))), 1, ...
{"fn_name": "nth_perm", "inputs": [[1, 1], [12, 5], [1000, 7], [1000, 8], [1000000, 10], [874, 7], [100, 5], [400, 6], [900, 8], [3000000, 10], [1234567, 10], [654321, 10], [100000, 9], [33333, 8]], "outputs": [["0"], ["02431"], ["1325460"], ["02436571"], ["2783915460"], ["1234560"], ["40231"], ["314250"], ["02354761"]...
INTRODUCTORY
PYTHON3
CODEWARS
2,442
def nth_perm(n,d):
04040398fa4ac644d96c383c5ab2881b
UNKNOWN
Given a side length `n`, traveling only right and down how many ways are there to get from the top left corner to the bottom right corner of an `n by n` grid? Your mission is to write a program to do just that! Add code to `route(n)` that returns the number of routes for a grid `n by n` (if n is less than 1 return 0)...
["from math import factorial\n\ndef routes(n):\n return n > 0 and factorial(2*n) // factorial(n)**2", "from math import factorial as f\nroutes=lambda n:f(n*2) // (f(n)*f(n)) if n>0 else 0", "def routes(n):\n if(n < 1):\n return(0);\n \n res = 1;\n for i in range(1, n + 1):\n res = res*(n + i)//i;\n \n ...
{"fn_name": "routes", "inputs": [[156], [106], [108], [126], [165], [125], [103]], "outputs": [[376594020312425061595746241557406711201605603899894320577733841460621358204120168599683135056], [360262512886894560870925723424985925545493469115736766525399280], [571070328060067027174940931265047783328344528146596234788184...
INTRODUCTORY
PYTHON3
CODEWARS
435
def routes(n):
e8538092980978daf693ada513e0cd66
UNKNOWN
_Based on [Project Euler problem 35](https://projecteuler.net/problem=35)_ A circular prime is a prime in which every circular permutation of that number is also prime. Circular permutations are created by rotating the digits of the number, for example: `197, 971, 719`. One-digit primes are circular primes by definiti...
["def circular_permutations(n):\n n = str(n)\n return [int(n[i:] + n[:i]) for i in range(len(n))]\n\ndef is_prime(n):\n return n > 1 and all(n % i != 0 for i in range(2, int(n**0.5)+1))\n\ndef circular_prime(n):\n return all(is_prime(x) for x in circular_permutations(n))\n", "def circular_prime(n):\n ret...
{"fn_name": "circular_prime", "inputs": [[197], [179], [971], [222], [9377], [7], [213], [35], [1]], "outputs": [[true], [false], [true], [false], [true], [true], [false], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,243
def circular_prime(n):
cfbf6456c932eddc2a004231aac23497
UNKNOWN
## Terminal game move function In this game, the hero moves from left to right. The player rolls the dice and moves the number of spaces indicated by the dice **two times**. ~~~if-not:sql Create a function for the terminal game that takes the current position of the hero and the roll (1-6) and return the new position...
["def move(position, roll):\n return position + 2*roll", "def move(position, roll):\n return position+roll*2", "move = lambda p,r: p+r*2", "def move(start, roll):\n return start + 2*roll", "def move(start, roll):\n return start + roll * 2", "def move(position, roll):\n return position+(roll<<1)", "move=lam...
{"fn_name": "move", "inputs": [[0, 4], [3, 6], [2, 5]], "outputs": [[8], [15], [12]]}
INTRODUCTORY
PYTHON3
CODEWARS
9,071
def move(position, roll):
f8802f2cbb2ea0579bd3bc30aa60de0a
UNKNOWN
Implement `String.eight_bit_signed_number?` (Ruby), `String.eightBitSignedNumber()` (Python), `eight_bit_signed_number()` (JS) or `StringUtils.isSignedEightBitNumber(String)` (Java) which should return `true/True` if given object is a number representable by 8 bit signed integer (-128 to -1 or 0 to 127), `false/False` ...
["import re\ndef signed_eight_bit_number(number):\n return bool(re.match(\"(0|-128|-?([1-9]|[1-9]\\d|1[01]\\d|12[0-7]))\\Z\", number))", "def signed_eight_bit_number(number):\n if number in list(map(str,list(range(-128,128)))):\n return True\n return False\n \n", "import re\n\nSIGNED_BYTE_PATTERN...
{"fn_name": "signed_eight_bit_number", "inputs": [[""], ["0"], ["00"], ["-0"], ["55"], ["-23"], ["042"], ["127"], ["128"], ["999"], ["-128"], ["-129"], ["-999"], ["1\n"], ["1 "], [" 1"], ["1\n2"], ["+1"], ["--1"], ["01"], ["-01"]], "outputs": [[false], [true], [false], [false], [true], [true], [false], [true], [false],...
INTRODUCTORY
PYTHON3
CODEWARS
1,505
def signed_eight_bit_number(number):
94d89fff42e8a2a85fabb202e9192152
UNKNOWN
Given two words and a letter, return a single word that's a combination of both words, merged at the point where the given letter first appears in each word. The returned word should have the beginning of the first word and the ending of the second, with the dividing letter in the middle. You can assume both words will...
["def string_merge(string1, string2, letter):\n return string1[:string1.index(letter)] + string2[string2.index(letter):]", "def string_merge(string1, string2, letter):\n \"\"\"given two words and a letter, merge one word that combines both at the first occurence of \n the letter\n >>> \"hello\",\"world\",\"l\"\n hel...
{"fn_name": "string_merge", "inputs": [["hello", "world", "l"], ["coding", "anywhere", "n"], ["jason", "samson", "s"], ["wonderful", "people", "e"], ["person", "here", "e"], ["apowiejfoiajsf", "iwahfeijouh", "j"], ["abcdefxxxyzz", "abcxxxyyyxyzz", "x"], ["12345654321", "123456789", "6"], ["JiOdIdA4", "oopopopoodddasdfd...
INTRODUCTORY
PYTHON3
CODEWARS
1,002
def string_merge(string1, string2, letter):
6a26a50569e288c91ec3205db76b64ac
UNKNOWN
You certainly can tell which is the larger number between 2^(10) and 2^(15). But what about, say, 2^(10) and 3^(10)? You know this one too. Things tend to get a bit more complicated with **both** different bases and exponents: which is larger between 3^(9) and 5^(6)? Well, by now you have surely guessed that you hav...
["from math import log\n\ndef compare_powers(*numbers):\n a,b = map(lambda n: n[1]*log(n[0]), numbers)\n return (a<b) - (a>b)", "from math import log\ndef compare_powers(n1, n2):\n val = n2[1] * log(n2[0]) - n1[1] * log(n1[0])\n return -1 if val < 0 else 1 if val > 0 else 0", "from math import log\n\ndef compar...
{"fn_name": "compare_powers", "inputs": [[[2, 10], [2, 15]], [[1, 10], [3, 10]], [[2, 10], [2, 10]], [[3, 9], [1, 6]], [[1, 7], [1, 8]], [[2, 100], [2, 150]], [[2, 100], [3, 100]], [[2, 100], [2, 100]], [[34, 98], [51, 67]], [[1024, 97], [1024, 81]]], "outputs": [[1], [1], [0], [-1], [0], [1], [1], [0], [-1], [-1]]}
INTRODUCTORY
PYTHON3
CODEWARS
970
def compare_powers(n1,n2):
319347cc1c840285a45e049e2148e1b9
UNKNOWN
Consider the following numbers (where `n!` is `factorial(n)`): ``` u1 = (1 / 1!) * (1!) u2 = (1 / 2!) * (1! + 2!) u3 = (1 / 3!) * (1! + 2! + 3!) ... un = (1 / n!) * (1! + 2! + 3! + ... + n!) ``` Which will win: `1 / n!` or `(1! + 2! + 3! + ... + n!)`? Are these numbers going to `0` because of `1/n!` or to infinity du...
["def going(n): \n s = 1.0\n for i in range(2, n + 1):\n s = s/i + 1\n return int(s * 1e6) / 1e6", "def going(n):\n factor = 1.0\n acc = 1.0\n for i in range(n, 1, -1):\n factor *= 1.0 / i\n acc += factor\n return int(acc * 1e6) / 1e6", "def going(n):\n a = 1.\n for i in...
{"fn_name": "going", "inputs": [[5], [6], [7], [8], [20], [30], [50], [113], [200], [523], [1011], [10110]], "outputs": [[1.275], [1.2125], [1.173214], [1.146651], [1.052786], [1.034525], [1.020416], [1.008929], [1.005025], [1.001915], [1.00099], [1.000098]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,211
def going(n):
656a163371aca962790f77f5fd78e3cb
UNKNOWN
The squarefree part of a positive integer is the largest divisor of that integer which itself has no square factors (other than 1). For example, the squareefree part of 12 is 6, since the only larger divisor is 12, and 12 has a square factor (namely, 4). Your challenge, should you choose to accept it, is to implement ...
["def square_free_part(n):\n if type(n) != int or n < 1:return None\n for i in xrange(2, int(n ** 0.5) + 1):\n while n % (i ** 2) == 0:\n n /= i\n return n", "def square_free_part(n):\n\n fac = lambda n: [i for i in range(2, (n//2)+1) if n % i == 0] + [n]\n issquare = lambda n: True if ...
{"fn_name": "square_free_part", "inputs": [[0], [-100], [2.5]], "outputs": [[null], [null], [null]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,163
def square_free_part(n):
6bb3fe2fc22ee1bfddcfff74a1447f96
UNKNOWN
Given time in 24-hour format, convert it to words. ``` For example: 13:00 = one o'clock 13:09 = nine minutes past one 13:15 = quarter past one 13:29 = twenty nine minutes past one 13:30 = half past one 13:31 = twenty nine minutes to two 13:45 = quarter to two 00:48 = twelve minutes to one 00:08 = eight minutes p...
["def solve(time):\n def number(n):\n if n > 20: return \"twenty {}\".format(number(n - 20))\n return [\n None, \"one\", \"two\", \"three\", \"four\",\n \"five\", \"six\", \"seven\", \"eight\", \"nine\",\n \"ten\", \"eleven\", \"twelve\", \"thirteen\",\n \"fo...
{"fn_name": "solve", "inputs": [["13:00"], ["13:09"], ["13:15"], ["13:29"], ["13:30"], ["13:31"], ["13:45"], ["13:59"], ["00:48"], ["00:08"], ["12:00"], ["00:00"], ["19:01"], ["07:01"], ["01:59"], ["12:01"], ["00:01"], ["11:31"], ["23:31"], ["11:45"], ["11:59"], ["23:45"], ["23:59"], ["01:45"]], "outputs": [["one o'clo...
INTRODUCTORY
PYTHON3
CODEWARS
10,909
def solve(time):
37e15862606e5ce50ae26741d73ff0bf
UNKNOWN
For building the encrypted string:Take every 2nd char from the string, then the other chars, that are not every 2nd char, and concat them as new String. Do this n times! Examples: ``` "This is a test!", 1 -> "hsi etTi sats!" "This is a test!", 2 -> "hsi etTi sats!" -> "s eT ashi tist!" ``` Write two methods: ```pyt...
["def decrypt(text, n):\n if text in (\"\", None):\n return text\n \n ndx = len(text) // 2\n\n for i in range(n):\n a = text[:ndx]\n b = text[ndx:]\n text = \"\".join(b[i:i+1] + a[i:i+1] for i in range(ndx + 1))\n return text\n\n\n\ndef encrypt(text, n):\n for i in range(n)...
{"fn_name": "decrypt", "inputs": [["This is a test!", 0], ["hsi etTi sats!", 1], ["s eT ashi tist!", 2], [" Tah itse sits!", 3], ["This is a test!", 4], ["This is a test!", -1], ["hskt svr neetn!Ti aai eyitrsig", 1], ["", 0], [null, 0]], "outputs": [["This is a test!"], ["This is a test!"], ["This is a test!"], ["This...
INTRODUCTORY
PYTHON3
CODEWARS
4,967
def decrypt(text, n):
326fa0d90aa33194445e0f6bdd66e822
UNKNOWN
You have been recruited by an unknown organization for your cipher encrypting/decrypting skills. Being new to the organization they decide to test your skills. Your first test is to write an algorithm that encrypts the given string in the following steps. 1. The first step of the encryption is a standard ROT13 cip...
["def encrypter(strng):\n return ''.join( c if c==' ' else chr(122 - ((ord(c)-97)+13) % 26) for c in strng )", "from string import ascii_lowercase as abc\n\ndef encrypter(strng):\n return strng.translate(str.maketrans(abc[::-1], abc[13:] + abc[:13]))", "def encrypter(strng):\n z={0:'m',1:'l',2:'k',3:'j',4:'i',...
{"fn_name": "encrypter", "inputs": [["amz"], ["welcome to the organization"], ["hello"], ["my name is"], ["goodbye"]], "outputs": [["man"], ["qibkyai ty tfi yvgmzenmteyz"], ["fibby"], ["ao zmai eu"], ["gyyjloi"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,320
def encrypter(strng):
74ae4122afe3d2a46adc925efedbc5e0
UNKNOWN
The look and say sequence is a sequence in which each number is the result of a "look and say" operation on the previous element. Considering for example the classical version startin with `"1"`: `["1", "11", "21, "1211", "111221", ...]`. You can see that the second element describes the first as `"1(times number)1"`,...
["from re import sub\n\ndef look_and_say_sequence(s, n):\n for _ in range(1, n):\n s = sub(r'(.)\\1*', lambda m: str(len(m.group(0))) + m.group(1), s)\n return s", "def look_and_say_sequence(first, n): \n result = first\n \n for _ in range(n-1):\n \n sequence = result\n result ...
{"fn_name": "look_and_say_sequence", "inputs": [["1", 1], ["1", 3], ["1", 5], ["22", 10], ["14", 2]], "outputs": [["1"], ["21"], ["111221"], ["22"], ["1114"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,572
def look_and_say_sequence(first_element, n):
12567cda01cbfc7709f70dcda0906c4e
UNKNOWN
Americans are odd people: in their buildings, the first floor is actually the ground floor and there is no 13th floor (due to superstition). Write a function that given a floor in the american system returns the floor in the european system. With the 1st floor being replaced by the ground floor and the 13th floor bei...
["def get_real_floor(n):\n if n <= 0: return n\n if n < 13: return n-1\n if n > 13: return n-2", "def get_real_floor(n):\n return n if n < 1 else n - 1 if n < 13 else n - 2", "def get_real_floor(n):\n return n - (1 if n < 13 else 2) if n > 0 else n", "def get_real_floor(n):\n return n - (n > 0) - (n >...
{"fn_name": "get_real_floor", "inputs": [[1], [0], [5], [10], [12], [14], [15], [37], [200], [-2], [-5]], "outputs": [[0], [0], [4], [9], [11], [12], [13], [35], [198], [-2], [-5]]}
INTRODUCTORY
PYTHON3
CODEWARS
13,344
def get_real_floor(n):
120f316a7a728ce45db74d9998d38a1a
UNKNOWN
Is the number even? If the numbers is even return `true`. If it's odd, return `false`. Oh yeah... the following symbols/commands have been disabled! use of ```%``` use of ```.even?``` in Ruby use of ```mod``` in Python
["def is_even(n):\n return not n & 1", "def is_even(n):\n return n // 2 * 2 == n", "def is_even(n): return n & 1 == 0 \n", "def is_even(n):\n return n/2 == int(n/2)", "def is_even(n):\n return str(n)[-1] in '02468'", "is_even=lambda n: n|1!=n", "def is_even(n):\n return str(bin(n)[2:])[-1] == '0'", "def ...
{"fn_name": "is_even", "inputs": [[2], [3], [14], [15], [26], [27]], "outputs": [[true], [false], [true], [false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
565
def is_even(n):
54dbebcf90f2a29b2968e6d700105428
UNKNOWN
General primality test are often computationally expensive, so in the biggest prime number race the idea is to study special sub-families of prime number and develop more effective tests for them. [Mersenne Primes](https://en.wikipedia.org/wiki/Mersenne_prime) are prime numbers of the form: Mn = 2^(n) - 1. So far, 49...
["def lucas_lehmer(n):\n return n in [2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279,\n 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701,\n 23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433,\n 1257787, 1398269, 2976221, 3021377, 697...
{"fn_name": "lucas_lehmer", "inputs": [[2], [3], [4], [5], [7], [10], [33], [101], [11213], [11215]], "outputs": [[true], [true], [false], [true], [true], [false], [false], [false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,854
def lucas_lehmer(n):
c4014126f701f17686655cbecacd2e18
UNKNOWN
Find the longest substring in alphabetical order. Example: the longest alphabetical substring in `"asdfaaaabbbbcttavvfffffdf"` is `"aaaabbbbctt"`. There are tests with strings up to `10 000` characters long so your code will need to be efficient. The input will only consist of lowercase characters and will be at lea...
["import re\n\nreg = re.compile('a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*')\n\ndef longest(s):\n return max(reg.findall(s), key=len)", "def longest(string):\n start = 0\n longest = string[0:1]\n length = len(string)\n for i in range(1, length):\n if string[i] < string[i - 1] or i == le...
{"fn_name": "longest", "inputs": [["asd"], ["nab"], ["abcdeapbcdef"], ["asdfaaaabbbbcttavvfffffdf"], ["asdfbyfgiklag"], ["z"], ["zyba"]], "outputs": [["as"], ["ab"], ["abcde"], ["aaaabbbbctt"], ["fgikl"], ["z"], ["z"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,334
def longest(s):
e7f0e0c2ab51ea59bae5d8859cf308ee
UNKNOWN
Hi there! You have to implement the `String get_column_title(int num) // syntax depends on programming language` function that takes an integer number (index of the Excel column) and returns the string represents the title of this column. #Intro In the MS Excel lines are numbered by decimals, columns - by sets of ...
["from string import ascii_uppercase as u\n\ndef get_column_title(n):\n assert isinstance(n, int) and n > 0\n col = []\n while n:\n n, r = divmod(n-1, 26)\n col.append(u[r])\n return ''.join(reversed(col))", "upper = __import__(\"string\").ascii_uppercase.__getitem__\n\ndef get_column_title(nu...
{"fn_name": "get_column_title", "inputs": [[1], [26], [52], [53], [702]], "outputs": [["A"], ["Z"], ["AZ"], ["BA"], ["ZZ"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,368
def get_column_title(num):
4252b405f308af6272308ed0dcc19d1d
UNKNOWN
What's in a name? ..Or rather, what's a name in? For us, a particular string is where we are looking for a name. Task Test whether or not the string contains all of the letters which spell a given name, in order. The format A function passing two strings, searching for one (the name) within the other. ``function nam...
["def name_in_str(str, name):\n it = iter(str.lower())\n return all(c in it for c in name.lower())", "def name_in_str(text, name):\n for c in text.lower():\n if c == name[0].lower():\n name = name[1:]\n if not name:\n return True\n return False", "def name_in_str(...
{"fn_name": "name_in_str", "inputs": [["Across the rivers", "chris"], ["Next to a lake", "chris"], ["Under a sea", "chris"], ["A crew that boards the ship", "chris"], ["A live son", "Allison"], ["Just enough nice friends", "Jennifer"], ["thomas", "Thomas"], ["pippippi", "Pippi"], ["pipipp", "Pippi"], ["ppipip", "Pippi"...
INTRODUCTORY
PYTHON3
CODEWARS
2,169
def name_in_str(str, name):
6e87a73656988e061c825d8107666c51
UNKNOWN
Write a function that takes in a binary string and returns the equivalent decoded text (the text is ASCII encoded). Each 8 bits on the binary string represent 1 character on the ASCII table. The input string will always be a valid binary string. Characters can be in the range from "00000000" to "11111111" (inclusive...
["def binary_to_string(binary):\n return \"\".join( [ chr( int(binary[i: i+8], 2) ) for i in range(0, len(binary), 8) ] )", "def binary_to_string(binary):\n return \"\".join(chr(int(binary[i:i+8],2)) for i in range(0,len(binary),8))\n", "def binary_to_string(binary):\n result = \"\"\n \n while binary:\n ...
{"fn_name": "binary_to_string", "inputs": [[""], ["0100100001100101011011000110110001101111"], ["00110001001100000011000100110001"], ["01010011011100000110000101110010011010110111001100100000011001100110110001100101011101110010111000101110001000000110010101101101011011110111010001101001011011110110111001110011001000000...
INTRODUCTORY
PYTHON3
CODEWARS
1,300
def binary_to_string(binary):
d9d82c5be7091c9b529520ef0cded15d
UNKNOWN
A [Narcissistic Number](https://en.wikipedia.org/wiki/Narcissistic_number) is a positive number which is the sum of its own digits, each raised to the power of the number of digits in a given base. In this Kata, we will restrict ourselves to decimal (base 10). For example, take 153 (3 digits): ``` 1^3 + 5^3 + 3^3 ...
["def narcissistic(value):\n return value == sum(int(x) ** len(str(value)) for x in str(value))", "def narcissistic( value ):\n value = str(value)\n size = len(value)\n sum = 0\n for i in value:\n sum += int(i) ** size\n return sum == int(value)", "def narcissistic(value):\n return bool(valu...
{"fn_name": "narcissistic", "inputs": [[1], [5], [7], [153], [370], [371], [1634]], "outputs": [[true], [true], [true], [true], [true], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,449
def narcissistic( value ):
f3f5ad1f7c25b1cad83927fd1e079a0d
UNKNOWN
For this exercise you will create a global flatten method. The method takes in any number of arguments and flattens them into a single array. If any of the arguments passed in are an array then the individual objects within the array will be flattened so that they exist at the same level as the other arguments. Any nes...
["def flatten(*a):\n r = []\n for x in a:\n if isinstance(x, list):\n r.extend(flatten(*x))\n else:\n r.append(x)\n return r", "def flatten(*args):\n return [x for a in args for x in (flatten(*a) if isinstance(a, list) else [a])]", "def flatten(*args):\n \n def _fla...
{"fn_name": "flatten", "inputs": [[1, 2, 3], [1, 2], [5, "string"], [-4.5, -3, 1, 4], [[3, 4, 5], [1, 2, 3]], [[1], [], 2, [4, 5, 6]], [[4, "string", 9, 3, 1], [], [], [], [], ["string"]], [1, 2, ["9", [], []], null], [[1, 2], [3, 4, 5], [6, [7], [[8]]]], [["hello", 2, ["text", [4, 5]]], [[]], "[list]"]], "outputs": [[...
INTRODUCTORY
PYTHON3
CODEWARS
2,437
def flatten(*args):
97b5d30d2ab0cdeb08402816dfd306a8
UNKNOWN
Create a function `sierpinski` to generate an ASCII representation of a Sierpinski triangle of order **N**. Seperate each line with `\n`. You don't have to check the input value. The output should look like this: sierpinski(4) * * * ...
["def sierpinski(n):\n t = ['*']\n for _ in range(n):\n t = [r.center(2*len(t[-1])+1) for r in t] + [r + ' ' + r for r in t]\n return '\\n'.join(t)", "def sierpinski(n):\n lines = [\"*\"]\n for i in range(2, n+2):\n lines = [l.center(2**i - 1) for l in lines] + [f\"{l} {l}\" for l in lines]...
{"fn_name": "sierpinski", "inputs": [[1], [2], [3]], "outputs": [[" * \n* *"], [" * \n * * \n * * \n* * * *"], [" * \n * * \n * * \n * * * * \n * * \n * * * * \n * * * * \n* * * * * * * *"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,739
def sierpinski(n):
6809c29e6da7a892e90a9377fd56aa23
UNKNOWN
Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors is 2500 which is 50 * 50, a square! Given two integers m, n (1 <= m <= n) we want to find all integers between m and n whose sum of squared divisors is itself a square. 42 is su...
["CACHE = {}\n\ndef squared_cache(number):\n if number not in CACHE:\n divisors = [x for x in range(1, number + 1) if number % x == 0]\n CACHE[number] = sum([x * x for x in divisors])\n return CACHE[number] \n \n return CACHE[number]\n\ndef list_squared(m, n):\n ret = []\n\n for numb...
{"fn_name": "list_squared", "inputs": [[1, 250], [42, 250], [250, 500], [300, 600], [600, 1500], [1500, 1800], [1800, 2000], [2000, 2200], [2200, 5000], [5000, 10000]], "outputs": [[[[1, 1], [42, 2500], [246, 84100]]], [[[42, 2500], [246, 84100]]], [[[287, 84100]]], [[]], [[[728, 722500], [1434, 2856100]]], [[[1673, 28...
INTRODUCTORY
PYTHON3
CODEWARS
48,829
def list_squared(m, n):
b12e235bc69cf2946f7fdd00839a7cfa
UNKNOWN
Your task is to remove all duplicate words from a string, leaving only single (first) words entries. Example: Input: 'alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta' Output: 'alpha beta gamma delta'
["def remove_duplicate_words(s):\n return ' '.join(dict.fromkeys(s.split()))", "def remove_duplicate_words(s):\n s = s.split(\" \")\n words = []\n for item in s:\n if item not in words:\n words.append(item)\n return \" \".join(words)\n", "def remove_duplicate_words(s):\n return ' '.j...
{"fn_name": "remove_duplicate_words", "inputs": [["alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta"], ["my cat is my cat fat"]], "outputs": [["alpha beta gamma delta"], ["my cat is fat"]]}
INTRODUCTORY
PYTHON3
CODEWARS
17,872
def remove_duplicate_words(s):
a192d89a2de6e243aae977b04e897a50
UNKNOWN
Write a function that accepts two square matrices (`N x N` two dimensional arrays), and return the sum of the two. Both matrices being passed into the function will be of size `N x N` (square), containing only integers. How to sum two matrices: Take each cell `[n][m]` from the first matrix, and add it with the same `...
["import numpy as np\ndef matrix_addition(a, b):\n return(np.mat(a)+np.mat(b)).tolist()", "def matrix_addition(a, b):\n for row in range(len(a)):\n for index in range(len(a)):\n a[row][index] += b[row][index]\n return a\n", "def matrix_addition(a, b):\n return [[sum(xs) for xs in zip(ra, r...
{"fn_name": "matrix_addition", "inputs": [[[[1, 2, 3], [3, 2, 1], [1, 1, 1]], [[2, 2, 1], [3, 2, 3], [1, 1, 3]]], [[[1, 2], [1, 2]], [[2, 3], [2, 3]]], [[[1]], [[2]]]], "outputs": [[[[3, 4, 4], [6, 4, 4], [2, 2, 4]]], [[[3, 5], [3, 5]]], [[[3]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,212
def matrix_addition(a, b):
d68ae6c097f6319db8abc2d6cdf230bb
UNKNOWN
# Introduction A grille cipher was a technique for encrypting a plaintext by writing it onto a sheet of paper through a pierced sheet (of paper or cardboard or similar). The earliest known description is due to the polymath Girolamo Cardano in 1550. His proposal was for a rectangular stencil allowing single letters, ...
["def grille(msg, code):\n return ''.join(msg[-1-i] for i,c in enumerate(bin(code)[::-1]) if c == '1' and i < len(msg))[::-1]", "def grille(message, code):\n binary = bin(code)[2:][-len(message):].zfill(len(message))\n return ''.join(char for char, code in zip(message, binary) if code == '1')", "def grille(m, ...
{"fn_name": "grille", "inputs": [["abcdef", 5], ["", 5], ["abcd", 1], ["0abc", 2], ["ab", 255], ["ab", 256], ["abcde", 32], ["tcddoadepwweasresd", 77098]], "outputs": [["df"], [""], ["d"], ["b"], ["ab"], [""], [""], ["codewars"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,846
def grille(message, code):
426727953286b0a3253c37a12b52f0a1
UNKNOWN
In this Kata, we define an arithmetic progression as a series of integers in which the differences between adjacent numbers are the same. You will be given an array of ints of `length > 2` and your task will be to convert it into an arithmetic progression by the following rule: ```Haskell For each element there are exa...
["def solve(arr):\n res = []\n for first in (arr[0]-1, arr[0], arr[0]+1):\n for second in (arr[1]-1, arr[1], arr[1]+1):\n val, step, count = second, second-first, abs(arr[0]-first) + abs(arr[1]-second)\n for current in arr[2:]:\n val += step\n if abs(val-...
{"fn_name": "solve", "inputs": [[[1, 1, 3, 5, 6, 5]], [[2, 1, 2]], [[1, 2, 3]], [[1, 1, 10]], [[24, 21, 14, 10]], [[3, 2, 1, 1, 1]], [[1, 3, 6, 9, 12]], [[0, 0, 0, 0, 0]], [[5, 4, 3, 2, 1, 1]], [[1, 2, 1]], [[1, 2, 3, 1, 1]], [[1, 3, 6, 8, 10]], [[5, 6, 5, 3, 1, 1]]], "outputs": [[4], [1], [0], [-1], [3], [4], [1], [0]...
INTRODUCTORY
PYTHON3
CODEWARS
6,525
def solve(arr):
52686cc21a564619c54be891c9fd7b70
UNKNOWN
In this kata you will be given a random string of letters and tasked with returning them as a string of comma-separated sequences sorted alphabetically, with each sequence starting with an uppercase character followed by `n-1` lowercase characters, where `n` is the letter's alphabet position `1-26`. ## Example ```pyt...
["def alpha_seq(s):\n return \",\".join( (c * (ord(c)-96)).capitalize() for c in sorted(s.lower()) )", "def alpha_seq(string):\n alpha = 'abcdefghijklmnopqrstuvwxyz'\n output = ''\n for s in ''.join(sorted((string.lower()))):\n output += s.upper()\n output += s * alpha.find(s)\n output ...
{"fn_name": "alpha_seq", "inputs": [["BfcFA"], ["ZpglnRxqenU"], ["NyffsGeyylB"], ["MjtkuBovqrU"], ["EvidjUnokmM"], ["HbideVbxncC"]], "outputs": [["A,Bb,Ccc,Ffffff,Ffffff"], ["Eeeee,Ggggggg,Llllllllllll,Nnnnnnnnnnnnnn,Nnnnnnnnnnnnnn,Pppppppppppppppp,Qqqqqqqqqqqqqqqqq,Rrrrrrrrrrrrrrrrrr,Uuuuuuuuuuuuuuuuuuuuu,Xxxxxxxxxxxx...
INTRODUCTORY
PYTHON3
CODEWARS
1,633
def alpha_seq(string):
86d3e2e33386bf0aac5bab75c4c2dffb
UNKNOWN
Given an `array` of digital numbers, return a new array of length `number` containing the last even numbers from the original array (in the same order). The original array will be not empty and will contain at least "number" even numbers. For example: ``` ([1, 2, 3, 4, 5, 6, 7, 8, 9], 3) => [4, 6, 8] ([-22, 5, 3, 11, ...
["def even_numbers(arr,n):\n return [i for i in arr if i % 2 == 0][-n:] ", "def even_numbers(arr, n):\n result = []\n a = list(reversed(arr))\n for number in a:\n if n == 0:\n break\n if number % 2 == 0:\n result.append(number)\n n -= 1\n return list(reverse...
{"fn_name": "even_numbers", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9], 3], [[-22, 5, 3, 11, 26, -6, -7, -8, -9, -8, 26], 2], [[6, -25, 3, 7, 5, 5, 7, -3, 23], 1]], "outputs": [[[4, 6, 8]], [[-8, 26]], [[6]]]}
INTRODUCTORY
PYTHON3
CODEWARS
16,352
def even_numbers(arr,n):
d3c08501d7f1ba85109bdf7d8de28c3f
UNKNOWN
With one die of 6 sides we will have six different possible results:``` 1, 2, 3, 4, 5, 6``` . With 2 dice of six sides, we will have 36 different possible results: ``` (1,1),(1,2),(2,1),(1,3),(3,1),(1,4),(4,1),(1,5), (5,1), (1,6),(6,1),(2,2),(2,3),(3,2),(2,4),(4,2), (2,5),(5,2)(2,6),(6,2),(3,3),(3,4),(4,3),(3,5),(5,...
["import numpy as np\n\ndef products(n, min_divisor, max_divisor): \n if n == 1:\n yield []\n for divisor in range(min_divisor, max_divisor+1):\n if n % divisor == 0:\n for product in products(n // divisor, divisor, max_divisor):\n yield product + [divisor] \n\ndef eq_...
{"fn_name": "eq_dice", "inputs": [[[6, 6]], [[5, 6, 4]], [[3, 15, 8, 20]], [[6]], [[3, 3]], [[20]], [[3, 6]]], "outputs": [[3], [5], [44], [0], [0], [1], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,100
def eq_dice(set_):
089ea0a0608201da19d75fbf09867700
UNKNOWN
This kata focuses on the Numpy python package and you can read up on the Numpy array manipulation functions here: https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.array-manipulation.html You will get two integers `N` and `M`. You must return an array with two sub-arrays with numbers in ranges `[0, N / 2)` an...
["import numpy as np\n\n\ndef reorder(a, b):\n return np.roll(np.arange(a).reshape(2, -1), b, 1).tolist()\n", "from collections import deque\n\n\ndef reorder(n, m):\n a, b = deque(range(n // 2)), deque(range(n // 2, n))\n a.rotate(m)\n b.rotate(m)\n return [list(a), list(b)]", "# Numpy?\n# https://media....
{"fn_name": "reorder", "inputs": [[10, 1], [10, 3], [10, 97]], "outputs": [[[[4, 0, 1, 2, 3], [9, 5, 6, 7, 8]]], [[[2, 3, 4, 0, 1], [7, 8, 9, 5, 6]]], [[[3, 4, 0, 1, 2], [8, 9, 5, 6, 7]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,023
def reorder(a, b):
c535f32edb6e882551658e9dd5f9bbe2
UNKNOWN
In this Kata, you will be given a string and two indexes (`a` and `b`). Your task is to reverse the portion of that string between those two indices inclusive. ~~~if-not:fortran ``` solve("codewars",1,5) = "cawedors" -- elements at index 1 to 5 inclusive are "odewa". So we reverse them. solve("cODEWArs", 1,5) = "cAWE...
["def solve(s,a,b):\n return s[:a]+s[a:b+1][::-1]+s[b+1:]", "def solve(st,a,b):\n return st[:a]+st[a:b+1][::-1]+ st[b+1:]", "def solve(st,a,b):\n return f'{st[:a]}{st[a : b + 1][::-1]}{st[b + 1 :]}'", "def solve(st,a,b):\n sub, rev = st[a:b+1], st[a:b+1][::-1]\n return st.replace(sub, rev)", "def solve(s...
{"fn_name": "solve", "inputs": [["codewars", 1, 5], ["codingIsFun", 2, 100], ["FunctionalProgramming", 2, 15], ["abcefghijklmnopqrstuvwxyz", 0, 20], ["abcefghijklmnopqrstuvwxyz", 5, 20]], "outputs": [["cawedors"], ["conuFsIgnid"], ["FuargorPlanoitcnmming"], ["vutsrqponmlkjihgfecbawxyz"], ["abcefvutsrqponmlkjihgwxyz"]]}
INTRODUCTORY
PYTHON3
CODEWARS
931
def solve(st,a,b):
f09f6f211912d6355118e932b6f967ed
UNKNOWN
A **pandigital number** is one that has its digits from ```1``` to ```9``` occuring only once (they do not have the digit 0). The number ```169```, is the first pandigital square, higher than ```100```, having its square root, ```13```, pandigital too. The number ```1728``` is the first pandigital cubic, higher than ...
["def is_pandigital(n):\n s = str(n)\n return not '0' in s and len(set(s)) == len(s)\n\ndef pow_root_pandigit(val, n, k):\n res = []\n current = int(round(val ** (1.0 / n), 5)) + 1\n while len(res) < k and current <= 987654321 ** (1.0 / n):\n if is_pandigital(current):\n p = current ** ...
{"fn_name": "pow_root_pandigit", "inputs": [[388, 2, 3], [1750, 3, 5], [1728, 3, 4], [600000000, 2, 5], [900000000, 2, 5]], "outputs": [[[[23, 529], [24, 576], [25, 625]]], [[[13, 2197], [17, 4913], [18, 5832], [19, 6859], [21, 9261]]], [[[13, 2197], [17, 4913], [18, 5832], [19, 6859]]], [[25941, 672935481]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,650
def pow_root_pandigit(val, n, k):