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
25cdc3b6f481ef52a6ab1ff2532692c6
UNKNOWN
You have to create a function named reverseIt. Write your function so that in the case a string or a number is passed in as the data , you will return the data in reverse order. If the data is any other type, return it as it is. Examples of inputs and subsequent outputs: ``` "Hello" -> "olleH" "314159" -> "951413" ...
["def reverse_it(data):\n if type(data) in [int, str, float]:\n return type(data)(str(data)[::-1])\n return data", "def reverse_it(data):\n t = type(data)\n return t(''.join(reversed(str(data)))) if t in [str, int, float] else data", "def reverse_it(data):\n return data if any(t is type(data) for ...
{"fn_name": "reverse_it", "inputs": [["Hello"], [314159], ["314159"], [[]], [{}], [true], [[1, 2, 3]]], "outputs": [["olleH"], [951413], ["951413"], [[]], [{}], [true], [[1, 2, 3]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,685
def reverse_it(data):
6ae153e087deb48843f00becd9da8f68
UNKNOWN
Every positive integer number, that is not prime, may be decomposed in prime factors. For example the prime factors of 20, are: ``` 2, 2, and 5, because: 20 = 2 . 2 . 5 ``` The first prime factor (the smallest one) of ```20``` is ```2``` and the last one (the largest one) is ```5```. The sum of the first and the last ...
["def sflpf_data(val, nMax):\n r=[]\n for i in range(2,nMax):\n fac=primef(i)\n if len(fac)>1 and fac[0]+fac.pop()==val: r.append(i) \n return r\n \ndef primef(n):\n i= 2; f= []\n while i*i<=n:\n if n%i: i+=1\n else: n//=i; f.append(i)\n if n>1: f.append(n)\n return f",...
{"fn_name": "sflpf_data", "inputs": [[10, 100], [10, 200], [15, 150], [501, 1000], [501, 5000]], "outputs": [[[21, 25, 63]], [[21, 25, 63, 105, 125, 147, 189]], [[26, 52, 78, 104, 130]], [[998]], [[998, 1996, 2994, 3992, 4990]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,142
def sflpf_data(val, nMax):
ac891b0231bf6a0a03e80d3754ee7c88
UNKNOWN
Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468. Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, 66420. We shall call a positive integer that is neither increasing nor decreasi...
["from operator import lt, gt\n\nmemo = {}\nis_bouncy = lambda s: memo[s] if s in memo else memo.setdefault(s, any(map(lt, s[:-1], s[1:])) and any(map(gt, s[:-1], s[1:])))\n\ndef bouncy_ratio(percent):\n if not 0 < percent < 1: raise Exception(\"Wrong percentage: {}\".format(percent))\n x, y = 100, 0\n while y...
{"fn_name": "bouncy_ratio", "inputs": [[0.1], [0.15], [0.5], [0.75], [0.9]], "outputs": [[132], [160], [538], [3088], [21780]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,006
def bouncy_ratio(percent):
a3d183134372db10a37115b1bab92cb7
UNKNOWN
Gematria is an Assyro-Babylonian-Greek system of code and numerology later adopted into Jewish culture. The system assigns numerical value to a word or a phrase in the belief that words or phrases with identical numerical values bear some relation to each other or bear some relation to the number itself. While more com...
["\n\nTOME = {'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 'f':6, 'g':7, 'h':8, 'i':9, 'k':10, 'l':20, 'm':30, 'n':40, 'o':50, 'p':60, 'q':70, 'r':80, 's':90, 't':100, 'u':200, 'x':300, 'y':400, 'z':500, 'j':600, 'v':700, 'w':900}\n\ndef gematria(s): return sum(TOME.get(c,0) for c in s.lower())", "def gematria(string):\n d = ...
{"fn_name": "gematria", "inputs": [["love"], ["jaels"], ["JAELS"], ["Devil"], ["Coding is fun"]], "outputs": [[775], [716], [716], [738], [458]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,248
def gematria(string):
95cd4d8cd2202f779e3e1e43412aba28
UNKNOWN
Ever the learned traveller, Alan Partridge has pretty strong views on London: ``` "Go to London. I guarantee you'll either be mugged or not appreciated. Catch the train to London, stopping at Rejection, Disappointment, Backstabbing Central and Shattered Dreams Parkway." ``` Your job is to check that the provided list ...
["def alan(arr):\n s = {'Rejection', 'Disappointment', 'Backstabbing Central', 'Shattered Dreams Parkway'}\n return \"Smell my cheese you mother!\" if s.issubset(arr) else \"No, seriously, run. You will miss it.\"", "def alan(arr):\n a = ['Rejection', 'Disappointment', 'Backstabbing Central', 'Shattered Dreams...
{"fn_name": "alan", "inputs": [[["Norwich", "Rejection", "Disappointment", "Backstabbing Central", "Shattered Dreams Parkway", "London"]], [["London", "Norwich"]], [["Norwich", "Tooting", "Bank", "Rejection", "Disappointment", "Backstabbing Central", "Exeter", "Shattered Dreams Parkway", "Belgium", "London"]], [["Londo...
INTRODUCTORY
PYTHON3
CODEWARS
3,072
def alan(arr):
5c66c0c2bba166a8cce8acd5a2b3d68c
UNKNOWN
Imagine a funnel filled with letters. The bottom letter drops out of the funnel and onto a conveyor belt: ``` \b,c/ --> \b,c/ \a/ --> \ / a ------- ------- ``` If there are two letters above a gap, the smaller letter falls into the gap. ``` \b,c/ --> \ c/ \ / --> \b/ ...
["def funnel_out(funnel):\n r=\"\"\n h=len(funnel)\n while funnel[h-1][0]!=\"~\":\n r+=funnel[h-1][0]\n funnel[h-1][0]=\"~\"\n i=h-1\n j=0\n while i>0:\n if funnel[i-1][j] < funnel[i-1][j+1]:\n funnel[i][j]=funnel[i-1][j]\n funnel[i-1][j]=\"~\"\n else:\n...
{"fn_name": "funnel_out", "inputs": [[[["q"]]], [[["b", "c"], ["a"]]], [[["d", "a", "c"], ["b", "e"], ["f"]]], [[["a", "e", "c", "f"], ["d", "i", "h"], ["j", "g"], ["b"]]]], "outputs": [["q"], ["abc"], ["fbadec"], ["bghcfiejda"]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,224
def funnel_out(funnel):
b4c0fa37adcea880b5ea765b3a4d3215
UNKNOWN
Every now and then people in the office moves teams or departments. Depending what people are doing with their time they can become more or less boring. Time to assess the current team. ```if-not:java You will be provided with an object(staff) containing the staff names as keys, and the department they work in as valu...
["def boredom(staff):\n lookup = {\n \"accounts\": 1,\n \"finance\": 2,\n \"canteen\": 10,\n \"regulation\": 3, \n \"trading\": 6,\n \"change\": 6,\n \"IS\": 8,\n \"retail\": 5,\n \"cleaning\": 4,\n \"pissing about\": 25\n }\n n = sum(lookup...
{"fn_name": "boredom", "inputs": [[{"tim": "change", "jim": "accounts", "randy": "canteen", "sandy": "change", "andy": "change", "katie": "IS", "laura": "change", "saajid": "IS", "alex": "trading", "john": "accounts", "mr": "finance"}], [{"tim": "IS", "jim": "finance", "randy": "pissing about", "sandy": "cleaning", "an...
INTRODUCTORY
PYTHON3
CODEWARS
3,890
def boredom(staff):
7640383f86c0e54bba6be52c08fa0e9b
UNKNOWN
Bob has a server farm crunching numbers. He has `nodes` servers in his farm. His company has a lot of work to do. The work comes as a number `workload` which indicates how many jobs there are. Bob wants his servers to get an equal number of jobs each. If that is impossible, he wants the first servers to receive more ...
["def distribute(nodes, workload):\n w = list(range(workload))[::-1]\n return [[w.pop() for _ in range(workload // nodes + (workload % nodes > n))] for n in range(nodes)]", "def distribute(n, w):\n g, (d,r) = iter(range(w)), divmod(w,n)\n return [ [next(g) for _ in range(d+(i<r))] for i in range(n)]", "def ...
{"fn_name": "distribute", "inputs": [[2, 4], [3, 3], [3, 9], [2, 5], [4, 10], [4, 5], [1, 1], [2, 1], [5, 4], [5, 1]], "outputs": [[[[0, 1], [2, 3]]], [[[0], [1], [2]]], [[[0, 1, 2], [3, 4, 5], [6, 7, 8]]], [[[0, 1, 2], [3, 4]]], [[[0, 1, 2], [3, 4, 5], [6, 7], [8, 9]]], [[[0, 1], [2], [3], [4]]], [[[0]]], [[[0], []]],...
INTRODUCTORY
PYTHON3
CODEWARS
2,650
def distribute(nodes, workload):
cc5bd316aa7894c44c9c6c305c8c03ef
UNKNOWN
Yup!! The problem name reflects your task; just add a set of numbers. But you may feel yourselves condescended, to write a C/C++ program just to add a set of numbers. Such a problem will simply question your erudition. So, lets add some flavor of ingenuity to it. Addition operation requires cost now, and the cost is th...
["from heapq import *\n\ndef add_all(lst):\n\n heapify(lst)\n total = 0\n while len(lst) > 1:\n s = heappop(lst) + heappop(lst)\n total += s\n heappush(lst, s)\n\n return total", "import heapq\n\ndef add_all(xs): \n heapq.heapify(xs)\n cost = 0\n while len(xs) > 1:\n c =...
{"fn_name": "add_all", "inputs": [[[1, 2, 3]], [[1, 2, 3, 4]], [[1, 2, 3, 4, 5]]], "outputs": [[9], [19], [33]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,723
def add_all(lst):
67cdd4aa5cc6d7d18b44ced9e8e9fa04
UNKNOWN
Find the difference between two collections. The difference means that either the character is present in one collection or it is present in other, but not in both. Return a sorted set with difference. The collections can contain any character and can contain duplicates. For instance: A = [a,a,t,e,f,i,j] B = [t,g,g...
["def diff(a, b):\n return sorted(set(a) ^ set(b))", "def diff(a, b):\n return sorted(set(a).symmetric_difference(b))", "# return a sorted set with the difference\ndef diff(a, b):\n a = set(a)\n b = set(b)\n c = a.symmetric_difference(b)\n return sorted(list(c))", "# return a sorted set with the difference\nd...
{"fn_name": "diff", "inputs": [[["a", "b"], ["a", "b"]], [[], []]], "outputs": [[[]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,622
def diff(a, b):
e37a326e7d829a9541e4c1ac86680545
UNKNOWN
We have an integer array with unique elements and we want to do the permutations that have an element fixed, in other words, these permutations should have a certain element at the same position than the original. These permutations will be called: **permutations with one fixed point**. Let's see an example with an a...
["def fixed_points_perms(n, k):\n if k > n:\n return 0\n if k == n:\n return 1\n if k == 0:\n subf = lambda n: 1 if n == 0 else n * subf(n - 1) + (-1)**n\n return subf(n)\n return fixed_points_perms(n-1, k-1) * n // k\n", "from functools import lru_cache\nfrom math import factori...
{"fn_name": "fixed_points_perms", "inputs": [[4, 1], [4, 2], [4, 3], [10, 3], [10, 4], [20, 2], [4, 0], [4, 4], [4, 5]], "outputs": [[8], [6], [0], [222480], [55650], [447507315596451070], [9], [1], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,226
def fixed_points_perms(n,k):
fcbdb055ae56452fe1983a55935f9ae5
UNKNOWN
In this Kata, you will be given an array of unique elements, and your task is to rerrange the values so that the first max value is followed by the first minimum, followed by second max value then second min value, etc. For example: The first max is `15` and the first min is `7`. The second max is `12` and the second...
["def solve(arr):\n arr = sorted(arr, reverse=True)\n res = []\n while len(arr):\n res.append(arr.pop(0))\n if len(arr):\n res.append(arr.pop())\n return res", "def solve(arr):\n lmax, lmin = iter(sorted(arr)) , iter(sorted(arr)[::-1])\n return [next(lmax) if i%2==1 else next(...
{"fn_name": "solve", "inputs": [[[15, 11, 10, 7, 12]], [[91, 75, 86, 14, 82]], [[84, 79, 76, 61, 78]], [[52, 77, 72, 44, 74, 76, 40]], [[1, 6, 9, 4, 3, 7, 8, 2]], [[78, 79, 52, 87, 16, 74, 31, 63, 80]]], "outputs": [[[15, 7, 12, 10, 11]], [[91, 14, 86, 75, 82]], [[84, 61, 79, 76, 78]], [[77, 40, 76, 44, 74, 52, 72]], [...
INTRODUCTORY
PYTHON3
CODEWARS
3,384
def solve(arr):
e4d41d03619a5cfdf3857953c8361aa3
UNKNOWN
Write a function that takes a string which has integers inside it separated by spaces, and your task is to convert each integer in the string into an integer and return their sum. ### Example ```python summy("1 2 3") ==> 6 ``` Good luck!
["def summy(string_of_ints):\n return sum(map(int,string_of_ints.split()))", "def summy(s):\n return sum(map(int, s.split(' ')))", "def summy(string_of_ints): \n return sum([int(element) for element in string_of_ints.split(\" \")])", "def summy(s):\n return eval(s.replace(' ', '+'))", "import re\n\ndef s...
{"fn_name": "summy", "inputs": [["1 2 3"], ["1 2 3 4"], ["1 2 3 4 5"], ["10 10"], ["0 0"]], "outputs": [[6], [10], [15], [20], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
732
def summy(s):
72ac1f63beae7c7f8c53a9c139fc54ee
UNKNOWN
You are a biologist working on the amino acid composition of proteins. Every protein consists of a long chain of 20 different amino acids with different properties. Currently, you are collecting data on the percentage, various amino acids make up a protein you are working on. As manually counting the occurences of am...
["def aa_percentage(seq, residues=[\"A\", \"I\", \"L\", \"M\", \"F\", \"W\", \"Y\", \"V\"]):\n return round(sum(seq.count(r) for r in residues)/len(seq)*100)", "def aa_percentage(seq, acid='AILMFWYV'):\n return round(sum(x in acid for x in seq) * 100 / len(seq) )", "def aa_percentage(protein, residue=\"AILMFWYV\"):...
{"fn_name": "aa_percentage", "inputs": [["MSRSLLLRFLLFLLLLPPLP", ["M"]], ["MSRSLLLRFLLFLLLLPPLP", ["M", "L"]], ["MSRSLLLRFLLFLLLLPPLP", ["F", "S", "L"]], ["MSRSLLLRFLLFLLLLPPLP"], ["RLMADDFFGQTLMAAAAAAQERRR", ["A"]], ["RLMADDFFGQTLMAAAAAAQERRR", ["A", "R", "D"]], ["RLMADDFFGQTLMAAAAAAQERRR"], ["PLPPLPLLEELELRPFFMAAGGTP...
INTRODUCTORY
PYTHON3
CODEWARS
1,596
def aa_percentage(seq, residues=["A", "I", "L", "M", "F", "W", "Y", "V"]):
f769f2779273e542569246c33a3c94f1
UNKNOWN
Assume we take a number `x` and perform any one of the following operations: ```Pearl a) Divide x by 3 (if it is divisible by 3), or b) Multiply x by 2 ``` After each operation, we write down the result. If we start with `9`, we can get a sequence such as: ``` [9,3,6,12,4,8] -- 9/3=3 -> 3*2=6 -> 6*2=12 -> 12/3=4 -> 4*2...
["def solve(a):\n for i in a:\n li = [i]\n while 1:\n if li[-1] % 3 == 0 and li[-1] // 3 in a : li.append(li[-1] // 3)\n elif li[-1] * 2 in a : li.append(li[-1] * 2)\n else : break\n if len(li) == len(a) : return li", "def solve(arr): \n ar, v = arr[:], lamb...
{"fn_name": "solve", "inputs": [[[1, 3]], [[4, 2]], [[12, 3, 9, 4, 6, 8]], [[4, 8, 6, 3, 12, 9]], [[558, 744, 1488, 279, 2232, 1116]], [[9, 1, 3]], [[3000, 9000]], [[4, 1, 2]], [[10, 5]]], "outputs": [[[3, 1]], [[2, 4]], [[9, 3, 6, 12, 4, 8]], [[9, 3, 6, 12, 4, 8]], [[279, 558, 1116, 2232, 744, 1488]], [[9, 3, 1]], [[9...
INTRODUCTORY
PYTHON3
CODEWARS
3,236
def solve(arr):
a6b45667cbb2b0de908075c534985f01
UNKNOWN
# Grains Write a program that calculates the number of grains of wheat on a chessboard given that the number on each square is double the previous one. There are 64 squares on a chessboard. #Example: square(1) = 1 square(2) = 2 square(3) = 4 square(4) = 8 etc... Write a program that shows how many grains were on ea...
["def square(number):\n return 2**(number-1)", "def square(n):\n return 1<<n-1", "square=lambda n: 2**(n-1)", "def square(number):\n return 1 << (number-1)", "square=lambda n:1<<n-1", "def square(number = 1):\n return 2 ** (number - 1)", "square=lambda a:1<<(a-1)", "def square(number):\n grains = 1\n...
{"fn_name": "square", "inputs": [[1], [3], [4], [16], [32]], "outputs": [[1], [4], [8], [32768], [2147483648]]}
INTRODUCTORY
PYTHON3
CODEWARS
687
def square(number):
074ca9736635dcba9dc1a4a612e8c4d7
UNKNOWN
I have started studying electronics recently, and I came up with a circuit made up of 2 LEDs and 3 buttons. Here 's how it works: 2 buttons (`red` and `blue`) are connected to the LEDs (`red` and `blue` respectively). Buttons pressing pattern will be remembered and represented through the LEDs when the third button is...
["def button_sequences(seqR, seqB):\n pattern, state = '', ''\n toBool = lambda seq : [i == '1' for i in seq]\n for red, blue in zip(toBool(seqR), toBool(seqB)):\n if red and state == 'R' or blue and state == 'B':\n continue\n state = 'R' if red else 'B' if blue else ''\n patter...
{"fn_name": "button_sequences", "inputs": [["10011010", "10110111"], ["01001000", "01011100"], ["00010100", "01011100"], ["10101010", "01010101"], ["11011011", "11111011"]], "outputs": [["RBRB"], ["RB"], ["BRB"], ["RBRBRBRB"], ["RBR"]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,075
def button_sequences(seqR, seqB):
7feccfdc44909d3dcb2fe7656ad2e405
UNKNOWN
# Task Write a function that accepts `msg` string and returns local tops of string from the highest to the lowest. The string's tops are from displaying the string in the below way: ``` 7891012 TUWvXY 6 3 ABCDE S ...
["def tops(msg):\n n = len(msg)\n res,i,j,k = \"\",2,2,7\n while i < n:\n res = msg[i:i+j] + res\n i,j,k=i+k,j+1,k+4\n return res", "def transform(i): return (3*i-4+2*(i-1)*(i-2), i)\n\ndef tops(msg):\n iMax = int((3+(9+8*len(msg))**.5) / 4)\n return ''.join( msg[i:i+c] for i,c in map(tr...
{"fn_name": "tops", "inputs": [[""], ["abcde"], ["123456789abcdefghijklmnopqrstuwyxvzABCDEFGHIJKLMNOPQRSTU"], ["123456789abcdefghijklmnopqrstuwyxvzABCDEFGHIJKLMNOPQRSTUWvXYZ123456789012345678910123"]], "outputs": [[""], ["cd"], ["TUABCDElmnoabc34"], ["7891012TUWvXYABCDElmnoabc34"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,952
def tops(msg):
a8109158429ee4941fa3d35703bfeae6
UNKNOWN
Complete the function that takes 3 numbers `x, y and k` (where `x ≤ y`), and returns the number of integers within the range `[x..y]` (both ends included) that are divisible by `k`. More scientifically: `{ i : x ≤ i ≤ y, i mod k = 0 }` ## Example Given ```x = 6, y = 11, k = 2``` the function should return `3`, bec...
["def divisible_count(x,y,k):\n return y//k - (x-1)//k", "def divisible_count(x,y,k):\n upper = y//k\n lower = (x-1)//k\n return upper - lower", "divisible_count=lambda x,y,k:y//k-~-x//k", "def divisible_count(x,y,k):\n ans = 0\n \n while True:\n if x % k == 0:\n break\n el...
{"fn_name": "divisible_count", "inputs": [[6, 11, 2], [11, 345, 17], [0, 1, 7], [20, 20, 2], [20, 20, 8], [19, 20, 2], [0, 10, 1], [11, 14, 2], [101, 9999999999999999999999999999999999999999999, 11], [1005, 9999999999999999999999999999999999999999999, 109]], "outputs": [[3], [20], [1], [1], [0], [1], [11], [2], [909090...
INTRODUCTORY
PYTHON3
CODEWARS
1,180
def divisible_count(x,y,k):
0a2dafe663099e7252b72671be169ce8
UNKNOWN
## Task Given `n` representing the number of floors build a beautiful multi-million dollar mansions like the ones in the example below: ``` /\ / \ / \ /______\ number of floors 3 | | | | |______| /\ / \ /____\ | | 2 floors |____| /\ /__\ 1 floor...
["def my_crib(n):\n roof = \"\\n\".join(\"%s/%s\\\\%s\"%(\" \"*(n-i),\" \"*i*2,\" \"*(n-i)) for i in range(n))\n ceiling = \"\\n/%s\\\\\\n\"%(\"_\"*(n*2))\n walls = (\"|%s|\\n\"%(\" \"*(n*2)))*(n-1)\n floor = \"|%s|\"%(\"_\"*(n*2))\n \n return roof + ceiling + walls + floor", "def my_crib(n):\n roo...
{"fn_name": "my_crib", "inputs": [[1], [2], [3]], "outputs": [[" /\\ \n/__\\\n|__|"], [" /\\ \n / \\ \n/____\\\n| |\n|____|"], [" /\\ \n / \\ \n / \\ \n/______\\\n| |\n| |\n|______|"]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,266
def my_crib(n):
160f19565165a9b17f8cb778b1c980d2
UNKNOWN
Write a program that will take a string of digits and give you all the possible consecutive slices of length `n` in that string. Raise an error if `n` is larger than the length of the string. ## Examples For example, the string `"01234"` has the following 2-digit slices: ``` [0, 1], [1, 2], [2, 3], [3, 4] ``` The...
["def series_slices(digits, n):\n if n > len(digits):\n raise ValueError\n else:\n return [[int(digit) for digit in digits[i:i+n]] for i in range(0, len(digits)-n+1)]", "def series_slices(s, n):\n if n > len(s):\n raise\n \n arr = [int(d) for d in s]\n return [ arr[i:i+n] for i in...
{"fn_name": "series_slices", "inputs": [["01234", 1], ["01234", 2], ["01234", 3], ["01234", 4], ["01234", 5]], "outputs": [[[[0], [1], [2], [3], [4]]], [[[0, 1], [1, 2], [2, 3], [3, 4]]], [[[0, 1, 2], [1, 2, 3], [2, 3, 4]]], [[[0, 1, 2, 3], [1, 2, 3, 4]]], [[[0, 1, 2, 3, 4]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,030
def series_slices(digits, n):
be09f78268625ed065e1112b40a29d6d
UNKNOWN
Your job is to change the given string `s` using a non-negative integer `n`. Each bit in `n` will specify whether or not to swap the case for each alphabetic character in `s`: if the bit is `1`, swap the case; if its `0`, leave it as is. When you finished with the last bit of `n`, start again with the first bit. You ...
["from itertools import cycle\n\ndef swap(s,n):\n b = cycle(bin(n)[2:])\n return \"\".join(c.swapcase() if c.isalpha() and next(b) == '1' else c for c in s)", "from itertools import cycle\n\ndef swap(s,n):\n doSwap = cycle(map(int,f\"{n:b}\"))\n return ''.join(c.swapcase() if c.isalpha() and next(doSwap) el...
{"fn_name": "swap", "inputs": [["Hello world!", 11], ["the quick broWn fox leapt over the fence", 9], ["eVerybody likes ice cReam", 85], ["gOOd MOrniNg", 7864], ["how are you today?", 12345], ["the lord of the rings", 0], ["", 11345]], "outputs": [["heLLO wORLd!"], ["The QUicK BrowN foX LeaPT ovER thE FenCE"], ["EVErYb...
INTRODUCTORY
PYTHON3
CODEWARS
2,137
def swap(s,n):
bd0440abbd56e46feb94d4df46f491ca
UNKNOWN
Consider X as the aleatory variable that count the number of letters in a word. Write a function that, give in input an array of words (strings), calculate the variance of X. Max decimal of the variance : 4. Some wiki: Variance , Aleatory variable Example: Consider "Hello" and "World": X is { 5 } with P(X = 5...
["variance=lambda w:round(__import__('statistics').pvariance(map(len,w)),4)", "from statistics import pvariance\n\ndef variance(words):\n return round(pvariance(map(len, words)), 4)", "from statistics import pvariance as var\n\nvariance = lambda words: round(var(len(word) for word in words), 4)", "def variance(words...
{"fn_name": "variance", "inputs": [[["Hello", "world"]], [["Hi", "world"]], [["Variance", "is", "not", "a", "good", "stimator"]]], "outputs": [[0], [2.25], [7.5556]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,356
def variance(words):
129cec24f5b0727d455e0f4cd67e5619
UNKNOWN
Happy traveller [Part 1] There is a play grid NxN; Always square! 0 1 2 3 0 [o, o, o, X] 1 [o, o, o, o] 2 [o, o, o, o] 3 [o, o, o, o] You start from a random point. I mean, you are given the coordinates of your start position in format (row, col). And your TASK is to define the number of unique paths to re...
["from math import factorial as f\ncount_paths=lambda n,c:f(c[0]+abs(n-c[1]-1))//(f(abs(n-c[1]-1))*f(c[0])) if n!=1 else 0", "from math import factorial\ndef count_paths(N, coords):\n if N==1:\n return 0\n x=coords[0]\n y=N-1-coords[1]\n return factorial(x+y)//(factorial(x)*factorial(y))", "count_pat...
{"fn_name": "count_paths", "inputs": [[1, [0, 0]], [2, [1, 0]], [2, [1, 1]], [3, [1, 0]], [5, [4, 0]], [6, [5, 0]], [7, [6, 0]]], "outputs": [[0], [2], [1], [3], [70], [252], [924]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,192
def count_paths(N, coords):
123ee0b4384dacc07043eb73c81a9162
UNKNOWN
You are given a certain integer, ```n, n > 0```. You have to search the partition or partitions, of n, with maximum product value. Let'see the case for ```n = 8```. ``` Partition Product [8] 8 [7, 1] 7 [6, 2] 12 [6, 1, 1] ...
["def find_part_max_prod(n):\n if n == 1: return [[1], 1]\n q, r = divmod(n, 3)\n if r == 0: return [[3]*q, 3**q]\n if r == 1: return [[4] + [3]*(q - 1), [3]*(q - 1) + [2, 2], 3**(q - 1) * 2**2]\n return [[3]*q + [2], 3**q * 2]", "from collections import defaultdict\nfrom functools import reduce\n\ndef find_part_m...
{"fn_name": "find_part_max_prod", "inputs": [[8], [10]], "outputs": [[[[3, 3, 2], 18]], [[[4, 3, 3], [3, 3, 2, 2], 36]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,718
def find_part_max_prod(n):
285de65b240c2c0d14d255d9e5a81c8d
UNKNOWN
# Exclusive "or" (xor) Logical Operator ## Overview In some scripting languages like PHP, there exists a logical operator (e.g. ```&&```, ```||```, ```and```, ```or```, etc.) called the "Exclusive Or" (hence the name of this Kata). The exclusive or evaluates two booleans. It then returns true if **exactly one of th...
["def xor(a,b):\n return a != b", "def xor(a,b):\n return a ^ b", "from operator import xor", "def xor(a,b):\n return a is not b", "def xor(a,b):\n print(a,b)\n if a == True and b == True: \n return False\n elif a == True or b == True:\n return True\n return False", "xor = int.__xo...
{"fn_name": "xor", "inputs": [[false, false], [true, false], [false, true], [true, true]], "outputs": [[false], [true], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
13,094
def xor(a,b):
9c9e23ac86972708fccf3adb617faf81
UNKNOWN
## Problem There are `n` apples that need to be divided into four piles. We need two mysterious number `x` and `y`. Let The number of first pile equals to `x+y`, the number of second pile equals to `x-y`, the number of third pile equals to `x*y`, the number of fourth pile equals to `x/y`. We need to calculate how many...
["def four_piles(n,y):\n x,r=divmod(n*y,(y+1)**2)\n return [] if r or x==y else [x+y,x-y,x*y,x//y]\n", "def four_piles(n,y): \n x = y * n / (y**2 + 2*y + 1)\n return [x + y, x - y, x * y, x / y] if int(x) == x and x - y > 0 else []", "def four_piles(n,y):\n x = y*n / (1+2*y+y**2)\n ans = [x+y, x...
{"fn_name": "four_piles", "inputs": [[48, 3], [100, 4], [25, 4], [24, 4]], "outputs": [[[12, 6, 27, 3]], [[20, 12, 64, 4]], [[]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,791
def four_piles(n,y):
00fb9a58da589a7845045bc0ab41a89d
UNKNOWN
You will be given a string (x) featuring a cat 'C' and a mouse 'm'. The rest of the string will be made up of '.'. You need to find out if the cat can catch the mouse from it's current position. The cat can jump over three characters. So: C.....m returns 'Escaped!' <-- more than three characters between C...m retu...
["def cat_mouse(x):\n return 'Escaped!' if x.count('.') > 3 else 'Caught!'", "def cat_mouse(x):\n esc = [\"C......m\",\"C......m\",\"C.......m\",\"m.....C\",\"C........m\",\"m.........C\",\"C.........m\",\"m....C\",\"m..........C\",\"m.......C\",\"m.......C\",\"m.........C\",\"C.....m\",\"C....m\",\"C.........m\"...
{"fn_name": "cat_mouse", "inputs": [["C....m"], ["C..m"], ["C.....m"], ["C.m"], ["m...C"]], "outputs": [["Escaped!"], ["Caught!"], ["Escaped!"], ["Caught!"], ["Caught!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,087
def cat_mouse(x):
12b27770c55626239453e46b5e7e397a
UNKNOWN
You are given two positive integers `a` and `b` (`a < b <= 20000`). Complete the function which returns a list of all those numbers in the interval `[a, b)` whose digits are made up of prime numbers (`2, 3, 5, 7`) but which are not primes themselves. Be careful about your timing! Good luck :)
["from math import sqrt\ndef is_prime(n):\n if n < 2: return False\n for x in range(2, int(sqrt(n)) + 1):\n if n % x == 0: return False\n return True\n\ndef all_dig_prime(n):\n for d in str(n):\n if d not in \"2357\": return False\n return True\n\ndef not_primes(a, b):\n res = []\n fo...
{"fn_name": "not_primes", "inputs": [[2, 222], [2, 77], [2700, 3000], [500, 999], [999, 2500]], "outputs": [[[22, 25, 27, 32, 33, 35, 52, 55, 57, 72, 75, 77]], [[22, 25, 27, 32, 33, 35, 52, 55, 57, 72, 75]], [[2722, 2723, 2725, 2727, 2732, 2733, 2735, 2737, 2752, 2755, 2757, 2772, 2773, 2775]], [[522, 525, 527, 532, 53...
INTRODUCTORY
PYTHON3
CODEWARS
4,468
def not_primes(a, b):
c570f8718b3cdb8e5c726cbf491cd48a
UNKNOWN
Implement `String#whitespace?(str)` (Ruby), `String.prototype.whitespace(str)` (JavaScript), `String::whitespace(str)` (CoffeeScript), or `whitespace(str)` (Python), which should return `true/True` if given object consists exclusively of zero or more whitespace characters, `false/False` otherwise.
["def whitespace(string):\n return not string or string.isspace()", "def whitespace(string):\n return not string.lstrip()", "def whitespace(string):\n return string.strip() == \"\"", "def whitespace(string):\n return string.strip(\"\\n\\t\\r \") == \"\"", "whitespace = lambda x: not x.strip()", "from re imp...
{"fn_name": "whitespace", "inputs": [[""], [" "], ["\n\r\n\r"], ["a"], ["w\n"], ["\t"], [" a\n"], ["\t \n\r\n "], ["\n\r\n\r "], ["\n\r\n\r 3"]], "outputs": [[true], [true], [true], [false], [false], [true], [false], [true], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
720
def whitespace(string):
0932ce3ddd3a65992f208a787c0dabe5
UNKNOWN
While most devs know about [big/little-endianness](https://en.wikipedia.org/wiki/Endianness), only a selected few know the secret of real hard core coolness with mid-endians. Your task is to take a number and return it in its mid-endian format, putting the most significant couple of bytes in the middle and all the oth...
["import re\ndef mid_endian(n):\n h= hex(n)[2:].upper()\n r= re.findall('..','0'*(len(h)%2)+h)\n return \"\".join(r[1::2][::-1]+r[0::2])", "def mid_endian(n):\n bs = n.to_bytes((n.bit_length() + 7) // 8 or 1, byteorder='little')\n return (bs[len(bs)%2::2] + bs[::-2]).hex().upper()", "from collections imp...
{"fn_name": "mid_endian", "inputs": [[9999999], [0], [658188], [168496141], [43135012110]], "outputs": [["96987F"], ["00"], ["0B0A0C"], ["0D0B0A0C"], ["0D0B0A0C0E"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,367
def mid_endian(n):
3586f5134a40edf085fec1265586bae0
UNKNOWN
We define the sequence ```SF``` in the following way in terms of four previous sequences: ```S1```, ```S2```, ```S3``` and ```ST``` We are interested in collecting the terms of SF that are multiple of ten. The first term multiple of ten of this sequence is ```60``` Make the function ```find_mult10_SF()``` that yo...
["def find_mult10_SF(n):\n n = 4*n - 1\n \n return (6 ** n + 3 * 2 ** n) / 4\n", "def find_mult10_SF(n):\n # ST(n) = 6 ** n + 5 ** n - 2 ** n - 1\n # SF(n) = (6 ** n + 3 * (2 ** n)) / 4\n # SF is divisible by 10 if n = 3 mod 4\n #\n # => nth 10 multiple of 10 is ST(n * 4 - 1)\n k = n * 4 - 1\...
{"fn_name": "find_mult10_SF", "inputs": [[1], [2], [3]], "outputs": [[60], [70080], [90700800]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,521
def find_mult10_SF(n):
ac17d0190a3bb8d766b3607bbdc4f1da
UNKNOWN
We define the score of permutations of combinations, of an integer number (the function to obtain this value:```sc_perm_comb```) as the total sum of all the numbers obtained from the permutations of all the possible combinations of its digits. For example we have the number 348. ```python sc_perm_comb(348) = 3 + 4 + 8 ...
["from itertools import permutations\n\ndef sc_perm_comb(num):\n sNum = str(num)\n return sum({ int(''.join(p)) for d in range(1, len(sNum)+1) for p in permutations(sNum, d) })", "import itertools\n\n#With combinations, we allow leading zeros, e.g. '03' is allowed, because when we permute, '03' becomes '30' \nde...
{"fn_name": "sc_perm_comb", "inputs": [[348], [340], [333], [6], [0]], "outputs": [[3675], [1631], [369], [6], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,106
def sc_perm_comb(num):
4f3f716dc2e1015364f522b54e26b003
UNKNOWN
You're given a string of dominos. For each slot, there are 3 options: * "|" represents a standing domino * "/" represents a knocked over domino * " " represents a space where there is no domino For example: ```python "||| ||||//| |/" ``` What you must do is find the resulting string if the first domino is ...
["def domino_reaction(s):\n ds = \"\"\n for (i,d) in enumerate(s):\n if( d==\"|\" ): \n ds += \"/\"\n else:\n return ds+s[i:]\n return ds\n", "def domino_reaction(s):\n return s.replace(\"|\", \"/\", min(len(s.split(\" \")[0]), len(s.split(\"/\")[0])))", "def domino_react...
{"fn_name": "domino_reaction", "inputs": [["||| ||||//| |/"], ["|||||"], [" ///"], [""], [" "], [" |"], ["||||| |||"], ["|||||/|||"]], "outputs": [["/// ||||//| |/"], ["/////"], [" ///"], [""], [" "], [" |"], ["///// |||"], ["//////|||"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,225
def domino_reaction(s):
1ee3f98de0e1ce64d037f105740614d0
UNKNOWN
Make a function that returns the value multiplied by 50 and increased by 6. If the value entered is a string it should return "Error". Note: in `C#`, you'll always get the input as a string, so the above applies if the string isn't representing a double value.
["def problem(a):\n try:\n return a * 50 + 6\n except TypeError:\n return \"Error\"", "def problem(a):\n return \"Error\" if isinstance(a,str) else a*50+6", "def problem(a):\n return \"Error\" if a == str(a) else a * 50 + 6", "def problem(a):\n #Easy Points ^_^\n try:\n return flo...
{"fn_name": "problem", "inputs": [["hello"], [1], [5], [0], [1.2], [3], ["RyanIsCool"]], "outputs": [["Error"], [56], [256], [6], [66], [156], ["Error"]]}
INTRODUCTORY
PYTHON3
CODEWARS
12,535
def problem(a):
9ac00268fc25e0d5c9b01345dcc323bd
UNKNOWN
Given a string of integers, return the number of odd-numbered substrings that can be formed. For example, in the case of `"1341"`, they are `1, 1, 3, 13, 41, 341, 1341`, a total of `7` numbers. `solve("1341") = 7`. See test cases for more examples. Good luck! If you like substring Katas, please try [Longest vo...
["def solve(s):\n return sum(i+1 for i,d in enumerate(list(s)) if d in '13579')", "def solve(s):\n return sum( int(c)%2 for i in range(len(s)) for c in s[i:] )", "import itertools\n\n# Walk through s from left to right. If the current digit is odd,\n# It can create odd substrings with every previous digit.\n# The...
{"fn_name": "solve", "inputs": [["1341"], ["1357"], ["13471"], ["134721"], ["1347231"], ["13472315"]], "outputs": [[7], [10], [12], [13], [20], [28]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,223
def solve(s):
babf55e46765eba32b07b624bca43f76
UNKNOWN
In number theory, Euler's totient is an arithmetic function, introduced in 1763 by Euler, that counts the positive integers less than or equal to `n` that are relatively prime to `n`. Thus, if `n` is a positive integer, then `φ(n)`, notation introduced by Gauss in 1801, is the number of positive integers `k ≤ n` for wh...
["def totient(n):\n if not isinstance(n,int) or n<1: return 0\n \n phi = n >= 1 and n\n for p in range(2, int(n ** .5) + 1):\n if not n % p:\n phi -= phi // p\n while not n % p:\n n //= p\n if n > 1: phi -= phi // n\n return phi", "PRIMES = [2, 3, 5, 7, 11, ...
{"fn_name": "totient", "inputs": [[15], [18], [19], [false], ["wow doge"], [0.0435]], "outputs": [[8], [6], [18], [0], [0], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,982
def totient(n):
6fac013ba44731240e0f8253dfaa0919
UNKNOWN
In programming you know the use of the logical negation operator (**!**), it reverses the meaning of a condition. Your task is to complete the function 'negationValue()' that takes a string of negations with a value and returns what the value would be if those negations were applied to it. ```python negation_value("!...
["def negation_value(s, x):\n return len(s) % 2 ^ bool(x)", "def negation_value(s, val):\n return len(s)&1 ^ bool(val)", "def negation_value(s, val):\n return (bool(val) if (len(s) % 2 == 0) else not val)", "def negation_value(str, val):\n return bool(not val if len(str) % 2 else val)", "negation_value = lamb...
{"fn_name": "negation_value", "inputs": [["!", false], ["!", true], ["!!!", []]], "outputs": [[true], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
910
def negation_value(s, val):
ca7d23b58a4031c46a7d4313dda2325a
UNKNOWN
You get an array of different numbers to sum up. But there is one problem, those numbers all have different bases. For example: ```python You get an array of numbers with their base as an input: [["101",16],["7640",8],["1",9]] ``` The output should be the sum as an integer value with a base of 10, so according to the...
["def sum_it_up(a):\n return sum(int(*x) for x in a)", "def sum_it_up(a):\n return sum(int(n, b) for n, b in a)", "sum_it_up=lambda n: sum(int(x[0],x[1]) for x in n)", "def sum_it_up(numbers_with_bases):\n return sum(int(number, base) for number, base in numbers_with_bases)", "def sum_it_up(numbers_with_bases)...
{"fn_name": "sum_it_up", "inputs": [[[["101", 2], ["10", 8]]], [[["ABC", 16], ["11", 2]]], [[["101", 16], ["7640", 8], ["1", 9]]], [[]]], "outputs": [[13], [2751], [4258], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
911
def sum_it_up(numbers_with_bases):
5c3abead7e60b54e125598aae6ec622f
UNKNOWN
Challenge: Given a two-dimensional array, return a new array which carries over only those arrays from the original, which were not empty and whose items are all of the same type (i.e. homogenous). For simplicity, the arrays inside the array will only contain characters and integers. Example: Given [[1, 5, 4], ['a',...
["def filter_homogenous(arrays):\n return[a for a in arrays if len(set(map(type,a)))==1]", "def homogenous(a):\n return len(set(map(type, a))) == 1\n \ndef filter_homogenous(arrays):\n return list(filter(homogenous, arrays))", "def is_homogenous(array):\n return len(set(map(type, array))) == 1\n\ndef fil...
{"fn_name": "filter_homogenous", "inputs": [[[[1, 5, 4], ["a", 3, 5], ["b"], [], ["1", 2, 3]]], [[[123, 234, 432], ["", "abc"], [""], ["", 1], ["", "1"], []]], [[[1, 2, 3], ["1", "2", "3"], ["1", 2, 3]]]], "outputs": [[[[1, 5, 4], ["b"]]], [[[123, 234, 432], ["", "abc"], [""], ["", "1"]]], [[[1, 2, 3], ["1", "2", "3"]]...
INTRODUCTORY
PYTHON3
CODEWARS
1,953
def filter_homogenous(arrays):
e25e13a373adcd4313889dd10603390c
UNKNOWN
You've just entered a programming contest and have a chance to win a million dollars. This is the last question you have to solve, so your victory (and your vacation) depend on it. Can you guess the function just by looking at the test cases? There are two numerical inputs and one numerical output. Goodluck! hint: go ...
["TABLE = str.maketrans('0123456789','9876543210')\n\ndef code(*args):\n return sum(map(lambda n:int(str(n).translate(TABLE)), args))", "def code(x, y):\n return sum(int('9' * len(str(n))) - n for n in [x, y])\n", "code=lambda Q,S:10**len(str(Q))+10**len(str(S))-2-Q-S", "def code(x, y):\n return sum(int('9' * ...
{"fn_name": "code", "inputs": [[9, 8], [123, 456], [3, 2], [1, 1], [12, 8], [200, 100], [100, 200]], "outputs": [[1], [1419], [13], [16], [88], [1698], [1698]]}
INTRODUCTORY
PYTHON3
CODEWARS
912
def code(x,y):
5a1a8a2f284bdfcacfedfcc01f48cf38
UNKNOWN
Here you have to do some mathematical operations on a "dirty string". This kata checks some basics, it's not too difficult. __So what to do?__ Input: String which consists of two positive numbers (doubles) and exactly one operator like `+, -, * or /` always between these numbers. The string is dirty, which means tha...
["import re\n\ndef calculate_string(st): \n st = re.sub(r'[^-+*/\\d.]', '', st)\n result = eval(st)\n return str(int(round(result)))", "def calculate_string(st: str) -> str:\n return f\"{eval(''.join(s for s in st if s in '0123456789.+-/*')):.0f}\"", "def calculate_string(st):\n clean = \"\"\n for i i...
{"fn_name": "calculate_string", "inputs": [[";$%\u00a7fsdfsd235??df/sdfgf5gh.000kk0000"], ["sdfsd23454sdf*2342"], ["fsdfsd235???34.4554s4234df-sdfgf2g3h4j442"], ["fsdfsd234.4554s4234df+sf234442"], ["a1a2b3c.c0c/a1a0b.cc00c"]], "outputs": [["47"], ["54929268"], ["-210908"], ["234676"], ["12"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,019
def calculate_string(st):
61373dc6509e0f0624238091eb35f2bb
UNKNOWN
Poor Cade has got his number conversions mixed up again! Fix his ```convert_num()``` function so it correctly converts a base-10 ```int```eger, to the selected of ```bin```ary or ```hex```adecimal. ```#The output should be a string at all times``` ```python convert_num(number, base): if 'base' = hex: re...
["def convert_num(number, base):\n try:\n if base == 'hex':\n return hex(number)\n if base == 'bin':\n return bin(number)\n except:\n return 'Invalid number input'\n return 'Invalid base input'", "def convert_num(number, base):\n if not isinstance(number, int):\n ...
{"fn_name": "convert_num", "inputs": [[122, "bin"], ["dog", "bin"], [0, "hex"], [123, "lol"]], "outputs": [["0b1111010"], ["Invalid number input"], ["0x0"], ["Invalid base input"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,234
def convert_num(number, base):
627a9846cd4f13ef8c28543d163ab007
UNKNOWN
# Task You are given two string `a` an `s`. Starting with an empty string we can do the following two operations: ``` append the given string a to the end of the current string. erase one symbol of the current string.``` Your task is to find the least number of operations needed to construct the given string s. Assume...
["def string_constructing(a, s):\n if len(s) == 0:\n return 0\n i = -1\n for j, c in enumerate(s):\n i = a.find(c, i+1)\n if i < 0 or i == len(a) - 1:\n break\n return len(a) - j + (i < 0) + string_constructing(a, s[j + (i >= 0):])", "def string_constructing(pattern,target):\...
{"fn_name": "string_constructing", "inputs": [["aba", "abbabba"], ["aba", "abaa"], ["aba", "a"], ["a", "a"], ["a", "aaa"], ["abcdefgh", "hgfedcba"]], "outputs": [[9], [4], [3], [1], [3], [64]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,456
def string_constructing(a, s):
6d474e5e23bcc64cd7739cf4df96dee8
UNKNOWN
In this kata, you've to count lowercase letters in a given string and return the letter count in a hash with 'letter' as key and count as 'value'. The key must be 'symbol' instead of string in Ruby and 'char' instead of string in Crystal. Example: ```python letter_count('arithmetics') #=> {"a": 1, "c": 1, "e": 1, "h...
["from collections import Counter\ndef letter_count(s):\n return Counter(s)", "def letter_count(s):\n return {i: s.count(i) for i in s}", "from collections import Counter as letter_count", "def letter_count(s):\n letters = {}\n for i in list(s):\n if i in letters:\n letters[i] += 1\n ...
{"fn_name": "letter_count", "inputs": [["codewars"], ["activity"], ["arithmetics"], ["traveller"], ["daydreamer"]], "outputs": [[{"a": 1, "c": 1, "d": 1, "e": 1, "o": 1, "r": 1, "s": 1, "w": 1}], [{"a": 1, "c": 1, "i": 2, "t": 2, "v": 1, "y": 1}], [{"a": 1, "c": 1, "e": 1, "h": 1, "i": 2, "m": 1, "r": 1, "s": 1, "t": 2...
INTRODUCTORY
PYTHON3
CODEWARS
1,316
def letter_count(s):
4572e7b1c76c71605983bbffe5abf9a3
UNKNOWN
Suppose I have two vectors: `(a1, a2, a3, ..., aN)` and `(b1, b2, b3, ..., bN)`. The dot product between these two vectors is defined as: ``` a1*b1 + a2*b2 + a3*b3 + ... + aN*bN ``` The vectors are classified as orthogonal if the dot product equals zero. Complete the function that accepts two sequences as inputs an...
["def is_orthogonal(u, v): \n return sum(i*j for i,j in zip(u,v)) == 0", "def is_orthogonal(u, v):\n return sum(a*b for a, b in zip(u, v)) == 0", "from numpy import dot\n\ndef is_orthogonal(u, v): \n return not dot(u,v )", "def is_orthogonal(u, v):\n dot_product = 0\n for pair in zip(u, v):\n dot_...
{"fn_name": "is_orthogonal", "inputs": [[[1, 2], [2, 1]], [[1, -2], [2, 1]], [[7, 8], [7, -6]], [[-13, -26], [-8, 4]], [[1, 2, 3], [0, -3, 2]], [[3, 4, 5], [6, 7, -8]], [[3, -4, -5], [-4, -3, 0]], [[1, -2, 3, -4], [-4, 3, 2, -1]], [[2, 4, 5, 6, 7], [-14, -12, 0, 8, 4]], [[5, 10, 1, 20, 2], [-2, -20, -1, 10, 5]]], "outp...
INTRODUCTORY
PYTHON3
CODEWARS
1,070
def is_orthogonal(u, v):
475c21fd2903da1bffaa97ebf98b379a
UNKNOWN
An acrostic is a text in which the first letter of each line spells out a word. It is also a quick and cheap way of writing a poem for somebody, as exemplified below : Write a program that reads an acrostic to identify the "hidden" word. Specifically, your program will receive a list of words (reprensenting an acros...
["def read_out(acrostic):\n return \"\".join( word[0] for word in acrostic )", "def read_out(acrostic):\n return ''.join(next(zip(*acrostic)))", "from operator import itemgetter\n\ndef read_out(acrostic):\n return ''.join(map(itemgetter(0), acrostic))", "def read_out(acrostic):\n return ''.join(e[0] for e i...
{"fn_name": "read_out", "inputs": [[["Jolly", "Amazing", "Courteous", "Keen"]], [["Marvelous", "Excellent", "Gifted"]]], "outputs": [["JACK"], ["MEG"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,064
def read_out(acrostic):
8310416ea24391c2dacbd1abca4fb370
UNKNOWN
Your task is to define a function that understands basic mathematical expressions and solves them. For example: ```python calculate("1 + 1") # => 2 calculate("18 + 4*6") # => 42 calculate("245 - 826") # => -581 calculate("09 + 000482") # => 491 calculate("8 / 4 + 6") # => 8 calculate("5 + 1 / 5") ...
["import re\ndef calculate(input):\n try:\n return eval(re.sub(r'(\\d+)', lambda m: str(int(m.group(1))), input))\n except:\n return False", "import re\ndef calculate(s):\n try:\n s = re.sub(r'(?<!\\d)0+(0|[1-9]\\d*)', lambda m: m.group(1), s)\n s = re.sub(r'\\d+(?!\\.)', lambda m: ...
{"fn_name": "calculate", "inputs": [["1 + 1"], ["9 - 4"], ["1 - 4"], ["3 * 4"], ["9 / 3"], ["26 + 73"], ["524 + 277"], ["1 / 2"], ["2 / 5"], ["1 + 2 + 3 + 4 + 5 + 6"], ["123 - 3 - 20 - 100"], ["123 * 987 * 135 * 246"], ["200 / 2 / 10 / 5"], ["1+2-3+4-5+6-7+8-9+10"], ["5*2/3*9/10*123/8"], ["1*2*3/1/2/3+1+2+3-1-2-3"], ["...
INTRODUCTORY
PYTHON3
CODEWARS
11,313
def calculate(input):
3d41b5747627705c9735e33422a0b8c4
UNKNOWN
# Task Your task is to find the smallest number which is evenly divided by all numbers between `m` and `n` (both inclusive). # Example For `m = 1, n = 2`, the output should be `2`. For `m = 2, n = 3`, the output should be `6`. For `m = 3, n = 2`, the output should be `6` too. For `m = 1, n = 10`, the outpu...
["from fractions import gcd\nfrom functools import reduce\n\ndef mn_lcm(m, n):\n return reduce(lambda x, y: (x * y) / gcd(x, y), list(range(min(m, n), max(m, n) + 1)))\n\n", "from fractions import gcd\nfrom functools import reduce\ndef mn_lcm(m, n):\n return reduce(lambda x, y: (x * y) / gcd(x, y), range(min(m, n...
{"fn_name": "mn_lcm", "inputs": [[1, 2], [1, 5], [5, 1], [1, 10], [2, 3], [3, 5], [10, 20], [1, 25], [24, 25]], "outputs": [[2], [60], [60], [2520], [6], [60], [232792560], [26771144400], [600]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,690
def mn_lcm(m, n):
0a4946a5605393b9bb7e2d9591e1426e
UNKNOWN
# Task Alireza and Ali have a `3×3 table` and playing on that. they have 4 table(2×2) A,B,C and D in this table. At beginning all of 9 numbers in 3×3 table is zero. Alireza in each move choose a 2×2 table from A, B, C and D and increase all of 4 numbers in that by one. He asks Ali, how much he increase table ...
["def table_game(table):\n (a, ab, b), (ac, abcd, bd), (c, cd, d) = table\n if (a + b == ab) and (c + d == cd) and (a + c == ac) and (b + d == bd) and (a + b + c + d == abcd):\n return [a, b, c, d]\n return [-1]", "def table_game(table):\n a, b, c, d = table[0][0], table[0][2], table[2][0], table[2][...
{"fn_name": "table_game", "inputs": [[[[1, 2, 1], [2, 4, 2], [1, 2, 1]]], [[[3, 7, 4], [5, 16, 11], [2, 9, 7]]], [[[1, 4, 2], [5, 10, 5], [4, 7, 3]]], [[[2, 4, 2], [4, 6, 4], [2, 4, 2]]], [[[1, 2, 1], [1, 2, 1], [1, 2, 1]]], [[[2, 4, 2], [4, 8, 4], [2, 4, 2]]], [[[1, 3, 2], [5, 10, 5], [4, 7, 3]]]], "outputs": [[[1, 1,...
INTRODUCTORY
PYTHON3
CODEWARS
2,284
def table_game(table):
b25ec17c947be9837b91fcc0b1d6d739
UNKNOWN
How much bigger is a 16-inch pizza compared to an 8-inch pizza? A more pragmatic question is: How many 8-inch pizzas "fit" in a 16-incher? The answer, as it turns out, is exactly four 8-inch pizzas. For sizes that don't correspond to a round number of 8-inchers, you must round the number of slices (one 8-inch pizza = ...
["def how_many_pizzas(n):\n return 'pizzas: {}, slices: {}'.format(*divmod(n * n // 8, 8))", "def how_many_pizzas(n):\n pizzas, slices = (int(n) for n in divmod(n**2, 64))\n return f\"pizzas: {pizzas}, slices: {slices // 8}\"", "def how_many_pizzas(n):\n q, r = divmod(n**2, 8**2)\n return f\"pizzas: {q},...
{"fn_name": "how_many_pizzas", "inputs": [[16], [12], [8], [6], [0]], "outputs": [["pizzas: 4, slices: 0"], ["pizzas: 2, slices: 2"], ["pizzas: 1, slices: 0"], ["pizzas: 0, slices: 4"], ["pizzas: 0, slices: 0"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,353
def how_many_pizzas(n):
271531e9e5e23daa0f9e3901c175ef0c
UNKNOWN
In this Kata, you will be given a string with brackets and an index of an opening bracket and your task will be to return the index of the matching closing bracket. Both the input and returned index are 0-based **except in Fortran where it is 1-based**. An opening brace will always have a closing brace. Return `-1` if...
["def solve(s, idx):\n stack = []\n for i, c in enumerate(s):\n if c == '(': stack += [i]\n if c == ')':\n if not stack: break\n if stack.pop() == idx: return i\n \n return -1", "def solve(s, i):\n c = s[i] == '('\n if not c: return -1\n while c != 0 ...
{"fn_name": "solve", "inputs": [["((1)23(45))(aB)", 0], ["((1)23(45))(aB)", 1], ["((1)23(45))(aB)", 2], ["((1)23(45))(aB)", 6], ["((1)23(45))(aB)", 11], ["(g(At)IO(f)(tM(qk)YF(n)Nr(E)))", 11], ["(g(At)IO(f)(tM(qk)YF(n)Nr(E)))", 0], ["(>_(va)`?(h)C(as)(x(hD)P|(fg)))", 19]], "outputs": [[10], [3], [-1], [9], [14], [28], ...
INTRODUCTORY
PYTHON3
CODEWARS
3,133
def solve(st, idx):
3bf9201205fde88cc4cc36679a2cf23a
UNKNOWN
Given a number `n`, make a down arrow shaped pattern. For example, when `n = 5`, the output would be: 123454321 1234321 12321 121 1 and for `n = 11`, it would be: 123456789010987654321 1234567890987654321 12345678987654321 123456787654321 1234567654321 ...
["def half(i, n):\n return \"\".join(str(d%10) for d in range(1, n-i+1))\n\ndef line(i, n):\n h = half(i, n)\n return \" \" * i + h + h[-2::-1]\n\ndef get_a_down_arrow_of(n):\n return \"\\n\".join(line(i, n) for i in range(n))\n", "from itertools import cycle, islice\n\ndef get_a_down_arrow_of(n):\n \n ...
{"fn_name": "get_a_down_arrow_of", "inputs": [[5]], "outputs": [["123454321\n 1234321\n 12321\n 121\n 1"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,943
def get_a_down_arrow_of(n):
4444daa6cde3233fad916dec88e122f9
UNKNOWN
Description: The mean (or average) is the most popular measure of central tendency; however it does not behave very well when the data is skewed (i.e. wages distribution). In such cases, it's better to use the median. Your task for this kata is to find the median of an array consisting of n elements. You can assume ...
["from statistics import median", "def median(arr):\n arr.sort()\n return (arr[(len(arr) - 1)//2] + arr[(len(arr))//2])/2", "from numpy import median", "import numpy as np\ndef median(arr):\n return np.median(arr) if len(arr)>0 else None\n", "from random import choice\n\ndef median(lst):\n return quickselec...
{"fn_name": "median", "inputs": [[[1, 2, 3, 4]], [[3, 4, 1, 2, 5]], [[10, 29, 23, 94, 76, 96, 5, 85, 4, 33, 47, 41, 87]], [[1]], [[1, -1]]], "outputs": [[2.5], [3], [41], [1], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,590
def median(arr):
bf5929d2cc529d7f169a94ee186a4da2
UNKNOWN
In this simple assignment you are given a number and have to make it negative. But maybe the number is already negative? **Example:** ``` c makeNegative(1); // return -1 makeNegative(-5); // return -5 makeNegative(0); // return 0 ``` ``` cfml makeNegative(1); // return -1 makeNegative(-5); // return -5 makeNegative(0)...
["def make_negative( number ):\n return -abs(number)", "def make_negative( number ):\n return -number if number>0 else number", "def make_negative( number ):\n return (-1) * abs(number)", "def make_negative(number):\n if number >= 0:\n return (0 - number)\n else:\n return number", "def make...
{"fn_name": "make_negative", "inputs": [[42], [-9], [0], [1], [-1]], "outputs": [[-42], [-9], [0], [-1], [-1]]}
INTRODUCTORY
PYTHON3
CODEWARS
13,554
def make_negative( number ):
ac686f945ecea846b540841142c097f0
UNKNOWN
# Task You are given a string `s`. Let's call its substring a group, if all letters in it are adjacent and the same(such as `"aa","bbb","cccc"`..). Let's call the substiring with 2 or more adjacent group a big group(such as `"aabb","bbccc"`...). Your task is to count the number of `big groups` in the given string. ...
["from re import findall; repeat_adjacent=lambda s: len(findall(r\"((.)\\2+(?!\\2)){2,}\",s))", "import re\nrepeat_adjacent=lambda s:sum(len(set(i[0]))>1 for i in re.findall(r'((([a-z])\\3+){2,})', s))", "from functools import partial\nfrom itertools import groupby\nfrom operator import ne\n\ndef repeat_adjacent(s):\n ...
{"fn_name": "repeat_adjacent", "inputs": [["ccccoodeffffiiighhhhhhhhhhttttttts"], ["soooooldieeeeeer"], ["ccccoooooooooooooooooooooooddee"], ["wwwwaaaarrioooorrrrr"], ["gztxxxxxggggggggggggsssssssbbbbbeeeeeeehhhmmmmmmmitttttttlllllhkppppp"]], "outputs": [[3], [0], [1], [2], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,860
def repeat_adjacent(string):
dbbf5dae099728ce3075cd3160f7cf9f
UNKNOWN
Make a function **"add"** that will be able to sum elements of **list** continuously and return a new list of sums. For example: ``` add [1,2,3,4,5] == [1, 3, 6, 10, 15], because it's calculated like this : [1, 1 + 2, 1 + 2 + 3, 1 + 2 + 3 + 4, 1 + 2 + 3 + 4 + 5] ``` If you want to learn more see https://en.wikiped...
["from itertools import accumulate\ndef add(l):\n return list(accumulate(l)) if isinstance(l, list) and all(isinstance(x, int) for x in l) \\\n else 'Invalid input'", "from itertools import accumulate\n\ndef add(lst):\n return list(accumulate(lst))", "from itertools import accumulate\n\ndef add(a):\n re...
{"fn_name": "add", "inputs": [[[5, 10, 15, 20, 25, 30, 35, 40]], [[6, 12, 18, 24, 30, 36, 42]], [[7, 14, 21, 28, 35, 42, 49, 56]], [[8, 16, 24, 32, 40, 48, 56, 64]], [[9, 18, 27, 36, 45, 54]]], "outputs": [[[5, 15, 30, 50, 75, 105, 140, 180]], [[6, 18, 36, 60, 90, 126, 168]], [[7, 21, 42, 70, 105, 147, 196, 252]], [[8,...
INTRODUCTORY
PYTHON3
CODEWARS
1,451
def add(l):
8755cd842ac5ae21100d9f3500d16d61
UNKNOWN
A nested list (or *array* in JavaScript) is a list that apears as a value inside another list, ```python [item, item, [item, item], item] ``` in the above list, [item, item] is a nested list. Your goal is to write a function that determines the depth of the deepest nested list within a given list. return 1 if t...
["def list_depth(l):\n depths = [1]\n for x in l:\n if isinstance(x, list):\n depths.append(list_depth(x) + 1)\n return max(depths)", "def list_depth(lst):\n result = [list_depth(a) for a in lst if isinstance(a, list)]\n return 1 + max(result) if result else 1\n", "def list_depth(l):\n ...
{"fn_name": "list_depth", "inputs": [[[1, [2, [3, [4, [5, [6], 5], 4], 3], 2], 1]], [[true]], [[]], [[2, "yes", [true, false]]], [[2.0, [2, 0], 3.7, [3, 7], 6.7, [6, 7]]], [[[[[]]], [[[]]]]], [[true, false, true, [false], true]], [[[], [], [[], []]]], [[77]], [[2, "yes", [true, [false]]]], [[77, [77]]], [[[77], 77, [[7...
INTRODUCTORY
PYTHON3
CODEWARS
2,768
def list_depth(l):
f4b676e938a000bc189e77a478bce009
UNKNOWN
In this exercise, you will have to create a function named tiyFizzBuzz. This function will take on a string parameter and will return that string with some characters replaced, depending on the value: - If a letter is a upper case consonants, replace that character with "Iron". - If a letter is a lower case consonants...
["def tiy_fizz_buzz(s):\n return \"\".join((\"Iron \"*c.isupper() + \"Yard\"*(c.lower() in \"aeiou\")).strip() or c for c in s)", "def tiy_fizz_buzz(strin):\n strin = list(strin)\n for i, char in enumerate(strin):\n if char in \"AEIOU\" : strin[i] = \"Iron Yard\"\n elif char in ...
{"fn_name": "tiy_fizz_buzz", "inputs": [[" "], ["H"], ["b"], ["A"], ["a"], ["Hello WORLD!"], ["H6H4Na ./?U"]], "outputs": [[" "], ["Iron"], ["b"], ["Iron Yard"], ["Yard"], ["IronYardllYard IronIron YardIronIronIron!"], ["Iron6Iron4IronYard ./?Iron Yard"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,438
def tiy_fizz_buzz(string):
f45e49ec9665eff4cba44d589f7c6a29
UNKNOWN
Given an array (or list) of scores, return the array of _ranks_ for each value in the array. The largest value has rank 1, the second largest value has rank 2, and so on. Ties should be handled by assigning the same rank to all tied values. For example: ranks([9,3,6,10]) = [2,4,3,1] and ranks([3,3,3,3,3,5,1...
["def ranks(a):\n sortA = sorted(a, reverse=True)\n return [sortA.index(s) + 1 for s in a]\n", "def ranks(results):\n ranks = {}\n for k, v in enumerate(sorted(results, reverse=True), start=1):\n if not v in ranks:\n ranks[v] = k\n return [ranks[i] for i in results]", "def ranks(a):\n re...
{"fn_name": "ranks", "inputs": [[[]], [[2]], [[2, 2]], [[1, 2, 3]], [[-5, -10, 3, 1]], [[-1, 3, 3, 3, 5, 5]], [[1, 10, 4]], [[5, 2, 3, 5, 5, 4, 9, 8, 0]]], "outputs": [[[]], [[1]], [[1, 1]], [[3, 2, 1]], [[3, 4, 1, 2]], [[6, 3, 3, 3, 1, 1]], [[3, 1, 2]], [[3, 8, 7, 3, 3, 6, 1, 2, 9]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,751
def ranks(a):
f41660a5c141731ee90623c9914a5450
UNKNOWN
A family of kookaburras are in my backyard. I can't see them all, but I can hear them! # How many kookaburras are there? ## Hint The trick to counting kookaburras is to listen carefully * The males go ```HaHaHa```... * The females go ```hahaha```... * And they always alternate male/female ^ Kata Note : No...
["import re\n\ndef kooka_counter(laughing):\n return len(re.findall(r'(ha)+|(Ha)+',laughing))", "def kooka_counter(laughing):\n return 0 if laughing == '' else laughing.count('Hah') + laughing.count('haH') + 1", "def kooka_counter(laughing):\n return laughing.count(\"Haha\") + laughing.count(\"haHa\") + bool(l...
{"fn_name": "kooka_counter", "inputs": [[""], ["hahahahaha"], ["hahahahahaHaHaHa"], ["HaHaHahahaHaHa"], ["hahahahahahahaHaHa"]], "outputs": [[0], [1], [2], [3], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,406
def kooka_counter(laughing):
4fbb852407abe1f37884ea48249e3700
UNKNOWN
Write a function that calculates the *least common multiple* of its arguments; each argument is assumed to be a non-negative integer. In the case that there are no arguments (or the provided array in compiled languages is empty), return `1`. ~~~if:objc NOTE: The first (and only named) argument of the function `n` spec...
["from functools import reduce\ndef lcm(*args):\n return reduce(lcms, args) if args else 1\n\ndef gcd(a,b):\n \"\"\"Euclidean Algorithm\"\"\"\n return b if a == 0 else gcd(b % a, a)\n \ndef lcms(a, b):\n return (a*b) // gcd(a,b)", "from math import gcd\nfrom functools import reduce\ndef lcm(*args):\n ...
{"fn_name": "lcm", "inputs": [[2, 5], [2, 3, 4], [9], [0], [0, 1], [1, 1, 1], [5, 6, 7, 9, 6, 9, 18, 4, 5, 15, 15, 10, 17, 7], [17, 20, 4, 15, 4, 18, 12, 14, 20, 19, 2, 14, 13, 7], [11, 13, 4, 5, 17, 4, 10, 13, 16, 13, 13], [20, 1, 6, 10, 3, 7, 8, 4], [3, 9, 9, 19, 18, 14, 18, 9], [3, 9, 9, 19, 18, 14, 18, 0]], "output...
INTRODUCTORY
PYTHON3
CODEWARS
563
def lcm(*args):
7ea5ed554466d2fb8d5a5787e646dc5d
UNKNOWN
To celebrate the start of the Rio Olympics (and the return of 'the Last Leg' on C4 tonight) this is an Olympic inspired kata. Given a string of random letters, you need to examine each. Some letters naturally have 'rings' in them. 'O' is an obvious example, but 'b', 'p', 'e', 'A', etc are all just as applicable. 'B' e...
["def olympic_ring(string):\n return (['Not even a medal!'] * 2 + ['Bronze!', 'Silver!', 'Gold!'])[min(4, sum(map(\"abdegopqABBDOPQR\".count, string)) // 2)]", "def olympic_ring(string):\n rings = string.translate(str.maketrans(\n 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',\n '120100000000001111...
{"fn_name": "olympic_ring", "inputs": [["wHjMudLwtoPGocnJ"], ["eCEHWEPwwnvzMicyaRjk"], ["JKniLfLW"], ["EWlZlDFsEIBufsalqof"], ["IMBAWejlGRTDWetPS"]], "outputs": [["Bronze!"], ["Bronze!"], ["Not even a medal!"], ["Silver!"], ["Gold!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,808
def olympic_ring(string):
9a1046c3742a2504e41ea95f84814a20
UNKNOWN
The pizza store wants to know how long each order will take. They know: - Prepping a pizza takes 3 mins - Cook a pizza takes 10 mins - Every salad takes 3 mins to make - Every appetizer takes 5 mins to make - There are 2 pizza ovens - 5 pizzas can fit in a oven - Prepping for a pizza must be done before it can be put ...
["from math import ceil\n\ndef order(pizzas, salads, appetizers):\n tp = 3 * pizzas / 2 + 10 * math.ceil(pizzas / 10)\n ts = 3 * salads + 5 * appetizers\n return max(tp, ts)\n", "def order(pizzas, salads, appetizers):\n side_total = 0\n pizza_total = 0 \n side_total += salads * 3 \n side_total += a...
{"fn_name": "order", "inputs": [[2, 0, 0], [3, 1, 2], [0, 3, 2], [13, 0, 0], [6, 2, 4], [6, 1, 3], [5, 3, 4]], "outputs": [[13], [14.5], [19], [39.5], [26], [19], [29]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,258
def order(pizzas, salads, appetizers):
5d67372232b047e04c6bc257469c2ff7
UNKNOWN
# Solve For X You will be given an equation as a string and you will need to [solve for X](https://www.mathplacementreview.com/algebra/basic-algebra.php#solve-for-a-variable) and return x's value. For example: ```python solve_for_x('x - 5 = 20') # should return 25 solve_for_x('20 = 5 * x - 5') # should return 5 solv...
["from itertools import count\n\ndef solve_for_x(equation):\n return next( x for n in count(0) for x in [n, -n] if eval(equation.replace(\"x\", str(x)).replace(\"=\", \"==\")) )", "import re\ndef solve_for_x(equation):\n left,right = equation.split(\"=\")\n answer = False\n TrialAndErrorRipMs = -1000\n w...
{"fn_name": "solve_for_x", "inputs": [["x - 5 = 20"], ["5 * x + 5 = 30"], ["20 = 5 * x - 5"], ["24 = 4 + 5 * x"], ["x = 5"], ["x * 100 = 700"], ["2 * x + 5 = 105"], ["2 * x = 198"], ["x - 100 + 2 - 50 = 52"], ["x / 3 = 33"], ["x + 80 = 20"], ["x + 20 = -60"], ["5 * x + 20 - x = 60"], ["x + x + 6 = 10"], ["5 * x = x + 8...
INTRODUCTORY
PYTHON3
CODEWARS
6,580
def solve_for_x(equation):
ddd088b5d7e0b74a9f300d1a0f9f5f5b
UNKNOWN
Write function heron which calculates the area of a triangle with sides a, b, and c. Heron's formula: sqrt (s \* (s - a) \* (s - b) \* (s - c)), where s = (a + b + c) / 2. Output should have 2 digits precision.
["import math\ndef heron(a,b,c):\n s=(a+b+c)/2\n return round(math.sqrt(s*(s-a)*(s-b)*(s - c)),2)", "def heron(a,b,c):\n return round((1/4)*(4*b*b*c*c-(b*b+c*c-a*a)**2)**(1/2),2)", "heron=lambda*args:(lambda a,b,c,s:round((s*(s-a)*(s-b)*(s-c))**.5,2))(*args,sum(args)/2)", "def heron(*sides):\n s=sum(sides)/...
{"fn_name": "heron", "inputs": [[3, 4, 5], [6, 8, 10]], "outputs": [[6], [24]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,175
def heron(a,b,c):
3e400d50d68eb8d4b2458705c724f1a6
UNKNOWN
HELP! Jason can't find his textbook! It is two days before the test date, and Jason's textbooks are all out of order! Help him sort a list (ArrayList in java) full of textbooks by subject, so he can study before the test. The sorting should **NOT** be case sensitive
["def sorter(textbooks):\n return sorted(textbooks,key=str.lower)", "def sorter(textbooks):\n return sorted(textbooks, key=str.casefold)", "def sorter(textbooks):\n return sorted(textbooks, key = lambda arg: arg.lower())", "sorter = lambda x: sorted(x,key=lambda s:s.lower())", "sorter = lambda text: sorted(tex...
{"fn_name": "sorter", "inputs": [[["Algebra", "History", "Geometry", "English"]], [["Algebra", "history", "Geometry", "english"]], [["Alg#bra", "$istory", "Geom^try", "**english"]]], "outputs": [[["Algebra", "English", "Geometry", "History"]], [["Algebra", "english", "Geometry", "history"]], [["$istory", "**english", "...
INTRODUCTORY
PYTHON3
CODEWARS
13,287
def sorter(textbooks):
7c1ad21eae4ca5e5e98c0513790ddfde
UNKNOWN
Create a function xMasTree(height) that returns a christmas tree of the correct height. The height is passed through to the function and the function should return a list containing each line of the tree. ``` xMasTree(5) should return : ['____#____', '___###___', '__#####__', '_#######_', '#########', '____#____', '__...
["def xMasTree(n):\n return [(\"#\"*(x*2+1)).center(n*2-1, \"_\") for x in list(range(n))+[0]*2]", "def xMasTree(n):\n hashtags = '#' * (n - 1)\n spaces = '_' * (n - 1)\n tree = []\n for i in range(n):\n left = spaces[i:] + hashtags[:i]\n tree.append(left + '#' + left[::-1])\n for i in ra...
{"fn_name": "xMasTree", "inputs": [[3], [7], [2], [4], [6]], "outputs": [[["__#__", "_###_", "#####", "__#__", "__#__"]], [["______#______", "_____###_____", "____#####____", "___#######___", "__#########__", "_###########_", "#############", "______#______", "______#______"]], [["_#_", "###", "_#_", "_#_"]], [["___#__...
INTRODUCTORY
PYTHON3
CODEWARS
1,634
def xMasTree(n):
5764fad3447515f4e31145124f1fd9eb
UNKNOWN
## Task Your challenge is to write a function named `getSlope`/`get_slope`/`GetSlope` that calculates the slope of the line through two points. ## Input ```if:javascript,python Each point that the function takes in is an array 2 elements long. The first number is the x coordinate and the second number is the y coord...
["def getSlope(p1, p2):\n return None if p1[0] == p2[0] else (p2[1] - p1[1])/(p2[0] - p1[0])\n", "def getSlope(p1, p2):\n if p2[0] - p1[0]: return (p2[1]-p1[1]) / (p2[0]-p1[0])", "def getSlope(p1, p2):\n return None if p1[0] == p2[0] else (p1[1] - p2[1]) / (p1[0] - p2[0])", "def getSlope(p1, p2):\n if not (...
{"fn_name": "getSlope", "inputs": [[[1, 1], [2, 2]], [[-5, -5], [9, 9]], [[1, 8], [2, 9]], [[8, 3], [-4, 5]], [[5, 3], [8, 9]], [[1, 3], [0, 3]], [[11, 1], [1, 11]], [[1, 1], [1, 2]], [[-5, 9], [-5, 12]], [[1, 1], [1, 1]], [[-5, 9], [-5, 9]]], "outputs": [[1], [1], [1], [-0.16666666666666666], [2], [0], [-1], [null], [...
INTRODUCTORY
PYTHON3
CODEWARS
1,303
def getSlope(p1, p2):
d0ee363cc6fd9bd3ececa08d2a8bcba1
UNKNOWN
An ordered sequence of numbers from 1 to N is given. One number might have deleted from it, then the remaining numbers were mixed. Find the number that was deleted. Example: - The starting array sequence is `[1,2,3,4,5,6,7,8,9]` - The mixed array with one deleted number is `[3,2,4,6,7,8,1,9]` - Your function shoul...
["def find_deleted_number(arr, mixed_arr):\n return sum(arr)-sum(mixed_arr)", "def find_deleted_number(a, b):\n return (set(a) - set(b)).pop() if len(a) != len(b) else 0", "def find_deleted_number(arr, mixed_arr):\n lost = 0\n for i in arr:\n if i not in mixed_arr:\n lost = i\n ...
{"fn_name": "find_deleted_number", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 7, 9, 4, 8, 1, 2, 3]], [[1, 2, 3, 4, 5, 6, 7], [2, 3, 6, 1, 5, 4, 7]], [[1, 2, 3, 4, 5, 6, 7, 8, 9], [5, 7, 6, 9, 4, 8, 1, 2, 3]], [[1], []], [[], []]], "outputs": [[6], [0], [0], [1], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,263
def find_deleted_number(arr, mixed_arr):
deabe502155ebe6a3b39c8c69d7b63f5
UNKNOWN
In this kata, you need to make a (simplified) LZ78 encoder and decoder. [LZ78](https://en.wikipedia.org/wiki/LZ77_and_LZ78#LZ78) is a dictionary-based compression method created in 1978. You will find a detailed explanation about how it works below. The input parameter will always be a non-empty string of upper case ...
["import re\n\ndef encoder(s):\n d, out, it = {},[], iter(s)\n for c in it:\n i,k = 0,c\n while k in d: \n i,c = d[k], next(it,'')\n if not c: break\n k += c\n d[k] = len(d)+1\n out.append(f'{i}{c}')\n return ''.join(out)\n\n\ndef decoder(s):\n d ...
{"fn_name": "encoder", "inputs": [["ABAABABAABAB"], ["ABAABABAABABAA"], ["ABBCBCABABCAABCAABBCAA"], ["AAAAAAAAAAAAAAA"], ["ABCABCABCABCABCABC"], ["ABCDDEFGABCDEDBBDEAAEDAEDCDABC"]], "outputs": [["0A0B1A2A4A4B"], ["0A0B1A2A4A4B3"], ["0A0B2C3A2A4A6B6"], ["0A1A2A3A4A"], ["0A0B0C1B3A2C4C7A6"], ["0A0B0C0D4E0F0G1B3D0E4B2D10A...
INTRODUCTORY
PYTHON3
CODEWARS
9,933
def encoder(data):
6f26dc8a49f26a447bf5ef863bb20cb6
UNKNOWN
# Task The sequence of `Chando` is an infinite sequence of all Chando's numbers in ascending order. A number is called `Chando's` if it is an integer that can be represented as a sum of different positive integer powers of 5. The first Chando's numbers is 5 (5^1). And the following nth Chando's numbers are: ``` ...
["def nth_chandos_number(n):\n return int((bin(n)+\"0\")[2:], 5)", "from itertools import combinations, chain\nfrom math import log\ndef nth_chandos_number(n):\n l = [0] + [5 ** i for i in range(1, int(log(n, 5)) + 10)]\n m = chain(*[combinations(l, ni) for ni in range(1, len(l) + 1)])\n ls = sorted(list(se...
{"fn_name": "nth_chandos_number", "inputs": [[1], [2], [9], [123], [23]], "outputs": [[5], [25], [630], [97530], [3280]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,590
def nth_chandos_number(n):
273823b6a2a14446a40b590a1a6ed844
UNKNOWN
In another Kata I came across a weird `sort` function to implement. We had to sort characters as usual ( 'A' before 'Z' and 'Z' before 'a' ) except that the `numbers` had to be sorted **after** the `letters` ( '0' after 'z') !!! (After a couple of hours trying to solve this unusual-sorting-kata I discovered final test...
["def unusual_sort(array):\n return sorted(array, key=lambda x: (str(x).isdigit(), str(x), -isinstance(x, int)))", "def unusual_sort(array):\n return sorted(array, key=lambda item: (str(item).isdigit(), str(item), isinstance(item, str)))", "import string\n\n\ndef unusual_sort(array):\n #your code here\n upp...
{"fn_name": "unusual_sort", "inputs": [[["0", "9", "8", "1", "7", "2", "6", "3", "5", "4"]], [["3", "2", "1", "c", "b", "a"]], [["c", "b", "a", "9", "5", "0", "X", "Y", "Z"]], [[3, "3", "2", 2, "2", "1", 1, "a", "b", "c"]], [[]], [[1]], [["a"]]], "outputs": [[["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]], [["a", ...
INTRODUCTORY
PYTHON3
CODEWARS
2,309
def unusual_sort(array):
c186f33c2c4f518af3334ecd3d5f3fdd
UNKNOWN
Given a list of white pawns on a chessboard (any number of them, meaning from 0 to 64 and with the possibility to be positioned everywhere), determine how many of them have their backs covered by another. Pawns attacking upwards since we have only white ones. Please remember that a pawn attack(and defend as well) onl...
["def covered_pawns(pawns):\n pawns = set(pawns)\n return len({p for p in pawns for x,y in [map(ord, p)] if {chr(x-1)+chr(y-1), chr(x+1)+chr(y-1)} & pawns})", "def covered_pawns(pawns):\n count = 0\n for i in range(len(pawns)):\n x, y = list(pawns[i])\n if \"\".join([chr(ord(x) - 1), str(int(y...
{"fn_name": "covered_pawns", "inputs": [[["f7", "b1", "h1", "c7", "h7"]], [["e5", "b2", "b4", "g4", "a1", "a5"]], [["a2", "b1", "c2"]], [["a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "d1", "d2", "d3", "d4", "d5", "d6", "d...
INTRODUCTORY
PYTHON3
CODEWARS
3,107
def covered_pawns(pawns):
a1a740e3242fd1167eb4e44a9c8266ec
UNKNOWN
Count the number of divisors of a positive integer `n`. Random tests go up to `n = 500000`. ## Examples ```python divisors(4) == 3 # 1, 2, 4 divisors(5) == 2 # 1, 5 divisors(12) == 6 # 1, 2, 3, 4, 6, 12 divisors(30) == 8 # 1, 2, 3, 5, 6, 10, 15, 30 ```
["def divisors(n):\n return len([l_div for l_div in range(1, n + 1) if n % l_div == 0]);", "# For Beginners.\n\n# Time: 11724ms\n# it's slow because use isinstance\ndef divisors5(n):\n return len(list([e for e in [x if n % x == 0 else None for x in range(1, n + 1)] if isinstance(e, int)]))\n\n\n# Time: 7546ms\n#...
{"fn_name": "divisors", "inputs": [[1], [4], [5], [12], [25], [30], [4096]], "outputs": [[1], [3], [2], [6], [3], [8], [13]]}
INTRODUCTORY
PYTHON3
CODEWARS
14,344
def divisors(n):
e2cb454d343e95c726d517cf0c2fb026
UNKNOWN
For a pole vaulter, it is very important to begin the approach run at the best possible starting mark. This is affected by numerous factors and requires fine-tuning in practice. But there is a guideline that will help a beginning vaulter start at approximately the right location for the so-called "three-step approach,"...
["def starting_mark(height):\n return round(9.45 + (10.67 - 9.45) / (1.83 - 1.52) * (height - 1.52), 2)", "# The linear relashionship is obvious taking a couple a informations (L1,H1) and (L2,H2)\n# One gets 3.9354838709677433 = (H1-H2)/(L1-L2) and beta = H1-3.9354838709677433*H1\n\ndef starting_mark(height):\n r...
{"fn_name": "starting_mark", "inputs": [[1.52], [1.83], [1.22], [2.13], [1.75]], "outputs": [[9.45], [10.67], [8.27], [11.85], [10.36]]}
INTRODUCTORY
PYTHON3
CODEWARS
16,344
def starting_mark(height):
8de055cbd00c65589e319a85d5310490
UNKNOWN
Complete the function that accepts a valid string and returns an integer. Wait, that would be too easy! Every character of the string should be converted to the hex value of its ascii code, then the result should be the sum of the numbers in the hex strings (ignore letters). ## Examples ``` "Yo" ==> "59 6f" ==> 5 + 9...
["def hex_hash(code):\n return sum(int(d) for c in code for d in hex(ord(c)) if d.isdigit())", "def hex_hash(s):\n return sum(sum(int(c) for c in hex(ord(c))[2:] if c in \"0123456789\") for c in s)", "def hex_hash(code):\n first = ''\n for i in code :\n first += hex(ord(i))[2:]\n second = ''\n ...
{"fn_name": "hex_hash", "inputs": [["kcxnjsklsHskjHDkl7878hHJk"], [""], ["ThisIsATest!"], ["dhsajkbfyewquilb4y83q903ybr8q9apf7\\9ph79qw0-eq230br[wq87r0=18-[#20r370B 7Q0RFP23B79037902RF79WQ0[]]]"]], "outputs": [[218], [0], [120], [802]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,290
def hex_hash(code):
37a11955428191e3d3af4c61d2dde89b
UNKNOWN
Create a function that returns the average of an array of numbers ("scores"), rounded to the nearest whole number. You are not allowed to use any loops (including for, for/in, while, and do/while loops).
["def average(array):\n return round(sum(array) / len(array))", "from statistics import mean\n\ndef average(array):\n return round(mean(array))", "from statistics import mean\ndef average(array):\n return int(round(mean(array), 0))", "from numpy import mean\ndef average(array):\n return round(mean(array))",...
{"fn_name": "average", "inputs": [[[5, 78, 52, 900, 1]], [[5, 25, 50, 75]], [[2]], [[1, 1, 1, 1, 9999]], [[0]]], "outputs": [[207], [39], [2], [2001], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
932
def average(array):
62d466bee6315774356cccd70b2efde4
UNKNOWN
## Task You are given an array of integers. On each move you are allowed to increase exactly one of its element by one. Find the minimal number of moves required to obtain a strictly increasing sequence from the input. ## Example For `arr = [1, 1, 1]`, the output should be `3`. ## Input/Output - `[input]` integ...
["from functools import reduce\n\narray_change = lambda arr: reduce(lambda a, u: (max(a[0] + 1, u), a[1] + max(0, a[0] - u + 1)), arr, (-10001, 0))[1]", "def array_change(arr):\n if not arr: return 0\n x, y = arr[0], 0\n for i in arr[1:]:\n x = max(x + 1, i)\n y += x - i\n return y", "def array_change(arr):\n...
{"fn_name": "array_change", "inputs": [[[1, 1, 1]], [[-1000, 0, -2, 0]], [[2, 1, 10, 1]], [[2, 3, 3, 5, 5, 5, 4, 12, 12, 10, 15]]], "outputs": [[3], [5], [12], [13]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,910
def array_change(arr):
ed4b6a2487bdbaf9c94083c02e2861bb
UNKNOWN
A hero is on his way to the castle to complete his mission. However, he's been told that the castle is surrounded with a couple of powerful dragons! each dragon takes 2 bullets to be defeated, our hero has no idea how many bullets he should carry.. Assuming he's gonna grab a specific given number of bullets and move fo...
["def hero(bullets, dragons):\n return bullets >= dragons * 2", "def hero(bullets, dragons):\n '''\n Ascertains if hero can survive\n Parameters:\n bullets: (int) - number of bullets hero has\n dragons: (int) - number of dragons\n Returns:\n True (Survive) or False (Hero gets killed)...
{"fn_name": "hero", "inputs": [[10, 5], [7, 4], [4, 5], [100, 40], [1500, 751], [0, 1]], "outputs": [[true], [false], [false], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
13,556
def hero(bullets, dragons):
a439a038920828f065ddda58411c8458
UNKNOWN
You are given two strings. In a single move, you can choose any of them, and delete the first (i.e. leftmost) character. For Example: * By applying a move to the string `"where"`, the result is the string `"here"`. * By applying a move to the string `"a"`, the result is an empty string `""`. Implement a function tha...
["def shift_left(a, b):\n r = len(a) + len(b)\n for i in range(-1, -min(len(a), len(b)) - 1, -1):\n if a[i] != b[i]:\n break\n r -= 2\n return r", "def shift_left(a, b):\n r = 0\n while a != b:\n if len(b) > len(a):\n b = b[1::] \n r += 1\n els...
{"fn_name": "shift_left", "inputs": [["test", "west"], ["test", "yes"], ["b", "ab"], ["abacabadabacaba", "abacabadacaba"], ["aaabc", "bc"], ["dark", "d"], ["dadc", "dddc"], ["nogkvcdldfpvlbkpedsecl", "nogkvcdldfpvlbkpedsecl"]], "outputs": [[2], [7], [1], [18], [3], [5], [4], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,583
def shift_left(a, b):
2484c870eac9c61ed888b4d1cb608154
UNKNOWN
You have an array of numbers. Your task is to sort ascending odd numbers but even numbers must be on their places. Zero isn't an odd number and you don't need to move it. If you have an empty array, you need to return it. *Example* ```python sort_array([5, 3, 2, 8, 1, 4]) == [1, 3, 2, 8, 5, 4] ```
["def sort_array(arr):\n odds = sorted((x for x in arr if x%2 != 0), reverse=True)\n return [x if x%2==0 else odds.pop() for x in arr]", "def sort_array(source_array):\n odds = iter(sorted(v for v in source_array if v % 2))\n return [next(odds) if i % 2 else i for i in source_array]", "def sort_array(source_arr...
{"fn_name": "sort_array", "inputs": [[[5, 3, 2, 8, 1, 4, 11]], [[2, 22, 37, 11, 4, 1, 5, 0]], [[1, 111, 11, 11, 2, 1, 5, 0]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 2, 3, 4, 9, 8, 7, 6, 5]]], "outputs": [[[1, 3, 2, 8, 5, 4, 11]], [[2, 22, 1, 5, 4, 11, 37, 0]], [[1, 1, 5, 11, 2, 11, ...
INTRODUCTORY
PYTHON3
CODEWARS
2,398
def sort_array(source_array):
950672b8c05bf4a8a99d3fa828135c39
UNKNOWN
# Pythagorean Triples A Pythagorean triplet is a set of three numbers a, b, and c where `a^2 + b^2 = c^2`. In this Kata, you will be tasked with finding the Pythagorean triplets whose product is equal to `n`, the given argument to the function `pythagorean_triplet`. ## Your task In this Kata, you will be tasked with...
["def pythagorean_triplet(n):\n for a in range(3, n):\n for b in range(a+1, n):\n c = (a*a + b*b)**0.5\n if a*b*c > n:\n break\n if c == int(c) and a*b*c == n:\n return [a, b, c]", "def getTriplets(n):\n divs = {y for x in range(1,int(n**.5)+1)...
{"fn_name": "pythagorean_triplet", "inputs": [[60], [780], [2040], [4200], [12180], [120120], [192720], [328860], [907200], [1440600]], "outputs": [[[3, 4, 5]], [[5, 12, 13]], [[8, 15, 17]], [[7, 24, 25]], [[20, 21, 29]], [[33, 56, 65]], [[48, 55, 73]], [[60, 63, 87]], [[42, 144, 150]], [[49, 168, 175]]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,289
def pythagorean_triplet(n):
cfb7deffd7e3bf3014ba3ab5acac6fec
UNKNOWN
Define n!! as n!! = 1 \* 3 \* 5 \* ... \* n if n is odd, n!! = 2 \* 4 \* 6 \* ... \* n if n is even. Hence 8!! = 2 \* 4 \* 6 \* 8 = 384, there is no zero at the end. 30!! has 3 zeros at the end. For a positive integer n, please count how many zeros are there at the end of n!!. Example: count\_zeros\_n\_d...
["def count_zeros_n_double_fact(n): \n if n % 2 != 0:\n return 0\n k = 0\n while n >= 10:\n k += n // 10\n n //= 5\n return k", "def count_zeros_n_double_fact(n):\n return 0 if n%2 == 1 else (n // 6250) + (n // 1250) + (n // 250) + ( n // 50 ) + ( n // 10 ) ", "from functools import ...
{"fn_name": "count_zeros_n_double_fact", "inputs": [[8], [30], [487], [500]], "outputs": [[0], [3], [0], [62]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,453
def count_zeros_n_double_fact(n):
68f959091bab9095ff255e0fe43d19b0
UNKNOWN
Given a string, capitalize the letters that occupy even indexes and odd indexes separately, and return as shown below. Index `0` will be considered even. For example, `capitalize("abcdef") = ['AbCdEf', 'aBcDeF']`. See test cases for more examples. The input will be a lowercase string with no spaces. Good luck! If y...
["def capitalize(s):\n s = ''.join(c if i%2 else c.upper() for i,c in enumerate(s))\n return [s, s.swapcase()]", "def capitalize(s):\n result = ['','']\n for i,c in enumerate(s):\n result[0] += c.lower() if i % 2 else c.upper()\n result[1] += c.upper() if i % 2 else c.lower()\n return resul...
{"fn_name": "capitalize", "inputs": [["abcdef"], ["codewars"], ["abracadabra"], ["codewarriors"], ["indexinglessons"], ["codingisafunactivity"]], "outputs": [[["AbCdEf", "aBcDeF"]], [["CoDeWaRs", "cOdEwArS"]], [["AbRaCaDaBrA", "aBrAcAdAbRa"]], [["CoDeWaRrIoRs", "cOdEwArRiOrS"]], [["InDeXiNgLeSsOnS", "iNdExInGlEsSoNs"]]...
INTRODUCTORY
PYTHON3
CODEWARS
28,461
def capitalize(s):
cfe55c43e62586e7692691c5491acf0b
UNKNOWN
This is simple version of harder [Square Sums](/kata/square-sums). # Square sums Write function `square_sums_row` (or `squareSumsRow`/`SquareSumsRow` depending on language rules) that, given integer number `N` (in range `2..43`), returns array of integers `1..N` arranged in a way, so sum of each 2 consecutive numbers...
["def square_sums_row(n):\n\n def dfs():\n if not inp: yield res\n for v in tuple(inp):\n if not res or not ((res[-1]+v)**.5 % 1):\n res.append(v)\n inp.discard(v)\n yield from dfs()\n inp.add(res.pop())\n\n inp, res = set(range(...
{"fn_name": "square_sums_row", "inputs": [[5], [24]], "outputs": [[false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
9,910
def square_sums_row(n):
93644b0e6ecb335a6592e66322b5cbfb
UNKNOWN
A Madhav array has the following property: ```a[0] = a[1] + a[2] = a[3] + a[4] + a[5] = a[6] + a[7] + a[8] + a[9] = ...``` Complete the function/method that returns `true` if the given array is a Madhav array, otherwise it returns `false`. *Edge cases: An array of length* `0` *or* `1` *should not be considered a Mad...
["def is_madhav_array(arr):\n nTerms = ((1+8*len(arr))**.5-1)/2\n return (len(arr) > 1 and not nTerms%1 and\n len({ sum(arr[int(i*(i+1)//2):int(i*(i+1)//2)+i+1]) for i in range(int(nTerms))}) == 1)", "def is_madhav_array(arr):\n p = 1\n c = 2\n while p < len(arr) and arr[0] == sum(arr[p:p + c]...
{"fn_name": "is_madhav_array", "inputs": [[[6, 2, 4, 2, 2, 2, 1, 5, 0, 0]], [[6, 2, 4, 2, 2, 2, 1, 5, 0, -100]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, -2, -1]], [[-6, -3, -3, 8, -5, -4]], [[-6, -3, -3, 8, -10, -4]], [[3, 1, 2, 3, 0]], [[3, 3]], [[]], [[1]], [[5, 2, 4, 1, 0, 3]], [[6, 2, 4, 2, 2, 2, 1, 5, 0, 0, -12, ...
INTRODUCTORY
PYTHON3
CODEWARS
2,607
def is_madhav_array(arr):
33fca673e0cb4421f8628e9bd4872455
UNKNOWN
In your class, you have started lessons about [arithmetic progression](https://en.wikipedia.org/wiki/Arithmetic_progression). Since you are also a programmer, you have decided to write a function that will return the first `n` elements of the sequence with the given common difference `d` and first element `a`. Note tha...
["def arithmetic_sequence_elements(a, r, n):\n return ', '.join(str(a + b * r) for b in range(n))\n", "def arithmetic_sequence_elements(a, r, n):\n return \", \".join((str(a+r*i) for i in range(n)))", "from itertools import count, islice\n\ndef arithmetic_sequence_elements(a, r, n):\n return ', '.join([str(x) ...
{"fn_name": "arithmetic_sequence_elements", "inputs": [[1, 2, 5], [1, 0, 5], [1, -3, 10], [100, -10, 10]], "outputs": [["1, 3, 5, 7, 9"], ["1, 1, 1, 1, 1"], ["1, -2, -5, -8, -11, -14, -17, -20, -23, -26"], ["100, 90, 80, 70, 60, 50, 40, 30, 20, 10"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,511
def arithmetic_sequence_elements(a, r, n):
6027f009a2f62a8118dad3f5ac166cbf
UNKNOWN
You will get an array of numbers. Every preceding number is smaller than the one following it. Some numbers will be missing, for instance: ``` [-3,-2,1,5] //missing numbers are: -1,0,2,3,4 ``` Your task is to return an array of those missing numbers: ``` [-1,0,2,3,4] ```
["def find_missing_numbers(arr):\n if not arr:\n return []\n return sorted(set(range(arr[0] + 1, arr[-1])).difference(arr))\n", "def find_missing_numbers(arr):\n return [x for x in range(arr[0], arr[-1]+1) if x not in arr] if arr else []", "def find_missing_numbers(arr):\n return [n for n in range(ar...
{"fn_name": "find_missing_numbers", "inputs": [[[-3, -2, 1, 4]], [[-1, 0, 1, 2, 3, 4]], [[]], [[0]], [[-4, 4]]], "outputs": [[[-1, 0, 2, 3]], [[]], [[]], [[]], [[-3, -2, -1, 0, 1, 2, 3]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,344
def find_missing_numbers(arr):
3b8441afe2729ebb6fd6faebdd8e39d1
UNKNOWN
Your task is to make two functions, ```max``` and ```min``` (`maximum` and `minimum` in PHP and Python) that take a(n) array/vector of integers ```list``` as input and outputs, respectively, the largest and lowest number in that array/vector. #Examples ```python maximun([4,6,2,1,9,63,-134,566]) returns 566 minimun([-5...
["minimum = min\nmaximum = max", "minimum,maximum = min,max", "def minimum(arr):\n return min(arr)\n\ndef maximum(arr):\n return max(arr)", "\ndef minimum(arr):\n min = None\n for i in arr:\n if min == None:\n min = i\n elif i < min:\n min = i\n return min\n \nd...
{"fn_name": "minimum", "inputs": [[[-52, 56, 30, 29, -54, 0, -110]], [[42, 54, 65, 87, 0]], [[1, 2, 3, 4, 5, 10]], [[-1, -2, -3, -4, -5, -10]], [[9]]], "outputs": [[-110], [0], [1], [-10], [9]]}
INTRODUCTORY
PYTHON3
CODEWARS
15,055
def minimum(arr):
4cdeb702db2743f4ec1c952c22e512bc
UNKNOWN
**Steps** 1. Square the numbers that are greater than zero. 2. Multiply by 3 every third number. 3. Multiply by -1 every fifth number. 4. Return the sum of the sequence. **Example** `{ -2, -1, 0, 1, 2 }` returns `-6` ``` 1. { -2, -1, 0, 1 * 1, 2 * 2 } 2. { -2, -1, 0 * 3, 1, 4 } 3. { -2, -1, 0, 1, -1 * 4 } 4. -6 ```...
["def calc(a):\n return sum( x**(1 + (x>=0)) * (1 + 2*(not i%3)) * (-1)**(not i%5) for i,x in enumerate(a,1))", "def calc(a):\n for i, n in enumerate(a):\n if a[i] > 0: a[i] *= a[i]\n if i % 3 == 2: a[i] = a[i] * 3\n if i % 5 == 4: a[i] = a[i] * -1\n return sum(a)", "def calc(a):\n prin...
{"fn_name": "calc", "inputs": [[[0, 2, 1, -6, -3, 3]], [[0]], [[1, 1, 1, 1, 1]], [[1, 1, -9, 9, 16, -15, -45, -73, 26]], [[1, -1, 10, -9, 16, 15, 45, -73, -26]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[-5, -5, -5, -5, -5, -5, -5]]], "outputs": [[31], [0], [5], [1665], [2584], [0], [-45]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,066
def calc(a):
82d41a1d23d1f5ad5480d33f054fc2c0
UNKNOWN
# Task In the city, a bus named Fibonacci runs on the road every day. There are `n` stations on the route. The Bus runs from station1 to stationn. At the departure station(station1), `k` passengers get on the bus. At the second station(station2), a certain number of passengers get on and the same number get off. T...
["def sim(k,n,p):\n r = [(k,k,0),(k,p,p)]\n for i in range(n-2):\n u,d = r[0][1]+r[1][1],r[1][1]\n r = [r[1],(r[1][0]+u-d,u,d)]\n return r[1][0]\n\ndef calc(k,n,m,x):\n z,o = sim(k,n-1,0), sim(k,n-1,1)\n return sim(k,x,(m-z)//(o-z))", "def fibLikeGen():\n a,b = (1,0), (0,1) ...
{"fn_name": "calc", "inputs": [[5, 7, 32, 4], [12, 23, 212532, 8]], "outputs": [[13], [252]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,530
def calc(k,n,m,x):
78fb1db3add939897902afa52093d6dd
UNKNOWN
###Instructions A time period starting from ```'hh:mm'``` lasting until ```'hh:mm'``` is stored in an array: ``` ['08:14', '11:34'] ``` A set of different time periods is then stored in a 2D Array like so, each in its own sub-array: ``` [['08:14','11:34'], ['08:16','08:18'], ['22:18','01:14'], ['09:30','10:32'], ['04:...
["def sort_time(arr):\n arr, s = sorted(arr, key=lambda t: t[0]), []\n while arr:\n nextTP = next((i for i,t in enumerate(arr) if not s or t[0] >= s[-1][1]), 0)\n s.append(arr.pop(nextTP))\n return s", "def sort_time(arr):\n arr = sorted(arr, key = lambda x: x[0])\n out = [[\"\", \"00:00\"]...
{"fn_name": "sort_time", "inputs": [[[["08:14", "11:34"], ["08:16", "08:18"], ["13:48", "01:14"], ["09:30", "10:32"], ["04:23", "05:11"], ["11:48", "13:48"], ["01:12", "01:14"], ["01:13", "08:15"]]], [[["00:00", "00:05"], ["16:37", "18:19"], ["12:07", "12:12"], ["00:30", "02:49"], ["12:12", "12:14"], ["12:14", "15:00"]...
INTRODUCTORY
PYTHON3
CODEWARS
3,906
def sort_time(arr):
8edd638804c2b16b33db6e3ebd27e994
UNKNOWN
Calculate the number of items in a vector that appear at the same index in each vector, with the same value. ```python vector_affinity([1, 2, 3, 4, 5], [1, 2, 2, 4, 3]) # => 0.6 vector_affinity([1, 2, 3], [1, 2, 3]) # => 1.0 ``` Affinity value should be realized on a scale of 0.0 to 1.0, with 1.0 being absolut...
["def vector_affinity(a, b):\n longer = len(a) if len(a) > len(b) else len(b)\n return len([i for i, j in zip(a, b) if i == j]) / float(longer) if longer > 0 else 1.0", "def vector_affinity(a, b):\n return sum([1.0 for x, y in zip(a, b) if x == y]) / max(len(a), len(b)) if max(len(a), len(b)) else 1", "from iterto...
{"fn_name": "vector_affinity", "inputs": [[[1, 2, 3], [1, 2, 3, 4, 5]], [[1, 2, 3, 4], [1, 2, 3, 5]], [[1, 2, 3, 4, 5], []], [[1, 2, 3], [1, 2, 3]], [[6, 6, 6, 6, 6, 6], [6, null, null, 6, 6, null]], [[6], [6, 6, 6, 6, 6, 6]], [[], []], [[null], [null]]], "outputs": [[0.6], [0.75], [0.0], [1.0], [0.5], [0.1666666666666...
INTRODUCTORY
PYTHON3
CODEWARS
1,771
def vector_affinity(a, b):
97b56116a4954c8701838260f5ed3807
UNKNOWN
You probably know that the "mode" of a set of data is the data point that appears most frequently. Looking at the characters that make up the string `"sarsaparilla"` we can see that the letter `"a"` appears four times, more than any other letter, so the mode of `"sarsaparilla"` is `"a"`. But do you know what happens w...
["from collections import Counter\n\ndef modes(data):\n cnts = Counter(data)\n mx, mn = max(cnts.values()), min(cnts.values())\n return sorted([k for k in cnts if cnts[k] == mx and cnts[k] != mn])", "def modes(data):\n frequency = {}\n mode_list = []\n \n # adds or creates a counter for each charac...
{"fn_name": "modes", "inputs": [["tomato"], [[1, 3, 3, 7]], [["redder"]]], "outputs": [[["o", "t"]], [[3]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,140
def modes(data):
df4c2a2a1c9ee1eeb18b66b98a8a75ed
UNKNOWN
A grid is a perfect starting point for many games (Chess, battleships, Candy Crush!). Making a digital chessboard I think is an interesting way of visualising how loops can work together. Your task is to write a function that takes two integers `rows` and `columns` and returns a chessboard pattern as a two dimensiona...
["def chess_board(rows, columns):\n return [[\"OX\"[(row+col)%2] for col in range(columns)] for row in range(rows)]", "def chess_board(rows, columns):\n ans=[]\n for i in range(1,rows+1,1):\n l=[]\n for j in range(i,columns+i,1):\n if j%2!=0:\n l.append('O')\n ...
{"fn_name": "chess_board", "inputs": [[1, 1], [1, 2], [2, 1], [2, 2], [6, 6]], "outputs": [[[["O"]]], [[["O", "X"]]], [[["O"], ["X"]]], [[["O", "X"], ["X", "O"]]], [[["O", "X", "O", "X", "O", "X"], ["X", "O", "X", "O", "X", "O"], ["O", "X", "O", "X", "O", "X"], ["X", "O", "X", "O", "X", "O"], ["O", "X", "O", "X", "O", ...
INTRODUCTORY
PYTHON3
CODEWARS
1,663
def chess_board(rows, columns):
44e1d424bd3f7e925f093440c49c8085
UNKNOWN
Integral numbers can be even or odd. Even numbers satisfy `n = 2m` ( with `m` also integral ) and we will ( completely arbitrarily ) think of odd numbers as `n = 2m + 1`. Now, some odd numbers can be more odd than others: when for some `n`, `m` is more odd than for another's. Recursively. :] Even numbers are just ...
["def oddest(numbers):\n most_odd = 0 # The current most odd number in the list\n max_oddity = -1 # The current greatest oddity rate, starts at -1 so that even an even number can be the unique most odd\n is_unique = True # If the current most odd number is really the most, so if there is no uniqu...
{"fn_name": "oddest", "inputs": [[[1, 2]], [[1, 3]], [[1, 5]], [[]], [[0]], [[0, 1]], [[1, 3, 5, 7]], [[2, 4]], [[-1]], [[-1, -1]], [[-1, 0, 1]], [[-3, 3]], [[-5, 3]]], "outputs": [[1], [3], [null], [null], [0], [1], [7], [null], [-1], [null], [-1], [3], [null]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,881
def oddest(a):
ff75fcd3d0a9312c4a3dc63a545ac277
UNKNOWN
# Introduction The Condi (Consecutive Digraphs) cipher was introduced by G4EGG (Wilfred Higginson) in 2011. The cipher preserves word divisions, and is simple to describe and encode, but it's surprisingly difficult to crack. # Encoding Algorithm The encoding steps are: - Start with an `initial key`, e.g. `cryptogra...
["#from string import ascii_lowercase as LOWER\nLOWER = \"abcdefghijklmnopqrstuvwxyz\"\n\ndef encode(message, key, shift, encode=True):\n key = sorted(LOWER, key=f\"{key}{LOWER}\".index)\n result = []\n for char in message:\n if char in key:\n i = key.index(char)\n char = key[(i + ...
{"fn_name": "encode", "inputs": [["on", "cryptogram", 10]], "outputs": [["jx"]]}
INTRODUCTORY
PYTHON3
CODEWARS
7,967
def encode(message, key, shift, encode=True):
f4d528f23a1b781a75f97dbbf3372056
UNKNOWN
There were and still are many problem in CW about palindrome numbers and palindrome strings. We suposse that you know which kind of numbers they are. If not, you may search about them using your favourite search engine. In this kata you will be given a positive integer, ```val``` and you have to create the function ``...
["def palindrome(n):\n s = str(n)\n return s[::-1] == s\n\ndef next_pal(val):\n val += 1\n while not palindrome(val):\n val += 1\n return val", "def next_pal(val):\n int_to_digits = lambda n: [int(d) for d in str(n)]\n digits_to_int = lambda a: int(\"\".join(map(str, a)))\n \n digits =...
{"fn_name": "next_pal", "inputs": [[11], [188], [191], [2541]], "outputs": [[22], [191], [202], [2552]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,579
def next_pal(val):
d11de4e9081ba86cd2d38f580051d1d3
UNKNOWN
Implement `String#ipv4_address?`, which should return true if given object is an IPv4 address - four numbers (0-255) separated by dots. It should only accept addresses in canonical representation, so no leading `0`s, spaces etc.
["from re import compile, match\n\nREGEX = compile(r'((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){4}$')\n\n\ndef ipv4_address(address):\n # refactored thanks to @leonoverweel on CodeWars\n return bool(match(REGEX, address + '.'))\n", "import socket\ndef ipv4_address(address):\n try: # No need to do work that'...
{"fn_name": "ipv4_address", "inputs": [[""], ["127.0.0.1"], ["0.0.0.0"], ["255.255.255.255"], ["10.20.30.40"], ["10.256.30.40"], ["10.20.030.40"], ["127.0.1"], ["127.0.0.0.1"], ["..255.255"], ["127.0.0.1\n"], ["\n127.0.0.1"], [" 127.0.0.1"], ["127.0.0.1 "], [" 127.0.0.1 "], ["127.0.0.1."], [".127.0.0.1"], ["127..0.1"]]...
INTRODUCTORY
PYTHON3
CODEWARS
2,138
def ipv4_address(address):