problem_id
stringlengths
32
32
name
stringclasses
1 value
problem
stringlengths
200
14k
solutions
stringlengths
12
1.12M
test_cases
stringlengths
37
74M
difficulty
stringclasses
3 values
language
stringclasses
1 value
source
stringclasses
7 values
num_solutions
int64
12
1.12M
starter_code
stringlengths
0
956
a2bb88c9ce3441c5b281eb80ac02b0f4
UNKNOWN
On Unix system type files can be identified with the ls -l command which displays the type of the file in the first alphabetic letter of the file system permissions field. You can find more information about file type on Unix system on the [wikipedia page](https://en.wikipedia.org/wiki/Unix_file_types). - '-' A regula...
["dict = {'-':\"file\",'d':\"directory\",'l':\"symlink\",'c':\"character_file\",'b':\"block_file\",'p':\"pipe\",'s':\"socket\",'D':\"door\"}\ndef linux_type(file_attribute):\n return dict[file_attribute[0]]", "def linux_type(s):\n return {x: y for x, y in zip(\"-dlcbpsD\", \"file directory symlink character_file ...
{"fn_name": "linux_type", "inputs": [["-rwxrwxrwx"], ["Drwxr-xr-x"], ["lrwxrw-rw-"], ["srwxrwxrwx"]], "outputs": [["file"], ["door"], ["symlink"], ["socket"]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,962
def linux_type(file_attribute):
4f4df72054b7a117397404bcef5f9a17
UNKNOWN
Given two arrays of integers `m` and `n`, test if they contain *at least* one identical element. Return `true` if they do; `false` if not. Your code must handle any value within the range of a 32-bit integer, and must be capable of handling either array being empty (which is a `false` result, as there are no duplicate...
["def duplicate_elements(m, n):\n return not set(m).isdisjoint(n)", "def duplicate_elements(m, n):\n return any(x in n for x in m)", "def duplicate_elements(m, n):\n return bool(set(m) & set(n))", "def duplicate_elements(m, n):\n return bool(set(m).intersection(n))", "def duplicate_elements(m, n):\n retu...
{"fn_name": "duplicate_elements", "inputs": [[[1, 2, 3, 4, 5], [1, 6, 7, 8, 9]], [[9, 8, 7], [8, 1, 3]], [[2398632, 9172846, 4728162], [2398632, 9235623, 8235492]], [[-2, -4, -6, -8], [-2, -3, -5, -7]], [[-9, -8, -7], [-8, -1, -3]], [[-2398632, -9172846, -4728162], [-2398632, -9235623, -8235492]], [[1, 3, 5, 7, 9], [2,...
INTRODUCTORY
PYTHON3
CODEWARS
824
def duplicate_elements(m, n):
37d0344c1a53be0db9efd3f5750646d2
UNKNOWN
The prime numbers are not regularly spaced. For example from `2` to `3` the step is `1`. From `3` to `5` the step is `2`. From `7` to `11` it is `4`. Between 2 and 50 we have the following pairs of 2-steps primes: `3, 5 - 5, 7, - 11, 13, - 17, 19, - 29, 31, - 41, 43` We will write a function `step` with parameters: ...
["import math\ndef isPrime(n):\n if n <= 1:\n return False\n for i in range(2,int(math.sqrt(n)+1)):\n if n % i == 0:\n return False\n return True\n\ndef step(g,m,n):\n if m >= n:\n return []\n else:\n for i in range(m,n+1-g):\n if isPrime(i) and isPrime(i...
{"fn_name": "step", "inputs": [[2, 100, 110], [4, 100, 110], [6, 100, 110], [8, 300, 400], [10, 300, 400], [4, 30000, 100000], [6, 30000, 100000], [8, 30000, 100000], [11, 30000, 100000], [16, 5, 20], [2, 10000000, 11000000], [52, 1300, 15000], [10, 4900, 5000], [30, 4900, 5000], [2, 4900, 5000], [2, 104000, 105000], [...
INTRODUCTORY
PYTHON3
CODEWARS
3,860
def step(g, m, n):
c33207c497823d3d346b4b986163373e
UNKNOWN
Given some points (cartesian coordinates), return true if all of them lie on a line. Treat both an empty set and a single point as a line. ```python on_line(((1,2), (7,4), (22,9)) == True on_line(((1,2), (-3,-14), (22,9))) == False ```
["def on_line(points):\n points = list(set(points))\n cross_product = lambda a, b, c: a[0]*(b[1]-c[1]) + b[0]*(c[1]-a[1]) + c[0]*(a[1]-b[1])\n return all(cross_product(p, *points[:2]) == 0 for p in points[2:])", "from functools import partial\n\ndef collinear(p1, p2, p3):\n return (p3[1] - p2[1])*(p2[0] - p...
{"fn_name": "on_line", "inputs": [[[]], [[1, 1]]], "outputs": [[true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,514
def on_line(points):
065b50a10e67735707540743f07769a5
UNKNOWN
## Description Your job is to create a simple password validation function, as seen on many websites. The rules for a valid password are as follows: - There needs to be at least 1 uppercase letter. - There needs to be at least 1 lowercase letter. - There needs to be at least 1 number. - The password needs to be at le...
["CRITERIA = (str.islower, str.isupper, str.isdigit)\n\ndef password(s):\n return len(s)>7 and all( any(map(f,s)) for f in CRITERIA)", "import re\n\ndef password(s):\n return bool(re.match(r'(?=.*[A-Z])(?=.*[a-z])(?=.*\\d).{8}', s))", "import re \n\ndef password(string):\n patterns = (r'[A-Z]', r'[a-z]', r'[0-...
{"fn_name": "password", "inputs": [["Abcd1234"], ["Abcd123"], ["abcd1234"], ["AbcdefGhijKlmnopQRsTuvwxyZ1234567890"], ["ABCD1234"], ["Ab1!@#$%^&*()-_+={}[]|\\:;?/>.<,"], ["!@#$%^&*()-_+={}[]|\\:;?/>.<,"], [""], [" aA1----"], ["4aA1----"]], "outputs": [[true], [false], [false], [true], [false], [true], [false], [false],...
INTRODUCTORY
PYTHON3
CODEWARS
3,330
def password(string):
281411e0638063ba7021f3f1703c4859
UNKNOWN
Deoxyribonucleic acid, DNA is the primary information storage molecule in biological systems. It is composed of four nucleic acid bases Guanine ('G'), Cytosine ('C'), Adenine ('A'), and Thymine ('T'). Ribonucleic acid, RNA, is the primary messenger molecule in cells. RNA differs slightly from DNA its chemical structu...
["def dna_to_rna(dna):\n return dna.replace(\"T\", \"U\")", "dna_to_rna = lambda s: s.replace('T', 'U')", "def dna_to_rna(dna):\n rna = []\n for x in dna:\n if x == 'T':\n rna.append('U')\n else:\n rna.append(x)\n return ''.join(rna)\n", "dna_to_rna = lambda dna:dna.trans...
{"fn_name": "dna_to_rna", "inputs": [["TTTT"], ["GCAT"], ["GACCGCCGCC"], ["GATTCCACCGACTTCCCAAGTACCGGAAGCGCGACCAACTCGCACAGC"], ["CACGACATACGGAGCAGCGCACGGTTAGTACAGCTGTCGGTGAACTCCATGACA"], ["AACCCTGTCCACCAGTAACGTAGGCCGACGGGAAAAATAAACGATCTGTCAATG"], ["GAAGCTTATCCGTTCCTGAAGGCTGTGGCATCCTCTAAATCAGACTTGGCTACGCCGTTAGCCGAGGGCTT...
INTRODUCTORY
PYTHON3
CODEWARS
13,143
def dna_to_rna(dna):
7a4f2c6f0dc160f37e57b26a62481c6f
UNKNOWN
Iahub got bored, so he invented a game to be played on paper.  He writes n integers a1, a2, ..., an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1 ≤ i ≤ j ≤ n) and flips all values ak for which their positions are in range [i, j] (that is i ≤ k ≤ j)....
["def flipping_game(num):\n current = 0\n biggest = 0\n for i in num:\n current = max(0, current - ( i or -1 ) )\n biggest = max(biggest, current)\n \n return sum(num) + (biggest or -1)", "def flipping_game(num):\n return max([sum(num) + num[i: j + 1].count(0) - num[i: j + 1].count(1...
{"fn_name": "flipping_game", "inputs": [[[1, 0, 0, 1, 0, 0]], [[1, 0, 0, 1]], [[1]], [[0]], [[1, 0, 0, 0, 1, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1...
INTRODUCTORY
PYTHON3
CODEWARS
2,763
def flipping_game(num):
ae023de4b1d7819a23c88b8c36595cb1
UNKNOWN
Check your arrows You have a quiver of arrows, but some have been damaged. The quiver contains arrows with an optional range information (different types of targets are positioned at different ranges), so each item is an arrow. You need to verify that you have some good ones left, in order to prepare for battle: ```py...
["def any_arrows(arrows):\n return any(not i.get(\"damaged\", False) for i in arrows)\n", "def any_arrows(arrows):\n return any(not arrow.get('damaged', False) for arrow in arrows)\n", "def any_arrows(arrows):\n return any([True for a in arrows if 'damaged' not in a or a['damaged'] == False])", "def any_arrows...
{"fn_name": "any_arrows", "inputs": [[[]], [[{"range": 5, "damaged": false}]], [[{"range": 5, "damaged": false}, {"range": 15, "damaged": true}]], [[{"range": 5}, {"range": 10, "damaged": true}, {"damaged": true}]], [[{"range": 10, "damaged": true}, {"damaged": true}]]], "outputs": [[false], [true], [true], [true], [fa...
INTRODUCTORY
PYTHON3
CODEWARS
17,468
def any_arrows(arrows):
d23ffe995dc74faa1080c4ee2f7a83e2
UNKNOWN
This function should take two string parameters: a person's name (`name`) and a quote of theirs (`quote`), and return a string attributing the quote to the person in the following format: ```python '[name] said: "[quote]"' ``` For example, if `name` is `'Grae'` and `'quote'` is `'Practice makes perfect'` then your fu...
["def quotable(name, quote):\n return '{} said: \"{}\"'.format(name, quote)", "def quotable(name, quote):\n return f'{name} said: \"{quote}\"'", "def quotable(name, quote):\n return name + ' said: ' + '\"' + quote + '\"'", "quotable = '{} said: \"{}\"'.format\n", "def quotable(name, quote):\n said = \" said...
{"fn_name": "quotable", "inputs": [["Grae", "Practice makes perfect"], ["Dan", "Get back to work, Grae"], ["Alex", "Python is great fun"], ["Bethany", "Yes, way more fun than R"], ["Darrell", "What the heck is this thing?"]], "outputs": [["Grae said: \"Practice makes perfect\""], ["Dan said: \"Get back to work, Grae\""...
INTRODUCTORY
PYTHON3
CODEWARS
888
def quotable(name, quote):
a39db81876bc3ce609ccbda239e1824f
UNKNOWN
You have to create a method "compoundArray" which should take as input two int arrays of different length and return one int array with numbers of both arrays shuffled one by one. ```Example: Input - {1,2,3,4,5,6} and {9,8,7,6} Output - {1,9,2,8,3,7,4,6,5,6} ```
["def compound_array(a, b):\n x = []\n while a or b:\n if a: x.append(a.pop(0))\n if b: x.append(b.pop(0))\n return x", "def compound_array(a, b):\n x = min(map(len,(a,b)))\n return sum(map(list,zip(a,b)),[]) + a[x:] + b[x:]", "def compound_array(a, b):\n\n res = []\n \n for i in range(max(l...
{"fn_name": "compound_array", "inputs": [[[1, 2, 3, 4, 5, 6], [9, 8, 7, 6]], [[0, 1, 2], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]], [[11, 12], [21, 22, 23, 24]], [[2147483647, 2147483646, 2147483645, 2147483644, 2147483643], [9]], [[214, 215, 216, 217, 218], []], [[], [214, 215, 219, 217, 218]], [[], []]], "outputs": [[[1, 9, 2,...
INTRODUCTORY
PYTHON3
CODEWARS
1,643
def compound_array(a, b):
176afd9210f5b52c5338da4596e925ef
UNKNOWN
## The Problem James is a DJ at a local radio station. As it's getting to the top of the hour, he needs to find a song to play that will be short enough to fit in before the news block. He's got a database of songs that he'd like you to help him filter in order to do that. ## What To Do Create `longestPossible`(`lon...
["songs = [{'artist': 'Marillion', 'title': 'Keyleigh', 'playback': '03:36'}, {'artist': 'Pink Floyd', 'title': 'Time', 'playback': '06:48'}, {'artist': 'Rush', 'title': 'YYZ', 'playback': '04:27'}, {'artist': 'Bonobo', 'title': 'Days To Come', 'playback': '03:50'}, {'artist': 'Coldplay', 'title': 'Yellow', 'playback':...
{"fn_name": "longest_possible", "inputs": [[215], [270], [13], [300]], "outputs": [["For Reasons Unknown"], ["YYZ"], [false], ["Surfing With The Alien"]]}
INTRODUCTORY
PYTHON3
CODEWARS
9,700
songs = [{'artist': 'Marillion', 'title': 'Keyleigh', 'playback': '03:36'}, {'artist': 'Pink Floyd', 'title': 'Time', 'playback': '06:48'}, {'artist': 'Rush', 'title': 'YYZ', 'playback': '04:27'}, {'artist': 'Bonobo', 'title': 'Days To Come', 'playback': '03:50'}, {'artist': 'Coldplay', 'title': 'Yellow', 'playback': ...
7d5cd9b60f33941105c15dba5355e474
UNKNOWN
# Task You are given a function that should insert an asterisk (`*`) between every pair of **even digits** in the given input, and return it as a string. If the input is a sequence, concat the elements first as a string. ## Input The input can be an integer, a string of digits or a sequence containing integers onl...
["import re\n\ndef asterisc_it(s):\n if isinstance(s,int): s=str(s)\n elif isinstance(s,list): s=''.join(map(str,s))\n return re.sub(r'(?<=[02468])(?=[02468])', '*', s)", "def asterisc_it(n): \n if type(n) == list: n = \"\".join(str(i) for i in n)\n if type(n) == int : n = str(n)\n return \"\".join...
{"fn_name": "asterisc_it", "inputs": [[5312708], [9682135], [2222], [1111], [9999], ["0000"], [8], [2], [0], [[1, 4, 64, 68, 67, 23, 1]]], "outputs": [["531270*8"], ["96*8*2135"], ["2*2*2*2"], ["1111"], ["9999"], ["0*0*0*0"], ["8"], ["2"], ["0"], ["14*6*4*6*8*67231"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,269
def asterisc_it(n):
c3b3c49313fce6c4cc9e59b16ff8619f
UNKNOWN
A [Mersenne prime](https://en.wikipedia.org/wiki/Mersenne_prime) is a prime number that can be represented as: Mn = 2^(n) - 1. Therefore, every Mersenne prime is one less than a power of two. Write a function that will return whether the given integer `n` will produce a Mersenne prime or not. The tests will check ra...
["def valid_mersenne(n):\n return n in {2,3,5,7,13,17,19,31,61,89,107,127,521,607,1279}", "def valid_mersenne(n):\n '''Currently using the Lucas-Lehmer test.'''\n \n if n < 2:\n return False\n \n if n == 2:\n return True\n \n mersenne = 2**n - 1\n \n residue = 4\n for _ in...
{"fn_name": "valid_mersenne", "inputs": [[2], [3], [5], [7], [11], [13], [17], [19], [21], [23], [31], [49], [61], [89], [107], [127], [221], [521], [607], [1279]], "outputs": [[true], [true], [true], [true], [false], [true], [true], [true], [false], [false], [true], [false], [true], [true], [true], [true], [false], [t...
INTRODUCTORY
PYTHON3
CODEWARS
1,962
def valid_mersenne(n):
eb8d1df6125c6a182d635508e99f833c
UNKNOWN
As a treat, I'll let you read part of the script from a classic 'I'm Alan Partridge episode: ``` Lynn: Alan, there’s that teacher chap. Alan: Michael, if he hits me, will you hit him first? Michael: No, he’s a customer. I cannot hit customers. I’ve been told. I’ll go and get some stock. Alan: Yeah, chicken stock. Phil:...
["def apple(x):\n return \"It's hotter than the sun!!\" if int(x) ** 2 > 1000 else \"Help yourself to a honeycomb Yorkie for the glovebox.\"", "def apple(x):\n if int(x)**2 > 1000:\n return \"It's hotter than the sun!!\"\n else:\n return \"Help yourself to a honeycomb Yorkie for the glovebox.\"", ...
{"fn_name": "apple", "inputs": [["50"], [4], ["12"], [60]], "outputs": [["It's hotter than the sun!!"], ["Help yourself to a honeycomb Yorkie for the glovebox."], ["Help yourself to a honeycomb Yorkie for the glovebox."], ["It's hotter than the sun!!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
18,697
def apple(x):
d0e2c10282bf49b1e12f52592916bc77
UNKNOWN
# Task Write a function `deNico`/`de_nico()` that accepts two parameters: - `key`/`$key` - string consists of unique letters and digits - `message`/`$message` - string with encoded message and decodes the `message` using the `key`. First create a numeric key basing on the provided `key` by assigning each letter p...
["def de_nico(key, msg):\n ll, order, s = len(key), [sorted(key).index(c) for c in key], ''\n while msg:\n s, msg = s + ''.join(msg[i] for i in order if i < len(msg)), msg[ll:]\n return s.strip()", "def de_nico(key,msg):\n \n decoder = []\n \n # assign key letters numbers according to alphab...
{"fn_name": "de_nico", "inputs": [["crazy", "cseerntiofarmit on "], ["crazy", "cseerntiofarmit on"], ["abc", "abcd"], ["ba", "2143658709"], ["a", "message"], ["key", "eky"]], "outputs": [["secretinformation"], ["secretinformation"], ["abcd"], ["1234567890"], ["message"], ["key"]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,523
def de_nico(key,msg):
e287a02a315366729e9b83eae395913f
UNKNOWN
Bit Vectors/Bitmaps A bitmap is one way of efficiently representing sets of unique integers using single bits. To see how this works, we can represent a set of unique integers between `0` and `< 20` using a vector/array of 20 bits: ``` var set = [3, 14, 2, 11, 16, 4, 6];``` ``` var bitmap = [0, 0, 1, 1, 1, 0, 1, 0, 0, ...
["def to_bits(s):\n lst = [0] * 5000\n for i in map(int,s.split()): lst[i] = 1\n return lst", "def to_bits(s):\n return [1 if i in set(map(int, s.split(\"\\n\"))) else 0 for i in range(5000)]", "def to_bits(string):\n bitmap = [0] * 5000\n for x in map(int, string.split()):\n bitmap[x] = 1\n ...
{"fn_name": "to_bits", "inputs": [["4814\n3815\n54\n2747\n1449\n1880\n1109\n4942\n1646\n1750\n2933\n963\n1757\n137\n4100\n2188\n2487\n3027\n1771\n1223\n4458\n2755\n247\n3975\n2125\n1071\n3967\n3557\n2741\n3052\n2013\n4741\n4501\n975\n1194\n2352\n3548\n3436\n462\n2990\n1072\n53\n920\n3028\n3648\n2928\n4186\n2057\n3238\n...
INTRODUCTORY
PYTHON3
CODEWARS
1,558
def to_bits(string):
f582188caf3f9cf06f92c7d2747d21d3
UNKNOWN
Some new cashiers started to work at your restaurant. They are good at taking orders, but they don't know how to capitalize words, or use a space bar! All the orders they create look something like this: `"milkshakepizzachickenfriescokeburgerpizzasandwichmilkshakepizza"` The kitchen staff are threatening to quit,...
["def get_order(order):\n menu = ['burger', 'fries', 'chicken', 'pizza', 'sandwich', 'onionrings', 'milkshake', 'coke']\n clean_order = ''\n for i in menu:\n clean_order += (i.capitalize() + ' ') * order.count(i)\n return clean_order[:-1]", "MENU = [\"Burger\", \"Fries\", \"Chicken\", \"Pizza\", \"Sa...
{"fn_name": "get_order", "inputs": [["burgerfriesfriesfriesfriesfriespizzasandwichcokefriesburger"]], "outputs": [["Burger Burger Fries Fries Fries Fries Fries Fries Pizza Sandwich Coke"]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,370
def get_order(order):
47473f925993dc73dc1854f8023529db
UNKNOWN
# Kata Task You are given a list of cogs in a gear train Each element represents the number of teeth of that cog e.g. `[100, 50, 25]` means * 1st cog has 100 teeth * 2nd cog has 50 teeth * 3rd cog has 25 teeth If the ``nth`` cog rotates clockwise at 1 RPM what is the RPM of the cogs at each end of the gear train?...
["def cog_RPM(cogs, n):\n return [\n cogs[n] / cogs[0] * (-1 if n % 2 else 1),\n cogs[n] / cogs[-1] * (1 if (len(cogs) - n) % 2 else -1),\n ]", "def cog_RPM(cogs, n):\n sign1 = -1 if n % 2 else 1\n sign2 = 1 if (len(cogs) - n) % 2 else -1\n return [sign1 * cogs[n] / cogs[0], sign2 * cogs[n...
{"fn_name": "cog_RPM", "inputs": [[[100], 0], [[100, 100, 100, 100], 0], [[100, 100, 100, 100], 1], [[100, 100, 100, 100], 2], [[100, 100, 100, 100], 3]], "outputs": [[[1, 1]], [[1, -1]], [[-1, 1]], [[1, -1]], [[-1, 1]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,815
def cog_RPM(cogs, n):
cf2ddff57baad370c433310f308f2d54
UNKNOWN
In this Kata we are passing a number (n) into a function. Your code will determine if the number passed is even (or not). The function needs to return either a true or false. Numbers may be positive or negative, integers or floats. Floats are considered UNeven for this kata.
["def is_even(n): \n return n%2 == 0", "def is_even(n):\n\n#a modulos will return the whole number remainder of a division\n\n#using the modulos sign with 2 and another number will only return 0 and 1 \n\n#if the remainder of n and 2 is equal to 1 the number will be odd\n \n if (n % 2) == 1:\n return False...
{"fn_name": "is_even", "inputs": [[0], [0.5], [1], [2], [-4], [15], [20], [220], [222222221], [500000000]], "outputs": [[true], [false], [false], [true], [true], [false], [true], [true], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
10,317
def is_even(n):
a67a79d5a30ccd431f1541e665715109
UNKNOWN
## Story > "You have serious coding skillz? You wannabe a [scener](https://en.wikipedia.org/wiki/Demoscene)? Complete this mission and u can get in teh crew!" You have read a similar message on your favourite [diskmag](https://en.wikipedia.org/wiki/Disk_magazine) back in the early 90s, and got really excited. You con...
["from math import pi, sin\n\ndef scroller(text, amp, period):\n return '\\n'.join(' ' * (amp + int(round(sin(i * 2 * pi / period) * amp))) + c for i, c in enumerate(text))\n", "import math\ndef scroller(text, amp, period):\n l = lambda i, c: ' '*(amp+i) + c + \"\\n\"\n return (''.join([l(round(amp * math.sin(...
{"fn_name": "scroller", "inputs": [["Hello World!", 3, 10], ["I'm a Codewars warrior lately...", 5, 18]], "outputs": [[" H\n e\n l\n l\n o\n \n W\no\nr\n l\n d\n !"], [" I\n '\n m\n \n a\n \n C\n o\n d\n e\n w\n a\n r\...
INTRODUCTORY
PYTHON3
CODEWARS
2,130
def scroller(text, amp, period):
88b67b66e5bc27c21ff6035f438d0769
UNKNOWN
Implement a function that normalizes out of range sequence indexes (converts them to 'in range' indexes) by making them repeatedly 'loop' around the array. The function should then return the value at that index. Indexes that are not out of range should be handled normally and indexes to empty sequences should return u...
["def norm_index_test(a, n):\n if a: return a[n % len(a)]", "def norm_index_test(seq, ind):\n if seq:\n return seq[ind%len(seq)]\n return None", "def norm_index_test(seq, ind): \n try:\n return seq[ind%len(seq)]\n except:\n pass", "def norm_index_test(seq, ind): \n if seq==[]:\n ...
{"fn_name": "norm_index_test", "inputs": [[[], 10]], "outputs": [[null]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,014
def norm_index_test(seq, ind):
ff61ddaee461aa97721e4388733a012b
UNKNOWN
You're given an ancient book that unfortunately has a few pages in the wrong position, fortunately your computer has a list of every page number in order from ``1`` to ``n``. You're supplied with an array of numbers, and should return an array with each page number that is out of place. Incorrect page numbers will not...
["def find_page_number(pages):\n n, miss = 1, []\n for i in pages:\n if i!=n: miss.append(i)\n else: n+=1\n return miss", "def find_page_number(pages):\n n = [1]\n return [i for i in pages if n[-1] != i or n.append(n[-1]+1)]", "def find_page_number(p):\n r, i = [], 0\n\n while i < ...
{"fn_name": "find_page_number", "inputs": [[[1, 2, 10, 3, 4, 5, 8, 6, 7]], [[1, 2, 3, 4, 50, 5, 6, 7, 51, 8, 40, 9]], [[1, 2, 3000, 3, 4, 5, 8, 6, 7, 8, 100, 9, 40, 10, 11, 13]], [[1, 2, 3, 4, 50, 5, 6, 7, 51, 8, 9]], [[4, 1, 2, 3, 3, 4, 26, 5, 6, 2, 7]]], "outputs": [[[10, 8]], [[50, 51, 40]], [[3000, 8, 100, 40, 13]]...
INTRODUCTORY
PYTHON3
CODEWARS
1,745
def find_page_number(pages):
17a850b45c6ee0deec7315aa7439429e
UNKNOWN
Your job is to write a function which increments a string, to create a new string. - If the string already ends with a number, the number should be incremented by 1. - If the string does not end with a number. the number 1 should be appended to the new string. Examples: `foo -> foo1` `foobar23 -> foobar24` `foo004...
["def increment_string(strng):\n head = strng.rstrip('0123456789')\n tail = strng[len(head):]\n if tail == \"\": return strng+\"1\"\n return head + str(int(tail) + 1).zfill(len(tail))", "def increment_string(strng):\n \n # strip the decimals from the right\n stripped = strng.rstrip('1234567890')\n ...
{"fn_name": "increment_string", "inputs": [["foo"], ["foobar001"], ["foobar1"], ["foobar00"], ["foobar99"], [""], ["foobar000"], ["foobar999"], ["foobar00999"], ["1"], ["009"]], "outputs": [["foo1"], ["foobar002"], ["foobar2"], ["foobar01"], ["foobar100"], ["1"], ["foobar001"], ["foobar1000"], ["foobar01000"], ["2"], [...
INTRODUCTORY
PYTHON3
CODEWARS
38,445
def increment_string(strng):
02b5bfa76f22e0517a18dff4da0d35a5
UNKNOWN
The Earth has been invaded by aliens. They demand our beer and threaten to destroy the Earth if we do not supply the exact number of beers demanded. Unfortunately, the aliens only speak Morse code. Write a program to convert morse code into numbers using the following convention: 1 .---- 2 ..--- 3 ...-- 4 ....- 5 ......
["MORSE_TO_NUM = {\n \".----\" : \"1\",\n \"..---\" : \"2\",\n \"...--\" : \"3\",\n \"....-\" : \"4\",\n \".....\" : \"5\",\n \"-....\" : \"6\",\n \"--...\" : \"7\",\n \"---..\" : \"8\",\n \"----.\" : \"9\",\n \"-----\" : \"0\",\n}\n\ndef morse_converter(s):\n return int(\"\".join(MORSE...
{"fn_name": "morse_converter", "inputs": [[".----.----.----.----.----"], ["..----------...-....----------"], ["---------------"], ["..---.--------....--"], [".----..---...--....-.....-....--...---..----.-----"]], "outputs": [[11111], [207600], [0], [2193], [1234567890]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,692
def morse_converter(s):
a8e1ae8020aafc59fce7817e208cfbad
UNKNOWN
For every good kata idea there seem to be quite a few bad ones! In this kata you need to check the provided 2 dimensional array (x) for good ideas 'good' and bad ideas 'bad'. If there are one or two good ideas, return 'Publish!', if there are more than 2 return 'I smell a series!'. If there are no good ideas, as is of...
["from itertools import chain\n\ndef well(arr):\n c = sum(isinstance(x, str) and x.lower() == 'good' for x in chain.from_iterable(arr))\n return (\n 'I smell a series!' if c > 2 else\n 'Publish!' if c > 0 else\n 'Fail!'\n )", "def well(arr):\n good_ideas = str(arr).lower().count('good')...
{"fn_name": "well", "inputs": [[[["bad", "bAd", "bad"], ["bad", "bAd", "bad"], ["bad", "bAd", "bad"]]], [[["gOOd", "bad", "BAD", "bad", "bad"], ["bad", "bAd", "bad"], ["GOOD", "bad", "bad", "bAd"]]], [[["gOOd", "bAd", "BAD", "bad", "bad", "GOOD"], ["bad"], ["gOOd", "BAD"]]]], "outputs": [["Fail!"], ["Publish!"], ["I sm...
INTRODUCTORY
PYTHON3
CODEWARS
2,531
def well(arr):
8ed4c8d47ca4be0c6196ece54903846c
UNKNOWN
A lot of goods have an International Article Number (formerly known as "European Article Number") abbreviated "EAN". EAN is a 13-digits barcode consisting of 12-digits data followed by a single-digit checksum (EAN-8 is not considered in this kata). The single-digit checksum is calculated as followed (based upon the ...
["validate_ean = lambda code: (sum(map(int, code[0::2])) + sum(map(int, code[1::2])) * 3) % 10 == 0", "def validate_ean(code):\n data, last = code[:12], int(code[12])\n checksum = -sum(int(d) * 3**(i % 2) for i, d in enumerate(data)) % 10\n return last == checksum ", "def validate_ean(code):\n checksum = ...
{"fn_name": "validate_ean", "inputs": [["9783815820865"], ["9783815820864"], ["9783827317100"]], "outputs": [[true], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,103
def validate_ean(code):
c08eef28332a86c5f66f7643b4e25db2
UNKNOWN
The town sheriff dislikes odd numbers and wants all odd numbered families out of town! In town crowds can form and individuals are often mixed with other people and families. However you can distinguish the family they belong to by the number on the shirts they wear. As the sheriff's assistant it's your job to find all...
["def odd_ones_out(numbers):\n return [i for i in numbers if numbers.count(i) % 2 == 0]", "from collections import Counter\n\ndef odd_ones_out(numbers):\n cnt = Counter(numbers)\n return [v for v in numbers if not cnt[v]&1 ]", "def odd_ones_out(numbers):\n temp = []\n count = 0\n for i in range(len(nu...
{"fn_name": "odd_ones_out", "inputs": [[[1, 2, 3, 1, 3, 3]], [[75, 68, 75, 47, 68]], [[42, 72, 32, 4, 94, 82, 67, 67]], [[100, 100, 5, 5, 100, 50, 68, 50, 68, 50, 68, 5, 100]], [[82, 86, 71, 58, 44, 79, 50, 44, 79, 67, 82, 82, 55, 50]]], "outputs": [[[1, 1]], [[75, 68, 75, 68]], [[67, 67]], [[100, 100, 100, 100]], [[44...
INTRODUCTORY
PYTHON3
CODEWARS
1,637
def odd_ones_out(numbers):
996c7da2019d0f055c292ac104db9752
UNKNOWN
# Task Given an array of roots of a polynomial equation, you should reconstruct this equation. ___ ## Output details: * If the power equals `1`, omit it: `x = 0` instead of `x^1 = 0` * If the power equals `0`, omit the `x`: `x - 2 = 0` instead of `x - 2x^0 = 0` * There should be no 2 signs in a row: `x - 1 = 0` ins...
["import re\n\ndef polynomialize(roots):\n \n def deploy(roots):\n r = -roots[0]\n if len(roots) == 1: return [r, 1]\n \n sub = deploy(roots[1:]) + [0]\n return [c*r + sub[i-1] for i,c in enumerate(sub)]\n \n coefs = deploy(roots)\n poly = ' + '.join([\"{}x^{}\".format...
{"fn_name": "polynomialize", "inputs": [[[0]], [[0, 0]], [[-1]], [[1]], [[1, -1]], [[0, -2, -3]], [[0, 2, 3]], [[1, 2, 3, 4, 5]]], "outputs": [["x = 0"], ["x^2 = 0"], ["x + 1 = 0"], ["x - 1 = 0"], ["x^2 - 1 = 0"], ["x^3 + 5x^2 + 6x = 0"], ["x^3 - 5x^2 + 6x = 0"], ["x^5 - 15x^4 + 85x^3 - 225x^2 + 274x - 120 = 0"]]}
INTRODUCTORY
PYTHON3
CODEWARS
9,756
def polynomialize(roots):
dec9694b8cfacaf778607e9fd5f44271
UNKNOWN
In this Kata, you're to complete the function `sum_square_even_root_odd`. You will be given a list of numbers, `nums`, as the only argument to the function. Take each number in the list and *square* it if it is even, or *square root* the number if it is odd. Take this new list and find the *sum*, rounding to two decim...
["def sum_square_even_root_odd(nums):\n return round(sum(n ** 2 if n % 2 == 0 else n ** 0.5 for n in nums), 2)", "def sum_square_even_root_odd(nums):\n return round(sum(n**(0.5 if n % 2 else 2) for n in nums), 2)", "sum_square_even_root_odd=lambda l:round(sum(x**[2,.5][x&1]for x in l),2)\n", "def sum_square_even_...
{"fn_name": "sum_square_even_root_odd", "inputs": [[[4, 5, 7, 8, 1, 2, 3, 0]], [[1, 14, 9, 8, 17, 21]]], "outputs": [[91.61], [272.71]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,080
def sum_square_even_root_odd(nums):
716d14e082b618708522c524d34b7370
UNKNOWN
# Task Given array of integers, for each position i, search among the previous positions for the last (from the left) position that contains a smaller value. Store this value at position i in the answer. If no such value can be found, store `-1` instead. # Example For `items = [3, 5, 2, 4, 5]`, the output should be...
["def array_previous_less(arr):\n return [next((y for y in arr[:i][::-1] if y < x),-1) for i,x in enumerate(arr)]", "def array_previous_less(arr):\n out = []\n \n for i, n in enumerate(arr):\n x = -1\n for m in arr[:i][::-1]:\n if m < n:\n x = m\n break\n...
{"fn_name": "array_previous_less", "inputs": [[[3, 5, 2, 4, 5]], [[2, 2, 1, 3, 4, 5, 5, 3]], [[3, 2, 1]]], "outputs": [[[-1, 3, -1, 2, 4]], [[-1, -1, -1, 1, 3, 4, 4, 1]], [[-1, -1, -1]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,259
def array_previous_less(arr):
15bda8b0a7712f9d86de2c61e2706da2
UNKNOWN
You are playing euchre and you want to know the new score after finishing a hand. There are two teams and each hand consists of 5 tricks. The team who wins the majority of the tricks will win points but the number of points varies. To determine the number of points, you must know which team called trump, how many trick...
["def update_score(score, trump, alone, tricks):\n done = tricks.count(trump)\n mul = 2 if done == 5 and alone else 1\n add = 1 if done in (3, 4) else 2\n winner = trump if done > 2 else (3 - trump)\n return [pts + (add * mul if team == winner else 0) for team, pts in enumerate(score, 1)]", "def update_s...
{"fn_name": "update_score", "inputs": [[[4, 0], 1, false, [2, 2, 2, 2, 2]], [[4, 2], 1, true, [2, 2, 2, 2, 2]], [[4, 4], 2, false, [2, 2, 2, 2, 2]], [[4, 6], 2, true, [2, 2, 2, 2, 2]], [[7, 2], 1, false, [1, 2, 2, 2, 2]], [[7, 4], 1, true, [1, 2, 2, 2, 2]], [[7, 6], 2, false, [1, 2, 2, 2, 2]], [[7, 7], 2, true, [1, 2, ...
INTRODUCTORY
PYTHON3
CODEWARS
3,559
def update_score(current_score, called_trump, alone, tricks):
188d9c6a8547380d811e38ffa154d811
UNKNOWN
There's a new security company in Paris, and they decided to give their employees an algorithm to make first name recognition faster. In the blink of an eye, they can now detect if a string is a first name, no matter if it is a one-word name or an hyphenated name. They're given this documentation with the algorithm: ...
["import re\n\n\ndef show_me(name):\n return bool(re.match(r'(-[A-Z][a-z]+)+$', '-' + name))", "def show_me(name):\n return all(word.isalpha() and word.capitalize() == word for word in name.split('-'))", "from re import match, compile\ndef show_me(name):\n return match(compile(r'^[A-Z][a-z]+(?:-[A-Z][a-z]+)*$'),...
{"fn_name": "show_me", "inputs": [["Francis"], ["Jean-Eluard"], ["Le Mec"], ["Bernard-Henry-Levy"], ["Meme Gertrude"], ["A-a-a-a----a-a"], ["Z-------------"], ["Jean-luc"], ["Jean--Luc"], ["JeanLucPicard"], ["-Jean-Luc"], ["Jean-Luc-Picard-"]], "outputs": [[true], [true], [false], [true], [false], [false], [false], [fa...
INTRODUCTORY
PYTHON3
CODEWARS
1,120
def show_me(name):
1baaed72ab2659700f05a5852ad01ca9
UNKNOWN
Given the number n, return a string which shows the minimum number of moves to complete the tower of Hanoi consisting of n layers. Tower of Hanoi : https://en.wikipedia.org/wiki/Tower_of_Hanoi Example - 2 layered Tower of Hanoi Input: n=2 Start [[2, 1], [], []] Goal [[], [], [2, 1]] Expected Output : '[[2, 1], []...
["def hanoiArray(n):\n A, B, C = list(range(n, 0, -1)), [], []\n res = [str([A, C, B])]\n def rec(n, X, Y, Z):\n if not n: return\n rec(n-1, X, Z, Y)\n Y.append(X.pop())\n res.append(str([A, C, B]))\n rec(n-1, Z, Y, X) \n rec(n, A, B, C)\n return '\\n'.join(res)"...
{"fn_name": "hanoiArray", "inputs": [[2], [3]], "outputs": [["[[2, 1], [], []]\n[[2], [1], []]\n[[], [1], [2]]\n[[], [], [2, 1]]"], ["[[3, 2, 1], [], []]\n[[3, 2], [], [1]]\n[[3], [2], [1]]\n[[3], [2, 1], []]\n[[], [2, 1], [3]]\n[[1], [2], [3]]\n[[1], [], [3, 2]]\n[[], [], [3, 2, 1]]"]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,482
def hanoiArray(n):
ab8e5c824662c5cff2c9c17e50181e24
UNKNOWN
Base on the fairy tale [Diamonds and Toads](https://en.wikipedia.org/wiki/Diamonds_and_Toads) from Charles Perrault. In this kata you will have to complete a function that take 2 arguments: - A string, that correspond to what the daugther says. - A string, that tell you wich fairy the girl have met, this one can be `...
["from collections import Counter\n\ndef diamonds_and_toads(sentence, fairy):\n c = Counter(sentence)\n d = {'good':['ruby', 'crystal'], 'evil':['python', 'squirrel']}\n\n return {s:c[s[0]] + 2*c[s[0].upper()] for s in d[fairy]}", "def diamonds_and_toads(sentence,fairy):\n items = {\"ruby\":0, \"crystal\":0...
{"fn_name": "diamonds_and_toads", "inputs": [["Ruby and Crystal", "good"], ["This string contain some Ruby and some Crystal in it", "good"], ["Python and Squirrel", "evil"], ["This string contain some Python and some Squirrel in it", "evil"]], "outputs": [[{"ruby": 3, "crystal": 2}], [{"ruby": 4, "crystal": 3}], [{"pyt...
INTRODUCTORY
PYTHON3
CODEWARS
2,758
def diamonds_and_toads(sentence,fairy):
14fd856355426bdd735499c895ee6adf
UNKNOWN
Your coworker was supposed to write a simple helper function to capitalize a string (that contains a single word) before they went on vacation. Unfortunately, they have now left and the code they gave you doesn't work. Fix the helper function they wrote so that it works as intended (i.e. make the first character in th...
["def capitalize_word(word):\n return word.capitalize()\n\n # .capitilize() for the first word in the string\n # .title() for each word in the string\n", "def capitalize_word(word):\n return word.capitalize()", "def capitalize_word(word):\n\n return \"\".join(char.capitalize() for char in word.split())",...
{"fn_name": "capitalize_word", "inputs": [["word"], ["i"], ["glasswear"]], "outputs": [["Word"], ["I"], ["Glasswear"]]}
INTRODUCTORY
PYTHON3
CODEWARS
10,758
def capitalize_word(word):
049a414089728f512d062ddadb6e4405
UNKNOWN
The male gametes or sperm cells in humans and other mammals are heterogametic and contain one of two types of sex chromosomes. They are either X or Y. The female gametes or eggs however, contain only the X sex chromosome and are homogametic. The sperm cell determines the sex of an individual in this case. If a sperm c...
["def chromosome_check(sperm):\n return 'Congratulations! You\\'re going to have a {}.'.format('son' if 'Y' in sperm else 'daughter')", "def chromosome_check(sperm):\n gender = {\"XY\" : \"son\", \"XX\" : \"daughter\"}\n \n return \"Congratulations! You're going to have a {}.\".format(gender[sperm])", "def ...
{"fn_name": "chromosome_check", "inputs": [["XY"], ["XX"]], "outputs": [["Congratulations! You're going to have a son."], ["Congratulations! You're going to have a daughter."]]}
INTRODUCTORY
PYTHON3
CODEWARS
17,524
def chromosome_check(sperm):
17b6dea349abb2182ed0c3c23d0f0e41
UNKNOWN
You are a skier (marked below by the `X`). You have made it to the Olympics! Well done. ``` \_\_\_X\_ \*\*\*\*\*\ \*\*\*\*\*\*\ \*\*\*\*\*\*\*\ \*\*\*\*\*\*\*\*\ \*\*\*\*\*\*\*\*\*\\.\_\_\_\_/ ``` Your job in this kata is to calculate the maximum speed you will achieve during your downhill run. The speed is dictated ...
["def ski_jump(mountain):\n height = len(mountain)\n speed = height * 1.5\n jump_length = height * speed * 9 / 10\n return (\n f\"{jump_length:.2f} metres: He's crap!\" if jump_length < 10 else\n f\"{jump_length:.2f} metres: He's ok!\" if jump_length < 25 else\n f\"{jump_length:.2f} me...
{"fn_name": "ski_jump", "inputs": [[["*"]], [["*", "**", "***"]], [["*", "**", "***", "****", "*****", "******"]], [["*", "**", "***", "****", "*****", "******", "*******", "********"]]], "outputs": [["1.35 metres: He's crap!"], ["12.15 metres: He's ok!"], ["48.60 metres: He's flying!"], ["86.40 metres: Gold!!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,484
def ski_jump(mountain):
a25a057ab758ed0e161bfd48c3f4dbca
UNKNOWN
Another Fibonacci... yes but with other kinds of result. The function is named `aroundFib` or `around_fib`, depending of the language. Its parameter is `n` (positive integer). First you have to calculate `f` the value of `fibonacci(n)` with `fibonacci(0) --> 0` and `fibonacci(1) --> 1` (see: ) - 1) Find the count of ...
["from collections import Counter\nfib = [0, 1]\n\ndef around_fib(n):\n while len(fib) <= n: fib.append(fib[-1] + fib[-2])\n f = str(fib[n])\n val = max((v, -int(k)) for k,v in Counter(f).items())\n last = f[-(len(f)%25 or 25):]\n return f\"Last chunk {last}; Max is {val[0]} for digit {-val[1]}\"", "def ...
{"fn_name": "around_fib", "inputs": [[666], [934], [617], [576], [982], [628], [901], [957], [916], [823], [988], [703], [873], [664], [749], [581], [986], [904], [716], [673], [12965], [17001], [16381], [18035], [10611], [13959], [17962], [13505], [15366], [13883], [10210], [16797], [15923], [18108], [12314], [15708],...
INTRODUCTORY
PYTHON3
CODEWARS
4,958
def around_fib(n):
326745eee0f47d61cbdcefec944c445b
UNKNOWN
In computer science and discrete mathematics, an [inversion](https://en.wikipedia.org/wiki/Inversion_%28discrete_mathematics%29) is a pair of places in a sequence where the elements in these places are out of their natural order. So, if we use ascending order for a group of numbers, then an inversion is when larger num...
["def count_inversion(nums):\n return sum(a > b for i, a in enumerate(nums) for b in nums[i + 1:])\n", "def count_inversion(s):\n return sum(s[i] > s[j]\n for i in range(len(s) - 1)\n for j in range(i + 1, len(s)))", "def count_inversion(sequence):\n def rec(arr):\n if len(ar...
{"fn_name": "count_inversion", "inputs": [[[1, 2, 3]], [[-3, -2, -1]], [[-20, 0, 20]], [[-13, 4, 8]], [[1, 3, 2]], [[-2, -3, -1]], [[-20, 20, 0]], [[-13, 9, 8]], [[3, 6, 2]], [[3, 6, 2, 7, 3]], [[26, 32, -21, 45, 21]], [[14, 12, 17, 124, 1, -12, 21, -24]], [[]], [[25, 12, 7, 4, 2, -7, -12, -22]], [[324, 123, 36, 4, -1,...
INTRODUCTORY
PYTHON3
CODEWARS
3,080
def count_inversion(sequence):
618a12feb3dc71358d6e9ce6f875ce58
UNKNOWN
write me a function `stringy` that takes a `size` and returns a `string` of alternating `'1s'` and `'0s'`. the string should start with a `1`. a string with `size` 6 should return :`'101010'`. with `size` 4 should return : `'1010'`. with `size` 12 should return : `'101010101010'`. The size will always be positive ...
["def stringy(size):\n return \"\".join([str(i % 2) for i in range(1, size + 1)])", "def stringy(size):\n return ('10' * size)[:size]", "from itertools import cycle, islice\n\ndef stringy(size):\n return ''.join(islice(cycle('10'), size))", "def stringy(size):\n s = \"\"\n for x in range (0, size):\n ...
{"fn_name": "stringy", "inputs": [[3], [5], [12], [26], [28]], "outputs": [["101"], ["10101"], ["101010101010"], ["10101010101010101010101010"], ["1010101010101010101010101010"]]}
INTRODUCTORY
PYTHON3
CODEWARS
15,311
def stringy(size):
0084863766b6816e4d09b3d9ea659445
UNKNOWN
In this Kata, you will be given a lower case string and your task will be to remove `k` characters from that string using the following rule: ```Python - first remove all letter 'a', followed by letter 'b', then 'c', etc... - remove the leftmost character first. ``` ```Python For example: solve('abracadabra', 1) = 'b...
["def solve(st,k): \n for l in sorted(st)[:k]:\n st=st.replace(l,'',1)\n return st", "solve = lambda s, k: ''.join(t[1] for t in sorted(sorted(enumerate(s), key=lambda x:x[1])[k:]))", "from collections import Counter\nfrom itertools import accumulate\nfrom operator import add\nfrom string import ascii_lowe...
{"fn_name": "solve", "inputs": [["abracadabra", 0], ["abracadabra", 1], ["abracadabra", 2], ["abracadabra", 6], ["abracadabra", 8], ["abracadabra", 50], ["hxehmvkybeklnj", 5], ["cccaabababaccbc", 3], ["cccaabababaccbc", 9], ["u", 1], ["back", 3]], "outputs": [["abracadabra"], ["bracadabra"], ["brcadabra"], ["rcdbr"], [...
INTRODUCTORY
PYTHON3
CODEWARS
2,204
def solve(st,k):
e2b94452b3f041d44f3d1d507f888067
UNKNOWN
Given two integer arrays where the second array is a shuffled duplicate of the first array with one element missing, find the missing element. Please note, there may be duplicates in the arrays, so checking if a numerical value exists in one and not the other is not a valid solution. ``` find_missing([1, 2, 2, 3], [1...
["def find_missing(arr1, arr2):\n return sum(arr1) - sum(arr2)\n", "from functools import reduce\ndef find_missing(arr1, arr2):\n from itertools import chain\n from functools import reduce\n from operator import xor\n return reduce(xor, chain(arr1, arr2))\n", "def find_missing(A1, A2):\n return sum(A1...
{"fn_name": "find_missing", "inputs": [[[1, 2, 3], [1, 3]], [[6, 1, 3, 6, 8, 2], [3, 6, 6, 1, 2]], [[7], []], [[4, 3, 3, 61, 8, 8], [8, 61, 8, 3, 4]], [[0, 0, 0, 0, 0], [0, 0, 0, 0]]], "outputs": [[2], [8], [7], [3], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,203
def find_missing(arr1, arr2):
87b62c7b7f4c1baea156220f951260c2
UNKNOWN
You have to write a function that describe Leo: ```python def leo(oscar): pass ``` if oscar was (integer) 88, you have to return "Leo finally won the oscar! Leo is happy". if oscar was 86, you have to return "Not even for Wolf of wallstreet?!" if it was not 88 or 86 (and below 88) you should return "When will you gi...
["def leo(oscar):\n if oscar == 88:\n return \"Leo finally won the oscar! Leo is happy\"\n elif oscar == 86:\n return \"Not even for Wolf of wallstreet?!\"\n elif oscar < 88:\n return \"When will you give Leo an Oscar?\"\n elif oscar > 88:\n return \"Leo got one a...
{"fn_name": "leo", "inputs": [[88], [87], [86]], "outputs": [["Leo finally won the oscar! Leo is happy"], ["When will you give Leo an Oscar?"], ["Not even for Wolf of wallstreet?!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,578
def leo(oscar):
aebc0c007b050cfe729b32cbc1ea2f2e
UNKNOWN
Your car is old, it breaks easily. The shock absorbers are gone and you think it can handle about 15 more bumps before it dies totally. Unfortunately for you, your drive is very bumpy! Given a string showing either flat road ("\_") or bumps ("n"), work out if you make it home safely. 15 bumps or under, return "Woohoo!...
["def bumps(road):\n return \"Woohoo!\" if road.count(\"n\") <= 15 else \"Car Dead\"", "def bumps(road):\n return 'Car Dead' if road.count('n')>15 else 'Woohoo!'", "def bumps(road):\n return \"Woohoo!\" if road.count('n')<16 else \"Car Dead\"", "from collections import Counter\n\n\ndef bumps(road):\n return...
{"fn_name": "bumps", "inputs": [["n"], ["_nnnnnnn_n__n______nn__nn_nnn"], ["______n___n_"], ["nnnnnnnnnnnnnnnnnnnnn"]], "outputs": [["Woohoo!"], ["Car Dead"], ["Woohoo!"], ["Car Dead"]]}
INTRODUCTORY
PYTHON3
CODEWARS
17,441
def bumps(road):
81d160b706129767cc5f0f165884d0e6
UNKNOWN
In Russia regular bus tickets usually consist of 6 digits. The ticket is called lucky when the sum of the first three digits equals to the sum of the last three digits. Write a function to find out whether the ticket is lucky or not. Return true if so, otherwise return false. Consider that input is always a string. Wat...
["def is_lucky(ticket):\n if len(ticket) == 6 and ticket.isdigit():\n t = list(map(int, ticket))\n return sum(t[:3]) == sum(t[3:])\n return False", "def is_lucky(t):\n return len(t) == 6 and t.isdigit() and sum(map(int, t[:3])) == sum(map(int, t[3:]))", "def is_lucky(ticket):\n if len(ticket) ...
{"fn_name": "is_lucky", "inputs": [["123321"], ["12341234"], ["100001"], ["100200"], ["912435"], ["12a12a"], ["999999"], ["1111"], ["000000"], [""]], "outputs": [[true], [false], [true], [false], [true], [false], [true], [false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,958
def is_lucky(ticket):
6d1f6b6f221b8ad91ca9824883ef71ca
UNKNOWN
In this Kata, we will calculate the **minumum positive number that is not a possible sum** from a list of positive integers. ``` solve([1,2,8,7]) = 4 => we can get 1, 2, 3 (from 1+2), but we cannot get 4. 4 is the minimum number not possible from the list. solve([4,1,2,3,12]) = 11. We can get 1, 2, 3, 4, 4+1=5, 4+2=...
["def solve(xs):\n m = 0\n for x in sorted(xs):\n if x > m + 1:\n break\n m += x\n return m + 1", "from itertools import accumulate\n\ndef solve(arr):\n arr = sorted(arr)\n return next((x+1 for x, i in zip(accumulate([0]+arr), arr+[0]) if i > x + 1), sum(arr)+1)", "def solve(r):\...
{"fn_name": "solve", "inputs": [[[1, 2, 8, 7]], [[2, 12, 3, 1]], [[4, 2, 8, 3, 1]], [[4, 2, 7, 3, 1]], [[4, 2, 12, 3]]], "outputs": [[4], [7], [19], [18], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,699
def solve(arr):
5cc0a3ecafc75142fb21a997c7966724
UNKNOWN
### Task King Arthur and his knights are having a New Years party. Last year Lancelot was jealous of Arthur, because Arthur had a date and Lancelot did not, and they started a duel. To prevent this from happening again, Arthur wants to make sure that there are at least as many women as men at this year's party. He g...
["def invite_more_women(arr):\n return sum(arr) > 0", "def invite_more_women(arr):\n return arr.count(1) > arr.count(-1)", "def invite_more_women(arr):\n x = arr.count(-1)\n y = arr.count(1)\n if x >= y:\n return 0\n else:\n return 1", "\ndef invite_more_women(arr):\n a = sum(arr)\n ...
{"fn_name": "invite_more_women", "inputs": [[[1, -1, 1]], [[-1, -1, -1]], [[1, -1]], [[1, 1, 1]], [[]]], "outputs": [[true], [false], [false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
18,138
def invite_more_women(arr):
63995ac3ac1240485fbdebb80a0d772f
UNKNOWN
You are given three piles of casino chips: white, green and black chips: * the first pile contains only white chips * the second pile contains only green chips * the third pile contains only black chips Each day you take exactly two chips of different colors and head to the casino. You can choose any color, but you a...
["def solve(xs):\n x, y, z = sorted(xs)\n return min(x + y, (x + y + z) // 2)", "def solve(arr):\n cnt = 0\n arr.sort()\n while(arr[2]<(arr[0]+arr[1])):\n arr[0]-=1\n arr[1]-=1\n cnt+=1\n return cnt+arr[0]+arr[1]", "def solve(arr):\n a,b,c = sorted(arr)\n ...
{"fn_name": "solve", "inputs": [[[1, 1, 1]], [[1, 2, 1]], [[4, 1, 1]], [[8, 2, 8]], [[8, 1, 4]], [[7, 4, 10]], [[12, 12, 12]], [[1, 23, 2]]], "outputs": [[1], [2], [2], [9], [5], [10], [18], [3]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,309
def solve(arr):
810ef28b505b6e9af780bb2e6ea0a670
UNKNOWN
The dragon's curve is a self-similar fractal which can be obtained by a recursive method. Starting with the string `D0 = 'Fa'`, at each step simultaneously perform the following operations: ``` replace 'a' with: 'aRbFR' replace 'b' with: 'LFaLb' ``` For example (spaces added for more visibility) : ``` 1st iterati...
["def Dragon(n):\n if not isinstance(n, int) or n < 0:\n return ''\n \n value = 'Fa'\n \n for i in range(n):\n value = value.replace('a', 'aRcFR')\n value = value.replace('b', 'LFaLb')\n value = value.replace('c', 'b')\n \n return value.replace('a', '').replace('...
{"fn_name": "Dragon", "inputs": [["a"], [1.1], [-1]], "outputs": [[""], [""], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,783
def Dragon(n):
cce322827a0561ad345b57fbd0c999e5
UNKNOWN
# Task For the given set `S` its powerset is the set of all possible subsets of `S`. Given an array of integers nums, your task is to return the powerset of its elements. Implement an algorithm that does it in a depth-first search fashion. That is, for every integer in the set, we can either choose to take or not tak...
["from itertools import compress,product\n\ndef powerset(a):\n return [list(compress(a,p)) for p in product((0,1),repeat=len(a))]\n", "def powerset(nums):\n if not nums:\n return [[]]\n l = powerset(nums[1:])\n a = nums[0]\n return l + [[a] + q for q in l]", "def powerset(nums):\n t = []\n f...
{"fn_name": "powerset", "inputs": [[[1, 2]], [[1, 2, 3]], [[1]], [[125, 15, 155, 15, 158]], [[1, 2, 3, 4]]], "outputs": [[[[], [2], [1], [1, 2]]], [[[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]]], [[[], [1]]], [[[], [158], [15], [15, 158], [155], [155, 158], [155, 15], [155, 15, 158], [15], [15, 158], [15, 15],...
INTRODUCTORY
PYTHON3
CODEWARS
1,463
def powerset(nums):
faf97ecb5cfb369b04c3e6724c224844
UNKNOWN
Complete the function that takes one argument, a list of words, and returns the length of the longest word in the list. For example: ```python ['simple', 'is', 'better', 'than', 'complex'] ==> 7 ``` Do not modify the input list.
["def longest(words):\n return max(map(len, words))", "def longest(words):\n return max(len(i) for i in words)", "def longest(words):\n return len(max(words, key=len))", "def longest(words):\n number_of_chars = [len(word) for word in words]\n return max(number_of_chars)", "longest = lambda w: len(max(w, ...
{"fn_name": "longest", "inputs": [[["simple", "is", "better", "than", "complex"]], [["explicit", "is", "better", "than", "implicit"]], [["beautiful", "is", "better", "than", "ugly"]]], "outputs": [[7], [8], [9]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,069
def longest(words):
5d4f20864d597ff85d3e553def2fcb44
UNKNOWN
Fibonacci numbers are generated by setting F0 = 0, F1 = 1, and then using the formula: # Fn = Fn-1 + Fn-2 Your task is to efficiently calculate the **n**th element in the Fibonacci sequence and then count the occurrence of each digit in the number. Return a list of integer pairs sorted in **descending** order. 10 ≤ ...
["from collections import Counter\n\ndef fib_digits(n):\n a, b = 0, 1\n for i in range(n): a, b = b, a+b\n return sorted(((b, int(a)) for a, b in Counter(str(a)).items()), reverse=True)", "from operator import itemgetter\ndef fib_digits(n):\n a,b = 1,1\n num=n\n num_int=int(num-2)\n for i in range ...
{"fn_name": "fib_digits", "inputs": [[10]], "outputs": [[[[2, 5]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,631
def fib_digits(n):
f0a55f354662e544f0e8d1021444b883
UNKNOWN
Your classmates asked you to copy some paperwork for them. You know that there are 'n' classmates and the paperwork has 'm' pages. Your task is to calculate how many blank pages do you need. ### Example: ```python paperwork(5, 5) == 25 ``` **Note:** if `n < 0` or `m < 0` return `0`! Waiting for translations and Fee...
["def paperwork(n, m):\n return n * m if n > 0 and m > 0 else 0", "def paperwork(n, m):\n if m<0 or n<0:\n return 0\n else:\n return n*m", "def paperwork(n, m):\n return max(n, 0)*max(m, 0)", "def paperwork(n, m):\n return n*m if n>=0 and m>=0 else 0", "def paperwork(n, m):\n return 0 if...
{"fn_name": "paperwork", "inputs": [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 0]], "outputs": [[25], [0], [0], [0], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,314
def paperwork(n, m):
edde63971ddb886df2d16451c2bb4374
UNKNOWN
You may be familiar with the concept of combinations: for example, if you take 5 cards from a 52 cards deck as you would playing poker, you can have a certain number (2,598,960, would you say?) of different combinations. In mathematics the number of *k* combinations you can have taking from a set of *n* elements is ca...
["from math import factorial\n\ndef choose(n, k):\n return factorial(n) / ( factorial(k) * factorial(n-k) ) if k <=n else 0", "import sys\nimport functools\nsys.setrecursionlimit(1_000_000)\n\n# lru_cache is a python shortcut for memoization\n# memoization is a technique to avoid repeatedly calculating\n# something ...
{"fn_name": "choose", "inputs": [[1, 1], [5, 4], [10, 5], [10, 20], [52, 5], [100, 10], [500, 4], [1000, 3], [200, 8], [300, 6]], "outputs": [[1], [5], [252], [0], [2598960], [17310309456440], [2573031125], [166167000], [55098996177225], [962822846700]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,192
def choose(n,k):
faaba2a21d166c3c4e9dbfb2db5b4eb6
UNKNOWN
Imagine that you have an array of 3 integers each representing a different person. Each number can be 0, 1, or 2 which represents the number of hands that person holds up. Now imagine there is a sequence which follows these rules: * None of the people have their arms raised at first * Firstly, a person raises 1 hand; ...
["def get_positions(n):\n return tuple(n // d % 3 for d in (1, 3, 9))", "def get_positions(n):\n return n%3, n//3%3, n//9%3", "def get_positions(n): #Jai Shree Ram!!!\n num2=n\n num3=n\n p2=[0,0,0,1,1,1,2,2,2]\n p3=[0,0,0,0,0,0,0,0,0,\n 1,1,1,1,1,1,1,1,1,\n 2,2,2,2,2,2,2,2,2]\n \n ...
{"fn_name": "get_positions", "inputs": [[54], [98], [3]], "outputs": [[[0, 0, 0]], [[2, 2, 1]], [[0, 1, 0]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,440
def get_positions(n):
d33a3205c691fec04e62b7cb94e04d46
UNKNOWN
Thanks to the effects of El Nino this year my holiday snorkelling trip was akin to being in a washing machine... Not fun at all. Given a string made up of '~' and '\_' representing waves and calm respectively, your job is to check whether a person would become seasick. Remember, only the process of change from wave t...
["def sea_sick(sea):\n return \"Throw Up\" if (sea.count(\"~_\") + sea.count(\"_~\"))/len(sea) > 0.2 else \"No Problem\"", "def sea_sick(sea):\n changes = sum(1 for a,b in zip(sea,sea[1:]) if a!=b)\n return \"No Problem\" if changes*5 <= len(sea) else \"Throw Up\"", "def sea_sick(sea):\n waves = sum(sea[i: ...
{"fn_name": "sea_sick", "inputs": [["~"], ["_~~~~~~~_~__~______~~__~~_~~"], ["______~___~_"], ["____"], ["_~~_~____~~~~~~~__~_~"]], "outputs": [["No Problem"], ["Throw Up"], ["Throw Up"], ["No Problem"], ["Throw Up"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,434
def sea_sick(sea):
5782f6e9ac562f8032ab4e6f2285a8cd
UNKNOWN
Given an array of ones and zeroes, convert the equivalent binary value to an integer. Eg: `[0, 0, 0, 1]` is treated as `0001` which is the binary representation of `1`. Examples: ``` Testing: [0, 0, 0, 1] ==> 1 Testing: [0, 0, 1, 0] ==> 2 Testing: [0, 1, 0, 1] ==> 5 Testing: [1, 0, 0, 1] ==> 9 Testing: [0, 0, 1, 0] =...
["def binary_array_to_number(arr):\n return int(\"\".join(map(str, arr)), 2)", "def binary_array_to_number(arr):\n return int(''.join(str(a) for a in arr), 2)", "def binary_array_to_number(arr):\n s = 0\n for digit in arr:\n s = s * 2 + digit\n\n return s", "def binary_array_to_number(arr):\n ret...
{"fn_name": "binary_array_to_number", "inputs": [[[0, 0, 0, 1]], [[0, 0, 1, 0]], [[1, 1, 1, 1]], [[0, 1, 1, 0]]], "outputs": [[1], [2], [15], [6]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,966
def binary_array_to_number(arr):
6c237d3283edc9d6bbf1976532e0f4f2
UNKNOWN
You have to write two methods to *encrypt* and *decrypt* strings. Both methods have two parameters: ``` 1. The string to encrypt/decrypt 2. The Qwerty-Encryption-Key (000-999) ``` The rules are very easy: ``` The crypting-regions are these 3 lines from your keyboard: 1. "qwertyuiop" 2. "asdfghjkl" 3. "zxcvbnm,." If ...
["from collections import deque\nKEYBOARD = ['zxcvbnm,.', 'ZXCVBNM<>', 'asdfghjkl', 'ASDFGHJKL', 'qwertyuiop', 'QWERTYUIOP']\n\ndef encrypt(text, encryptKey): return converter(text, encryptKey, 1)\ndef decrypt(text, encryptKey): return converter(text, encryptKey, -1)\n \ndef converter(text, encryptKey, sens):\n d...
{"fn_name": "encrypt", "inputs": [["A", 111], ["Abc", 212], ["Ball", 134], ["Ball", 444], ["This is a test.", 348], ["Do the kata Kobayashi Maru Test. Endless fun and excitement when finding a solution.", 583]], "outputs": [["S"], ["Smb"], [">fdd"], [">gff"], ["Iaqh qh g iyhi,"], ["Sr pgi jlpl Jr,lqlage Zlow Piapc I.sk...
INTRODUCTORY
PYTHON3
CODEWARS
9,552
def encrypt(text, encryptKey):
bc4a2026d1c3b62d964aacdd4a72f5ab
UNKNOWN
You will receive an uncertain amount of integers in a certain order ```k1, k2, ..., kn```. You form a new number of n digits in the following way: you take one of the possible digits of the first given number, ```k1```, then the same with the given number ```k2```, repeating the same process up to ```kn``` and you con...
["from itertools import product\ndef proc_seq(*args):\n nums = set(int(''.join(l)) for l in product(*(str(a) for a in args)) if l[0] != '0')\n if len(nums) == 1: return [1, nums.pop()]\n return [len(nums), min(nums), max(nums), sum(nums)]", "from itertools import product\n\ndef proc_seq(*args):\n p = set([i...
{"fn_name": "proc_seq", "inputs": [[23, 17, 89], [22, 22, 22, 22], [230, 15, 8]], "outputs": [[[8, 218, 379, 2388]], [[1, 2222]], [[4, 218, 358, 1152]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,846
def proc_seq(*args):
fbcfef1c479688c2ac4e98ecefba67d8
UNKNOWN
HTML Element Generator In this kata, you will be creating a python function that will take arguments and turn them into an HTML element. An HTML tag has three parts: The opening tag, which consists of a tag name and potentially attributes, all in between angle brackets. The element content, which is the data that is s...
["def html(tag, *contents, **attr):\n openTag = tag + ''.join(f' {\"class\" if k==\"cls\" else k}=\"{v}\"' for k,v in attr.items())\n \n return '\\n'.join( f'<{openTag}>{c}</{tag}>' for c in contents) or f'<{openTag} />'", "def html(tag, *args, **kwargs):\n open = tag + ''.join(f' {\"class\" if k == \"cls\"...
{"fn_name": "html", "inputs": [["br"], ["title", "Webpage Title"]], "outputs": [["<br />"], ["<title>Webpage Title</title>"]]}
INTRODUCTORY
PYTHON3
CODEWARS
9,045
def html(tag_name, *args, **kwargs):
b690a7f27f7ec35b7b215496c1a66e95
UNKNOWN
# Task John has an important number, and he doesn't want others to see it. He decided to encrypt the number, using the following steps: ``` His number is always a non strict increasing sequence ie. "123" He converted each digit into English words. ie. "123"--> "ONETWOTHREE" And then, rearrange the letters randomly....
["from collections import Counter \n\nEXECUTIONS_ORDER = [('Z', Counter(\"ZERO\"), '0'),\n ('W', Counter(\"TWO\"), '2'),\n ('U', Counter(\"FOUR\"), '4'),\n ('X', Counter(\"SIX\"), '6'),\n ('G', Counter(\"EIGHT\"), '8'),\n ...
{"fn_name": "original_number", "inputs": [["ONE"], ["OEN"], ["ONETWO"], ["OONETW"], ["TTONWOHREEE"]], "outputs": [["1"], ["1"], ["12"], ["12"], ["123"]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,600
def original_number(s):
d1d3b466acab2695e95e3fa3a7a4e039
UNKNOWN
In this Kata you are expected to find the coefficients of quadratic equation of the given two roots (`x1` and `x2`). Equation will be the form of ```ax^2 + bx + c = 0``` Return type is a Vector (tuple in Rust, Array in Ruby) containing coefficients of the equations in the order `(a, b, c)`. Since there are infinitel...
["def quadratic(x1, x2):\n return (1,-x1-x2,x1*x2)\n", "def quadratic(x1, x2):\n return (1, -(x1 + x2), x1 * x2)\n", "import numpy as np\n\ndef quadratic(*args):\n return tuple(np.poly(args))", "def quadratic(x1, x2):\n equ = 1 , - x1-x2 , x1*x2\n return equ\n", "def quadratic(x1, x2):\n a = (1, -(x1+...
{"fn_name": "quadratic", "inputs": [[0, 1], [4, 9], [2, 6], [-5, -4]], "outputs": [[[1, -1, 0]], [[1, -13, 36]], [[1, -8, 12]], [[1, 9, 20]]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,408
def quadratic(x1, x2):
7a5b73569f1fa7b2f29bc0d1a56f9cc6
UNKNOWN
Make a function that receives a value, ```val``` and outputs the smallest higher number than the given value, and this number belong to a set of positive integers that have the following properties: - their digits occur only once - they are odd - they are multiple of three ```python next_numb(12) == 15 next_numb(1...
["def unique_digits(n):\n return len(set(str(n))) == len(str(n))\n\ndef next_numb(val):\n val += 1\n while val % 3: val += 1\n if val % 2 == 0: val += 3\n \n while not unique_digits(val):\n val += 6\n if val > 9876543210: break\n else:\n return val\n \n return \"There is ...
{"fn_name": "next_numb", "inputs": [[12], [13], [99], [999999], [9999999999]], "outputs": [[15], [15], [105], [1023459], ["There is no possible number that fulfills those requirements"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,537
def next_numb(val):
78bf072ec426427bfb63515ee0998e8f
UNKNOWN
Given two arrays of strings, return the number of times each string of the second array appears in the first array. #### Example ```python array1 = ['abc', 'abc', 'xyz', 'cde', 'uvw'] array2 = ['abc', 'cde', 'uap'] ``` How many times do the elements in `array2` appear in `array1`? * `'abc'` appears twice in the fi...
["def solve(a,b):\n return [a.count(e) for e in b]", "from collections import Counter\n\ndef solve(a,b):\n c = Counter(a)\n return [c[s] for s in b]", "def solve(a,b):\n return [a.count(x) for x in b]", "def solve(a,b):\n return list(map(a.count, b))", "def solve(haystack, needles):\n return [haystack...
{"fn_name": "solve", "inputs": [[["abc", "abc", "xyz", "abcd", "cde"], ["abc", "cde", "uap"]], [["abc", "xyz", "abc", "xyz", "cde"], ["abc", "cde", "xyz"]], [["quick", "brown", "fox", "is", "quick"], ["quick", "abc", "fox"]]], "outputs": [[[2, 1, 0]], [[2, 1, 2]], [[2, 0, 1]]]}
INTRODUCTORY
PYTHON3
CODEWARS
841
def solve(a,b):
0b28653778181f77b690caf26cfaf256
UNKNOWN
Given a string and an array of integers representing indices, capitalize all letters at the given indices. For example: * `capitalize("abcdef",[1,2,5]) = "aBCdeF"` * `capitalize("abcdef",[1,2,5,100]) = "aBCdeF"`. There is no index 100. The input will be a lowercase string with no spaces and an array of digits. Goo...
["def capitalize(s,ind):\n ind = set(ind)\n return ''.join(c.upper() if i in ind else c for i,c in enumerate(s))", "def capitalize(s, ind):\n result = list(s)\n for index in ind:\n try:\n result[index] = result[index].upper()\n except IndexError:\n break # assumes the in...
{"fn_name": "capitalize", "inputs": [["abcdef", [1, 2, 5]], ["abcdef", [1, 2, 5, 100]], ["codewars", [1, 3, 5, 50]], ["abracadabra", [2, 6, 9, 10]], ["codewarriors", [5]], ["indexinglessons", [0]]], "outputs": [["aBCdeF"], ["aBCdeF"], ["cOdEwArs"], ["abRacaDabRA"], ["codewArriors"], ["Indexinglessons"]]}
INTRODUCTORY
PYTHON3
CODEWARS
17,990
def capitalize(s,ind):
623b7208f545065408c56e1c438cc80e
UNKNOWN
**An [isogram](https://en.wikipedia.org/wiki/Isogram)** (also known as a "nonpattern word") is a logological term for a word or phrase without a repeating letter. It is also used by some to mean a word or phrase in which each letter appears the same number of times, not necessarily just once. You task is to write a me...
["from collections import Counter\nimport re\n\ndef is_isogram(word):\n if type(word) is not str or not word: return False\n return len(set( Counter(re.sub(r'[^a-z]', \"\", word.lower())).values() )) == 1", "from collections import Counter\n\ndef is_isogram(word):\n try:\n return len(set(Counter(filter(...
{"fn_name": "is_isogram", "inputs": [[null], [3], ["Dermatoglyphics"], ["isogram"], ["eleven"], ["moOse"], ["isIsogram"], [""], ["-.-"], ["subdermatoglyphic"], ["Alphabet"], ["thumbscrew-japingly"], ["Hjelmqvist-Gryb-Zock-Pfund-Wax"], ["Emily Jung Schwartzkopf"], ["aabbccddeeffgg"]], "outputs": [[false], [false], [true...
INTRODUCTORY
PYTHON3
CODEWARS
2,176
def is_isogram(word):
0673936f59693d1f7b3cd3b76869d159
UNKNOWN
Your task is to Combine two Strings. But consider the rule... By the way you don't have to check errors or incorrect input values, everything is ok without bad tricks, only two input strings and as result one output string;-)... And here's the rule: Input Strings `a` and `b`: For every character in string `a` swap ...
["def work_on_strings(a, b):\n new_a = [letter if b.lower().count(letter.lower()) % 2 == 0 else letter.swapcase() for letter in a]\n new_b = [letter if a.lower().count(letter.lower()) % 2 == 0 else letter.swapcase() for letter in b]\n return ''.join(new_a) + ''.join(new_b)", "from collections import Counter\n\...
{"fn_name": "work_on_strings", "inputs": [["abc", "cde"], ["abcdeFgtrzw", "defgGgfhjkwqe"], ["abcdeFg", "defgG"], ["abab", "bababa"]], "outputs": [["abCCde"], ["abcDeFGtrzWDEFGgGFhjkWqE"], ["abcDEfgDEFGg"], ["ABABbababa"]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,079
def work_on_strings(a,b):
4ae56a6efc52a6b1347e15891a1eccfa
UNKNOWN
# Task Determine the client's membership level based on the invested `amount` of money and the given thresholds for membership levels. There are four membership levels (from highest to lowest): `Platinum, Gold, Silver, Bronze` The minimum investment is the threshold limit for `Bronze` membership. If the given amount...
["def membership(amount, platinum, gold, silver, bronze):\n ordered = reversed(sorted((v, k) for k, v in locals().items() if k != 'amount'))\n return next((level.capitalize() for threshold, level in ordered if amount >= threshold), 'Not a member')", "def membership(amount, platinum, gold, silver, bronze):\n ...
{"fn_name": "membership", "inputs": [[100000, 1000000, 100000, 10000, 1000], [1001, 1000000, 100000, 10000, 1000], [998, 1000000, 100000, 10000, 1000], [0, 1000000, 100000, 10000, 1000]], "outputs": [["Gold"], ["Bronze"], ["Not a member"], ["Not a member"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,539
def membership(amount, platinum, gold, silver, bronze):
6f70403ada9aba33e2c2443817b335d7
UNKNOWN
Create a method `sayHello`/`say_hello`/`SayHello` that takes as input a name, city, and state to welcome a person. Note that `name` will be an array consisting of one or more values that should be joined together with one space between each, and the length of the `name` array in test cases will vary. Example: ```pyth...
["def say_hello(name, city, state):\n return \"Hello, {}! Welcome to {}, {}!\".format(\" \".join(name), city, state)\n", "def say_hello(name, city, state):\n return f\"Hello, {' '.join(name)}! Welcome to {city}, {state}!\"", "def say_hello(name, city, state):\n return 'Hello, %s! Welcome to %s, %s!' % (' '.join(...
{"fn_name": "say_hello", "inputs": [[["John", "Smith"], "Phoenix", "Arizona"], [["Franklin", "Delano", "Roosevelt"], "Chicago", "Illinois"], [["Wallace", "Russel", "Osbourne"], "Albany", "New York"], [["Lupin", "the", "Third"], "Los Angeles", "California"], [["Marlo", "Stanfield"], "Baltimore", "Maryland"]], "outputs":...
INTRODUCTORY
PYTHON3
CODEWARS
16,928
def say_hello(name, city, state):
a3afe85712a9e85e252da13214327ea2
UNKNOWN
Finding your seat on a plane is never fun, particularly for a long haul flight... You arrive, realise again just how little leg room you get, and sort of climb into the seat covered in a pile of your own stuff. To help confuse matters (although they claim in an effort to do the opposite) many airlines omit the letters...
["def plane_seat(a):\n front, middle, back = (list(range(1,21)), list(range(21,41)), list(range(41,61)))\n left, center, right = ('ABC', 'DEF', \"GHK\")\n x, y = ('', '')\n \n if int(a[:-1]) in front: x = 'Front-'\n if int(a[:-1]) in middle: x = 'Middle-'\n if int(a[:-1]) in back: x = ...
{"fn_name": "plane_seat", "inputs": [["2B"], ["20B"], ["58I"], ["60D"], ["17K"]], "outputs": [["Front-Left"], ["Front-Left"], ["No Seat!!"], ["Back-Middle"], ["Front-Right"]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,991
def plane_seat(a):
3cccdbc2d737aea620d103ef5a7c01de
UNKNOWN
We define the function `f1(n,k)`, as the least multiple of `n` that has all its digits less than `k`. We define the function `f2(n,k)`, as the least multiple of `n` that has all the digits that are less than `k`. Each digit may occur more than once in both values of `f1(n,k)` and `f2(n,k)`. The possible values for ...
["def find_f1_eq_f2(n,k):\n s = set(range(k))\n while True:\n n += 1\n testn = n\n while True:\n f = set(map(int,str(testn)))\n if f<=s:\n if f==s: return n\n break\n testn += n", "def find_f1_eq_f2(n,k):\n s = set(range(k))\n ...
{"fn_name": "find_f1_eq_f2", "inputs": [[542, 5], [1750, 6], [14990, 7], [3456, 4], [30500, 3], [62550, 5], [568525, 7], [9567100, 8]], "outputs": [[547], [1799], [14996], [3462], [30501], [62557], [568531], [9567115]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,327
def find_f1_eq_f2(n,k):
f1638026a4715534aab5fb99457bb459
UNKNOWN
Given a string as input, move all of its vowels to the end of the string, in the same order as they were before. Vowels are (in this kata): `a, e, i, o, u` Note: all provided input strings are lowercase. ## Examples ```python "day" ==> "dya" "apple" ==> "pplae" ```
["def move_vowels(s): \n return ''.join(sorted(s, key=lambda k: k in 'aeiou'))", "import re\n\ndef move_vowels(input):\n return ''.join(''.join(l) for l in zip(*re.findall(r'([^aeiou])?([aeiou])?', input)))", "def move_vowels(i): \n s, v = '', ''\n for letter in i:\n if letter in 'aeiou': v+=letter\n...
{"fn_name": "move_vowels", "inputs": [["day"], ["apple"], ["peace"], ["maker"], ["programming"], ["javascript"], ["python"], ["ruby"], ["haskell"], ["clojure"], ["csharp"]], "outputs": [["dya"], ["pplae"], ["pceae"], ["mkrae"], ["prgrmmngoai"], ["jvscrptaai"], ["pythno"], ["rbyu"], ["hskllae"], ["cljroue"], ["cshrpa"]]...
INTRODUCTORY
PYTHON3
CODEWARS
1,288
def move_vowels(input):
cb8fc72eb481061a17e0cbd8a1ed578a
UNKNOWN
Your task is to construct a building which will be a pile of n cubes. The cube at the bottom will have a volume of n^3, the cube above will have volume of (n-1)^3 and so on until the top which will have a volume of 1^3. You are given the total volume m of the building. Being given m can you find the number n of cube...
["def find_nb(m):\n n = 1\n volume = 0\n while volume < m:\n volume += n**3\n if volume == m:\n return n\n n += 1\n return -1", "def find_nb(m):\n n=s=0\n while True:\n n+=1\n s+=n\n k=s*s\n if k== m:\n return n\n elif k>m:\n r...
{"fn_name": "find_nb", "inputs": [[4183059834009], [24723578342962], [135440716410000], [40539911473216], [26825883955641], [41364076483082], [9541025211025], [112668204662785], [79172108332642], [1788719004901], [131443152397956], [1801879360282], [18262169777476], [11988186060816], [826691919076], [36099801072722], [...
INTRODUCTORY
PYTHON3
CODEWARS
1,625
def find_nb(m):
5615439bd11181a53012ffbdd5355323
UNKNOWN
> [Run-length encoding](https://en.wikipedia.org/w/index.php?title=Run-length_encoding) (RLE) is a very simple form of data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the origina...
["from itertools import groupby\n\ndef run_length_encoding(s):\n return [[sum(1 for _ in g), c] for c, g in groupby(s)]", "from itertools import groupby\ndef run_length_encoding(s):\n return [[len(list(b)), a] for a,b in groupby(s)]", "def run_length_encoding(s):\n count, prev, lst = 1, '', []\n for c in s:\n ...
{"fn_name": "run_length_encoding", "inputs": [[""], ["abc"], ["aab"], ["hello world!"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb"]], "outputs": [[[]], [[[1, "a"], [1, "b"], [1, "c"]]], [[[2, "a"], [1, "b"]]], [[[1, "h"], [1, "e"], [2, "l"], [1, "o"], [1, " "], [1, "w"], [1, "o"], [1, "r"], [1, "l"], [1, "d"], [1, "!"]]]...
INTRODUCTORY
PYTHON3
CODEWARS
4,353
def run_length_encoding(s):
311543a3cf8b39e45a7d4c4fac46d618
UNKNOWN
Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love. Write a function that will take the number of petals of each flower and return tru...
["def lovefunc( flower1, flower2 ):\n return (flower1+flower2)%2", "def lovefunc(flower1, flower2):\n return flower1 % 2 != flower2 % 2", "def lovefunc( flower1, flower2 ):\n return (flower1 + flower2) % 2 == 1", "def lovefunc(a, b):\n if a % 2 == 0 and b % 2 == 0:\n return False\n elif a % 2 != 0...
{"fn_name": "lovefunc", "inputs": [[1, 4], [2, 2], [0, 1], [0, 0]], "outputs": [[true], [false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
14,840
def lovefunc( flower1, flower2 ):
45ed859815eb15613b022c0b3ddd223f
UNKNOWN
This kata is based on a [variation](https://www.codewars.com/kata/happy-numbers-5) of *Happy Numbers* by TySlothrop. It is advisable to complete it first to grasp the idea and then move on to this one. ___ Hello, my dear friend, and welcome to another *Happy Numbers* kata! What? You're not interested in them anymore?...
["sum_dig = lambda n, D={str(d): d*d for d in range(10)}: sum(map(D.get, str(n)))\nis_happy = lambda n: n > 4 and is_happy(sum_dig(n)) or n == 1\n\nhappy_set = set(filter(is_happy, range(100)))\nfor n in range(100, 3 * 10 ** 5):\n if sum_dig(n) in happy_set: happy_set.add(n)\n\nfrom bisect import bisect\ndef perform...
{"fn_name": "performant_numbers", "inputs": [[10], [50], [100]], "outputs": [[[1, 7, 10]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100]]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,203
def performant_numbers(n, happy_list=sorted(happy_set)):
1ada448576babf88c396c82214f26598
UNKNOWN
In this kata, your task is to identify the pattern underlying a sequence of numbers. For example, if the sequence is [1, 2, 3, 4, 5], then the pattern is [1], since each number in the sequence is equal to the number preceding it, plus 1. See the test cases for more examples. A few more rules : pattern may contain neg...
["from itertools import cycle\n\ndef find_pattern(s):\n diffs = [y - x for x, y in zip(s, s[1:])] \n for i in range(1, len(diffs) + 1):\n if len(diffs) % i == 0 and all(a == b for a, b in zip(diffs, cycle(diffs[:i]))): return diffs[:i]", "def find_pattern(seq):\n start, end = [], []\n for i in ran...
{"fn_name": "find_pattern", "inputs": [[[1, 2, 3, 4, 5]], [[1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]], [[1, 5, 2, 3, 1, 5, 2, 3, 1]], [[1, 5, 4, 8, 7, 11, 10, 14, 13]], [[0, 1]], [[4, 5, 6, 8, 3, 4, 5, 6, 8, 3, 4, 5, 6, 8, 3, 4]], [[4, 5, 3, -2, -1, 0, -2, -7, -6]], [[4, 5, 6, 5, 3, 2, 3, 4, 5, 6, 5, 3, 2, 3,...
INTRODUCTORY
PYTHON3
CODEWARS
2,178
def find_pattern(seq):
6e4105f49289b43064f598ad44ed1bd0
UNKNOWN
Not considering number 1, the integer 153 is the first integer having this property: the sum of the third-power of each of its digits is equal to 153. Take a look: 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 The next number that experiments this particular behaviour is 370 with the same power. Write the function `eq_...
["def eq_sum_powdig(hMax, exp):\n return [i for i in range(2, hMax + 1) if i == sum(int(c) ** exp for c in str(i))]\n", "def eq_sum_powdig(hMax, exp):\n ret = []\n for i in range(10, hMax + 1):\n if i == sum(int(j) ** exp for j in str(i)):\n ret.append(i)\n return ret", "def eq_sum_powdig(...
{"fn_name": "eq_sum_powdig", "inputs": [[100, 2], [1000, 2], [2000, 2], [200, 3], [370, 3], [400, 3], [500, 3], [1000, 3], [1500, 3]], "outputs": [[[]], [[]], [[]], [[153]], [[153, 370]], [[153, 370, 371]], [[153, 370, 371, 407]], [[153, 370, 371, 407]], [[153, 370, 371, 407]]]}
INTRODUCTORY
PYTHON3
CODEWARS
819
def eq_sum_powdig(hMax, exp):
967607c29ffe508c88c2c38c5b10b099
UNKNOWN
*`This kata is a tribute/fanwork to the TV-show: Supernatural`* Balls! Those wayward Winchester boys are in trouble again, hunting something down in New Orleans. You are Bobby Singer, you know how "idjits" they can be, so you have to prepare. They will call you any minute with the race of the thing, and you want to ...
["database = '''werewolf : Silver knife or bullet to the heart\nvampire : Behead it with a machete\nwendigo : Burn it to death\nshapeshifter : Silver knife or bullet to the heart\nangel : Use the angelic blade\ndemon : Use Ruby's knife, or some Jesus-juice\nghost : Salt and iron, and don't forget to burn the corpse\ndr...
{"fn_name": "bob", "inputs": [["vampire"], ["pagan god"], ["werepuppy"]], "outputs": [["Behead it with a machete, idjits!"], ["It depends on which one it is, idjits!"], ["I have friggin no idea yet, idjits!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,265
def bob(what):
f2d3ed6e5d9849dc873e1c3cc530874d
UNKNOWN
An onion array is an array that satisfies the following condition for all values of `j` and `k`: If all of the following are `true`: * `j >= 0` * `k >= 0` * `j + k = array.length - 1` * `j != k` then: * `a[j] + a[k] <= 10` ### Examples: ``` [1, 2, 19, 4, 5] => true (as 1+5 <= 10 and 2+4 <= 10) [1, 2, 19, 4,...
["def is_onion_array(a):\n return all(a[i] + a[-i-1] <= 10 for i in range(len(a) // 2))", "from typing import List\n\n\ndef is_onion_array(a: List[int]) -> bool:\n return all(aj + ak <= 10 for aj, ak in zip(a, a[:(len(a) - 1) // 2:-1]))\n", "def is_onion_array(a):\n for i in range(0,len(a)//2):\n if a[i...
{"fn_name": "is_onion_array", "inputs": [[[6, 0, 4]], [[1, 1, 15, 10, -1]]], "outputs": [[true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,585
def is_onion_array(a):
a3f3025b2b7db550a87621132f060584
UNKNOWN
## Fixed xor Write a function that takes two hex strings as input and XORs them against each other. If the strings are different lengths the output should be the length of the shortest string. Hint: The strings would first need to be converted to binary to be XOR'd. ## Note: If the two strings are of different leng...
["def fixed_xor(a, b):\n return \"\".join(f\"{int(x, 16)^int(y, 16):x}\" for x, y in zip(a, b))", "def fixed_xor(a, b):\n\n m = min(len(a), len(b)) \n \n return f\"{int(a[:m], 16) ^ int(b[:m], 16):0{m}x}\" if m else \"\"\n", "def fixed_xor(a, b):\n return \"\".join(format(int(x, 16) ^ int(y, 16), \"x...
{"fn_name": "fixed_xor", "inputs": [["1c0111001f010100061a024b53535009181c", "686974207468652062756c6c277320657965"], ["aadf", "bce2"], ["ab3f", "ac"], ["", ""], ["c611d9bdd9de38b9eb", "23a0745505d4d25494"], ["7d1e875da9d5e89b54c7eaf", "3541599be591709795cebd5"], ["785a6677b3e52f0e7", "a8d97da7441"], ["6cbd75511e7f750c...
INTRODUCTORY
PYTHON3
CODEWARS
1,604
def fixed_xor(a, b):
38b2ce2134d27c772febab54d8f1dc41
UNKNOWN
In some ranking people collects points. The challenge is sort by points and calulate position for every person. But remember if two or more persons have same number of points, they should have same position number and sorted by name (name is unique). For example: Input structure: Output should be:
["def ranking(a):\n a.sort(key=lambda x: (-x[\"points\"], x[\"name\"]))\n for i, x in enumerate(a):\n x[\"position\"] = i + 1 if not i or x[\"points\"] < a[i-1][\"points\"] else a[i-1][\"position\"]\n return a", "def ranking(people):\n people = people[:]\n people.sort(key=lambda person: (-person['...
{"fn_name": "ranking", "inputs": [[[]]], "outputs": [[[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,936
def ranking(people):
3674f18be988a29a91959d0aa40dc30d
UNKNOWN
A country has coins with denominations ```python coins_list = d1 < d2 < · · · < dn. ``` You want to make change for n cents, using the smallest number of coins. ```python # Example 1: U.S. coins d1 = 1 d2 = 5 d3 = 10 d4 = 25 ## Optimal change for 37 cents – 1 quarter, 1 dime, 2 pennies. # Example 2: Alien Planet Z c...
["from collections import deque\n\ndef loose_change(coins_list, amount_of_change):\n q = deque([(0, amount_of_change)])\n\n while q:\n l, a = q.popleft()\n if a == 0:\n return l\n q.extend((l + 1, a - i) for i in coins_list if a >= i)", "def loose_change(coins_list, amount):\n s...
{"fn_name": "loose_change", "inputs": [[[1, 5, 10, 25], 37], [[1, 3, 4], 6], [[25, 5, 10, 1, 21], 63], [[1, 4, 5, 10], 8], [[1, 2, 5, 10, 20, 50, 100, 200], 93]], "outputs": [[4], [2], [3], [2], [5]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,666
def loose_change(coins_list, amount_of_change):
3e7c4186516e06bd0b87c7dbca79ea3e
UNKNOWN
# Task A ciphertext alphabet is obtained from the plaintext alphabet by means of rearranging some characters. For example "bacdef...xyz" will be a simple ciphertext alphabet where a and b are rearranged. A substitution cipher is a method of encoding where each letter of the plaintext alphabet is replaced with the co...
["def is_substitution_cipher(s1, s2):\n return len(set(s1)) == len(set(s2)) == len(set(zip(s1, s2)))", "def f(s1, s2):\n d = {}\n for a, b in zip(s1, s2):\n if (a in d and d[a] != b):\n return False\n d[a] = b\n return True\n\ndef is_substitution_cipher(s1, s2):\n return f(s1, s2...
{"fn_name": "is_substitution_cipher", "inputs": [["aacb", "aabc"], ["aa", "bc"], ["aaxxaaz", "aazzaay"], ["aaxyaa", "aazzaa"], ["aazzaa", "aaxyaa"], ["jpeuizmi", "mxxcwriq"]], "outputs": [[true], [false], [true], [false], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,700
def is_substitution_cipher(s1, s2):
60d7e6c055ead88a55970a8fd50bad29
UNKNOWN
NOTE: It is recommended you complete [Introduction to Esolangs](https://www.codewars.com/kata/esolang-interpreters-number-1-introduction-to-esolangs-and-my-first-interpreter-ministringfuck/) or [MiniBitFlip](https://www.codewars.com/kata/esolang-minibitflip/) before solving this one. Task: Make an interpreter for an es...
["def interpreter(tape):\n memory, ptr, output = {0: 0}, 0, \"\"\n \n for command in tape:\n if command == \">\": ptr += 1\n elif command == \"<\": ptr -= 1\n elif command == \"!\": memory[len(memory)] = 0\n elif command == \"*\": output += chr(memory.get(ptr, 0) % 256) \n ...
{"fn_name": "interpreter", "inputs": [["++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++...
INTRODUCTORY
PYTHON3
CODEWARS
6,254
def interpreter(tape):
a7f8ac99e66453eef55f82edec5051d4
UNKNOWN
A group of friends (n >= 2) have reunited for a get-together after a very long time. They agree that they will make presentations on holiday destinations or expeditions they have been to only if it satisfies **one simple rule**: > the holiday/journey being presented must have been visited _only_ by the presenter a...
["from collections import Counter\n\ndef presentation_agenda(friend_list):\n uniqueDest = {d for d,c in Counter(d for p in friend_list for d in p['dest']).items() if c == 1}\n pFilteredDest = tuple((p['person'], [d for d in p['dest'] if d in uniqueDest]) for p in friend_list)\n return [{'person': name, 'des...
{"fn_name": "presentation_agenda", "inputs": [[[{"person": "Abe", "dest": ["London", "Dubai"]}, {"person": "Bond", "dest": ["Melbourne", "Dubai"]}]], [[{"person": "Abe", "dest": ["Dubai"]}, {"person": "Brad", "dest": ["Dubai"]}]], [[{"person": "Abe", "dest": ["London", "Dubai"]}, {"person": "Bond", "dest": ["Melbourne"...
INTRODUCTORY
PYTHON3
CODEWARS
4,660
def presentation_agenda(friend_list):
784bd172dcce09deffa4aa76ec9e8c66
UNKNOWN
Define a "prime prime" number to be a rational number written as one prime number over another prime number: `primeA / primeB` (e.g. `7/31`) Given a whole number `N`, generate the number of "prime prime" rational numbers less than 1, using only prime numbers between `0` and `N` (non inclusive). Return the count of th...
["from bisect import bisect_left\n\ndef sieve(n):\n sieve, primes = [0]*(n+1), []\n for i in range(2, n+1):\n if not sieve[i]:\n primes.append(i)\n for j in range(i**2, n+1, i): sieve[j] = 1\n return primes\n\nPRIMES = sieve(100000)\n\ndef prime_primes(n):\n lst = PRIMES[:bisect...
{"fn_name": "prime_primes", "inputs": [[6], [4], [10], [65], [0], [1000], [666]], "outputs": [[[3, 1]], [[1, 0]], [[6, 3]], [[153, 63]], [[0, 0]], [[14028, 6266]], [[7260, 3213]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,389
def prime_primes(N):
62e983878d689e045a059991cdce9f1d
UNKNOWN
An array is called `zero-balanced` if its elements sum to `0` and for each positive element `n`, there exists another element that is the negative of `n`. Write a function named `ìsZeroBalanced` that returns `true` if its argument is `zero-balanced` array, else return `false`. Note that an `empty array` will not sum to...
["from collections import Counter\n\ndef is_zero_balanced(arr):\n c = Counter(arr)\n return bool(arr) and all(c[k] == c[-k] for k in c)", "def is_zero_balanced(arr):\n return all(arr) == sum(arr) == 0", "def is_zero_balanced(arr):\n return arr != [] and sum(arr) == 0 and all(-x in arr for x in arr)", "def i...
{"fn_name": "is_zero_balanced", "inputs": [[[3]], [[-3]], [[0, 0, 0, 0, 0, 0]], [[0, 1, -1]], [[]], [[3, -2, -1]], [[0]], [[1, 1, -2]], [[-1, 1, -2, 2, -2, -2, -4, 4]], [[0, 0, 0, 0, 0]]], "outputs": [[false], [false], [true], [true], [false], [false], [true], [false], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,293
def is_zero_balanced(arr):
93a07942d4694851c8117b176949fa94
UNKNOWN
A core idea of several left-wing ideologies is that the wealthiest should *support* the poorest, no matter what and that is exactly what you are called to do using this kata (which, on a side note, was born out of the necessity to redistribute the width of `div`s into a given container). You will be given two paramete...
["def socialist_distribution(population, minimum):\n if minimum > sum(population)//len(population):\n return []\n while min(population) < minimum:\n population[population.index(min(population))] += 1\n population[population.index(max(population))] -= 1\n return population\n", "def socialis...
{"fn_name": "socialist_distribution", "inputs": [[[2, 3, 5, 15, 75], 5], [[2, 3, 5, 15, 75], 20], [[2, 3, 5, 45, 45], 5], [[2, 3, 5, 45, 45], 30], [[24, 48, 22, 19, 37], 30]], "outputs": [[[5, 5, 5, 15, 70]], [[20, 20, 20, 20, 20]], [[5, 5, 5, 42, 43]], [[]], [[30, 30, 30, 30, 30]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,167
def socialist_distribution(population, minimum):
27b67bbe0b442add743303905c9770c1
UNKNOWN
In this kata, we want to discover a small property of numbers. We say that a number is a **dd** number if it contains d occurences of a digit d, (d is in [1,9]). ## Examples * 664444309 is a **dd** number, as it contains 4 occurences of the number 4 * 30313, 122 are **dd** numbers as they respectively contain 3 occu...
["from collections import Counter\n\n\ndef is_dd(n):\n return any(value==count for value, count in Counter(int(x) for x in str(n)).items())", "from collections import Counter\n\ndef is_dd(n):\n return any(int(k) == v for k, v in Counter(str(n)).items())", "def is_dd(n):\n for i in range(1, 10):\n if str...
{"fn_name": "is_dd", "inputs": [[664444309], [122], [30313], [5023011], [9081231]], "outputs": [[true], [true], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,281
def is_dd(n):
e983c3ef22b1ba2fc63b04b9d87357e2
UNKNOWN
Your task is to get Zodiac Sign using input ```day``` and ```month```. For exapmle: ```python get_zodiac_sign(1,5) => 'Taurus' get_zodiac_sign(10,10) => 'Libra' ``` Correct answers are (preloaded): ```python SIGNS = ['Capricorn', 'Aquarius', 'Pisces', 'Aries', 'Taurus', 'Gemini', 'Cancer', 'Leo', 'Virgo', 'Libra',...
["def get_zodiac_sign(day, month):\n\n signs = [\"Aquarius\", \"Pisces\", \"Aries\", \"Taurus\", \"Gemini\", \"Cancer\",\n \"Leo\", \"Virgo\", \"Libra\", \"Scorpio\", \"Sagittarius\", \"Capricorn\"]\n\n limits = [20, 19, 21, 20, 21, 21, 23, 23, 23, 23, 22, 22]\n\n return signs[month - 1] if limits[...
{"fn_name": "get_zodiac_sign", "inputs": [[10, 10], [1, 5], [6, 9], [25, 11]], "outputs": [["Libra"], ["Taurus"], ["Virgo"], ["Sagittarius"]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,287
def get_zodiac_sign(day, month):
9de48104f6270a3120b4e2c591cf2f29
UNKNOWN
This kata is inspired on the problem #50 of the Project Euler. The prime ``` 41``` is the result of the sum of many consecutive primes. In fact, ``` 2 + 3 + 5 + 7 + 11 + 13 = 41 , (6 addens) ``` Furthermore, the prime ``` 41``` is the prime below ``` 100 (val_max)``` that has the longest chain of consecutive ...
["# RWH primes\nLIMIT = 500000\nsieve = [True] * (LIMIT//2)\nfor n in range(3, int(LIMIT**0.5) +1, 2):\n if sieve[n//2]: sieve[n*n//2::n] = [False] * ((LIMIT-n*n-1)//2//n +1)\nPRIMES = [2] + [2*i+1 for i in range(1, LIMIT//2) if sieve[i]]\n\n\ndef prime_maxlength_chain(val_max):\n if val_max < 5:\n return ...
{"fn_name": "prime_maxlength_chain", "inputs": [[100], [200], [500], [1000]], "outputs": [[[41]], [[197]], [[499]], [[953]]]}
INTRODUCTORY
PYTHON3
CODEWARS
10,693
def prime_maxlength_chain(n):
16cdeecf87b012600c66d5bbee8c8278
UNKNOWN
# Description: Count the number of exclamation marks and question marks, return the product. # Examples ``` Product("") == 0 product("!") == 0 Product("!ab? ?") == 2 Product("!!") == 0 Product("!??") == 2 Product("!???") == 3 Product("!!!??") == 6 Product("!!!???") == 9 Product("!???!!") == 9 Product("!????!!!?") =...
["def product(s):\n return s.count(\"?\")*s.count(\"!\")", "def product(s):\n return s.count(\"!\")*s.count(\"?\")", "def product(s):\n ce = cq = 0\n for i in s:\n if i == '!':\n ce += 1\n elif i == '?':\n cq += 1\n return ce * cq", "def product(s):\n exclamation = ...
{"fn_name": "product", "inputs": [[""], ["!"], ["!!??!!"]], "outputs": [[0], [0], [8]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,092
def product(s):
6348a5feca042d8a407c4f3bd4dc1436
UNKNOWN
>When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said # Description: In kindergarten, the teacher gave the children some candies. The number of candies each child gets is not always the same. Here is an array `candies`(all e...
["def distribution_of_candy(candies):\n steps = 0\n while len(set(candies)) > 1:\n candies = [(a + 1) // 2 + (b + 1) // 2\n for a, b in zip(candies, candies[-1:] + candies)]\n steps += 1\n return [steps, candies.pop()]", "def distribution_of_candy(candies):\n n = 0\n while...
{"fn_name": "distribution_of_candy", "inputs": [[[1, 2, 3, 4, 5]], [[10, 2, 8, 22, 16, 4, 10, 6, 14, 20]]], "outputs": [[[6, 6]], [[17, 18]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,825
def distribution_of_candy(candies):
5a317cfaf0f1b41683582d47f51a927b
UNKNOWN
# Task You are given a regular array `arr`. Let's call a `step` the difference between two adjacent elements. Your task is to sum the elements which belong to the sequence of consecutive elements of length `at least 3 (but as long as possible)`, such that the steps between the elements in this sequence are the sam...
["def sum_of_regular_numbers(arr):\n res, value, save = 0, arr[1] - arr[0], arr[:2]\n for x,y in zip(arr[1:], arr[2:]):\n if y-x == value:\n save.append(y)\n else:\n if len(save) >= 3: res += sum(save)\n value, save = y-x, [x, y]\n if len(save) >= 3: res+= sum(sav...
{"fn_name": "sum_of_regular_numbers", "inputs": [[[54, 70, 86, 1, -2, -5, 0, 5, 78, 145, 212, 15]], [[59, 58, 57, 55, 53, 51]], [[7, 2, -3, 3, 9, 15]], [[-17, -9, 1, 9, 17, 4, -9]], [[7, 2, 3, 2, -2, 400, 802]], [[-1, 7000, 1, -6998, -13997]]], "outputs": [[639], [390], [30], [39], [1200], [-13994]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,444
def sum_of_regular_numbers(arr):
f59d181ef6c5e67fc01889c70458367d
UNKNOWN
Introduction The GADERYPOLUKI is a simple substitution cypher used in scouting to encrypt messages. The encryption is based on short, easy to remember key. The key is written as paired letters, which are in the cipher simple replacement. The most frequently used key is "GA-DE-RY-PO-LU-KI". ``` G => A g => a a =>...
["def encode(str, key):\n key = key.lower() + key.upper()\n dict = { char: key[i-1] if i % 2 else key[i+1] for i, char in enumerate(key) }\n return ''.join( dict.get(char, char) for char in str )\n\ndecode = encode", "def encode(message, key):\n a, b = (f\"{key[i::2]}{key[i::2].upper()}\" for i in (0, 1))\n...
{"fn_name": "encode", "inputs": [["Gug hgs g cgt", "gaderypoluki"], ["Dkucr pu yhr ykbir", "politykarenu"], ["ABCD", "gaderypoluki"], ["Ala has a cat", "gaderypoluki"]], "outputs": [["Ala has a cat"], ["Dance on the table"], ["GBCE"], ["Gug hgs g cgt"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,383
def encode(message, key):
19bd637db182def978ed04902dffe5b8
UNKNOWN
>When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said # Description: Give you two arrays `arr1` and `arr2`. They have the same length(length>=2). The elements of two arrays always be integer. Sort `arr1` according to th...
["import numpy as np\n\ndef sort_two_arrays(arr1, arr2):\n idx2 = np.argsort(arr2, kind='mergesort')\n idx1 = np.argsort(arr1, kind='mergesort')\n return [[arr1[i] for i in idx2], [arr2[i] for i in idx1]]", "def sort_two_arrays(*args):\n sortedIdxRev = [ sorted((v,i) for i,v in enumerate(a)) for a in args[:...
{"fn_name": "sort_two_arrays", "inputs": [[[5, 4, 3, 2, 1], [6, 5, 7, 8, 9]], [[2, 1, 3, 4, 5], [5, 6, 7, 8, 9]], [[5, 6, 9, 2, 6, 5], [3, 6, 7, 4, 8, 1]]], "outputs": [[[[4, 5, 3, 2, 1], [9, 8, 7, 5, 6]]], [[[2, 1, 3, 4, 5], [6, 5, 7, 8, 9]]], [[[5, 5, 2, 6, 9, 6], [4, 3, 1, 6, 8, 7]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,952
def sort_two_arrays(arr1, arr2):
a806abcc6a5949b9dc3676280bd4cebc
UNKNOWN
Given two numbers and an arithmetic operator (the name of it, as a string), return the result of the two numbers having that operator used on them. ```a``` and ```b``` will both be positive integers, and ```a``` will always be the first number in the operation, and ```b``` always the second. The four operators are "...
["def arithmetic(a, b, operator):\n return {\n 'add': a + b,\n 'subtract': a - b,\n 'multiply': a * b,\n 'divide': a / b,\n }[operator]", "def arithmetic(a, b, operator):\n if operator == \"add\":\n return a + b\n elif operator == \"subtract\":\n return a - b\n e...
{"fn_name": "arithmetic", "inputs": [[1, 2, "add"], [8, 2, "subtract"], [5, 2, "multiply"], [8, 2, "divide"]], "outputs": [[3], [6], [10], [4]]}
INTRODUCTORY
PYTHON3
CODEWARS
22,159
def arithmetic(a, b, operator):
b90a1d6db15f75c686b57fbb87fff7bf
UNKNOWN
Time to win the lottery! Given a lottery ticket (ticket), represented by an array of 2-value arrays, you must find out if you've won the jackpot. Example ticket: To do this, you must first count the 'mini-wins' on your ticket. Each sub array has both a string and a number within it. If the character code of any of ...
["def bingo(ticket, win):\n return 'Winner!' if sum(chr(n) in s for s, n in ticket) >= win else 'Loser!'", "def bingo(ticket, win):\n return \"Winner!\" if sum( w in map(ord, s) for s, w in ticket ) >= win else \"Loser!\"", "def bingo(ticket,win):\n counter = 0\n for x,y in ticket:\n for i in x:\n ...
{"fn_name": "bingo", "inputs": [[[["ABC", 65], ["HGR", 74], ["BYHT", 74]], 2], [[["ABC", 65], ["HGR", 74], ["BYHT", 74]], 1], [[["HGTYRE", 74], ["BE", 66], ["JKTY", 74]], 3]], "outputs": [["Loser!"], ["Winner!"], ["Loser!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,367
def bingo(ticket, win):
7cb2ae591aa574dea9159881aba03f56
UNKNOWN
The __Hamming weight__ of a string is the number of symbols that are different from the zero-symbol of the alphabet used. There are several algorithms for efficient computing of the Hamming weight for numbers. In this Kata, speaking technically, you have to find out the number of '1' bits in a binary representation of ...
["def hamming_weight(x):return bin(x).count('1')", "hamming_weight = lambda x: list(bin(x)).count('1') # :) \n", "def hamming_weight(x):\n count = 0\n while x:\n x &= x-1\n count += 1\n return count\n", "def hamming_weight(x):\n w = 0\n while x:\n w += x & 1\n x >>= 1\n return w", "def ...
{"fn_name": "hamming_weight", "inputs": [[0], [1], [2], [10], [21], [2048]], "outputs": [[0], [1], [1], [2], [3], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
678
def hamming_weight(x):