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
49ec61bde76bb3007d125da3a90119cc
UNKNOWN
You work in the best consumer electronics corporation, and your boss wants to find out which three products generate the most revenue. Given 3 lists of the same length like these: * products: `["Computer", "Cell Phones", "Vacuum Cleaner"]` * amounts: `[3, 24, 8]` * prices: `[199, 299, 399]` return the three product ...
["def top3(*args):\n return [item[0] for item in sorted(zip(*args), key=lambda x: x[1]*x[2], reverse=True)[:3]]", "import heapq\n\ndef top3(products, amounts, prices):\n items = zip(products, amounts, prices)\n return [product for product, _, _ in heapq.nlargest(3, items, key=lambda item: item[1] * item[2])]",...
{"fn_name": "top3", "inputs": [[["Computer", "Cell Phones", "Vacuum Cleaner"], [3, 24, 8], [199, 299, 399]], [["Cell Phones", "Vacuum Cleaner", "Computer", "Autos", "Gold", "Fishing Rods", "Lego", " Speakers"], [5, 25, 2, 7, 10, 3, 2, 24], [51, 225, 22, 47, 510, 83, 82, 124]], [["Cell Phones", "Vacuum Cleaner", "Comput...
INTRODUCTORY
PYTHON3
CODEWARS
2,708
def top3(products, amounts, prices):
b62192cc26894fe4545b345a24ea1fba
UNKNOWN
### What is simplifying a square root? If you have a number, like 80, for example, you would start by finding the greatest perfect square divisible by 80. In this case, that's 16. Find the square root of 16, and multiply it by 80 / 16. Answer = 4 √5. ##### The above example: ![simplify_roots_example.png](https://i....
["def simplify(n):\n for d in range(int(n ** .5), 0, -1):\n if not n % d ** 2: break\n if d*d == n: return '%d' % d\n elif d == 1: return 'sqrt %d' % n\n else: return '%d sqrt %d' % (d, n // d ** 2)\n\ndef desimplify(s):\n x, _, y = s.partition('sqrt')\n return int(x or '1') ** 2 * int(y or '1'...
{"fn_name": "simplify", "inputs": [[1], [2], [3], [8], [15], [16], [18], [20], [24], [32], [4], [7], [9], [10], [12], [13], [14], [50], [80], [200]], "outputs": [["1"], ["sqrt 2"], ["sqrt 3"], ["2 sqrt 2"], ["sqrt 15"], ["4"], ["3 sqrt 2"], ["2 sqrt 5"], ["2 sqrt 6"], ["4 sqrt 2"], ["2"], ["sqrt 7"], ["3"], ["sqrt 10"]...
INTRODUCTORY
PYTHON3
CODEWARS
4,411
def simplify(n):
75b02dd6b6b68b325fa9f1d7d496b50a
UNKNOWN
Complete the function that returns an array of length `n`, starting with the given number `x` and the squares of the previous number. If `n` is negative or zero, return an empty array/list. ## Examples ``` 2, 5 --> [2, 4, 16, 256, 65536] 3, 3 --> [3, 9, 81] ```
["def squares(x,n):\n return [x**(2**i) for i in range(n)]", "from itertools import accumulate, repeat\ndef squares(x, n):\n return list(accumulate(repeat(x, n), lambda a, _: a * a))", "def squares(x, n):\n result = [x] if n > 0 else []\n for i in range(0, n-1):\n result.append(result[-1]**2)\n re...
{"fn_name": "squares", "inputs": [[2, 5], [3, 3], [5, 3], [10, 4], [2, 0], [2, -4]], "outputs": [[[2, 4, 16, 256, 65536]], [[3, 9, 81]], [[5, 25, 625]], [[10, 100, 10000, 100000000]], [[]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,261
def squares(x, n):
ebf166c1ab3b52fb3a6ae39af851abfc
UNKNOWN
You get a "text" and have to shift the vowels by "n" positions to the right. (Negative value for n should shift to the left.) "Position" means the vowel's position if taken as one item in a list of all vowels within the string. A shift by 1 would mean, that every vowel shifts to the place of the next vowel. Shifting ov...
["import re\nfrom collections import deque\n\ndef vowel_shift(text,n):\n try:\n tokens = re.split(r'([aeiouAEIOU])', text)\n if len(tokens) > 1:\n vowels = deque(tokens[1::2])\n vowels.rotate(n)\n tokens[1::2] = vowels\n return ''.join(tokens)\n except TypeErr...
{"fn_name": "vowel_shift", "inputs": [[null, 0], ["", 0], ["This is a test!", 0], ["This is a test!", 1], ["This is a test!", 3], ["This is a test!", 4], ["This is a test!", -1], ["This is a test!", -5], ["Brrrr", 99], ["AEIOUaeiou", 1]], "outputs": [[null], [""], ["This is a test!"], ["Thes is i tast!"], ["This as e t...
INTRODUCTORY
PYTHON3
CODEWARS
3,348
def vowel_shift(text, n):
a58e87abe3fb4be80dfeb5c552942e07
UNKNOWN
An Arithmetic Progression is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an Arithmetic Progression. There is however one hitch: exactly one term from the original series is missing from the set of number...
["def find_missing(sequence):\n t = sequence\n return (t[0] + t[-1]) * (len(t) + 1) / 2 - sum(t)\n", "def find_missing(sequence):\n interval = (sequence[-1] - sequence[0])/len(sequence)\n for previous, item in enumerate(sequence[1:]):\n if item - sequence[previous] != interval:\n return it...
{"fn_name": "find_missing", "inputs": [[[1, 2, 3, 4, 6, 7, 8, 9]]], "outputs": [[5]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,035
def find_missing(sequence):
157ce11f56fab0ca550873dd8111f7c6
UNKNOWN
Complete the function ```caffeineBuzz```, which takes a non-zero integer as it's one argument. If the integer is divisible by 3, return the string ```"Java"```. If the integer is divisible by 3 and divisible by 4, return the string ```"Coffee"``` If the integer is one of the above and is even, add ```"Script"``` to ...
["def caffeineBuzz(n):\n if n%12 == 0:\n return \"CoffeeScript\"\n elif n%6 == 0:\n return \"JavaScript\"\n elif n%3 == 0:\n return \"Java\"\n else:\n return \"mocha_missing!\"", "def caffeineBuzz(n):\n result = \"mocha_missing!\"\n if not n % 3:\n if not n % 4:\n ...
{"fn_name": "caffeineBuzz", "inputs": [[1], [3], [6], [12]], "outputs": [["mocha_missing!"], ["Java"], ["JavaScript"], ["CoffeeScript"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,884
def caffeineBuzz(n):
50e47495cf4b57a4ab41dc2bea28fc1f
UNKNOWN
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: 2332 110011 54322345 For a given number ```num```, return its closest numerical palindrome which can either be smaller or larger than ```num```. If there are 2 poss...
["def palindrome(num):\n if type(num) is not int or num < 0:\n return \"Not valid\"\n else:\n c =0\n for i in range(num,num**2):\n if is_pal(i):\n return i\n elif is_pal(i-c):\n return i-c\n else:\n c +=2\n \ndef...
{"fn_name": "palindrome", "inputs": [[8], [281], [1029], [1221], ["BGHHGB"], ["11029"], [-1029]], "outputs": [[11], [282], [1001], [1221], ["Not valid"], ["Not valid"], ["Not valid"]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,871
def palindrome(num):
357d026e34fb016b29f97f419eb592fb
UNKNOWN
Ahoy Matey! Welcome to the seven seas. You are the captain of a pirate ship. You are in battle against the royal navy. You have cannons at the ready.... or are they? Your task is to check if the gunners are loaded and ready, if they are: ```Fire!``` If they aren't ready: ```Shiver me timbers!``` Your gunners for...
["def cannons_ready(gunners):\n return 'Shiver me timbers!' if 'nay' in gunners.values() else 'Fire!'", "def cannons_ready(gunners):\n for i in gunners:\n if gunners[i] == 'nay':\n return 'Shiver me timbers!'\n return 'Fire!'", "def cannons_ready(g):\n return ['Fire!','Shiver me timbers!']['na...
{"fn_name": "cannons_ready", "inputs": [[{"Joe": "nay", "Johnson": "nay", "Peter": "aye"}]], "outputs": [["Shiver me timbers!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
16,483
def cannons_ready(gunners):
9edf56af33b2872ef53f160649125f98
UNKNOWN
# Task Dudka has `n` details. He must keep exactly 3 of them. To do this, he performs the following operations until he has only 3 details left: ``` He numbers them. He keeps those with either odd or even numbers and throws the others away.``` Dudka wants to know how many ways there are to get exactly 3 details. Y...
["from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef three_details(n):\n if n <= 3: return n==3\n q, r = divmod(n, 2)\n return three_details(q) + three_details(q+r)", "from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef three_details(n):\n if n in (3,5,7):\n return 1\n e...
{"fn_name": "three_details", "inputs": [[3], [6], [4], [10], [15]], "outputs": [[1], [2], [0], [2], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,798
def three_details(n):
5c7734e055ca93742c3307464ffe52c2
UNKNOWN
Write a function that takes a positive integer n, sums all the cubed values from 1 to n, and returns that sum. Assume that the input n will always be a positive integer. Examples: ```python sum_cubes(2) > 9 # sum of the cubes of 1 and 2 is 1 + 8 ```
["def sum_cubes(n):\n return sum(i**3 for i in range(0,n+1))", "def sum_cubes(n):\n return (n*(n+1)/2)**2", "def sum_cubes(n):\n return sum(x ** 3 for x in range(n+1))", "def sum_cubes(n):\n return (n*(n+1)//2)**2", "def sum_cubes(n):\n return sum([i**3 for i in range(1,n+1)])", "def sum_cubes(n):\n r...
{"fn_name": "sum_cubes", "inputs": [[1], [2], [3], [4], [10], [123]], "outputs": [[1], [9], [36], [100], [3025], [58155876]]}
INTRODUCTORY
PYTHON3
CODEWARS
10,405
def sum_cubes(n):
72a6723d1401eab2a4e4fa4679dc2715
UNKNOWN
## Task Generate a sorted list of all possible IP addresses in a network. For a subnet that is not a valid IPv4 network return `None`. ## Examples ``` ipsubnet2list("192.168.1.0/31") == ["192.168.1.0", "192.168.1.1"] ipsubnet2list("213.256.46.160/28") == None ```
["import ipaddress as ip\n\ndef ipsubnet2list(subnet):\n try: return list(map(str,ip.ip_network(subnet).hosts()))\n except: pass", "def ip_to_int(ip):\n return sum(int(i[0]) << i[1]*8 for i in zip(ip.split('.'), range(3,-1,-1)))\ndef int_to_ip(num):\n return '.'.join(str(num >> i*8 & 0xff) for i in range(3,...
{"fn_name": "ipsubnet2list", "inputs": [["192.168.1.0/31"], ["195.20.15.0/28"], ["174.0.153.152/29"], ["213.192.46.160/28"], ["213.256.46.160/28"]], "outputs": [[["192.168.1.0", "192.168.1.1"]], [["195.20.15.1", "195.20.15.2", "195.20.15.3", "195.20.15.4", "195.20.15.5", "195.20.15.6", "195.20.15.7", "195.20.15.8", "19...
INTRODUCTORY
PYTHON3
CODEWARS
4,487
def ipsubnet2list(subnet):
bba23b2fcbd897fe2d27110630baf867
UNKNOWN
# Largest Rectangle in Background Imagine a photo taken to be used in an advertisement. The background on the left of the motive is whitish and you want to write some text on that background. So you scan the photo with a high resolution scanner and, for each line, count the number of pixels from the left that are suff...
["def largest_rect(h):\n st=[]; m=0; i=0\n while i<len(h):\n if len(st)==0 or h[st[-1]]<=h[i]: st.append(i); i+=1\n else: l=st.pop(); m=max(m, h[l]*(i if len(st)==0 else i-st[-1]-1))\n while len(st)>0: l=st.pop(); m=max(m, h[l]*(i if len(st)==0 else i-st[-1]-1))\n return m", "def largest_rect(...
{"fn_name": "largest_rect", "inputs": [[[3, 5, 12, 4, 10]], [[6, 2, 5, 4, 5, 1, 6]], [[9, 7, 5, 4, 2, 5, 6, 7, 7, 5, 7, 6, 4, 4, 3, 2]], [[]], [[0]], [[0, 0, 0]], [[1, 1, 1]], [[1, 2, 3]], [[3, 2, 1]], [[100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 1...
INTRODUCTORY
PYTHON3
CODEWARS
4,460
def largest_rect(histogram):
f7d7d5c326885db8ad91c2e77bdf800a
UNKNOWN
You have a two-dimensional list in the following format: ```python data = [[2, 5], [3, 4], [8, 7]] ``` Each sub-list contains two items, and each item in the sub-lists is an integer. Write a function `process_data()` that processes each sub-list like so: * `[2, 5]` --> `2 - 5` --> `-3` * `[3, 4]` --> `3 - 4` --> ...
["def process_data(data):\n r = 1\n for d in data:\n r *= d[0] - d[1]\n return r", "from functools import reduce\nfrom itertools import starmap\nfrom operator import mul, sub\n\ndef process_data(data):\n return reduce(mul, starmap(sub, data))", "def process_data(data):\n product = 1\n \n for...
{"fn_name": "process_data", "inputs": [[[[2, 5], [3, 4], [8, 7]]], [[[2, 9], [2, 4], [7, 5]]], [[[5, 4], [6, 4]]], [[[2, 1], [5, 3], [7, 4], [10, 6]]]], "outputs": [[3], [28], [2], [24]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,357
def process_data(data):
f2c9383f253f2ef59aa2886a77415347
UNKNOWN
You are going to be given a word. Your job will be to make sure that each character in that word has the exact same number of occurrences. You will return `true` if it is valid, or `false` if it is not. For example: `"abcabc"` is a valid word because `'a'` appears twice, `'b'` appears twice, and`'c'` appears twice. ...
["from collections import Counter\n\ndef validate_word(word):\n return len(set(Counter(word.lower()).values())) == 1", "from collections import Counter\n\n\ndef validate_word(word):\n return 1 == len(set(Counter(word.upper()).values()))\n", "def validate_word(word):\n word = word.lower()\n return len(set(wo...
{"fn_name": "validate_word", "inputs": [["abcabc"], ["Abcabc"], ["AbcabcC"], ["AbcCBa"], ["pippi"], ["?!?!?!"], ["abc123"], ["abcabcd"], ["abc!abc!"], ["abc:abc"]], "outputs": [[true], [true], [false], [true], [false], [true], [true], [false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,241
def validate_word(word):
6c2be97d192b815a550c68d66d08b87f
UNKNOWN
Write a function that takes one or more arrays and returns a new array of unique values in the order of the original provided arrays. In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array. The unique numbers should be sorted by their o...
["def unite_unique(*arg):\n res = []\n for arr in arg:\n for val in arr:\n if not val in res: res.append(val)\n return res", "from itertools import chain\n\ndef unite_unique(*args):\n return list(dict.fromkeys(chain.from_iterable(args)))", "from itertools import chain\n\ndef unite_unique(*...
{"fn_name": "unite_unique", "inputs": [[[1, 2], [3, 4]], [[1, 3, 2], [5, 2, 1, 4], [2, 1]], [[4, 3, 2, 2]], [[4, "a", 2], []], [[], [4, "a", 2]], [[], [4, "a", 2], []], [[]], [[], []], [[], [1, 2]], [[], [1, 2, 1, 2], [2, 1, 1, 2, 1]]], "outputs": [[[1, 2, 3, 4]], [[1, 3, 2, 5, 4]], [[4, 3, 2]], [[4, "a", 2]], [[4, "a"...
INTRODUCTORY
PYTHON3
CODEWARS
2,765
def unite_unique(*args):
421d0612de0b676f96f2837ad78c6dc1
UNKNOWN
Brief ===== Sometimes we need information about the list/arrays we're dealing with. You'll have to write such a function in this kata. Your function must provide the following informations: * Length of the array * Number of integer items in the array * Number of float items in the array * Number of string character ...
["def array_info(x):\n if not x:\n return 'Nothing in the array!'\n return [\n [len(x)],\n [sum(isinstance(i, int) for i in x) or None],\n [sum(isinstance(i, float) for i in x) or None],\n [sum(isinstance(i, str) and not i.isspace() for i in x) or None],\n [sum(isinstance...
{"fn_name": "array_info", "inputs": [[[1, 2, 3.33, 4, 5.01, "bass", "kick", " "]], [[0.001, 2, " "]], [[]], [[" "]], [[" ", " "]], [["jazz"]], [[4]], [[3.1416]], [[11, 22, 33.33, 44.44, "hasan", "ahmad"]], [["a", "b", "c", "d", " "]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[1, 2.23, "string", " "]]], "outputs": [[[[8], [3], [...
INTRODUCTORY
PYTHON3
CODEWARS
3,769
def array_info(x):
d1c12e3721093720b18e826531a2a41e
UNKNOWN
In this kata you will have to modify a sentence so it meets the following rules: convert every word backwards that is: longer than 6 characters OR has 2 or more 'T' or 't' in it convert every word uppercase that is: exactly 2 characters long OR before a comma convert every word to a "0" tha...
["import re\n\ndef spiner(s,p):\n return ( s[::-1] if len(s) > 6 or s.lower().count('t') > 1\n else s.upper() if len(s) == 2 or p == ','\n else '0' if len(s) == 1\n else s) + p\n\ndef spin_solve(sentence):\n return re.sub(r\"((?:\\w|['-])+)(\\W)?\", lambda m: spiner(m.group(1), m.grou...
{"fn_name": "spin_solve", "inputs": [["Welcome."], ["If a man does not keep pace with his companions, perhaps it is because he hears a different drummer."], ["As Grainier drove along in the wagon behind a wide, slow, sand-colored mare, clusters of orange butterflies exploded off the purple blackish piles of bear sign a...
INTRODUCTORY
PYTHON3
CODEWARS
4,117
def spin_solve(sentence):
d9629cb2b74a6c6a3c4a68ef9a8050f6
UNKNOWN
# Task Let's consider a table consisting of `n` rows and `n` columns. The cell located at the intersection of the i-th row and the j-th column contains number i × j. The rows and columns are numbered starting from 1. You are given a positive integer `x`. Your task is to count the number of cells in a table that cont...
["def count_number(n, x):\n return len([j for j in range(1,n+1) if x%j==0 and x/j <= n]) ", "from math import ceil\n\ndef count_number(n, x):\n return sum(x % i == 0 for i in range(max(int(ceil(x / n)), 1), min(n,x) + 1))", "def count_number(n, x):\n #your code here\n return sum(1 for i in range(1,n+1) if x...
{"fn_name": "count_number", "inputs": [[5, 5], [10, 5], [6, 12], [6, 169], [100000, 1000000000]], "outputs": [[2], [2], [4], [0], [16]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,121
def count_number(n, x):
408344d25dc1ebc96688483dafae14cb
UNKNOWN
If the first day of the month is a Friday, it is likely that the month will have an `Extended Weekend`. That is, it could have five Fridays, five Saturdays and five Sundays. In this Kata, you will be given a start year and an end year. Your task will be to find months that have extended weekends and return: ``` - The...
["from calendar import month_abbr\nfrom datetime import datetime \ndef solve(a,b):\n res = [month_abbr[month]\n for year in range(a, b+1) \n for month in [1,3,5,7,8,10,12] \n if datetime(year, month, 1).weekday() == 4]\n return (res[0],res[-1], len(res))", "from datetime import date\n\ndef solve(a, b):...
{"fn_name": "solve", "inputs": [[2016, 2020], [1900, 1950], [1800, 2500]], "outputs": [[["Jan", "May", 5]], [["Mar", "Dec", 51]], [["Aug", "Oct", 702]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,326
def solve(a,b):
ee85d10a4d9746e28b327b7773dbb3a7
UNKNOWN
It's the most hotly anticipated game of the school year - Gryffindor vs Slytherin! Write a function which returns the winning team. You will be given two arrays with two values. The first given value is the number of points scored by the team's Chasers and the second a string with a 'yes' or 'no' value if the team ...
["def game_winners(gryffindor, slytherin):\n g, s = (team[0] + 150 * (team[1] == 'yes') for team in [gryffindor, slytherin])\n return 'Gryffindor wins!' if g > s else 'Slytherin wins!' if s > g else \"It's a draw!\"", "def game_winners(gryffindor, slytherin):\n g = gryffindor[0]\n s = slytherin[0]\n if g...
{"fn_name": "game_winners", "inputs": [[[100, "yes"], [100, "no"]], [[350, "no"], [250, "yes"]], [[100, "yes"], [250, "no"]], [[0, "yes"], [150, "no"]], [[150, "no"], [0, "yes"]]], "outputs": [["Gryffindor wins!"], ["Slytherin wins!"], ["It's a draw!"], ["It's a draw!"], ["It's a draw!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,024
def game_winners(gryffindor, slytherin):
a7edce679b17706174ce764bbb29ba0c
UNKNOWN
Imagine that you are given two sticks. You want to end up with three sticks of equal length. You are allowed to cut either or both of the sticks to accomplish this, and can throw away leftover pieces. Write a function, maxlen, that takes the lengths of the two sticks (L1 and L2, both positive values), that will return...
["def maxlen(s1, s2):\n sm, lg = sorted((s1, s2))\n return min(max(lg / 3, sm), lg / 2)", "def maxlen(l1, l2):\n return max(min(l1 / 2, l2), min(l1, l2 / 2), max(l1, l2) / 3)", "def maxlen(*args):\n x,y = sorted(args)\n return [y/2, x, y/3][ (y>2*x) + (y>3*x) ]", "def maxlen(*s):\n a, b = min(s), max(...
{"fn_name": "maxlen", "inputs": [[5, 12], [12, 5], [5, 17], [17, 5], [7, 12], [12, 7]], "outputs": [[5], [5], [5.666666666666667], [5.666666666666667], [6.0], [6.0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,359
def maxlen(l1, l2):
6ae0a710eea2f8ec568fa7c13cd4db00
UNKNOWN
A triangle is called an equable triangle if its area equals its perimeter. Return `true`, if it is an equable triangle, else return `false`. You will be provided with the length of sides of the triangle. Happy Coding!
["def equable_triangle(a, b, c):\n p = a + b + c\n ph = p / 2\n return p * p == ph * (ph - a) * (ph - b) * (ph - c)", "def equable_triangle(a,b,c):\n p = (a + b + c) / 2\n return (p * (p - a) * (p - b) * (p - c)) ** .5 == 2 * p", "def equable_triangle(a,b,c):\n return (a + b + c) * 16 == (a + b - c) *...
{"fn_name": "equable_triangle", "inputs": [[5, 12, 13], [2, 3, 4], [6, 8, 10], [7, 15, 20], [17, 17, 30], [7, 10, 12], [6, 11, 12], [25, 25, 45], [13, 37, 30], [6, 25, 29], [10, 11, 18], [73, 9, 80], [12, 35, 37], [120, 109, 13], [9, 10, 17]], "outputs": [[true], [false], [true], [true], [false], [false], [false], [fal...
INTRODUCTORY
PYTHON3
CODEWARS
1,364
def equable_triangle(a,b,c):
f5887b850ce964b01f52162db61824c0
UNKNOWN
From Wikipedia : "The n-back task is a continuous performance task that is commonly used as an assessment in cognitive neuroscience to measure a part of working memory and working memory capacity. [...] The subject is presented with a sequence of stimuli, and the task consists of indicating when the current stimulus ma...
["def count_targets(n, sequence):\n return sum(a == b for a, b in zip(sequence, sequence[n:]))", "def count_targets(n, s):\n return sum(s[i] == s[i-n] for i in range(n,len(s)))", "def count_targets(n, sequence):\n return sum(1 for a, b in zip(sequence, sequence[n:]) if a == b)", "def count_targets(n, seq):\n ...
{"fn_name": "count_targets", "inputs": [[1, [1, 1, 1, 1, 1]], [2, [1, 1, 1, 1, 1]], [1, [1, 2, 1, 2, 1]], [2, [1, 2, 1, 2, 1]], [9, [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]], [1, []], [1, [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ...
INTRODUCTORY
PYTHON3
CODEWARS
1,173
def count_targets(n, sequence):
22a9614c060c19b1f475f443848740b1
UNKNOWN
```if-not:julia,racket Write a function that returns the total surface area and volume of a box as an array: `[area, volume]` ``` ```if:julia Write a function that returns the total surface area and volume of a box as a tuple: `(area, volume)` ``` ```if:racket Write a function that returns the total surface area and vo...
["def get_size(w, h, d):\n area = 2*(w*h + h*d + w*d)\n volume = w*h*d\n return [area, volume]", "def get_size(w,h,l):\n return [2*(w*l+h*l+h*w), w*h*l]", "def get_size(w,h,d):\n return [2 * (w * d + h * d + h * w), w * h * d]", "def get_size(w, h, d):\n return [2 * (w*h + w*d + h*d), w * h * d]", "ge...
{"fn_name": "get_size", "inputs": [[4, 2, 6], [1, 1, 1], [1, 2, 1], [1, 2, 2], [10, 10, 10]], "outputs": [[[88, 48]], [[6, 1]], [[10, 2]], [[16, 4]], [[600, 1000]]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,734
def get_size(w,h,d):
62ac38e92885d16e1e3726a566b6da6c
UNKNOWN
Given two arrays `a` and `b` write a function `comp(a, b)` (`compSame(a, b)` in Clojure) that checks whether the two arrays have the "same" elements, with the same multiplicities. "Same" means, here, that the elements in `b` are the elements in `a` squared, regardless of the order. ## Examples ## Valid arrays ``` a = ...
["def comp(array1, array2):\n try:\n return sorted([i ** 2 for i in array1]) == sorted(array2)\n except:\n return False", "def comp(a1, a2):\n return None not in (a1,a2) and [i*i for i in sorted(a1)]==sorted(a2)", "def comp(array1, array2):\n if array1 and array2:\n return sorted([x*x f...
{"fn_name": "comp", "inputs": [[[], [1]]], "outputs": [[false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,184
def comp(array1, array2):
dd6d5ed79ac9bef9305a0540db4e7df7
UNKNOWN
# Don't give me five! In this kata you get the start number and the end number of a region and should return the count of all numbers except numbers with a 5 in it. The start and the end number are both inclusive! Examples: ``` 1,9 -> 1,2,3,4,6,7,8,9 -> Result 8 4,17 -> 4,6,7,8,9,10,11,12,13,14,16,17 -> Result 12 ``...
["def dont_give_me_five(start, end):\n return sum('5' not in str(i) for i in range(start, end + 1))", "def dont_give_me_five(start,end):\n return len([num for num in range(start, end+1) if '5' not in str(num)])", "def dont_give_me_five(start,end):\n tick = 0\n for x in range(start, end+1):\n if '5' n...
{"fn_name": "dont_give_me_five", "inputs": [[1, 9], [4, 17], [1, 90], [-4, 17], [-4, 37], [-14, -1], [-14, -6]], "outputs": [[8], [12], [72], [20], [38], [13], [9]]}
INTRODUCTORY
PYTHON3
CODEWARS
20,547
def dont_give_me_five(start,end):
2b5273346019fe645f351d398d775d38
UNKNOWN
Ronny the robot is watching someone perform the Cups and Balls magic trick. The magician has one ball and three cups, he shows Ronny which cup he hides the ball under (b), he then mixes all the cups around by performing multiple two-cup switches (arr). Ronny can record the switches but can't work out where the ball is....
["from functools import reduce\n\ndef cup_and_balls(b, arr):\n return reduce(lambda x, y: y[1] if x == y[0] else y[0] if x == y[1] else x, arr, b)", "def cup_and_balls(b, a):\n for l, r in a:\n b = r if b == l else l if b == r else b\n return b", "def cup_and_balls(b, arr):\n for switch in arr:\n ...
{"fn_name": "cup_and_balls", "inputs": [[2, [[1, 2]]], [1, [[2, 3], [1, 2], [1, 2]]], [2, [[1, 3], [1, 2], [2, 1], [2, 3]]]], "outputs": [[1], [1], [3]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,300
def cup_and_balls(b, arr):
2814f1fb7fb8c3379c7fab946a80e599
UNKNOWN
# The museum of incredible dull things The museum of incredible dull things wants to get rid of some exhibitions. Miriam, the interior architect, comes up with a plan to remove the most boring exhibitions. She gives them a rating, and then removes the one with the lowest rating. However, just as she finished rating a...
["def remove_smallest(numbers):\n a = numbers[:]\n if a:\n a.remove(min(a))\n return a", "def remove_smallest(numbers):\n if len(numbers) < 1: \n return numbers\n idx = numbers.index(min(numbers))\n return numbers[0:idx] + numbers[idx+1:]\n", "def remove_smallest(n):\n return n[:n.ind...
{"fn_name": "remove_smallest", "inputs": [[[1, 2, 3, 4, 5]], [[1, 2, 3, 4]], [[5, 3, 2, 1, 4]], [[1, 2, 3, 1, 1]], [[]]], "outputs": [[[2, 3, 4, 5]], [[2, 3, 4]], [[5, 3, 2, 4]], [[2, 3, 1, 1]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
21,367
def remove_smallest(numbers):
f38980f57566d72acb7936e6834709b0
UNKNOWN
Your program will receive an array of complex numbers represented as strings. Your task is to write the `complexSum` function which have to return the sum as a string. Complex numbers can be written in the form of `a+bi`, such as `2-3i` where `2` is the real part, `3` is the imaginary part, and `i` is the "imaginary ...
["def complexSum(arr, sub={'1i': 'i', '-1i': '-i', '0i': '0'}):\n s = str(sum(complex(x.replace('i', 'j')) for x in arr)).replace('j', 'i')\n s = s.strip('()')\n s = s.replace('+0i', '')\n return sub.get(s, s) ", "def complexSum(arr):\n a = [complex(i.replace(\"i\", \"j\")) for i in arr]\n s = 0\n ...
{"fn_name": "complexSum", "inputs": [[["2+3i", "3-i"]], [["2-3i", "3+i"]], [["3", "-3+i"]], [[]], [["3+4i"]], [["123+456i"]], [["0"]], [["-i"]], [["1", "1"]], [["-5", "5"]], [["1", "10", "100", "1000"]], [["5+4i", "11+3i"]], [["-2-4i", "-8+6i"]], [["-1-i", "7+10i"]], [["3+4i", "3-4i"]], [["10+i", "10-i", "9"]], [["2+3i...
INTRODUCTORY
PYTHON3
CODEWARS
3,563
def complexSum(arr):
f39bde48dbafd4028e6d06c2827576c0
UNKNOWN
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: 2332 110011 54322345 For a given number ```num```, write a function which returns the number of numerical palindromes within each number. For this kata, single digi...
["def palindrome(num):\n if not isinstance(num, int) or num < 0:\n return 'Not valid'\n s = str(num)\n return sum(sum(s[i:i+n] == s[i:i+n][::-1] for i in range(len(s)-n+1)) for n in range(2, len(s)+1))\n", "def palindrome(num):\n \n if not isinstance(num, int) or num < 0:\n return \"Not...
{"fn_name": "palindrome", "inputs": [[2], [141221001], [1551], [13598], ["ACCDDCCA"], ["1551"], [-4505]], "outputs": [[0], [5], [2], [0], ["Not valid"], ["Not valid"], ["Not valid"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,085
def palindrome(num):
ae78ba7f8be336b26b342df17d8aace9
UNKNOWN
Variation of this nice kata, the war has expanded and become dirtier and meaner; both even and odd numbers will fight with their pointy `1`s. And negative integers are coming into play as well, with, ça va sans dire, a negative contribution (think of them as spies or saboteurs). Again, three possible outcomes: `odds w...
["def bits_war(numbers):\n odd, even = 0, 0\n for number in numbers:\n if number % 2 == 0:\n if number > 0:\n even += bin(number).count('1')\n else:\n even -= bin(number).count('1')\n else:\n if number > 0:\n odd += bin(nu...
{"fn_name": "bits_war", "inputs": [[[1, 5, 12]], [[7, -3, 20]], [[7, -3, -2, 6]], [[-3, -5]], [[]]], "outputs": [["odds win"], ["evens win"], ["tie"], ["evens win"], ["tie"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,555
def bits_war(numbers):
f08f2ecb2f4609b1de2274b37a1b3928
UNKNOWN
# Task Given a string `str`, reverse it omitting all non-alphabetic characters. # Example For `str = "krishan"`, the output should be `"nahsirk"`. For `str = "ultr53o?n"`, the output should be `"nortlu"`. # Input/Output - `[input]` string `str` A string consists of lowercase latin letters, digits and sym...
["def reverse_letter(s):\n return ''.join([i for i in s if i.isalpha()])[::-1]\n\n", "reverse_letter = lambda s: ''.join([i for i in s if i.isalpha()])[::-1]\n", "def reverse_letter(string):\n return ''.join(filter(str.isalpha, reversed(string)))", "import re\ndef reverse_letter(string):\n return re.sub(\"[^a-zA...
{"fn_name": "reverse_letter", "inputs": [["krishan"], ["ultr53o?n"], ["ab23c"], ["krish21an"]], "outputs": [["nahsirk"], ["nortlu"], ["cba"], ["nahsirk"]]}
INTRODUCTORY
PYTHON3
CODEWARS
15,895
def reverse_letter(string):
16fd4da7e2ce26d810f4129e205e7bb8
UNKNOWN
- Input: Integer `n` - Output: String Example: `a(4)` prints as ``` A A A A A A A A ``` `a(8)` prints as ``` A A A A A A A A A A A A A A A A A A ``` `a(12)` prints as ``` A A A...
["def a(n):\n \"\"\"\n \"\"\"\n if n % 2 != 0:\n n = n - 1\n if n < 4:\n return ''\n side = \" \" * (n - 1)\n li = [side + \"A\" + side]\n for i in range(1, n):\n side = side[1:]\n middle = \"A \" * (i - 1) if i == (n / 2) else \" \" * (i - 1)\n li.append(side + ...
{"fn_name": "a", "inputs": [[4], [7], [11], [30], [-5], [0], [3]], "outputs": [[" A \n A A \n A A A \nA A"], [" A \n A A \n A A \n A A A A \n A A \nA A"], [" A \n A A \n A A \n A A \n A A \n A A A A ...
INTRODUCTORY
PYTHON3
CODEWARS
1,829
def a(n):
45a49808e343ca2bce9711d727293b4e
UNKNOWN
In Math, an improper fraction is a fraction where the numerator (the top number) is greater than or equal to the denominator (the bottom number) For example: ```5/3``` (five third). A mixed numeral is a whole number and a fraction combined into one "mixed" number. For example: ```1 1/2``` (one and a half) is a mixed n...
["def convert_to_mixed_numeral(parm):\n a, b = list(map(int, parm.split('/')))\n d, r = divmod(abs(a), b)\n s = (0 < a) - (a < 0)\n return parm if d == 0 else ('{}' + ' {}/{}' * (r != 0)).format(d * s, r, b)\n", "def convert_to_mixed_numeral(parm):\n sign, parm = parm[:(\"-\" in parm)], parm[(\"-\" in pa...
{"fn_name": "convert_to_mixed_numeral", "inputs": [["74/3"], ["9999/24"], ["74/30"], ["13/5"], ["5/3"], ["1/1"], ["10/10"], ["900/10"], ["9920/124"], ["6/2"], ["9/77"], ["96/100"], ["12/18"], ["6/36"], ["1/18"], ["-64/8"], ["-6/8"], ["-9/78"], ["-504/26"], ["-47/2"], ["-21511/21"]], "outputs": [["24 2/3"], ["416 15/24"...
INTRODUCTORY
PYTHON3
CODEWARS
3,317
def convert_to_mixed_numeral(parm):
4cc7d85b633ffc2ff8d5c5dbfd808822
UNKNOWN
Goldbach's conjecture is one of the oldest and best-known unsolved problems in number theory and all of mathematics. It states: Every even integer greater than 2 can be expressed as the sum of two primes. For example: `6 = 3 + 3` `8 = 3 + 5` `10 = 3 + 7 = 5 + 5` `12 = 5 + 7` Some rules for the conjecture: - pairs...
["def goldbach(n):\n if n < 2:\n return []\n if n == 4:\n return [[2, 2]]\n l = n - 2\n sieve = [True] * (l // 2)\n for i in range(3, int(l**0.5) + 1, 2):\n if sieve[i // 2]:\n sieve[i * i // 2::i] = [False] * ((l - i * i - 1) // (2 * i) + 1)\n primes = [(2 * i + 1) for...
{"fn_name": "goldbach", "inputs": [[2], [4], [6], [8], [10], [52], [54], [56], [58], [100], [200], [1000], [5000]], "outputs": [[[]], [[[2, 2]]], [[[3, 3]]], [[[3, 5]]], [[[3, 7], [5, 5]]], [[[5, 47], [11, 41], [23, 29]]], [[[7, 47], [11, 43], [13, 41], [17, 37], [23, 31]]], [[[3, 53], [13, 43], [19, 37]]], [[[5, 53], ...
INTRODUCTORY
PYTHON3
CODEWARS
2,094
def goldbach(n):
c3197875f1385cbd73e0b422f039d822
UNKNOWN
Consider a pyramid made up of blocks. Each layer of the pyramid is a rectangle of blocks, and the dimensions of these rectangles increment as you descend the pyramid. So, if a layer is a `3x6` rectangle of blocks, then the next layer will be a `4x7` rectangle of blocks. A `1x10` layer will be on top of a `2x11` layer o...
["def num_blocks(w, l, h):\n return w*l*h + (w+l)*h*(h-1)/2 + h*(h-1)*(2*h-1)/6", "def num_blocks(w, l, h):\n return w*l*h + (w+l) * (h-1)*h//2 + (h-1)*h*(2*h-1)//6\n \n\"\"\"\nFor those who wonder:\n\nfirst layer being of size w*l, the total number of blocks, SB, is:\n\n SB = w*l + (w+1)*(l+1) + (w+2)*(...
{"fn_name": "num_blocks", "inputs": [[1, 1, 2], [2, 4, 3], [1, 10, 10], [20, 30, 40]], "outputs": [[5], [47], [880], [83540]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,244
def num_blocks(w, l, h):
c62b001d79d2fa4aa84163853f7944e6
UNKNOWN
Implement a function, so it will produce a sentence out of the given parts. Array of parts could contain: - words; - commas in the middle; - multiple periods at the end. Sentence making rules: - there must always be a space between words; - there must not be a space between a comma and word on the left; - there must ...
["def make_sentences(parts):\n return ' '.join(parts).replace(' ,', ',').strip(' .') + '.'", "import re\n\ndef make_sentences(parts):\n return re.sub(' ([,.])', r'\\1', ' '.join(parts).replace(' ,', ',')).rstrip('.') + '.'", "import re\n\ndef make_sentences(parts):\n return re.match(r'[^\\.]+', ' '.join(parts)...
{"fn_name": "make_sentences", "inputs": [[["hello", "world"]], [["Quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog"]], [["hello", ",", "my", "dear"]], [["one", ",", "two", ",", "three"]], [["One", ",", "two", "two", ",", "three", "three", "three", ",", "4", "4", "4", "4"]], [["hello", "world", "."]], [["By...
INTRODUCTORY
PYTHON3
CODEWARS
1,312
def make_sentences(parts):
d9679bb9b1149e390343ed7cd4da1605
UNKNOWN
You're a statistics professor and the deadline for submitting your students' grades is tonight at midnight. Each student's grade is determined by their mean score across all of the tests they took this semester. You've decided to automate grade calculation by writing a function `calculate_grade()` that takes a list of...
["from bisect import bisect\nfrom statistics import mean\n\n\ndef calculate_grade(scores):\n return 'FDCBA'[bisect([60, 70, 80, 90], mean(scores))]\n", "def calculate_grade(scores):\n for score in scores:\n mean = sum(scores)/len(scores)\n if mean >= 90 and mean <= 100:\n return \"A\"\n ...
{"fn_name": "calculate_grade", "inputs": [[[92, 94, 99]], [[50, 60, 70, 80, 90]], [[50, 55]]], "outputs": [["A"], ["C"], ["F"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,287
def calculate_grade(scores):
a3e64e017bbbe5be22efc12370d180aa
UNKNOWN
Converting a 24-hour time like "0830" or "2030" to a 12-hour time (like "8:30 am" or "8:30 pm") sounds easy enough, right? Well, let's see if you can do it! You will have to define a function named "to12hourtime", and you will be given a four digit time string (in "hhmm" format) as input. Your task is to return a 12...
["from datetime import datetime\n\ndef to12hourtime(t):\n return datetime.strptime(t, '%H%M').strftime('%I:%M %p').lstrip('0').lower()", "def to12hourtime(t):\n hour = int(t[:2])\n \n if hour >= 12:\n hour -= 12\n suf = 'pm'\n else:\n suf = 'am'\n \n if hour == 0:\n hour...
{"fn_name": "to12hourtime", "inputs": [["0000"], ["0001"], ["0002"], ["0003"], ["0004"], ["0005"], ["0006"], ["0007"], ["0008"], ["0009"], ["0010"], ["0011"], ["0012"], ["0013"], ["0014"], ["0015"], ["0016"], ["0017"], ["0018"], ["0019"], ["0020"], ["0021"], ["0022"], ["0023"], ["0024"], ["0025"], ["0026"], ["0027"], [...
INTRODUCTORY
PYTHON3
CODEWARS
1,976
def to12hourtime(t):
a1d43fe884aa79230d14a060d722b49e
UNKNOWN
I assume most of you are familiar with the ancient legend of the rice (but I see wikipedia suggests [wheat](https://en.wikipedia.org/wiki/Wheat_and_chessboard_problem), for some reason) problem, but a quick recap for you: a young man asks as a compensation only `1` grain of rice for the first square, `2` grains for the...
["squares_needed = int.bit_length", "def squares_needed(grains):\n return grains.bit_length()", "def squares_needed(grains):\n if grains < 1:\n return 0\n else:\n return 1 + squares_needed(grains // 2)", "from math import log2, ceil\n\ndef squares_needed(grains):\n return grains and ceil(log2(...
{"fn_name": "squares_needed", "inputs": [[0], [1], [2], [3], [4]], "outputs": [[0], [1], [2], [2], [3]]}
INTRODUCTORY
PYTHON3
CODEWARS
17,432
def squares_needed(grains):
688b59973c4139e405cdc076d731715b
UNKNOWN
Write a function called "filterEvenLengthWords". Given an array of strings, "filterEvenLengthWords" returns an array containing only the elements of the given array whose length is an even number. var output = filterEvenLengthWords(['word', 'words', 'word', 'words']); console.log(output); // --> ['word', 'word']
["def filter_even_length_words(words):\n return [word for word in words if len(word) % 2 == 0]", "def filter_even_length_words(words):\n even_words_array=[]\n for i in words:\n if len(i)%2==0:\n even_words_array.append(i)\n return even_words_array\n", "def filter_even_length_words(words):\n r...
{"fn_name": "filter_even_length_words", "inputs": [[["Hello", "World"]], [["One", "Two", "Three", "Four"]]], "outputs": [[[]], [["Four"]]]}
INTRODUCTORY
PYTHON3
CODEWARS
973
def filter_even_length_words(words):
984b9857d91389334d00780b155b3d1a
UNKNOWN
### Tongues Gandalf's writings have long been available for study, but no one has yet figured out what language they are written in. Recently, due to programming work by a hacker known only by the code name ROT13, it has been discovered that Gandalf used nothing but a simple letter substitution scheme, and further, th...
["def tongues(code):\n AsT = \"\"\n for i in code:\n if i == \"i\":\n AsT = AsT + \"o\"\n elif i == \"t\":\n AsT = AsT + \"n\"\n elif i == \"a\":\n AsT = AsT + \"e\"\n elif i == \"d\":\n AsT = AsT + \"r\"\n elif i == \"f\":\n ...
{"fn_name": "tongues", "inputs": [["Ita dotf ni dyca nsaw ecc."], ["Tim oh nsa nowa gid ecc fiir wat ni liwa ni nsa eor ig nsaod liytndu."], ["Giydhlida etr hakat uaedh efi iyd gidagensadh pdiyfsn ytni nsoh"], ["litnotatn e tam tenoit."], ["Nsa zyolv pdimt gij xywbar ikad nsa cequ rifh."], ["Tywpadh (1234567890) etr by...
INTRODUCTORY
PYTHON3
CODEWARS
5,348
def tongues(code):
ceac03cf81e6aba00502af9648e51fd1
UNKNOWN
Your task is to make function, which returns the sum of a sequence of integers. The sequence is defined by 3 non-negative values: **begin**, **end**, **step**. If **begin** value is greater than the **end**, function should returns **0** *Examples* ~~~if-not:nasm ~~~ This is the first kata in the series: 1) Sum ...
["def sequence_sum(start, end, step):\n return sum(range(start, end+1, step))", "def sequence_sum(begin_number, end_number, step):\n return sum(range(begin_number, end_number+1, step))", "def sequence_sum(b, e, s):\n k = (e - b) // s\n return (1 + k) * (b + s * k / 2) if b <= e else 0", "def sequence_sum(begin,...
{"fn_name": "sequence_sum", "inputs": [[2, 6, 2], [1, 5, 1], [1, 5, 3], [0, 15, 3], [16, 15, 3], [2, 24, 22], [2, 2, 2], [2, 2, 1], [1, 15, 3], [15, 1, 3]], "outputs": [[12], [15], [5], [45], [0], [26], [2], [2], [35], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
20,410
def sequence_sum(begin_number, end_number, step):
11cf4ca3bbd55b15acde7aaa5a83f651
UNKNOWN
# Task You're standing at the top left corner of an `n × m` grid and facing towards the `right`. Then you start walking one square at a time in the direction you are facing. If you reach the border of the grid or if the next square you are about to visit has already been visited, you turn right. You stop w...
["def direction_in_grid(n, m):\n return \"LR\"[n%2] if m >= n else \"UD\"[m%2]\n", "def direction_in_grid(n,m):\n return \"LRUD\"[n%2 if m>=n else 2+m%2]\n", "NEXT = {'R': 'D', 'D': 'L', 'L': 'U', 'U': 'R'}\n\ndef direction_in_grid(n, m, d='R'):\n while n > 1:\n n, m, d = m, n-1, NEXT[d]\n return d", "...
{"fn_name": "direction_in_grid", "inputs": [[1, 1], [2, 2], [2, 3], [2, 4], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [5, 4], [5, 5], [5, 6], [100, 100]], "outputs": [["R"], ["L"], ["L"], ["L"], ["D"], ["U"], ["R"], ["R"], ["R"], ["U"], ["D"], ["L"], ["L"], ["L"], ["U"], ["R"], ["R...
INTRODUCTORY
PYTHON3
CODEWARS
1,113
def direction_in_grid(n,m):
6f1bbcef178886262733a61ac41c5009
UNKNOWN
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: * 232 * 110011 * 54322345 Complete the function to test if the given number (`num`) **can be rearranged** to form a numerical palindrome or not. Return a boolean (`...
["from collections import Counter\ndef palindrome(num):\n if not isinstance(num, int) or num < 0:\n return 'Not valid'\n return num > 10 and sum(1 for v in Counter(map(int, str(num))).values() if v % 2) <= 1", "def palindrome(num):\n s = str(num)\n return \"Not valid\" if not isinstance(num, int) or ...
{"fn_name": "palindrome", "inputs": [[5], [1212], ["ololo"], [1331], [194], [111222], ["Hello world!"], [3357665], ["357665"], [-42]], "outputs": [[false], [true], ["Not valid"], [true], [false], [false], ["Not valid"], [true], ["Not valid"], ["Not valid"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,280
def palindrome(num):
e40fd59130d0448a5a0609267d827455
UNKNOWN
You are given an initial 2-value array (x). You will use this to calculate a score. If both values in (x) are numbers, the score is the sum of the two. If only one is a number, the score is that number. If neither is a number, return 'Void!'. Once you have your score, you must return an array of arrays. Each sub arr...
["def explode(arr): \n return [arr] * sum(v for v in arr if isinstance(v,int)) or 'Void!'", "def explode(arr): \n numbers = [n for n in arr if type(n) == int]\n return [arr] * sum(numbers) if numbers else \"Void!\"", "def explode(arr): \n a,b,c = arr[0],arr[1],0\n if type(a) == int: c+=a\n if type(...
{"fn_name": "explode", "inputs": [[[9, 3]], [["a", 3]], [[6, "c"]], [["a", "b"]], [[1, 0]]], "outputs": [[[[9, 3], [9, 3], [9, 3], [9, 3], [9, 3], [9, 3], [9, 3], [9, 3], [9, 3], [9, 3], [9, 3], [9, 3]]], [[["a", 3], ["a", 3], ["a", 3]]], [[[6, "c"], [6, "c"], [6, "c"], [6, "c"], [6, "c"], [6, "c"]]], ["Void!"], [[[1, ...
INTRODUCTORY
PYTHON3
CODEWARS
1,430
def explode(arr):
23315f91eb79c78094c07339cbb05d54
UNKNOWN
# Covfefe Your are given a string. You must replace the word(s) `coverage` by `covfefe`, however, if you don't find the word `coverage` in the string, you must add `covfefe` at the end of the string with a leading space. For the languages where the string is not immutable (such as ruby), don't modify the given strin...
["def covfefe(s):\n return s.replace(\"coverage\",\"covfefe\") if \"coverage\" in s else s+\" covfefe\"", "def covfefe(s):\n if 'coverage' in s:\n return s.replace('coverage', 'covfefe')\n else:\n return s + ' ' + 'covfefe'\n", "def covfefe(s):\n return \"\".join(s.replace(\"coverage\", \"covf...
{"fn_name": "covfefe", "inputs": [["coverage"], ["coverage coverage"], ["nothing"], ["double space "], ["covfefe"]], "outputs": [["covfefe"], ["covfefe covfefe"], ["nothing covfefe"], ["double space covfefe"], ["covfefe covfefe"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,246
def covfefe(s):
b64a52a2d8fe3d4162749f762265af57
UNKNOWN
# Task Mr.Odd is my friend. Some of his common dialogues are “Am I looking odd?” , “It’s looking very odd” etc. Actually “odd” is his favorite word. In this valentine when he went to meet his girlfriend. But he forgot to take gift. Because of this he told his gf that he did an odd thing. His gf became angry and gave...
["import re\n\npattern = re.compile('o(.*?)d(.*?)d')\n\ndef odd(s):\n n = 0\n while pattern.search(s):\n n += 1\n s = pattern.sub(r'\\1\\2', s, count=1)\n return n", "import re\n\no = re.compile(r\"o(.*?)d(.*?)d\")\n\ndef odd(stg):\n count = 0\n while o.search(stg):\n count += 1\n ...
{"fn_name": "odd", "inputs": [["oudddbo"], ["ouddddbo"], ["ooudddbd"], ["qoddoldfoodgodnooofostorodrnvdmddddeidfoi"]], "outputs": [[1], [1], [2], [6]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,661
def odd(s):
c6a61df0255486942577c372d8832152
UNKNOWN
## Description You've been working with a lot of different file types recently as your interests have broadened. But what file types are you using the most? With this question in mind we look at the following problem. Given a `List/Array` of Filenames (strings) `files` return a `List/Array of string(s)` contatining ...
["from collections import Counter\nimport re\n\ndef solve(files):\n c = Counter(re.match('.*(\\.[^.]+)$', fn).group(1) for fn in files)\n m = max(c.values(),default=0)\n return sorted(k for k in c if c[k] == m)", "from collections import Counter\n\ndef solve(files):\n c = Counter(f[f.rfind(\".\"):] for f in...
{"fn_name": "solve", "inputs": [[["direful.pr", "festive.html", "historical.wav", "holistic.mp3", "impossible.jar", "gentle.cpp", "gleaming.xml", "inconclusive.js", "erect.jar", "befitting.mp3", "brief.wp", "beautiful.jar", "energetic.pt", "careful.wp", "defective.cpp", "icky.wav", "gorgeous.txt", "good.pt", "fat.pt", ...
INTRODUCTORY
PYTHON3
CODEWARS
2,574
def solve(files):
52a619ec3b6566b279d98a4b315e4589
UNKNOWN
# Base64 Numeric Translator Our standard numbering system is (Base 10). That includes 0 through 9. Binary is (Base 2), only 1’s and 0’s. And Hexadecimal is (Base 16) (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F). A hexadecimal “F” has a (Base 10) value of 15. (Base 64) has 64 individual characters which translate ...
["DIGITS = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\"\n\ndef base64_to_base10(string):\n return sum(DIGITS.index(digit) * 64**i\n for i, digit in enumerate(string[::-1]))", "base64_to_base10=lambda strr:int(''.join([('0'*6+bin('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvw...
{"fn_name": "base64_to_base10", "inputs": [["WIN"], ["b64"], ["B64"], ["/+/"], ["HelloWorld"]], "outputs": [[90637], [114360], [7864], [262079], [134710352538679645]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,815
def base64_to_base10(string):
9cac1ee155bf07036909e62cba9c2c13
UNKNOWN
This kata aims to show the vulnerabilities of hashing functions for short messages. When provided with a SHA-256 hash, return the value that was hashed. You are also given the characters that make the expected value, but in alphabetical order. The returned value is less than 10 characters long. Return `nil` for Ruby ...
["from hashlib import sha256\nfrom itertools import permutations\n\n\ndef sha256_cracker(hash, chars):\n for p in permutations(chars, len(chars)):\n current = ''.join(p)\n if sha256(current.encode('utf-8')).hexdigest() == hash:\n return current\n", "import hashlib\nimport itertools\n\ndef sh...
{"fn_name": "sha256_cracker", "inputs": [["b8c49d81cb795985c007d78379e98613a4dfc824381be472238dbd2f974e37ae", "deGioOstu"], ["f58262c8005bb64b8f99ec6083faf050c502d099d9929ae37ffed2fe1bb954fb", "abc"]], "outputs": [["GoOutside"], [null]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,638
def sha256_cracker(hash, chars):
81cfc2daab86cc5e365aeb55b621876a
UNKNOWN
*Recreation of [Project Euler problem #6](https://projecteuler.net/problem=6)* Find the difference between the sum of the squares of the first `n` natural numbers `(1 <= n <= 100)` and the square of their sum. ## Example For example, when `n = 10`: * The square of the sum of the numbers is: (1 + 2 + 3 + 4 + 5 + 6...
["def difference_of_squares(x):\n r = range(1,x+1,1)\n return (sum(r) ** 2) - (sum( z**2 for z in r))", "difference_of_squares = lambda n: n ** 2 * (n + 1) ** 2 / 4 - n * (n + 1) * (2 * n + 1) / 6", "def difference_of_squares(x):\n \n # Initialize\n square_sum = 0\n sum_squares = 0\n \n # Loop o...
{"fn_name": "difference_of_squares", "inputs": [[5], [10], [100]], "outputs": [[170], [2640], [25164150]]}
INTRODUCTORY
PYTHON3
CODEWARS
15,554
def difference_of_squares(n):
54c7a0de1714f699b2c7c5f156cfcde4
UNKNOWN
In this Kata, you will be given two numbers, n and k and your task will be to return the k-digit array that sums to n and has the maximum possible GCD. For example, given `n = 12, k = 3`, there are a number of possible `3-digit` arrays that sum to `12`, such as `[1,2,9], [2,3,7], [2,4,6], ...` and so on. Of all the po...
["def solve(n,k):\n maxGcd = 2*n // (k * (k+1))\n for gcd in range(maxGcd, 0, -1):\n last = n-gcd * k*(k-1)//2\n if not last % gcd:\n return [gcd*x if x != k else last for x in range(1,k+1)]\n return []", "solve=lambda n,k: [n] if k==1 else (lambda r: r[-1] if len(r) else [])(list(filt...
{"fn_name": "solve", "inputs": [[12, 7], [12, 3], [12, 4], [18, 3], [18, 5], [24, 3], [24, 4], [24, 5], [24, 6], [276, 12]], "outputs": [[[]], [[2, 4, 6]], [[1, 2, 3, 6]], [[3, 6, 9]], [[1, 2, 3, 4, 8]], [[4, 8, 12]], [[2, 4, 6, 12]], [[1, 2, 3, 4, 14]], [[1, 2, 3, 4, 5, 9]], [[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, ...
INTRODUCTORY
PYTHON3
CODEWARS
3,183
def solve(n,k):
6ee9bb2cf8307f6706817c19c94dc0b0
UNKNOWN
Given a mathematical equation that has `*,+,-,/`, reverse it as follows: ```Haskell solve("100*b/y") = "y/b*100" solve("a+b-c/d*30") = "30*d/c-b+a" ``` More examples in test cases. Good luck! Please also try: [Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9db0000f2) [Simple remove duplicat...
["import re\n\ndef solve(eq):\n return ''.join(reversed(re.split(r'(\\W+)', eq)))", "def solve(eq):\n #\n # implemantation takes advantage of abscence of spaces\n #\n leq = (eq.replace('*', ' * ')\n .replace('/', ' / ')\n .replace('+', ' + ')\n .replace('-', ' - ')\n ...
{"fn_name": "solve", "inputs": [["100*b/y"], ["a+b-c/d*30"], ["a*b/c+50"]], "outputs": [["y/b*100"], ["30*d/c-b+a"], ["50+c/b*a"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,295
def solve(eq):
85f3ff41fe7f08400d947a7a358f55ef
UNKNOWN
You have to create a function,named `insertMissingLetters`, that takes in a `string` and outputs the same string processed in a particular way. The function should insert **only after the first occurrence** of each character of the input string, all the **alphabet letters** that: -**are NOT** in the original string ...
["def insert_missing_letters(s):\n s, lst, found, inside = s.lower(), [], set(), set(s.upper())\n for a in s:\n lst.append(a if a in found else\n a + ''.join(c for c in map(chr, range(ord(a)-31,91)) if c not in inside) )\n found.add(a)\n \n return ''.join(lst)", "from str...
{"fn_name": "insert_missing_letters", "inputs": [["hello"], ["abcdefghijklmnopqrstuvwxyz"], ["hellllllllllllooooo"], ["pixxa"], ["xpixax"], ["z"]], "outputs": [["hIJKMNPQRSTUVWXYZeFGIJKMNPQRSTUVWXYZlMNPQRSTUVWXYZloPQRSTUVWXYZ"], ["abcdefghijklmnopqrstuvwxyz"], ["hIJKMNPQRSTUVWXYZeFGIJKMNPQRSTUVWXYZlMNPQRSTUVWXYZlllllll...
INTRODUCTORY
PYTHON3
CODEWARS
3,341
def insert_missing_letters(st):
74d1c5b5ebea26603e4720c203db61a9
UNKNOWN
Given n number of people in a room, calculate the probability that any two people in that room have the same birthday (assume 365 days every year = ignore leap year). Answers should be two decimals unless whole (0 or 1) eg 0.05
["def calculate_probability(n):\n return round(1 - (364 / 365) ** (n * (n - 1) / 2), 2)", "def calculate_probability(n, p=1):\n for i in range(n):\n p *= 365 - i\n return round(1 - p / 365**n, 2)", "from math import factorial\n\ndef calculate_probability(n):\n return round(1 - factorial(365) / (facto...
{"fn_name": "calculate_probability", "inputs": [[5], [15], [1], [365], [366]], "outputs": [[0.03], [0.25], [0], [1], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,413
def calculate_probability(n):
e2223e35c105702a4a21d99cab2b6215
UNKNOWN
## Task: Your task is to write a function which returns the sum of following series upto nth term(parameter). Series: 1 + 1/4 + 1/7 + 1/10 + 1/13 + 1/16 +... ## Rules: * You need to round the answer to 2 decimal places and return it as String. * If the given value is 0 then it should return 0.00 * You will ...
["def series_sum(n):\n return '{:.2f}'.format(sum(1.0/(3 * i + 1) for i in range(n)))", "def series_sum(n):\n sum = 0.0\n for i in range(0,n):\n sum += 1 / (1 + 3 * float(i))\n return '%.2f' % sum", "def series_sum(n):\n seriesSum = 0.0\n for x in range(n):\n seriesSum += 1 / (1 + x * 3)...
{"fn_name": "series_sum", "inputs": [[1], [2], [3], [4], [5], [6], [7], [8], [9], [15], [39], [58], [0]], "outputs": [["1.00"], ["1.25"], ["1.39"], ["1.49"], ["1.57"], ["1.63"], ["1.68"], ["1.73"], ["1.77"], ["1.94"], ["2.26"], ["2.40"], ["0.00"]]}
INTRODUCTORY
PYTHON3
CODEWARS
14,846
def series_sum(n):
78d1c3563639f2de84e5aca52c6d6e85
UNKNOWN
You've made it through the moat and up the steps of knowledge. You've won the temples games and now you're hunting for treasure in the final temple run. There's good news and bad news. You've found the treasure but you've triggered a nasty trap. You'll surely perish in the temple chamber. With your last movements, you...
["def mark_spot(n):\n if not isinstance(n, int) or not n%2 or n<1: return '?'\n\n spots = [[' ']*n for _ in range(n)]\n for i,row in enumerate(spots):\n row[i],row[-1-i] = 'XX'\n\n return '\\n'.join( ' '.join(row).rstrip() for row in spots+[\"\"] )", "def mark_spot(n):\n if type(n) is not int or n...
{"fn_name": "mark_spot", "inputs": [[5], [1], [[]], [11], ["treasure"], ["5"], [-1], [3], [2], [0.5]], "outputs": [["X X\n X X\n X\n X X\nX X\n"], ["X\n"], ["?"], ["X X\n X X\n X X\n X X\n X X\n X\n X X\n X ...
INTRODUCTORY
PYTHON3
CODEWARS
2,967
def mark_spot(n):
1e70bc504a092b0e0ed28dd0ca349b7d
UNKNOWN
# Task A robot is standing at the `(0, 0)` point of the Cartesian plane and is oriented towards the vertical (y) axis in the direction of increasing y values (in other words, he's facing up, or north). The robot executes several commands each of which is a single positive integer. When the robot is given a positive in...
["def robot_walk(a):\n i=3\n while(i<len(a) and a[i] < a[i-2]): i+=1\n return i<len(a)\n", "def robot_walk(a):\n return any(x <= y for x,y in zip(a[1:], a[3:]))", "def robot_walk(a):\n if len(set(a)) == 1:\n return True\n movings = []\n p = (0, 0) # x, y\n dir = (0, 1)\n for k in a: \n ...
{"fn_name": "robot_walk", "inputs": [[[4, 4, 3, 2, 2, 3]], [[7, 5, 4, 5, 2, 3]], [[10, 3, 10, 2, 5, 1, 2]], [[11, 8, 6, 6, 4, 3, 7, 2, 1]], [[5, 5, 5, 5]], [[34241, 23434, 2341]], [[9348, 2188, 9348]]], "outputs": [[true], [true], [false], [true], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,767
def robot_walk(a):
c738c17d5dde722dbcb11aa346b8cec5
UNKNOWN
Dee is lazy but she's kind and she likes to eat out at all the nice restaurants and gastropubs in town. To make paying quick and easy she uses a simple mental algorithm she's called The Fair %20 Rule. She's gotten so good she can do this in a few seconds and it always impresses her dates but she's perplexingly still si...
["def calc_tip(p, r):\n if p % 10 < 5:\n p //= 10\n else:\n p = p // 10 + 1\n if r == 1:\n tip = p + 1\n elif r == 0:\n tip = p - 1\n else:\n tip = int(p/2) - 1\n return tip if tip >= 0 else 0", "def calc_tip(p, r):\n if p%10<5: p-=p%10\n else: p+=(10-p%10)\n ...
{"fn_name": "calc_tip", "inputs": [[4, 1], [4, 0], [4, -1], [5, 1], [5, 0], [5, -1], [14, 1], [14, 0], [14, -1], [15, 1], [15, 0], [15, -1], [24, 1], [24, 0], [24, -1], [25, 1], [25, 0], [25, -1], [125, 1], [125, 0], [125, -1], [144, 1], [144, 0], [144, -1]], "outputs": [[1], [0], [0], [2], [0], [0], [2], [0], [0], [3]...
INTRODUCTORY
PYTHON3
CODEWARS
1,543
def calc_tip(p, r):
a97e4757b5b0009214e7440f58fdb641
UNKNOWN
For every string, after every occurrence of `'and'` and `'but'`, insert the substring `'apparently'` directly after the occurrence. If input does not contain 'and' or 'but', return the original string. If a blank string, return `''`. If substring `'apparently'` is already directly after an `'and'` and/or `'but'`, do ...
["import re\n\ndef apparently(string):\n return re.sub(r'(?<=\\b(and|but)\\b(?! apparently\\b))', ' apparently', string)", "import re\napparently=lambda Q:re.sub(r'(?<=\\band|\\bbut)\\b(?! apparently\\b)',' apparently',Q)", "import re\nfrom functools import partial\n\napparently = partial(re.sub, r'(?<=\\b(and|but)\...
{"fn_name": "apparently", "inputs": [["A fast-food resteraunt down the street was grumbling my tummy but I could not go."], ["apparently"], ["and"], ["but"], ["but apparently"], ["and apparently"], ["but but but and and and"], [""], ["but and apparently apparently apparently apparently"], ["and apparentlybutactuallynot...
INTRODUCTORY
PYTHON3
CODEWARS
1,657
def apparently(string):
3b9b3e1a1f59ec38c2198ffb0244e2cf
UNKNOWN
You are given two positive integers ```a``` and ```b```. You can perform the following operations on ```a``` so as to obtain ```b``` : ``` (a-1)/2 (if (a-1) is divisible by 2) a/2 (if a is divisible by 2) a*2 ``` ```b``` will always be a power of 2. You are to write a function ```operation(a,b)``` that effici...
["from math import log2\n\ndef operation(a,b, n = 0):\n while log2(a) % 1:\n n += 1\n a //= 2\n return n + abs(log2(a/b))", "def operation(a,b):\n res = 0\n while a != 1 << a.bit_length()-1:\n a, res = a>>1, res+1\n return res + abs(a.bit_length() - b.bit_length())", "from math impor...
{"fn_name": "operation", "inputs": [[1, 1], [2, 4], [3, 8], [4, 16], [4, 1], [1, 4]], "outputs": [[0], [1], [4], [2], [2], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,145
def operation(a,b):
14c8360471a01b577a52c772df1412bc
UNKNOWN
# Task Write a function that accepts `msg` string and returns local tops of string from the highest to the lowest. The string's tops are from displaying the string in the below way: ``` 3 p 2 4 ...
["def tops(msg):\n i,d,s = 1,5, ''\n while i < len(msg):\n s += msg[i]\n i += d\n d += 4\n return s[::-1]", "def tops(msg):\n if len(msg) < 2:\n return ''\n g = 2\n k = ''\n ni = 0\n k += msg[1]\n for i in msg[1:]:\n if ni == g * 2 + 1:\n k += i\n...
{"fn_name": "tops", "inputs": [[""], ["12"], ["abcdefghijklmnopqrstuvwxyz12345"], ["abcdefghijklmnopqrstuvwxyz1236789ABCDEFGHIJKLMN"]], "outputs": [[""], ["2"], ["3pgb"], ["M3pgb"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,716
def tops(msg):
f260c28652f0adce93643cdfc34274dd
UNKNOWN
### Task The __dot product__ is usually encountered in linear algebra or scientific computing. It's also called __scalar product__ or __inner product__ sometimes: > In mathematics, the __dot product__, or __scalar product__ (or sometimes __inner product__ in the context of Euclidean space), is an algebraic operation t...
["def min_dot(a, b):\n return sum(x * y for (x, y) in zip(sorted(a), sorted(b, reverse = True)))", "from numpy import dot\n\ndef min_dot(a, b):\n return dot(sorted(a), sorted(b, reverse=True))", "def min_dot(a, b):\n return sum(map(int.__mul__, sorted(a), sorted(b)[::-1]))", "def min_dot(a, b):\n a, b = sor...
{"fn_name": "min_dot", "inputs": [[[], []], [[1, 2, 3, 4, 5], [0, 1, 1, 1, 0]], [[1, 2, 3, 4, 5], [0, 0, 1, 1, -4]], [[1, 3, 5], [4, -2, 1]]], "outputs": [[0], [6], [-17], [-3]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,065
def min_dot(a, b):
0ed5dcf3a3de3ba6f2d7c9cec61083de
UNKNOWN
In Dark Souls, players level up trading souls for stats. 8 stats are upgradable this way: vitality, attunement, endurance, strength, dexterity, resistance, intelligence, and faith. Each level corresponds to adding one point to a stat of the player's choice. Also, there are 10 possible classes each having their own star...
["from itertools import accumulate\n\nCHARACTERS = {\n \"warrior\": (4, [11, 8, 12, 13, 13, 11, 9, 9]),\n \"knight\": (5, [14, 10, 10, 11, 11, 10, 9, 11]),\n \"wanderer\": (3, [10, 11, 10, 10, 14, 12, 11, 8]),\n \"thief\": (5, [9, 11, 9, 9, 15, 10, 12, 11]),\n \"bandit\": (4, [12, 8, 14, 14, 9, 11, 8, 10...
{"fn_name": "souls", "inputs": [["deprived", [11, 11, 11, 11, 11, 11, 11, 11]], ["pyromancer", [10, 12, 11, 12, 9, 12, 11, 8]], ["pyromancer", [16, 12, 11, 12, 9, 12, 10, 8]], ["pyromancer", [16, 12, 11, 12, 9, 12, 13, 8]], ["pyromancer", [16, 12, 11, 12, 9, 12, 13, 10]]], "outputs": [["Starting as a deprived, level 6 ...
INTRODUCTORY
PYTHON3
CODEWARS
10,270
def souls(character, build):
28940fc2be46fc7dd1431070de51235c
UNKNOWN
Given a non-negative number, return the next bigger polydivisible number, or an empty value like `null` or `Nothing`. A number is polydivisible if its first digit is cleanly divisible by `1`, its first two digits by `2`, its first three by `3`, and so on. There are finitely many polydivisible numbers.
["d, polydivisible, arr = 1, [], list(range(1, 10))\nwhile arr:\n d += 1\n polydivisible.extend(arr)\n arr = [n for x in arr for n in\n range(-(-x*10 // d) * d, (x+1) * 10, d)]\n\ndef next_num(n):\n from bisect import bisect\n idx = bisect(polydivisible, n)\n if idx < len(polydivisible):\n ...
{"fn_name": "next_num", "inputs": [[0], [10], [11], [1234], [123220], [998], [999], [1234567890], [3608528850368400786036724], [3608528850368400786036725]], "outputs": [[1], [12], [12], [1236], [123252], [1020], [1020], [1236004020], [3608528850368400786036725], [null]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,313
def next_num(n):
8fd75d81f80c8ef1f4fa25219fba2169
UNKNOWN
You are currently in the United States of America. The main currency here is known as the United States Dollar (USD). You are planning to travel to another country for vacation, so you make it today's goal to convert your USD (all bills, no cents) into the appropriate currency. This will help you be more prepared for w...
["def convert_my_dollars(usd, currency):\n curs = {\n 'Ar':478, 'Ba':82, 'Cr':6, 'Cz':21, 'Do':48, 'Ph':50,\n 'Uz':10000, 'Ha':64, 'Gu':7, 'Ta':32, 'Ro':4, 'Eg':18,\n 'Vi':22573, 'In':63, 'Ni':31, 'Ve':10, 'No':8, 'Ja':111,\n 'Sa':3, 'Th':32, 'Ke':102, 'So':1059}\n return f\"You now ha...
{"fn_name": "convert_my_dollars", "inputs": [[7, "Armenian Dram"], [322, "Armenian Dram"], [25, "Bangladeshi Taka"], [730, "Bangladeshi Taka"], [37, "Croatian Kuna"], [40, "Croatian Kuna"], [197, "Czech Koruna"], [333, "Czech Koruna"], [768, "Dominican Peso"], [983, "Dominican Peso"]], "outputs": [["You now have 3346 o...
INTRODUCTORY
PYTHON3
CODEWARS
2,072
def convert_my_dollars(usd, currency):
97376f6e5604c1db1e9128c18167294e
UNKNOWN
You are given an array with several `"even"` words, one `"odd"` word, and some numbers mixed in. Determine if any of the numbers in the array is the index of the `"odd"` word. If so, return `true`, otherwise `false`.
["def odd_ball(arr):\n return arr.index(\"odd\") in arr", "def odd_ball(xs):\n return xs.index('odd') in xs", "def odd_ball(arr):\n i = arr.index('odd')\n return i in arr", "def odd_ball(arr):\n g=arr.index('odd')\n if g in arr:\n return True\n else:\n return False", "#krishp\ndef odd...
{"fn_name": "odd_ball", "inputs": [[["even", 4, "even", 7, "even", 55, "even", 6, "even", 10, "odd", 3, "even"]], [["even", 4, "even", 7, "even", 55, "even", 6, "even", 9, "odd", 3, "even"]], [["even", 10, "odd", 2, "even"]]], "outputs": [[true], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
891
def odd_ball(arr):
6cbe04303e6e2a2ded9766dd64c71081
UNKNOWN
Jenny has written a function that returns a greeting for a user. However, she's in love with Johnny, and would like to greet him slightly different. She added a special case to her function, but she made a mistake. Can you help her?
["def greet(name):\n if name == \"Johnny\":\n return \"Hello, my love!\"\n return \"Hello, {name}!\".format(name=name)", "def greet(name):\n if name == \"Johnny\":\n return \"Hello, my love!\"\n else:\n return \"Hello, {name}!\".format(name=name)\n", "def greet(name):\n return \"Hell...
{"fn_name": "greet", "inputs": [["James"], ["Jane"], ["Jim"], ["Johnny"]], "outputs": [["Hello, James!"], ["Hello, Jane!"], ["Hello, Jim!"], ["Hello, my love!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
15,507
def greet(name):
584f75a994ae7d1213b69dcb4744cb34
UNKNOWN
You're re-designing a blog and the blog's posts have the following format for showing the date and time a post was made: *Weekday* *Month* *Day*, *time* e.g., Friday May 2, 7pm You're running out of screen real estate, and on some pages you want to display a shorter format, *Weekday* *Month* *Day* that omits the ti...
["def shorten_to_date(long_date):\n return long_date.split(',')[0]", "def shorten_to_date(long_date):\n return long_date[:long_date.index(',')]", "def shorten_to_date(long_date):\n return long_date[:long_date.rfind(',')]\n", "def shorten_to_date(long_date):\n index = long_date.index(',')\n new_string = l...
{"fn_name": "shorten_to_date", "inputs": [["Monday February 2, 8pm"], ["Tuesday May 29, 8pm"], ["Wed September 1, 3am"], ["Friday May 2, 9am"], ["Tuesday January 29, 10pm"]], "outputs": [["Monday February 2"], ["Tuesday May 29"], ["Wed September 1"], ["Friday May 2"], ["Tuesday January 29"]]}
INTRODUCTORY
PYTHON3
CODEWARS
13,432
def shorten_to_date(long_date):
18a8a664e9de60b69b5b1175c1e14cff
UNKNOWN
Your task is to write a function named `do_math` that receives a single argument. This argument is a string that contains multiple whitespace delimited numbers. Each number has a single alphabet letter somewhere within it. ``` Example : "24z6 1x23 y369 89a 900b" ``` As shown above, this alphabet letter can appear anyw...
["from functools import reduce\nfrom itertools import cycle\nfrom operator import add, truediv, mul, sub\n\n\ndef do_math(s):\n xs = sorted(s.split(), key=lambda x: next(c for c in x if c.isalpha()))\n xs = [int(''.join(filter(str.isdigit, x))) for x in xs]\n ops = cycle([add, sub, mul, truediv])\n return r...
{"fn_name": "do_math", "inputs": [["24z6 1z23 y369 89z 900b"], ["24z6 1x23 y369 89a 900b"], ["10a 90x 14b 78u 45a 7b 34y"], ["111a 222c 444y 777u 999a 888p"], ["1z 2t 3q 5x 6u 8a 7b"]], "outputs": [[1414], [1299], [60], [1459], [8]]}
INTRODUCTORY
PYTHON3
CODEWARS
15,054
def do_math(s) :
2adec0c9b9eaaabce56513b4504bbf5c
UNKNOWN
###Task: You have to write a function `pattern` which creates the following pattern (see examples) up to the desired number of rows. * If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string. * If any even number is passed as argument then the pattern should last upto the largest odd nu...
["def pattern(n):\n return '\\n'.join(str(i)*i for i in range(1,n+1,2))", "def pattern(n):\n string = \"\"\n a = n;\n if a % 2 == 0:\n a -= 1;\n for x in range (1, a + 1):\n if x % 2 != 0:\n string += str(x) * x\n \n if x != a:\n string += \"\...
{"fn_name": "pattern", "inputs": [[4], [1], [5], [0], [-25]], "outputs": [["1\n333"], ["1"], ["1\n333\n55555"], [""], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,072
def pattern(n):
8bca61b259743f3aa993627d2e7bbe25
UNKNOWN
Round any given number to the closest 0.5 step I.E. ``` solution(4.2) = 4 solution(4.3) = 4.5 solution(4.6) = 4.5 solution(4.8) = 5 ``` Round **up** if number is as close to previous and next 0.5 steps. ``` solution(4.75) == 5 ```
["import math\ndef solution(n):\n d=0\n if n - 0.25< math.floor(n):\n d=math.floor(n)\n elif n - 0.75< math.floor(n):\n d=math.floor(n)+0.5\n else:\n d=math.ceil(n)\n return d", "def solution(n):\n return round(n * 2) / 2 if n != 4.25 else 4.5", "def solution(n):\n #your code h...
{"fn_name": "solution", "inputs": [[4.2], [4.25], [4.4], [4.6], [4.75], [4.8], [4.5], [4.55], [4.74], [4.74999999999], [4.74999999991]], "outputs": [[4], [4.5], [4.5], [4.5], [5], [5], [4.5], [4.5], [4.5], [4.5], [4.5]]}
INTRODUCTORY
PYTHON3
CODEWARS
726
def solution(n):
e100ba6f943942793d7d8fd5792355bb
UNKNOWN
At the annual family gathering, the family likes to find the oldest living family member’s age and the youngest family member’s age and calculate the difference between them. You will be given an array of all the family members' ages, in any order. The ages will be given in whole numbers, so a baby of 5 months, will ...
["def difference_in_ages(ages):\n # your code here\n return (min(ages) , max(ages) , max(ages) - min(ages))", "def difference_in_ages(ages):\n x, y = min(ages), max(ages)\n return x, y, y-x", "def difference_in_ages(ages):\n age = sorted(ages)\n return (age[0], age[-1], (age[-1]-age[0]))", "def differ...
{"fn_name": "difference_in_ages", "inputs": [[[16, 22, 31, 44, 3, 38, 27, 41, 88]], [[5, 8, 72, 98, 41, 16, 55]], [[57, 99, 14, 32]], [[62, 0, 3, 77, 88, 102, 26, 44, 55]], [[2, 44, 34, 67, 88, 76, 31, 67]], [[46, 86, 33, 29, 87, 47, 28, 12, 1, 4, 78, 92]], [[66, 73, 88, 24, 36, 65, 5]], [[12, 76, 49, 37, 29, 17, 3, 65...
INTRODUCTORY
PYTHON3
CODEWARS
15,958
def difference_in_ages(ages):
f788a05b5a940c6450f693ba8f85204b
UNKNOWN
**Principal Diagonal** -- The principal diagonal in a matrix identifies those elements of the matrix running from North-West to South-East. **Secondary Diagonal** -- the secondary diagonal of a matrix identifies those elements of the matrix running from North-East to South-West. For example: ``` matrix: [...
["def diagonal(m):\n P = sum(m[i][i] for i in range(len(m)))\n S = sum(m[i][-i-1] for i in range(len(m)))\n if P > S:\n return \"Principal Diagonal win!\"\n elif S > P:\n return \"Secondary Diagonal win!\"\n else:\n return 'Draw!'\n", "def diagonal(matrix):\n sp, ss = map(sum, zip...
{"fn_name": "diagonal", "inputs": [[[[2, 2, 2], [4, 2, 6], [8, 8, 2]]], [[[7, 2, 2], [4, 2, 6], [1, 8, 1]]], [[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[1, 2, 2, 5, 1], [4, 1, 6, 1, 1], [1, 8, 5, 6, 2], [1, 5, 2, 1, 2], [1, 8, 2, 6, 1]]], [[[88, 2, 2, 5, 1, 1, 2, 2, 5, 1], [4, 1, 6, 1, 1, 1, 2, 2, 7, 1], [1, 8, 1, 6, 2, 1,...
INTRODUCTORY
PYTHON3
CODEWARS
2,638
def diagonal(matrix):
c8f254ff28f66d4b82e14422fcef530d
UNKNOWN
Write a function groupIn10s which takes any number of arguments, and groups them into sets of 10s and sorts each group in ascending order. The return value should be an array of arrays, so that numbers between 0-9 inclusive are in position 0 and numbers 10-19 are in position 1, etc. Here's an example of the required...
["from collections import defaultdict\ndef group_in_10s(*args):\n if not args: return []\n tens = defaultdict(list)\n for n in sorted(args): tens[n//10].append(n)\n return [tens.get(d, None) for d in range(max(tens) + 1)]", "from itertools import groupby\n\ndef group_in_10s(*args):\n if not args:\n ...
{"fn_name": "group_in_10s", "inputs": [[100]], "outputs": [[[null, null, null, null, null, null, null, null, null, null, [100]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,698
def group_in_10s(*args):
a766d1488d50c0015b5b50158a457ffd
UNKNOWN
Seven is a hungry number and its favourite food is number 9. Whenever it spots 9 through the hoops of 8, it eats it! Well, not anymore, because you are going to help the 9 by locating that particular sequence (7,8,9) in an array of digits and tell 7 to come after 9 instead. Seven "ate" nine, no more! (If 9 is not in d...
["import re\n\ndef hungry_seven(arr):\n ss,s = '', ''.join(map(str,arr))\n while ss!=s:\n ss,s = s,re.sub(r'(7+)(89)',r'\\2\\1', s)\n return list(map(int,s))", "def hungry_seven(arr):\n s = str(arr)\n if '7, 8, 9' in s:\n return hungry_seven(s.replace('7, 8, 9', '8, 9, 7'))\n return eval...
{"fn_name": "hungry_seven", "inputs": [[[7, 8, 9]], [[7, 7, 7, 8, 9]], [[8, 7, 8, 9, 8, 9, 7, 8]], [[8, 7, 8, 7, 9, 8]]], "outputs": [[[8, 9, 7]], [[8, 9, 7, 7, 7]], [[8, 8, 9, 8, 9, 7, 7, 8]], [[8, 7, 8, 7, 9, 8]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,889
def hungry_seven(arr):
6e76b7cd774b2ca973fec40ed9e43cc3
UNKNOWN
# Definition An **_element is leader_** *if it is greater than The Sum all the elements to its right side*. ____ # Task **_Given_** an *array/list [] of integers* , **_Find_** *all the **_LEADERS_** in the array*. ___ # Notes * **_Array/list_** size is *at least 3* . * **_Array/list's numbers_** Will be **_mixt...
["def array_leaders(numbers):\n return [n for (i,n) in enumerate(numbers) if n>sum(numbers[(i+1):])]\n", "def array_leaders(numbers):\n res = []\n s = 0\n for n in reversed(numbers):\n if n > s:\n res.append(n)\n s += n\n res.reverse()\n return res\n\narrayLeaders = array_lead...
{"fn_name": "array_leaders", "inputs": [[[1, 2, 3, 4, 0]], [[16, 17, 4, 3, 5, 2]], [[-1, -29, -26, -2]], [[-36, -12, -27]], [[5, 2]], [[0, -1, -29, 3, 2]]], "outputs": [[[4]], [[17, 5, 2]], [[-1]], [[-36, -12]], [[5, 2]], [[0, -1, 3, 2]]]}
INTRODUCTORY
PYTHON3
CODEWARS
14,588
def array_leaders(numbers):
791704e606724d9bfc0fc5b191fb8e29
UNKNOWN
Given an array of 4 integers ```[a,b,c,d]``` representing two points ```(a, b)``` and ```(c, d)```, return a string representation of the slope of the line joining these two points. For an undefined slope (division by 0), return ```undefined``` . Note that the "undefined" is case-sensitive. ``` a:x1 b:y1 ...
["def find_slope(points):\n x1, y1, x2, y2 = points\n if x2 - x1 == 0:\n return \"undefined\"\n return str((y2 - y1) // (x2 - x1))", "def find_slope(points):\n x1, y1, x2, y2 = points\n dx = x2 - x1\n dy = y2 - y1\n if dx != 0:\n return str(int(dy / dx))\n else:\n return 'un...
{"fn_name": "find_slope", "inputs": [[[12, -18, -15, -18]], [[3, -20, 5, 8]], [[17, -3, 17, 8]], [[1, -19, -2, -7]], [[19, 3, 20, 3]], [[6, -12, 15, -3]], [[15, -3, 15, -3]], [[9, 3, 19, -17]], [[3, 6, 4, 10]], [[2, 7, 4, -7]], [[1, 24, 2, 88]], [[4, 384, 8, 768]], [[4, 16, 4, 18]], [[7, 28, 9, 64]], [[18, -36, 12, 36]...
INTRODUCTORY
PYTHON3
CODEWARS
14,800
def find_slope(points):
3151b858042b0cda1ed709956e295c9c
UNKNOWN
In this Kata, you will be given a number and your task will be to return the nearest prime number. ```Haskell solve(4) = 3. The nearest primes are 3 and 5. If difference is equal, pick the lower one. solve(125) = 127 ``` We'll be testing for numbers up to `1E10`. `500` tests. More examples in test cases. Good lu...
["def solve(n):\n print('starting with {0}'.format(n), flush=True)\n\n def is_prime(p):\n if p % 2 == 0 :\n return False\n for x in range(3,int(p**.5)):\n if p % x == 0:\n return False\n return True\n #return not any([p%x==0 for x in range(3,int(p**...
{"fn_name": "solve", "inputs": [[3], [11], [4], [110], [1110], [3000], [35000], [350000], [3500000], [10000000000]], "outputs": [[3], [11], [3], [109], [1109], [2999], [34981], [350003], [3499999], [10000000019]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,058
def solve(n):
f562971f6873da9ea48ac2bc21043c2f
UNKNOWN
Johnny is a farmer and he annually holds a beet farmers convention "Drop the beet". Every year he takes photos of farmers handshaking. Johnny knows that no two farmers handshake more than once. He also knows that some of the possible handshake combinations may not happen. However, Johnny would like to know the minima...
["from math import ceil\n\ndef get_participants(h):\n return int(ceil(0.5 + (0.25 + 2 * h) ** 0.5))\n", "def get_participants(handshakes, n = 1):\n return get_participants(handshakes, n + 1) if (n * n - n)/2 < handshakes else n", "def get_participants(handshakes):\n from math import ceil\n \n \"\"\"\n ...
{"fn_name": "get_participants", "inputs": [[0], [1], [3], [6], [7]], "outputs": [[1], [2], [3], [4], [5]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,710
def get_participants(h):
5bef9b47acbb36e6bd464a53964225e4
UNKNOWN
This is a beginner friendly kata especially for UFC/MMA fans. It's a fight between the two legends: Conor McGregor vs George Saint Pierre in Madison Square Garden. Only one fighter will remain standing, and after the fight in an interview with Joe Rogan the winner will make his legendary statement. It's your job to r...
["statements = {\n 'george saint pierre': \"I am not impressed by your performance.\",\n 'conor mcgregor': \"I'd like to take this chance to apologize.. To absolutely NOBODY!\"\n}\n\ndef quote(fighter):\n return statements[fighter.lower()]", "h = {\n 'george saint pierre': \"I am not impressed by your perfo...
{"fn_name": "quote", "inputs": [["George Saint Pierre"], ["Conor McGregor"], ["george saint pierre"], ["conor mcgregor"]], "outputs": [["I am not impressed by your performance."], ["I'd like to take this chance to apologize.. To absolutely NOBODY!"], ["I am not impressed by your performance."], ["I'd like to take this ...
INTRODUCTORY
PYTHON3
CODEWARS
26,595
def quote(fighter):
4f859b591edf732384d30ebd0242aba1
UNKNOWN
# Task Let's say that `"g" is happy` in the given string, if there is another "g" immediately to the right or to the left of it. Find out if all "g"s in the given string are happy. # Example For `str = "gg0gg3gg0gg"`, the output should be `true`. For `str = "gog"`, the output should be `false`. # Input/Output...
["import re\n\ndef happy_g(s):\n return not re.search(r'(?<!g)g(?!g)',s)", "import re\n\ndef happy_g(s):\n return re.sub(\"g{2,}\", \"\", s).count(\"g\") < 1", "import re\n\ndef happy_g(s):\n return not re.search(r'(^|[^g])g([^g]|$)', s)", "import re\ndef happy_g(s):\n return bool(re.match(\"^(g{2,}|[^g])+$\"...
{"fn_name": "happy_g", "inputs": [["gg0gg3gg0gg"], ["gog"], ["ggg ggg g ggg"], ["A half of a half is a quarter."], ["good grief"], ["bigger is ggooder"], ["gggggggggg"]], "outputs": [[true], [false], [false], [true], [false], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
996
def happy_g(s):
d34011c65ca2547f709c243be30f4cb4
UNKNOWN
Create a program that will return whether an input value is a str, int, float, or bool. Return the name of the value. ### Examples - Input = 23 --> Output = int - Input = 2.3 --> Output = float - Input = "Hello" --> Output = str - Input = True --> Output = bool
["def types(x):\n return type(x).__name__", "def types(x):\n return str(type(x).__name__)", "def types(x):\n return str(type(x))[8:-2]", "types = lambda x: type(x).__name__", "types = lambda d: type(d).__name__", "def types(n):\n return type(n).__name__", "def types(x):\n return str(type(x)).split('\\'')...
{"fn_name": "types", "inputs": [[10], [9.7], ["Hello World!"], [[1, 2, 3, 4]], [1023], [true], ["True"], [{"name": "John", "age": 32}], [null], [3.141], [false], ["8.6"], ["*&^"], [4.5]], "outputs": [["int"], ["float"], ["str"], ["list"], ["int"], ["bool"], ["str"], ["dict"], ["NoneType"], ["float"], ["bool"], ["str"],...
INTRODUCTORY
PYTHON3
CODEWARS
325
def types(x):
4ab458cd93ad4308a5b0c6640de17289
UNKNOWN
# Introduction The first century spans from the **year 1** *up to* and **including the year 100**, **The second** - *from the year 101 up to and including the year 200*, etc. # Task : Given a year, return the century it is in.
["def century(year):\n return (year + 99) // 100", "import math\n\ndef century(year):\n return math.ceil(year / 100)", "def century(year):\n return (year / 100) if year % 100 == 0 else year // 100 + 1", "def century(year):\n if year%100==0:\n return year//100\n else:\n return year//100+1", ...
{"fn_name": "century", "inputs": [[1705], [1900], [1601], [2000], [356], [89]], "outputs": [[18], [19], [17], [20], [4], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
15,822
def century(year):
d987a5d1753dd4055e4df3a7a46e55c9
UNKNOWN
Your boss decided to save money by purchasing some cut-rate optical character recognition software for scanning in the text of old novels to your database. At first it seems to capture words okay, but you quickly notice that it throws in a lot of numbers at random places in the text. For example: ```python string_clea...
["def string_clean(s):\n return ''.join(x for x in s if not x.isdigit())", "import re\n\ndef string_clean(s):\n return re.sub(r'\\d', '', s)", "def string_clean(s):\n return \"\".join(c for c in s if not c.isdigit())", "string_clean = lambda s: __import__('re').sub(r'\\d', '', s)", "def string_clean(s):\n i...
{"fn_name": "string_clean", "inputs": [[""], ["! !"], ["123456789"], ["(E3at m2e2!!)"], ["Dsa32 cdsc34232 csa!!! 1I 4Am cool!"], ["A1 A1! AAA 3J4K5L@!!!"], ["Adgre2321 A1sad! A2A3A4 fv3fdv3J544K5L@"], ["Ad2dsad3ds21 A 1$$s122ad! A2A3Ae24 f44K5L@222222 "], ["33333Ad2dsad3ds21 A3333 1$$s122a!d! A2!A!3Ae$24 f2##222 "]...
INTRODUCTORY
PYTHON3
CODEWARS
14,103
def string_clean(s):
78dea5eac2c0b4be96e62d2c53fe5b19
UNKNOWN
You just got done with your set at the gym, and you are wondering how much weight you could lift if you did a single repetition. Thankfully, a few scholars have devised formulas for this purpose (from [Wikipedia](https://en.wikipedia.org/wiki/One-repetition_maximum)) : ### Epley ### McGlothin ### Lombardi Your ...
["def calculate_1RM(w, r):\n if r == 0: return 0\n if r == 1: return w\n \n return round(max([\n w * (1 + r / 30), # Epley\n 100 * w / (101.3 - 2.67123 * r), # McGlothin\n w * r**0.10 # Lombardi\n ]))", "def calculate_1RM(w, r):\n return (\n ...
{"fn_name": "calculate_1RM", "inputs": [[135, 20], [200, 8], [270, 2], [360, 1], [400, 0]], "outputs": [[282], [253], [289], [360], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,046
def calculate_1RM(w, r):
f6832e532d75b877cd98d340e8af6cab
UNKNOWN
Write ```python remove(text, what) ``` that takes in a string ```str```(```text``` in Python) and an object/hash/dict/Dictionary ```what``` and returns a string with the chars removed in ```what```. For example: ```python remove('this is a string',{'t':1, 'i':2}) == 'hs s a string' # remove from 'this is a string' the ...
["def remove(text, what):\n for char in what:\n text = text.replace(char,'',what[char])\n return text", "def remove(text, what):\n for c, n in what.items():\n text = text.replace(c, '', n)\n return text", "def remove(text, what):\n for char, count in list(what.items()):\n text = \"\".join(te...
{"fn_name": "remove", "inputs": [["this is a string", {"t": 1, "i": 2}], ["hello world", {"x": 5, "i": 2}], ["apples and bananas", {"a": 50, "n": 1}], ["a", {"a": 1, "n": 1}], ["codewars", {"c": 5, "o": 1, "d": 1, "e": 1, "w": 1, "z": 1, "a": 1, "r": 1, "s": 1}]], "outputs": [["hs s a string"], ["hello world"], ["pples...
INTRODUCTORY
PYTHON3
CODEWARS
1,001
def remove(text, what):
a92ae933be3d643030edc1b0fbd94fdf
UNKNOWN
Write a function getMean that takes as parameters an array (arr) and 2 integers (x and y). The function should return the mean between the mean of the the first x elements of the array and the mean of the last y elements of the array. The mean should be computed if both x and y have values higher than 1 but less or eq...
["def get_mean(arr,x,y):\n if 1 < x <= len(arr) and 1 < y <= len(arr):\n return (sum(arr[:x])/x+sum(arr[-y:])/y)/2\n return -1", "from operator import truediv\n\n\ndef mean(arr):\n return truediv(sum(arr), len(arr))\n\n\ndef get_mean(arr, x, y):\n if min(x, y) < 2 or max(x, y) > len(arr):\n ret...
{"fn_name": "get_mean", "inputs": [[[1, 3, 2, 4], 2, 3], [[1, 3, 2], 2, 2], [[1, 3, 2, 4], 1, 2], [[1, 3, 2, 4], 2, 8], [[1, -1, 2, -1], 2, 3]], "outputs": [[2.5], [2.25], [-1], [-1], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,871
def get_mean(arr,x,y):
dd47fa8d9060d0759c2de96f9c77b1a4
UNKNOWN
The internet is a very confounding place for some adults. Tom has just joined an online forum and is trying to fit in with all the teens and tweens. It seems like they're speaking in another language! Help Tom fit in by translating his well-formatted English into n00b language. The following rules should be observed: ...
["import re\nbase = \"too?|fore?|oo|be|are|you|please|people|really|have|know|s|[.,']\".split('|')\nnoob = \"2|4|00|b|r|u|plz|ppl|rly|haz|no|z|\".split('|')\n\ndef n00bify(text):\n for b, n in zip(base, noob):\n keep_casing = lambda m: n.upper() if m.group().isupper() else n\n text = re.sub(b, keep_cas...
{"fn_name": "n00bify", "inputs": [["Hi, how are you today?"], ["I think it would be nice if we could all get along."], ["Let's eat, Grandma!"], ["Woot woot woot woot woot woot!"], ["Hi, I can have cheeseburger?"], ["Sometimes I use ? in the middle of a sentence; is that ok?!"], ["Unto us a child is born."], ["What happ...
INTRODUCTORY
PYTHON3
CODEWARS
10,138
def n00bify(text):
e54ae278894a6e758eec1b459d59d7b9
UNKNOWN
A number `n` is called `prime happy` if there is at least one prime less than `n` and the `sum of all primes less than n` is evenly divisible by `n`. Write `isPrimeHappy(n)` which returns `true` if `n` is `prime happy` else `false`.
["def is_prime_happy(n):\n return n in [5, 25, 32, 71, 2745, 10623, 63201, 85868]", "is_prime_happy=lambda n:n>2and(2+sum(p*all(p%d for d in range(3,int(p**.5)+1,2))for p in range(3,n,2)))%n<1", "from itertools import compress\nimport numpy as np\n\ns = np.ones(100000)\ns[:2] = s[4::2] = 0\nfor i in range(3, int(len...
{"fn_name": "is_prime_happy", "inputs": [[5], [8], [25], [32], [2], [0]], "outputs": [[true], [false], [true], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,458
def is_prime_happy(n):
79de4c1f63699ee817dd757b1eaa977f
UNKNOWN
In this Kata, you will count the number of times the first string occurs in the second. ```Haskell solve("zaz","zazapulz") = 4 because they are ZAZapulz, ZAzapulZ, ZazApulZ, zaZApulZ ``` More examples in test cases. Good luck! Please also try [Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9...
["def solve(a, b):\n if len(a) is 1:\n return b.count(a)\n index = [x for x in range(len(b)-1) if b[x] is a[0]]\n return sum(solve(a[1:], b[x+1:]) for x in index)", "def solve(a, b, i=0, j=0):\n return i == len(a) or sum(solve(a,b,i+1,x+1) for x in range(j, len(b)-(len(a)-i-1)) if a[i] == b[x])", "fr...
{"fn_name": "solve", "inputs": [["zaz", "zazapulz"], ["rat", "ratatoulie"], ["kata", "katakatak"], ["code", "codeodecode"], ["kata", "kataxxxxkatak"], ["code", "cozzdezodeczzode"], ["zaaz", "zazaapulz"], ["defg", "dsedsfsgsg"], ["defg", "dvsxvevdvsvfvsvgvsvgg"]], "outputs": [[4], [3], [7], [11], [7], [11], [4], [2], [3...
INTRODUCTORY
PYTHON3
CODEWARS
3,182
def solve(a, b):
d012f951d77abb83919e7b93cb35bd9f
UNKNOWN
There was a test in your class and you passed it. Congratulations! But you're an ambitious person. You want to know if you're better than the average student in your class. You receive an array with your peers' test scores. Now calculate the average and compare your score! ~~~if-not:nasm,racket Return `True` if you'r...
["def better_than_average(class_points, your_points):\n return your_points > sum(class_points) / len(class_points)", "def better_than_average(class_points, your_points):\n average = (sum(class_points) + your_points) / (len(class_points) + 1)\n return your_points > average\n", "import statistics\ndef better_tha...
{"fn_name": "better_than_average", "inputs": [[[2, 3], 5], [[100, 40, 34, 57, 29, 72, 57, 88], 75], [[12, 23, 34, 45, 56, 67, 78, 89, 90], 69]], "outputs": [[true], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
18,179
def better_than_average(class_points, your_points):
81fe7c1f2f02d307eac1716435bc0ca4
UNKNOWN
## Description The task is described in the title: find the sum of all numbers with the same digits(permutations) **including** duplicates. However, due to the fact that this is a performance edition kata, `num` can go up to `10**10000`. That's a number with 10001 digits(at most). Be sure to use efficient algorithms a...
["from math import factorial as fact\n\ndef sum_arrangements(n):\n s = str(n)\n perms = fact(len(s)-1)\n coefAll = int('1'*len(s))\n return coefAll*perms*sum(map(int,s))", "def sum_arrangements(num):\n import math\n numLength = len(str(num))\n scaleFactor = int(\"1\"*numLength) * math.factorial(n...
{"fn_name": "sum_arrangements", "inputs": [[123], [1185]], "outputs": [[1332], [99990]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,988
def sum_arrangements(num):
37994de986aa9ec51e848c2005bed540
UNKNOWN
Introduction Mr. Safety loves numeric locks and his Nokia 3310. He locked almost everything in his house. He is so smart and he doesn't need to remember the combinations. He has an algorithm to generate new passcodes on his Nokia cell phone. Task Can you crack his numeric locks? Mr. Safety's treasures wait for ...
["def unlock(message): return message.lower().translate(message.maketrans(\"abcdefghijklmnopqrstuvwxyz\",\"22233344455566677778889999\"))", "from string import ascii_lowercase as alc\ndef unlock(message):\n return message.lower().translate(str.maketrans(alc, '22233344455566677778889999'))", "def unlock(message):\n ...
{"fn_name": "unlock", "inputs": [["Nokia"], ["Valut"], ["toilet"], ["waterheater"], ["birdhouse"]], "outputs": [["66542"], ["82588"], ["864538"], ["92837432837"], ["247346873"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,612
def unlock(message):
6416605f21611eee364310e6b99aad35
UNKNOWN
My friend John and I are members of the "Fat to Fit Club (FFC)". John is worried because each month a list with the weights of members is published and each month he is the last on the list which means he is the heaviest. I am the one who establishes the list so I told him: "Don't worry any more, I will modify the or...
["def order_weight(_str):\n return ' '.join(sorted(sorted(_str.split(' ')), key=lambda x: sum(int(c) for c in x)))", "def sum_string(s):\n sum = 0\n for digit in s:\n sum += int(digit)\n return sum\n\ndef order_weight(strng):\n # your code\n initial_list = sorted(strng.split())\n result = \"...
{"fn_name": "order_weight", "inputs": [["103 123 4444 99 2000"], ["2000 10003 1234000 44444444 9999 11 11 22 123"], [""], ["10003 1234000 44444444 9999 2000 123456789"], ["3 16 9 38 95 1131268 49455 347464 59544965313 496636983114762 85246814996697"], ["71899703 200 6 91 425 4 67407 7 96488 6 4 2 7 31064 9 7920 1 34608...
INTRODUCTORY
PYTHON3
CODEWARS
23,346
def order_weight(strng):
e64ef82b6ec9567fe1f82d3c6019f536
UNKNOWN
Write a simple function that takes polar coordinates (an angle in degrees and a radius) and returns the equivalent cartesian coordinates (rouded to 10 places). ``` For example: coordinates(90,1) => (0.0, 1.0) coordinates(45, 1) => (0.7071067812, 0.7071067812) ```
["from math import cos, sin, radians\n\ndef coordinates(deg, r, precision=10):\n x, y = r * cos(radians(deg)), r * sin(radians(deg))\n return round(x, precision), round(y, precision)", "from math import cos,sin,radians\n\ndef coordinates(d, r):\n convert = lambda x: round(r*x(radians(d)),10)\n return ( conv...
{"fn_name": "coordinates", "inputs": [[90, 1], [90, 2], [0, 1], [45, 1], [1090, 10000], [-270, 1]], "outputs": [[[0.0, 1.0]], [[0.0, 2.0]], [[1.0, 0.0]], [[0.7071067812, 0.7071067812]], [[9848.0775301221, 1736.4817766693]], [[0.0, 1.0]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,615
def coordinates(degrees, radius):
0054676402e2ed0433d622730a720296
UNKNOWN
Given few numbers, you need to print out the digits that are not being used. Example: ```python unused_digits(12, 34, 56, 78) # "09" unused_digits(2015, 8, 26) # "3479" ``` Note: - Result string should be sorted - The test case won't pass Integer with leading zero
["def unused_digits(*args):\n return \"\".join(number for number in \"0123456789\" if number not in str(args))", "def unused_digits(*l):\n digits_set = set(list(\"0123456789\"))\n test_set = set(\"\".join(str(i) for i in l))\n d = digits_set.difference(test_set)\n r = \"\".join(sorted(d))\n return r",...
{"fn_name": "unused_digits", "inputs": [[12, 34, 56, 78], [2015, 8, 26], [276, 575], [643], [864, 896, 744], [364, 500, 715, 730], [93, 10, 11, 40], [1, 11, 111, 1111, 11111], [9, 87, 654, 3210]], "outputs": [["09"], ["3479"], ["013489"], ["0125789"], ["01235"], ["289"], ["25678"], ["023456789"], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,651
def unused_digits(*args):
844fd24f8e2f54c35d07d94436f19d8a
UNKNOWN
Implement a function called makeAcronym that returns the first letters of each word in a passed in string. Make sure the letters returned are uppercase. If the value passed in is not a string return 'Not a string'. If the value passed in is a string which contains characters other than spaces and alphabet letters, r...
["def make_acronym(phrase):\n try:\n return ''.join(word[0].upper() if word.isalpha() else 0 for word in phrase.split())\n except AttributeError:\n return 'Not a string'\n except TypeError:\n return 'Not letters'", "from operator import itemgetter\n\ndef make_acronym(phrase):\n if type(...
{"fn_name": "make_acronym", "inputs": [["My aunt sally"], ["Please excuse my dear aunt Sally"], ["How much wood would a woodchuck chuck if a woodchuck could chuck wood"], ["Unique New York"], ["a42"], ["1111"], [64], [[]], [{}], [""]], "outputs": [["MAS"], ["PEMDAS"], ["HMWWAWCIAWCCW"], ["UNY"], ["Not letters"], ["Not ...
INTRODUCTORY
PYTHON3
CODEWARS
2,222
def make_acronym(phrase):
6827e25bb8615ee0884db682e96439f6
UNKNOWN
# Description: Replace the pair of exclamation marks and question marks to spaces(from the left to the right). A pair of exclamation marks and question marks must has the same number of "!" and "?". That is: "!" and "?" is a pair; "!!" and "??" is a pair; "!!!" and "???" is a pair; and so on.. # Examples ``` re...
["from itertools import groupby\n\ndef replace(s):\n queue, rle = {}, [[i, k, len(list(g))] for i, (k, g) in enumerate(groupby(s))]\n for i, k, l in reversed(rle):\n if l not in queue: queue[l] = {}\n queue[l].setdefault(k, []).append(i)\n for l in queue:\n while sum(map(bool, queue[l].val...
{"fn_name": "replace", "inputs": [["!!?!!?!!?!!?!!!??!!!??!!!??"], ["??!??!??!??!???!!???!!???!!"], ["?!!?!!?!!?!!!??!!!??!!!??!!!??!!!??"]], "outputs": [[" ? ? ?!!?!!! !!! !!! "], [" ! ! !??!??? ??? ??? "], ["? ? ? ?!!! !!! !!! !!!??!!!??"]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,857
def replace(s):