problem_id
int64
2.36k
5k
question
stringlengths
52
14k
solutions
stringlengths
79
675k
input_output
stringlengths
37
505k
difficulty
stringclasses
1 value
url
stringlengths
36
94
starter_code
stringlengths
0
952
2,661
A marine themed rival site to Codewars has started. Codwars is advertising their website all over the internet using subdomains to hide or obfuscate their domain to trick people into clicking on their site. Your task is to write a function that accepts a URL as a string and determines if it would result in an http req...
["import re\n\ndef find_codwars(url):\n return bool(re.match(r''\n '^(https?://)?' # http(s)://\n '([a-z]+\\.)*' # subdomains\n 'codwars\\.com' # codwars.com\n '([/?].*)?$' # directories or querystrings\n , url))", "import re\ndef find_codwars(url):\n domain = url....
{"fn_name": "find_codwars", "inputs": [["codwars.com"], ["http://codwars.com"], ["http://kcodwars.com"], ["https://www.codwars.com"], ["https://www.codwars.com/kata"], ["codewars.com.codwars.com"], ["https://www.codwars.com/kata?this=is&a=querystring"], ["https://this.is.an.unneccesarily.long.subdomain.codwars.com/kata...
introductory
https://www.codewars.com/kata/5967a67c8b0fc0093e000062
def find_codwars(url):
2,662
Pete and his mate Phil are out in the countryside shooting clay pigeons with a shotgun - amazing fun. They decide to have a competition. 3 rounds, 2 shots each. Winner is the one with the most hits. Some of the clays have something attached to create lots of smoke when hit, guarenteed by the packaging to generate 'r...
["def shoot(results):\n pete = phil = 0\n \n for shots, double in results:\n pete += shots[\"P1\"].count(\"X\") * (1 + double)\n phil += shots[\"P2\"].count(\"X\") * (1 + double)\n \n return \"Pete Wins!\" if pete > phil else \"Phil Wins!\" if phil > pete else \"Draw!\"", "def shoot(results...
{"fn_name": "shoot", "inputs": [[[[{"P1": "XX", "P2": "XO"}, true], [{"P1": "OX", "P2": "OO"}, false], [{"P1": "XX", "P2": "OX"}, true]]], [[[{"P1": "XX", "P2": "XO"}, false], [{"P1": "OX", "P2": "XX"}, false], [{"P1": "OO", "P2": "XX"}, true]]], [[[{"P1": "OO", "P2": "XX"}, false], [{"P1": "OO", "P2": "XX"}, false], [...
introductory
https://www.codewars.com/kata/57fa9bc99610ce206f000330
def shoot(results):
2,663
What adds up =========== Given three arrays of integers your task is to create an algorithm that finds the numbers in the first two arrays whose sum is equal to any number in the third. The return value should be an array containing the values from the argument arrays that adds up. The sort order of the resulting arra...
["def addsup(a1, a2, a3):\n return [[x,y,x+y] for x in a1 for y in a2 if x+y in a3]", "from itertools import product\n\ndef addsup(a1, a2, a3):\n goal = set(a3).__contains__\n return [[x, y, x+y] for x,y in product(a1, a2) if goal(x+y)]", "def addsup(a, b, t):\n t = set(t)\n return [[m, n, m+n] for m in a ...
{"fn_name": "addsup", "inputs": [[[], [1, 2, 3], [5, 2, 3]], [[1, 3, 4], [], [4, 6, 5]], [[1, 2, 3], [4, 5, 6], []]], "outputs": [[[]], [[]], [[]]]}
introductory
https://www.codewars.com/kata/53cce49fdf221844de0004bd
def addsup(a1, a2, a3):
2,664
In this Kata, you will check if it is possible to convert a string to a palindrome by changing one character. For instance: ```Haskell solve ("abbx") = True, because we can convert 'x' to 'a' and get a palindrome. solve ("abba") = False, because we cannot get a palindrome by changing any character. solve ("abcba") ...
["def solve(s):\n v = sum(s[i] != s[-1-i] for i in range((len(s))//2) )\n return v == 1 or not v and len(s)%2", "solve=lambda s:any(s[:y]+c+s[y+1:]==(s[:y]+c+s[y+1:])[::-1]!=s for y,x in enumerate(s)for c in set(s))", "def solve(s):\n d = sum(1 for i in range(len(s) // 2) if s[i] != s[-i-1])\n return d == 1...
{"fn_name": "solve", "inputs": [["abba"], ["abbaa"], ["abbx"], ["aa"], ["ab"], ["abcba"]], "outputs": [[false], [true], [true], [false], [true], [true]]}
introductory
https://www.codewars.com/kata/5a66ea69e6be38219f000110
def solve(s):
2,665
Your job at E-Corp is both boring and difficult. It isn't made any easier by the fact that everyone constantly wants to have a meeting with you, and that the meeting rooms are always taken! In this kata, you will be given an array. Each value represents a meeting room. Your job? Find the **first** empty one and return...
["def meeting(rooms):\n try:\n return rooms.index('O')\n except ValueError:\n return 'None available!'\n", "def meeting(rooms):\n return rooms.index(\"O\") if \"O\" in rooms else \"None available!\"", "def meeting(rooms):\n return next((i for i, r in enumerate(rooms) if r == 'O'), 'None availa...
{"fn_name": "meeting", "inputs": [[["X", "O", "X"]], [["O", "X", "X", "X", "X"]], [["X", "X", "O", "X", "X"]], [["X"]]], "outputs": [[1], [0], [2], ["None available!"]]}
introductory
https://www.codewars.com/kata/57f604a21bd4fe771b00009c
def meeting(rooms):
2,666
Kevin is noticing his space run out! Write a function that removes the spaces from the values and returns an array showing the space decreasing. For example, running this function on the array ['i', 'have','no','space'] would produce ['i','ihave','ihaveno','ihavenospace'].
["from itertools import accumulate\n\ndef spacey(a):\n return list(accumulate(a))", "def spacey(array):\n return [''.join(array[:i+1]) for i in range(len(array))]", "def spacey(array):\n strr = ''\n out = []\n for el in array:\n strr += str(el)\n out.append(strr)\n return out", "def spac...
{"fn_name": "spacey", "inputs": [[["kevin", "has", "no", "space"]], [["this", "cheese", "has", "no", "holes"]]], "outputs": [[["kevin", "kevinhas", "kevinhasno", "kevinhasnospace"]], [["this", "thischeese", "thischeesehas", "thischeesehasno", "thischeesehasnoholes"]]]}
introductory
https://www.codewars.com/kata/56576f82ab83ee8268000059
def spacey(array):
2,667
Will you make it? You were camping with your friends far away from home, but when it's time to go back, you realize that your fuel is running out and the nearest pump is ```50``` miles away! You know that on average, your car runs on about ```25``` miles per gallon. There are ```2``` gallons left. Considering these fa...
["'''\nVasyl Zakharuk\nPython Core 355\nCodewars Kata: Will you make it?\n''' \ndef zero_fuel(distance_to_pump, mpg, fuel_left):\n if fuel_left >= distance_to_pump / mpg:\n print(\"We got to the pump\")\n return True\n else:\n print(\"We pushed the car to the pump(((\")\n return False\...
{"fn_name": "zero_fuel", "inputs": [[50, 25, 2], [60, 30, 3], [70, 25, 1], [100, 25, 3]], "outputs": [[true], [true], [false], [false]]}
introductory
https://www.codewars.com/kata/5861d28f124b35723e00005e
def zero_fuel(distance_to_pump, mpg, fuel_left):
2,668
Step through my `green glass door`. You can take the `moon`, but not the `sun`. You can take your `slippers`, but not your `sandals`. You can go through `yelling`, but not `shouting`. You can't run through `fast`, but you can run with `speed`. You can take a `sheet`, but not your `blanket`. You can wear your `gla...
["def step_through_with(s):\n return any(m == n for m, n in zip(s, s[1:]))", "import re\ndef step_through_with(s): return re.compile(r'([a-z])\\1', re.I).search(s) is not None", "def step_through_with(s):\n prev = '' \n for letter in s:\n if prev == letter:\n return True\n prev = le...
{"fn_name": "step_through_with", "inputs": [["moon"], ["test"], ["glasses"], ["airplane"], ["free"], ["branch"], ["aardvark"]], "outputs": [[true], [false], [true], [false], [true], [false], [true]]}
introductory
https://www.codewars.com/kata/5642bf07a586135a6f000004
def step_through_with(s):
2,669
Consider the following series: `1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, 108, 116, 122` It is generated as follows: * For single digit integers, add the number to itself to get the next element. * For other integers, multiply all the non-zero digits and add the result to the original number to get the next elem...
["from operator import mul\nfrom functools import reduce\n\ndef genSequence(n):\n yield n\n while True:\n n += reduce(mul, [int(d) for d in str(n) if d != '0']) if n > 9 else n\n yield n\n\ndef extract(seq, v):\n return sorted(seq).index(v)\n\ndef convergence(n):\n gen1, genN = genSequence(1),...
{"fn_name": "convergence", "inputs": [[3], [5], [10], [15], [500], [5000]], "outputs": [[5], [6], [5], [2], [29], [283]]}
introductory
https://www.codewars.com/kata/59971e64bfccc70748000068
def convergence(n):
2,670
# Task Get the digits sum of `n`th number from the [Look-and-Say sequence](http://en.wikipedia.org/wiki/Look-and-say_sequence)(1-based). `1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211, ...` # Input/Output `[input]` integer `n` `n`th number in the sequence to get where `1 <= n <= 55` and `n=1 is "1"`. [out...
["def look_and_say_and_sum(N):\n l=[1]\n for n in range(N-1):\n result = [1,l[0]]\n for i in range(1,len(l)):\n if l[i]==result[-1]:\n result[-2] += 1\n else:\n result += [1,l[i]] \n l=result\n return sum(l)\n", "def look_and_say_and_sum(...
{"fn_name": "look_and_say_and_sum", "inputs": [[1], [2], [3], [4], [5]], "outputs": [[1], [2], [3], [5], [8]]}
introductory
https://www.codewars.com/kata/5922828c80a27c049c000078
def look_and_say_and_sum(n):
2,671
You will be given a string (x) featuring a cat 'C', a dog 'D' and a mouse 'm'. The rest of the string will be made up of '.'. You need to find out if the cat can catch the mouse from it's current position. The cat can jump (j) characters. Also, the cat cannot jump over the dog. So: if j = 5: ```..C.....m.``` ret...
["def cat_mouse(x,j):\n d, c, m = x.find('D'), x.find('C'), x.find('m')\n if -1 in [d, c, m]:\n return 'boring without all three'\n if abs(c - m) <= j:\n return 'Protected!' if c < d < m or m < d < c else 'Caught!' \n return 'Escaped!'", "def cat_mouse(x, j):\n try:\n cat, dog, mouse...
{"fn_name": "cat_mouse", "inputs": [["..D.....C.m", 2], ["............C.............D..m...", 8], ["m.C...", 5], [".CD......m.", 10], [".CD......m.", 1]], "outputs": [["Caught!"], ["Escaped!"], ["boring without all three"], ["Protected!"], ["Escaped!"]]}
introductory
https://www.codewars.com/kata/57ee2a1b7b45efcf700001bf
def cat_mouse(x,j):
2,672
You're playing a game with a friend involving a bag of marbles. In the bag are ten marbles: * 1 smooth red marble * 4 bumpy red marbles * 2 bumpy yellow marbles * 1 smooth yellow marble * 1 bumpy green marble * 1 smooth green marble You can see that the probability of picking a smooth red marble from the bag is `1 / ...
["def color_probability(color, texture):\n marbles = {\"smooth\": {\"red\": 1, \"yellow\": 1, \"green\": 1, \"total\": 3}, \"bumpy\": {\"red\": 4, \"yellow\": 2, \"green\": 1, \"total\": 7}}\n return \"{}\".format(marbles[texture][color] / marbles[texture][\"total\"])[:4]", "def color_probability(color, texture):...
{"fn_name": "color_probability", "inputs": [["red", "bumpy"], ["green", "bumpy"], ["yellow", "smooth"], ["red", "smooth"], ["green", "smooth"], ["yellow", "bumpy"]], "outputs": [["0.57"], ["0.14"], ["0.33"], ["0.33"], ["0.33"], ["0.28"]]}
introductory
https://www.codewars.com/kata/5864cdc483f7e6df980001c8
def color_probability(color, texture):
2,673
Passer ratings are the generally accepted standard for evaluating NFL quarterbacks. I knew a rating of 100 is pretty good, but never knew what makes up the rating. So out of curiosity I took a look at the wikipedia page and had an idea or my first kata: https://en.wikipedia.org/wiki/Passer_rating ## Formula There are...
["def passer_rating(att, yds, comp, td, ints):\n limit = lambda x: min(max(x, 0), 2.375)\n \n att = float(att) # for python 2 compatibility\n \n A = ((comp / att) - .3) * 5\n B = ((yds / att) - 3) * .25\n C = (td / att) * 20\n D = 2.375 - ((ints / att) * 25)\n \n A, B, C, D = map(limit,...
{"fn_name": "passer_rating", "inputs": [[432, 3554, 291, 28, 2], [5, 76, 4, 1, 0], [48, 192, 19, 2, 3], [1, 2, 1, 1, 0], [34, 172, 20, 1, 1], [10, 17, 2, 0, 1]], "outputs": [[112.2], [158.3], [39.6], [118.8], [69.7], [0.0]]}
introductory
https://www.codewars.com/kata/59952e17f902df0e5f000078
def passer_rating(att, yds, comp, td, ints):
2,674
You will be given a vector of strings. You must sort it alphabetically (case-sensitive, and based on the ASCII values of the chars) and then return the first value. The returned value must be a string, and have `"***"` between each of its letters. You should not remove or add elements from/to the array.
["def two_sort(lst):\n return '***'.join(min(lst))", "def two_sort(array):\n return '***'.join(min(array))", "def two_sort(arr):\n return '***'.join(sorted(arr)[0])", "def two_sort(a):\n a = sorted(a)\n result = \"***\".join(a[0])\n return result", "def two_sort(array):\n return '***'.join(sorted(a...
{"fn_name": "two_sort", "inputs": [[["bitcoin", "take", "over", "the", "world", "maybe", "who", "knows", "perhaps"]], [["turns", "out", "random", "test", "cases", "are", "easier", "than", "writing", "out", "basic", "ones"]], [["lets", "talk", "about", "javascript", "the", "best", "language"]], [["i", "want", "to", "tra...
introductory
https://www.codewars.com/kata/57cfdf34902f6ba3d300001e
def two_sort(array):
2,675
Help a fruit packer sort out the bad apples. There are 7 varieties of apples, all packaged as pairs and stacked in a fruit box. Some of the apples are spoiled. The fruit packer will have to make sure the spoiled apples are either removed from the fruit box or replaced. Below is the breakdown: Apple varieties are rep...
["def bad_apples(apples):\n lst, notFull = [], []\n for a,b in apples:\n if (bool(a) ^ bool(b)) and notFull: lst[notFull.pop()].append(a or b) # One bad and partially full box already present: fill it (as second element)\n elif a and b: lst.append([a,b]) ...
{"fn_name": "bad_apples", "inputs": [[[]], [[[0, 0], [0, 0]]], [[[0, 0], [0, 0], [0, 1], [0, 0], [0, 0]]], [[[0, 0], [3, 7], [0, 5]]], [[[1, 3], [7, 6], [7, 2], [1, 3], [2, 3], [4, 5], [7, 6]]], [[[1, 2], [6, 1], [5, 2], [6, 3], [1, 4], [2, 5], [7, 6], [0, 1]]], [[[0, 0], [1, 0], [0, 2], [3, 0], [4, 0], [0, 5], [0, 6],...
introductory
https://www.codewars.com/kata/59766edb9bfe7cd5b000006e
def bad_apples(apples):
2,676
In a far away country called AlgoLandia, there are `N` islands numbered `1` to `N`. Each island is denoted by `k[i]`. King Algolas, king of AlgoLandia, built `N - 1` bridges in the country. A bridge is built between islands `k[i]` and `k[i+1]`. Bridges are two-ways and are expensive to build. The problem is that there...
["from itertools import groupby\n\ndef find_needed_guards(islands):\n return sum(sum(1 for _ in g)>>1 for k,g in groupby(islands) if not k)", "def find_needed_guards(k):\n b = ''.join('1' if g else '0' for g in k)\n return sum(len(ng) // 2 for ng in b.split(\"1\"))", "def find_needed_guards(k):\n \n prev...
{"fn_name": "find_needed_guards", "inputs": [[[true, true, false, true, false]], [[false, false, true, false, false]], [[false, false, false, false, false]], [[false, false, false, false, false, false]], [[false, false]], [[true, false]], [[false, false, false, true, false, false, false, true]], [[false, false, true, f...
introductory
https://www.codewars.com/kata/5d0d1c14c843440026d7958e
def find_needed_guards(k):
2,677
# Background My TV remote control has arrow buttons and an `OK` button. I can use these to move a "cursor" on a logical screen keyboard to type words... # Keyboard The screen "keyboard" layout looks like this #tvkb { width : 400px; border: 5px solid gray; border-collapse: collapse; } #tvkb td { ...
["import re\n\nH, W = 6, 8\nKEYBOARD = \"abcde123fghij456klmno789pqrst.@0uvwxyz_/* \"\nMAP = {c: (i//W, i%W) for i,c in enumerate(KEYBOARD)}\n\n\ndef manhattan(*pts):\n dxy = [abs(z2-z1) for z1,z2 in zip(*pts)]\n return 1 + sum( min(dz, Z-dz) for dz,Z in zip(dxy, (H,W)) )\n\ndef toggle(m):\n ups, end ...
{"fn_name": "tv_remote", "inputs": [["Code Wars"], ["does"], ["your"], ["solution"], ["work"], ["for"], ["these"], ["words"], ["DOES"], ["YOUR"], ["SOLUTION"], ["WORK"], ["FOR"], ["THESE"], ["WORDS"], ["Does"], ["Your"], ["Solution"], ["Work"], ["For"], ["These"], ["Words"], ["A"], ["AADVARKS"], ["A/A/A/A/"], ["1234567...
introductory
https://www.codewars.com/kata/5b2c2c95b6989da552000120
def tv_remote(words):
2,678
Imagine if there were no order of operations. Instead, you would do the problem from left to right. For example, the equation `$a +b *c /d$` would become `$(((a+b)*c)//d)$` (`Math.floor(((a+b)*c)/d)` in JS). Return `None`/`null` (depending on your language) if the equation is `""`. ### Task: Given an equation with a...
["def no_order(equation):\n equation = equation.replace(' ', '')\n equation = equation.replace('+', ')+')\n equation = equation.replace('-', ')-')\n equation = equation.replace('*', ')*')\n equation = equation.replace('/', ')//')\n equation = equation.replace('%', ')%')\n equation = equation.replac...
{"fn_name": "no_order", "inputs": [["2 + 3- 4*1 ^ 3"], ["7 * 3 - 3/ 10 0"], ["1 20% 0 + 9"], ["6 9* 2+6 / 0"]], "outputs": [[1], [0], [null], [null]]}
introductory
https://www.codewars.com/kata/5e9df3a0a758c80033cefca1
def no_order(equation):
2,679
# Introduction Hamsters are rodents belonging to the subfamily Cricetinae. The subfamily contains about 25 species, classified in six or seven genera. They have become established as popular small house pets, and, partly because they are easy to breed in captivity, hamsters are often used as laboratory animals. # T...
["def hamster_me(code, message):\n code, dct = sorted(set(code)), {}\n for c1,c2 in zip(code, code[1:] + [chr(ord(\"z\") + ord(code[0]) - ord(\"a\"))]):\n for n in range(ord(c1), ord(c2)+1):\n dct[chr( (n-97)%26 + 97 )] = c1 + str(n-ord(c1)+1)\n return ''.join(dct[c] for c in message)", "def ...
{"fn_name": "hamster_me", "inputs": [["hamster", "hamster"], ["hamster", "helpme"], ["hmster", "hamster"], ["hhhhammmstteree", "hamster"], ["f", "abcdefghijklmnopqrstuvwxyz"]], "outputs": [["h1a1m1s1t1e1r1"], ["h1e1h5m4m1e1"], ["h1t8m1s1t1e1r1"], ["h1a1m1s1t1e1r1"], ["f22f23f24f25f26f1f2f3f4f5f6f7f8f9f10f11f12f13f14f15...
introductory
https://www.codewars.com/kata/595ddfe2fc339d8a7d000089
def hamster_me(code, message):
2,680
Two tortoises named ***A*** and ***B*** must run a race. ***A*** starts with an average speed of ```720 feet per hour```. Young ***B*** knows she runs faster than ***A***, and furthermore has not finished her cabbage. When she starts, at last, she can see that ***A*** has a `70 feet lead` but ***B***'s speed is `850 f...
["import math\n\ndef race(v1, v2, g):\n if v2 < v1: return None\n seconds = 0.1\n while (v1/3600) * seconds + g >= (v2/3600) * seconds:\n seconds += 0.05\n hours = seconds / 3600\n hoursRest = seconds % 3600\n minutes = hoursRest / 60\n seconds = hoursRest % 60\n return [math.floor(hours)...
{"fn_name": "race", "inputs": [[720, 850, 70], [80, 91, 37], [80, 100, 40], [720, 850, 37], [720, 850, 370], [120, 850, 37], [820, 850, 550], [820, 81, 550]], "outputs": [[[0, 32, 18]], [[3, 21, 49]], [[2, 0, 0]], [[0, 17, 4]], [[2, 50, 46]], [[0, 3, 2]], [[18, 20, 0]], [null]]}
introductory
https://www.codewars.com/kata/55e2adece53b4cdcb900006c
def race(v1, v2, g):
2,681
You drop a ball from a given height. After each bounce, the ball returns to some fixed proportion of its previous height. If the ball bounces to height 1 or less, we consider it to have stopped bouncing. Return the number of bounces it takes for the ball to stop moving. ``` bouncingBall(initialHeight, bouncingProporti...
["import math\n\ndef bouncing_ball(initial, proportion):\n return math.ceil(math.log(initial, 1/proportion))", "def bouncing_ball(initial, proportion):\n count = 0\n while initial > 1:\n initial = initial * proportion\n count = count + 1\n return count", "def bouncing_ball(i, p , n = 0):\n ...
{"fn_name": "bouncing_ball", "inputs": [[2, 0.5], [4, 0.5], [10, 0.1], [100, 0.1], [9, 0.3], [30, 0.3]], "outputs": [[1], [2], [1], [2], [2], [3]]}
introductory
https://www.codewars.com/kata/5a40c250c5e284a76400008c
def bouncing_ball(initial, proportion):
2,682
Given a set of elements (integers or string characters) that may occur more than once, we need to know the amount of subsets that none of their values have repetitions. Let's see with an example: ``` set numbers = {1, 2, 3, 4} ``` The subsets are: ``` {{1}, {2}, {3}, {4}, {1,2}, {1,3}, {1,4}, {2,3}, {2,4},{3,4}, {1,...
["def est_subsets(arr):\n return 2**len(set(arr)) - 1", "est_subsets = lambda a: 2 ** len(set(a)) - 1", "est_subsets=lambda n:2 ** len(set(n)) - 1", "from math import factorial\nfrom collections import Counter\n\ndef C(n, r):\n return factorial(n) // factorial(r) // factorial(n-r)\n \ndef est_subsets(arr):\n ...
{"fn_name": "est_subsets", "inputs": [[[1, 2, 3, 4]], [["a", "b", "c", "d", "d"]]], "outputs": [[15], [15]]}
introductory
https://www.codewars.com/kata/584703d76f6cf6ffc6000275
def est_subsets(arr):
2,683
It's tricky keeping track of who is owed what when spending money in a group. Write a function to balance the books. * The function should take one parameter: an object/dict with two or more name-value pairs which represent the members of the group and the amount spent by each. * The function should return an object/d...
["def split_the_bill(x):\n diff = sum(x.values())/float(len(x))\n return {k: round(x[k]-diff, 2) for k in x}", "def split_the_bill(spendings):\n fair_amount = sum(spendings.values()) / float(len(spendings))\n return {name: round(amount - fair_amount, 2) for name, amount in spendings.items()}\n", "def split_...
{"fn_name": "split_the_bill", "inputs": [[{"A": 20, "B": 15, "C": 10}], [{"A": 40, "B": 25, "X": 10}], [{"A": 40, "B": 25, "C": 10, "D": 153, "E": 58}], [{"A": 475, "B": 384, "C": 223, "D": 111, "E": 19}], [{"A": 20348, "B": 493045, "C": 2948, "D": 139847, "E": 48937534, "F": 1938724, "G": 4, "H": 2084}]], "outputs": [...
introductory
https://www.codewars.com/kata/5641275f07335295f10000d0
def split_the_bill(x):
2,684
## Witamy! You are in Poland and want to order a drink. You need to ask "One beer please": "Jedno piwo poprosze" ``` java Translator.orderingBeers(1) = "Jedno piwo poprosze" ``` But let's say you are really thirsty and want several beers. Then you need to count in Polish. And more difficult, you need to understand t...
["def ordering_beers(beers):\n assert 0 <= beers < 100\n \n units = [\"\", \"jeden\", \"dwa\", \"trzy\", \"cztery\", \"piec\", \"szesc\" , \"siedem\", \"osiem\", \"dziewiec\",\n \"dziesiec\", \"jedenascie\", \"dwanascie\", \"trzynascie\", \"czternascie\", \"pietnascie\", \"szesnascie\", \"siedemnasc...
{"fn_name": "ordering_beers", "inputs": [[0], [1], [2], [3], [4], [5], [8], [10], [11], [12], [13], [14], [15], [16], [20], [21], [22], [28], [33], [44], [55], [98], [99]], "outputs": [["Woda mineralna poprosze"], ["Jedno piwo poprosze"], ["Dwa piwa poprosze"], ["Trzy piwa poprosze"], ["Cztery piwa poprosze"], ["Piec p...
introductory
https://www.codewars.com/kata/54f4e56e00ecc43c6d000220
def ordering_beers(beers):
2,685
Third day at your new cryptoanalyst job and you come across your toughest assignment yet. Your job is to implement a simple keyword cipher. A keyword cipher is a type of monoalphabetic substitution where two parameters are provided as such (string, keyword). The string is encrypted by taking the keyword, dropping any l...
["abc = \"abcdefghijklmnopqrstuvwxyz\"\n\ndef keyword_cipher(s, keyword, key=\"\"):\n for c in keyword + abc:\n if c not in key:\n key += c\n return s.lower().translate(str.maketrans(abc, key))", "from string import ascii_lowercase\n\ndef keyword_cipher(a, b):\n return a.lower().translate(str...
{"fn_name": "keyword_cipher", "inputs": [["Welcome home", "secret"], ["hello", "wednesday"], ["HELLO", "wednesday"], ["HeLlO", "wednesday"], ["WELCOME HOME", "gridlocked"], ["alpha bravo charlie", "delta"], ["Home Base", "seven"], ["basecamp", "covert"], ["one two three", "rails"], ["Test", "unbuntu"]], "outputs": [["w...
introductory
https://www.codewars.com/kata/57241cafef90082e270012d8
def keyword_cipher(msg, keyword):
2,686
Create a function that takes a string as a parameter and does the following, in this order: 1. replaces every letter with the letter following it in the alphabet (see note below) 2. makes any vowels capital 3. makes any consonants lower case **Note:** the alphabet should wrap around, so `Z` becomes `A` So, for examp...
["def changer(s):\n return s.lower().translate(str.maketrans('abcdefghijklmnopqrstuvwxyz', 'bcdEfghIjklmnOpqrstUvwxyzA'))", "changer=lambda s: \"\".join([a if not a.isalpha() else chr((ord(a)-96)%26+97).upper() if a in \"zdhnt\" else chr(ord(a)+1) for a in s.lower()])", "table = str.maketrans(\"abcdefghijklmnopqrstu...
{"fn_name": "changer", "inputs": [["Cat30"], ["Alice"], ["sponge1"], ["Hello World"], ["dogs"], ["z"]], "outputs": [["dbU30"], ["bmjdf"], ["tqpOhf1"], ["Ifmmp xpsmE"], ["Epht"], ["A"]]}
introductory
https://www.codewars.com/kata/58039f8efca342e4f0000023
def changer(string):
2,687
Complete the method so that it formats the words into a single comma separated value. The last word should be separated by the word 'and' instead of a comma. The method takes in an array of strings and returns a single formatted string. Empty string values should be ignored. Empty arrays or null/nil values being passed...
["def format_words(words):\n return ', '.join(word for word in words if word)[::-1].replace(',', 'dna ', 1)[::-1] if words else ''", "def format_words(words):\n # reject falsey words\n if not words: return \"\"\n \n # ignoring empty strings\n words = [word for word in words if word]\n \n number_...
{"fn_name": "format_words", "inputs": [[["one", "two", "three", "four"]], [["one"]], [["one", "", "three"]], [["", "", "three"]], [["one", "two", ""]], [[]], [null], [[""]]], "outputs": [["one, two, three and four"], ["one"], ["one and three"], ["three"], ["one and two"], [""], [""], [""]]}
introductory
https://www.codewars.com/kata/51689e27fe9a00b126000004
def format_words(words):
2,688
# Task let F(N) be the sum square of digits of N. So: `F(1) = 1, F(3) = 9, F(123) = 14` Choose a number A, the sequence {A0, A1, ...} is defined as followed: ``` A0 = A A1 = F(A0) A2 = F(A1) ... ``` if A = 123, we have: ``` 123 → 14(1 x 1 + 2 x 2 + 3 x 3) → 17(1 x 1 + 4 x 4) → 50(1 ...
["from itertools import count\n\n# Couldn't find the pattern of why it's 1 or 8, I'm sad :(\ndef repeat_sequence_len(n):\n memo = {}\n for i in count():\n if n in memo: return i - memo[n]\n memo[n] = i\n n = sum(d*d for d in map(int, str(n)))", "def F(n):\n return sum(int(d)**2 for d in st...
{"fn_name": "repeat_sequence_len", "inputs": [[1], [85], [810], [812], [818], [833]], "outputs": [[1], [8], [8], [8], [1], [1]]}
introductory
https://www.codewars.com/kata/58a3f57ecebc06bfcb00009c
def repeat_sequence_len(n):
2,689
You get a new job working for Eggman Movers. Your first task is to write a method that will allow the admin staff to enter a person’s name and return what that person's role is in the company. You will be given an array of object literals holding the current employees of the company. You code must find the employee ...
["employees = [{'first_name': 'Ollie', 'last_name': 'Hepburn', 'role': 'Boss'}, {'first_name': 'Morty', 'last_name': 'Smith', 'role': 'Truck Driver'}, {'first_name': 'Peter', 'last_name': 'Ross', 'role': 'Warehouse Manager'}, {'first_name': 'Cal', 'last_name': 'Neil', 'role': 'Sales Assistant'}, {'first_name': 'Jesse',...
{"fn_name": "find_employees_role", "inputs": [["Dipper Pines"], ["Morty Smith"], ["Anna Bell"], ["Anna"], ["Bell Anna"], ["Jewel Bell"], ["Bell Jewel"]], "outputs": [["Does not work here!"], ["Truck Driver"], ["Admin"], ["Does not work here!"], ["Does not work here!"], ["Receptionist"], ["Does not work here!"]]}
introductory
https://www.codewars.com/kata/55c9fb1b407024afe6000055
employees = [{'first_name': 'Ollie', 'last_name': 'Hepburn', 'role': 'Boss'}, {'first_name': 'Morty', 'last_name': 'Smith', 'role': 'Truck Driver'}, {'first_name': 'Peter', 'last_name': 'Ross', 'role': 'Warehouse Manager'}, {'first_name': 'Cal', 'last_name': 'Neil', 'role': 'Sales Assistant'}, {'first_name': 'Jesse', ...
2,690
Remove the parentheses = In this kata you are given a string for example: ```python "example(unwanted thing)example" ``` Your task is to remove everything inside the parentheses as well as the parentheses themselves. The example above would return: ```python "exampleexample" ``` Other than parentheses only letters...
["def remove_parentheses(s):\n lvl,out = 0,[]\n for c in s:\n lvl += c=='('\n if not lvl: out.append(c)\n lvl -= c==')' \n return ''.join(out)", "import re\n\ndef remove_parentheses(s):\n while (t := re.sub(r'\\([^()]*\\)', '', s)) != s:\n s = t\n return s", "def remove_par...
{"fn_name": "remove_parentheses", "inputs": [["example(unwanted thing)example"], ["example (unwanted thing) example"], ["a (bc d)e"], ["a(b(c))"], ["hello example (words(more words) here) something"], ["(first group) (second group) (third group)"]], "outputs": [["exampleexample"], ["example example"], ["a e"], ["a"], ...
introductory
https://www.codewars.com/kata/5f7c38eb54307c002a2b8cc8
def remove_parentheses(s):
2,691
In this Kata, you will be given a string that has lowercase letters and numbers. Your task is to compare the number groupings and return the largest number. Numbers will not have leading zeros. For example, `solve("gh12cdy695m1") = 695`, because this is the largest of all number groupings. Good luck! Please also t...
["import re\n\n\ndef solve(s):\n return max(map(int,re.findall(r\"(\\d+)\", s)))", "def solve(s):\n largest = 0\n number = 0\n \n for char in s:\n if char.isdigit():\n number = number * 10 + int(char)\n if largest < number:\n largest = number\n else:\n ...
{"fn_name": "solve", "inputs": [["gh12cdy695m1"], ["2ti9iei7qhr5"], ["vih61w8oohj5"], ["f7g42g16hcu5"], ["lu1j8qbbb85"]], "outputs": [[695], [9], [61], [42], [85]]}
introductory
https://www.codewars.com/kata/59dd2c38f703c4ae5e000014
def solve(s):
2,692
#Bubbleing around Since everybody hates chaos and loves sorted lists we should implement some more sorting algorithms. Your task is to implement a Bubble sort (for some help look at https://en.wikipedia.org/wiki/Bubble_sort) and return a list of snapshots after **each change** of the initial list. e.g. If the initi...
["def bubble(l):\n ret = []\n for i in range(len(l) - 1, 0, -1):\n for j in range(i):\n if l[j] > l[j + 1]:\n l[j], l[j + 1] = l[j + 1], l[j]\n ret.append(l[:])\n return ret", "def bubble(l):\n bubbling,bubbles = True, []\n while bubbling :\n bubblin...
{"fn_name": "bubble", "inputs": [[[]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[1, 3, 3, 7, 4, 2]]], "outputs": [[[]], [[]], [[[1, 3, 3, 4, 7, 2], [1, 3, 3, 4, 2, 7], [1, 3, 3, 2, 4, 7], [1, 3, 2, 3, 4, 7], [1, 2, 3, 3, 4, 7]]]]}
introductory
https://www.codewars.com/kata/57403b5ad67e87b5e7000d1d
def bubble(l):
2,693
In this kata the function returns an array/list like the one passed to it but with its nth element removed (with `0 <= n <= array/list.length - 1`). The function is already written for you and the basic tests pass, but random tests fail. Your task is to figure out why and fix it. Good luck! ~~~if:javascript Some good...
["def remove_nth_element(a, n):\n return a[:n] + a[n+1:]", "def remove_nth_element(lst, n):\n lst_copy = lst.copy()\n del lst_copy[n]\n return lst_copy", "def remove_nth_element(lst, n):\n # Fix it\n import copy\n lst_copy = copy.deepcopy(lst)\n del lst_copy[n]\n return lst_copy\n", "def remo...
{"fn_name": "remove_nth_element", "inputs": [[[9, 7, 6, 9], 0]], "outputs": [[[7, 6, 9]]]}
introductory
https://www.codewars.com/kata/5a7b3d08fd5777bf6a000121
def remove_nth_element(lst, n):
2,694
Paul is an excellent coder and sits high on the CW leaderboard. He solves kata like a banshee but would also like to lead a normal life, with other activities. But he just can't stop solving all the kata!! Given an array (x) you need to calculate the Paul Misery Score. The values are worth the following points: kata ...
["def paul(x):\n points = {'life': 0, 'eating': 1, 'kata': 5, 'Petes kata': 10}\n misery = sum(map(points.get, x))\n return ['Miserable!', 'Sad!', 'Happy!', 'Super happy!']\\\n [(misery<40)+(misery<70)+(misery<100)]", "def paul(x):\n val = x.count(\"kata\")*5 + x.count(\"Petes kata\")*10 + x.coun...
{"fn_name": "paul", "inputs": [[["life", "eating", "life"]], [["life", "Petes kata", "Petes kata", "Petes kata", "eating"]], [["Petes kata", "Petes kata", "eating", "Petes kata", "Petes kata", "eating"]]], "outputs": [["Super happy!"], ["Super happy!"], ["Happy!"]]}
introductory
https://www.codewars.com/kata/57ee31c5e77282c24d000024
def paul(x):
2,695
# Task Yesterday you found some shoes in your room. Each shoe is described by two values: ``` type indicates if it's a left or a right shoe; size is the size of the shoe. ``` Your task is to check whether it is possible to pair the shoes you found in such a way that each pair consists of a right and a left shoe of an...
["def pair_of_shoes(a):\n return sorted(s for lr, s in a if lr == 1) == sorted(s for lr, s in a if lr == 0)", "from collections import defaultdict\ndef pair_of_shoes(shoes):\n sz = defaultdict(list)\n for i in shoes:\n sz[i[1]].append(i[0])\n return all( (i[1].count(1) == i[1].count(0)) for i in sz.i...
{"fn_name": "pair_of_shoes", "inputs": [[[[0, 21], [1, 23], [1, 21], [0, 23]]], [[[0, 21], [1, 23], [1, 21], [1, 23]]], [[[0, 23], [1, 21], [1, 23], [0, 21], [1, 22], [0, 22]]], [[[0, 23], [1, 21], [1, 23], [0, 21]]], [[[0, 23], [1, 21], [1, 22], [0, 21]]], [[[0, 23]]], [[[0, 23], [1, 23]]], [[[0, 23], [1, 23], [1, 23]...
introductory
https://www.codewars.com/kata/58885a7bf06a3d466e0000e3
def pair_of_shoes(shoes):
2,696
# Task The string is called `prime` if it cannot be constructed by concatenating some (more than one) equal strings together. For example, "abac" is prime, but "xyxy" is not("xyxy"="xy"+"xy"). Given a string determine if it is prime or not. # Input/Output - `[input]` string `s` string containing only lower...
["def prime_string(s):\n return (s + s).find(s, 1) == len(s)", "import re\ndef prime_string(s):\n return not not re.sub(r\"^(.+)\\1+$\",\"\",s)", "def prime_string(s):\n n=len(s)\n return all(s!= s[:i]*(n//i) for i in range(1,n//2 +1))\n \n \n \n \n", "def prime_string(s):\n n = len(s)\n return n ==...
{"fn_name": "prime_string", "inputs": [["abac"], ["abab"], ["aaaa"], ["x"], ["abc"], ["fdsyffdsyffdsyffdsyffdsyf"], ["utdutdtdutd"], ["abba"]], "outputs": [[true], [false], [false], [true], [true], [false], [true], [true]]}
introductory
https://www.codewars.com/kata/589d36bbb6c071f7c20000f7
def prime_string(s):
2,697
Complete the solution so that the function will break up camel casing, using a space between words. ### Example ``` solution("camelCasing") == "camel Casing" ```
["def solution(s):\n return ''.join(' ' + c if c.isupper() else c for c in s)\n", "import re\ndef solution(s):\n return re.sub('([A-Z])', r' \\1', s)", "def solution(s):\n final_string = \"\"\n for i in range(len(s)):\n char = s[i]\n if char.isupper():\n final_string += \" \" + char...
{"fn_name": "solution", "inputs": [["helloWorld"], ["camelCase"], ["breakCamelCase"]], "outputs": [["hello World"], ["camel Case"], ["break Camel Case"]]}
introductory
https://www.codewars.com/kata/5208f99aee097e6552000148
def solution(s):
2,698
Your task is to create a function called ```sum_arrays()``` in Python or ```addArrays``` in Javascript, which takes two arrays consisting of integers, and returns the sum of those two arrays. The twist is that (for example) ```[3,2,9]``` does not equal ``` 3 + 2 + 9```, it would equal ```'3' + '2' + '9'``` converted t...
["def sum_arrays(*args):\n if all(x == [] for x in args) or all(x == [0] for x in args):\n return []\n elif any(x == [] for x in args):\n return max(args)\n else:\n s = sum(int(''.join(map(str, x))) for x in args)\n minus = s < 0\n return [int(x) * -1 if minus and i == 0 else int...
{"fn_name": "sum_arrays", "inputs": [[[3, 2, 9], [1, 2]], [[4, 7, 3], [1, 2, 3]], [[1], [5, 7, 6]], [[3, 2, 6, 6], [-7, 2, 2, 8]], [[-4, 5, 7, 3, 6], [5, 3, 4, 5]], [[], []], [[0], []], [[], [1, 2]], [[1, 4, 5], []], [[0], [0]]], "outputs": [[[3, 4, 1]], [[5, 9, 6]], [[5, 7, 7]], [[-3, 9, 6, 2]], [[-4, 0, 3, 9, 1]], [[...
introductory
https://www.codewars.com/kata/59c3e8c9f5d5e40cab000ca6
def sum_arrays(array1,array2):
2,699
Create a function that transforms any positive number to a string representing the number in words. The function should work for all numbers between 0 and 999999. ### Examples ``` number2words(0) ==> "zero" number2words(1) ==> "one" number2words(9) ==> "nine" number2words(10) ==> "ten" number2words(17) ==> ...
["words = \"zero one two three four five six seven eight nine\" + \\\n\" ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty\" + \\\n\" thirty forty fifty sixty seventy eighty ninety\"\nwords = words.split(\" \")\n\ndef number2words(n):\n if n < 20:\n return words[n]\n el...
{"fn_name": "number2words", "inputs": [[0], [1], [8], [5], [9], [10], [19], [20], [22], [54], [80], [98], [100], [301], [793], [800], [650], [1000], [1003], [3052], [7300], [7217], [8340], [99997], [888887]], "outputs": [["zero"], ["one"], ["eight"], ["five"], ["nine"], ["ten"], ["nineteen"], ["twenty"], ["twenty-two"]...
introductory
https://www.codewars.com/kata/52724507b149fa120600031d
def number2words(n):
2,700
## Your Story "A *piano* in the home meant something." - *Fried Green Tomatoes at the Whistle Stop Cafe* You've just realized a childhood dream by getting a beautiful and beautiful-sounding upright piano from a friend who was leaving the country. You immediately started doing things like playing "Heart and Soul" over ...
["def black_or_white_key(key_press_count):\n return \"black\" if (key_press_count - 1) % 88 % 12 in [1, 4, 6, 9, 11] else \"white\"\n", "w, b = \"white\", \"black\"\nkeyboard = [w, b, w, w, b, w, b, w, w, b, w, b]\n\ndef black_or_white_key(count):\n return keyboard[(count - 1) % 88 % 12]", "def black_or_white_key...
{"fn_name": "black_or_white_key", "inputs": [[1], [5], [12], [42], [88], [89], [92], [100], [111], [200], [2017]], "outputs": [["white"], ["black"], ["black"], ["white"], ["white"], ["white"], ["white"], ["black"], ["white"], ["black"], ["white"]]}
introductory
https://www.codewars.com/kata/589273272fab865136000108
def black_or_white_key(key_press_count):
2,701
# A History Lesson Tetris is a puzzle video game originally designed and programmed by Soviet Russian software engineer Alexey Pajitnov. The first playable version was completed on June 6, 1984. Pajitnov derived its name from combining the Greek numerical prefix tetra- (the falling pieces contain 4 segments) and tenni...
["points = [0, 40, 100, 300, 1200]\n\ndef get_score(arr) -> int:\n cleared = 0\n score = 0\n for lines in arr:\n level = cleared // 10\n score += (level+1) * points[lines]\n cleared += lines\n return score", "def get_score(arr) -> int:\n return sum([0, 40, 100, 300, 1200][n] * (1 + (...
{"fn_name": "get_score", "inputs": [[[0, 1, 2, 3, 4]], [[0, 1, 1, 3, 0, 2, 1, 2]], [[2, 0, 4, 2, 2, 3, 0, 0, 3, 3]], [[0]], [[]]], "outputs": [[1640], [620], [3300], [0], [0]]}
introductory
https://www.codewars.com/kata/5da9af1142d7910001815d32
def get_score(arr) -> int:
2,702
# Task You are given two strings s and t of the same length, consisting of uppercase English letters. Your task is to find the minimum number of "replacement operations" needed to get some `anagram` of the string t from the string s. A replacement operation is performed by picking exactly one character from the string...
["from collections import Counter\n\ndef create_anagram(s, t):\n return sum((Counter(s) - Counter(t)).values())", "def create_anagram(s, t):\n return sum(max(0, s.count(c) - t.count(c)) for c in set(s))", "def create_anagram(s, t):\n for c in s: t = t.replace(c, \"\", 1)\n return len(t)", "def create_anagra...
{"fn_name": "create_anagram", "inputs": [["AABAA", "BBAAA"], ["OVGHK", "RPGUC"], ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAB", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAC"]], "outputs": [[1], [4], [1]]}
introductory
https://www.codewars.com/kata/5887099cc815166a960000c6
def create_anagram(s, t):
2,703
Complete the square sum function so that it squares each number passed into it and then sums the results together. For example, for `[1, 2, 2]` it should return `9` because `1^2 + 2^2 + 2^2 = 9`. ```if:racket In Racket, use a list instead of an array, so '(1 2 3) should return 9. ```
["def square_sum(numbers):\n return sum(x ** 2 for x in numbers)", "def square_sum(numbers):\n return sum(x * x for x in numbers) ", "def square_sum(numbers):\n return sum(map(lambda x: x**2,numbers))", "def square_sum(numbers):\n res = 0\n for num in numbers:\n res = res + num*num\n return res...
{"fn_name": "square_sum", "inputs": [[[1, 2]], [[0, 3, 4, 5]], [[]], [[-1, -2]], [[-1, 0, 1]]], "outputs": [[5], [50], [0], [5], [2]]}
introductory
https://www.codewars.com/kata/515e271a311df0350d00000f
def square_sum(numbers):
2,704
# Task Given a `sequence` of integers, check whether it is possible to obtain a strictly increasing sequence by erasing no more than one element from it. # Example For `sequence = [1, 3, 2, 1]`, the output should be `false`; For `sequence = [1, 3, 2]`, the output should be `true`. # Input/Output - `[input]` ...
["def almost_increasing_sequence(sequence):\n save, first = -float('inf'), True\n for i,x in enumerate(sequence):\n if x > save: save = x\n elif first:\n if i == 1 or x > sequence[i-2]: save = x\n first = False\n else: return False\n return True", "is_increasing_seque...
{"fn_name": "almost_increasing_sequence", "inputs": [[[1, 3, 2, 1]], [[1, 3, 2]], [[1, 2, 3]], [[1, 2, 3, 1]], [[1, 4, 10, 4, 2]], [[10, 1, 2, 3, 4, 5]], [[1, 1, 1, 2, 3]], [[0, -2, 5, 6]], [[1, 1]], [[4, 5, 6, 1, 2, 3]], [[149, 15, 23, 32, 41, 48, 58, 66, 69, 75, 81, 91, 178, 100, 109, 118, 128, 134, 143]]], "outputs"...
introductory
https://www.codewars.com/kata/5893e7578afa367a61000036
def almost_increasing_sequence(sequence):
2,705
## Task Write a function that accepts two arguments and generates a sequence containing the integers from the first argument to the second inclusive. ## Input Pair of integers greater than or equal to `0`. The second argument will always be greater than or equal to the first. ## Example ```python generate_intege...
["def generate_integers(m, n): \n return list(range(m,n+1))", "def generate_integers(m, n): \n return [*range(m, n + 1)]", "def generate_integers(m, n):\n return [i for i in range(m,n+1)]\n", "def generate_integers(m, n):\n ans = []\n for each in range(m,n+1):\n ans.append(each)\n return ans", ...
{"fn_name": "generate_integers", "inputs": [[2, 5]], "outputs": [[[2, 3, 4, 5]]]}
introductory
https://www.codewars.com/kata/5841f680c5c9b092950001ae
def generate_integers(m, n):
2,706
# Story&Task There are three parties in parliament. The "Conservative Party", the "Reformist Party", and a group of independants. You are a member of the “Conservative Party” and you party is trying to pass a bill. The “Reformist Party” is trying to block it. In order for a bill to pass, it must have a majority vo...
["def pass_the_bill(total, conservative, reformist):\n ind = total - conservative - reformist\n majority = total//2 + 1\n if conservative > majority:\n return 0\n elif conservative + ind < majority:\n return -1\n else:\n return majority - conservative", "def pass_the_bill(t, c, r):\n...
{"fn_name": "pass_the_bill", "inputs": [[8, 3, 3], [13, 4, 7], [7, 4, 3], [11, 4, 1], [11, 5, 1], [11, 6, 1], [11, 4, 4], [11, 5, 4], [11, 5, 5], [11, 4, 6], [11, 4, 5], [15, 9, 3], [16, 7, 8], [16, 8, 7], [16, 1, 8]], "outputs": [[2], [-1], [0], [2], [1], [0], [2], [1], [1], [-1], [2], [0], [-1], [1], [-1]]}
introductory
https://www.codewars.com/kata/58c8a6daa7f31a623200016a
def pass_the_bill(total_members, conservative_party_members, reformist_party_members):
2,707
*This kata is based on [Project Euler Problem 539](https://projecteuler.net/problem=539)* ##Object Find the last number between 1 and `n` (inclusive) that survives the elimination process ####How It Works Start with the first number on the left then remove every other number moving right until you reach the the end...
["def last_man_standing(n):\n dir, lst = -1, range(2,n+1,2)\n while len(lst) != 1:\n lst = lst[len(lst)%2 or dir == 1 ::2]\n dir = -dir\n return lst[0]", "from math import log\n\ndef last_man_standing(n):\n return 1 + sum((((n >> i) | (i + 1)) % 2) << i for i in range(int(log(n, 2))))", "def l...
{"fn_name": "last_man_standing", "inputs": [[9], [10], [100], [1000], [50000]], "outputs": [[6], [8], [54], [510], [22358]]}
introductory
https://www.codewars.com/kata/567c26df18e9b1083a000049
def last_man_standing(n):
2,708
Write a code that receives an array of numbers or strings, goes one by one through it while taking one value out, leaving one value in, taking, leaving, and back again to the beginning until all values are out. It's like a circle of people who decide that every second person will leave it, until the last person is th...
["from collections import deque\n\ndef yes_no(arr):\n d, result = deque(arr), []\n while d:\n result.append(d.popleft())\n d.rotate(-1)\n return result", "def yes_no(arr):\n result = []\n while arr:\n result.append(arr.pop(0))\n if arr:\n arr.append(arr.pop(0))\n ...
{"fn_name": "yes_no", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [["this", "code", "is", "right", "the"]], [[]], [["a"]], [["a", "b"]]], "outputs": [[[1, 3, 5, 7, 9, 2, 6, 10, 8, 4]], [["this", "is", "the", "right", "code"]], [[]], [["a"]], [["a", "b"]]]}
introductory
https://www.codewars.com/kata/573c84bf0addf9568d001299
def yes_no(arr):
2,709
Write a function `take_umbrella()` that takes two arguments: a string representing the current weather and a float representing the chance of rain today. Your function should return `True` or `False` based on the following criteria. * You should take an umbrella if it's currently raining or if it's cloudy and the cha...
["def take_umbrella(weather, rain_chance):\n # Your code here.\n return (weather=='cloudy' and rain_chance>0.20) or weather=='rainy' or (weather=='sunny' and rain_chance>0.5)", "def take_umbrella(weather, rain_chance):\n return rain_chance > {'sunny': 0.5, 'cloudy': 0.2, 'rainy': -1}[weather]", "def take_umbre...
{"fn_name": "take_umbrella", "inputs": [["sunny", 0.4], ["rainy", 0.0], ["cloudy", 0.2]], "outputs": [[false], [true], [false]]}
introductory
https://www.codewars.com/kata/5865a28fa5f191d35f0000f8
def take_umbrella(weather, rain_chance):
2,710
Write a program that, given a word, computes the scrabble score for that word. ## Letter Values You'll need these: ``` Letter Value A, E, I, O, U, L, N, R, S, T 1 D, G 2 B, C, M, P 3 F, H, V, W, Y 4 K ...
["def scrabble_score(st): \n x = 0\n for y in st:\n if 'a' in y.lower():\n x += 1\n if 'e' in y.lower():\n x += 1\n if 'i' in y.lower():\n x += 1\n if 'o' in y.lower():\n x += 1\n if 'u' in y.lower():\n x += 1\n if 'l...
{"fn_name": "scrabble_score", "inputs": [[""], ["a"], ["street"], ["STREET"], [" a"], ["st re et"], ["f"], ["quirky"], ["MULTIBILLIONAIRE"], ["alacrity"]], "outputs": [[0], [1], [6], [6], [1], [6], [4], [22], [20], [13]]}
introductory
https://www.codewars.com/kata/558fa34727c2d274c10000ae
def scrabble_score(st):
2,711
You have n dices each one having s sides numbered from 1 to s. How many outcomes add up to a specified number k? For example if we roll four normal six-sided dices we have four outcomes that add up to 5. (1, 1, 1, 2) (1, 1, 2, 1) (1, 2, 1, 1) (2, 1, 1, 1)
["def outcome(n, s, k): \n if n == 1: return 1 if 0 < k <= s else 0\n return sum(outcome(n - 1, s, k - j - 1) for j in range(s)) if k > 0 else 0", "def outcome(n, s, k):\n return n <= k <= n*s and (n in (1, k) or sum(outcome(n-1, s, k-x-1) for x in range(min(s, k-n+1))))", "def outcome(n, s, k):\n if n =...
{"fn_name": "outcome", "inputs": [[1, 6, 0], [1, 0, 1], [0, 6, 1], [1, 6, 1], [1, 6, 2], [1, 6, 3], [1, 6, 4], [1, 6, 5], [1, 6, 6], [1, 6, 7], [2, 6, 1], [2, 6, 2], [2, 6, 3], [2, 6, 4], [2, 6, 5], [2, 6, 6], [2, 6, 7], [2, 6, 8], [2, 6, 9], [2, 6, 10], [2, 6, 11], [2, 6, 12], [2, 6, 13], [3, 6, 6], [3, 6, 9], [3, 6, ...
introductory
https://www.codewars.com/kata/58ff61d2d6b38ee5270000bc
def outcome(n, s, k):
2,712
# One is the loneliest number ## Task The range of vision of a digit is its own value. `1` can see one digit to the left and one digit to the right,` 2` can see two digits, and so on. Thus, the loneliness of a digit `N` is the sum of the digits which it can see. Given a non-negative integer, your funtion must deter...
["def loneliest(n):\n a = list(map(int, str(n)))\n b = [(sum(a[max(0, i - x):i+x+1]) - x, x) for i, x in enumerate(a)]\n return (min(b)[0], 1) in b", "def loneliest(n): \n def loneliness(it):\n i,v = it\n return sum(lst[max(0,i-v):i+v+1])-v, abs(v-1)\n \n lst = list(map(int,str(n)))\n ...
{"fn_name": "loneliest", "inputs": [[34315], [123456], [8854778], [65432165432], [0], [1], [11111]], "outputs": [[true], [true], [false], [false], [false], [true], [true]]}
introductory
https://www.codewars.com/kata/5dfa33aacec189000f25e9a9
def loneliest(number):
2,713
Many years ago, Roman numbers were defined by only `4` digits: `I, V, X, L`, which represented `1, 5, 10, 50`. These were the only digits used. The value of a sequence was simply the sum of digits in it. For instance: ``` IV = VI = 6 IX = XI = 11 XXL = LXX = XLX = 70 ``` It is easy to see that this system is ambiguous,...
["INITIAL = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292]\n\ndef solve(n):\n return INITIAL[n] if n < 12 else 292 + (49 * (n-11))", "from functools import lru_cache\n\nDIGITS = [1, 5, 10, 50]\nTHRESHOLD = 12\n\ndef solve_naive (n):\n minimal = n * min(DIGITS)\n maximal = n * max(DIGITS)\n return maxim...
{"fn_name": "solve", "inputs": [[1], [2], [3], [4], [5], [6], [10], [10000000]], "outputs": [[4], [10], [20], [35], [56], [83], [244], [489999753]]}
introductory
https://www.codewars.com/kata/5b983dcd660b1227d00002c9
def solve(n):
2,714
There are just some things you can't do on television. In this case, you've just come back from having a "delicious" Barth burger and you're set to give an interview. The Barth burger has made you queezy, and you've forgotten some of the import rules of the "You Can't Do That on Television" set. If you say any of the ...
["import re\n\nWATER_PATTERN = re.compile(r\"water|wet|wash\", re.I)\nSLIME_PATTERN = re.compile(r\"\\bI don't know\\b|slime\", re.I)\n\n\ndef bucket_of(said):\n water = WATER_PATTERN.search(said)\n slime = SLIME_PATTERN.search(said)\n\n if water:\n return 'sludge' if slime else 'water'\n\n return 's...
{"fn_name": "bucket_of", "inputs": [["water"], ["wet"], ["wash"], ["i don't know"], ["slime"], ["wet water"], ["slime water"], ["I don't know if this will work"], ["I don't know if this will work without watering it first."], [""], ["is there SLIME in that?!"], ["i won't say anything"], ["WaTeR?"], ["but i can say slud...
introductory
https://www.codewars.com/kata/5667525f0f157f7a0a000004
def bucket_of(said):
2,715
# Introduction You are the developer working on a website which features a large counter on its homepage, proudly displaying the number of happy customers who have downloaded your companies software. You have been tasked with adding an effect to this counter to make it more interesting. Instead of just displaying ...
["def counter_effect(hit_count):\n return [[i for i in range(int(hit_count[x]) + 1)] for x in range(4)]", "def counter_effect(n):\n return [list(range(int(x)+1)) for x in n]", "def counter_effect(hit):\n b = []\n for i in str(hit):\n a = []\n for k in range(int(i)+1):\n a.append(k)\...
{"fn_name": "counter_effect", "inputs": [["1250"], ["0050"], ["0000"]], "outputs": [[[[0, 1], [0, 1, 2], [0, 1, 2, 3, 4, 5], [0]]], [[[0], [0], [0, 1, 2, 3, 4, 5], [0]]], [[[0], [0], [0], [0]]]]}
introductory
https://www.codewars.com/kata/57b6f850a6fdc76523001162
def counter_effect(hit_count):
2,716
**Step 1:** Create a function called `encode()` to replace all the lowercase vowels in a given string with numbers according to the following pattern: ``` a -> 1 e -> 2 i -> 3 o -> 4 u -> 5 ``` For example, `encode("hello")` would return `"h2ll4"`. There is no need to worry about uppercase vowels in this kata. **Step...
["def encode(s, t=str.maketrans(\"aeiou\", \"12345\")):\n return s.translate(t)\n \ndef decode(s, t=str.maketrans(\"12345\", \"aeiou\")):\n return s.translate(t)", "CIPHER = (\"aeiou\", \"12345\")\n\ndef encode(st):\n return st.translate(str.maketrans(CIPHER[0], CIPHER[1]))\n \ndef decode(st):\n retur...
{"fn_name": "encode", "inputs": [["hello"], ["How are you today?"], ["This is an encoding test."]], "outputs": [["h2ll4"], ["H4w 1r2 y45 t4d1y?"], ["Th3s 3s 1n 2nc4d3ng t2st."]]}
introductory
https://www.codewars.com/kata/53697be005f803751e0015aa
def encode(st):
2,717
Given an array of integers, return the smallest common factors of all integers in the array. When i say **Smallest Common Factor** i mean the smallest number above 1 that can divide all numbers in the array without a remainder. If there are no common factors above 1, return 1 (technically 1 is always a common factor)...
["def scf(lst):\n return next((k for k in range(2, 1 + min(lst, default=1)) if all(n % k == 0 for n in lst)), 1)\n", "from functools import reduce\nfrom math import floor, gcd, sqrt\n\ndef smallest_factor(n):\n return next((d for d in range(2, floor(sqrt(n)) + 1) if n % d == 0), n)\n\ndef scf(nums):\n return 1...
{"fn_name": "scf", "inputs": [[[200, 30, 18, 8, 64, 34]], [[21, 45, 51, 27, 33]], [[133, 147, 427, 266]], [[3, 5, 7]], [[]]], "outputs": [[2], [3], [7], [1], [1]]}
introductory
https://www.codewars.com/kata/5933af2db328fbc731000010
def scf(lst):
2,718
# Task Timed Reading is an educational tool used in many schools to improve and advance reading skills. A young elementary student has just finished his very first timed reading exercise. Unfortunately he's not a very good reader yet, so whenever he encountered a word longer than maxLength, he simply skipped it and re...
["import re\ndef timed_reading(max_length, text):\n return sum(len(i) <= max_length for i in re.findall('\\w+', text))", "def timed_reading(max_length, text):\n count = 0\n for punctuation_mark in '!.,?\\'\\\"_-)(':\n text = text.replace(punctuation_mark , '')\n listed_text = text.split(\" \")\n\n ...
{"fn_name": "timed_reading", "inputs": [[4, "The Fox asked the stork, 'How is the soup?'"], [1, "..."], [3, "This play was good for us."], [3, "Suddenly he stopped, and glanced up at the houses"], [6, "Zebras evolved among the Old World horses within the last four million years."], [5, "Although zebra species may have ...
introductory
https://www.codewars.com/kata/588817db5fb13af14a000020
def timed_reading(max_length, text):
2,719
This kata is all about adding numbers. You will create a function named add. This function will return the sum of all the arguments. Sounds easy, doesn't it?? Well here's the twist. The inputs will gradually increase with their index as parameter to the function. ```python add(3,4,5) #returns (3*1)+(4*2)+(5*3)=26 ...
["def add(*args):\n return sum((i+1)*v for i,v in enumerate(args))", "def add(*args):\n return sum(n * i for i, n in enumerate(args, 1))", "def add(*args):\n return sum(i * x for i, x in enumerate(args, 1))", "def add(*args):\n return sum(pos * value for pos, value in enumerate(args, 1))\n", "def add(*args)...
{"fn_name": "add", "inputs": [[100, 200, 300], [2], [4, -3, -2], [-1, -2, -3, -4]], "outputs": [[1400], [2], [-8], [-30]]}
introductory
https://www.codewars.com/kata/555b73a81a6285b6ce000047
def add(*args):
2,720
In the following 6 digit number: ``` 283910 ``` `91` is the greatest sequence of 2 consecutive digits. In the following 10 digit number: ``` 1234567890 ``` `67890` is the greatest sequence of 5 consecutive digits. Complete the solution so that it returns the greatest sequence of five consecutive digits found withi...
["def solution(digits):\n numlist = [int(digits[i:i+5]) for i in range(0,len(digits)-4)]\n return max(numlist)", "def solution(digits):\n return int(max(digits[a:a + 5] for a in range(len(digits) - 4)))", "def solution(digits):\n result = -1;\n for i in range(len(digits)):\n current = int(digits[i...
{"fn_name": "solution", "inputs": [["1234567898765"]], "outputs": [[98765]]}
introductory
https://www.codewars.com/kata/51675d17e0c1bed195000001
def solution(digits):
2,721
The task is very simple. You must to return pyramids. Given a number ```n``` you print a pyramid with ```n``` floors For example , given a ```n=4``` you must to print this pyramid: ``` /\ / \ / \ /______\ ``` Other example, given a ```n=6``` you must to print this pyramid: ``` /\ / \ ...
["def pyramid(n):\n return '\\n'.join(\"/{}\\\\\".format(\" _\"[r==n-1] * r*2).center(2*n).rstrip() for r in range(n)) + '\\n'", "def pyramid(n):\n return '\\n'.join(('/%s\\\\' % (' _'[i == n-1] * i*2)).rjust(n+i+1) for i in range(n)) + '\\n'", "def pyramid(n):\n return \"\".join(\n f\"{' ' * (n - i - 1...
{"fn_name": "pyramid", "inputs": [[4], [6], [10]], "outputs": [[" /\\\n / \\\n / \\\n/______\\\n"], [" /\\\n / \\\n / \\\n / \\\n / \\\n/__________\\\n"], [" /\\\n / \\\n / \\\n / \\\n / \\\n / \\\n / \\\n / ...
introductory
https://www.codewars.com/kata/5a1c28f9c9fc0ef2e900013b
def pyramid(n):
2,722
Complete the function/method so that it returns the url with anything after the anchor (`#`) removed. ## Examples ```python # returns 'www.codewars.com' remove_url_anchor('www.codewars.com#about') # returns 'www.codewars.com?page=1' remove_url_anchor('www.codewars.com?page=1') ```
["def remove_url_anchor(url):\n return url.split('#')[0]", "def remove_url_anchor(url):\n return url.partition('#')[0]", "def remove_url_anchor(url):\n import re\n return re.sub('#.*$','',url)", "def remove_url_anchor(url):\n index = url.find('#')\n return url[:index] if index >= 0 else url", "def remove_url_...
{"fn_name": "remove_url_anchor", "inputs": [["www.codewars.com#about"], ["www.codewars.com/katas/?page=1#about"], ["www.codewars.com/katas/"]], "outputs": [["www.codewars.com"], ["www.codewars.com/katas/?page=1"], ["www.codewars.com/katas/"]]}
introductory
https://www.codewars.com/kata/51f2b4448cadf20ed0000386
def remove_url_anchor(url):
2,723
You are given a string of numbers between 0-9. Find the average of these numbers and return it as a floored whole number (ie: no decimal places) written out as a string. Eg: "zero nine five two" -> "four" If the string is empty or includes a number greater than 9, return "n/a"
["N = ['zero','one','two','three','four','five','six','seven','eight','nine']\n\ndef average_string(s):\n try:\n return N[sum(N.index(w) for w in s.split()) // len(s.split())]\n except (ZeroDivisionError, ValueError):\n return 'n/a'", "def average_string(s):\n if not s:\n return 'n/a'\n\n ...
{"fn_name": "average_string", "inputs": [["zero nine five two"], ["four six two three"], ["one two three four five"], ["five four"], ["zero zero zero zero zero"], ["one one eight one"], ["one"], [""], ["ten"], ["pippi"]], "outputs": [["four"], ["three"], ["three"], ["four"], ["zero"], ["two"], ["one"], ["n/a"], ["n/a"]...
introductory
https://www.codewars.com/kata/5966847f4025872c7d00015b
def average_string(s):
2,724
Modify the `kebabize` function so that it converts a camel case string into a kebab case. Notes: - the returned string should only contain lowercase letters
["def kebabize(s):\n return ''.join(c if c.islower() else '-' + c.lower() for c in s if c.isalpha()).strip('-')", "def kebabize(string):\n result = \"\"\n \n for c in string:\n if c.isupper():\n if result is not \"\":\n result += \"-{}\".format(c.lower())\n else:\...
{"fn_name": "kebabize", "inputs": [["myCamelCasedString"], ["myCamelHas3Humps"], ["SOS"], ["42"], ["CodeWars"]], "outputs": [["my-camel-cased-string"], ["my-camel-has-humps"], ["s-o-s"], [""], ["code-wars"]]}
introductory
https://www.codewars.com/kata/57f8ff867a28db569e000c4a
def kebabize(string):
2,725
As a part of this Kata, you need to create a function that when provided with a triplet, returns the index of the numerical element that lies between the other two elements. The input to the function will be an array of three distinct numbers (Haskell: a tuple). For example: gimme([2, 3, 1]) => 0 *2* is the num...
["def gimme(inputArray):\n # Implement this function\n return inputArray.index(sorted(inputArray)[1])", "def gimme(input_array):\n return input_array.index(sorted(input_array)[1])\n", "gimme=lambda l:l.index(sorted(l)[1])", "def gimme(lst):\n return lst.index(sorted(lst)[len(lst)//2])\n", "def gimme(arr):\n...
{"fn_name": "gimme", "inputs": [[[2, 3, 1]], [[5, 10, 14]], [[1, 3, 4]], [[15, 10, 14]], [[-0.41, -23, 4]], [[-15, -10, 14]]], "outputs": [[0], [1], [1], [2], [0], [1]]}
introductory
https://www.codewars.com/kata/545a4c5a61aa4c6916000755
def gimme(input_array):
2,726
Given an integer, if the length of it's digits is a perfect square, return a square block of sqroot(length) * sqroot(length). If not, simply return "Not a perfect square!". Examples: 1212 returns: >1212 Note: 4 digits so 2 squared (2x2 perfect square). 2 digits on each line. 123123123 returns: >123123123 Note:...
["def square_it(digits):\n s = str(digits)\n n = len(s)**0.5\n if n != int(n):\n return \"Not a perfect square!\"\n n = int(n)\n return \"\\n\".join(s[i*n:i*n+n] for i in range(int(n)))", "square_it=lambda n:len(str(n))**.5%1and\"Not a perfect square!\"or'\\n'.join(map(''.join,zip(*[iter(str(n))]*...
{"fn_name": "square_it", "inputs": [[4547286933343749825161701915681956276108219454705210545289005317346009798484488964285906487], [90189877259570782117221886144647133351119464323162996566552951010740268249057549708185088193991122784476567524182655933233701139127237445845740732409435163234477841573580660927256314688880...
introductory
https://www.codewars.com/kata/5705ca6a41e5be67720012c0
def square_it(digits):
2,727
# Task Given string `s`, which contains only letters from `a to z` in lowercase. A set of alphabet is given by `abcdefghijklmnopqrstuvwxyz`. 2 sets of alphabets mean 2 or more alphabets. Your task is to find the missing letter(s). You may need to output them by the order a-z. It is possible that there is more ...
["from collections import Counter\nfrom string import ascii_lowercase\n\ndef missing_alphabets(s):\n c = Counter(s)\n m = max(c.values())\n return ''.join(letter * (m - c[letter]) for letter in ascii_lowercase)", "from collections import Counter\nfrom string import ascii_lowercase as alphabet\n\ndef missing_al...
{"fn_name": "missing_alphabets", "inputs": [["abcdefghijklmnopqrstuvwxy"], ["abcdefghijklmnopqrstuvwxyz"], ["aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy"], ["abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxy"], ["codewars"]], "outputs": [["z"], [""], ["zz"], ["ayzz"], ["bfghijklmnpqtuvxyz"]]}
introductory
https://www.codewars.com/kata/58a664bb586e986c940001d5
def missing_alphabets(s):
2,728
A common problem in number theory is to find x given a such that: a * x = 1 mod [n] Then x is called the inverse of a modulo n. Your goal is to code a function inverseMod wich take a and n as parameters and return x. You may be interested by these pages: http://en.wikipedia.org/wiki/Modular_multiplicative_invers...
["def egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n\n\ndef inverseMod(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n return None\n else:\n return x % m\n \n\n", "def gcd_ext(a, b):\n if b == 0:\n ...
{"fn_name": "inverseMod", "inputs": [[2, 5], [48, 101], [7, 733], [48, 733], [2, 733], [229, 101], [229, 103], [229, 105], [5, 5], [61965, 17408], [101014, 125445], [156435434, 3543432125]], "outputs": [[3], [40], [419], [168], [367], [15], [9], [94], [null], [null], [7969], [1056765589]]}
introductory
https://www.codewars.com/kata/53c945d750fe7094ee00016b
def inverseMod(a, m):
2,729
A few years ago, Aaron left his old school and registered at another due to security reasons. Now he wishes to find Jane, one of his schoolmates and good friends. There are `n` schools numbered from 1 to `n`. One can travel between each pair of schools by buying a ticket. The ticket between schools `i` and `j` costs `...
["def find_jane(n):\n return (n - 1) // 2", "import math\ndef find_jane(n):\n return math.ceil((n-2)/2)", "def find_jane(n):\n return (n-1) // 2\n \n\"\"\"\n1,2,3,...,n\ncost = (a+b) % (n+1)\n\nbest association is:\n b = n+1-a -> cost=0\n \n 1 2 3 4 5 -> 1 <-> 5\n 2 <-> 4\n\...
{"fn_name": "find_jane", "inputs": [[2], [10]], "outputs": [[0], [4]]}
introductory
https://www.codewars.com/kata/5bdc1558ab6bc57f47000b8e
def find_jane(n):
2,730
The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single `100`, `50` or `25` dollar bill. An "Avengers" ticket costs `25 dollars`. Vasya is currently working as a clerk. He wants to sell a ticket to every single person in thi...
["def tickets(people):\n till = {100.0:0, 50.0:0, 25.0:0}\n\n for paid in people:\n till[paid] += 1\n change = paid-25.0\n \n for bill in (50,25):\n while (bill <= change and till[bill] > 0):\n till[bill] -= 1\n change -= bill\n\n if change != 0:\n return 'NO'\n \n retur...
{"fn_name": "tickets", "inputs": [[[25, 25, 50]], [[25, 25, 50, 100]], [[25, 100]], [[25, 25, 25, 25, 25, 25, 25, 25, 25, 25]], [[50, 50, 50, 50, 50, 50, 50, 50, 50, 50]], [[100, 100, 100, 100, 100, 100, 100, 100, 100, 100]], [[25, 25, 25, 25, 50, 100, 50]], [[50, 100, 100]], [[25, 25, 100]], [[25, 25, 25, 25, 25, 25, ...
introductory
https://www.codewars.com/kata/555615a77ebc7c2c8a0000b8
def tickets(people):
2,731
###Instructions Write a function that takes a negative or positive integer, which represents the number of minutes before (-) or after (+) Sunday midnight, and returns the current day of the week and the current time in 24hr format ('hh:mm') as a string. ```python day_and_time(0) should return 'Sunday 00:00' d...
["from datetime import timedelta, datetime\ndef day_and_time(mins):\n return \"{:%A %H:%M}\".format(datetime(2017, 1, 1) + timedelta(minutes = mins))", "def day_and_time(mins):\n dow = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']\n return \"{} {:02d}:{:02d}\".format(dow[(mins // 144...
{"fn_name": "day_and_time", "inputs": [[0], [-3], [45], [759], [1236], [1447], [7832], [18876], [259180], [-349000]], "outputs": [["Sunday 00:00"], ["Saturday 23:57"], ["Sunday 00:45"], ["Sunday 12:39"], ["Sunday 20:36"], ["Monday 00:07"], ["Friday 10:32"], ["Saturday 02:36"], ["Thursday 23:40"], ["Tuesday 15:20"]]}
introductory
https://www.codewars.com/kata/56fac4cfda8ca6ec0f001746
def day_and_time(mins):
2,732
## Task You will receive a string consisting of lowercase letters, uppercase letters and digits as input. Your task is to return this string as blocks separated by dashes (`"-"`). The elements of a block should be sorted with respect to the hierarchy listed below, and each block cannot contain multiple instances of th...
["from collections import Counter\n\ndef blocks(s):\n sort = lambda c: (c.isdigit(), c.isupper(), c)\n answer, counter = [], Counter(s)\n while counter:\n block = ''.join(sorted(counter, key=sort))\n answer.append(block)\n counter = counter - Counter(block)\n return '-'.join(answer)", "...
{"fn_name": "blocks", "inputs": [["heyitssampletestkk"], ["dasf6ds65f45df65gdf651vdf5s1d6g5f65vqweAQWIDKsdds"], ["SDF45648374RHF8BFVYg378rg3784rf87g3278bdqG"], [""], ["aaaaaaaaaa"]], "outputs": [["aehiklmpsty-ekst-est"], ["adefgqsvwADIKQW1456-dfgsv156-dfs56-dfs56-dfs56-df56-d5-d"], ["bdfgqrBDFGHRSVY2345678-grF3478-gF34...
introductory
https://www.codewars.com/kata/5e0f6a3a2964c800238ca87d
def blocks(s):
2,733
Given a string of words (x), you need to return an array of the words, sorted alphabetically by the final character in each. If two words have the same last letter, they returned array should show them in the order they appeared in the given string. All inputs will be valid.
["def last(s):\n return sorted(s.split(), key=lambda x: x[-1])", "def last(s):\n return sorted(s.split(), key = lambda word: word[-1])", "from operator import itemgetter\n\ndef last(s):\n return sorted(s.split(), key=itemgetter(-1))", "def last(s):\n return sorted(s.split(\" \"), key=lambda w: w[-1])", "las...
{"fn_name": "last", "inputs": [["man i need a taxi up to ubud"], ["what time are we climbing up the volcano"], ["take me to semynak"], ["massage yes massage yes massage"], ["take bintang and a dance please"]], "outputs": [[["a", "need", "ubud", "i", "taxi", "man", "to", "up"]], [["time", "are", "we", "the", "climbing",...
introductory
https://www.codewars.com/kata/57eba158e8ca2c8aba0002a0
def last(s):
2,734
## The story you are about to hear is true Our cat, Balor, sadly died of cancer in 2015. While he was alive, the three neighborhood cats Lou, Mustache Cat, and Raoul all recognized our house and yard as Balor's territory, and would behave respectfully towards him and each other when they would visit. But after Balor...
["from itertools import combinations\nfrom math import hypot\n\ndef peaceful_yard(yard, d):\n cats = ((i, j) for i,r in enumerate(yard) for j,c in enumerate(r) if c in 'LMR')\n return all(hypot(q[0] - p[0], q[1] - p[1]) >= d for p,q in combinations(cats, 2))", "def peaceful_yard(yard, min_distance):\n # Extract ca...
{"fn_name": "peaceful_yard", "inputs": [[["------------", "------------", "-L----------", "------------", "------------", "------------"], 10], [["------------", "---M--------", "------------", "------------", "-------R----", "------------"], 6], [["-----------L", "--R---------", "------------", "------------", "------...
introductory
https://www.codewars.com/kata/5869848f2d52095be20001d1
def peaceful_yard(yard, min_distance):
2,735
# Definition **_Jumping number_** is the number that *All adjacent digits in it differ by 1*. ____ # Task **_Given_** a number, **_Find if it is Jumping or not_** . ____ # Warm-up (Highly recommended) # [Playing With Numbers Series](https://www.codewars.com/collections/playing-with-numbers) ___ # Notes * **_N...
["def jumping_number(number):\n arr = list(map(int, str(number)))\n return ('Not!!', 'Jumping!!')[all(map(lambda a, b: abs(a - b) == 1, arr, arr[1:]))]", "def jumping_number(number):\n digits = [int(char) for char in str(number)]\n if len(digits) == 1:\n return 'Jumping!!'\n else:\n deltas ...
{"fn_name": "jumping_number", "inputs": [[1], [7], [9], [23], [32], [79], [98], [987654322]], "outputs": [["Jumping!!"], ["Jumping!!"], ["Jumping!!"], ["Jumping!!"], ["Jumping!!"], ["Not!!"], ["Jumping!!"], ["Not!!"]]}
introductory
https://www.codewars.com/kata/5a54e796b3bfa8932c0000ed
def jumping_number(number):
2,736
Create a function that takes a list of one or more non-negative integers, and arranges them such that they form the largest possible number. Examples: `largestArrangement([4, 50, 8, 145])` returns 8504145 (8-50-4-145) `largestArrangement([4, 40, 7])` returns 7440 (7-4-40) `largestArrangement([4, 46, 7])` returns 74...
["from functools import cmp_to_key\n\ncmp = lambda a, b: int('%i%i' % (b, a)) - int('%i%i' % (a, b))\nlargest_arrangement = lambda n: int(''.join(str(i) for i in sorted(n, key = cmp_to_key(cmp))))", "def largest_arrangement(numbers):\n numbers = list(map(str, numbers))\n for x in range(len(numbers)):\n for...
{"fn_name": "largest_arrangement", "inputs": [[[50, 2, 1, 9]], [[3655, 89]], [[8]], [[12, 13, 89, 155, 8, 26, 0]], [[76, 4, 3, 81, 514, 6, 716]], [[817, 6879, 163, 348, 8, 22, 47]], [[411, 742, 89, 691, 284]], [[587, 625, 638, 898, 122]], [[797, 535, 210, 87]], [[5, 2, 1, 9, 50, 56]], [[197, 853, 819]], [[23044, 2, 762...
introductory
https://www.codewars.com/kata/59d902f627ee004281000160
def largest_arrangement(numbers):
2,737
You are given an array that of arbitrary depth that needs to be nearly flattened into a 2 dimensional array. The given array's depth is also non-uniform, so some parts may be deeper than others. All of lowest level arrays (most deeply nested) will contain only integers and none of the higher level arrays will contain ...
["def near_flatten(a):\n r = []\n for x in a:\n if isinstance(x[0], int): r.append(x)\n else: r.extend(near_flatten(x))\n return sorted(r)", "def near_flatten(xs):\n def f(xs):\n if all(not isinstance(x, list) for x in xs):\n yield xs\n return\n for x in xs:...
{"fn_name": "near_flatten", "inputs": [[[[1]]], [[[1, 2, 3], [4, 5, 6]]], [[[1, 2, 3], [[4, 5], [[6], [7, 8]]]]], [[[[1, 2, 3], [9, 10]], [[4, 5], [6, 7, 8]]]]], "outputs": [[[[1]]], [[[1, 2, 3], [4, 5, 6]]], [[[1, 2, 3], [4, 5], [6], [7, 8]]], [[[1, 2, 3], [4, 5], [6, 7, 8], [9, 10]]]]}
introductory
https://www.codewars.com/kata/5ae64f86783bb4722c0000d7
def near_flatten(nested):
2,738
An Ironman Triathlon is one of a series of long-distance triathlon races organized by the World Triathlon Corporaion (WTC). It consists of a 2.4-mile swim, a 112-mile bicycle ride and a marathon (26.2-mile) (run, raced in that order and without a break. It hurts... trust me. Your task is to take a distance that an ath...
["def i_tri(s):\n total = 2.4 + 112 + 26.2\n to_go = '%.2f to go!' % (total - s)\n \n return ( 'Starting Line... Good Luck!' if s == 0 else\n {'Swim': to_go} if s < 2.4 else\n {'Bike': to_go} if s < 2.4 + 112 else\n {'Run': to_go} if s < total - 10 else\n {'Run':...
{"fn_name": "i_tri", "inputs": [[36], [103], [0], [2], [151]], "outputs": [[{"Bike": "104.60 to go!"}], [{"Bike": "37.60 to go!"}], ["Starting Line... Good Luck!"], [{"Swim": "138.60 to go!"}], ["You're done! Stop running!"]]}
introductory
https://www.codewars.com/kata/57d001b405c186ccb6000304
def i_tri(s):
2,739
Find the sum of the odd numbers within an array, after cubing the initial integers. The function should return `undefined`/`None`/`nil`/`NULL` if any of the values aren't numbers. ~~~if:java,csharp Note: There are ONLY integers in the JAVA and C# versions of this Kata. ~~~ ~~~if:python Note: Booleans should not be c...
["def cube_odd(arr):\n return sum( n**3 for n in arr if n % 2 ) if all(type(n) == int for n in arr) else None", "def cube_odd(arr):\n if any(type(x) is not int for x in arr):\n return None\n return sum(x ** 3 for x in arr if x % 2 != 0)", "def cube_odd(arr):\n if len(set(map(type,arr))) < 2:\n ...
{"fn_name": "cube_odd", "inputs": [[[1, 2, 3, 4]], [[-3, -2, 2, 3]], [["a", 12, 9, "z", 42]], [[true, false, 2, 4, 1]]], "outputs": [[28], [0], [null], [null]]}
introductory
https://www.codewars.com/kata/580dda86c40fa6c45f00028a
def cube_odd(arr):
2,740
# Scenario With **_Cereal crops_** like wheat or rice, before we can eat the grain kernel, we need to remove that inedible hull, or *to separate the wheat from the chaff*. ___ # Task **_Given_** a *sequence of n integers* , **_separate_** *the negative numbers (chaff) from positive ones (wheat).* ___ # Notes * *...
["def wheat_from_chaff(values):\n i, j = 0, len(values)-1\n while True:\n while i < j and values[i] < 0: i += 1\n while i < j and values[j] > 0: j -= 1\n if i >= j: return values\n values[i], values[j] = values[j], values[i]", "def wheat_from_chaff(values):\n i, j = 0, len(values) -...
{"fn_name": "wheat_from_chaff", "inputs": [[[2, -4, 6, -6]], [[7, -3, -10]], [[7, -8, 1, -2]], [[8, 10, -6, -7, 9]], [[-3, 4, -10, 2, -6]], [[2, -6, -4, 1, -8, -2]], [[16, 25, -48, -47, -37, 41, -2]], [[-30, -11, 36, 38, 34, -5, -50]], [[-31, -5, 11, -42, -22, -46, -4, -28]], [[46, 39, -45, -2, -5, -6, -17, -32, 17]], ...
introductory
https://www.codewars.com/kata/5bdcd20478d24e664d00002c
def wheat_from_chaff(values):
2,741
The "Russian Peasant Method" is an old algorithm used by Russian peasants (and before them ancient Egyptians) to perform multiplication. Consider that X and Y are two numbers. X can be any number but Y must be a positive integer. To multiply X and Y: 1. Let the product = 0 2. If Y is odd, then the product = product ...
["def russian_peasant_multiplication(x, y):\n product = 0\n while y != 0:\n if y % 2 == 1:\n product += x\n x += x\n y //= 2\n \n return product", "def russian_peasant_multiplication(x, y, product=0):\n product += x if y % 2 else 0\n x += x\n y //= 2\n if y:\n...
{"fn_name": "russian_peasant_multiplication", "inputs": [[10, 5], [1.001, 2], [175, 18], [-2, 2], [2500, 123]], "outputs": [[50], [2.002], [3150], [-4], [307500]]}
introductory
https://www.codewars.com/kata/5870ef72aa04283934000043
def russian_peasant_multiplication(x, y):
2,742
Given a string and an array of index numbers, return the characters of the string rearranged to be in the order specified by the accompanying array. Ex: scramble('abcd', [0,3,1,2]) -> 'acdb' The string that you will be returning back will have: 'a' at index 0, 'b' at index 3, 'c' at index 1, 'd' at index 2, because...
["def scramble(string, array):\n return \"\".join(v for _, v in sorted(zip(array, string)))", "def scramble(string, array):\n res = array[:]\n for (i,a) in enumerate(array):\n res[a]=string[i]\n return \"\".join(res)\n", "def scramble(string, lst):\n result = [None] * len(string)\n for char, in...
{"fn_name": "scramble", "inputs": [["abcd", [0, 3, 1, 2]], ["sc301s", [4, 0, 3, 1, 5, 2]], ["bskl5", [2, 1, 4, 3, 0]]], "outputs": [["acdb"], ["c0s3s1"], ["5sblk"]]}
introductory
https://www.codewars.com/kata/5822d89270ca28c85c0000f3
def scramble(string, array):
2,743
Program a function `sumAverage(arr)` where `arr` is an array containing arrays full of numbers, for example: ```python sum_average([[1, 2, 2, 1], [2, 2, 2, 1]]) ``` First, determine the average of each array. Then, return the sum of all the averages. - All numbers will be less than 100 and greater than -100. - `arr`...
["from statistics import mean\nfrom math import floor\n\ndef sum_average(arr):\n return floor(sum(map(mean, arr)))", "from statistics import mean\nfrom math import floor\n\ndef sum_average(arr):\n return floor(sum(mean(lst) for lst in arr))", "import math\n\ndef sum_average(arr):\n return math.floor(sum([sum(a...
{"fn_name": "sum_average", "inputs": [[[[1, 2, 2, 1], [2, 2, 2, 1]]], [[[52, 64, 84, 21, 54], [44, 87, 46, 90, 43]]], [[[44, 76, 12], [96, 12, 34, 53, 76, 34, 56, 86, 21], [34, 65, 34, 76, 34, 87, 34]]], [[[41, 16, 99, 93, 59, 18, 35, 23, 55, 45, 38, 39, 74, 60, 95, 44, 59, 70, 44, 89, 90, 19, 23, 67, 65, 66, 41, 89, 4...
introductory
https://www.codewars.com/kata/56d5166ec87df55dbe000063
def sum_average(arr):
2,744
Create a function that interprets code in the esoteric language **Poohbear** ## The Language Poohbear is a stack-based language largely inspired by Brainfuck. It has a maximum integer value of 255, and 30,000 cells. The original intention of Poohbear was to be able to send messages that would, to most, be completely ...
["from operator import add, mul, floordiv as fdiv, pow\n\ndef poohbear(s):\n \n def updateMem(func, v): mem[p] = func(mem.get(p, 0), v) % 256\n\n braces, stack = {}, []\n for i,c in enumerate(s):\n if c == 'W': stack.append(i)\n if c == 'E':\n braces[i] = stack[-1]\n brac...
{"fn_name": "poohbear", "inputs": [["LQTcQAP>pQBBTAI-PA-PPL+P<BVPAL+T+P>PL+PBLPBP<DLLLT+P"], ["LLQT+P >LLLc+QIT-P AAAP P"], ["LLQT>+WN+<P>E"], ["cW>LQQT+P<pE"], ["+W>LQQT+P<-E"], ["+LTQII>+WN<P>+E"], ["+LTQIITTIWP-E"], ["LILcABNBpYDYYYYLLL+P-+W-EQNW-ELLQUTTTT+P"], ["++W-NE"], ["W>UQLIPNPPP45vSDFJLLIPNPqwVMT<E"], ["LLIL...
introductory
https://www.codewars.com/kata/59a9735a485a4d807f00008a
def poohbear(s):
2,745
The Tower of Hanoi problem involves 3 towers. A number of rings decreasing in size are placed on one tower. All rings must then be moved to another tower, but at no point can a larger ring be placed on a smaller ring. Your task: Given a number of rings, return the MINIMUM number of moves needed to move all the ring...
["def tower_of_hanoi(rings):\n return 2**rings - 1", "def tower_of_hanoi(rings):\n moves = 2**rings - 1\n return moves", "def tower_of_hanoi(rings):\n answer = 1\n for i in range(rings-1):\n answer = (answer *2) +1\n return answer", "def tower_of_hanoi(r):\n return ~(-1<<r)", "def tower_of_h...
{"fn_name": "tower_of_hanoi", "inputs": [[4], [5], [10], [50]], "outputs": [[15], [31], [1023], [1125899906842623]]}
introductory
https://www.codewars.com/kata/5899f1df27926b7d000000eb
def tower_of_hanoi(rings):
2,746
Check if it is a vowel(a, e, i, o, u,) on the ```n``` position in a string (the first argument). Don't forget about uppercase. A few cases: ``` { checkVowel('cat', 1) -> true // 'a' is a vowel checkVowel('cat', 0) -> false // 'c' is not a vowel checkVowel('cat', 4) -> false // this position doesn't exist } `...
["def check_vowel(s,i):\n return 0 <= i < len(s) and s[i] in \"aieouAEIOU\"", "def check_vowel(string, position):\n return 0 <= position < len(string) and string[position].lower() in \"aeiou\"", "def check_vowel(string, position):\n if position < 0:\n return False\n try:\n return string[position]...
{"fn_name": "check_vowel", "inputs": [["cat", 1], ["cat", 0], ["cat", 4], ["Amanda", -2], ["Amanda", 0], ["Amanda", 2]], "outputs": [[true], [false], [false], [false], [true], [true]]}
introductory
https://www.codewars.com/kata/5a2b7edcb6486a856e00005b
def check_vowel(string, position):
2,747
We are given a sequence of coplanar points and see all the possible triangles that may be generated which all combinations of three points. We have the following list of points with the cartesian coordinates of each one: ``` Points [x, y] A [1, 2] B [3, 3] C [4, 1] D [1, 1] E [4, -1] ``` With ...
["from itertools import combinations\n\n\ndef isRect(a,b,c):\n X,Y,Z = sorted( sum( (q-p)**2 for p,q in zip(p1,p2)) for p1,p2 in [(a,b), (a,c), (b,c)] )\n return X+Y == Z\n\ndef count_rect_triang(points):\n return sum( isRect(*c) for c in combinations(set(map(tuple, points)), 3) )", "from itertools import comb...
{"fn_name": "count_rect_triang", "inputs": [[[[1, 2], [3, 3], [4, 1], [1, 1], [4, -1]]], [[[1, 2], [4, -1], [3, 3], [4, -1], [4, 1], [1, 1], [4, -1], [4, -1], [3, 3], [1, 2]]]], "outputs": [[3], [3]]}
introductory
https://www.codewars.com/kata/57d99f6bbfcdc5b3b0000286
def count_rect_triang(points):
2,748
Given: an array containing hashes of names Return: a string formatted as a list of names separated by commas except for the last two names, which should be separated by an ampersand. Example: ``` ruby list([ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Maggie'} ]) # returns 'Bart, Lisa & Maggie' list([ {name: 'Bart'}, {...
["def namelist(names):\n if len(names) > 1:\n return '{} & {}'.format(', '.join(name['name'] for name in names[:-1]), \n names[-1]['name'])\n elif names:\n return names[0]['name']\n else:\n return ''", "def namelist(names):\n if len(names)==0: return ''\n ...
{"fn_name": "namelist", "inputs": [[[{"name": "Bart"}, {"name": "Lisa"}, {"name": "Maggie"}, {"name": "Homer"}, {"name": "Marge"}]], [[{"name": "Bart"}, {"name": "Lisa"}, {"name": "Maggie"}]], [[{"name": "Bart"}, {"name": "Lisa"}]], [[{"name": "Bart"}]], [[]]], "outputs": [["Bart, Lisa, Maggie, Homer & Marge"], ["Bart,...
introductory
https://www.codewars.com/kata/53368a47e38700bd8300030d
def namelist(names):
2,749
In this Kata, you will be given an array and your task will be to determine if an array is in ascending or descending order and if it is rotated or not. Consider the array `[1,2,3,4,5,7,12]`. This array is sorted in `Ascending` order. If we rotate this array once to the left, we get `[12,1,2,3,4,5,7]` and twice-rotat...
["def solve(lst):\n a, b, c = lst[0] < lst[1], lst[1] < lst[2], lst[-1] < lst[0]\n m = a if a == b else c\n return ('R' if c == m else '') + ('A' if m else 'D')", "def solve(arr):\n if sorted(arr) == arr:\n return \"A\"\n if sorted(arr)[::-1] == arr:\n return \"D\"\n return \"RA\" if arr...
{"fn_name": "solve", "inputs": [[[1, 2, 3, 4, 5, 7]], [[7, 1, 2, 3, 4, 5]], [[2, 3, 4, 5, 7, 12]], [[7, 12, 1, 2, 3, 4, 5]], [[4, 5, 6, 1, 2, 3]], [[9, 8, 7, 6, 5]], [[5, 9, 8, 7, 6]], [[6, 5, 9, 8, 7]], [[9, 6, 7]], [[10, 12, 11]], [[13, 10, 11]]], "outputs": [["A"], ["RA"], ["A"], ["RA"], ["RA"], ["D"], ["RD"], ["RD"...
introductory
https://www.codewars.com/kata/5a16cab2c9fc0e09ce000097
def solve(arr):
2,750
# Task You are given a positive integer `n`. We intend to make some ascending sequences according to the following rules: 1. Make a sequence of length 1: [ n ] 2. Or, insert a number to the left side of the sequence. But this number can not exceed half of the first number of the sequence. 3. Follow rule 2, cont...
["from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef make_sequences(n):\n return 1 + sum(map(make_sequences, range(1, n//2+1)))", "RESULTS = [1,1,2,2,4,4,6,6,10,10,14,14,20,20,26,26,36,36,46,46,60,60,74,74,94,94,114,114,140,140,166,166,202,202,238,238,284,284,330,330,390,390,450,450,524,524,598,598,692...
{"fn_name": "make_sequences", "inputs": [[6], [10], [1000]], "outputs": [[6], [14], [1981471878]]}
introductory
https://www.codewars.com/kata/5be0f1786279697939000157
def make_sequences(n):
2,751
Write a method that will search an array of strings for all strings that contain another string, ignoring capitalization. Then return an array of the found strings. The method takes two parameters, the query string and the array of strings to search, and returns an array. If the string isn't contained in any of the...
["def word_search(query, seq):\n return [x for x in seq if query.lower() in x.lower()] or [\"None\"]", "def word_search(query, seq):\n query = query.lower()\n result = [x for x in seq if query in x.lower()]\n return result if result else ['None']", "import re\n\ndef word_search(query, seq):\n return [w f...
{"fn_name": "word_search", "inputs": [["ab", ["za", "ab", "abc", "zab", "zbc"]], ["aB", ["za", "ab", "abc", "zab", "zbc"]], ["ab", ["za", "aB", "Abc", "zAB", "zbc"]], ["abcd", ["za", "aB", "Abc", "zAB", "zbc"]]], "outputs": [[["ab", "abc", "zab"]], [["ab", "abc", "zab"]], [["aB", "Abc", "zAB"]], [["None"]]]}
introductory
https://www.codewars.com/kata/54b81566cd7f51408300022d
def word_search(query, seq):
2,752
Given a sorted array of numbers, return the summary of its ranges. ## Examples ```python summary_ranges([1, 2, 3, 4]) == ["1->4"] summary_ranges([1, 1, 1, 1, 1]) == ["1"] summary_ranges([0, 1, 2, 5, 6, 9]) == ["0->2", "5->6", "9"] summary_ranges([0, 1, 2, 3, 3, 3, 4, 5, 6, 7]) == ["0->7"] summary_ranges([0, 1, 2, 3, 3...
["def summary_ranges(nums):\n ret, s = [], float('-inf')\n for e, n in zip([s] + nums, nums + [-s]):\n if n - e > 1:\n ret.append(['{}', '{}->{}'][s<e].format(s,e))\n s = n\n return ret[1:]", "def summary_ranges(nums):\n if not nums:\n return []\n ranges = []\n firs...
{"fn_name": "summary_ranges", "inputs": [[[]], [[1, 1, 1, 1]], [[1, 2, 3, 4]], [[0, 1, 2, 5, 6, 9]], [[0, 1, 2, 3, 4, 5, 6, 7]], [[0, 1, 2, 3, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7, 9, 10]], [[-2, 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 12]], [[-3, -2, -1, 0, 2, 3]], [[-2]]], "outputs": [[[]], [["1"]], [["1->4"]], [["0->2", "5->6...
introductory
https://www.codewars.com/kata/55fb6537544ae06ccc0000dc
def summary_ranges(nums):
2,753
KISS stands for Keep It Simple Stupid. It is a design principle for keeping things simple rather than complex. You are the boss of Joe. Joe is submitting words to you to publish to a blog. He likes to complicate things. Define a function that determines if Joe's work is simple or complex. Input will be non emtpy st...
["def is_kiss(words):\n wordsL = words.split(' ')\n l = len(wordsL)\n for word in wordsL:\n if len(word) > l: return \"Keep It Simple Stupid\"\n return \"Good work Joe!\"", "def is_kiss(words):\n words = words.split(\" \")\n return \"Keep It Simple Stupid\" if any(len(word)>len(words) for word ...
{"fn_name": "is_kiss", "inputs": [["Joe had a bad day"], ["Joe had some bad days"], ["Joe is having no fun"], ["Sometimes joe cries for hours"], ["Joe is having lots of fun"], ["Joe is working hard a lot"], ["Joe listened to the noise and it was an onamonapia"], ["Joe listened to the noises and there were some onamonap...
introductory
https://www.codewars.com/kata/57eeb8cc5f79f6465a0015c1
def is_kiss(words):
2,754
Oh no! You have stumbled upon a mysterious signal consisting of beeps of various lengths, and it is of utmost importance that you find out the secret message hidden in the beeps. There are long and short beeps, the longer ones roughly three times as long as the shorter ones. Hmm... that sounds familiar. That's righ...
["lm = ['.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-', '-.--', '--..', '-----', '.----', '..---', '...--', '....-', '.....', '-....', '--...', '---..', '----.']\nll = \"abcdefghijklmnopqrstuvwxyz01...
{"fn_name": "decode", "inputs": [[".... . .-.. .-.. --- .-- --- .-. .-.. -.."], [".---- ... - .- -. -.. ..--- -. -.."], [".. .- -- .- - . ... -"], [".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. ----- .---- ..--- ...-- ....- ..... -.... --... ---.. ---...
introductory
https://www.codewars.com/kata/54b0306c56f22d0bf9000ffb
def decode(s):
2,755
Return a new array consisting of elements which are multiple of their own index in input array (length > 1). Some cases: ``` [22, -6, 32, 82, 9, 25] => [-6, 32, 25] [68, -1, 1, -7, 10, 10] => [-1, 10] [-56,-85,72,-26,-14,76,-27,72,35,-21,-67,87,0,21,59,27,-92,68] => [-85, 72, 0, 68] ```
["def multiple_of_index(l):\n return [l[i] for i in range(1, len(l)) if l[i] % i == 0]", "def multiple_of_index(arr):\n return [val for index, val in enumerate(arr) if index and val % index == 0]\n\n", "def multiple_of_index(arr):\n return [arr[i] for i in range(1,len(arr)) if arr[i] % i == 0]\n", "def multipl...
{"fn_name": "multiple_of_index", "inputs": [[[22, -6, 32, 82, 9, 25]], [[68, -1, 1, -7, 10, 10]], [[11, -11]], [[-56, -85, 72, -26, -14, 76, -27, 72, 35, -21, -67, 87, 0, 21, 59, 27, -92, 68]], [[28, 38, -44, -99, -13, -54, 77, -51]], [[-1, -49, -1, 67, 8, -60, 39, 35]]], "outputs": [[[-6, 32, 25]], [[-1, 10]], [[-11]]...
introductory
https://www.codewars.com/kata/5a34b80155519e1a00000009
def multiple_of_index(arr):
2,756
The number `1035` is the smallest integer that exhibits a non frequent property: one its multiples, `3105 = 1035 * 3`, has its same digits but in different order, in other words, `3105`, is one of the permutations of `1035`. The number `125874` is the first integer that has this property when the multiplier is `2`, th...
["from bisect import bisect\n\nmemo = {3: [3105, 7425, 30105, 31050, 37125, 42741, 44172, 71253, 72441, 74142, 74250, 74628, 74925, 82755, 85725],\n 4: [7128, 8712, 67128, 70416, 71208, 71280, 71328, 71928, 72108, 78912, 79128, 80712, 86712, 87120, 87132, 87192, 87912, 95832],\n 5: [],\n 6: [8316, ...
{"fn_name": "search_permMult", "inputs": [[10000, 7], [5000, 7], [10000, 4], [8000, 4], [5000, 3], [10000, 3]], "outputs": [[1], [0], [2], [1], [1], [2]]}
introductory
https://www.codewars.com/kata/55f1a53d9c77b0ed4100004e
def search_permMult(nMax, k):
2,757
Your users passwords were all stole in the Yahoo! hack, and it turns out they have been lax in creating secure passwords. Create a function that checks their new password (passed as a string) to make sure it meets the following requirements: Between 8 - 20 characters Contains only the following characters: (and at ...
["import re;\ndef check_password(s):\n if re.search('^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\\d)(?=.*?[!@#$%^&*?])[a-zA-Z\\d!@#$%^&*?]{8,20}$', s) :\n return 'valid'\n else:\n return 'not valid'", "import re\n\ndef check_password(s):\n m = re.match(r'(?=.{8,20}$)(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%...
{"fn_name": "check_password", "inputs": [[""], ["password"], ["P1@p"], ["P1@pP1@p"], ["P1@pP1@pP1@pP1@pP1@pP1@p"]], "outputs": [["not valid"], ["not valid"], ["not valid"], ["valid"], ["not valid"]]}
introductory
https://www.codewars.com/kata/57e35f1bc763b8ccce000038
def check_password(s):
2,758
## Welcome to my (amazing) kata! You are given a gigantic number to decode. Each number is a code that alternates in a pattern between encoded text and a smaller, encoded number. The pattern's length varies with every test, but the alternation between encoded text and an encoded number will always be there. Followi...
["def decode(number):\n return ', '.join(\n str(int(w, 2)) if i % 2 else\n ''.join( chr(int(w[x:x+3])-4) for x in range(0, len(w), 3) )\n for i, w in enumerate( str(number).strip('98').split('98') )\n )", "def decode(number):\n split = str(number).replace('98', ' ').split()\n split[...
{"fn_name": "decode", "inputs": [[103115104105123101118119981001098], [103115104105123101118119981001098103115104105123101118119981001098103115104105123101118119981001098], [10910111611511211510710912610510611511810811512311912012111610910412010810911911110112010110911998100109810512210511412010811512110710810912011910...
introductory
https://www.codewars.com/kata/5940ec284aafb87ef3000028
def decode(number):
2,759
```if-not:ruby Create a function, that accepts an arbitrary number of arrays and returns a single array generated by alternately appending elements from the passed in arguments. If one of them is shorter than the others, the result should be padded with empty elements. ``` ```if:ruby Create a function, that accepts an ...
["from itertools import chain, zip_longest\n\ndef interleave(*args):\n return list(chain.from_iterable(zip_longest(*args)))", "def interleave(*args):\n max_len = max(map(len,args))\n interleaved = []\n \n for i in range(max_len):\n for arr in args:\n if i < len(arr):\n in...
{"fn_name": "interleave", "inputs": [[[1, 2, 3], ["c", "d", "e"]], [[1, 2, 3], [4, 5]], [[1, 2], [3, 4, 5]], [[null], [null, null], [null, null, null]], [[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[]]], "outputs": [[[1, "c", 2, "d", 3, "e"]], [[1, 4, 2, 5, 3, null]], [[1, 3, 2, 4, null, 5]], [[null, null, null, null, null, nul...
introductory
https://www.codewars.com/kata/523d2e964680d1f749000135
def interleave(*args):
2,760
How many licks does it take to get to the tootsie roll center of a tootsie pop? A group of engineering students from Purdue University reported that its licking machine, modeled after a human tongue, took an average of 364 licks to get to the center of a Tootsie Pop. Twenty of the group's volunteers assumed the lickin...
["def total_licks(env):\n d = 252\n vm = 0\n for k,v in env.items():\n d+=v\n if v > vm:\n vm, km = v, k\n return 'It took ' + str(d) + ' licks to get to the tootsie roll center of a tootsie pop.' + (' The toughest challenge was ' + km + '.' if vm > 0 else '')", "from operator impor...
{"fn_name": "total_licks", "inputs": [[{"freezing temps": 10, "clear skies": -2}], [{"happiness": -5, "clear skies": -2}], [{}], [{"dragons": 100, "evil wizards": 110, "trolls": 50}], [{"white magic": -250}]], "outputs": [["It took 260 licks to get to the tootsie roll center of a tootsie pop. The toughest challenge was...
introductory
https://www.codewars.com/kata/566091b73e119a073100003a
def total_licks(env):