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
4010bd04a5ca00da3f5fc759d89be036
UNKNOWN
Given a string, you progressively need to concatenate the first letter from the left and the first letter to the right and "1", then the second letter from the left and the second letter to the right and "2", and so on. If the string's length is odd drop the central element. For example: ```python char_concat("abcdef...
["def char_concat(word, index = 1):\n if len(word) < 2: return ''\n return word[0:1] + word[-1:] + str(index) + char_concat(word[1:-1], index + 1)", "def char_concat(word):\n return ''.join([(word[i]+word[-1-i]+str(i+1))for i in range(len(word)//2)])\n", "def char_concat(word):\n return ''.join( \"{}{}{}\".form...
{"fn_name": "char_concat", "inputs": [["abc def"], ["CodeWars"], ["CodeWars Rocks"], ["1234567890"], ["$'D8KB)%PO@s"]], "outputs": [["af1be2cd3"], ["Cs1or2da3eW4"], ["Cs1ok2dc3eo4WR5a 6rs7"], ["101292383474565"], ["$s1'@2DO38P4K%5B)6"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,109
def char_concat(word):
ce86fdf3a9f40db80daa42eb6ec4a1a7
UNKNOWN
You know how sometimes you write the the same word twice in a sentence, but then don't notice that it happened? For example, you've been distracted for a second. Did you notice that *"the"* is doubled in the first sentence of this description? As as aS you can see, it's not easy to spot those errors, especially if wor...
["def count_adjacent_pairs(st): \n words = st.lower().split(' ')\n currentWord = None\n count = 0\n for i, word in enumerate(words):\n if i+1 < len(words):\n if word == words[i+1]:\n if word != currentWord:\n currentWord = word\n count +...
{"fn_name": "count_adjacent_pairs", "inputs": [[""], ["orange Orange kiwi pineapple apple"], ["banana banana banana"], ["banana banana banana terracotta banana terracotta terracotta pie!"], ["pineapple apple"]], "outputs": [[0], [1], [1], [2], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,168
def count_adjacent_pairs(st):
5dd8be39cb5bfa8f845057aae18e049c
UNKNOWN
## Task An `ATM` ran out of 10 dollar bills and only has `100, 50 and 20` dollar bills. Given an amount between `40 and 10000 dollars (inclusive)` and assuming that the ATM wants to use as few bills as possible, determinate the minimal number of 100, 50 and 20 dollar bills the ATM needs to dispense (in that order)....
["def withdraw(n):\n n50 = 0\n n20, r = divmod(n, 20)\n if r == 10:\n n20 -= 2\n n50 += 1\n n100, n20 = divmod(n20, 5)\n return [n100, n50, n20]", "def withdraw(n):\n hundreds, fifties, rest = n // 100, (n % 100) // 50, n % 50\n if rest % 20 == 10:\n if fifties == 0:\n ...
{"fn_name": "withdraw", "inputs": [[40], [250], [260], [230], [60]], "outputs": [[[0, 0, 2]], [[2, 1, 0]], [[2, 0, 3]], [[1, 1, 4]], [[0, 0, 3]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,554
def withdraw(n):
5ae6446e9a09499bd26c9b926b53f4f7
UNKNOWN
Construct a function 'coordinates', that will return the distance between two points on a cartesian plane, given the x and y coordinates of each point. There are two parameters in the function, ```p1``` and ```p2```. ```p1``` is a list ```[x1,y1]``` where ```x1``` and ```y1``` are the x and y coordinates of the first ...
["def coordinates(p1,p2, precision = 0):\n return round(sum( (b-a)**2 for a,b in zip(p1,p2) )**.5, precision)", "import math\n\ndef coordinates(p1, p2, precision=0):\n return round(math.hypot(p1[0] - p2[0], p1[1] - p2[1]), precision)", "def coordinates(a, b, p = 0):\n return round(sum((i - j) ** 2 for i, j in ...
{"fn_name": "coordinates", "inputs": [[[3, 6], [14, 6]], [[-2, 5], [-2, -10], 2], [[1, 2], [4, 6]], [[5, 3], [10, 15], 2], [[-2, -10], [6, 5]], [[4, 7], [6, 2], 3], [[-4, -5], [-5, -4], 1], [[3, 8], [3, 8]], [[-3, 8], [3, 8]], [[3, 8], [3, -8]]], "outputs": [[11], [15], [5], [13], [17], [5.385], [1.4], [0], [6], [16]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,380
def coordinates(p1, p2, precision=0):
de05922a6ba3ff1eb03d093caf7d51a7
UNKNOWN
You're about to go on a trip around the world! On this trip you're bringing your trusted backpack, that anything fits into. The bad news is that the airline has informed you, that your luggage cannot exceed a certain amount of weight. To make sure you're bringing your most valuable items on this journey you've decided...
["def pack_bagpack(scores, weights, capacity):\n load = [0] * (capacity + 1)\n for score, weight in zip(scores, weights):\n load = [max(l, weight <= w and load[w - weight] + score)\n for w, l in enumerate(load)]\n return load[-1]", "def pack_bagpack(S,W,C) :\n M = [0] * (1 + C)\n fo...
{"fn_name": "pack_bagpack", "inputs": [[[15, 10, 9, 5], [1, 5, 3, 4], 8], [[20, 5, 10, 40, 15, 25], [1, 2, 3, 8, 7, 4], 10], [[19, 8, 6, 20, 3, 16], [8, 2, 3, 10, 1, 5], 17], [[100, 5, 16, 18, 50], [25, 1, 3, 2, 15], 14]], "outputs": [[29], [60], [46], [39]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,179
def pack_bagpack(scores, weights, capacity):
caaf6491dce47c7b1be5196e1c66a1f1
UNKNOWN
You are provided with array of positive non-zero ints and int n representing n-th power (n >= 2). For the given array, calculate the sum of each value to the n-th power. Then subtract the sum of the original array. Example 1: Input: {1, 2, 3}, 3 --> (1 ^ 3 + 2 ^ 3 + 3 ^ 3 ) - (1 + 2 + 3) --> 36 - 6 --> Output: 30 Ex...
["def modified_sum(lst, p):\n return sum(n**p - n for n in lst)", "def modified_sum(a, n):\n return sum(i ** n for i in a) - sum(a)", "def modified_sum(a, n):\n return sum([x ** n - x for x in a])", "def modified_sum(a, n):\n return sum(i**n - i for i in a)", "def modified_sum(a, n):\n ans = 0\n for s...
{"fn_name": "modified_sum", "inputs": [[[1, 2, 3], 3], [[1, 2], 5], [[3, 5, 7], 2], [[1, 2, 3, 4, 5], 3], [[2, 7, 13, 17], 2], [[2, 5, 8], 3], [[2, 4, 6, 8], 6], [[5, 10, 15], 4], [[3, 6, 9, 12], 3]], "outputs": [[30], [30], [68], [210], [472], [630], [312940], [61220], [2670]]}
INTRODUCTORY
PYTHON3
CODEWARS
867
def modified_sum(a, n):
30836331d05a90d45af3355a6df2276e
UNKNOWN
You just took a contract with the Jedi council. They need you to write a function, `greet_jedi()`, which takes two arguments (a first name and a last name), works out the corresponding *Jedi name*, and returns a string greeting the Jedi. A person's *Jedi name* is the first three letters of their last name followed by ...
["def greet_jedi(first, last):\n return \"Greetings, master {}{}\".format(last[:3].capitalize(), first[:2].capitalize())", "def greet_jedi(f, l):\n return 'Greetings, master ' + l[0:3].capitalize() + f[0:2].capitalize()", "def greet_jedi(first, last):\n return 'Greetings, master %s%s' % (last[:3].capitalize(), f...
{"fn_name": "greet_jedi", "inputs": [["Beyonce", "Knowles"], ["Chris", "Angelico"], ["grae", "drake"]], "outputs": [["Greetings, master KnoBe"], ["Greetings, master AngCh"], ["Greetings, master DraGr"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,259
def greet_jedi(first, last):
025a6227cf9e7521535bd381d2461008
UNKNOWN
Consider the array `[3,6,9,12]`. If we generate all the combinations with repetition that sum to `12`, we get `5` combinations: `[12], [6,6], [3,9], [3,3,6], [3,3,3,3]`. The length of the sub-arrays (such as `[3,3,3,3]` should be less than or equal to the length of the initial array (`[3,6,9,12]`). Given an array of...
["from itertools import combinations_with_replacement\n\ndef find(arr,n):\n return sum( sum(c) == n for x in range(1,len(arr)+1) for c in combinations_with_replacement(arr, x) )", "def find(arr,n):\n return(findl(arr,n,len(arr)))\ndef findl(arr,n,l):\n return(sum(findl(arr[1:],n-arr[0]*i,l-i) for i in range(l+...
{"fn_name": "find", "inputs": [[[1, 2, 3], 10], [[1, 2, 3], 7], [[1, 2, 3], 5], [[3, 6, 9, 12], 12], [[1, 4, 5, 8], 8], [[3, 6, 9, 12], 15], [[3, 6, 9, 12, 14, 18], 30]], "outputs": [[0], [2], [3], [5], [3], [5], [21]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,589
def find(arr,n):
4e483e70f78d9fd9eaeb40e1f9c70d9d
UNKNOWN
Given an array of ints, return the index such that the sum of the elements to the right of that index equals the sum of the elements to the left of that index. If there is no such index, return `-1`. If there is more than one such index, return the left-most index. For example: ``` peak([1,2,3,5,3,2,1]) = 3, because ...
["def peak(arr):\n for i, val in enumerate(arr):\n if sum(arr[:i]) == sum(arr[i+1:]):\n return i\n return -1", "def peak(arr):\n for i in range(len(arr)):\n if sum(arr[:i]) == sum(arr[i+1:]): return i\n return -1", "def peak(arr):\n sl, sr = 0, sum(arr)\n for i,v in enumerate(...
{"fn_name": "peak", "inputs": [[[1, 2, 3, 5, 3, 2, 1]], [[1, 12, 3, 3, 6, 3, 1]], [[10, 20, 30, 40]]], "outputs": [[3], [2], [-1]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,567
def peak(arr):
e30497606a44fc33cebeed708a6c0bf3
UNKNOWN
Gordon Ramsay shouts. He shouts and swears. There may be something wrong with him. Anyway, you will be given a string of four words. Your job is to turn them in to Gordon language. Rules: Obviously the words should be Caps, Every word should end with '!!!!', Any letter 'a' or 'A' should become '@', Any other vowel ...
["def gordon(a):\n return '!!!! '.join(a.upper().split()).translate(str.maketrans('AEIOU', '@****'))+'!!!!'", "def gordon(s):\n return \" \".join(x + \"!!!!\" for x in s.upper().translate(str.maketrans(\"AIUEO\", \"@****\")).split())", "def gordon(a):\n return \" \".join(word.upper().translate(str.maketrans(\"...
{"fn_name": "gordon", "inputs": [["What feck damn cake"], ["are you stu pid"], ["i am a chef"], ["dont you talk tome"], ["how dare you feck"]], "outputs": [["WH@T!!!! F*CK!!!! D@MN!!!! C@K*!!!!"], ["@R*!!!! Y**!!!! ST*!!!! P*D!!!!"], ["*!!!! @M!!!! @!!!! CH*F!!!!"], ["D*NT!!!! Y**!!!! T@LK!!!! T*M*!!!!"], ["H*W!!!! D@R...
INTRODUCTORY
PYTHON3
CODEWARS
1,559
def gordon(a):
20a2dbcad61019ba0bf75b638988be3c
UNKNOWN
Oh no! Ghosts have reportedly swarmed the city. It's your job to get rid of them and save the day! In this kata, strings represent buildings while whitespaces within those strings represent ghosts. So what are you waiting for? Return the building(string) without any ghosts(whitespaces)! Example: Should return: If ...
["ghostbusters = lambda s: (s.replace(' ','') if (' ' in s) else\n \"You just wanted my autograph didn't you?\")", "import re\ndef ghostbusters(building):\n bs = re.subn('\\s','',building)\n return bs[0] if bs[1] else \"You just wanted my autograph didn't you?\"", "message = \"You just w...
{"fn_name": "ghostbusters", "inputs": [["Factor y"], ["O f fi ce"], ["BusStation"], ["Suite "], ["YourHouse"], ["H o t e l "]], "outputs": [["Factory"], ["Office"], ["You just wanted my autograph didn't you?"], ["Suite"], ["You just wanted my autograph didn't you?"], ["Hotel"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,594
def ghostbusters(building):
75a3b0e21b32ccde009036b2db424198
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: Given a string `str` that contains some "(" or ")". Your task is to find the longest substring in `str`(all brackets in the substring are closed). The resu...
["def find_longest(st):\n res,pos=0,[0]\n for i,b in enumerate(st,1):\n if b==\"(\": pos.append(i)\n else: \n try:pos.pop();res=max(res,i-pos[-1])\n except:pos.append(i)\n return res", "def find_longest(s):\n stack, m = [-1], 0\n for i,j in enumerate(s):\n if ...
{"fn_name": "find_longest", "inputs": [[")()("], ["((()"], ["((("], ["())((("], ["())()))))()()("]], "outputs": [[2], [2], [0], [2], [4]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,093
def find_longest(st):
12c61c2a9a98ebb766ddbac90d4c6316
UNKNOWN
In this Kata, you will remove the left-most duplicates from a list of integers and return the result. ```python # Remove the 3's at indices 0 and 3 # followed by removing a 4 at index 1 solve([3, 4, 4, 3, 6, 3]) # => [4, 6, 3] ``` More examples can be found in the test cases. Good luck!
["def solve(arr): \n re = []\n for i in arr[::-1]:\n if i not in re:\n re.append(i)\n return re[::-1]", "def solve(arr): \n return list(dict.fromkeys(arr[::-1]))[::-1]", "def solve(arr): \n return [a for i,a in enumerate(arr) if a not in arr[i+1:]]", "def solve(arr): \n list = arr.co...
{"fn_name": "solve", "inputs": [[[3, 4, 4, 3, 6, 3]], [[1, 2, 1, 2, 1, 2, 3]], [[1, 2, 3, 4]], [[1, 1, 4, 5, 1, 2, 1]]], "outputs": [[[4, 6, 3]], [[1, 2, 3]], [[1, 2, 3, 4]], [[4, 5, 2, 1]]]}
INTRODUCTORY
PYTHON3
CODEWARS
17,261
def solve(arr):
1aa7a04b651cfe69c78f41067bddd95e
UNKNOWN
### Happy Holidays fellow Code Warriors! Now, Dasher! Now, Dancer! Now, Prancer, and Vixen! On, Comet! On, Cupid! On, Donder and Blitzen! That's the order Santa wanted his reindeer...right? What do you mean he wants them in order by their last names!? Looks like we need your help Code Warrior! ### Sort Santa's Reinde...
["def sort_reindeer(reindeer_names):\n return sorted(reindeer_names, key=lambda s:s.split()[1])", "def sort_reindeer(names):\n return sorted(names, key=lambda x: x.split()[1])", "def lastname(name):\n name = name.split()\n return name[1]\n \ndef sort_reindeer(reindeer_names):\n reindeer_names.sort(key...
{"fn_name": "sort_reindeer", "inputs": [[["Kenjiro Mori", "Susumu Tokugawa", "Juzo Okita", "Akira Sanada"]], [[]], [["Yasuo Kodai", "Kenjiro Sado", "Daisuke Aihara", "Susumu Shima", "Akira Sanada", "Yoshikazu Okita", "Shiro Yabu", "Sukeharu Nanbu", "Sakezo Yamamoto", "Hikozaemon Ohta", "Juzo Mori", "Saburo Tokugawa"]],...
INTRODUCTORY
PYTHON3
CODEWARS
1,433
def sort_reindeer(reindeer_names):
516a6aaa9c354f63c49e7d1851732dae
UNKNOWN
The number 81 has a special property, a certain power of the sum of its digits is equal to 81 (nine squared). Eighty one (81), is the first number in having this property (not considering numbers of one digit). The next one, is 512. Let's see both cases with the details 8 + 1 = 9 and 9^(2) = 81 512 = 5 + 1 + 2 = 8 a...
["series = [0]\nfor a in range(2, 99):\n for b in range(2, 42):\n c = a**b\n if a == sum(map(int, str(c))):\n series.append(c)\npower_sumDigTerm = sorted(series).__getitem__", "def dig_sum(n):\n return sum(map(int, str(n)))\n\n\n\nterms = []\nfor b in range(2, 400):\n for p in range(2,...
{"fn_name": "power_sumDigTerm", "inputs": [[1], [2], [3], [4], [5], [6], [7]], "outputs": [[81], [512], [2401], [4913], [5832], [17576], [19683]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,010
def power_sumDigTerm(n):
e6854ceb2ac1648f92131ccaa08c97f1
UNKNOWN
A binary gap within a positive number ```num``` is any sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of ```num```. For example: ```9``` has binary representation ```1001``` and contains a binary gap of length ```2```. ```529``` has binary representation...
["def gap(num):\n s = bin(num)[2:].strip(\"0\")\n return max(map(len, s.split(\"1\")))", "import re\ndef gap(num):\n x=re.findall('(?=(10+1))',bin(num).lstrip('0b')) \n return max([len(i)-2 for i in x]) if x else 0", "import re\n\ndef gap(num):\n\n n = 0\n\n for m in re.finditer('(?=(1(0+)1))', bin(nu...
{"fn_name": "gap", "inputs": [[9]], "outputs": [[2]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,107
def gap(num):
273670766bdfc05b8e4cd3c819c5942d
UNKNOWN
# Task Miss X has only two combs in her possession, both of which are old and miss a tooth or two. She also has many purses of different length, in which she carries the combs. The only way they fit is horizontally and without overlapping. Given teeth' positions on both combs, find the minimum length of the purse she ...
["def combs(a, b):\n return min(mesh(a, b), mesh(b, a))\n\ndef mesh(a, b):\n for i in range(len(a)):\n for j, k in zip(a[i:], b):\n if j + k == '**': break\n else:\n return max(i + len(b), len(a))\n return len(a) + len(b) ", "def combs(comb1, comb2):\n options ...
{"fn_name": "combs", "inputs": [["*..*", "*.*"], ["*...*", "*.*"], ["*..*.*", "*.***"], ["*.*", "*.*"], ["*.**", "*.*"]], "outputs": [[5], [5], [9], [4], [5]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,755
def combs(comb1, comb2):
592e8cd46b5ba8fde6a73dd47804f9ef
UNKNOWN
Given an array of numbers, calculate the largest sum of all possible blocks of consecutive elements within the array. The numbers will be a mix of positive and negative values. If all numbers of the sequence are nonnegative, the answer will be the sum of the entire array. If all numbers in the array are negative, your ...
["def largest_sum(arr):\n sum = max_sum = 0\n for n in arr:\n sum = max(sum + n, 0)\n max_sum = max(sum, max_sum)\n return max_sum", "def largest_sum(arr):\n a, b, ar = 0, 0, arr[:]\n for i in ar:\n b+=i\n if b < 0: b = 0\n if b > a: a = b\n return a", "def largest_s...
{"fn_name": "largest_sum", "inputs": [[[-1, -2, -3]], [[]], [[1, 2, 3, 4]], [[31, -41, 59, 26, -53, 58, 97, -93, -23, 84]]], "outputs": [[0], [0], [10], [187]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,837
def largest_sum(arr):
011bc259dbc06d2ef4441a012bfb021d
UNKNOWN
Two strings ```a``` and b are called isomorphic if there is a one to one mapping possible for every character of ```a``` to every character of ```b```. And all occurrences of every character in ```a``` map to same character in ```b```. ## Task In this kata you will create a function that return ```True``` if two give...
["def isomorph(a, b):\n return [a.index(x) for x in a] == [b.index(y) for y in b]\n", "from itertools import zip_longest\n\ndef isomorph(a, b):\n return len(set(a)) == len(set(b)) == len(set(zip_longest(a, b)))", "def isomorph(s, t):\n if len(s) != len(t):\n return False\n p= set(zip(s, t))\n return all(l...
{"fn_name": "isomorph", "inputs": [["ESTATE", "DUELED"], ["XXX", "YYY"], ["CBAABC", "DEFFED"], ["RAMBUNCTIOUSLY", "THERMODYNAMICS"], ["DISCRIMINATIVE", "SIMPLIFICATION"], ["SEE", "SAW"], ["BANANA", "SENSE"], ["AB", "CC"], ["XXY", "XYY"], ["ABCBACCBA", "ABCBACCAB"], ["AA", "BBB"], ["abcdefghijk", "abcdefghijba"]], "outp...
INTRODUCTORY
PYTHON3
CODEWARS
2,084
def isomorph(a, b):
f21b44b7a78e1dd3dc61b9623a23c966
UNKNOWN
For a given 2D vector described by cartesian coordinates of its initial point and terminal point in the following format: ```python [[x1, y1], [x2, y2]] ``` Your function must return this vector's length represented as a floating point number. Error must be within 1e-7. Coordinates can be integers or floating point...
["def vector_length(vector):\n (x1,y1),(x2,y2) = vector\n return ((x1-x2)**2 + (y1-y2)**2) ** .5", "import math\n\n\ndef vector_length(vector):\n return math.hypot(vector[0][0] - vector[1][0],\n vector[0][1] - vector[1][1])\n", "import math\ndef vector_length(v):\n return math.sqrt(math.p...
{"fn_name": "vector_length", "inputs": [[[[0, 1], [0, 0]]], [[[0, 3], [4, 0]]], [[[1, -1], [1, -1]]]], "outputs": [[1], [5], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
916
def vector_length(vector):
4a8c149df405bc68706d90129d2615bd
UNKNOWN
```if:python Note: Python may currently have some performance issues. If you find them, please let me know and provide suggestions to improve the Python version! It's my weakest language... any help is much appreciated :) ``` Artlessly stolen and adapted from Hackerrank. Kara Danvers is new to CodeWars, and eager to...
["def leaderboard_climb(arr, kara):\n scores = sorted(set(arr), reverse=True)\n position = len(scores)\n ranks = []\n \n for checkpoint in kara:\n while position >= 1 and checkpoint >= scores[position - 1]:\n position -= 1\n ranks.append(position + 1) \n \n return ranks"...
{"fn_name": "leaderboard_climb", "inputs": [[[100, 90, 90, 80], [70, 80, 105]], [[982, 490, 339, 180], [180, 250, 721, 2500]], [[1982, 490, 339, 180], [180, 250, 721, 880]], [[1079, 490, 339, 180], [180, 250, 1200, 1980]]], "outputs": [[[4, 3, 1]], [[4, 4, 2, 1]], [[4, 4, 2, 2]], [[4, 4, 1, 1]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,560
def leaderboard_climb(arr, kara):
b6b976866c49c4274dbaf9c17f859642
UNKNOWN
Alan's child can be annoying at times. When Alan comes home and tells his kid what he has accomplished today, his kid never believes him. Be that kid. Your function 'AlanAnnoyingKid' takes as input a sentence spoken by Alan (a string). The sentence contains the following structure: "Today I " + [action_verb] +...
["OUTPUT = \"I don't think you {} today, I think you {} {} {}!\".format\n\n\ndef alan_annoying_kid(phrase):\n words = phrase.split()\n action = ' '.join(words[2:]).rstrip('.')\n if \"didn't\" in phrase:\n return OUTPUT(action, 'did', words[3], 'it')\n return OUTPUT(action, \"didn't\", words[2][:-2], ...
{"fn_name": "alan_annoying_kid", "inputs": [["Today I played football."], ["Today I didn't play football."], ["Today I didn't attempt to hardcode this Kata."], ["Today I cleaned the kitchen."], ["Today I learned to code like a pro."]], "outputs": [["I don't think you played football today, I think you didn't play at al...
INTRODUCTORY
PYTHON3
CODEWARS
3,645
def alan_annoying_kid(s):
f6b515a8e5fb468f2fc480fd63ca586d
UNKNOWN
# Task You have two sorted arrays `a` and `b`, merge them to form new array of unique items. If an item is present in both arrays, it should be part of the resulting array if and only if it appears in both arrays the same number of times. # Example For `a = [1, 3, 40, 40, 50, 60, 60, 60]` and `b = [2, 40, 40, 50...
["def merge_arrays(a, b):\n out = []\n for n in a+b:\n if n in a and n in b:\n if a.count(n) == b.count(n):\n out.append(n)\n else:\n out.append(n)\n return sorted(set(out))", "from collections import Counter\n\ndef merge_arrays(a, b):\n ca, cb = Counter(a)...
{"fn_name": "merge_arrays", "inputs": [[[10, 10, 10, 15, 20, 20, 25, 25, 30, 7000], [10, 15, 20, 20, 27, 7200]], [[500, 550, 1000, 1000, 1400, 3500], [2, 2, 2, 2, 3, 1500]], [[5], [5, 5, 7]]], "outputs": [[[15, 20, 25, 27, 30, 7000, 7200]], [[2, 3, 500, 550, 1000, 1400, 1500, 3500]], [[7]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,017
def merge_arrays(a, b):
6b318e28af71e11586223f3763cdc053
UNKNOWN
# Task Mobius function - an important function in number theory. For each given n, it only has 3 values: ``` 0 -- if n divisible by square of a prime. Such as: 4, 8, 9 1 -- if n not divisible by any square of a prime and have even number of prime factor. Such as: 6, 10, 21 -1 -- otherwise. Such as: 3, 5, 7,...
["def mobius(n):\n sP, p = set(), 2\n while n>1 and p <= n**.5:\n while not n%p:\n if p in sP: return 0\n sP.add(p)\n n //= p\n p += 1 + (p!=2)\n return (-1)**((len(sP) + (n!= 1)) % 2)", "def mobius(n):\n s, p, m = 0, 2, n ** .5\n while p <= m:\n if n...
{"fn_name": "mobius", "inputs": [[10], [9], [8], [100000000001], [7], [5]], "outputs": [[1], [0], [0], [0], [-1], [-1]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,501
def mobius(n):
f02e3b16f5d5b7047da7e0c9ad88a1d4
UNKNOWN
# Task You are given an array of integers. Your task is to determine the minimum number of its elements that need to be changed so that elements of the array will form an arithmetic progression. Note that if you swap two elements, you're changing both of them, for the purpose of this kata. Here an arithmetic progres...
["from collections import defaultdict\n\ndef fix_progression(arr):\n res = 0\n for i in range(len(arr)):\n D = defaultdict(int)\n for j in range(i):\n q, r = divmod(arr[i]-arr[j], i-j)\n if not r:\n D[q] += 1\n res = max(res, D[q])\n return len(...
{"fn_name": "fix_progression", "inputs": [[[1, 2, 3]], [[1, 3, 0, 7, 9]], [[1, 10, 2, 12, 3, 14, 4, 16, 5]], [[7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7]], [[2, -1, -4, 12, 1, -13, -16, -19, -6, -25]], [[-1, 2, 5, 8, 11, 14, 17, -6, 23, 26, -25, 32]], [[-10, -21, -20, -25, -13, 14, 2, 6, -50, -55, -...
INTRODUCTORY
PYTHON3
CODEWARS
5,502
def fix_progression(arr):
608da2ae536cdff6ab1f279b67da6d95
UNKNOWN
A `Nice array` is defined to be an array where for every value `n` in the array, there is also an element `n-1` or `n+1` in the array. example: ``` [2,10,9,3] is Nice array because 2=3-1 10=9+1 3=2+1 9=10-1 ``` Write a function named `isNice`/`IsNice` that returns `true` if its array argument is a Nice array, else `...
["def is_nice(arr):\n s = set(arr)\n return bool(arr) and all( n+1 in s or n-1 in s for n in s)", "def is_nice(arr):\n return all(x+1 in arr or x-1 in arr for x in arr) and len(arr)>0", "def is_nice(arr):\n for x in arr:\n if x + 1 not in arr and x - 1 not in arr:\n return False\n retur...
{"fn_name": "is_nice", "inputs": [[[2, 10, 9, 3]], [[3, 4, 5, 7]], [[0, 2, 19, 4, 4]], [[3, 2, 1, 0]], [[3, 2, 10, 4, 1, 6]], [[1, 1, 8, 3, 1, 1]], [[0, 1, 2, 3]], [[1, 2, 3, 4]], [[0, -1, 1]], [[0, 2, 3]], [[0]], [[]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 3, -2, 5, 4]], [[0, -1, -2, -3, -4]], [[1, -1, 3]], [[1, -...
INTRODUCTORY
PYTHON3
CODEWARS
1,268
def is_nice(arr):
5245f4d59ce7efd21f67bf9456977afa
UNKNOWN
Given two arrays, the purpose of this Kata is to check if these two arrays are the same. "The same" in this Kata means the two arrays contains arrays of 2 numbers which are same and not necessarily sorted the same way. i.e. [[2,5], [3,6]] is same as [[5,2], [3,6]] or [[6,3], [5,2]] or [[6,3], [2,5]] etc [[2,5], [3,6]]...
["def same(arr_a, arr_b):\n return sorted(map(sorted, arr_a)) == sorted(map(sorted, arr_b))", "def same(arr_a, arr_b):\n return sorted(sorted(a) for a in arr_a) == sorted(sorted(b) for b in arr_b)\n", "same=lambda a,b:sorted(sum(a,[])) == sorted(sum(b,[]))", "def same(arr_a, arr_b):\n return sorted(sorted(x) for...
{"fn_name": "same", "inputs": [[[[2, 5], [3, 6]], [[5, 2], [3, 6]]], [[[2, 5], [3, 6]], [[6, 3], [5, 2]]], [[[2, 5], [3, 6]], [[6, 3], [2, 5]]], [[[2, 5], [3, 5], [6, 2]], [[2, 6], [5, 3], [2, 5]]], [[[2, 5], [3, 5], [6, 2]], [[3, 5], [6, 2], [5, 2]]], [[], []], [[[2, 3], [3, 4]], [[4, 3], [2, 4]]], [[[2, 3], [3, 2]], ...
INTRODUCTORY
PYTHON3
CODEWARS
1,293
def same(arr_a, arr_b):
c31a503038614cd2b3b41820e3254100
UNKNOWN
Challenge: Given two null-terminated strings in the arguments "string" and "prefix", determine if "string" starts with the "prefix" string. Return 1 (or any other "truthy" value) if true, 0 if false. Example: ``` startsWith("hello world!", "hello"); // should return 1. startsWith("hello world!", "HELLO"); // should re...
["starts_with = str.startswith", "def starts_with(st, prefix): \n return st.startswith(prefix)", "def starts_with(st, prefix): \n return 1 if st[:len(prefix)] == prefix else 0", "def starts_with(st, prefix): \n x = len(prefix)\n if len(prefix) > len(st):\n return False\n if st[:x] == prefix:\n ...
{"fn_name": "starts_with", "inputs": [["hello world!", "hello"], ["hello world!", "HELLO"], ["nowai", "nowaisir"], ["", ""], ["abc", ""], ["", "abc"]], "outputs": [[true], [false], [false], [true], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,426
def starts_with(st, prefix):
671aad8469c9f79a5073e3479790dec0
UNKNOWN
In this kata you will be given an **integer n**, which is the number of times that is thown a coin. You will have to return an array of string for all the possibilities (heads[H] and tails[T]). Examples: ```coin(1) should return {"H", "T"}``` ```coin(2) should return {"HH", "HT", "TH", "TT"}``` ```coin(3) should return...
["from itertools import product\n\ndef coin(n):\n return list(map(''.join, product(*([\"HT\"]*n))))", "from itertools import product\n\ndef coin(n):\n return list(map(''.join, product('HT', repeat=n)))", "from itertools import product\n\ndef coin(n):\n return [''.join(xs) for xs in product('HT', repeat=n)]", "...
{"fn_name": "coin", "inputs": [[1], [2], [3]], "outputs": [[["H", "T"]], [["HH", "HT", "TH", "TT"]], [["HHH", "HHT", "HTH", "HTT", "THH", "THT", "TTH", "TTT"]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,379
def coin(n):
8d7e4bee568de42ec760912f3114a474
UNKNOWN
In this kata you have to correctly return who is the "survivor", ie: the last element of a Josephus permutation. Basically you have to assume that n people are put into a circle and that they are eliminated in steps of k elements, like this: ``` josephus_survivor(7,3) => means 7 people in a circle; one every 3 is eli...
["def josephus_survivor(n, k):\n v = 0\n for i in range(1, n + 1): v = (v + k) % i\n return v + 1", "def josephus_survivor(n,k):\n soldiers = [int(i) for i in range(1, n + 1)]\n counter = -1\n while len(soldiers) != 1:\n counter += k\n while counter >= len(soldiers):\n counter...
{"fn_name": "josephus_survivor", "inputs": [[7, 3], [11, 19], [40, 3], [14, 2], [100, 1], [1, 300], [2, 300], [5, 300], [7, 300], [300, 300]], "outputs": [[4], [10], [28], [13], [100], [1], [1], [1], [7], [265]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,932
def josephus_survivor(n,k):
11f13e140f5f86f27423d8a5ba1276f4
UNKNOWN
JavaScript provides a built-in parseInt method. It can be used like this: - `parseInt("10")` returns `10` - `parseInt("10 apples")` also returns `10` We would like it to return `"NaN"` (as a string) for the second case because the input string is not a valid number. You are asked to write a `myParseInt` method with...
["def my_parse_int(s):\n try:\n return int(s)\n except ValueError:\n return 'NaN'", "def my_parse_int(string):\n try:\n return int(string)\n except ValueError:\n return 'NaN'\n", "def my_parse_int(s):\n return int(s) if s.strip().isdigit() else \"NaN\"\n", "def my_parse_int(st...
{"fn_name": "my_parse_int", "inputs": [["9"], ["09"], ["009"], [" 9"], [" 9 "], ["\t9\n"], ["5 friends"], ["5friends"], ["I <3 u"], ["17.42"], ["0x10"], ["123~~"], ["1 1"], ["1 2 3"], ["1.0"]], "outputs": [[9], [9], [9], [9], [9], [9], ["NaN"], ["NaN"], ["NaN"], ["NaN"], ["NaN"], ["NaN"], ["NaN"], ["NaN"], ["NaN"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,271
def my_parse_int(string):
37e1080ba443df06661b102b002921ea
UNKNOWN
You are standing on top of an amazing Himalayan mountain. The view is absolutely breathtaking! you want to take a picture on your phone, but... your memory is full again! ok, time to sort through your shuffled photos and make some space... Given a gallery of photos, write a function to sort through your pictures. You ...
["def sort_photos(lst):\n lst = [[int(d) for d in f.split(\".img\")] for f in lst]\n s, l = sorted(lst), min(len(lst), 5)\n return [f\"{y}.img{n+(i==l)}\" for i, (y, n) in enumerate(s[-5:]+s[-1:])]\n", "def sort_photos(pics):\n tmp = sorted((pic[:8], int(pic[8:])) for pic in pics)\n return [x+str(y) for ...
{"fn_name": "sort_photos", "inputs": [[["2016.img1", "2016.img2", "2016.img3", "2016.img4", "2016.img5"]], [["2016.img4", "2016.img5", "2016.img1", "2016.img3", "2016.img2"]], [["2012.img2", "2016.img1", "2016.img3", "2016.img4", "2016.img5"]], [["2016.img1", "2013.img3", "2016.img2", "2015.img3", "2012.img7", "2016.im...
INTRODUCTORY
PYTHON3
CODEWARS
1,557
def sort_photos(pics):
0bac8d7e7c22f93fe77e857f6e74c70d
UNKNOWN
*** No Loops Allowed *** You will be given an array (a) and a value (x). All you need to do is check whether the provided array contains the value, without using a loop. Array can contain numbers or strings. X can be either. Return true if the array contains the value, false if not. With strings you will need to acco...
["def check(a, x): \n return x in a", "check=lambda a,x:x in a", "check = list.__contains__", "from operator import contains as check", "def check(a, x): \n return a.count(x) > 0", "check = lambda x,a: a in x", "def check(a, x): \n#My first solution\n\n# if x in a:\n# return True\n# else:\n# ...
{"fn_name": "check", "inputs": [[[66, 101], 66], [[80, 117, 115, 104, 45, 85, 112, 115], 45], [["t", "e", "s", "t"], "e"], [["what", "a", "great", "kata"], "kat"], [[66, "codewars", 11, "alex loves pushups"], "alex loves pushups"], [["come", "on", 110, "2500", 10, "!", 7, 15], "Come"], [["when's", "the", "next", "Katat...
INTRODUCTORY
PYTHON3
CODEWARS
11,237
def check(a, x):
598b5976611bd419848de986f10cf039
UNKNOWN
Given an array of integers `a` and integers `t` and `x`, count how many elements in the array you can make equal to `t` by **increasing** / **decreasing** it by `x` (or doing nothing). *EASY!* ```python # ex 1 a = [11, 5, 3] t = 7 x = 2 count(a, t, x) # => 3 ``` - you can make 11 equal to 7 by subtracting 2 twice - ...
["def count(a, t, x):\n return sum(not (t-v)%x if x else t==v for v in a)", "def count(a, t, y):\n return sum(not (x-t) % y if y else x == t for x in a)", "count=lambda a,t,x:sum(x and not(e-t)%x or e-t==0for e in a)", "def count(a, t, x):\n return sum((t-i)%x==0 for i in a) if x else sum(i==t for i in a)", "def...
{"fn_name": "count", "inputs": [[[11, 5, 3], 7, 2], [[-4, 6, 8], -7, -3]], "outputs": [[3], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
937
def count(a, t, x):
ac9b8ef6b732797180a3837d045cf838
UNKNOWN
Given a string `S` and a character `C`, return an array of integers representing the shortest distance from the current character in `S` to `C`. ### Notes * All letters will be lowercase. * If the string is empty, return an empty array. * If the character is not present, return an empty array. ## Examples ```python...
["def shortest_to_char(s, c):\n if not s or not c:\n return []\n\n indexes = [i for i, ch in enumerate(s) if ch == c]\n if not indexes:\n return []\n \n return [ min(abs(i - ic) for ic in indexes) for i in range(len(s)) ]\n", "def shortest_to_char(s, c):\n L = [i for i,x in enumerate...
{"fn_name": "shortest_to_char", "inputs": [["lovecodewars", "e"], ["aaaaa", "a"], ["aabbaabb", "a"], ["aaaabbbb", "b"], ["aaaaa", "b"], ["lovecoding", ""], ["", ""]], "outputs": [[[3, 2, 1, 0, 1, 2, 1, 0, 1, 2, 3, 4]], [[0, 0, 0, 0, 0]], [[0, 0, 1, 1, 0, 0, 1, 2]], [[4, 3, 2, 1, 0, 0, 0, 0]], [[]], [[]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,750
def shortest_to_char(s, c):
0eb9ba5e7e2bbbc0218d47358380c1d7
UNKNOWN
The objective is to disambiguate two given names: the original with another This kata is slightly more evolved than the previous one: [Author Disambiguation: to the point!](https://www.codewars.com/kata/580a429e1cb4028481000019). The function ```could_be``` is still given the original name and another one to test aga...
["import re\nimport unicodedata\n\nNAME = re.compile(\"[\\w-]+\")\n\ndef decompose(name):\n standarized = unicodedata.normalize('NFKD', name.lower()) \\\n .encode('ascii', 'ignore') if type(name) != str \\\n else name.lower()\n return re.findall(NAME, standarized)\n\ndef could_be(original, another):...
{"fn_name": "could_be", "inputs": [["Carlos Ray Norris", "Carlos Ray Norris"], ["Carlos Ray Norris", "Carlos Ray"], ["Carlos Ray Norris", "Ray Norris"], ["Carlos Ray Norris", "Carlos Norris"], ["Carlos Ray Norris", "Norris"], ["Carlos Ray Norris", "Carlos"], ["Carlos Ray Norris", "Norris Carlos"], ["Carlos Ray Norris",...
INTRODUCTORY
PYTHON3
CODEWARS
5,779
def could_be(original, another):
006cd63aa78082dc35fa837bdc61a102
UNKNOWN
A number m of the form 10x + y is divisible by 7 if and only if x − 2y is divisible by 7. In other words, subtract twice the last digit from the number formed by the remaining digits. Continue to do this until a number known to be divisible or not by 7 is obtained; you can stop when this number has *at most* 2 digits...
["def seven(m, step = 0):\n if m < 100: return (m, step)\n x, y, step = m // 10, m % 10, step + 1\n res = x - 2 * y\n return seven(res, step)", "def seven(m):\n steps = 0\n while m > 99:\n q, r = divmod(m, 10)\n m = q - (2 * r)\n steps += 1\n return m, steps\n", "seven = lambda m,s=0: ...
{"fn_name": "seven", "inputs": [[1021], [477557101], [477557102], [2340029794923400297949], [1603], [371], [1369851], [483], [483595], [0], [170232833617690725]], "outputs": [[[10, 2]], [[28, 7]], [[47, 7]], [[14, 20]], [[7, 2]], [[35, 1]], [[0, 5]], [[42, 1]], [[28, 4]], [[0, 0]], [[0, 16]]]}
INTRODUCTORY
PYTHON3
CODEWARS
20,315
def seven(m):
01b84c9337fbb511d539f4279ca1b2fc
UNKNOWN
Imagine a triangle of numbers which follows this pattern: * Starting with the number "1", "1" is positioned at the top of the triangle. As this is the 1st row, it can only support a single number. * The 2nd row can support the next 2 numbers: "2" and "3" * Likewise, the 3rd row, can only support the next 3 numbers:...
["def cumulative_triangle(n):\n return n*(n*n+1)/2", "def cumulative_triangle(n):\n return (n**3+n)/2", "def cumulative_triangle(n):\n return n*(n*n+1)//2", "cumulative_triangle=lambda n:(n**3+n)/2", "def cumulative_triangle(n):\n start = sum(range(n)) + 1\n return sum(range(start, start + n))", "def cum...
{"fn_name": "cumulative_triangle", "inputs": [[1], [2], [3], [4], [15], [150], [100], [500], [1000], [10000]], "outputs": [[1], [5], [15], [34], [1695], [1687575], [500050], [62500250], [500000500], [500000005000]]}
INTRODUCTORY
PYTHON3
CODEWARS
932
def cumulative_triangle(n):
732c23caa96c8870fe49bf155ea40d62
UNKNOWN
##Overview Write a helper function that takes in a Time object and converts it to a more human-readable format. You need only go up to '_ weeks ago'. ```python to_pretty(0) => "just now" to_pretty(40000) => "11 hours ago" ``` ##Specifics - The output will be an amount of time, t, included in one of the following phr...
["def to_pretty(s):\n if not s: return \"just now\"\n for t, w in (60, \"seconds\"), (60, \"minutes\"), (24, \"hours\"), (7, \"days\"), (53, \"weeks\"):\n s, r = divmod(s, t)\n if not s: return (r > 1 and str(r) + \" \" + w or (\"a \", \"an \")[t == 24] + w[:-1]) + \" ago\"", "def to_pretty(seconds)...
{"fn_name": "to_pretty", "inputs": [[0], [1], [30], [90], [180], [4000], [40000], [140000], [400000], [1000000], [10000000]], "outputs": [["just now"], ["a second ago"], ["30 seconds ago"], ["a minute ago"], ["3 minutes ago"], ["an hour ago"], ["11 hours ago"], ["a day ago"], ["4 days ago"], ["a week ago"], ["16 weeks ...
INTRODUCTORY
PYTHON3
CODEWARS
4,305
def to_pretty(seconds):
6dc0067db661faa6302479908dcf10ca
UNKNOWN
# Convert a linked list to a string ## Related Kata Although this Kata is not part of an official Series, you may also want to try out [Parse a linked list from a string](https://www.codewars.com/kata/582c5382f000e535100001a7) if you enjoyed this Kata. ## Preloaded Preloaded for you is a class, struct or derived da...
["def stringify(list):\n return 'None' if list == None else str(list.data) + ' -> ' + stringify(list.next)", "def stringify(ll):\n r = []\n while ll:\n r, ll = r + [str(ll.data)], ll.next\n return ' -> '.join(r + ['None'])", "def stringify(head):\n if head is None:\n return \"None\"\n re...
{"fn_name": "stringify", "inputs": [[null]], "outputs": [["None"]]}
INTRODUCTORY
PYTHON3
CODEWARS
20,622
def stringify(node):
9c2ba5b6748608fc4c31dad0173110c0
UNKNOWN
Ho ho! So you think you know integers, do you? Well then, young wizard, tell us what the Nth digit of the [Champernowne constant](https://en.wikipedia.org/wiki/Champernowne_constant) is! The constant proceeds like this: `0.12345678910111213141516...` I hope you see the pattern! Conjure a function that will accept an...
["def champernowne_digit(n):\n if not type(n) is int or n < 1:\n return float(\"NaN\")\n i, l = 1, 11\n while l <= n:\n i, l = i + 1, l + 9 * (i + 1) * 10**i\n return ((n - l) // (i * 10**(i - 1 - (n - l) % i))) % 10\n\nchampernowneDigit = champernowne_digit\n", "DIGIT_CNTS = [1] + [(10**i - 1...
{"fn_name": "champernowneDigit", "inputs": [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [20], [35], [36], [37], [100], [101], [102], [103], [104], [105], [190], [2890], [38890], [488890], [5888890], [3678608], [3678609], [3678610], [3678611], [3678612], [3678613], [3678614], [3897249], [3897189], [38...
INTRODUCTORY
PYTHON3
CODEWARS
3,763
def champernowneDigit(n):
ac366adfa70a17f0d8b3e5509ccf4625
UNKNOWN
# Description: Find the longest successive exclamation marks and question marks combination in the string. A successive exclamation marks and question marks combination must contains two part: a substring of "!" and a substring "?", they are adjacent. If more than one result are found, return the one which at lef...
["import re\n\ndef find(stg):\n matches = re.findall(r\"(!+|\\?+)\", stg)\n return max((f\"{a}{b}\" for a, b in zip(matches, matches[1:])), key=len, default=\"\")", "from itertools import groupby\n\ndef find(s):\n L = [k*len(list(v)) for k,v in groupby(s)]\n return max((x + y for x,y in zip(L, L[1:])), key=...
{"fn_name": "find", "inputs": [["!!"], ["!??"], ["!?!!"], ["!!???!????"], ["!!???!?????"], ["!????!!!?"], ["!?!!??!!!?"]], "outputs": [[""], ["!??"], ["?!!"], ["!!???"], ["!?????"], ["????!!!"], ["??!!!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,222
def find(s):
c8dfcdeb2612ee00f378722270644232
UNKNOWN
Everyone Knows AdFly and their Sister Sites. If we see the Page Source of an ad.fly site we can see this perticular line: Believe it or not This is actually the Encoded url which you would skip to. The Algorithm is as Follows: ``` 1) The ysmm value is broken like this ysmm = 0 1 2 3 4 5 6 7 8 9 = "0123456789" cod...
["import base64\nimport binascii\nimport math\nfrom itertools import zip_longest\n\n\ndef adFly_decoder(sc):\n code1 = \"\"\n code2 = \"\"\n flip = False\n for c in sc:\n if flip:\n code2 += c\n else:\n code1 += c\n flip = not flip\n\n try:\n url = base64...
{"fn_name": "adFly_decoder", "inputs": [["O=T0ZToPdRHJRmwdcOz1oGvTL22lFzkRZhih5GsbezSw9kndbvyR50wYawHIAF/SdhT1"], ["N=z0dDoMdyHIRmwac1zMolvWLz2RFmkMZiiZ5HsZeySw9kndbvyR50wYawHIAF/SdhT1"], ["lololol"]], "outputs": [["http://yahoo.com"], ["http://google.com"], ["Invalid"]]}
INTRODUCTORY
PYTHON3
CODEWARS
7,072
def adFly_decoder(sc):
f7550bc2d9638a1710bbf1b11e17b963
UNKNOWN
## Description: Remove all exclamation marks from the end of words. Words are separated by spaces in the sentence. ### Examples ``` remove("Hi!") === "Hi" remove("Hi!!!") === "Hi" remove("!Hi") === "!Hi" remove("!Hi!") === "!Hi" remove("Hi! Hi!") === "Hi Hi" remove("!!!Hi !!hi!!! !hi") === "!!!Hi !!hi !hi" ```
["def remove(s):\n return ' '.join(w.rstrip('!') or w for w in s.split())", "from re import sub\ndef remove(s):\n return sub('(\\w+)!+(\\s+|$)','\\\\1\\\\2', s)\n", "def remove(s):\n return \" \".join(x.rstrip(\"!\") for x in s.split())", "import re\n\ndef remove(s):\n return re.sub(r'\\b!+(?= |$)', '', s)"...
{"fn_name": "remove", "inputs": [["Hi!"], ["Hi!!!"], ["!Hi"], ["!Hi!"], ["Hi! Hi!"]], "outputs": [["Hi"], ["Hi"], ["!Hi"], ["!Hi"], ["Hi Hi"]]}
INTRODUCTORY
PYTHON3
CODEWARS
765
def remove(s):
b64bfbb474ec745810dee130530c9758
UNKNOWN
Bob has ladder. He wants to climb this ladder, but being a precocious child, he wonders about exactly how many ways he could to climb this `n` size ladder using jumps of up to distance `k`. Consider this example... n = 5\ k = 3 Here, Bob has ladder of length 5, and with each jump, he can ascend up to 3 steps (he can...
["from collections import deque\n\ndef count_ways(n, k):\n s,d = 1,deque([0]*k)\n for i in range(n):\n d.append(s)\n s = 2*s-d.popleft()\n return s-d.pop()", "from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef count_ways(n, k):\n if n < 0:\n return 0\n elif n <= 1:\n ...
{"fn_name": "count_ways", "inputs": [[1, 3], [3, 3], [2, 3], [5, 3], [4, 3], [10, 6], [14, 7]], "outputs": [[1], [4], [2], [13], [7], [492], [7936]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,971
def count_ways(n, k):
cdcdf75e4d57d61cfd55632262c017e6
UNKNOWN
Implement a function, `multiples(m, n)`, which returns an array of the first `m` multiples of the real number `n`. Assume that `m` is a positive integer. Ex. ``` multiples(3, 5.0) ``` should return ``` [5.0, 10.0, 15.0] ```
["def multiples(m, n):\n return [i * n for i in range(1, m+1)]", "def multiples(m, n):\n return [k * n for k in range(1, m+1)]", "multiples=lambda m,n:[n*e for e in range(1,m+1)]", "def multiples(m, n):\n array_multiples = []\n for i in range(1,m+1):\n array_multiples.append(float(i*n))\n return a...
{"fn_name": "multiples", "inputs": [[3, 5], [1, 3.14], [5, -1]], "outputs": [[[5, 10, 15]], [[3.14]], [[-1, -2, -3, -4, -5]]]}
INTRODUCTORY
PYTHON3
CODEWARS
12,570
def multiples(m, n):
1d5ea8cf75728d55cab46ad73eaddada
UNKNOWN
# Introduction Digital Cypher assigns a unique number to each letter of the alphabet: ``` a b c d e f g h i j k l m n o p q r s t u v w x y z 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ``` In the encrypted word we write the corresponding numbers instead o...
["def find_the_key(message, code):\n diffs = \"\".join( str(c - ord(m) + 96) for c, m in zip(code, message) )\n for size in range(1, len(code) +1):\n key = diffs[:size]\n if (key * len(code))[:len(code)] == diffs:\n return int(key)", "def find_the_key(message, code):\n key = \"\".join(...
{"fn_name": "find_the_key", "inputs": [["scout", [20, 12, 18, 30, 21]], ["masterpiece", [14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8]], ["nomoretears", [15, 17, 14, 17, 19, 7, 21, 7, 2, 20, 20]], ["notencrypted", [14, 15, 20, 5, 14, 3, 18, 25, 16, 20, 5, 4]], ["tenthousand", [21, 5, 14, 20, 8, 16, 21, 19, 1, 14, 5]], ["one...
INTRODUCTORY
PYTHON3
CODEWARS
3,431
def find_the_key(message, code):
b6f27461e22c55581ac436231e011cb9
UNKNOWN
We’ve all seen katas that ask for conversion from snake-case to camel-case, from camel-case to snake-case, or from camel-case to kebab-case — the possibilities are endless. But if we don’t know the case our inputs are in, these are not very helpful. ### Task: So the task here is to implement a function (called `id` ...
["import re\n\nCASES = [\n ('snake', re.compile(r'\\A[a-z]+(_[a-z]+)+\\Z')),\n ('kebab', re.compile(r'\\A[a-z]+(-[a-z]+)+\\Z')),\n ('camel', re.compile(r'\\A[a-z]+([A-Z][a-z]*)+\\Z')),\n ('none', re.compile(r'')),\n]\n\ndef case_id(c_str):\n for case, pattern in CASES:\n if pattern.match(c_str): r...
{"fn_name": "case_id", "inputs": [["hello-world"], ["hello-to-the-world"], ["hello_world"], ["hello_to_the_world"], ["helloWorld"], ["helloToTheWorld"], ["hello-World"], ["hello-To-The-World"], ["good-Night"], ["he--llo"], ["good-night"], ["good_night"], ["goodNight"], ["hello_World"], ["hello_To_The_World"], ["he_lloW...
INTRODUCTORY
PYTHON3
CODEWARS
3,415
def case_id(c_str):
9ac2f96676d2287dbe121ba93e190bf2
UNKNOWN
# Task Lonerz got some crazy growing plants and he wants to grow them nice and well. Initially, the garden is completely barren. Each morning, Lonerz can put any number of plants into the garden to grow. And at night, each plant mutates into two plants. Lonerz really hopes to see `n` plants in his garde...
["def plant_doubling(n):\n return bin(n).count(\"1\")", "def plant_doubling(n):\n p = 0\n while n:\n if n % 2 == 1:\n n -= 1\n p += 1\n n //= 2\n return p", "def plant_doubling(n):\n return bin(n)[2:].count(\"1\")", "import math\ndef plant_doubling(n):\n times = 0\n...
{"fn_name": "plant_doubling", "inputs": [[5], [8], [536870911], [1]], "outputs": [[2], [1], [29], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,344
def plant_doubling(n):
9f0cab4f780a344a5e1f2b04e4895c05
UNKNOWN
# Triple Trouble Create a function that will return a string that combines all of the letters of the three inputed strings in groups. Taking the first letter of all of the inputs and grouping them next to each other. Do this for every letter, see example below! **E.g. Input: "aa", "bb" , "cc" => Output: "abcabc"** ...
["def triple_trouble(one, two, three):\n return ''.join(''.join(a) for a in zip(one, two, three))\n", "def triple_trouble(one, two, three):\n return \"\".join(a+b+c for a,b,c in zip(one,two,three))", "def triple_trouble(*args):\n return \"\".join(\"\".join(a) for a in zip(*args))", "def triple_trouble(one,...
{"fn_name": "triple_trouble", "inputs": [["aaa", "bbb", "ccc"], ["aaaaaa", "bbbbbb", "cccccc"], ["burn", "reds", "roll"], ["Bm", "aa", "tn"], ["LLh", "euo", "xtr"]], "outputs": [["abcabcabc"], ["abcabcabcabcabcabc"], ["brrueordlnsl"], ["Batman"], ["LexLuthor"]]}
INTRODUCTORY
PYTHON3
CODEWARS
16,819
def triple_trouble(one, two, three):
97d1820390544c97c2fe06f1892b98e2
UNKNOWN
# Introduction Ka ka ka cypher is a cypher used by small children in some country. When a girl wants to pass something to the other girls and there are some boys nearby, she can use Ka cypher. So only the other girls are able to understand her. She speaks using KA, ie.: `ka thi ka s ka bo ka y ka i ka s ka u ka gly...
["import re\n\nKA_PATTERN = re.compile(r'(?![aeiou]+$)([aeiou]+)', re.I)\n\ndef ka_co_ka_de_ka_me(word):\n return 'ka' + KA_PATTERN.sub(r'\\1ka', word)", "from functools import partial\nfrom re import compile\n\nka_co_ka_de_ka_me = partial(compile(r\"(?i)^|(?<=[aeiou])(?![aeiou]|$)\").sub, \"ka\")", "def ka_co_ka_de...
{"fn_name": "ka_co_ka_de_ka_me", "inputs": [["ka"], ["a"], ["aa"], ["z"], ["Abbaa"], ["maintenance"], ["Woodie"], ["Incomprehensibilities"]], "outputs": [["kaka"], ["kaa"], ["kaaa"], ["kaz"], ["kaAkabbaa"], ["kamaikantekanakance"], ["kaWookadie"], ["kaIkancokamprekahekansikabikalikatiekas"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,683
def ka_co_ka_de_ka_me(word):
05a387edadc631db37fb8be988366c44
UNKNOWN
A carpet shop sells carpets in different varieties. Each carpet can come in a different roll width and can have a different price per square meter. Write a function `cost_of_carpet` which calculates the cost (rounded to 2 decimal places) of carpeting a room, following these constraints: * The carpeting has to be don...
["def cost_of_carpet(room_length, room_width, roll_width, roll_cost):\n x, y = sorted((room_length, room_width))\n if y == 0 or x > roll_width: return \"error\"\n if y < roll_width: return round(x * roll_width * roll_cost, 2)\n return round(y * roll_width * roll_cost, 2)", "def cost_of_carpet(room_length, r...
{"fn_name": "cost_of_carpet", "inputs": [[3, 5, 4, 10], [4, 5, 4, 10], [0, 0, 4, 10], [3, 2, 4, 10], [3.9, 2, 4, 10], [5, 6, 4, 10], [3, 2, 4, 0], [3, 2, 2, 10]], "outputs": [[200], [200], ["error"], [80], [80], ["error"], [0], [60]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,307
def cost_of_carpet(room_length, room_width, roll_width, roll_cost):
53c1b7252fca5bc6211cb31c405ee79e
UNKNOWN
Given an integer `n` return `"odd"` if the number of its divisors is odd. Otherwise return `"even"`. **Note**: big inputs will be tested. ## Examples: All prime numbers have exactly two divisors (hence `"even"`). For `n = 12` the divisors are `[1, 2, 3, 4, 6, 12]` – `"even"`. For `n = 4` the divisors are `[1, 2, 4...
["def oddity(n):\n #your code here\n return 'odd' if n**0.5 == int(n**0.5) else 'even'", "oddity=lambda n: [\"odd\",\"even\"][n**.5%1!=0]", "import math\ndef oddity(n):\n return math.sqrt(n) % 1 == 0 and 'odd' or 'even'", "import math\ndef oddity(n):\n \n return \"even\" if math.sqrt(n)%1 else \"odd\"\n"...
{"fn_name": "oddity", "inputs": [[1], [5], [16], [27], [121]], "outputs": [["odd"], ["even"], ["odd"], ["even"], ["odd"]]}
INTRODUCTORY
PYTHON3
CODEWARS
940
def oddity(n):
00705af5fef965a2c4572cec8066ecf1
UNKNOWN
You are given two arrays `arr1` and `arr2`, where `arr2` always contains integers. Write the function `find_array(arr1, arr2)` such that: For `arr1 = ['a', 'a', 'a', 'a', 'a']`, `arr2 = [2, 4]` `find_array returns ['a', 'a']` For `arr1 = [0, 1, 5, 2, 1, 8, 9, 1, 5]`, `arr2 = [1, 4, 7]` `find_array returns [1, 1, 1]`...
["def find_array(arr1, arr2):\n return [ arr1[i] for i in arr2 if i< len(arr1) ]", "def find_array(arr1, arr2):\n return [arr1[i] for i in arr2 if i <= len(arr1)]", "def find_array(arr1, arr2):\n arr = []\n try:\n for i in arr2:\n if len(arr1) == 0 or len(arr2) == 0:\n retur...
{"fn_name": "find_array", "inputs": [[["a", "a", "a", "a", "a"], [2, 4]], [[0, 1, 5, 2, 1, 8, 9, 1, 5], [1, 4, 7]], [[1, 2, 3, 4, 5], [0]], [["this", "is", "test"], [0, 1, 2]], [[0, 3, 4], [2, 6]], [[1], []], [[], [2]], [[], []]], "outputs": [[["a", "a"]], [[1, 1, 1]], [[1]], [["this", "is", "test"]], [[4]], [[]], [[]]...
INTRODUCTORY
PYTHON3
CODEWARS
1,220
def find_array(arr1, arr2):
5a20b3fe3cc18e0e642692f9e3191545
UNKNOWN
# Task You are given a binary string (a string consisting of only '1' and '0'). The only operation that can be performed on it is a Flip operation. It flips any binary character ( '0' to '1' and vice versa) and all characters to the `right` of it. For example, applying the Flip operation to the 4th character of ...
["def bin_str(s):\n return s.count(\"10\") * 2 + (s[-1] == \"1\")", "def bin_str(input):\n flips_needed = 0\n last_seen = '0'\n for c in input:\n if last_seen != c:\n flips_needed += 1\n last_seen = c\n return flips_needed", "import re\n\ndef bin_str(s):\n return len(re.fi...
{"fn_name": "bin_str", "inputs": [["0101"], ["10000"], ["0000000000"], ["1111111111"], ["10101010101010"], ["11111000011111"], ["000001111100000"], ["111000000000"], ["00000000111111111"], ["1010101011111111111111000000000"]], "outputs": [[3], [2], [0], [1], [14], [3], [2], [2], [1], [10]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,281
def bin_str(s):
2c8ff5e6788771355111d720e4322c97
UNKNOWN
Given a string, return a new string that has transformed based on the input: * Change case of every character, ie. lower case to upper case, upper case to lower case. * Reverse the order of words from the input. **Note:** You will have to handle multiple spaces, and leading/trailing spaces. For example: ``` "Exampl...
["def string_transformer(s):\n return ' '.join(s.swapcase().split(' ')[::-1])", "def string_transformer(s):\n return ' ' .join(s.split(' ')[::-1]).swapcase()", "def string_transformer(s):\n #1st step: split the string (done)\n x = []\n s = s.split(\" \")\n for i in range(1, 2 * len(s) - 1, 2):\n ...
{"fn_name": "string_transformer", "inputs": [["Example string"], ["Example Input"], ["To be OR not to be That is the Question"], [""], ["You Know When THAT Hotline Bling"], [" A b C d E f G "]], "outputs": [["STRING eXAMPLE"], ["iNPUT eXAMPLE"], ["qUESTION THE IS tHAT BE TO NOT or BE tO"], [""], ["bLING hOTLINE that...
INTRODUCTORY
PYTHON3
CODEWARS
2,254
def string_transformer(s):
d657269bbd52b0dd150944671586f979
UNKNOWN
Very simple, given a number, find its opposite. Examples: ``` 1: -1 14: -14 -34: 34 ``` ~~~if:sql You will be given a table: `opposite`, with a column: `number`. Return a table with a column: `res`. ~~~
["def opposite(number):\n return -number", "def opposite(number):\n return number * -1", "def opposite(number):\n return number * (-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1...
{"fn_name": "opposite", "inputs": [[1], [25.6], [0], [1425.2222], [-3.1458], [-95858588225]], "outputs": [[-1], [-25.6], [0], [-1425.2222], [3.1458], [95858588225]]}
INTRODUCTORY
PYTHON3
CODEWARS
22,507
def opposite(number):
37ce391233de7f32ebf956c529e5d4c4
UNKNOWN
Find the volume of a cone whose radius and height are provided as parameters to the function `volume`. Use the value of PI provided by your language (for example: `Math.PI` in JS, `math.pi` in Python or `Math::PI` in Ruby) and round down the volume to an Interger. If you complete this kata and there are no issues, ple...
["from math import pi\n\ndef volume(r,h):\n return pi * r**2 * h // 3", "from math import pi\n\n\ndef volume(r, h):\n return int(pi * r ** 2 * h / 3)", "from math import pi,floor\n\ndef volume(r,h):\n return floor(h/3 * pi * r ** 2)", "from math import pi\ndef volume(r,h):\n return (pi*h*r**2)//3", "import ...
{"fn_name": "volume", "inputs": [[7, 3], [56, 30], [0, 10], [10, 0], [0, 0]], "outputs": [[153], [98520], [0], [0], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,076
def volume(r,h):
5470c6a985ce5ae7014f89da40a8253d
UNKNOWN
Write a function taking in a string like `WOW this is REALLY amazing` and returning `Wow this is really amazing`. String should be capitalized and properly spaced. Using `re` and `string` is not allowed. Examples: ```python filter_words('HELLO CAN YOU HEAR ME') #=> Hello can you hear me filter_words('now THI...
["def filter_words(st):\n return ' '.join(st.capitalize().split())", "def filter_words(st):\n return \" \".join(st.split()).capitalize()\n", "def filter_words(st):\n st1 = st.lower()\n st2 = st1.capitalize()\n st3 = \" \".join(st2.split())\n return st3", "def filter_words(s):\n return ' '.join(s.spli...
{"fn_name": "filter_words", "inputs": [["HELLO world!"], ["This will not pass "], ["NOW THIS is a VERY EXCITING test!"]], "outputs": [["Hello world!"], ["This will not pass"], ["Now this is a very exciting test!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,174
def filter_words(st):
2cdecbf44bf5a1f1ccbafa1703b8d74c
UNKNOWN
Nickname Generator Write a function, `nicknameGenerator` that takes a string name as an argument and returns the first 3 or 4 letters as a nickname. If the 3rd letter is a consonant, return the first 3 letters. If the 3rd letter is a vowel, return the first 4 letters. If the string is less than 4 characters, retur...
["def nickname_generator(name):\n return \"Error: Name too short\" if len(name) < 4 else name[:3+(name[2] in \"aeiuo\")]", "def nickname_generator(name):\n return name[:3+(name[2] in 'aeiou')] if len(name) > 3 else 'Error: Name too short'", "def nickname_generator(name):\n return \"Error: Name too short\" if l...
{"fn_name": "nickname_generator", "inputs": [["Jimmy"], ["Samantha"], ["Sam"], ["Kayne"], ["Melissa"], ["James"], ["Gregory"], ["Jeannie"], ["Kimberly"], ["Timothy"], ["Dani"], ["Saamy"], ["Saemy"], ["Saimy"], ["Saomy"], ["Saumy"], ["Boyna"], ["Kiyna"], ["Sayma"], ["Ni"], ["Jam"], ["Suv"]], "outputs": [["Jim"], ["Sam"]...
INTRODUCTORY
PYTHON3
CODEWARS
1,706
def nickname_generator(name):
214971202c70827e3c5a5476a991147a
UNKNOWN
At the start of each season, every player in a football team is assigned their own unique squad number. Due to superstition or their history certain numbers are more desirable than others. Write a function generateNumber() that takes two arguments, an array of the current squad numbers (squad) and the new player's des...
["def generate_number(squad, n):\n if n not in squad: return n\n for i in range(1, 10):\n for j in range(1, 10):\n if i + j == n and i * 10 + j not in squad:\n return i * 10 + j", "def generate_number(lst, n):\n lst = set(lst)\n return (n if n not in lst else\n ne...
{"fn_name": "generate_number", "inputs": [[[1, 2, 3, 4, 6, 9, 10, 15, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 29, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 29, 38, 47, 56, 65, 69, 74, 83, 92], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 18, 23, 69], 18], [[1, 2, 3, 4, 6, 9, 10, 15, ...
INTRODUCTORY
PYTHON3
CODEWARS
2,359
def generate_number(squad, n):
9431161cf2821f0c82d911373560dcb8
UNKNOWN
This kata is an extension of "Combinations in a Set Using Boxes":https://www.codewars.com/kata/5b5f7f7607a266914200007c The goal for this kata is to get all the possible combinations (or distributions) (with no empty boxes) of a certain number of balls, but now, **with different amount of boxes.** In the previous kata...
["MAX_BALL = 2+1800\nDP,lst = [None], [0,1]\nfor _ in range(MAX_BALL):\n DP.append([sum(lst), *max( (v,i) for i,v in enumerate(lst) )])\n lst.append(0)\n lst = [ v*i + lst[i-1] for i,v in enumerate(lst) ]\n \ncombs_non_empty_boxesII = DP.__getitem__\n", "# this is [A000110, A002870, A024417]\n\n# Stirling n...
{"fn_name": "combs_non_empty_boxesII", "inputs": [[4], [3], [2], [20]], "outputs": [[[15, 7, 2]], [[5, 3, 2]], [[2, 1, 2]], [[51724158235372, 15170932662679, 8]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,747
def combs_non_empty_boxesII(n):
8897340725746e7058981d0fcab04cd0
UNKNOWN
###Story Sometimes we are faced with problems when we have a big nested dictionary with which it's hard to work. Now, we need to solve this problem by writing a function that will flatten a given dictionary. ###Info Python dictionaries are a convenient data type to store and process configurations. They allow you to s...
["def flatten(dictionary):\n stack = [((), dictionary)]\n result = {}\n while stack:\n path, current = stack.pop()\n for k, v in current.items():\n if v == {}:\n result[\"/\".join((path + (k,)))] = \"\";\n if isinstance(v, dict):\n stack.append(...
{"fn_name": "flatten", "inputs": [[{"key": "value"}], [{"key": {"deeper": {"more": {"enough": "value"}}}}], [{"empty": {}}], [{"additional": {"place": {"cell": "2", "zone": "1"}}, "job": "scout", "name": {"last": "Drone", "first": "One"}, "recent": {}}], [{"job": {"1": "scout", "2": "worker", "3": "writer", "4": "reade...
INTRODUCTORY
PYTHON3
CODEWARS
3,486
def flatten(dictionary):
db734ba02ae93bff736b3314447ec28a
UNKNOWN
Theory This section does not need to be read and can be skipped, but it does provide some clarity into the inspiration behind the problem. In music theory, a major scale consists of seven notes, or scale degrees, in order (with tonic listed twice for demonstrative purposes): Tonic, the base of the scale and the note ...
["def is_tune(notes):\n return bool(notes) and any(\n all((n + i) % 12 in {0, 2, 4, 5, 7, 9, 11} for n in notes)\n for i in range(12)\n )", "def is_tune(notes):\n if not notes: return False \n for j in range(12):\n if set((i + j) % 12 for i in notes).issubset({0, 2, 4, 5, 7, 9, 11}):\n ...
{"fn_name": "is_tune", "inputs": [[[1, 3, 6, 8, 10, 12]], [[1, 3, 6, 8, 10, 12, 13, 15]], [[1, 6, 3]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]], [[1, 3, 5, 6, 8, 10, 12]], [[3, 5, 6, 8, 10, 12]], [[]], [[1]], [[-11, -9, -7, -6, -4, -2, 0, 1, 3, 6, 8, 10, 12, 13, 15]], [[-4, -2, 0, 1, 3, 6, 8, 10, 12, 13, 15]]], "outpu...
INTRODUCTORY
PYTHON3
CODEWARS
2,204
def is_tune(notes):
6988409786fc1f644f885ce39554f5b6
UNKNOWN
*** No Loops Allowed *** You will be given an array (a) and a limit value (limit). You must check that all values in the array are below or equal to the limit value. If they are, return true. Else, return false. You can assume all values in the array are numbers. Do not use loops. Do not modify input array. Looking...
["def small_enough(a, limit): \n return max(a) <= limit", "def small_enough(a, limit): \n if max(a) <= limit:\n return True\n else:\n return False", "def small_enough(a, limit): \n if a[0] > limit:\n return False\n \n if len(a) > 1:\n return small_enough(a[1:], limit)\n...
{"fn_name": "small_enough", "inputs": [[[66, 101], 200], [[78, 117, 110, 99, 104, 117, 107, 115], 100], [[101, 45, 75, 105, 99, 107], 107], [[80, 117, 115, 104, 45, 85, 112, 115], 120]], "outputs": [[true], [false], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,589
def small_enough(a, limit):
c2d8db68a01af0ff07d923459218b87a
UNKNOWN
Write a function `count_vowels` to count the number of vowels in a given string. ### Notes: - Return `nil` or `None` for non-string inputs. - Return `0` if the parameter is omitted. ### Examples: ```python count_vowels("abcdefg") => 2 count_vowels("aAbcdeEfg") => 4 count_vowels(12) => None ```
["def count_vowels(s = ''):\n return sum(x.lower() in 'aeoui' for x in s) if type(s) == str else None", "import re\n\ndef count_vowels(s = ''):\n if isinstance(s, str):\n return sum(1 for _ in re.finditer(r'[aeiou]',s, flags=re.I))", "def count_vowels(s = ''):\n if type(s) != str: \n return None\...
{"fn_name": "count_vowels", "inputs": [["abcdefg"], ["asdfdsafdsafds"], [""], ["asdfdsaf asdfsdaf 13243242 dsafdsafds"], ["aeiouAEIOU"], ["1213"], ["12 3"], ["ewqriwetruituofdsajflsd23423r5043"], ["asdfviosdfopsiewrwwer asdf asdfdsaf)(asdflkajdsf "], ["asdfdsaf asdfsasdfdsafgjlsdjf asdfdsf daf 13243242...
INTRODUCTORY
PYTHON3
CODEWARS
1,624
def count_vowels(s = ''):
d256788d91f08e1b6b9c316ac1bdbcf6
UNKNOWN
In this simple exercise, you will build a program that takes a value, `integer `, and returns a list of its multiples up to another value, `limit `. If `limit` is a multiple of ```integer```, it should be included as well. There will only ever be positive integers passed into the function, not consisting of 0. The limi...
["def find_multiples(integer, limit):\n return list(range(integer, limit+1, integer))", "def find_multiples(integer, limit):\n arr = []\n count = integer\n while count <= limit:\n arr.append(count)\n count += integer\n return arr", "find_multiples = lambda a, b: list(range(a, b + 1, a))", "...
{"fn_name": "find_multiples", "inputs": [[5, 25], [1, 2], [5, 7], [4, 27], [11, 54]], "outputs": [[[5, 10, 15, 20, 25]], [[1, 2]], [[5]], [[4, 8, 12, 16, 20, 24]], [[11, 22, 33, 44]]]}
INTRODUCTORY
PYTHON3
CODEWARS
16,255
def find_multiples(integer, limit):
f645e299c8cf7e131e322563a6d8aeca
UNKNOWN
This will probably be a little series :) X-Shape You will get an odd Integer n (>= 3) and your task is to draw a X. Each line is separated with '\n'. Use the following characters: ■ □ For Ruby, Crystal and PHP: whitespace and o e.g.: ■□□□■ ■□■ ...
["def x(n):\n ret = [['\u25a1' for _ in range(n)] for _ in range(n)]\n for i in range(len(ret)):\n ret[i][i] = '\u25a0';\n ret[i][-1 - i] = '\u25a0';\n return '\\n'.join(''.join(row) for row in ret)", "f, e = \"\u25a0\u25a1\"\n\n\ndef x(n):\n l = n // 2\n middle = [f\"{e * l}{f}{e * l}\"]\n...
{"fn_name": "x", "inputs": [[3], [7]], "outputs": [["\u25a0\u25a1\u25a0\n\u25a1\u25a0\u25a1\n\u25a0\u25a1\u25a0"], ["\u25a0\u25a1\u25a1\u25a1\u25a1\u25a1\u25a0\n\u25a1\u25a0\u25a1\u25a1\u25a1\u25a0\u25a1\n\u25a1\u25a1\u25a0\u25a1\u25a0\u25a1\u25a1\n\u25a1\u25a1\u25a1\u25a0\u25a1\u25a1\u25a1\n\u25a1\u25a1\u25a0\u25a1\u2...
INTRODUCTORY
PYTHON3
CODEWARS
2,241
def x(n):
3bf7ba4e27eb6cadeb4008e21fff2368
UNKNOWN
Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result. It should remove all values from list `a`, which are present in list `b`. ```python array_diff([1,2],[1]) == [2] ``` If a value is present in `b`, all of its occurrences must be removed from th...
["def array_diff(a, b):\n return [x for x in a if x not in b]", "def array_diff(a, b):\n return [x for x in a if x not in set(b)]", "def array_diff(a, b):\n set_b = set(b)\n return [i for i in a if i not in set_b]", "def array_diff(a, b):\n #your code here\n for i in range(len(b)):\n while b[i]...
{"fn_name": "array_diff", "inputs": [[[1, 2], [1]], [[1, 2, 2], [1]], [[1, 2, 2], [2]], [[1, 2, 2], []], [[], [1, 2]]], "outputs": [[[2]], [[2, 2]], [[1]], [[1, 2, 2]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
879
def array_diff(a, b):
37f763348988662bad7a70d64294e0c8
UNKNOWN
# The Problem Dan, president of a Large company could use your help. He wants to implement a system that will switch all his devices into offline mode depending on his meeting schedule. When he's at a meeting and somebody texts him, he wants to send an automatic message informing that he's currently unavailable and th...
["def check_availability(schedule, current_time):\n for tb, te in schedule:\n if tb <= current_time < te:\n return te\n return True", "def check_availability(schedule, current_time):\n for time in schedule:\n if time[0] <= current_time < time[1]:\n return time[1]\n return...
{"fn_name": "check_availability", "inputs": [[[["09:30", "10:15"], ["12:20", "15:50"]], "10:00"], [[["09:30", "10:15"], ["12:20", "15:50"]], "11:00"], [[["09:30", "10:15"], ["12:20", "15:50"]], "10:15"], [[], "10:15"], [[["12:13", "23:50"]], "10:15"], [[["12:13", "23:50"]], "23:55"], [[["12:13", "23:50"]], "17:43"]], "...
INTRODUCTORY
PYTHON3
CODEWARS
1,427
def check_availability(schedule, current_time):
90efe9b0d22d10fdcb4a035e98d2b2bd
UNKNOWN
The purpose of this series is developing understanding of stastical problems in AS and A level maths. Let's get started with a simple concept in statistics: Mutually exclusive events. The probability of an OR event is calculated by the following rule: `P(A || B) = P(A) + P(B) - P(A && B)` The probability of event A ...
["def mutually_exclusive(dice, call1, call2):\n dice = dict(dice)\n if abs(sum(dice.values()) - 1) < 1e-12:\n return '%0.2f' % (dice[call1] + dice[call2])", "def mutually_exclusive(dice, call1, call2):\n if sum(prob for _, prob in dice) != 1:\n return None\n x = dict(dice)\n return format(x...
{"fn_name": "mutually_exclusive", "inputs": [[[[3, 0.4], [4, 0.1], [1, 0.01], [2, 0.09], [5, 0.2], [6, 0.1]], 1, 6], [[[1, 0.1], [2, 0.14], [3, 0.16], [4, 0.2], [5, 0.15], [6, 0.25]], 1, 4], [[[1, 0.6], [2, 0.1001], [3, 0.0999], [4, 0.1], [5, 0.05], [6, 0.05]], 3, 4], [[[6, 0.25], [1, 0.1], [3, 0.16], [2, 0.14], [5, 0....
INTRODUCTORY
PYTHON3
CODEWARS
2,882
def mutually_exclusive(dice, call1, call2):
58db8206112e9f7248035e6f1502711b
UNKNOWN
# Task The year of `2013` is the first year after the old `1987` with only distinct digits. Now your task is to solve the following problem: given a `year` number, find the minimum year number which is strictly larger than the given one and has only distinct digits. # Input/Output - `[input]` integer `year` `1...
["def distinct_digit_year(year):\n year += 1\n while len(set(str(year))) != 4:\n year += 1\n return year\n #coding and coding..\n", "def distinct_digit_year(year):\n year += 1\n \n if len(set(str(year))) == len(str(year)):\n return year \n \n return distinct_digit_year(year)",...
{"fn_name": "distinct_digit_year", "inputs": [[1987], [2013]], "outputs": [[2013], [2014]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,827
def distinct_digit_year(year):
cbf36346d1df52b4893357ca13b6d1dc
UNKNOWN
Let us begin with an example: A man has a rather old car being worth $2000. He saw a secondhand car being worth $8000. He wants to keep his old car until he can buy the secondhand one. He thinks he can save $1000 each month but the prices of his old car and of the new one decrease of 1.5 percent per month. Furtherm...
["def nbMonths(oldCarPrice, newCarPrice, saving, loss):\n months = 0\n budget = oldCarPrice\n \n while budget < newCarPrice:\n months += 1\n if months % 2 == 0:\n loss += 0.5\n \n oldCarPrice *= (100 - loss) / 100\n newCarPrice *= (100 - loss) / 100\n bud...
{"fn_name": "nbMonths", "inputs": [[2000, 8000, 1000, 1.5], [8000, 12000, 500, 1], [18000, 32000, 1500, 1.25], [7500, 32000, 300, 1.55]], "outputs": [[[6, 766]], [[8, 597]], [[8, 332]], [[25, 122]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,208
def nbMonths(startPriceOld, startPriceNew, savingperMonth, percentLossByMonth):
82671bf30f63a7f349a8c02eb206899f
UNKNOWN
# Introduction Digital Cypher assigns to each letter of the alphabet unique number. For example: ``` a b c d e f g h i j k l m 1 2 3 4 5 6 7 8 9 10 11 12 13 n o p q r s t u v w x y z 14 15 16 17 18 19 20 21 22 23 24 25 26 ``` Instead of letters in encrypted word we write the corre...
["from itertools import cycle\n\ndef encode(message, key):\n return [ord(a) - 96 + int(b) for a,b in zip(message,cycle(str(key)))]", "def encode(message, key):\n # initialize variables\n output = []\n i = 0\n \n # convert key to a list of integers\n key = [int(d) for d in str(key)]\n \n # enc...
{"fn_name": "encode", "inputs": [["scout", 1939], ["masterpiece", 1939]], "outputs": [[[20, 12, 18, 30, 21]], [[14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8]]]}
INTRODUCTORY
PYTHON3
CODEWARS
26,856
def encode(message, key):
b8e4edcd7b18b7ff7648c472717d81a0
UNKNOWN
##Task: You have to write a function **pattern** which creates the following pattern upto n number of rows. *If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string.* ##Pattern: (n) (n)(n-1) (n)(n-1)(n-2) ................ ................. (n)(n-1)(n-2)....4 ...
["def pattern(n):\n return '\\n'.join(''.join(str(i) for i in range(n, j, -1)) for j in range(n - 1, -1, -1))", "def pattern(n):\n return \"\\n\".join(\"\".join(str(j) for j in range(n, n-i, -1)) for i in range(1, n+1))", "def pattern(n):\n full = [str(x) for x in range(n, 0, -1)]\n take = lambda x: ''.join...
{"fn_name": "pattern", "inputs": [[1], [2], [5], [0], [-25]], "outputs": [["1"], ["2\n21"], ["5\n54\n543\n5432\n54321"], [""], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,094
def pattern(n):
ee32eef70f76177240980d5dac7ccd84
UNKNOWN
You have stumbled across the divine pleasure that is owning a dog and a garden. Now time to pick up all the cr@p! :D Given a 2D array to represent your garden, you must find and collect all of the dog cr@p - represented by '@'. You will also be given the number of bags you have access to (bags), and the capactity of ...
["def crap(garden, bags, cap):\n cap *= bags\n for turf in garden:\n if 'D' in turf: return 'Dog!!'\n cap -= turf.count('@')\n return 'Cr@p' if cap < 0 else 'Clean'", "from collections import Counter\nfrom itertools import chain\n\ndef crap(garden, bags, cap):\n c = Counter(chain(*garden))\n ...
{"fn_name": "crap", "inputs": [[[["_", "_", "_", "_"], ["_", "_", "_", "@"], ["_", "_", "@", "_"]], 2, 2], [[["_", "_", "_", "_"], ["_", "_", "_", "@"], ["_", "_", "@", "_"]], 1, 1], [[["_", "_"], ["_", "@"], ["D", "_"]], 2, 2], [[["_", "_", "_", "_"], ["_", "_", "_", "_"], ["_", "_", "_", "_"]], 2, 2], [[["@", "@"], [...
INTRODUCTORY
PYTHON3
CODEWARS
2,282
def crap(garden, bags, cap):
6f8e2782031d80a1b2a47a2d2285fcc7
UNKNOWN
Your dad doesn't really *get* punctuation, and he's always putting extra commas in when he posts. You can tolerate the run-on sentences, as he does actually talk like that, but those extra commas have to go! Write a function called ```dadFilter``` that takes a string as argument and returns a string with the extraneou...
["from re import compile, sub\n\nREGEX = compile(r',+')\n\n\ndef dad_filter(strng):\n return sub(REGEX, ',', strng).rstrip(' ,')\n", "import re\ndef dad_filter(string):\n return re.sub(r',+',r',',string).rstrip(', ')", "import re\ndef dad_filter(string):\n return re.sub(r'((?<=\\,)\\,+|[\\s,]+\\Z)','',string)"...
{"fn_name": "dad_filter", "inputs": [["all this,,,, used to be trees,,,,,,"], ["Listen,,,, kid,,,,,,"], ["Luke,,,,,,,,, I am your father,,,,,,,,, "], ["i,, don't believe this round earth,,, show me evadence!!"], ["Dead or alive,,,, you're coming with me,,, "]], "outputs": [["all this, used to be trees"], ["Listen, k...
INTRODUCTORY
PYTHON3
CODEWARS
1,298
def dad_filter(string):
722f9701e0afdb109194b4dcc3749607
UNKNOWN
Write a program to determine if two numbers are coprime. A pair of numbers are coprime if their greatest shared factor is 1. For example: ``` 20 and 27 Factors of 20: 1, 2, 4, 5, 10, 20 Factors of 27: 1, 3, 9, 27 Greatest shared factor: 1 20 and 27 are coprime``` An example of two numbers that are not coprime: ``` 12 a...
["from fractions import gcd\n\ndef are_coprime(n, m):\n return gcd(n, m) == 1", "def are_coprime(n, m):\n # All hail Euclid and his wonderful algorithm\n while m > 0:\n n, m = m, n % m\n return n == 1", "from math import gcd\n\ndef are_coprime(n , m):\n return gcd(n, m) == 1", "from fractions import...
{"fn_name": "are_coprime", "inputs": [[20, 27], [12, 39], [17, 34], [34, 17], [35, 10], [64, 27]], "outputs": [[true], [false], [false], [false], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,437
def are_coprime(n, m):
2581dca87722e831e9acd282114903cb
UNKNOWN
Jack really likes his number five: the trick here is that you have to multiply each number by 5 raised to the number of digits of each numbers, so, for example: ```python multiply(3)==15 multiply(10)==250 multiply(200)==25000 multiply(0)==0 multiply(-3)==-15 ```
["def multiply(n):\n return n*5**len(str(abs(n))) ", "def multiply(n):\n return 5 ** len(str(abs(n))) * n", "multiply=lambda n: n*5**len(str(abs(n)))", "def multiply(n):\n return n * 5 ** number_of_digits(n)\n\n\ndef number_of_digits(n: int):\n return 1 if -10 < n < 10 else 1 + number_of_digits(n // 10)", "de...
{"fn_name": "multiply", "inputs": [[10], [5], [200], [0], [-2]], "outputs": [[250], [25], [25000], [0], [-10]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,989
def multiply(n):
c382a4931d51b5a2b4c441cf36dc855f
UNKNOWN
## Task Given an array of strings, reverse them and their order in such way that their length stays the same as the length of the original inputs. ### Example: ``` Input: {"I", "like", "big", "butts", "and", "I", "cannot", "lie!"} Output: {"!", "eilt", "onn", "acIdn", "ast", "t", "ubgibe", "kilI"} ``` Good luck!
["def reverse(a):\n s=reversed(''.join(a))\n return [''.join(next(s) for _ in w) for w in a]", "def reverse(a):\n s = ''.join(a)[::-1]\n l, x = [], 0\n for i in a:\n l.append(s[x:x+len(i)])\n x += len(i)\n return l", "def reverse(a):\n s=list(''.join(a))\n return [''.join(s.pop() f...
{"fn_name": "reverse", "inputs": [[["I", "like", "big", "butts", "and", "I", "cannot", "lie!"]], [["?kn", "ipnr", "utotst", "ra", "tsn", "iksr", "uo", "yer", "ofebta", "eote", "vahu", "oyodpm", "ir", "hsyn", "amwoH"]]], "outputs": [[["!", "eilt", "onn", "acIdn", "ast", "t", "ubgibe", "kilI"]], [["How", "many", "shrimp"...
INTRODUCTORY
PYTHON3
CODEWARS
1,533
def reverse(a):
4b4c11f673131f4b3536d60e393e53fc
UNKNOWN
I'm afraid you're in a rather unfortunate situation. You've injured your leg, and are unable to walk, and a number of zombies are shuffling towards you, intent on eating your brains. Luckily, you're a crack shot, and have your trusty rifle to hand. The zombies start at `range` metres, and move at 0.5 metres per second...
["def zombie_shootout(zombies, distance, ammo, shot=0):\n \n if not zombies:\n return f'You shot all {shot} zombies.'\n \n if distance <= 0:\n return f'You shot {shot} zombies before being eaten: overwhelmed.'\n \n if not ammo:\n return f'You shot {shot} zombies before being eaten...
{"fn_name": "zombie_shootout", "inputs": [[3, 10, 10], [100, 8, 200], [50, 10, 8], [10, 10, 10], [17, 8, 200], [9, 10, 8], [20, 10, 20], [100, 49, 200], [50, 10, 19], [50, 10, 49], [100, 10, 20], [19, 10, 20], [20, 10, 100], [20, 10, 19], [19, 15, 19], [19, 3, 19]], "outputs": [["You shot all 3 zombies."], ["You shot 1...
INTRODUCTORY
PYTHON3
CODEWARS
3,552
def zombie_shootout(zombies, distance, ammo):
19e016a7cd9d795fb1e593cd30707216
UNKNOWN
# Introduction There is a war and nobody knows - the alphabet war! There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began. # Task Write a function that accepts `fight` string consists of only small letters and return who wins the fight. ...
["def alphabet_war(fight):\n d = {'w':4,'p':3,'b':2,'s':1,\n 'm':-4,'q':-3,'d':-2,'z':-1}\n r = sum(d[c] for c in fight if c in d)\n \n return {r==0:\"Let's fight again!\",\n r>0:\"Left side wins!\",\n r<0:\"Right side wins!\"\n }[True]", "def alphabet_war(fight):\n ...
{"fn_name": "alphabet_war", "inputs": [["z"], ["zdqmwpbs"], ["wq"], ["zzzzs"], ["wwwwww"]], "outputs": [["Right side wins!"], ["Let's fight again!"], ["Left side wins!"], ["Right side wins!"], ["Left side wins!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
45,899
def alphabet_war(fight):
fe0e7ca1c48640ebfae5159c8b82fb9c
UNKNOWN
#### Task: Your job here is to implement a function `factors`, which takes a number `n`, and outputs an array of arrays comprised of two parts, `sq` and `cb`. The part `sq` will contain all the numbers that, when squared, yield a number which is a factor of `n`, while the `cb` part will contain all the numbers that, w...
["def factors(n):\n sq = [a for a in range(2, n+1) if not n % (a**2)]\n cb = [b for b in range(2, n+1) if not n % (b**3)]\n return [sq, cb]", "def factors(n):\n sq = [i for i in range(2, int(n**0.5) + 2) if n%(i*i)==0]\n cb = [i for i in range(2, int(n**(1/3) + 2)) if n%(i*i*i)==0]\n return [sq, cb]",...
{"fn_name": "factors", "inputs": [[1], [4], [16], [81], [80], [100], [5], [120], [18], [8]], "outputs": [[[[], []]], [[[2], []]], [[[2, 4], [2]]], [[[3, 9], [3]]], [[[2, 4], [2]]], [[[2, 5, 10], []]], [[[], []]], [[[2], [2]]], [[[3], []]], [[[2], [2]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,821
def factors(n):
b90bdd1f9b7e073e3fe811ecf8b70ce9
UNKNOWN
# Summation Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0. For example: ```if-not:racket ~~~ summation(2) -> 3 1 + 2 summation(8) -> 36 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 ~~~ ``` ```if:racket ~~~racket (summation 2) ; 3 (+ 1 2) (summat...
["def summation(num):\n return sum(range(num + 1))\n \n", "def summation(num):\n return (1+num) * num / 2", "def summation(num):\n return sum(range(1,num+1))\n \n", "def summation(num):\n return sum(range(num + 1))\n \n", "def summation(num):\n total = 0\n for i in range(0, num+1):\n t...
{"fn_name": "summation", "inputs": [[1], [8], [22], [100], [213]], "outputs": [[1], [36], [253], [5050], [22791]]}
INTRODUCTORY
PYTHON3
CODEWARS
12,077
def summation(num):
cef3877b30415772807cc4058d9f0306
UNKNOWN
Consider having a cow that gives a child every year from her fourth year of life on and all her subsequent children do the same. After n years how many cows will you have? Return null if n is not an integer. Note: Assume all the cows are alive after n years.
["def count_cows(n):\n if not isinstance(n, int):\n return None\n return 1 if n < 3 else count_cows(n-1) + count_cows(n-3)", "def count_cows(n):\n if isinstance(n, int):\n a, b, c = 1, 0, 0\n for _ in range(n):\n a, b, c = c, a, b + c\n return a + b + c", "def count_cows(...
{"fn_name": "count_cows", "inputs": [[1], [3], [5]], "outputs": [[1], [2], [4]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,933
def count_cows(n):
4f54ff2d3c5722fdf4a7fe8a5e398c88
UNKNOWN
Colour plays an important role in our lifes. Most of us like this colour better then another. User experience specialists believe that certain colours have certain psychological meanings for us. You are given a 2D array, composed of a colour and its 'common' association in each array element. The function you will wri...
["def colour_association(arr):\n return [{k: v} for k, v in arr]", "def colour_association(arr):\n return [{color: assoc} for color, assoc in arr]", "def colour_association(arr):\n result = []\n for association in arr:\n colour, value = association\n result.append({colour : value})\n return...
{"fn_name": "colour_association", "inputs": [[[["white", "goodness"], ["blue", "tranquility"]]], [[["red", "energy"], ["yellow", "creativity"], ["brown", "friendly"], ["green", "growth"]]], [[["pink", "compassion"], ["purple", "ambition"]]], [[["gray", "intelligence"], ["black", "classy"]]], [[["white", "goodness"], ["...
INTRODUCTORY
PYTHON3
CODEWARS
2,013
def colour_association(arr):
71aeac38609fc2d24bea024e10c943aa
UNKNOWN
This is a problem that involves adding numbers to items in a list. In a list you will have to add the item's remainder when divided by a given divisor to each item. For example if the item is 40 and the divisor is 3 you would have to add 1 since 40 minus the closest multiple of 3 which is 39 is 1. So the 40 in the lis...
["def solve(nums,div):\n return [x + x % div for x in nums]\n\n", "def solve(nums,div): return [n+n%div for n in nums]", "solve = lambda n, d: [k + k%d for k in n]\n", "def solve(numbers, divisor):\n return [num + (num % divisor) for num in numbers]\n", "solve = lambda n, d: [i + i % d for i in n]", "def solve(nu...
{"fn_name": "solve", "inputs": [[[2, 7, 5, 9, 100, 34, 32, 0], 3], [[], 2], [[1000, 999, 998, 997], 5], [[0, 0, 0, 0], 5], [[4, 3, 2, 1], 5], [[33, 23, 45, 78, 65], 10]], "outputs": [[[4, 8, 7, 9, 101, 35, 34, 0]], [[]], [[1000, 1003, 1001, 999]], [[0, 0, 0, 0]], [[8, 6, 4, 2]], [[36, 26, 50, 86, 70]]]}
INTRODUCTORY
PYTHON3
CODEWARS
892
def solve(nums,div):
fc8bee5546eb8b418e9943cf2f4abf66
UNKNOWN
Given a lowercase string that has alphabetic characters only and no spaces, return the highest value of consonant substrings. Consonants are any letters of the alphabet except `"aeiou"`. We shall assign the following values: `a = 1, b = 2, c = 3, .... z = 26`. For example, for the word "zodiacs", let's cross out the...
["import re\n\ndef solve(s):\n return max(sum(ord(c)-96 for c in subs) for subs in re.split('[aeiou]+', s))", "def solve(s):\n max_ord = 0\n curr_ord = 0\n for char in s:\n if char not in 'aeiou':\n curr_ord += ord(char)-ord('a')+1\n else:\n if curr_ord > max_ord:\n ...
{"fn_name": "solve", "inputs": [["zodiac"], ["chruschtschov"], ["khrushchev"], ["strength"], ["catchphrase"], ["twelfthstreet"], ["mischtschenkoana"]], "outputs": [[26], [80], [38], [57], [73], [103], [80]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,423
def solve(s):
dd86fa2a26428cb43b239ab26ab84cb1
UNKNOWN
A high school has a strange principal. On the first day, he has his students perform an odd opening day ceremony: There are number of lockers "n" and number of students "n" in the school. The principal asks the first student to go to every locker and open it. Then he has the second student go to every second locker an...
["# First, I coded a straightforward solution. It would work, but because it had to loop over all\n# students, and for every student over each locker, it had to do n^2 iterations. With numbers under\n# 10k this proved no problem, however the test cases apparently tested bigger numbers, since my\n# program kept getting ...
{"fn_name": "num_of_open_lockers", "inputs": [[0], [1], [4], [56], [128], [500], [562], [74864], [3991700], [950811894]], "outputs": [[0], [1], [2], [7], [11], [22], [23], [273], [1997], [30835]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,324
def num_of_open_lockers(n):
a3c10909416967722d033d5179a4a8ca
UNKNOWN
Complete the function that takes two integers (`a, b`, where `a < b`) and return an array of all integers between the input parameters, **including** them. For example: ``` a = 1 b = 4 --> [1, 2, 3, 4] ```
["def between(a,b):\n return list(range(a,b+1))", "def between(a,b):\n # good luck\n return list((x for x in range(a, b + 1)))\n # thanks\n", "def between(a,b):\n return [result for result in range(a,b+1)]\n", "between=lambda a,b:list(range(a,b+1))", "def between(a,b):\n arr = []\n for i in range(a...
{"fn_name": "between", "inputs": [[1, 4], [-2, 2], [-10, 10], [5, 100]], "outputs": [[[1, 2, 3, 4]], [[-2, -1, 0, 1, 2]], [[-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35...
INTRODUCTORY
PYTHON3
CODEWARS
6,891
def between(a,b):
b273235d94184d55d0cc679891c1d91c
UNKNOWN
###Task: You have to write a function **pattern** which creates the following Pattern(See Examples) upto n(parameter) number of rows. ####Rules/Note: * If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string. * All the lines in the pattern have same length i.e equal to the number of char...
["def pattern(n):\n output = []\n for i in range (1, n + 1):\n wing = ' ' * (n - i) + ''.join(str(d % 10) for d in range(1, i))\n output.append(wing + str(i % 10) + wing[::-1])\n return '\\n'.join(output)", "def pattern(n):\n result = []\n for i in range(1, n+1):\n string = \"\"\n ...
{"fn_name": "pattern", "inputs": [[7], [1], [4], [0], [-25]], "outputs": [[" 1 \n 121 \n 12321 \n 1234321 \n 123454321 \n 12345654321 \n1234567654321"], ["1"], [" 1 \n 121 \n 12321 \n1234321"], [""], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,682
def pattern(n):
d4bde7d048eaf648e9f8ed30c1fb63d9
UNKNOWN
Create a function ```python has_two_cube_sums(n) ``` which checks if a given number `n` can be written as the sum of two cubes in two different ways: `n = a³+b³ = c³+d³`. All the numbers `a`, `b`, `c` and `d` should be different and greater than `0`. E.g. 1729 = 9³+10³ = 1³+12³. ```python has_two_cube_sums(1729); /...
["def has_two_cube_sums(n):\n cubic_list = [i**3 for i in range(1, int((n)**(1./3.)) + 1)]\n return sum([(n != 2*c) and ((n-c) in cubic_list) for c in cubic_list]) > 3\n", "def has_two_cube_sums(n):\n x = 0\n for a in range(int(n**0.35)):\n for b in range(a,int(n**0.35)):\n if a**3+b**3 ==...
{"fn_name": "has_two_cube_sums", "inputs": [[1], [1729], [42], [4103], [4102], [4104], [4105], [4106], [0], [46163]], "outputs": [[false], [true], [false], [false], [false], [true], [false], [false], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,143
def has_two_cube_sums(n):
c23e6c024e03d1cf0cea45ffeda28055
UNKNOWN
In this Kata, you will be given an array of numbers in which two numbers occur once and the rest occur only twice. Your task will be to return the sum of the numbers that occur only once. For example, `repeats([4,5,7,5,4,8]) = 15` because only the numbers `7` and `8` occur once, and their sum is `15`. More examples ...
["def repeats(arr):\n return sum([x for x in arr if arr.count(x) == 1])", "from collections import Counter\n\ndef repeats(arr):\n return sum(k for k, v in Counter(arr).items() if v == 1)", "def repeats(arr):\n return sum(n for n in arr if arr.count(n) == 1)", "def repeats(arr):\n single = [] #create a list to...
{"fn_name": "repeats", "inputs": [[[4, 5, 7, 5, 4, 8]], [[9, 10, 19, 13, 19, 13]], [[16, 0, 11, 4, 8, 16, 0, 11]], [[5, 17, 18, 11, 13, 18, 11, 13]], [[5, 10, 19, 13, 10, 13]]], "outputs": [[15], [19], [12], [22], [24]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,127
def repeats(arr):
1d6aa0d602db1d93a6412f5e7c2c53b9
UNKNOWN
__Definition:__ According to Wikipedia, a [complete binary tree](https://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees) is a binary tree _"where every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible."_ The Wikipedia page referenced above also...
["def complete_binary_tree(a):\n def in_order(n=0):\n if n < len(a):\n yield from in_order(2 * n + 1)\n yield n\n yield from in_order(2 * n + 2)\n\n result = [None] * len(a)\n for i, x in zip(in_order(), a):\n result[i] = x\n return result", "def mid(n):\n x...
{"fn_name": "complete_binary_tree", "inputs": [[[1]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]], "outputs": [[[1]], [[4, 2, 6, 1, 3, 5]], [[7, 4, 9, 2, 6, 8, 10, 1, 3, 5]]]}
INTRODUCTORY
PYTHON3
CODEWARS
8,327
def complete_binary_tree(a):
f51daa7168f7559544502c0f8ad3b3fa
UNKNOWN
## Introduction Each chemical element in its neutral state has a specific number of electrons associated with it. This is represented by the **atomic number** which is noted by an integer number next to or above each element of the periodic table (as highlighted in the image above). As we move from left to right, st...
["ELEMENTS = ['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', ...
{"fn_name": "get_electron_configuration", "inputs": [["H"], ["Cr"], ["C"], ["Br"], ["V"]], "outputs": [["H -> 1s1"], ["Cr -> 1s2 2s2 2p6 3s2 3p6 3d5 4s1"], ["C -> 1s2 2s2 2p2"], ["Br -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p5"], ["V -> 1s2 2s2 2p6 3s2 3p6 3d3 4s2"]]}
INTRODUCTORY
PYTHON3
CODEWARS
29,542
ELEMENTS = ['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', '...
88c29e38c482689e52aa938cfe200718
UNKNOWN
John has some amount of money of which he wants to deposit a part `f0` to the bank at the beginning of year `1`. He wants to withdraw each year for his living an amount `c0`. Here is his banker plan: - deposit `f0` at beginning of year 1 - his bank account has an interest rate of `p` percent per year, constant over t...
["def fortune(f, p, c, n, i):\n for _ in range(n-1):\n f = int(f * (100 + p) / 100 - c)\n c = int(c * (100 + i) / 100)\n if f < 0:\n return False\n return True", "def fortune(money, interest, withdraw, years, inflation):\n interest = 1 + (interest / 100)\n inflation = 1 + (in...
{"fn_name": "fortune", "inputs": [[100000, 1, 2000, 15, 1], [100000, 1, 9185, 12, 1], [100000000, 1, 100000, 50, 1], [100000000, 1.5, 10000000, 50, 1], [100000000, 5, 1000000, 50, 1], [9999, 61.8161, 10000.0, 3, 0], [9998.5, 61.8155, 10000.0, 3, 0], [10000.0, 0, 10000.0, 2, 0], [999.5, 61.87, 1000.0, 3, 0]], "outputs":...
INTRODUCTORY
PYTHON3
CODEWARS
2,226
def fortune(f0, p, c0, n, i):
e1d84af03ed54c82c834b52abeb3ef23
UNKNOWN
**This Kata is intended as a small challenge for my students** All Star Code Challenge #29 Your friend Nhoj has dislexia, but can easily read messages if the words are written backwards. Create a function called `reverseSentence()/reverse_sentence()` that accepts a string argument. The function returns a string of ...
["def reverse_sentence(sentence):\n return ' '.join(w[::-1] for w in sentence.split())", "def reverse_sentence(sentence):\n return \" \".join(word[::-1] for word in sentence.split())", "def reverse_sentence(sentence):\n return ' '.join(reversed(sentence[::-1].split(' ')))\n", "def reverse_sentence(sentence):\n ...
{"fn_name": "reverse_sentence", "inputs": [["Hello !Nhoj Want to have lunch?"], ["1 2 3 4 5"], ["CodeWars"], ["CodeWars rules!"], [""]], "outputs": [["olleH johN! tnaW ot evah ?hcnul"], ["1 2 3 4 5"], ["sraWedoC"], ["sraWedoC !selur"], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
948
def reverse_sentence(sentence):
2d7d01de7762cff5416360df4f18fee2
UNKNOWN
# Task Round the given number `n` to the nearest multiple of `m`. If `n` is exactly in the middle of 2 multiples of m, return `n` instead. # Example For `n = 20, m = 3`, the output should be `21`. For `n = 19, m = 3`, the output should be `18`. For `n = 50, m = 100`, the output should be `50`. # Input/Output...
["def rounding(n, m):\n return n if n % m == m / 2 else m * round(n / m)", "def rounding(n,m):\n down, up = (n//m)*m, (n//m)*m+m\n if up-n < n-down : return up\n elif up-n == n-down : return n\n return down", "def rounding(n, m):\n return n if (n / m) % 1 == 0.5 else round(n / m) * m", "def rounding(n...
{"fn_name": "rounding", "inputs": [[20, 3], [19, 3], [1, 10], [50, 100], [123, 456]], "outputs": [[21], [18], [0], [50], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,302
def rounding(n, m):
77c0264e4c487088c3af2ecff69eb5ce
UNKNOWN
For an integer ```k``` rearrange all the elements of the given array in such way, that: all elements that are less than ```k``` are placed before elements that are not less than ```k```; all elements that are less than ```k``` remain in the same order with respect to each other; all elements that are not less than ```...
["def split_by_value(k, elements):\n return sorted(elements, key=lambda x: x >= k)", "def split_by_value(k, elements):\n return [x for x in elements if x < k] + [x for x in elements if x >= k]", "def split_by_value(k, elements):\n res = [[], []]\n for x in elements:\n res[k<=x].append(x)\n return ...
{"fn_name": "split_by_value", "inputs": [[5, [1, 3, 5, 7, 6, 4, 2]], [0, [5, 2, 7, 3, 2]], [6, [6, 4, 10, 10, 6]], [1, [3, 2, 8, 3, 2, 1]], [10, [9, 2, 4, 3, 4]]], "outputs": [[[1, 3, 4, 2, 5, 7, 6]], [[5, 2, 7, 3, 2]], [[4, 6, 10, 10, 6]], [[3, 2, 8, 3, 2, 1]], [[9, 2, 4, 3, 4]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,189
def split_by_value(k, elements):
03b92381ac9a8c186aad8378a749c911
UNKNOWN
*Inspired by the [Fold an Array](https://www.codewars.com/kata/fold-an-array) kata. This one is sort of similar but a little different.* --- ## Task You will receive an array as parameter that contains 1 or more integers and a number `n`. Here is a little visualization of the process: * Step 1: Split the array in t...
["def split_and_add(numbers, n):\n for _ in range(n):\n middle = len(numbers) // 2\n left = numbers[:middle]\n right = numbers[middle:]\n numbers = [a + b for a, b in zip((len(right) - len(left)) * [0] + left, right)]\n if len(numbers) == 1:\n return numbers\n return ...
{"fn_name": "split_and_add", "inputs": [[[1, 2, 3, 4, 5], 2], [[1, 2, 3, 4, 5], 3], [[15], 3], [[1, 2, 3, 4], 1], [[1, 2, 3, 4, 5, 6], 20], [[32, 45, 43, 23, 54, 23, 54, 34], 2], [[32, 45, 43, 23, 54, 23, 54, 34], 0], [[3, 234, 25, 345, 45, 34, 234, 235, 345], 3], [[3, 234, 25, 345, 45, 34, 234, 235, 345, 34, 534, 45, ...
INTRODUCTORY
PYTHON3
CODEWARS
2,426
def split_and_add(numbers, n):