problem_id
int64
0
5k
question
stringlengths
50
14k
solutions
stringlengths
12
1.21M
input_output
stringlengths
0
23.6M
difficulty
stringclasses
3 values
url
stringlengths
36
108
starter_code
stringlengths
0
1.4k
4,200
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
https://www.codewars.com/kata/577e277c9fb2a5511c00001d
def vowel_shift(text, n):
4,201
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
https://www.codewars.com/kata/52de553ebb55d1fca3000371
def find_missing(sequence):
4,202
The Ulam sequence `U` is defined by `u0 = u`, `u1 = v`, with the general term `uN` for `N > 2` given by the least integer expressible uniquely as the sum of two distinct earlier terms. In other words, the next number is always the smallest, unique sum of any two previous terms. Complete the function that creates an Ul...
["from itertools import combinations\nfrom collections import defaultdict\n\ndef ulam_sequence(u0, u1, n):\n seq = [u0, u1, u0 + u1]\n \n while len(seq) < n:\n candidates = defaultdict(int)\n \n for a, b in combinations(seq, 2):\n candidates[a + b] += 1\n \n for nu...
{"fn_name": "ulam_sequence", "inputs": [[1, 2, 5], [3, 4, 5], [5, 6, 8]], "outputs": [[[1, 2, 3, 4, 6]], [[3, 4, 7, 10, 11]], [[5, 6, 11, 16, 17, 21, 23, 26]]]}
introductory
https://www.codewars.com/kata/5995ff073acba5fa3a00011d
def ulam_sequence(u0, u1, n):
4,203
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
https://www.codewars.com/kata/5434283682b0fdb0420000e6
def caffeineBuzz(n):
4,204
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
https://www.codewars.com/kata/58df8b4d010a9456140000c7
def palindrome(num):
4,205
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
https://www.codewars.com/kata/5748a883eb737cab000022a6
def cannons_ready(gunners):
4,206
# 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
https://www.codewars.com/kata/58c212c6f130b7c4660000a5
def three_details(n):
4,207
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
https://www.codewars.com/kata/59a8570b570190d313000037
def sum_cubes(n):
4,208
## 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
https://www.codewars.com/kata/5980d4e258a9f5891e000062
def ipsubnet2list(subnet):
4,209
# 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
https://www.codewars.com/kata/595db7e4c1b631ede30004c4
def largest_rect(histogram):
4,210
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
https://www.codewars.com/kata/586e1d458cb711f0a800033b
def process_data(data):
4,211
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
https://www.codewars.com/kata/56786a687e9a88d1cf00005d
def validate_word(word):
4,212
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
https://www.codewars.com/kata/5729c30961cecadc4f001878
def unite_unique(*args):
4,213
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
https://www.codewars.com/kata/57f12b4d5f2f22651c00256d
def array_info(x):
4,214
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
https://www.codewars.com/kata/5a3277005b2f00a11b0011c4
def spin_solve(sentence):
4,215
# 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
https://www.codewars.com/kata/58b635903e78b34958000056
def count_number(n, x):
4,216
Create a method (**JS**: function) `every` which returns every nth element of an array. ### Usage With no arguments, `array.every` it returns every element of the array. With one argument, `array.every(interval)` it returns every `interval`th element. With two arguments, `array.every(interval, start_index)` it re...
["def every(lst, n=1, start=0):\n return lst[start::n]", "#code here\ndef every(array, interval=None, start=None):\n return array[start::interval]", "def every(arr, n = 1, m = 0):\n return arr[m::n]\n", "#code here\ndef every(arr,n=1,s=0):\n return arr[s::n]", "def every(arr, n = 1, i = 0):\n return arr[...
{"fn_name": "every", "inputs": [[[null, null, null, null, null], 2]], "outputs": [[[null, null, null]]]}
introductory
https://www.codewars.com/kata/5753b987aeb792508d0010e2
def every(array, interval = 1, start_index = 0):
4,217
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
https://www.codewars.com/kata/5be7f613f59e0355ee00000f
def solve(a,b):
4,218
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
https://www.codewars.com/kata/5840946ea3d4c78e90000068
def game_winners(gryffindor, slytherin):
4,219
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
https://www.codewars.com/kata/57c1f22d8fbb9fd88700009b
def maxlen(l1, l2):
4,220
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
https://www.codewars.com/kata/57d0089e05c186ccb600035e
def equable_triangle(a,b,c):
4,221
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
https://www.codewars.com/kata/599c7f81ca4fa35314000140
def count_targets(n, sequence):
4,222
```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
https://www.codewars.com/kata/565f5825379664a26b00007c
def get_size(w,h,d):
4,223
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
https://www.codewars.com/kata/550498447451fbbd7600041c
def comp(array1, array2):
4,224
# 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
https://www.codewars.com/kata/5813d19765d81c592200001a
def dont_give_me_five(start,end):
4,225
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
https://www.codewars.com/kata/5b715fd11db5ce5912000019
def cup_and_balls(b, arr):
4,226
# 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
https://www.codewars.com/kata/563cf89eb4747c5fb100001b
def remove_smallest(numbers):
4,227
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
https://www.codewars.com/kata/5a981424373c2e479c00017f
def complexSum(arr):
4,228
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
https://www.codewars.com/kata/58df62fe95923f7a7f0000cc
def palindrome(num):
4,229
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
https://www.codewars.com/kata/58865bfb41e04464240000b0
def bits_war(numbers):
4,230
# 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
https://www.codewars.com/kata/58b8c94b7df3f116eb00005b
def reverse_letter(string):
4,231
- 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
https://www.codewars.com/kata/55de3f83e92c3e521a00002a
def a(n):
4,232
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
https://www.codewars.com/kata/574e4175ff5b0a554a00000b
def convert_to_mixed_numeral(parm):
4,233
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
https://www.codewars.com/kata/56cf0eb69e14db4897000b97
def goldbach(n):
4,234
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
https://www.codewars.com/kata/5ca6c0a2783dec001da025ee
def num_blocks(w, l, h):
4,235
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
https://www.codewars.com/kata/5297bf69649be865e6000922
def make_sentences(parts):
4,236
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
https://www.codewars.com/kata/586e0dc9b98de0064b000247
def calculate_grade(scores):
4,237
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
https://www.codewars.com/kata/59b0ab12cf3395ef68000081
def to12hourtime(t):
4,238
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
https://www.codewars.com/kata/5b0d67c1cb35dfa10b0022c7
def squares_needed(grains):
4,239
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
https://www.codewars.com/kata/59564f3bcc15b5591a00004a
def filter_even_length_words(words):
4,240
### 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
https://www.codewars.com/kata/52763db7cffbc6fe8c0007f8
def tongues(code):
4,241
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
https://www.codewars.com/kata/586f6741c66d18c22800010a
def sequence_sum(begin_number, end_number, step):
4,242
# 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
https://www.codewars.com/kata/58bcd7f2f6d3b11fce000025
def direction_in_grid(n,m):
4,243
Write function avg which calculates average of numbers in given list.
["def find_average(array):\n return sum(array) / len(array) if array else 0", "def find_average(array):\n return 0 if not array else sum(array) / len(array)\n", "def find_average(array):\n try:\n return sum(array) / len(array)\n except ZeroDivisionError:\n return 0", "def find_average(array):\...
{"fn_name": "find_average", "inputs": [[[1, 2, 3]]], "outputs": [[2]]}
introductory
https://www.codewars.com/kata/57a2013acf1fa5bfc4000921
def find_average(array):
4,244
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
https://www.codewars.com/kata/58e26b5d92d04c7a4f00020a
def palindrome(num):
4,245
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
https://www.codewars.com/kata/57eb936de1051801d500008a
def explode(arr):
4,246
# 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
https://www.codewars.com/kata/592fd8f752ee71ac7e00008a
def covfefe(s):
4,247
# 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
https://www.codewars.com/kata/589d74722cae97a7260000d9
def odd(s):
4,248
## 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
https://www.codewars.com/kata/5c7254fcaccda64d01907710
def solve(files):
4,249
# 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
https://www.codewars.com/kata/5632e12703e2037fa7000061
def base64_to_base10(string):
4,250
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
https://www.codewars.com/kata/587f0abdd8730aafd4000035
def sha256_cracker(hash, chars):
4,251
*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
https://www.codewars.com/kata/558f9f51e85b46e9fa000025
def difference_of_squares(n):
4,252
Write a function that merges two sorted arrays into a single one. The arrays only contain integers. Also, the final outcome must be sorted and not have any duplicate.
["def merge_arrays(a, b): \n return sorted(set(a + b))", "def merge_arrays(first, second): \n return sorted(set(first + second))", "def merge_arrays(first, second): \n working = []\n for e in first:\n if e not in working:\n working.append(e)\n for i in second:\n if i not in worki...
{"fn_name": "merge_arrays", "inputs": [[[1, 3, 5], [2, 4, 6]], [[2, 4, 8], [2, 4, 6]], [[1, 2, 3], []], [[], []]], "outputs": [[[1, 2, 3, 4, 5, 6]], [[2, 4, 6, 8]], [[1, 2, 3]], [[]]]}
introductory
https://www.codewars.com/kata/573f5c61e7752709df0005d2
def merge_arrays(first, second):
4,253
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
https://www.codewars.com/kata/59f61aada01431e8c200008d
def solve(n,k):
4,254
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
https://www.codewars.com/kata/5aa3af22ba1bb5209f000037
def solve(eq):
4,255
Write a function which converts the input string to uppercase. ~~~if:bf For BF all inputs end with \0, all inputs are lowercases and there is no space between. ~~~
["def make_upper_case(s): return s.upper()", "make_upper_case = str.upper", "def make_upper_case(strng):\n return strng.upper()", "def make_upper_case(s):\n return \"\".join(i.capitalize() for i in s)", "def make_upper_case(s):\n if isinstance(s,str):\n return s.upper()\n else:\n return", "def...
{"fn_name": "make_upper_case", "inputs": [["hello"], ["hello world"], ["hello world !"], ["heLlO wORLd !"], ["1,2,3 hello world!"]], "outputs": [["HELLO"], ["HELLO WORLD"], ["HELLO WORLD !"], ["HELLO WORLD !"], ["1,2,3 HELLO WORLD!"]]}
introductory
https://www.codewars.com/kata/57a0556c7cb1f31ab3000ad7
def make_upper_case(s):
4,256
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
https://www.codewars.com/kata/5ad1e412cc2be1dbfb000016
def insert_missing_letters(st):
4,257
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
https://www.codewars.com/kata/5419cf8939c5ef0d50000ef2
def calculate_probability(n):
4,258
## 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
https://www.codewars.com/kata/555eded1ad94b00403000071
def series_sum(n):
4,259
## Task: You have to write a function `pattern` which returns the following Pattern(See Examples) upto desired number of rows. * Note:`Returning` the pattern is not the same as `Printing` the pattern. ### Parameters: pattern( n , x ); ^ ^ ...
["def pattern(n, *x):\n if n < 1:\n return \"\"\n x = x[0] if x and x[0] > 0 else 1\n result = []\n for i in range(1, n + 1):\n line = \" \" * (i - 1) + str(i % 10) + \" \" * (n - i)\n result.append((line + line[::-1][1:]) + (line[1:] + line[::-1][1:]) * (x - 1))\n return \"\\n\".joi...
{"fn_name": "pattern", "inputs": [[3, 7], [15, 3], [10, -29], [5], [4, 2, 3, 5, 7, -8], [-3, 5], [-11, -1], [-9999999], [-25, -11, 9], [-25, 5, -9, 55, -8, -7, 8]], "outputs": [["1 1 1 1 1 1 1 1\n 2 2 2 2 2 2 2 2 2 2 2 2 2 2 \n 3 3 3 3 3 3 3 \n 2 2 2 2 2 2 2 2 2 2 2 2 2 2 \n1 1 1 1 1...
introductory
https://www.codewars.com/kata/5592e5d3ede9542ff0000057
def pattern(n, x=1, *args):
4,260
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
https://www.codewars.com/kata/56648a2e2c464b8c030000bf
def mark_spot(n):
4,261
# 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
https://www.codewars.com/kata/58a64b48586e9828df000109
def robot_walk(a):
4,262
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
https://www.codewars.com/kata/568c3498e48a0231d200001f
def calc_tip(p, r):
4,263
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
https://www.codewars.com/kata/5b049d57de4c7f6a6c0001d7
def apparently(string):
4,264
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
https://www.codewars.com/kata/579ef9607cb1f38113000100
def operation(a,b):
4,265
# 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
https://www.codewars.com/kata/59b7571bbf10a48c75000070
def tops(msg):
4,266
### 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
https://www.codewars.com/kata/5457ea88aed18536fc000a2c
def min_dot(a, b):
4,267
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
https://www.codewars.com/kata/592a5f9fa3df0a28730000e7
def souls(character, build):
4,268
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
https://www.codewars.com/kata/5e4a1a43698ef0002d2a1f73
def next_num(n):
4,269
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
https://www.codewars.com/kata/5a5c118380eba8a53d0000ce
def convert_my_dollars(usd, currency):
4,270
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
https://www.codewars.com/kata/5a941f4e1a60f6e8a70025fe
def odd_ball(arr):
4,271
We all know about Roman Numerals, and if not, here's a nice [introduction kata](http://www.codewars.com/kata/5580d8dc8e4ee9ffcb000050). And if you were anything like me, you 'knew' that the numerals were not used for zeroes or fractions; but not so! I learned something new today: the [Romans did use fractions](https:/...
["FRACTIONS = \" . : :. :: :.: S S. S: S:. S:: S:.:\".split(\" \")\nUNITS = \" I II III IV V VI VII VIII IX\" .split(\" \")\nTENS = \" X XX XXX XL L LX LXX LXXX XC\" .split(\" \")\nHUNDREDS = \" C CC CCC CD D DC DCC DCCC CM\" .split(\" \")\nTHOUSANDS = \" M MM MMM MMMM MMMMM\" .sp...
{"fn_name": "roman_fractions", "inputs": [[-12], [0, -1], [0, 12], [0], [1], [1, 5], [1, 9], [1632, 2], [5000], [5001], [0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11]], "outputs": [["NaR"], ["NaR"], ["NaR"], ["N"], ["I"], ["I:.:"], ["IS:."], ["MDCXXXII:"], ["MMMMM"], ["...
introductory
https://www.codewars.com/kata/55832eda1430b01275000059
def roman_fractions(integer, fraction=None):
4,272
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
https://www.codewars.com/kata/55225023e1be1ec8bc000390
def greet(name):
4,273
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
https://www.codewars.com/kata/56b0ff16d4aa33e5bb00008e
def shorten_to_date(long_date):
4,274
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
https://www.codewars.com/kata/5782dd86202c0e43410001f6
def do_math(s) :
4,275
###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
https://www.codewars.com/kata/5574940eae1cf7d520000076
def pattern(n):
4,276
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
https://www.codewars.com/kata/51f1342c76b586046800002a
def solution(n):
4,277
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
https://www.codewars.com/kata/5720a1cb65a504fdff0003e2
def difference_in_ages(ages):
4,278
**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
https://www.codewars.com/kata/5a8c1b06fd5777d4c00000dd
def diagonal(matrix):
4,279
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
https://www.codewars.com/kata/5694d22eb15d78fe8d00003a
def group_in_10s(*args):
4,280
Determine the **area** of the largest square that can fit inside a circle with radius *r*.
["def area_largest_square(r):\n return 2 * r ** 2", "def area_largest_square(r):\n return 2 * r * r", "def area_largest_square(r):\n return r*r*2", "area_largest_square = lambda r: r*(r+r)", "area_largest_square = lambda r: r*r*2", "def area_largest_square(r):\n return r ** 2 * 2", "area_largest_square = lam...
{"fn_name": "area_largest_square", "inputs": [[5], [7], [50]], "outputs": [[50], [98], [5000]]}
introductory
https://www.codewars.com/kata/5887a6fe0cfe64850800161c
def area_largest_square(r):
4,281
To introduce the problem think to my neighbor who drives a tanker truck. The level indicator is down and he is worried because he does not know if he will be able to make deliveries. We put the truck on a horizontal ground and measured the height of the liquid in the tank. Fortunately the tank is a perfect cylinder ...
["import math\ndef tankvol(h, d, vt):\n r = d/2.0\n if h == r: return vt/2 # is the tank half full?\n half = h>r # is it more than half full\n h = d-h if half else h # adjust h accordingly\n a = r-h # perpendicular intercept of the chord\n b = math.sqrt(r**2-...
{"fn_name": "tankvol", "inputs": [[5, 7, 3848], [2, 7, 3848], [2, 8, 5026], [4, 9, 6361], [3, 10, 7853], [3, 5, 1963], [4, 7, 3848], [0, 7, 3848], [7, 7, 3848], [2, 5, 1963], [2, 4, 1256], [4, 10, 7853], [3, 9, 6361], [2, 10, 7853], [5, 9, 6361], [5, 6, 2827], [1, 4, 1256]], "outputs": [[2940], [907], [982], [2731], [1...
introductory
https://www.codewars.com/kata/55f3da49e83ca1ddae0000ad
def tankvol(h, d, vt):
4,282
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
https://www.codewars.com/kata/59e61c577905df540000016b
def hungry_seven(arr):
4,283
Help Johnny! He can't make his code work! Easy Code Johnny is trying to make a function that adds the sum of two encoded strings, but he can't find the error in his code! Help him!
["def add(s1, s2):\n return sum(ord(x) for x in s1+s2)", "def add(s1, s2):\n s1 = s1.encode()\n s2 = s2.encode()\n return sum(s1+s2)", "def add(s1, s2):\n s1 = s1.encode()\n s2 = s2.encode()\n s1 = sum(list(s1))\n s2 = sum(list(s2))\n return s1+s2", "def add(s1, s2):\n return sum(map(ord, ...
{"fn_name": "add", "inputs": [["a", "b"]], "outputs": [[195]]}
introductory
https://www.codewars.com/kata/5848cd33c3689be0dc00175c
def add(s1, s2):
4,284
# 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
https://www.codewars.com/kata/5a651865fd56cb55760000e0
def array_leaders(numbers):
4,285
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
https://www.codewars.com/kata/55a75e2d0803fea18f00009d
def find_slope(points):
4,286
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
https://www.codewars.com/kata/5a9078e24a6b340b340000b8
def solve(n):
4,287
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
https://www.codewars.com/kata/5574835e3e404a0bed00001b
def get_participants(h):
4,288
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
https://www.codewars.com/kata/582dafb611d576b745000b74
def quote(fighter):
4,289
# 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
https://www.codewars.com/kata/58bcd27b7288983803000002
def happy_g(s):
4,290
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
https://www.codewars.com/kata/55a89dd69fdfb0d5ce0000ac
def types(x):
4,291
# 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
https://www.codewars.com/kata/5a3fe3dde1ce0e8ed6000097
def century(year):
4,292
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
https://www.codewars.com/kata/57e1e61ba396b3727c000251
def string_clean(s):
4,293
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
https://www.codewars.com/kata/595bbea8a930ac0b91000130
def calculate_1RM(w, r):
4,294
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
https://www.codewars.com/kata/564ab935de55a747d7000040
def remove(text, what):
4,295
# Definition **_Balanced number_** is the number that * **_The sum of_** all digits to the **_left of the middle_** digit(s) and the sum of all digits to the **_right of the middle_** digit(s) are **_equal_***. ____ # Task **_Given_** a number, **_Find if it is Balanced or not_** . ____ # Warm-up (Highly recommen...
["def balancedNum(n):\n s = str(n)\n l = (len(s)-1)//2\n same = len(s) < 3 or sum(map(int, s[:l])) == sum(map(int, s[-l:]))\n return \"Balanced\" if same else \"Not Balanced\"\n\nbalanced_num = balancedNum", "def balanced_num(number):\n number = [int(n) for n in str(number)]\n left, right = 0, 0\n \n...
{"fn_name": "balanced_num", "inputs": [[56239814]], "outputs": [["Balanced"]]}
introductory
https://www.codewars.com/kata/5a4e3782880385ba68000018
def balanced_num(number):
4,296
Write a program that outputs the `n` largest elements from a list. Example: ```python largest(2, [7,6,5,4,3,2,1]) # => [6,7] ```
["def largest(n, xs):\n \"Find the n highest elements in a list\"\n \n return sorted(xs)[-n:];", "def largest(n,xs):\n import heapq\n return heapq.nlargest(n,xs)[::-1]", "def largest(n,xs):\n xs.sort()\n return xs[-n:]", "def largest(n,xs):\n list = sorted(xs)\n return list[-n:]", "import heapq\n\ndef largest(...
{"fn_name": "largest", "inputs": [[2, [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]]], "outputs": [[[9, 10]]]}
introductory
https://www.codewars.com/kata/53d32bea2f2a21f666000256
def largest(n,xs):
4,297
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
https://www.codewars.com/kata/583df40bf30065fa9900010c
def get_mean(arr,x,y):
4,298
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
https://www.codewars.com/kata/552ec968fcd1975e8100005a
def n00bify(text):
4,299
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
https://www.codewars.com/kata/59b2ae6b1b5ca3ca240000c1
def is_prime_happy(n):