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
2ea4e0eba27d0011affdacb341e27b7a
UNKNOWN
A series or sequence of numbers is usually the product of a function and can either be infinite or finite. In this kata we will only consider finite series and you are required to return a code according to the type of sequence: |Code|Type|Example| |-|-|-| |`0`|`unordered`|`[3,5,8,1,14,3]`| |`1`|`strictly increasing`...
["def sequence_classifier(arr):\n if all(arr[i] == arr[i+1] for i in range(len(arr)-1)): return 5\n if all(arr[i] < arr[i+1] for i in range(len(arr)-1)): return 1\n if all(arr[i] <= arr[i+1] for i in range(len(arr)-1)): return 2\n if all(arr[i] > arr[i+1] for i in range(len(arr)-1)): return 3\n if all(...
{"fn_name": "sequence_classifier", "inputs": [[[3, 5, 8, 1, 14, 3]], [[3, 5, 8, 9, 14, 23]], [[3, 5, 8, 8, 14, 14]], [[14, 9, 8, 5, 3, 1]], [[14, 14, 8, 8, 5, 3]], [[8, 8, 8, 8, 8, 8]], [[8, 9]], [[8, 8, 8, 8, 8, 9]], [[9, 8]], [[9, 9, 9, 8, 8, 8]], [[3, 5, 8, 1, 14, 2]]], "outputs": [[0], [1], [2], [3], [4], [5], [1],...
INTRODUCTORY
PYTHON3
CODEWARS
5,074
def sequence_classifier(arr):
86677fbf6b571209d6eab5412264d6b3
UNKNOWN
This challenge is based on [the kata](https://www.codewars.com/kata/n-smallest-elements-in-original-order) by GiacomoSorbi. Before doing this one it is advisable to complete the non-performance version first. ___ # Task You will be given an array of random integers and a number `n`. You have to extract `n` smallest ...
["from collections import Counter\nfrom itertools import count, islice\n\ndef performant_smallest(arr, n):\n cnts = Counter(arr)\n total = 0\n for i, c in sorted(cnts.items()):\n total += c\n if total >= n:\n break\n available = count(c + n - total, -1)\n it = (x for x in arr if ...
{"fn_name": "performant_smallest", "inputs": [[[1, 2, 3, 4, 5], 3], [[5, 4, 3, 2, 1], 3], [[1, 2, 3, 4, 1], 3], [[2, 1, 3, 2, 3], 3]], "outputs": [[[1, 2, 3]], [[3, 2, 1]], [[1, 2, 1]], [[2, 1, 2]]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,209
def performant_smallest(arr, n):
107a20d24cf39937e9aed2f671516b28
UNKNOWN
Alex is transitioning from website design to coding and wants to sharpen his skills with CodeWars. He can do ten kata in an hour, but when he makes a mistake, he must do pushups. These pushups really tire poor Alex out, so every time he does them they take twice as long. His first set of redemption pushups takes 5 mi...
["from math import log\n\ndef alex_mistakes(n, time):\n return int(log((time - n * 6) / 5 +1, 2))\n", "def alex_mistakes(katas, time):\n mistakes = 0\n pushup_time = 5\n time_left = time - katas * 6\n \n while time_left >= pushup_time:\n time_left -= pushup_time\n pushup_time *= 2\n ...
{"fn_name": "alex_mistakes", "inputs": [[10, 120], [11, 120], [3, 45], [8, 120], [6, 60], [9, 180], [20, 120], [20, 125], [20, 130], [20, 135]], "outputs": [[3], [3], [2], [3], [2], [4], [0], [1], [1], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,669
def alex_mistakes(number_of_katas, time_limit):
4be9be82bf4ff8d1888429779f3edbaf
UNKNOWN
One of the first chain emails I ever received was about a supposed Cambridge University study that suggests your brain can read words no matter what order the letters are in, as long as the first and last letters of each word are correct. Your task is to **create a function that can take any string and randomly jumbl...
["import re\nfrom random import sample\n\ndef mix_words(string):\n return re.sub(\n r'(?<=[a-zA-Z])([a-zA-Z]{2,})(?=[a-zA-Z])',\n lambda match: ''.join(sample(match.group(1), len(match.group(1)))),\n string)\n", "from re import sub\nfrom random import shuffle\n\ndef scramble(m):\n s = list(m....
{"fn_name": "mix_words", "inputs": [["Hi"], ["Hi!"], ["Hey"], ["Hey?"]], "outputs": [["Hi"], ["Hi!"], ["Hey"], ["Hey?"]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,153
def mix_words(s):
b8a7ee8451d679875cbc468f788e41b4
UNKNOWN
Your task is to find the first element of an array that is not consecutive. By not consecutive we mean not exactly 1 larger than the previous element of the array. E.g. If we have an array `[1,2,3,4,6,7,8]` then `1` then `2` then `3` then `4` are all consecutive but `6` is not, so that's the first non-consecutive num...
["def first_non_consecutive(arr):\n if not arr: return 0\n for i, x in enumerate(arr[:-1]):\n if x + 1 != arr[i + 1]:\n return arr[i + 1]", "def first_non_consecutive(a):\n i = a[0]\n for e in a:\n if e != i:\n return e\n i += 1\n return None", "def first_non_co...
{"fn_name": "first_non_consecutive", "inputs": [[[1, 2, 3, 4, 6, 7, 8]], [[1, 2, 3, 4, 5, 6, 7, 8]], [[4, 6, 7, 8, 9, 11]], [[4, 5, 6, 7, 8, 9, 11]], [[31, 32]], [[-3, -2, 0, 1]], [[-5, -4, -3, -1]]], "outputs": [[6], [null], [6], [11], [null], [0], [-1]]}
INTRODUCTORY
PYTHON3
CODEWARS
18,120
def first_non_consecutive(arr):
0a9d7c66db5dbb285daa18fb21863961
UNKNOWN
# Fun fact Tetris was the first video game played in outer space In 1993, Russian cosmonaut Aleksandr A. Serebrov spent 196 days on the Mir space station with a very special distraction: a gray Game Boy loaded with Tetris. During that time the game orbited the Earth 3,000 times and became the first video game played i...
["pos = {\"L4\":0, \"L3\":1, \"L2\":2, \"L1\":3, \"L0\":4, \"R0\":4, \"R1\":5, \"R2\":6, \"R3\":7, \"R4\":8}\n\ndef tetris(arr):\n current, res = [0]*9, 0\n for x in arr:\n p = pos[x[1:]]\n current[p] += int(x[0])\n if current[p] >= 30: break\n y = min(current)\n if y: current, ...
{"fn_name": "tetris", "inputs": [[["1R4", "2L3", "3L2", "4L1", "1L0", "2R1", "3R2", "4R3", "1L4"]], [["1L2", "4R2", "3L3", "3L1", "1L4", "1R4"]], [["4R4", "4L3", "4L2", "4L1", "4L0", "4R1", "4R2", "4R3", "3L4"]]], "outputs": [[1], [0], [3]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,186
def tetris(arr):
80dbfb4f4c9c5684f1f3219d94a7ada7
UNKNOWN
The number 45 is the first integer in having this interesting property: the sum of the number with its reversed is divisible by the difference between them(absolute Value). ``` 45 + 54 = 99 abs(45 - 54) = 9 99 is divisible by 9. ``` The first terms of this special sequence are : ``` n a(n) 1 ...
["MEMO = []\n\ndef sum_dif_rev(n):\n i = MEMO[-1] if MEMO else 0\n \n while len(MEMO) < n:\n i += 1\n r = int(str(i)[::-1])\n if i % 10 and r != i and (i + r) % abs(r - i) == 0:\n MEMO.append(i)\n\n return MEMO[n-1]", "from itertools import count\n\n# It's not worth it to mem...
{"fn_name": "sum_dif_rev", "inputs": [[1], [3], [4], [5], [6]], "outputs": [[45], [495], [594], [4356], [4545]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,877
def sum_dif_rev(n):
a13a3b4a4bcfbbf73746df413bbf624e
UNKNOWN
Farmer Bob have a big farm, where he growths chickens, rabbits and cows. It is very difficult to count the number of animals for each type manually, so he diceded to buy a system to do it. But he bought a cheap system that can count only total number of heads, total number of legs and total number of horns of animals o...
["def get_animals_count(legs, heads, horns):\n cows = horns // 2\n rabbits = legs // 2 - cows - heads\n chickens = heads - cows - rabbits\n return dict(cows=cows, rabbits=rabbits, chickens=chickens)", "def get_animals_count(ln, hn, horn):\n c,ln,hn = horn//2, ln - 2*horn, hn - horn//2\n return {\"rabb...
{"fn_name": "get_animals_count", "inputs": [[34, 11, 6], [154, 42, 10], [74, 20, 34], [152, 38, 34], [56, 17, 0]], "outputs": [[{"rabbits": 3, "chickens": 5, "cows": 3}], [{"rabbits": 30, "chickens": 7, "cows": 5}], [{"rabbits": 0, "chickens": 3, "cows": 17}], [{"rabbits": 21, "chickens": 0, "cows": 17}], [{"rabbits": ...
INTRODUCTORY
PYTHON3
CODEWARS
2,546
def get_animals_count(legs, heads, horns):
9089d78434f193dbf33ef2fcb0c2e0d7
UNKNOWN
You're continuing to enjoy your new piano, as described in Piano Kata, Part 1. You're also continuing the exercise where you start on the very first (leftmost, lowest in pitch) key on the 88-key keyboard, which (as shown below) is the note A, with the little finger on your left hand, then the second key, which is the b...
["def which_note(count):\n return \"A A# B C C# D D# E F F# G G#\".split()[(count - 1) % 88 % 12]", "keyboard = \"A A# B C C# D D# E F F# G G#\".split()\n\ndef which_note(count):\n return keyboard[(count - 1) % 88 % 12]", "NOTES = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#']\nNUMBER_OF_KEYS =...
{"fn_name": "which_note", "inputs": [[1], [5], [12], [42], [88], [89], [92], [100], [111], [200], [2017]], "outputs": [["A"], ["C#"], ["G#"], ["D"], ["C"], ["A"], ["C"], ["G#"], ["G"], ["G#"], ["F"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,041
def which_note(key_press_count):
b35901fcb33280fc288c2596969a96d1
UNKNOWN
In an infinite array with two rows, the numbers in the top row are denoted `. . . , A[−2], A[−1], A[0], A[1], A[2], . . .` and the numbers in the bottom row are denoted `. . . , B[−2], B[−1], B[0], B[1], B[2], . . .` For each integer `k`, the entry `A[k]` is directly above the entry `B[k]` in the array, as shown: ...
["def find_a(lst,n):\n if n<0: return find_a(lst[::-1], 3-n)\n if n<4: return lst[n]\n a,b,c,d = lst\n for _ in range(n-3):\n a,b,c,d = b, c, d, 6*d-10*c+6*b-a\n return d", "def find_a(A, n):\n if 0 <= n < 4: return A[n]\n if n < 0:\n A, n = A[::-1], abs(n) + 3\n B = [0] * 4\n B...
{"fn_name": "find_a", "inputs": [[[1, 2, 3, 4], 2], [[38, 200, -18, 45], 1], [[1, 0, 0, 1], 5], [[0, 2, 0, 3], -2], [[-20, 1, -3, 14], -5], [[1, 2, 3, 5], 100], [[0, 4, 6, 13], 100]], "outputs": [[3], [200], [20], [-126], [-44402], [60560100487003612846322657690093088848428068520476594299], [335254562473098582210532865...
INTRODUCTORY
PYTHON3
CODEWARS
5,256
def find_a(array, n):
a5ef34f2a9ad6fcd94c9f0733ad2b074
UNKNOWN
Given an array of integers. Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers. If the input array is empty or null, return an empty array. # Example For input `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]`, you should return `[10...
["def count_positives_sum_negatives(arr):\n if not arr: return []\n pos = 0\n neg = 0\n for x in arr:\n if x > 0:\n pos += 1\n if x < 0:\n neg += x\n return [pos, neg]", "def count_positives_sum_negatives(arr):\n pos = sum(1 for x in arr if x > 0)\n neg = sum(x for x in ...
{"fn_name": "count_positives_sum_negatives", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]], [[0, 2, 3, 0, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14]], [[1]], [[-1]], [[0, 0, 0, 0, 0, 0, 0, 0, 0]], [[]]], "outputs": [[[10, -65]], [[8, -50]], [[1, 0]], [[0, -1]], [[0, 0]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
18,339
def count_positives_sum_negatives(arr):
0ba0eecc0f2c8c4ea922a55f2d3dc9eb
UNKNOWN
Given two strings, the first being a random string and the second being the same as the first, but with three added characters somewhere in the string (three same characters), Write a function that returns the added character ### E.g ``` string1 = "hello" string2 = "aaahello" // => 'a' ``` The above is just an exa...
["from collections import Counter\n\ndef added_char(s1, s2): \n return next((Counter(s2) - Counter(s1)).elements())", "def added_char(s1, s2): \n for i in s2:\n if s1.count(i) != s2.count(i):\n return i", "from functools import reduce\nfrom operator import xor\n\ndef added_char(s1, s2): \n retur...
{"fn_name": "added_char", "inputs": [["hello", "checlclo"], ["aabbcc", "aacccbbcc"], ["abcde", "2db2a2ec"]], "outputs": [["c"], ["c"], ["2"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,063
def added_char(s1, s2):
f6eb78819fcd03814141cae8914ee790
UNKNOWN
Write a function called that takes a string of parentheses, and determines if the order of the parentheses is valid. The function should return `true` if the string is valid, and `false` if it's invalid. ## Examples ``` "()" => true ")(()))" => false "(" => false "(())((()())())...
["def valid_parentheses(string):\n cnt = 0\n for char in string:\n if char == '(': cnt += 1\n if char == ')': cnt -= 1\n if cnt < 0: return False\n return True if cnt == 0 else False", "def valid_parentheses(string):\n count = 0\n for i in string:\n if i == \"(\":\n ...
{"fn_name": "valid_parentheses", "inputs": [[")"], ["("], [""], ["hi)("], ["hi(hi)"], ["hi(hi)("], ["((())()())"], ["(c(b(a)))(d)"], ["hi(hi))("], ["())(()"]], "outputs": [[false], [false], [true], [false], [true], [false], [true], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
9,408
def valid_parentheses(string):
281e23ab80fc0b75f0dbf862208771af
UNKNOWN
Hi guys, welcome to introduction to DocTesting. The kata is composed of two parts; in part (1) we write three small functions, and in part (2) we write a few doc tests for those functions. Lets talk about the functions first... The reverse_list function takes a list and returns the reverse of it. If given an...
["def reverse_list(x):\n \"\"\"Takes an list and returns the reverse of it. \n If x is empty, return [].\n \n >>> reverse_list([1, 2, 3, 4])\n [4, 3, 2, 1]\n >>> reverse_list([])\n []\n \"\"\" \n \n return x[::-1]\n\ndef sum_list(x):\n \"\"\"Takes a list, and returns the sum of that lis...
{"fn_name": "reverse_list", "inputs": [[[1, 2, 3]], [[]]], "outputs": [[[3, 2, 1]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
7,178
def reverse_list(x):
9e4c161d5c11554ca1366e5cf875f3cd
UNKNOWN
# Task Your Informatics teacher at school likes coming up with new ways to help you understand the material. When you started studying numeral systems, he introduced his own numeral system, which he's convinced will help clarify things. His numeral system has base 26, and its digits are represented by English capital ...
["def new_numeral_system(n):\n a = [c for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' if c <= n]\n return ['{} + {}'.format(a[i], a[-1-i]) for i in range((len(a) + 1) // 2)]", "new_numeral_system=lambda n:['%c + %c'%(65+i,ord(n)-i)for i in range(ord(n)-63>>1)]", "def new_numeral_system(number):\n return [(chr(65+i) + ' ...
{"fn_name": "new_numeral_system", "inputs": [["G"], ["A"], ["D"], ["E"], ["O"]], "outputs": [[["A + G", "B + F", "C + E", "D + D"]], [["A + A"]], [["A + D", "B + C"]], [["A + E", "B + D", "C + C"]], [["A + O", "B + N", "C + M", "D + L", "E + K", "F + J", "G + I", "H + H"]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,594
def new_numeral_system(number):
57b8e93e9ac4f04c922924d9d82a9b35
UNKNOWN
Your work is to write a method that takes a value and an index, and returns the value with the bit at given index flipped. The bits are numbered from the least significant bit (index 1). Example: ```python flip_bit(15, 4) == 7 # 15 in binary is 1111, after flipping 4th bit, it becomes 0111, i.e. 7 flip_bit(15, 5) == ...
["def flip_bit(value, bit_index):\n return value ^ (1 << (bit_index-1))", "flip_bit=lambda n,k:n^1<<k-1", "def flip_bit(value, bit_index):\n return value ^ 2 ** (bit_index-1)", "def flip_bit(v, b):\n return 1<<b-1 ^ v", "flip_bit=lambda v, i: int(\"\".join([l if 64-i!=k else \"0\" if l==\"1\" else \"1\" for k,...
{"fn_name": "flip_bit", "inputs": [[0, 16], [2147483647, 31], [127, 8]], "outputs": [[32768], [1073741823], [255]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,307
def flip_bit(value, bit_index):
b1fe086b82c819f4396de41f8bac2c63
UNKNOWN
Reverse every other word in a given string, then return the string. Throw away any leading or trailing whitespace, while ensuring there is exactly one space between each word. Punctuation marks should be treated as if they are a part of the word in this kata.
["def reverse_alternate(string):\n return \" \".join(y[::-1] if x%2 else y for x,y in enumerate(string.split()))", "def reverse_alternate(s):\n return ' '.join(w[::-1] if i % 2 else w for i, w in enumerate(s.split()))", "def reverse_alternate(string):\n #your code here\n if string == \"\":\n return \"\"\n e...
{"fn_name": "reverse_alternate", "inputs": [["Did it work?"], ["I really hope it works this time..."], ["Reverse this string, please!"], ["Have a beer"], [" "], ["This is not a test "], ["This is a test "]], "outputs": [["Did ti work?"], ["I yllaer hope ti works siht time..."], ["Reverse siht string, !esaelp"]...
INTRODUCTORY
PYTHON3
CODEWARS
1,972
def reverse_alternate(string):
a988e7eca67e19158ae09de05679956d
UNKNOWN
Write a function that solves an algebraic expression given as a string. * The expression can include only sums and products. * The numbers in the expression are in standard notation (NOT scientific). * In contrast, the function should return a string with the calculated value given in scientific notation with 5 de...
["def sum_prod(strexpression):\n return \"%.5e\" %(eval(strexpression))", "def sum_prod(strexpression):\n # resisting using the dreaded eval :-)\n # split things up into numbers and operators\n strexpression = strexpression.replace(\"*\", \" * \").replace(\"+\", \" + \")\n equation = [float(x) if x[0].is...
{"fn_name": "sum_prod", "inputs": [["5*4+6"], ["5+4*6"], ["3*8+6*5"], ["5*8+6*3*2"], ["5.4*4.0+6.2+8.0"], ["0.5*1.2*56+9.6*5*81+1"], ["1"], ["1.333333333*1.23456789+0.003*0.002"]], "outputs": [["2.60000e+01"], ["2.90000e+01"], ["5.40000e+01"], ["7.60000e+01"], ["3.58000e+01"], ["3.92260e+03"], ["1.00000e+00"], ["1.6461...
INTRODUCTORY
PYTHON3
CODEWARS
1,946
def sum_prod(strexpression):
5c1d56b50fa9fb68e96d43769ea93af4
UNKNOWN
For "x", determine how many positive integers less than or equal to "x" are odd but not prime. Assume "x" is an integer between 1 and 10000. Example: 5 has three odd numbers (1,3,5) and only the number 1 is not prime, so the answer is 1 Example: 10 has five odd numbers (1,3,5,7,9) and only 1 and 9 are not prime, so t...
["def not_prime(x):\n if x == 1: return True\n for y in range(2, int(x ** 0.5) + 1):\n if x % y == 0:\n return True\n return False\ndef odd_not_prime(n):\n return sum(not_prime(x) for x in range(1, n + 1, 2))", "def odd_not_prime(n):\n return 1 + sum( any(not x%y for y in range(3,int(x*...
{"fn_name": "odd_not_prime", "inputs": [[5], [10], [99]], "outputs": [[1], [2], [26]]}
INTRODUCTORY
PYTHON3
CODEWARS
7,911
def odd_not_prime(n):
f842a83c5b7baf1614b3ef0742db407c
UNKNOWN
Santa is coming to town and he needs your help finding out who's been naughty or nice. You will be given an entire year of JSON data following this format: Your function should return `"Naughty!"` or `"Nice!"` depending on the total number of occurrences in a given year (whichever one is greater). If both are equal, r...
["def naughty_or_nice(data):\n nice = 0\n for month in data:\n for day in data[month]:\n nice += 1 if data[month][day] == \"Nice\" else -1\n return \"Nice!\" if nice >= 0 else \"Naughty!\"\n", "import json\n\ndef naughty_or_nice(data):\n parsed_data = json.dumps(data)\n return \"Nice!\"...
{"fn_name": "naughty_or_nice", "inputs": [[{"January": {"1": "Naughty", "2": "Nice", "3": "Naughty", "4": "Nice", "5": "Naughty", "6": "Nice", "7": "Naughty", "8": "Nice", "9": "Naughty", "10": "Nice", "11": "Naughty", "12": "Nice", "13": "Naughty", "14": "Nice", "15": "Naughty", "16": "Nice", "17": "Naughty", "18": "N...
INTRODUCTORY
PYTHON3
CODEWARS
1,584
def naughty_or_nice(data):
c7604f17d83ce57e1c7c27d95b756637
UNKNOWN
We have the first value of a certain sequence, we will name it ```initVal```. We define pattern list, ```patternL```, an array that has the differences between contiguous terms of the sequence. ``` E.g: patternL = [k1, k2, k3, k4]``` The terms of the sequence will be such values that: ```python term1 = initVal term2...
["from itertools import cycle\n\ndef sumDig_nthTerm(initVal, patternL, nthTerm):\n \n for c, i in enumerate(cycle(patternL), 2):\n initVal += i\n \n if c == nthTerm:\n return sum(int(v) for v in str(initVal))", "def sumDig_nthTerm(base, cycle, k):\n loop, remaining = divmod(k - ...
{"fn_name": "sumDig_nthTerm", "inputs": [[10, [2, 1, 3], 6], [10, [2, 1, 3], 15], [10, [2, 1, 3], 50], [10, [2, 1, 3], 78], [10, [2, 1, 3], 157], [10, [2, 2, 5, 8], 6], [10, [2, 2, 5, 8], 15], [10, [2, 2, 5, 8], 50], [10, [2, 2, 5, 8], 78], [10, [2, 2, 5, 8], 157], [100, [2, 2, 5, 8], 6], [100, [2, 2, 5, 8], 15], [100,...
INTRODUCTORY
PYTHON3
CODEWARS
1,034
def sumDig_nthTerm(initVal, patternL, nthTerm):
cb83485b84c20bfa5408a962b76ad1a8
UNKNOWN
# Task Given the birthdates of two people, find the date when the younger one is exactly half the age of the other. # Notes * The dates are given in the format YYYY-MM-DD and are not sorted in any particular order * Round **down** to the nearest day * Return the result as a string, like the input dates
["from dateutil.parser import parse\n\ndef half_life(*persons):\n p1,p2 = sorted(map(parse, persons))\n return str( p2+(p2-p1) )[:10]", "from datetime import datetime as dt\n\ndef half_life(p1, p2):\n d1, d2 = (dt.strptime(p, \"%Y-%m-%d\") for p in sorted((p1, p2)))\n return (d2 + (d2 - d1)).strftime(\"%Y-%...
{"fn_name": "half_life", "inputs": [["1990-12-06", "2000-02-29"], ["2012-03-31", "1990-06-09"], ["1984-08-14", "1990-04-17"], ["2000-06-30", "1978-03-17"], ["1969-12-20", "2000-10-07"]], "outputs": [["2009-05-24"], ["2034-01-21"], ["1995-12-19"], ["2022-10-14"], ["2031-07-26"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,330
def half_life(person1, person2):
4b6a191cb9993dd292dbe48857098a50
UNKNOWN
# Task Write a function named `sumEvenNumbers`, taking a sequence of numbers as single parameter. Your function must return the sum of **the even values** of this sequence. Only numbers without decimals like `4` or `4.0` can be even. ## Input * sequence of numbers: those numbers could be integers and/or floats. ...
["def sum_even_numbers(seq): \n return sum(n for n in seq if not n % 2)", "def sum_even_numbers(seq): \n return sum(x for x in seq if x%2==0)", "def sum_even_numbers(seq): \n return sum(filter(lambda n: n%2==0, seq))", "def sum_even_numbers(seq): \n # your code here\n nums = []\n b = 0\n for i in r...
{"fn_name": "sum_even_numbers", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[]], [[1337, 374, 849, 22.5, 19, 16, 0, 0, 16, 32]], [[-16, -32, 20, 21, 41, 42]], [[15397, 12422, 10495, 22729, 23921, 18326, 27955, 24073, 23690, 15002, 11615, 15682, 24346, 16725, 17252, 20467, 20493, 17807, 13041, 25861, 22471, 22747, 24...
INTRODUCTORY
PYTHON3
CODEWARS
1,094
def sum_even_numbers(seq):
74c52c9ee5e16595a333ebbdffea7a0c
UNKNOWN
In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out. ### Example ```python filter_list([1,2,'a','b']) == [1,2] filter_list([1,'a','b',0,15]) == [1,0,15] filter_list([1,2,'aasf','1','123',123]) == [1,2,123] ```
["def filter_list(l):\n 'return a new list with the strings filtered out'\n return [i for i in l if not isinstance(i, str)]\n", "def filter_list(l):\n 'return a new list with the strings filtered out'\n return [x for x in l if type(x) is not str]", "def filter_list(l):\n 'return a new list with the strings filtere...
{"fn_name": "filter_list", "inputs": [[[1, 2, "a", "b"]], [[1, "a", "b", 0, 15]], [[1, 2, "aasf", "1", "123", 123]], [["a", "b", "1"]]], "outputs": [[[1, 2]], [[1, 0, 15]], [[1, 2, 123]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
854
def filter_list(l):
24443334cb9dc11d85af63bebea6cf76
UNKNOWN
Given a name, turn that name into a perfect square matrix (nested array with the amount of arrays equivalent to the length of each array). You will need to add periods (`.`) to the end of the name if necessary, to turn it into a matrix. If the name has a length of 0, return `"name must be at least one letter"` ## ...
["from math import ceil\n\ndef matrixfy(s):\n if not s: return \"name must be at least one letter\"\n x = ceil(len(s)**.5)\n it = iter(s.ljust(x*x,'.'))\n return [ [next(it) for _ in range(x)] for _ in range(x)]", "def matrixfy(st):\n if not st:\n return 'name must be at least one letter'\n n ...
{"fn_name": "matrixfy", "inputs": [[""], ["G"], ["Beyonce"], ["Franklin"], ["Bill"], ["Frank"]], "outputs": [["name must be at least one letter"], [[["G"]]], [[["B", "e", "y"], ["o", "n", "c"], ["e", ".", "."]]], [[["F", "r", "a"], ["n", "k", "l"], ["i", "n", "."]]], [[["B", "i"], ["l", "l"]]], [[["F", "r", "a"], ["n",...
INTRODUCTORY
PYTHON3
CODEWARS
2,515
def matrixfy(st):
1fed6776106828424c750db5b53fbfb8
UNKNOWN
Learning to code around your full time job is taking over your life. You realise that in order to make significant steps quickly, it would help to go to a coding bootcamp in London. Problem is, many of them cost a fortune, and those that don't still involve a significant amount of time off work - who will pay your mor...
["def sabb(stg, value, happiness):\n sabbatical = (value + happiness + sum(1 for c in stg if c in \"sabbatical\")) > 22\n return \"Sabbatical! Boom!\" if sabbatical else \"Back to your desk, boy.\"", "def sabb(s, value, happiness):\n score = sum(c in \"sabticl\" for c in s.lower()) + value + happiness\n ret...
{"fn_name": "sabb", "inputs": [["Can I have a sabbatical?", 5, 5], ["Why are you shouting?", 7, 2], ["What do you mean I cant learn to code??", 8, 9], ["Please calm down", 9, 1], ["I can?! Nice. FaC..Im coming :D", 9, 9]], "outputs": [["Sabbatical! Boom!"], ["Back to your desk, boy."], ["Sabbatical! Boom!"], ["Back to ...
INTRODUCTORY
PYTHON3
CODEWARS
2,170
def sabb(s, value, happiness):
0ef4512efe03ce5dcaa3f7e7295b5439
UNKNOWN
Write a function that takes an integer and returns an array `[A, B, C]`, where `A` is the number of multiples of 3 (but not 5) below the given integer, `B` is the number of multiples of 5 (but not 3) below the given integer and `C` is the number of multiples of 3 and 5 below the given integer. For example, `solution(...
["def solution(number):\n A = (number - 1) // 3\n B = (number - 1) // 5\n C = (number - 1) // 15 \n return [A - C, B - C, C]", "def solution(number):\n n = number - 1\n a, b, c = n // 3, n // 5, n // 15\n return [a - c, b - c, c]", "def solution(n):\n n -= 1\n return [n//3-n//15, n//5-n//15, n...
{"fn_name": "solution", "inputs": [[20], [2020], [4], [2], [30], [300], [14], [141], [1415], [91415]], "outputs": [[[5, 2, 1]], [[539, 269, 134]], [[1, 0, 0]], [[0, 0, 0]], [[8, 4, 1]], [[80, 40, 19]], [[4, 2, 0]], [[37, 19, 9]], [[377, 188, 94]], [[24377, 12188, 6094]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,709
def solution(number):
fc5ffd6eeb52206e988602a3c0f2806b
UNKNOWN
A category page displays a set number of products per page, with pagination at the bottom allowing the user to move from page to page. Given that you know the page you are on, how many products are in the category in total, and how many products are on any given page, how would you output a simple string showing which...
["def pagination_text(page_number, page_size, total_products):\n first = page_size * (page_number - 1) + 1\n last = min(total_products, first + page_size - 1)\n return \"Showing %d to %d of %d Products.\" % (first, last, total_products)", "def pagination_text(page_number, page_size, total_products):\n lower...
{"fn_name": "pagination_text", "inputs": [[1, 10, 30], [3, 10, 26], [1, 10, 8], [2, 30, 350], [1, 23, 30], [2, 23, 30], [43, 15, 3456]], "outputs": [["Showing 1 to 10 of 30 Products."], ["Showing 21 to 26 of 26 Products."], ["Showing 1 to 8 of 8 Products."], ["Showing 31 to 60 of 350 Products."], ["Showing 1 to 23 of 3...
INTRODUCTORY
PYTHON3
CODEWARS
2,479
def pagination_text(page_number, page_size, total_products):
8058f05b997e64bef04705c0af0bd9ed
UNKNOWN
You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer `N`. Write a method that takes the array as an argument and returns this "outlier" `N`. ...
["def find_outlier(int):\n odds = [x for x in int if x%2!=0]\n evens= [x for x in int if x%2==0]\n return odds[0] if len(odds)<len(evens) else evens[0]\n", "def find_outlier(integers):\n even, odd = 0, 0\n for i in integers:\n if i % 2:\n even += 1\n last_even = i\n else:\n odd += 1\n ...
{"fn_name": "find_outlier", "inputs": [[[0, 1, 2]], [[1, 2, 3]]], "outputs": [[1], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,476
def find_outlier(integers):
f9505409b7425acdde58aa609f4d675e
UNKNOWN
*Are you a file extension master? Let's find out by checking if Bill's files are images or audio files. Please use regex if available natively for your language.* You will create 2 string methods: - **isAudio/is_audio**, matching 1 or + uppercase/lowercase letter(s) (combination possible), with the extension .mp3, .f...
["def is_audio(filename):\n name, ext = filename.split('.')\n return name.isalpha() and ext in {'mp3', 'flac', 'alac', 'aac'}\n\n\ndef is_img(filename):\n name, ext = filename.split('.')\n return name.isalpha() and ext in {'jpg', 'jpeg', 'png', 'bmp', 'gif'}", "import re\ndef is_audio(file_name):\n retur...
{"fn_name": "is_audio", "inputs": [["Nothing Else Matters.mp3"], ["NothingElseMatters.mp3"], ["DaftPunk.FLAC"], ["DaftPunk.flac"], ["AmonTobin.aac"], [" Amon Tobin.alac"], ["tobin.alac"]], "outputs": [[false], [true], [false], [true], [true], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,307
def is_audio(file_name):
81d21049f3bcf69dc357de0fe2d32cd3
UNKNOWN
Given a random string consisting of numbers, letters, symbols, you need to sum up the numbers in the string. Note: - Consecutive integers should be treated as a single number. eg, `2015` should be treated as a single number `2015`, NOT four numbers - All the numbers should be treaded as positive integer. eg, `11-14`...
["import re\ndef sum_from_string(string):\n d = re.findall(\"\\d+\",string)\n return sum(int(i) for i in d)", "import re\ndef sum_from_string(s):\n return sum(map(int, re.findall(r'\\d+', s)))", "from re import findall\n\n\ndef sum_from_string(string):\n return sum(int(a) for a in findall(r'\\d+', string))\...
{"fn_name": "sum_from_string", "inputs": [["In 2015, I want to know how much does iPhone 6+ cost?"], ["1+1=2"], ["e=mc^2"], ["aHR0cDovL3d3dy5jb2Rld2Fycy5jb20va2F0YS9uZXcvamF2YXNjcmlwdA=="], ["a30561ff4fb19170aa598b1431b52edad1fcc3e0"], ["x1KT CmZ__\rYouOY8Uqu-ETtz"], ["x1KT-8&*@\"CmZ__\rYouO __Y8Uq\\u-ETtz"], [""], ...
INTRODUCTORY
PYTHON3
CODEWARS
1,416
def sum_from_string(string):
ec02b41c00bbda002c9dda1186443e28
UNKNOWN
The characters of Chima need your help. Their weapons got mixed up! They need you to write a program that accepts the name of a character in Chima then tells which weapon he/she owns. For example: for the character `"Laval"` your program should return the solution `"Laval-Shado Valious"` You must complete the followi...
["def identify_weapon(character):\n tbl = {\n \"Laval\" : \"Laval-Shado Valious\",\n \"Cragger\" : \"Cragger-Vengdualize\",\n \"Lagravis\" : \"Lagravis-Blazeprowlor\",\n \"Crominus\" : \"Crominus-Grandorius\",\n \"Tormak\" : \"Tormak-Tygafyre\",\n \"LiElla\" : \"LiElla-Roarburn\...
{"fn_name": "identify_weapon", "inputs": [["Laval"], ["Crominus"], ["Lagravis"], ["Cragger"], ["Tormak"], ["LiElla"], ["G'loona"], ["Stinkin gorillas"], ["qwertyuiopasdfghjklzxcvbnm"]], "outputs": [["Laval-Shado Valious"], ["Crominus-Grandorius"], ["Lagravis-Blazeprowlor"], ["Cragger-Vengdualize"], ["Tormak-Tygafyre"],...
INTRODUCTORY
PYTHON3
CODEWARS
3,731
def identify_weapon(character):
82057897b194625c8d858ecedd7cc137
UNKNOWN
## Emotional Sort ( ︶︿︶) You'll have a function called "**sortEmotions**" that will return an array of **emotions** sorted. It has two parameters, the first parameter called "**arr**" will expect an array of **emotions** where an **emotion** will be one of the following: - **:D** -> Super Happy - **:)** -> Happy - **...
["def sort_emotions(arr, order):\n return sorted(arr, key=[':D',':)',':|',':(','T_T'].index, reverse=not order)", "def get_face(face):\n faces = { ':D':0, ':)':1, ':|':2, ':(':3, 'T_T':4 }\n return faces[face]\n\ndef sort_emotions(arr, order):\n return sorted(arr, key=get_face, reverse= not order)\n", "def ...
{"fn_name": "sort_emotions", "inputs": [[[":D", "T_T", ":D", ":("], true], [["T_T", ":D", ":(", ":("], true], [[":)", "T_T", ":)", ":D", ":D"], true], [[":D", "T_T", ":D", ":("], false], [["T_T", ":D", ":(", ":("], false], [[":)", "T_T", ":)", ":D", ":D"], false], [[], false], [[], true]], "outputs": [[[":D", ":D", ":(...
INTRODUCTORY
PYTHON3
CODEWARS
1,647
def sort_emotions(arr, order):
5ad14c02bb5720f1fa018cac7a981794
UNKNOWN
Python dictionaries are inherently unsorted. So what do you do if you need to sort the contents of a dictionary? Create a function that returns a sorted list of `(key, value)` tuples (Javascript: arrays of 2 items). The list must be sorted by the `value` and be sorted **largest to smallest**. ## Examples ```python ...
["def sort_dict(d):\n return sorted(d.items(), key=lambda x: x[1], reverse=True)", "from operator import itemgetter\n\ndef sort_dict(d):\n 'return a sorted list of tuples from the dictionary'\n return sorted(d.items(), key=itemgetter(1), reverse=True)", "def sort_dict(d):\n 'return a sorted list of tuples from the ...
{"fn_name": "sort_dict", "inputs": [[{"1": 3, "2": 2, "3": 1}], [{"1": 2, "2": 4, "3": 6}], [{"1": 5, "3": 10, "2": 2, "6": 3, "8": 8}], [{"a": 6, "b": 2, "c": 4}]], "outputs": [[[[1, 3], [2, 2], [3, 1]]], [[[3, 6], [2, 4], [1, 2]]], [[[3, 10], [8, 8], [1, 5], [6, 3], [2, 2]]], [[["a", 6], ["c", 4], ["b", 2]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,115
def sort_dict(d):
9379dfcaf88cf6c22de54e515ac2c19c
UNKNOWN
You are making your very own boardgame. The game is played by two opposing players, featuring a 6 x 6 tile system, with the players taking turns to move their pieces (similar to chess). The design is finished, now it's time to actually write and implement the features. Being the good programmer you are, you carefully p...
["def fight_resolve(d, a):\n return -1 if d.islower() == a.islower() else d if d.lower() + a.lower() in \"ka sp as pk\" else a", "def fight_resolve(d, a):\n return -1 if d.islower() == a.islower() else d if f\"{d}{a}\".lower() in \"aspka\" else a", "def fight_resolve(defender, attacker):\n res = attacker\n ...
{"fn_name": "fight_resolve", "inputs": [["K", "A"], ["S", "A"], ["k", "s"], ["a", "a"], ["k", "A"], ["K", "a"]], "outputs": [[-1], [-1], [-1], [-1], ["k"], ["K"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,087
def fight_resolve(defender, attacker):
ef4c68bbb529cb97cf5b2cedcfd59710
UNKNOWN
A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible pairs. For example `12` is the LCM of `(1, 12), (2, 12), (3,4)` etc. For a given positive integer N, the number of different integer pairs with LCM is equal to N can be called the LCM cardinality of that number N. In this ka...
["from itertools import combinations\nfrom math import gcd\n\n\ndef lcm_cardinality(n):\n return 1 + sum(1 for a, b in combinations(divisors(n), 2) if lcm(a, b) == n)\n \ndef divisors(n):\n d = {1, n}\n for k in range(2, int(n**0.5) + 1):\n if n % k == 0:\n d.add(k)\n d.add(...
{"fn_name": "lcm_cardinality", "inputs": [[1], [12], [24], [25], [101101291], [12345676], [1251562], [625], [9801], [30858025]], "outputs": [[1], [8], [11], [3], [5], [68], [41], [5], [23], [63]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,537
def lcm_cardinality(n):
a0a15f992114c2f8f01e8539542768a5
UNKNOWN
Write a program to determine if a string contains only unique characters. Return true if it does and false otherwise. The string may contain any of the 128 ASCII characters. Characters are case-sensitive, e.g. 'a' and 'A' are considered different characters.
["def has_unique_chars(s):\n return len(s) == len(set(s))", "def has_unique_chars(str):\n return len(set(str))==len(str)", "def has_unique_chars(s):\n return len(set(s)) == len(s)", "def has_unique_chars(s):\n return len(s) <= 128 and len(s) == len(set(s))", "def has_unique_chars(str):\n return len(str) == len...
{"fn_name": "has_unique_chars", "inputs": [[" nAa"], ["abcdef"], ["++-"]], "outputs": [[false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
774
def has_unique_chars(str):
a15729280f553ba7e9c61eb837c697ed
UNKNOWN
You would like to get the 'weight' of a name by getting the sum of the ascii values. However you believe that capital letters should be worth more than mere lowercase letters. Spaces, numbers, or any other character are worth 0. Normally in ascii a has a value of 97 A has a value of 65 ' ' has a value of ...
["def get_weight(name):\n return sum(ord(a) for a in name.swapcase() if a.isalpha())", "def get_weight(name):\n return sum(ord(c.swapcase()) for c in name if c.isalpha())", "import string as q\n\ndef get_weight(name):\n return sum(ord(char.swapcase()) for char in name if char in q.ascii_letters)", "def get_wei...
{"fn_name": "get_weight", "inputs": [["Joe"], ["CJ"], ["cj"], ["George Washington"], ["Billy Bob Joe"], ["King George II"], ["r2d2"], ["R2D2"], ["C3PO"]], "outputs": [[254], [205], [141], [1275], [909], [1012], [150], [214], [322]]}
INTRODUCTORY
PYTHON3
CODEWARS
895
def get_weight(name):
6970dbaa65b2dfc460a919688fb4dd37
UNKNOWN
# Story Due to lack of maintenance the minute-hand has fallen off Town Hall clock face. And because the local council has lost most of our tax money to a Nigerian email scam there are no funds to fix the clock properly. Instead, they are asking for volunteer programmers to write some code that tell the time by only...
["def what_time_is_it(angle):\n hr = int(angle // 30)\n mn = int((angle % 30) * 2)\n if hr == 0:\n hr = 12\n return '{:02d}:{:02d}'.format(hr, mn)", "def what_time_is_it(angle):\n angle %= 360\n h, m = divmod(angle, 30)\n return '{:02}:{:02}'.format(int(h or 12), int(m * 2))", "import time\n...
{"fn_name": "what_time_is_it", "inputs": [[0], [360], [90], [180], [270], [30], [40], [45], [50], [60]], "outputs": [["12:00"], ["12:00"], ["03:00"], ["06:00"], ["09:00"], ["01:00"], ["01:20"], ["01:30"], ["01:40"], ["02:00"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,083
def what_time_is_it(angle):
a43dd0087f40cb5c9d5f7ffe18a0f2bd
UNKNOWN
The integers 14 and 15, are contiguous (1 the difference between them, obvious) and have the same number of divisors. ```python 14 ----> 1, 2, 7, 14 (4 divisors) 15 ----> 1, 3, 5, 15 (4 divisors) ``` The next pair of contiguous integers with this property is 21 and 22. ```python 21 -----> 1, 3, 7, 21 (4 divisors) 22 --...
["def count_pairs_int(d, m):\n return sum(1 for i in range(1, m - d) if divisors(i) == divisors(i + d))\n\ndef divisors(n):\n return sum(1 + (n // k != k) for k in range(1, int(n**0.5) + 1) if n % k == 0)\n", "import numpy as np\n\nN = 100001\nxs = np.ones(N)\nxs[:2] = 0\nfor i in range(2, N//2):\n xs[i*2::i] ...
{"fn_name": "count_pairs_int", "inputs": [[1, 50], [3, 100], [3, 200], [6, 350], [6, 1000], [7, 1500], [7, 2500], [7, 3000], [9, 4000], [9, 5000], [11, 5000]], "outputs": [[8], [7], [18], [86], [214], [189], [309], [366], [487], [622], [567]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,016
def count_pairs_int(diff, n_max):
ccf00199b3fb5ea40bad7766736b250f
UNKNOWN
In order to prove it's success and gain funding, the wilderness zoo needs to prove to environmentalists that it has x number of mating pairs of bears. You must check within string (s) to find all of the mating pairs, and return a string containing only them. Line them up for inspection. Rules: Bears are either 'B' (...
["import re\n\ndef bears(n, s):\n a = re.findall(r\"B8|8B\", s)\n return [\"\".join(a), len(a) >= n]", "import re\ndef bears(x,s):\n r = re.findall(r'8B|B8', s)\n return [''.join(r),len(r)>=x]", "from regex import findall\n\ndef bears(x, s):\n res = findall(r\"(B8|8B)\", s)\n return [''.join(res), len...
{"fn_name": "bears", "inputs": [[7, "8j8mBliB8gimjB8B8jlB"], [3, "88Bifk8hB8BB8BBBB888chl8BhBfd"], [8, "8"], [1, "j8BmB88B88gkBBlf8hg8888lbe88"], [0, "8j888aam"]], "outputs": [[["B8B8B8", false]], [["8BB8B8B88B", true]], [["", false]], [["8BB88B", true]], [["", true]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,053
def bears(x,s):
da11b4b40842c64d5a509aa01d058a62
UNKNOWN
You managed to send your friend to queue for tickets in your stead, but there is a catch: he will get there only if you tell him how much that is going to take. And everybody can only take one ticket at a time, then they go back in the last position of the queue if they need more (or go home if they are fine). Each ti...
["def queue(queuers,pos):\n return sum(min(queuer, queuers[pos] - (place > pos)) for place, queuer in enumerate(queuers))", "def queue(queuers,pos):\n friendWait = queuers[pos]\n # Divide the line into the front of the line (up to the friend)\n # and back of the line (behind the friend):\n frontOfLine = ...
{"fn_name": "queue", "inputs": [[[2, 5, 3, 6, 4], 0], [[2, 5, 3, 6, 4], 1], [[2, 5, 3, 6, 4], 2], [[2, 5, 3, 6, 4], 3], [[2, 5, 3, 6, 4], 4]], "outputs": [[6], [18], [12], [20], [17]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,368
def queue(queuers,pos):
29806f4889c083f617788cc7f1d1fb8b
UNKNOWN
# Valid HK Phone Number ## Overview In Hong Kong, a valid phone number has the format ```xxxx xxxx``` where ```x``` is a decimal digit (0-9). For example: ## Task Define two functions, ```isValidHKPhoneNumber``` and ```hasValidHKPhoneNumber```, that ```return```s whether a given string is a valid HK phone number a...
["import re\n\nHK_PHONE_NUMBER = '\\d{4} \\d{4}'\n\ndef is_valid_HK_phone_number(number):\n return bool(re.match(HK_PHONE_NUMBER+'\\Z',number))\n\ndef has_valid_HK_phone_number(number):\n return bool(re.search(HK_PHONE_NUMBER,number))", "from re import match, search\n\nis_valid_HK_phone_number = lambda n: match('...
{"fn_name": "is_valid_HK_phone_number", "inputs": [["1234 5678"], ["2359 1478"], ["85748475"], ["3857 4756"], ["sklfjsdklfjsf"], [" 1234 5678 "], ["abcd efgh"], ["9684 2396"], ["836g 2986"], ["0000 0000"], ["123456789"], [" 987 634 "], [" 6 "], ["8A65 2986"], ["8368 2aE6"], ["8c65 2i86"]], "outputs": [[tru...
INTRODUCTORY
PYTHON3
CODEWARS
2,299
def is_valid_HK_phone_number(number):
3f7491fb2c16b802cc33a6247cef0109
UNKNOWN
My washing machine uses ```water``` amount of water to wash ```clothes``` amount of clothes. You are given a ```load``` amount of clothes to wash. For each single item of load above the standard amount of clothes, the washing machine will use 10% more water (multiplicative) to clean. For example, if the amount of clot...
["def how_much_water(water, clothes, load):\n if load > 2 * clothes:\n return \"Too much clothes\"\n\n if load < clothes:\n return \"Not enough clothes\"\n\n for i in range(load - clothes):\n water *= 1.1\n\n return round(water, 2)", "def how_much_water(l, x, n):\n return \"Too much ...
{"fn_name": "how_much_water", "inputs": [[10, 10, 21], [10, 10, 2], [10, 11, 20], [50, 15, 29], [50, 15, 15]], "outputs": [["Too much clothes"], ["Not enough clothes"], [23.58], [189.87], [50]]}
INTRODUCTORY
PYTHON3
CODEWARS
24,486
def how_much_water(water, load, clothes):
8f84e6de0edc7ca004fe81b8a6611448
UNKNOWN
Some new animals have arrived at the zoo. The zoo keeper is concerned that perhaps the animals do not have the right tails. To help her, you must correct the broken function to make sure that the second argument (tail), is the same as the last letter of the first argument (body) - otherwise the tail wouldn't fit! If t...
["def correct_tail(body, tail):\n return body.endswith(tail)\n", "def correct_tail(body, tail):\n return body[-1] == tail", "def correct_tail(body, tail):\n sub = body[len(body)-len(tail)]\n if sub == tail:\n return True\n else:\n return False", "correct_tail = str.endswith", "def correct_t...
{"fn_name": "correct_tail", "inputs": [["Fox", "x"], ["Rhino", "o"], ["Meerkat", "t"], ["Emu", "t"], ["Badger", "s"], ["Giraffe", "d"]], "outputs": [[true], [true], [true], [false], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
12,880
def correct_tail(body, tail):
d1ddf4a312c6d852cb853c28ec48884b
UNKNOWN
# Task John is a programmer. He treasures his time very much. He lives on the `n` floor of a building. Every morning he will go downstairs as quickly as possible to begin his great work today. There are two ways he goes downstairs: walking or taking the elevator. When John uses the elevator, he will go through the f...
["def shortest_time(n, m, speeds):\n lift, open, close, walk = speeds\n return min(\n # taking the elevator\n abs(m - n) * lift + open + close + (n - 1) * lift + open,\n # walking\n (n - 1) * walk\n )", "def shortest_time(n, m, speeds):\n a, b, c, d = spee...
{"fn_name": "shortest_time", "inputs": [[5, 6, [1, 2, 3, 10]], [1, 6, [1, 2, 3, 10]], [5, 5, [1, 2, 3, 10]], [2, 2, [1, 2, 3, 10]], [2, 2, [2, 3, 4, 10]], [5, 4, [1, 2, 3, 10]], [5, 4, [2, 3, 4, 5]], [1, 6, [0, 0, 0, 0]], [1, 6, [0, 2, 0, 0]], [1, 6, [20, 0, 10, 0]]], "outputs": [[12], [0], [11], [8], [10], [12], [20],...
INTRODUCTORY
PYTHON3
CODEWARS
1,725
def shortest_time(n, m, speeds):
867efa376d3633a93b81ebbfe63c8717
UNKNOWN
You've purchased a ready-meal from the supermarket. The packaging says that you should microwave it for 4 minutes and 20 seconds, based on a 600W microwave. Oh no, your microwave is 800W! How long should you cook this for?! ___ # Input You'll be given 4 arguments: ## 1. needed power The power of the needed microw...
["import math\n\ndef cooking_time(needed_power, minutes, seconds, power):\n t = math.ceil((60 * minutes + seconds) * int(needed_power[:-1]) / int(power[:-1]))\n return '%d minutes %d seconds' %(t // 60, t - t // 60 * 60)", "cooking_time=lambda n,m,s,p:'{} minutes {} seconds'.format(*divmod(-(-(m*60+s)*int(n[:-1])...
{"fn_name": "cooking_time", "inputs": [["600W", 4, 20, "800W"], ["800W", 3, 0, "1200W"], ["100W", 8, 45, "50W"], ["7500W", 0, 5, "600W"], ["450W", 3, 25, "950W"], ["21W", 64, 88, "25W"], ["83W", 61, 80, "26W"], ["38W", 95, 22, "12W"]], "outputs": [["3 minutes 15 seconds"], ["2 minutes 0 seconds"], ["17 minutes 30 secon...
INTRODUCTORY
PYTHON3
CODEWARS
2,494
def cooking_time(needed_power, minutes, seconds, power):
b85937af7bbb58b31d470f98cd23b72b
UNKNOWN
In this Kata, we are going to determine if the count of each of the characters in a string can be equal if we remove a single character from that string. For example: ``` solve('abba') = false -- if we remove any character, the count of each character will not be equal. solve('abbba') = true -- if we remove one b, the...
["from collections import Counter\n\ndef solve(s):\n return any(len(set(Counter(s.replace(c, '', 1)).values())) == 1 for c in s)", "from collections import Counter\n\ndef solve(s):\n c = Counter(s).values()\n cVal, mi, ma = Counter(c), min(c), max(c)\n return len(cVal) <= 2 and (len(cVal) == 1 and (1 in cVa...
{"fn_name": "solve", "inputs": [["aaaa"], ["abba"], ["abbba"], ["aabbcc"], ["aaaabb"], ["aabbccddd"], ["aabcde"], ["abcde"], ["aaabcde"], ["abbccc"]], "outputs": [[true], [false], [true], [false], [false], [true], [true], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,073
def solve(s):
33c9727ed9aca0ea96edad581aea7064
UNKNOWN
# Task A cake is sliced with `n` straight lines. Your task is to calculate the maximum number of pieces the cake can have. # Example For `n = 0`, the output should be `1`. For `n = 1`, the output should be `2`. For `n = 2`, the output should be `4`. For `n = 3`, the output should be `7`. See the followin...
["def cake_slice(n):\n return (n ** 2 + n + 2) // 2", "def cake_slice(n):\n return 0.5*n**2+0.5*n+1", "def cake_slice(n):\n return (n**2 + n) // 2 + 1", "cake_slice = lambda n: sum(range(n + 1)) + 1", "def cake_slice(n):\n #coding and coding...\n sum = 1\n for i in range(n):\n sum += i+1\n ret...
{"fn_name": "cake_slice", "inputs": [[0], [1], [2], [3], [10]], "outputs": [[1], [2], [4], [7], [56]]}
INTRODUCTORY
PYTHON3
CODEWARS
652
def cake_slice(n):
9897f6d53a1fffa286bc3c2937150e44
UNKNOWN
## A square of squares You like building blocks. You especially like building blocks that are squares. And what you even like more, is to arrange them into a square of square building blocks! However, sometimes, you can't arrange them into a square. Instead, you end up with an ordinary rectangle! Those blasted things!...
["import math\ndef is_square(n):\n return n > -1 and math.sqrt(n) % 1 == 0;", "import math\n\ndef is_square(n): \n\n if n < 0:\n return False\n\n sqrt = math.sqrt(n)\n \n return sqrt.is_integer()", "def is_square(n): \n return n >= 0 and (n**0.5) % 1 == 0", "import math\ndef is_square(n):...
{"fn_name": "is_square", "inputs": [[-1], [25], [26]], "outputs": [[false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,199
def is_square(n):
d032402dd2bb7db090f52ea4572bf408
UNKNOWN
Consider a game, wherein the player has to guess a target word. All the player knows is the length of the target word. To help them in their goal, the game will accept guesses, and return the number of letters that are in the correct position. Write a method that, given the correct word and the player's guess, return...
["def count_correct_characters(c, g):\n if len(c) != len(g): raise Exception('Error')\n return sum(1 for i,j in zip(c,g) if i==j)", "def count_correct_characters(s, t):\n assert len(s) == len(t)\n return sum(a == b for a, b in zip(s, t))", "def count_correct_characters(correct, guess):\n if len(correct) ...
{"fn_name": "count_correct_characters", "inputs": [["dog", "car"], ["dog", "god"], ["dog", "cog"], ["dog", "cod"], ["dog", "bog"], ["dog", "dog"], ["abcde", "abcde"], ["same", "same"], ["z", "z"]], "outputs": [[0], [1], [2], [1], [2], [3], [5], [4], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,813
def count_correct_characters(correct, guess):
4d199541c9017ea4893fec6f40e83dc7
UNKNOWN
After a hard quarter in the office you decide to get some rest on a vacation. So you will book a flight for you and your girlfriend and try to leave all the mess behind you. You will need a rental car in order for you to get around in your vacation. The manager of the car rental makes you some good offers. Every day ...
["def rental_car_cost(d):\n result = d * 40\n if d >= 7:\n result -= 50\n elif d >= 3:\n result -= 20\n return result", "def rental_car_cost(d):\n return d * 40 - (d > 2) * 20 - (d > 6) * 30", "def rental_car_cost(d):\n discount = 0\n if d >= 7:\n discount = 50\n elif d >= 3:\...
{"fn_name": "rental_car_cost", "inputs": [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]], "outputs": [[40], [80], [100], [140], [180], [220], [230], [270], [310], [350]]}
INTRODUCTORY
PYTHON3
CODEWARS
14,231
def rental_car_cost(d):
92d37a57ecde88bebff10408a544873c
UNKNOWN
# Bubblesort Algorithm ## Overview The Bubblesort Algorithm is one of many algorithms used to sort a list of similar items (e.g. all numbers or all letters) into either ascending order or descending order. Given a list (e.g.): ```python [9, 7, 5, 3, 1, 2, 4, 6, 8] ``` To sort this list in ascending order using Bub...
["def bubblesort_once(l):\n l = l[:]\n for i in range(len(l)-1):\n if l[i] > l[i+1]:\n l[i], l[i+1] = l[i+1], l[i]\n return l", "def bubblesort_once(L):\n if len(L)<=1 : return L\n if L[0]<=L[1]: return [L[0]] + bubblesort_once(L[1:])\n return [L[1]] + bubblesort_once([L[0]]+L[2:])",...
{"fn_name": "bubblesort_once", "inputs": [[[9, 7, 5, 3, 1, 2, 4, 6, 8]], [[1, 2]], [[2, 1]], [[1, 3]], [[3, 1]], [[24, 57]], [[89, 36]], [[1, 2, 3]], [[2, 4, 1]], [[17, 5, 11]], [[25, 16, 9]], [[103, 87, 113]], [[1032, 3192, 2864]], [[1, 2, 3, 4]], [[2, 3, 4, 1]], [[3, 4, 1, 2]], [[4, 1, 2, 3]], [[7, 5, 3, 1]], [[5, 3,...
INTRODUCTORY
PYTHON3
CODEWARS
1,909
def bubblesort_once(l):
d7521d85490bb10cdd6b9e70a591fe99
UNKNOWN
A special type of prime is generated by the formula `p = 2^m * 3^n + 1` where `m` and `n` can be any non-negative integer. The first `5` of these primes are `2, 3, 5, 7, 13`, and are generated as follows: ```Haskell 2 = 2^0 * 3^0 + 1 3 = 2^1 * 3^0 + 1 5 = 2^2 * 3^0 + 1 7 = 2^1 * 3^1 + 1 13 = 2^2 * 3^1 + 1 ..and so on...
["sb_primes = [2, 3, 5, 7, 13, 17, 19, 37, 73, 97, 109, 163, 193, 257, 433, 487, 577, 769, 1153, 1297, 1459, 2593, 2917, 3457, 3889, 10369, 12289, 17497, 18433, 39367, 52489, 65537, 139969, 147457, 209953, 331777, 472393, 629857, 746497, 786433, 839809, 995329, 1179649, 1492993]\n\ndef solve(x, y):\n return sum(x <=...
{"fn_name": "solve", "inputs": [[0, 10], [0, 15], [0, 100], [100, 1000], [340, 500], [3400, 5000], [20000, 60000], [750000, 1000000], [300000, 900000], [100, 1000000], [500000, 1000000], [1000000, 1500000], [0, 1500000]], "outputs": [[4], [5], [10], [8], [2], [2], [2], [3], [6], [32], [5], [2], [44]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,477
def solve(x, y):
292b042d4f25db7603226a58e1071426
UNKNOWN
In this Kata, you will be given a list of strings and your task will be to find the strings that have the same characters and return the sum of their positions as follows: ```Haskell solve(["abc","abbc", "ab", "xyz", "xy", "zzyx"]) = [1,8] -- we see that the elements at indices 0 and 1 have the same characters, as do...
["from collections import defaultdict\n\ndef solve(arr):\n dct = defaultdict(list)\n for i,fs in enumerate(map(frozenset, arr)):\n dct[fs].append(i)\n return sorted(sum(lst) for lst in dct.values() if len(lst) > 1)", "def solve(lst):\n seen, result = set(), []\n for i, st1 in enumerate(lst):\n ...
{"fn_name": "solve", "inputs": [[["abc", "abbc", "ab", "xyz", "xy", "zzyx"]], [["wkskkkkkk", "fokoo", "wkskk", "uizzzz", "fokooff", "wkskkkk", "uizzzzzzz"]], [["xhuhhh", "dghgg", "dghgghh", "mrerrrrrr", "xhuhhhhhh", "mrerrr"]], [["uczcccccc", "idffffiii", "pnjjjjjjj", "pnjjjj", "idffff", "uczcccc", "uczcc"]], [["rvjvvv...
INTRODUCTORY
PYTHON3
CODEWARS
2,261
def solve(arr):
054e60c90d23ecde4da98d010cca5d44
UNKNOWN
[Generala](https://en.wikipedia.org/wiki/Generala) is a dice game popular in South America. It's very similar to [Yahtzee](https://en.wikipedia.org/wiki/Yahtzee) but with a different scoring approach. It is played with 5 dice, and the possible results are: | Result | Points | Rules ...
["def points(dice):\n dice = sorted([int(d) for d in dice])\n counts = [dice.count(i) for i in range(1, 7)]\n if 5 in counts:\n # GENERALA\n return 50\n if 4 in counts:\n # POKER\n return 40\n if 3 in counts and 2 in counts:\n # FULLHOUSE\n return 30\n if coun...
{"fn_name": "points", "inputs": [["55555"], ["44444"], ["44441"], ["33233"], ["22262"], ["12121"], ["44455"], ["66116"], ["12345"], ["23456"], ["34561"], ["13564"], ["62534"], ["44421"], ["61623"], ["12346"]], "outputs": [[50], [50], [40], [40], [40], [30], [30], [30], [20], [20], [20], [20], [20], [0], [0], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
12,524
def points(dice):
0fb001223fea586dca72c718f9409d38
UNKNOWN
Complete the method which accepts an array of integers, and returns one of the following: * `"yes, ascending"` - if the numbers in the array are sorted in an ascending order * `"yes, descending"` - if the numbers in the array are sorted in a descending order * `"no"` - otherwise You can assume the array will always ...
["def is_sorted_and_how(arr):\n if arr == sorted(arr):\n return 'yes, ascending' \n elif arr == sorted(arr)[::-1]:\n return 'yes, descending'\n else:\n return 'no'", "def is_sorted_and_how(arr):\n if arr == sorted(arr):\n return 'yes, ascending'\n elif arr == sorted(arr, reverse=Tru...
{"fn_name": "is_sorted_and_how", "inputs": [[[1, 2]], [[15, 7, 3, -8]], [[4, 2, 30]]], "outputs": [["yes, ascending"], ["yes, descending"], ["no"]]}
INTRODUCTORY
PYTHON3
CODEWARS
29,636
def is_sorted_and_how(arr):
22db7725559179c0390b816fafdb60ab
UNKNOWN
Everyone knows passphrases. One can choose passphrases from poems, songs, movies names and so on but frequently they can be guessed due to common cultural references. You can get your passphrases stronger by different means. One is the following: choose a text in capital letters including or not digits and non alphab...
["def play_pass(s, n):\n\n # Step 1, 2, 3\n shiftText = \"\"\n for char in s:\n if char.isdigit():\n shiftText += str(9 - int(char))\n elif char.isalpha():\n shifted = ord(char.lower()) + n\n shiftText += chr(shifted) if shifted <= ord('z') else chr(shifted - 26)\...
{"fn_name": "play_pass", "inputs": [["I LOVE YOU!!!", 1], ["I LOVE YOU!!!", 0], ["AAABBCCY", 1], ["MY GRANMA CAME FROM NY ON THE 23RD OF APRIL 2015", 2], ["TO BE HONEST WITH YOU I DON'T USE THIS TEXT TOOL TOO OFTEN BUT HEY... MAYBE YOUR NEEDS ARE DIFFERENT.", 5], ["IN 2012 TWO CAMBRIDGE UNIVERSITY RESEARCHERS ANALYSED ...
INTRODUCTORY
PYTHON3
CODEWARS
3,632
def play_pass(s, n):
79df791eab57353d8a0062e2c9082f97
UNKNOWN
Write a function named sumDigits which takes a number as input and returns the sum of the absolute value of each of the number's decimal digits. For example: ```python sum_digits(10) # Returns 1 sum_digits(99) # Returns 18 sum_digits(-32) # Returns 5 ``` Let's assume that all numbers in the input will be int...
["def sum_digits(number):\n return sum(map(int, str(abs(number))))", "def sum_digits(n):\n return eval('+'.join(str(abs(n))))", "def sum_digits(number):\n num_string = str(abs(number))\n total = 0\n \n for char in num_string:\n total += int(char)\n \n return total", "def sum_digits(number...
{"fn_name": "sum_digits", "inputs": [[10], [99], [-32], [1234567890], [0], [666], [100000002], [800000009]], "outputs": [[1], [18], [5], [45], [0], [18], [3], [17]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,318
def sum_digits(number):
6b94d12267c5eb0e9ac3de0c74efbeeb
UNKNOWN
You are asked to write a simple cypher that rotates every character (in range [a-zA-Z], special chars will be ignored by the cipher) by 13 chars. As an addition to the original ROT13 cipher, this cypher will also cypher numerical digits ([0-9]) with 5 chars. Example: "The quick brown fox jumps over the 2 lazy dog...
["trans = \"abcdefghijklmnopqrstuvwxyz\" * 2\ntrans += trans.upper() + \"0123456789\" * 2\n\ndef ROT135(input):\n output = []\n for c in input:\n if c.isalpha():\n c = trans[trans.index(c) + 13]\n elif c.isdigit():\n c = trans[trans.index(c) + 5]\n output.append(c)\n ...
{"fn_name": "ROT135", "inputs": [["The quick brown fox jumps over the 2 lazy dogs"], ["Gur dhvpx oebja sbk whzcf bire gur 7 ynml qbtf"], ["1234567890"], ["12_-56789."]], "outputs": [["Gur dhvpx oebja sbk whzcf bire gur 7 ynml qbtf"], ["The quick brown fox jumps over the 2 lazy dogs"], ["6789012345"], ["67_-01234."]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,042
def ROT135(input):
e34b21a241e18a84f42104a92ffb902a
UNKNOWN
To celebrate today's launch of my Hero's new book: Alan Partridge: Nomad, We have a new series of kata arranged around the great man himself. Given an array of terms, if any of those terms relate to Alan Partridge, return Mine's a Pint! The number of ! after the t should be determined by the number of Alan related te...
["def part(arr):\n l = [\"Partridge\", \"PearTree\", \"Chat\", \"Dan\", \"Toblerone\", \"Lynn\", \"AlphaPapa\", \"Nomad\"]\n s = len([i for i in arr if i in l])\n return \"Mine's a Pint\"+\"!\"*s if s>0 else 'Lynn, I\\'ve pierced my foot on a spike!!'", "def part(arr):\n terms = {'Partridge', 'PearTree', 'C...
{"fn_name": "part", "inputs": [[["Grouse", "Partridge", "Pheasant"]], [["Pheasant", "Goose", "Starling", "Robin"]], [["Grouse", "Partridge", "Partridge", "Partridge", "Pheasant"]], [[]], [["Grouse", "Partridge", "Pheasant", "Goose", "Starling", "Robin", "Thrush", "Emu", "PearTree", "Chat", "Dan", "Square", "Toblerone",...
INTRODUCTORY
PYTHON3
CODEWARS
2,689
def part(arr):
6294068a925c83c5ae35bc74d86402db
UNKNOWN
Find the greatest common divisor of two positive integers. The integers can be large, so you need to find a clever solution. The inputs `x` and `y` are always greater or equal to 1, so the greatest common divisor will always be an integer that is also greater or equal to 1.
["#Try to make your own gcd method without importing stuff\ndef mygcd(x,y):\n #GOOD LUCK\n while y:\n x,y=y,x%y\n return x", "def mygcd(x,y):\n return x if y == 0 else mygcd(y, x % y)\n", "def mygcd(x,y):\n if x%y == 0:\n return y\n else:\n return mygcd(y,x%y)\n\n# reference: http:/...
{"fn_name": "mygcd", "inputs": [[1, 3], [60, 12], [2672, 5678], [10927782, 6902514], [1590771464, 1590771620]], "outputs": [[1], [12], [334], [846], [4]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,267
def mygcd(x,y):
4666b9998396755de7e1ec196334070f
UNKNOWN
## Task Find the sum of the first `n` elements in the Recamán Sequence. Input range: ```python 1000 tests 0 <= n <= 2,500,000 ``` ___ ## Sequence The sequence is formed using the next formula: * We start with `0` * At each step `i`, we subtract `i` from the previous number * If the result is not negative, and not...
["S, SS, SUM = [0], {0}, [0]\n\ndef rec(n):\n while len(S)<=n:\n v = S[-1] - len(S)\n if v<= 0 or v in SS: v += 2*len(S)\n S.append(v)\n SS.add(v)\n SUM.append(SUM[-1]+v)\n return SUM[n-1]", "# precaclulate results\nLIMIT = 2500000\nRECA_SUM = [0, 0]\nseen = {0}\nlast = 0\ntotal...
{"fn_name": "rec", "inputs": [[0], [1], [2], [5], [100], [200], [1000], [10000]], "outputs": [[0], [0], [1], [12], [7496], [36190], [837722], [82590002]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,392
def rec(x):
152eab544f4c602c7d7dc687d565229d
UNKNOWN
Implement a method that accepts 3 integer values a, b, c. The method should return true if a triangle can be built with the sides of given length and false in any other case. (In this case, all triangles must have surface greater than 0 to be accepted).
["def is_triangle(a, b, c):\n return (a<b+c) and (b<a+c) and (c<a+b)\n", "def is_triangle(a, b, c):\n a, b, c = sorted([a, b, c])\n return a + b > c\n", "def is_triangle(a, b, c):\n return (a + b) > c and (a + c) > b and (b + c) > a\n", "def is_triangle(a, b, c):\n \"\"\"Determine if three sides of given...
{"fn_name": "is_triangle", "inputs": [[1, 2, 2], [7, 2, 2], [1, 2, 3], [1, 3, 2], [3, 1, 2], [5, 1, 2], [1, 2, 5], [2, 5, 1], [4, 2, 3], [5, 1, 5], [2, 2, 2], [-1, 2, 3], [1, -2, 3], [1, 2, -3], [0, 2, 3]], "outputs": [[true], [false], [false], [false], [false], [false], [false], [false], [true], [true], [true], [false...
INTRODUCTORY
PYTHON3
CODEWARS
17,419
def is_triangle(a, b, c):
61dc6c11c3206679b203ab959ab37031
UNKNOWN
Consider the numbers `6969` and `9116`. When you rotate them `180 degrees` (upside down), these numbers remain the same. To clarify, if we write them down on a paper and turn the paper upside down, the numbers will be the same. Try it and see! Some numbers such as `2` or `5` don't yield numbers when rotated. Given a r...
["REV = {'6':'9', '9':'6'}\nBASE = set(\"01869\")\n\ndef isReversible(n):\n s = str(n)\n return ( not (set(s) - BASE) # contains only reversible characters\n and (not len(s)%2 or s[len(s)//2] not in \"69\") # does n...
{"fn_name": "solve", "inputs": [[0, 10], [10, 100], [100, 1000], [1000, 10000], [10000, 15000], [15000, 20000], [60000, 70000], [60000, 130000]], "outputs": [[3], [4], [12], [20], [6], [9], [15], [55]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,808
def solve(a, b):
7796c3036b86b0f900ba1035da491689
UNKNOWN
A rectangle can be split up into a grid of 1x1 squares, the amount of which being equal to the product of the two dimensions of the rectangle. Depending on the size of the rectangle, that grid of 1x1 squares can also be split up into larger squares, for example a 3x2 rectangle has a total of 8 squares, as there are 6 d...
["def findSquares(x,y):\n return sum( (x-i) * (y-i) for i in range(y) )", "def findSquares(x,y):\n if x > y:\n x, y = y, x\n return x*(x+1)*(2*x+1)/6 + (y-x)*x*(x+1)/2", "def findSquares(x,y):\n return sum((x-i)*(y-i) for i in range(min(x,y)))", "def findSquares(x,y):\n squares = 0\n while y >...
{"fn_name": "findSquares", "inputs": [[3, 2], [4, 3], [11, 4]], "outputs": [[8], [20], [100]]}
INTRODUCTORY
PYTHON3
CODEWARS
930
def findSquares(x,y):
de615074e0ca25eb9db7f2864fbd10f3
UNKNOWN
In English and programming, groups can be made using symbols such as `()` and `{}` that change meaning. However, these groups must be closed in the correct order to maintain correct syntax. Your job in this kata will be to make a program that checks a string for correct grouping. For instance, the following groups are...
["BRACES = { '(': ')', '[': ']', '{': '}' }\n\ndef group_check(s):\n stack = []\n for b in s:\n c = BRACES.get(b)\n if c:\n stack.append(c)\n elif not stack or stack.pop() != b:\n return False\n return not stack", "def group_check(s):\n while \"{}\" in s or \"()\" ...
{"fn_name": "group_check", "inputs": [["({})"], ["[[]()]"], ["[{()}]"], ["()"], ["([])"], ["{}([])"], ["{[{}[]()[]{}{}{}{}{}{}()()()()()()()()]{{{[[[((()))]]]}}}}(())[[]]{{}}[][][][][][][]({[]})"], [""], ["{(})"], ["[{}{}())"], ["{)[}"], ["[[[]])"], ["()[]{]"], ["{([]})"], ["([]"], ["[])"], ["([]))"], ["{{{{{{{{{{{((((...
INTRODUCTORY
PYTHON3
CODEWARS
2,212
def group_check(s):
17f9bca845b6c075bab54714b7cdda26
UNKNOWN
Write a function that checks if all the letters in the second string are present in the first one at least once, regardless of how many times they appear: ``` ["ab", "aaa"] => true ["trances", "nectar"] => true ["compadres", "DRAPES"] => true ["parses", "parsecs"] => false ``` Function should not be cas...
["def letter_check(arr): \n return set(arr[1].lower()) <= set(arr[0].lower())", "def letter_check(arr): \n a,b = (set(s.lower()) for s in arr)\n return b <= a", "def letter_check(arr): \n for i in arr[1]:\n if i.lower()not in arr[0].lower():\n return False\n return True", "def letter_ch...
{"fn_name": "letter_check", "inputs": [[["abcd", "aaa"]], [["trances", "nectar"]], [["THE EYES", "they see"]], [["assert", "staring"]], [["arches", "later"]], [["dale", "caller"]], [["parses", "parsecs"]], [["replays", "adam"]], [["mastering", "streaming"]], [["drapes", "compadres"]], [["deltas", "slated"]], [["deltas"...
INTRODUCTORY
PYTHON3
CODEWARS
1,051
def letter_check(arr):
e5aa8026a2795fe67cf46324a5c3c3e7
UNKNOWN
Every day we can send from the server a certain limit of e-mails. Task: Write a function that will return the integer number of e-mails sent in the percentage of the limit. Example: ``` limit - 1000; emails sent - 101; return - 10%; // becouse integer from 10,1 = 10 ``` Arguments: Integer, limit; Integer...
["def get_percentage(sent, limit = 1000):\n if not sent:\n return \"No e-mails sent\"\n elif sent >= limit:\n return \"Daily limit is reached\"\n return \"{}%\".format(int(sent * 100 / limit))", "def get_percentage(a, b=1000):\n return \"No e-mails sent\" if not a else \"Daily limit is reached...
{"fn_name": "get_percentage", "inputs": [[101, 1000], [256, 500], [259], [0], [1000, 1000]], "outputs": [["10%"], ["51%"], ["25%"], ["No e-mails sent"], ["Daily limit is reached"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,855
def get_percentage(sent, limit=1000):
0d6a0b9649c59ce155e4445bc973c418
UNKNOWN
Here's a way to construct a list containing every positive rational number: Build a binary tree where each node is a rational and the root is `1/1`, with the following rules for creating the nodes below: * The value of the left-hand node below `a/b` is `a/a+b` * The value of the right-hand node below `a/b` is `a+b/b` ...
["def rat_at(n):\n if n == 0:\n return 1, 1\n a, b = rat_at((n - 1) // 2)\n return (a, a + b) if n % 2 else (a + b, b)\n\ndef index_of(a, b):\n if a == b == 1:\n return 0\n return 2 * index_of(a, b - a) + 1 if b > a else 2 * index_of(a - b, b) + 2", "from math import ceil\ndef rat_at(n):\n ...
{"fn_name": "rat_at", "inputs": [[0], [3], [4], [10], [1000000000]], "outputs": [[[1, 1]], [[1, 3]], [[3, 2]], [[5, 2]], [[73411, 65788]]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,859
def rat_at(n):
45e0dd03769be540f450dc423a36122b
UNKNOWN
Andrzej was given a task: There are n jars with pills. In every jar there is a different type of pill and the amount of pills in each jar is infinite. One type of pill makes a person glow about 30 minutes after taking and none of the other types has any effect. His job is to determine, in which jar are the pills that m...
["def friends(n):\n return len(str(bin(n-1)))-3 if n >1 else 0", "def friends(n):\n return (n-1 or 1).bit_length()-1", "def friends(n):\n return 0 if n < 2 else (n - 1).bit_length() - 1", "from math import log2\n\ndef friends(n):\n return int(log2(max(2, n) - 1))", "from math import log2\n\ndef friends(n):\...
{"fn_name": "friends", "inputs": [[0], [1], [2], [4], [3], [16]], "outputs": [[0], [0], [0], [1], [1], [3]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,026
def friends(n):
994bbf8cbbd90688c16e349448f873ad
UNKNOWN
An array is called `centered-N` if some `consecutive sequence` of elements of the array sum to `N` and this sequence is preceded and followed by the same number of elements. Example: ``` [3,2,10,4,1,6,9] is centered-15 because the sequence 10,4,1 sums to 15 and the sequence is preceded by two elements [3,2] and foll...
["def is_centered(arr,n):\n l = int(len(arr)/2) if len(arr)%2==0 else int((len(arr)-1)/2)\n return any(sum(arr[i:-i])==n for i in range(1, l+1)) or sum(arr)==n", "from itertools import accumulate\n\ndef is_centered(arr, n):\n xs = [0] + list(accumulate(arr))\n return any(b-a==n for a, b in zip(xs[:len(arr)/...
{"fn_name": "is_centered", "inputs": [[[0, 0, 0], 0], [[3, 2, 10, 4, 1, 6, 9], 15], [[2, 10, 4, 1, 6, 9], 15], [[3, 2, 10, 4, 1, 6], 15], [[1, 1, 8, 3, 1, 1], 15], [[1, 1, 8, 3, 1, 1], 11], [[1, 1, 8, 3, 1, 1], 13], [[9, 0, 6], 0], [[], 25], [[25], 25], [[25, 26, 23, 24], 0], [[2, 1, 2], 0], [[1, 1, 15, -1, -1], 15], [...
INTRODUCTORY
PYTHON3
CODEWARS
1,974
def is_centered(arr,n):
51e6f232d528126061934c83780ae84e
UNKNOWN
Write a function named `first_non_repeating_letter` that takes a string input, and returns the first character that is not repeated anywhere in the string. For example, if given the input `'stress'`, the function should return `'t'`, since the letter *t* only occurs once in the string, and occurs first in the string. ...
["def first_non_repeating_letter(string):\n string_lower = string.lower()\n for i, letter in enumerate(string_lower):\n if string_lower.count(letter) == 1:\n return string[i]\n \n return \"\"", "from collections import Counter\ndef first_non_repeating_letter(string):\n cnt = Cou...
{"fn_name": "first_non_repeating_letter", "inputs": [["a"], ["stress"], ["moonmen"], [""], ["abba"], ["aa"], ["~><#~><"], ["hello world, eh?"], ["sTreSS"], ["Go hang a salami, I'm a lasagna hog!"]], "outputs": [["a"], ["t"], ["e"], [""], [""], [""], ["#"], ["w"], ["T"], [","]]}
INTRODUCTORY
PYTHON3
CODEWARS
8,486
def first_non_repeating_letter(string):
0afcdf231084d74c828e7c64d7a421d5
UNKNOWN
You'll be given a string, and have to return the total of all the unicode characters as an int. Should be able to handle any characters sent at it. examples: uniTotal("a") == 97 uniTotal("aaa") == 291
["def uni_total(string):\n return sum(map(ord, string))", "def uni_total(s):\n return sum(ord(c) for c in s)\n", "def uni_total(string):\n return sum(ord(c) for c in string)", "def uni_total(string):\n return sum(ord(x) for x in string)", "def uni_total(string):\n return sum([ord(i) for i in string])\n",...
{"fn_name": "uni_total", "inputs": [["a"], ["b"], ["c"], [""], ["aaa"], ["abc"], ["Mary Had A Little Lamb"], ["Mary had a little lamb"], ["CodeWars rocks"], ["And so does Strive"]], "outputs": [[97], [98], [99], [0], [291], [294], [1873], [2001], [1370], [1661]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,881
def uni_total(string):
2ac9d810229fb471186e6502ab42e214
UNKNOWN
Consider the following well known rules: - A number is divisible by 3 if the sum of its digits is divisible by 3. Let's call '3' a "1-sum" prime - For 37, we take numbers in groups of threes from the right and check if the sum of these groups is divisible by 37. Example: 37 * 123456787 = 4567901119 => 4 + 567 + 901...
["import math\n\ndef divisors(n):\n divs = [1]\n for i in range(2,int(math.sqrt(n))+1):\n if n%i == 0:\n divs.extend([i,n//i])\n divs.extend([n])\n return list(set(divs))\n\ndef solve(p):\n for d in sorted(divisors(p-1)):\n if pow(10, d, p) == 1:\n return \"{}-sum\".fo...
{"fn_name": "solve", "inputs": [[3], [7], [11], [13], [37], [47], [73], [239], [376049], [999883], [24701723], [45939401]], "outputs": [["1-sum"], ["3-altsum"], ["1-altsum"], ["3-altsum"], ["3-sum"], ["23-altsum"], ["4-altsum"], ["7-sum"], ["47006-altsum"], ["499941-sum"], ["12350861-sum"], ["11484850-altsum"]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,858
def solve(p):
bcfdc39829843fe6fc2cebfb233dd7a6
UNKNOWN
# Task A range-collapse representation of an array of integers looks like this: `"1,3-6,8"`, where `3-6` denotes the range from `3-6`, i.e. `[3,4,5,6]`. Hence `"1,3-6,8"` = `[1,3,4,5,6,8]`. Some other range-collapse representations of `[1,3,4,5,6,8]` include `"1,3-5,6,8", "1,3,4,5,6,8", etc`. Each range is writt...
["def descriptions(arr):\n return 2**sum(a+1==b for a,b in zip(arr,arr[1:]))", "\ndef pair_apply(a, fn): \n \"\"\"\n Apply a funtion to each pair of consecutive \n values in the array and return the resultant array\n \"\"\"\n return [fn(x, y) for x, y in zip(a, a[1:])]\n\ndef run_length_encode(a):\n ...
{"fn_name": "descriptions", "inputs": [[[1, 3, 4, 5, 6, 8]], [[1, 2, 3]], [[11, 43, 66, 123]], [[3, 4, 5, 8, 9, 10, 11, 23, 43, 66, 67]]], "outputs": [[8], [4], [1], [64]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,220
def descriptions(arr):
4a4fc2af1af6d746f8cb4cfc50dbfbb0
UNKNOWN
Implement a function which takes a string, and returns its hash value. Algorithm steps: * `a` := sum of the ascii values of the input characters * `b` := sum of every difference between the consecutive characters of the input (second char minus first char, third minus second, ...) * `c` := (`a` OR `b`) AND ((NOT `a`)...
["def string_hash(s):\n a = sum(ord(c) for c in s)\n b = sum(ord(b) - ord(a) for a, b in zip(s, s[1:]))\n c = (a | b) & (~a << 2)\n return c ^ (32 * (s.count(\" \") + 1))\n", "def string_hash(s):\n a, b = sum(ord(x) for x in s), sum(ord(y) - ord(x) for x, y in zip(s, s[1:]))\n return (a | b) & (~a << ...
{"fn_name": "string_hash", "inputs": [["int main(int argc, char *argv[]) { return 0; }"], [" Yo - What's Good?! "], [" df af asd "], ["global hash"], ["section .text"], ["hash:"], [" xor eax, eax"], [" ret"], ["; -----> end of hash <-----"], ["int hash(const char *str);"], [""], [" "], [" "], [" "], [" "]],...
INTRODUCTORY
PYTHON3
CODEWARS
1,971
def string_hash(s):
50f2cfb2fd2afa52708f6048d04d21ef
UNKNOWN
### Task: Your job is to take a pair of parametric equations, passed in as strings, and convert them into a single rectangular equation by eliminating the parameter. Both parametric halves will represent linear equations of x as a function of time and y as a function of time respectively. The format of the final equ...
["from fractions import gcd\nimport re\n\n\nINSERTER = re.compile(r'(?<!\\d)(?=[xyt])')\nFINDER = re.compile(r'-?\\d+')\n\n\ndef lcm(a,b): return a*b//gcd(a,b)\ndef simplify(s): return INSERTER.sub('1', s.replace(' ',''))\n\n\ndef para_to_rect(*equations):\n coefs = [ list(map(int, FINDER.findall(eq))) for eq i...
{"fn_name": "para_to_rect", "inputs": [["x = 12t + 18", "y = 8t + 7"], ["x = -12t + 18", "y = 8t + 7"], ["x = 12t + 18", "y = -8t + 7"], ["x = -12t + 18", "y = -8t + 7"], ["x = -t + 12", "y = 12t - 1"], ["x = -12t - 18", "y = 8t - 7"], ["x = -12t + 18", "y = 8t - 7"], ["x = -18t + 12", "y = 7t - 8"], ["x = 18t + 12", "...
INTRODUCTORY
PYTHON3
CODEWARS
7,599
def para_to_rect(eqn1, eqn2):
886328783975906976a9d6465360f4d4
UNKNOWN
Given an D-dimension array, where each axis is of length N, your goal is to find the sum of every index in the array starting from 0. For Example if D=1 and N=10 then the answer would be 45 ([0,1,2,3,4,5,6,7,8,9]) If D=2 and N = 3 the answer is 18 which would be the sum of every number in the following: ```python [ [(...
["def super_sum(D, N):\n #Number of possible combinations of D length from set [0...N]\n num = pow(N,D)\n #2x average value of a combination; 2x because dividing results in float and loss of precision\n dblAvg = D*(N-1)\n #Multiply number of possible combinations by the avergae value; now use true divisi...
{"fn_name": "super_sum", "inputs": [[2, 2], [2, 3], [3, 2], [3, 3], [1, 101], [10, 10], [10, 11], [11, 10], [11, 11], [15, 8], [19, 84], [17, 76]], "outputs": [[4], [18], [12], [81], [5050], [450000000000], [1296871230050], [4950000000000], [15692141883605], [1847179534663680], [2871495452512585452340652014195036913664...
INTRODUCTORY
PYTHON3
CODEWARS
1,143
def super_sum(D, N):
bd96629eb204e66bb1f85ddd42129d9a
UNKNOWN
**This Kata is intended as a small challenge for my students** All Star Code Challenge #16 Create a function called noRepeat() that takes a string argument and returns a single letter string of the **first** not repeated character in the entire string. ``` haskell noRepeat "aabbccdde" `shouldBe` 'e' noRepeat "wxyz" ...
["def no_repeat(s):\n return next(c for c in s if s.count(c) == 1)", "def no_repeat(string):\n return [x for x in string if string.count(x) == 1][0]", "from collections import Counter\n\n# Only work in 3.6+ because dicts are ordered\ndef no_repeat(string):\n return next(k for k,v in Counter(string).items() if ...
{"fn_name": "no_repeat", "inputs": [["aabbccdde"], ["wxyz"], ["testing"], ["codewars"], ["Testing"]], "outputs": [["e"], ["w"], ["e"], ["c"], ["T"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,049
def no_repeat(string):
8e9e7f0017df43c4725f64ef796fc7b8
UNKNOWN
Given a string, return the minimal number of parenthesis reversals needed to make balanced parenthesis. For example: ```Javascript solve(")(") = 2 Because we need to reverse ")" to "(" and "(" to ")". These are 2 reversals. solve("(((())") = 1 We need to reverse just one "(" parenthesis to make it balanced. solve("(...
["def solve(s):\n t = None\n while t != s:\n t, s = s, s.replace('()', '')\n return -1 if len(s) % 2 else sum(1 + (a == tuple(')(')) for a in zip(*[iter(s)] * 2))", "class Stack:\n def __init__(self):\n self.items = []\n\n def is_empty(self):\n return self.items == []\n\n def push...
{"fn_name": "solve", "inputs": [[")()("], ["((()"], ["((("], ["())((("], ["())()))))()()("]], "outputs": [[2], [1], [-1], [3], [4]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,792
def solve(s):
0f5b576cd619ca7cda54630e5a775565
UNKNOWN
[Langton's ant](https://en.wikipedia.org/wiki/Langton%27s_ant) is a two-dimensional Turing machine invented in the late 1980s. The ant starts out on a grid of black and white cells and follows a simple set of rules that has complex emergent behavior. ## Task Complete the function and return the `n`th iteration of Lan...
["BLACK = 0\nWHITE = 1\n# N, E, S, W\nCARDINALS = [(-1, 0), (0, 1), (1, 0), (0, -1)]\n\ndef ant(grid, column, row, n, direction=0):\n r, c, d = row, column, direction\n for _ in range(n):\n # Handle direction change and current cell colour flip\n if grid[r][c] == BLACK:\n grid[r][c] = WHI...
{"fn_name": "ant", "inputs": [[[[1]], 0, 0, 1, 0], [[[0]], 0, 0, 1, 0], [[[1]], 0, 0, 3, 0], [[[1]], 0, 0, 1]], "outputs": [[[[0, 0]]], [[[0, 1]]], [[[0, 1], [0, 1]]], [[[0, 0]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
10,551
def ant(grid, column, row, n, direction = 0):
9e33c3907fef8b365d2f1f6448b30912
UNKNOWN
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. Task: Write ``` smallest(n) ``` that will find the smallest positive number that is evenly divisible by all of the numbers from 1 to n (n <= 40). E.g ```python smallest(5) == 60 # 1 to 5 can all divide evenly int...
["def smallest(n):\n x, y, m = 1, 1, 1\n while m <= n:\n if x % m == 0:\n m += 1\n y = int(x)\n else:\n x += y\n return x\n", "from functools import reduce\nfrom math import gcd\nlcm = lambda x,y: x*y//gcd(x, y)\n\n# Note: there is a lcm function in numpy 1.17 but...
{"fn_name": "smallest", "inputs": [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20]], "outputs": [[1], [2], [6], [12], [60], [60], [420], [840], [2520], [2520], [27720], [27720], [360360], [360360], [360360], [720720], [12252240], [12252240], [232792560], [23...
INTRODUCTORY
PYTHON3
CODEWARS
1,352
def smallest(n):
88ca1d7ccf08c9c0e68ca3c30880eaa0
UNKNOWN
It's your Birthday. Your colleagues buy you a cake. The numbers of candles on the cake is provided (x). Please note this is not reality, and your age can be anywhere up to 1,000. Yes, you would look a mess. As a surprise, your colleagues have arranged for your friend to hide inside the cake and burst out. They pretend...
["cake=lambda c,d:['That was close!','Fire!'][c!=0and c*0.7<sum(ord(e)-96*(i%2!=0)for i,e in enumerate(d))]", "def cake(candles,debris):\n return 'Fire!' if candles and sum(ord(c) if i%2==0 else ord(c)-96 for i,c in enumerate(debris))>candles*0.7 else 'That was close!'", "def cake(candles,debris):\n s = sum(ord(c...
{"fn_name": "cake", "inputs": [[900, "abcdef"], [56, "ifkhchlhfd"], [256, "aaaaaddddr"], [333, "jfmgklfhglbe"], [12, "jaam"], [808, "alfbpmmpz"], [660, "zyxsqwh"], [651, "hmgoltyy"], [349, "nxls"], [958, "hovzfsxbmwu"], [301, "doda"], [383, "zwwl"], [871, "gnlyvknjga"], [583, "slhacx"], [0, "jpipe"]], "outputs": [["Tha...
INTRODUCTORY
PYTHON3
CODEWARS
2,740
def cake(candles,debris):
ed85d9ee073c3805e642f005727cb1e7
UNKNOWN
With a friend we used to play the following game on a chessboard (8, rows, 8 columns). On the first row at the *bottom* we put numbers: `1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9` On row 2 (2nd row from the bottom) we have: `1/3, 2/4, 3/5, 4/6, 5/7, 6/8, 7/9, 8/10` On row 3: `1/4, 2/5, 3/6, 4/7, 5/8, 6/9, 7/10, 8/11`...
["def game(n):\n return [n * n // 2] if n % 2 == 0 else [n * n, 2]", "'''\n n t(i) n-1 (n + i + 1) * (n - i)\ns(n) = \u03a3 ----- + \u03a3 ---------------------\n i=1 i + 1 i=1 2 * (n + i + 1)\n\n n i n-1 n - i\n = \u03a3 --- + \u03a3 -----\n ...
{"fn_name": "game", "inputs": [[0], [1], [8], [40], [101], [204], [807], [1808], [5014], [120000], [750000], [750001], [3000000], [3000001]], "outputs": [[[0]], [[1, 2]], [[32]], [[800]], [[10201, 2]], [[20808]], [[651249, 2]], [[1634432]], [[12570098]], [[7200000000]], [[281250000000]], [[562501500001, 2]], [[45000000...
INTRODUCTORY
PYTHON3
CODEWARS
1,413
def game(n):
2e757544cd536c3930cbab0fbe24c68f
UNKNOWN
Your task is to write an update for a lottery machine. Its current version produces a sequence of random letters and integers (passed as a string to the function). Your code must filter out all letters and return **unique** integers as a string, in their order of first appearance. If there are no integers in the string...
["def lottery(s):\n return \"\".join(dict.fromkeys(filter(str.isdigit, s))) or \"One more run!\"", "def lottery(s):\n \n result = ''\n \n for i in s:\n if i.isdigit() and i not in result:\n result += i\n \n return result or 'One more run!'", "def lottery(s):\n cifers = ''\n ...
{"fn_name": "lottery", "inputs": [["wQ8Hy0y5m5oshQPeRCkG"], ["ffaQtaRFKeGIIBIcSJtg"], ["555"], ["HappyNewYear2020"], ["20191224isXmas"], [""]], "outputs": [["805"], ["One more run!"], ["5"], ["20"], ["20194"], ["One more run!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,663
def lottery(s):
dd467547d2ebe5f3e0f01a0431e0b039
UNKNOWN
# Task Changu and Mangu are great buddies. Once they found an infinite paper which had 1,2,3,4,5,6,7,8,......... till infinity, written on it. Both of them did not like the sequence and started deleting some numbers in the following way. ``` First they deleted every 2nd number. So remaining numbers on the paper: 1,...
["def survivor(n):\n k = 2\n while n >= k and n % k:\n n -= n // k\n k += 1\n return n % k > 0", "def survivor(n):\n i=2\n while i<=n:\n if n%i==0:return False\n n-=n//i\n i+=1\n return True", "from itertools import count\n\ndef survivor(n):\n for i in count(2):\n...
{"fn_name": "survivor", "inputs": [[1], [5], [8], [9], [13], [15], [134], [289]], "outputs": [[true], [false], [false], [false], [true], [false], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,671
def survivor(n):
dcd9d7739c03ce75458033833f148a86
UNKNOWN
The goal of this Kata is to return the greatest distance of index positions between matching number values in an array or 0 if there are no matching values. Example: In an array with the values [0, 2, 1, 2, 4, 1] the greatest index distance is between the matching '1' values at index 2 and 5. Executing greatestDist...
["def greatest_distance(arr):\n return max(i - arr.index(x) for i,x in enumerate(arr))", "def greatest_distance(arr):\n indexes, d = {}, 0\n for i,n in enumerate(arr):\n if n in indexes: d = max(d, i-indexes[n])\n else: indexes[n] = i\n return d", "def greatest_distance(lst):\n r...
{"fn_name": "greatest_distance", "inputs": [[[9, 7, 1, 2, 3, 7, 0, -1, -2]], [[0, 7, 0, 2, 3, 7, 0, -1, -2]], [[1, 2, 3, 4]]], "outputs": [[4], [6], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,828
def greatest_distance(arr):
46af70b3fd9ffb8ee3ff071a7f013546
UNKNOWN
As most of you might know already, a prime number is an integer `n` with the following properties: * it must be greater than 1 * it must be divisible only by itself and 1 And that's it: -15 or 8 are not primes, 5 or 97 are; pretty easy, isn't it? Well, turns out that primes are not just a mere mathematical curiosity...
["primes = [2, 3, 5, 7]\n\ndef is_prime(n):\n if n < 2:\n return False\n m = int(n ** .5) + 1\n for p in primes:\n if p >= m: break\n if not n % p:\n return False\n q, d = primes[-1], 4 if (n + 1) % 6 else 2\n while q < m:\n q, d = q + d, 4 - d\n if is_prime(...
{"fn_name": "is_prime", "inputs": [[1], [2], [5], [143], [-1], [29], [53], [529]], "outputs": [[false], [true], [true], [false], [false], [true], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,856
def is_prime(n):
3230f6a9b96e897b3f9c3066de56848d
UNKNOWN
# Task Given a number `n`, return a string representing it as a sum of distinct powers of three, or return `"Impossible"` if that's not possible to achieve. # Input/Output `[input]` integer `n` A positive integer n. `1 ≤ n ≤ 10^16`. `[output]` a string A string representing the sum of powers of three which ad...
["import numpy as np\n\ndef sum_of_threes(n):\n s=np.base_repr(n,3)\n if '2' in s: return 'Impossible'\n return '+'.join(['3^{}'.format(i) for i,d in enumerate(s[::-1]) if d=='1'][::-1])\n", "def sum_of_threes(n):\n k, p = 0, []\n while n >= 3 ** k:\n k += 1\n while k >= 0:\n k -= 1\n ...
{"fn_name": "sum_of_threes", "inputs": [[4], [2], [28], [84], [1418194818], [87754], [531441], [8312964441463288], [5559060566575209], [243]], "outputs": [["3^1+3^0"], ["Impossible"], ["3^3+3^0"], ["3^4+3^1"], ["Impossible"], ["3^10+3^9+3^8+3^7+3^5+3^3+3^1+3^0"], ["3^12"], ["Impossible"], ["3^33+3^9+3^1"], ["3^5"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,451
def sum_of_threes(n):
e5521b7a589bd259dd9e9a47cb0917bd
UNKNOWN
Background ---------- In another dimension, there exist two immortal brothers: Solomon and Goromon. As sworn loyal subjects to the time elemental, Chronixus, both Solomon and Goromon were granted the power to create temporal folds. By sliding through these temporal folds, one can gain entry to parallel dimensions where...
["def solomons_quest(arr):\n pos, lvl = [0,0], 0\n for dilat,dir,dist in arr:\n lvl += dilat\n pos[dir in [0,2]] += dist * 2**lvl * (-1)**( dir in [2,3] )\n return pos", "def solomons_quest(arr):\n level = 0\n ds = [1j, 1, -1j, -1]\n pos = 0\n for level_shift, direction, distance in a...
{"fn_name": "solomons_quest", "inputs": [[[[1, 3, 5], [2, 0, 10], [-3, 1, 4], [4, 2, 4], [1, 1, 5], [-3, 0, 12], [2, 1, 12], [-2, 2, 6]]], [[[4, 0, 8], [2, 1, 2], [1, 0, 5], [-3, 3, 16], [2, 2, 2], [-1, 1, 7], [0, 0, 5], [-4, 3, 14]]], [[[1, 1, 20], [1, 2, 30], [1, 3, 8], [1, 0, 2], [1, 1, 6], [1, 2, 4], [1, 3, 6], [-7...
INTRODUCTORY
PYTHON3
CODEWARS
4,446
def solomons_quest(arr):
9ab6f6db645151fd04c5434ad65e6a1d
UNKNOWN
Spin-off of this kata, here you will have to figure out an efficient strategy to solve the problem of finding the sole duplicate number among an unsorted array/list of numbers starting from 1 up to n. Hints: a solution in linear time can be found; using the most intuitive ones to search for duplicates that can run in ...
["def find_dup(arr):\n return sum(arr) - sum(range(1, max(arr)+1))", "def find_dup(arr):\n seen = set()\n for a in arr:\n if a in seen:\n return a\n seen.add(a)\n", "find_dup=lambda arr: sum(arr)-len(arr)*(len(arr)-1)/2", "from collections import Counter\n\n\ndef find_dup(lst):\n re...
{"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
892
def find_dup(arr):
66ebbf9c9554110039ff80c3084f9ed6
UNKNOWN
You will be given two ASCII strings, `a` and `b`. Your task is write a function to determine which one of these strings is "worth" more, and return it. A string's worth is determined by the sum of its ASCII codepoint indexes. So, for example, the string `HELLO` has a value of 372: H is codepoint 72, E 69, L 76, and O ...
["def highest_value(a, b):\n return max(a, b, key=lambda s: sum(map(ord, s)))", "def highest_value(a, b):\n return a if sum(map(ord, a)) >= sum(map(ord, b)) else b", "def highest_value(a, b):\n return b if sum(ord(x) for x in b) > sum(ord(x) for x in a) else a", "def worth(s):\n return sum(map(ord, s))\n ...
{"fn_name": "highest_value", "inputs": [["AaBbCcXxYyZz0189", "KkLlMmNnOoPp4567"], ["ABcd", "0123"], ["!\"?$%^&*()", "{}[]@~'#:;"], ["ABCD", "DCBA"]], "outputs": [["KkLlMmNnOoPp4567"], ["ABcd"], ["{}[]@~'#:;"], ["ABCD"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,075
def highest_value(a, b):
61d7f8ecf1d6e0929f0d06e36de8ee49
UNKNOWN
Create a function `isAlt()` that accepts a string as an argument and validates whether the vowels (a, e, i, o, u) and consonants are in alternate order. ```python is_alt("amazon") // true is_alt("apple") // false is_alt("banana") // true ``` Arguments consist of only lowercase letters.
["import re\n\ndef is_alt(s):\n return not re.search('[aeiou]{2}|[^aeiou]{2}',s)", "def is_alt(s):\n vowels = list(\"aeiou\")\n v = s[0] in vowels\n \n for i in s:\n if (i in vowels) != v:\n return False\n v = not(v)\n return True", "def is_alt(s):\n a = s[::2]\n b = s[1...
{"fn_name": "is_alt", "inputs": [["amazon"], ["apple"], ["banana"], ["orange"], ["helipad"], ["yay"]], "outputs": [[true], [false], [true], [false], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,247
def is_alt(s):
68995ae5e7a4ce3c0088c0941b623637
UNKNOWN
Write a function, `persistence`, that takes in a positive parameter `num` and returns its multiplicative persistence, which is the number of times you must multiply the digits in `num` until you reach a single digit. For example: ```python persistence(39) => 3 # Because 3*9 = 27, 2*7 = 14, 1*4=4 ...
["def persistence(n):\n n = str(n)\n count = 0\n while len(n) > 1:\n p = 1\n for i in n:\n p *= int(i)\n n = str(p)\n count += 1\n return count\n # your code\n", "def persistence(n):\n if n < 10: return 0\n mult = 1\n while(n > 0):\n mult = n%10 * mu...
{"fn_name": "persistence", "inputs": [[39], [4], [25], [999], [444]], "outputs": [[3], [0], [2], [4], [3]]}
INTRODUCTORY
PYTHON3
CODEWARS
908
def persistence(n):
cf998549e50e2acdc7bd2e83ed0f9c9a
UNKNOWN
# Task Given an array `arr` and a number `n`. Call a pair of numbers from the array a `Perfect Pair` if their sum is equal to `n`. Find all of the perfect pairs and return the sum of their **indices**. Note that any element of the array can only be counted in one Perfect Pair. Also if there are multiple correct ...
["def pairwise(arr, n):\n s=[]\n for i in range(len(arr)-1):\n for j in range(i+1,len(arr)):\n if j in s or i in s: continue\n if arr[i]+arr[j] ==n:\n s.append(i)\n s.append(j)\n return sum(s)", "def pairwise(arr, n):\n\n iMap, s = {}, 0\n for i,...
{"fn_name": "pairwise", "inputs": [[[1, 4, 2, 3, 0, 5], 7], [[1, 3, 2, 4], 4], [[1, 1, 1], 2], [[0, 0, 0, 0, 1, 1], 1], [[15, 1, 1], 5]], "outputs": [[11], [1], [1], [10], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,390
def pairwise(arr, n):
1dcc63c047247f8dddb775fe75605b2c
UNKNOWN
The number ```1331``` is the first positive perfect cube, higher than ```1```, having all its digits odd (its cubic root is ```11```). The next one is ```3375```. In the interval [-5000, 5000] there are six pure odd digit perfect cubic numbers and are: ```[-3375,-1331, -1, 1, 1331, 3375]``` Give the numbers of this...
["from bisect import bisect_left, bisect\n\nss = set('13579')\nns = [i ** 3 for i in range(1, int((10 ** 17) ** (1/3)) + 3, 2) if set(str(i ** 3)) <= ss]\nns = [-n for n in ns[::-1]] + ns\n\ndef odd_dig_cubic(a, b):\n return ns[bisect_left(ns, a):bisect(ns, b)]", "import math\n\ndef odd_dig_cubic(a, b):\n ret = []\...
{"fn_name": "odd_dig_cubic", "inputs": [[-5000, 5000], [0, 5000], [-1, 5000], [-5000, -2]], "outputs": [[[-3375, -1331, -1, 1, 1331, 3375]], [[1, 1331, 3375]], [[-1, 1, 1331, 3375]], [[-3375, -1331]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,479
def odd_dig_cubic(a, b):
4b56b56fdf597f4d87f801a5550181de
UNKNOWN
You're fed up about changing the version of your software manually. Instead, you will create a little script that will make it for you. # Exercice Create a function `nextVersion`, that will take a string in parameter, and will return a string containing the next version number. For example: # Rules All numbers, ex...
["def next_version(version):\n ns = version.split('.')\n i = len(ns) - 1\n while i > 0 and ns[i] == '9':\n ns[i] = '0'\n i -= 1\n ns[i] = str(int(ns[i]) + 1)\n return '.'.join(ns)", "def next_version(version):\n tab = list(map(int, version.split('.')))\n for x in range(1, len(tab)+1):...
{"fn_name": "next_version", "inputs": [["1.2.3"], ["0.9.9"], ["1"], ["1.2.3.4.5.6.7.8"], ["9.9"]], "outputs": [["1.2.4"], ["1.0.0"], ["2"], ["1.2.3.4.5.6.7.9"], ["10.0"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,528
def next_version(version):
8695fc23491487c7f1c1f076c347e4f7
UNKNOWN
Remember the game 2048? The main part of this game is merging identical tiles in a row. * Implement a function that models the process of merging all of the tile values in a single row. * This function takes the array line as a parameter and returns a new array with the tile values from line slid towards the front...
["from itertools import groupby\n\ndef merge(line):\n merged = []\n for k,g in groupby( v for v in line if v ):\n g = list(g)\n n,r = divmod(len(g),2)\n if n: merged.extend([k*2]*n)\n if r: merged.append(k)\n return merged + [0]*(len(line)-len(merged))", "def merge(line):\n line ...
{"fn_name": "merge", "inputs": [[[2, 0, 2, 2]], [[2, 0, 2, 4]], [[0, 0, 2, 2]], [[2, 2, 0, 0]], [[2, 2, 2, 2, 2]], [[8, 16, 16, 8]]], "outputs": [[[4, 2, 0, 0]], [[4, 4, 0, 0]], [[4, 0, 0, 0]], [[4, 0, 0, 0]], [[4, 4, 2, 0, 0]], [[8, 32, 8, 0]]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,068
def merge(line):
94762ce3157679d1f5adcc9078cf8ac0
UNKNOWN
# Summation Of Primes The sum of the primes below or equal to 10 is **2 + 3 + 5 + 7 = 17**. Find the sum of all the primes **_below or equal to the number passed in_**. From Project Euler's [Problem #10](https://projecteuler.net/problem=10 "Project Euler - Problem 10").
["from bisect import bisect\n\ndef sieve(n):\n sieve, primes = [0]*(n+1), []\n for i in range(2, n+1):\n if not sieve[i]:\n primes.append(i) \n for j in range(i**2, n+1, i): sieve[j] = 1\n return primes\n\nPRIMES = sieve(1000000)\n\ndef summationOfPrimes(n):\n return sum(PRIMES[...
{"fn_name": "summationOfPrimes", "inputs": [[5], [6], [7], [8], [9], [10], [20], [30], [40], [50], [100], [200], [300], [400], [500], [1000], [2000], [3000], [4000], [5000], [25000]], "outputs": [[10], [10], [17], [17], [17], [17], [77], [129], [197], [328], [1060], [4227], [8275], [13887], [21536], [76127], [277050], ...
INTRODUCTORY
PYTHON3
CODEWARS
2,385
def summationOfPrimes(primes):