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
c03162f578f929da0bde5572f61c5d62
UNKNOWN
In this Kata, you will be given an array of integers and your task is to return the number of arithmetic progressions of size `3` that are possible from that list. In each progression, the differences between the elements must be the same. ``` [1, 2, 3, 5, 7, 9] ==> 5 // [1, 2, 3], [1, 3, 5], [1, 5, 9], [3, 5, 7], and...
["def solve(arr):\n return sum( y-x == z-y for i,x in enumerate(arr[:-2])\n for j,y in enumerate(arr[i+1:-1])\n for _,z in enumerate(arr[j+1:]))", "from itertools import combinations\n\ndef solve(xs):\n return sum(1 for a, b, c in combinations(xs, 3) if a - b ==...
{"fn_name": "solve", "inputs": [[[1, 2, 3, 4, 5]], [[1, 2, 3, 5, 7, 9]], [[0, 5, 8, 9, 11, 13, 14, 16, 17, 19]], [[0, 1, 2, 3, 5, 6, 7, 11, 13, 15, 17, 19]], [[0, 1, 4, 5, 7, 9, 10, 13, 15, 16, 18, 19]], [[0, 1, 2, 3, 5, 8, 11, 13, 14, 16, 18, 19]]], "outputs": [[4], [5], [10], [17], [15], [13]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,562
def solve(arr):
fef5e502719185e21c3d6fd7c7b0eb9f
UNKNOWN
I found this interesting interview question just today: > *8 coins are given where all the coins have equal weight, except one. The odd one weights less than the others, not being of pure gold. In the worst case, how many iterations are actually needed to find the odd one out on a two plates scale*. I am asking you t...
["from math import ceil, log\n\ndef how_many_measurements(n):\n return ceil(log(n, 3))", "def how_many_measurements(n):\n if n>1: \n return 1 + how_many_measurements(n/3) \n return 0", "import math\n\ndef how_many_measurements(n):\n return math.ceil(math.log(n, 3))", "from math import log, ceil\n\ndef how_...
{"fn_name": "how_many_measurements", "inputs": [[1], [2], [3], [8], [100]], "outputs": [[0], [1], [1], [2], [5]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,575
def how_many_measurements(n):
a28f0eb8865532bc006f0ea672755750
UNKNOWN
A forest fire has been spotted at *fire*, a simple 2 element array with x, y coordinates. The forest service has decided to send smoke jumpers in by plane and drop them in the forest. The terrain is dangerous and surveyors have determined that there are three possible safe *dropzones*, an array of three simple arrays...
["from math import hypot\n\ndef dropzone(fire, dropzones):\n return min(dropzones, key=lambda p: hypot(p[0]-fire[0], p[1]-fire[1]))", "def dropzone(p, dropzones):\n return min(dropzones, key=lambda q: (q[0]-p[0])**2 + (q[1]-p[1])**2)", "from scipy.spatial.distance import euclidean\ndef dropzone(p, dropzones):\n ...
{"fn_name": "dropzone", "inputs": [[[6, 8], [[3, 2], [6, 1], [7, 9]]], [[9, 2], [[1, 4], [9, 9], [5, 5]]]], "outputs": [[[7, 9]], [[5, 5]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,637
def dropzone(p, dropzones):
8f4ad5a41a685ff0e3d94ed46d5e942b
UNKNOWN
You are given an input string. For each symbol in the string if it's the first character occurrence, replace it with a '1', else replace it with the amount of times you've already seen it... But will your code be **performant enough**? ___ ## Examples: ``` input = "Hello, World!" result = "1112111121311...
["def numericals(s):\n dictio = {}\n t = \"\"\n for i in s:\n dictio[i] = dictio.get(i,0) + 1 \n t += str(dictio[i])\n return t", "from collections import defaultdict\n\ndef numericals(s):\n d, lst = defaultdict(int), []\n for c in s:\n d[c] += 1\n lst.append(d[c])\n ret...
{"fn_name": "numericals", "inputs": [["Hello, World!"], ["Hello, World! It's me, JomoPipi!"], ["hello hello"], ["Hello"], ["11111"], ["hope you 123456789 expected numbers in the string"], ["In this string, I'll make sure the amounts of a character go over 9"]], "outputs": [["1112111121311"], ["1112111121311211113122413...
INTRODUCTORY
PYTHON3
CODEWARS
2,066
def numericals(s):
25e9a688b39ce6eb555f3ca6b6f22c7e
UNKNOWN
# A History Lesson The Pony Express was a mail service operating in the US in 1859-60. It reduced the time for messages to travel between the Atlantic and Pacific coasts to about 10 days, before it was made obsolete by the [transcontinental telegraph](https://en.wikipedia.org/wiki/First_transcontinental_telegraph)...
["def riders(stations):\n riders, travelled = 1, 0\n \n for dist in stations:\n if travelled + dist > 100:\n riders += 1\n travelled = dist\n else:\n travelled += dist\n \n return riders", "def riders(stations):\n n = 1\n acc = 0\n for x in stations...
{"fn_name": "riders", "inputs": [[[18, 15]], [[43, 23, 40, 13]], [[33, 8, 16, 47, 30, 30, 46]], [[6, 24, 6, 8, 28, 8, 23, 47, 17, 29, 37, 18, 40, 49]], [[50, 50]], [[50, 50, 25, 50, 24]], [[50, 50, 25, 50, 25]], [[50, 50, 25, 50, 26]], [[90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90...
INTRODUCTORY
PYTHON3
CODEWARS
1,876
def riders(stations):
bc4207381111485bf1c7969ce9785d89
UNKNOWN
Some integral numbers are odd. All are more odd, or less odd, than others. 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. Re...
["def oddity(n):\n while True:\n n, m = divmod(n, 2)\n yield m \n\ndef oddest(arr):\n res = arr[0]\n for n in arr[1:]:\n if next(b > a for a, b in zip(oddity(res), oddity(n)) if a != b):\n res = n\n return res", "from functools import cmp_to_key\n\ndef comp(x, y):\n ...
{"fn_name": "oddest", "inputs": [[[1, 2]], [[1, 3]], [[1, 5]], [[0]], [[1, 3, 5, 7]], [[2, 4]], [[-1]], [[-1, 0, 1]], [[-3, 3]], [[-5, 3]], [[-42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -...
INTRODUCTORY
PYTHON3
CODEWARS
1,429
def oddest(a):
7c39c3f6c3eba07446fdeb117302ffe9
UNKNOWN
*Translations appreciated* ## Background information The Hamming Code is used to correct errors, so-called bit flips, in data transmissions. Later in the description follows a detailed explanation of how it works. In this Kata we will implement the Hamming Code with bit length 3, this has some advantages and disadvan...
["def encode(stg):\n return \"\".join(digit * 3 for char in stg for digit in f\"{ord(char):08b}\")\n\n\ndef decode(binary):\n reduced = (get_digit(triplet) for triplet in chunks(binary, 3))\n return \"\".join(get_char(byte) for byte in chunks(\"\".join(reduced), 8))\n\n\ndef chunks(seq, size):\n return (seq...
{"fn_name": "encode", "inputs": [["hey"], ["The Sensei told me that i can do this kata"], ["T3st"], ["T?st!%"]], "outputs": [["000111111000111000000000000111111000000111000111000111111111111000000111"], ["0001110001110001110000000001111110001110000000000001111110000001110001110000001110000000000000000001110001110000001...
INTRODUCTORY
PYTHON3
CODEWARS
5,031
def encode(string):
19bbf036b2d2936c75ba517f4d79a541
UNKNOWN
Write a function `getDrinkByProfession`/`get_drink_by_profession()` that receives as input parameter a string, and produces outputs according to the following table: Input Output "Jabroni" "Patron Tequila" "School Counselor" "Anything with Alcohol"  "Programmer"  "Hipster Craft Beer"  "Bike Gang Member" "Mo...
["d = {\n \"jabroni\": \"Patron Tequila\",\n \"school counselor\": \"Anything with Alcohol\",\n \"programmer\": \"Hipster Craft Beer\",\n \"bike gang member\": \"Moonshine\",\n \"politician\": \"Your tax dollars\",\n \"rapper\": \"Cristal\"\n}\n\ndef get_drink_by_profession(s):\n return d.get(s.low...
{"fn_name": "get_drink_by_profession", "inputs": [["jabrOni"], ["scHOOl counselor"], ["prOgramMer"], ["bike ganG member"], ["poLiTiCian"], ["rapper"], ["pundit"], ["Pug"], ["jabrOnI"], ["scHOOl COUnselor"], ["prOgramMeR"], ["bike GanG member"], ["poLiTiCiAN"], ["RAPPer"], ["punDIT"], ["pUg"]], "outputs": [["Patron Tequ...
INTRODUCTORY
PYTHON3
CODEWARS
17,781
def get_drink_by_profession(param):
aef46d685b58770d54f7d463f0fd06d3
UNKNOWN
# Your Task You have a cuboid with dimensions x,y,z ∈ ℕ. A subcuboid of this cuboid has dimensions length, width, height ∈ ℕ where 1≤length≤x, 1≤width≤y, 1≤height≤z. If two subcuboids have the same length, width, and height, but they are at different positions within the cuboid, they are distinct. Find the total number...
["def subcuboids(x,y,z):\n return x*y*z*(x+1)*(y+1)*(z+1)//8", "def n(x):\n return x * (x+1) // 2\n\ndef subcuboids(x, y, z):\n return n(x) * n(y) * n(z)", "def subcuboids(x,y,z):\n return (x*(x+1)//2)*(y*(y+1)//2)*(z*(z+1)//2)", "def subcuboids(x,y,z):\n return (x + 1) * (y + 1) * (z + 1) * x * y * z //...
{"fn_name": "subcuboids", "inputs": [[1, 1, 1], [2, 2, 2], [2, 3, 3], [4, 5, 6], [3, 7, 11]], "outputs": [[1], [27], [108], [3150], [11088]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,624
def subcuboids(x,y,z):
97c6afd882b5197a647605606366d8d9
UNKNOWN
Coffee Vending Machine Problems [Part 1] You have a vending machine, but it can not give the change back. You decide to implement this functionality. First of all, you need to know the minimum number of coins for this operation (i'm sure you don't want to return 100 pennys instead of 1$ coin). So, find an optimal numb...
["from functools import lru_cache\n\n\ndef optimal_number_of_coins(n, coins):\n @lru_cache(maxsize=None)\n def f(amount: int, idx: int) -> float:\n q, r = divmod(amount, coins[idx])\n if r == 0:\n return q\n elif amount < 0 or idx <= 0:\n return float(\"inf\")\n e...
{"fn_name": "optimal_number_of_coins", "inputs": [[1, [1, 2, 5, 10]], [5, [1, 2, 5, 10]], [6, [1, 3, 5, 10]], [10, [1, 2, 5, 10]], [12, [1, 3, 5, 10]], [53, [1, 2, 5, 25]], [7, [1, 1, 1, 25]], [76, [1, 3, 4, 10]], [33, [1, 6, 9, 10]], [63, [1, 2, 9, 10]], [239, [1, 2, 3, 10]], [333, [1, 1, 5, 25]], [543, [1, 3, 5, 25]]...
INTRODUCTORY
PYTHON3
CODEWARS
3,764
def optimal_number_of_coins(n, coins):
badae27071cf5485bb39434530fd3eb3
UNKNOWN
In this kata you need to create a function that takes a 2D array/list of non-negative integer pairs and returns the sum of all the "saving" that you can have getting the [LCM](https://en.wikipedia.org/wiki/Least_common_multiple) of each couple of number compared to their simple product. For example, if you are given: ...
["from fractions import gcd\n\ndef sum_differences_between_products_and_LCMs(pairs):\n return sum(a*b - a*b//gcd(a,b) for a, b in pairs if a and b)", "from fractions import gcd\n\ndef lcm(x, y):\n return x * y / gcd(x, y) if gcd(x, y) else 0\n \ndef sum_differences_between_products_and_LCMs(pairs):\n return...
{"fn_name": "sum_differences_between_products_and_LCMs", "inputs": [[[[15, 18], [4, 5], [12, 60]]], [[[1, 1], [0, 0], [13, 91]]], [[[15, 7], [4, 5], [19, 60]]], [[[20, 50], [10, 10], [50, 20]]], [[]]], "outputs": [[840], [1092], [0], [1890], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,843
def sum_differences_between_products_and_LCMs(pairs):
1e80517cb439c9618f072302860e3716
UNKNOWN
You are given an array of non-negative integers, your task is to complete the series from 0 to the highest number in the array. If the numbers in the sequence provided are not in order you should order them, but if a value repeats, then you must return a sequence with only one item, and the value of that item must be ...
["def complete_series(a):\n return list(range(max(a) + 1)) if len(a) == len(set(a)) else [0]", "def complete_series(seq): \n from collections import Counter\n if Counter(seq).most_common()[0][1] > 1:\n return [0]\n return [i for i in range(max(seq)+1)]", "def complete_series(seq): \n return [0] if...
{"fn_name": "complete_series", "inputs": [[[0, 1]], [[1, 4, 6]], [[3, 4, 5]], [[2, 1]], [[1, 4, 4, 6]]], "outputs": [[[0, 1]], [[0, 1, 2, 3, 4, 5, 6]], [[0, 1, 2, 3, 4, 5]], [[0, 1, 2]], [[0]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,237
def complete_series(seq):
6bb63b8ed38c4fa7a7097b47ef648034
UNKNOWN
Complete the function which takes two arguments and returns all numbers which are divisible by the given divisor. First argument is an array of `numbers` and the second is the `divisor`. ## Example ```python divisible_by([1, 2, 3, 4, 5, 6], 2) == [2, 4, 6] ```
["def divisible_by(numbers, divisor):\n return [x for x in numbers if x%divisor == 0]", "def divisible_by(numbers, divisor):\n return [i for i in numbers if i%divisor == 0]", "def divisible_by(numbers, divisor):\n return [n for n in numbers if n%divisor==0]", "def divisible_by(numbers, divisor):\n div_by = ...
{"fn_name": "divisible_by", "inputs": [[[1, 2, 3, 4, 5, 6], 2], [[1, 2, 3, 4, 5, 6], 3], [[0, 1, 2, 3, 4, 5, 6], 4], [[0], 4], [[1, 3, 5], 2], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1]], "outputs": [[[2, 4, 6]], [[3, 6]], [[0, 4]], [[0]], [[]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]]}
INTRODUCTORY
PYTHON3
CODEWARS
14,464
def divisible_by(numbers, divisor):
67aba86602bd94292ac6033580a3210b
UNKNOWN
Given a string, swap the case for each of the letters. e.g. CodEwArs --> cODeWaRS ### Examples ``` "" -> "" "CodeWars" -> "cODEwARS" "abc" -> "ABC" "ABC" -> "abc" "123235" -> "123235" ```
["def swap(string_):\n return string_.swapcase()", "swap = str.swapcase", "swap = lambda s: \"\".join([c.lower() if c.isupper() else c.upper() for c in s])", "swap = lambda s : s.swapcase() ", "def swap(s):\n '''\nSalvador Dali - The Persistence of Memory\n ;!>,!!!>\n <! ;!!!`\n !! `!!!.\n !!`...
{"fn_name": "swap", "inputs": [["HelloWorld"], ["CodeWars"], ["ThIs iS A l0NG sENTence witH nUMbERs in IT 123 456"], [""], [" "], [" "], [" 1a1 "], ["H_E_l-l_0 WO|||Rld"], ["TeSt"], ["EeEEeeEEEeee"]], "outputs": [["hELLOwORLD"], ["cODEwARS"], ["tHiS Is a L0ng SentENCE WITh NumBerS IN it 123 456"], [""], [" "], [" "],...
INTRODUCTORY
PYTHON3
CODEWARS
6,701
def swap(string_):
cc3a8599f2a424dc87c57e6efe4c5adf
UNKNOWN
Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 positive integers. No floats or non-positive integers will be passed. For example, when an array is passed like `[19, 5, 42, 2, 77]`, the output should be `7`. `[10, 343445353, 3453445, 3453545353453]` should return ...
["def sum_two_smallest_numbers(numbers):\n return sum(sorted(numbers)[:2])", "def sum_two_smallest_numbers(num_list):\n num_list.sort()\n return num_list[0] + num_list[1]", "def sum_two_smallest_numbers(numbers):\n smallest1 = None\n smallest2 = None \n for n in numbers: \n if not smallest1 or ...
{"fn_name": "sum_two_smallest_numbers", "inputs": [[[5, 8, 12, 18, 22]], [[7, 15, 12, 18, 22]], [[25, 42, 12, 18, 22]], [[1, 8, 12, 18, 5]], [[13, 12, 5, 61, 22]]], "outputs": [[13], [19], [30], [6], [17]]}
INTRODUCTORY
PYTHON3
CODEWARS
10,131
def sum_two_smallest_numbers(numbers):
88e3b7e91b2427c65e801f20861ab2db
UNKNOWN
We have 3 equations with 3 unknowns x, y, and z and we are to solve for these unknowns. Equations 4x -3y +z = -10, 2x +y +3z = 0, and -x +2y -5z = 17 will be passed in as an array of [[4, -3, 1, -10], [2, 1, 3, 0], [-1, 2, -5, 17]] and the result should be returned as an array like [1, 4, -2] (i.e. [x, y, z]). Note: I...
["import numpy as np\n\ndef solve_eq(eq):\n a = np.array([arr[:3] for arr in eq])\n b = np.array([arr[-1] for arr in eq])\n return [round(x) for x in np.linalg.solve(a,b)]", "import numpy as np\n\ndef solve_eq(eq):\n m = np.array(eq)\n return np.linalg.solve(m[:,:3], m[:,3]).round().astype(int).tolist()"...
{"fn_name": "solve_eq", "inputs": [[[[4, -3, 1, -10], [2, 1, 3, 0], [-1, 2, -5, 17]]], [[[2, 1, 3, 10], [-3, -2, 7, 5], [3, 3, -4, 7]]], [[[3, 2, 0, 7], [-4, 0, 3, -6], [0, -2, -6, -10]]], [[[4, 2, -5, -21], [2, -2, 1, 7], [4, 3, -1, -1]]]], "outputs": [[[1, 4, -2]], [[-1, 6, 2]], [[3, -1, 2]], [[1, 0, 5]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,019
def solve_eq(eq):
14465a2fc8272e7d40c2017b3b6559e3
UNKNOWN
Given a string of words and numbers. Extract the expression including: 1. the operator: either addition or subtraction 2. the two numbers that we are operating on Return the result of the calculation. Example: "Panda has 48 apples and loses 4" returns 44 "Jerry has 34 apples and gains 6" returns 40 "loses" and "g...
["def calculate(s):\n x=[int(i) for i in s.split() if i.isdigit()]\n return sum(x) if 'gains' in s.split() else x[0]-x[1]", "import re\ndef calculate(string):\n x,y=re.findall('\\d+',string)\n if re.search('loses', string): s= int(x)-int(y)\n if re.search('gains', string): s= int(x)+int(y)\n return s"...
{"fn_name": "calculate", "inputs": [["Panda has 48 apples and loses 4"], ["Jerry has 34 apples and gains 6"], ["Tom has 20 apples and gains 15"], ["Fred has 110 bananas and loses 50"], ["Pippi has 20 tunas and gains 0"]], "outputs": [[44], [40], [35], [60], [20]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,918
def calculate(string):
1ea2dc687b4418d285fb3d2b9b4201f6
UNKNOWN
Define two functions: `hex_to_bin` and `bin_to_hex` (or `hexToBin` and `binToHex`) # hex_to_bin Takes a hexadecimal string as an argument . **Note:** This string can contain upper or lower case characters and start with any amount of zeros. Returns the binary representation (without leading zeros) of the numerical...
["bin2hex = {\"0000\": \"0\", \"0001\": \"1\", \"0010\": \"2\", \"0011\": \"3\", \n \"0100\": \"4\", \"0101\": \"5\", \"0110\": \"6\", \"0111\": \"7\", \n \"1000\": \"8\", \"1001\": \"9\", \"1010\": \"a\", \"1011\": \"b\", \n \"1100\": \"c\", \"1101\": \"d\", \"1110\": \"e\", \"1111\": \"f...
{"fn_name": "bin_to_hex", "inputs": [["000101"], ["001111"], ["000"], ["10011010010"]], "outputs": [["5"], ["f"], ["0"], ["4d2"]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,766
def bin_to_hex(binary_string):
c0c04b7848fe717e79b4003cc3c6c58c
UNKNOWN
You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle 2 characters. #Examples: ~~~if-not:bf ``` Kata.getMiddle("test") should return "es" Kata.getMiddle("testing") should retur...
["def get_middle(s):\n return s[(len(s)-1)//2:len(s)//2+1]\n", "def get_middle(s):\n index, odd = divmod(len(s), 2)\n return s[index] if odd else s[index - 1:index + 1]\n", "import math\ndef get_middle(s):\n #your code here\n x = len(s)\n y = int(x/2)\n if x%2==0:\n return s[y-1:y+1]\n els...
{"fn_name": "get_middle", "inputs": [["test"], ["testing"], ["middle"], ["A"], ["of"]], "outputs": [["es"], ["t"], ["dd"], ["A"], ["of"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,013
def get_middle(s):
26c2305c5340b87dc3224c13945cd8b1
UNKNOWN
Laura Bassi was the first female professor at a European university. Despite her immense intellect, she was not always allowed to lecture publicly. One day a professor with very strong beliefs against women in academia sent some `agents` to find Bassi and end her career. Help her escape by telling her the safest pl...
["def advice(agents, n):\n frontier = { (x,y) for x,y in agents if 0<=x<n and 0<=y<n }\n bag = { (x,y) for x in range(n) for y in range(n)}\n if frontier==bag: return []\n while frontier and bag>frontier:\n bag -= frontier\n frontier = {pos for x,y in frontier for pos in ((x+1,y),(x-1,y),(x,y+...
{"fn_name": "advice", "inputs": [[[[1, 1]], 2], [[[1, 1]], 0], [[[9, 9]], 1], [[[0, 0]], 10]], "outputs": [[[[0, 0]]], [[]], [[[0, 0]]], [[[9, 9]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,754
def advice(agents, n):
01430be7200afae3431bae8eb90fa91d
UNKNOWN
Given a natural number n, we want to know in how many ways we may express these numbers as product of other numbers. For example the number ```python 18 = 2 x 9 = 3 x 6 = 2 x 3 x 3 # (we do not consider the product 18 x 1), (3 ways) ``` See this example a bit more complicated, ```python 60 = 2 x 30 = 3 x 20 = 4 x ...
["def prod_int_part(n, min_=2):\n total, fac = 0, []\n for d in range(min_, int(n ** .5) + 1):\n if not n % d:\n count, sub = prod_int_part(n // d, d)\n total += count + 1\n if not count: sub = [n // d]\n if not fac: fac = [d] + sub\n return [total, fac]", "de...
{"fn_name": "prod_int_part", "inputs": [[18], [60], [54], [37], [61]], "outputs": [[[3, [2, 3, 3]]], [[10, [2, 2, 3, 5]]], [[6, [2, 3, 3, 3]]], [[0, []]], [[0, []]]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,798
def prod_int_part(n):
7186fe94141fcd5d22ebc21303751941
UNKNOWN
You have to build a pyramid. This pyramid should be built from characters from a given string. You have to create the code for these four methods: ```python watch_pyramid_from_the_side(characters): watch_pyramid_from_above(characters): count_visible_characters_of_the_pyramid(characters): count_all_characters_of_th...
["def watch_pyramid_from_the_side(characters):\n if not characters : return characters\n baseLen = len(characters)*2-1\n return '\\n'.join( ' '*(i) + characters[i]*(baseLen-2*i) + ' '*(i) for i in range(len(characters)-1,-1,-1) )\n\n\ndef watch_pyramid_from_above(characters):\n if not characters : return ch...
{"fn_name": "watch_pyramid_from_the_side", "inputs": [[null], [""]], "outputs": [[null], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
8,665
def watch_pyramid_from_the_side(characters):
0a7331f8dae49f1db55fd636146fa9b7
UNKNOWN
Your task is to write function which takes string and list of delimiters as an input and returns list of strings/characters after splitting given string. Example: ```python multiple_split('Hi, how are you?', [' ']) => ['Hi,', 'how', 'are', 'you?'] multiple_split('1+2-3', ['+', '-']) => ['1', '2', '3'] ``` List of del...
["def multiple_split(string, delimiters=[]):\n for d in delimiters:\n string = string.replace(d, '###')\n return [s for s in string.split('###') if s]", "def multiple_split(s, d=[]):\n for i in d:\n s = s.replace(i, '___')\n return [x for x in s.split('___') if x]", "def multiple_split(s, deli...
{"fn_name": "multiple_split", "inputs": [["Hi everybody!", [" ", "!"]], ["(1+2)*6-3^9", ["+", "-", "(", ")", "^", "*"]], ["Solve_this|kata-very\\quickly!", ["!", "|", "\\", "_", "-"]], ["", []], [""], ["some strange string"], ["1_2_3_huhuh_hahaha", ["_"]], ["((1+2))*(6-3)^9", ["+", "-", "(", ")", "^", "*"]], ["(((1+2)-...
INTRODUCTORY
PYTHON3
CODEWARS
1,363
def multiple_split(string, delimiters=[]):
39c6efd8d4baeb355e9012f55abed67f
UNKNOWN
# Task Given an array of 2^(k) integers (for some integer `k`), perform the following operations until the array contains only one element: ``` On the 1st, 3rd, 5th, etc. iterations (1-based) replace each pair of consecutive elements with their sum; On the 2nd, 4th, 6th, etc. iterations replace each pair of consecut...
["def array_conversion(arr):\n sign = 0\n while len(arr) > 1:\n sign = 1^sign\n arr = list(map(lambda x, y: x+y, arr[0::2],arr[1::2]) if sign else map(lambda x, y: x*y, arr[0::2],arr[1::2]))\n return arr[0]", "array_conversion=c=lambda a,p=0:a[1:]and c([[x+y,x*y][p]for x,y in zip(*[iter(a)]*2)],1...
{"fn_name": "array_conversion", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[3, 3, 5, 5]]], "outputs": [[186], [64], [60]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,989
def array_conversion(arr):
19b4a225f1e1c3da625f4a02fd12a612
UNKNOWN
Write a function that calculates the original product price, without VAT. ## Example If a product price is `200.00` and VAT is `15%`, then the final product price (with VAT) is: `200.00 + 15% = 230.00` Thus, if your function receives `230.00` as input, it should return `200.00` **Notes:** * VAT is *always* `15%` f...
["def excluding_vat_price(price):\n try:\n return round(price / 1.15, 2)\n except TypeError:\n return -1", "def excluding_vat_price(price):\n return round(price / 1.15, 2) if price else -1", "excluding_vat_price = lambda p: round(p/115*100, 2) if p else -1", "def excluding_vat_price(price, vat=15...
{"fn_name": "excluding_vat_price", "inputs": [[230.0], [123], [777], [460.0], [null]], "outputs": [[200.0], [106.96], [675.65], [400.0], [-1]]}
INTRODUCTORY
PYTHON3
CODEWARS
12,246
def excluding_vat_price(price):
5b04be47f9f5df8f55a7781c9001f6af
UNKNOWN
Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words (that don't contain WUB). To make the dubstep remix of this so...
["def song_decoder(song):\n return \" \".join(song.replace('WUB', ' ').split())", "def song_decoder(song):\n return \" \".join(song.replace('WUB', ' ').split()).strip()\n", "def song_decoder(song):\n import re\n return re.sub('(WUB)+', ' ', song).strip()\n", "def song_decoder(song):\n return ' '.join([a ...
{"fn_name": "song_decoder", "inputs": [["AWUBBWUBC"], ["AWUBWUBWUBBWUBWUBWUBC"], ["WUBAWUBBWUBCWUB"], ["RWUBWUBWUBLWUB"], ["WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB"], ["WUBKSDHEMIXUJWUBWUBRWUBWUBWUBSWUBWUBWUBHWUBWUBWUB"], ["QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH"], ["WUBWUBOWUBWUBWUBIPVCQAFWYWUBWUBWUBQWUBWUBWU...
INTRODUCTORY
PYTHON3
CODEWARS
1,751
def song_decoder(song):
ebc267f593c94c9e057b438384e9eeff
UNKNOWN
This time no story, no theory. The examples below show you how to write function `accum`: **Examples:** ``` accum("abcd") -> "A-Bb-Ccc-Dddd" accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy" accum("cwAt") -> "C-Ww-Aaa-Tttt" ``` The parameter of accum is a string which includes only letters from `a..z` and `A.....
["def accum(s):\n return '-'.join(c.upper() + c.lower() * i for i, c in enumerate(s))", "def accum(s):\n return '-'.join((a * i).title() for i, a in enumerate(s, 1))\n", "def accum(s):\n output = \"\"\n for i in range(len(s)):\n output+=(s[i]*(i+1))+\"-\"\n return output.title()[:-1]", "def accum(...
{"fn_name": "accum", "inputs": [["ZpglnRxqenU"], ["NyffsGeyylB"], ["MjtkuBovqrU"], ["EvidjUnokmM"], ["HbideVbxncC"], ["VwhvtHtrxfE"], ["KurgiKmkphY"], ["NctlfBlnmfH"], ["WegunHvbdmV"], ["VoywwSpqidE"], ["VbaixFpxdcO"], ["OlyqvYwkuzF"], ["JrhfdMtchiH"], ["JiwpcSwslvW"], ["EagpiEvmabJ"], ["RznlcEmuxxP"], ["OrggaExarzP"],...
INTRODUCTORY
PYTHON3
CODEWARS
1,263
def accum(s):
7e6138617fd62b22e2dcf6bc32635b81
UNKNOWN
The numbers 12, 63 and 119 have something in common related with their divisors and their prime factors, let's see it. ``` Numbers PrimeFactorsSum(pfs) DivisorsSum(ds) Is ds divisible by pfs 12 2 + 2 + 3 = 7 1 + 2 + 3 + 4 + 6 + 12 = 28 28 / 7 = 4, Yes 63 3 + 3 + 7...
["from bisect import bisect_left\n\na = [12, 15, 35, 42, 60, 63, 66, 68, 84, 90, 95, 110, 114, 119, 140, 143, 152, 168, 189, 195, 204, 209, 216, 234, 245, 258, 264, 270, 280, 287, 290, 294, 297, 319, 322, 323, 352, 368, 377, 380, 384, 396, 470, 476, 480, 506, 510, 527, 531, 544, 552, 558, 559, 572, 588, 616, 621, 693, ...
{"fn_name": "ds_multof_pfs", "inputs": [[10, 100], [20, 120], [50, 140]], "outputs": [[[12, 15, 35, 42, 60, 63, 66, 68, 84, 90, 95]], [[35, 42, 60, 63, 66, 68, 84, 90, 95, 110, 114, 119]], [[60, 63, 66, 68, 84, 90, 95, 110, 114, 119, 140]]]}
INTRODUCTORY
PYTHON3
CODEWARS
7,289
def ds_multof_pfs(n_min, n_max):
4c6ecda0ae9aa72aa130fe3b68437cae
UNKNOWN
We need a function ```count_sel()``` that receives an array or list of integers (positive and negative) and may give us the following information in the order and structure presented bellow: ```[(1), (2), (3), [[(4)], 5]]``` (1) - Total amount of received integers. (2) - Total amount of different values the array h...
["from collections import defaultdict, Counter\n\n\ndef count_sel(nums):\n cnt = Counter(nums)\n d = defaultdict(list)\n total = 0\n unique = 0\n for k, v in cnt.items():\n d[v].append(k)\n total += v\n unique += 1\n maximum = max(d)\n return [total, unique, len(d[1]), [sorted(...
{"fn_name": "count_sel", "inputs": [[[-3, -2, -1, 3, 4, -5, -5, 5, -1, -5]], [[5, -1, 1, -1, -2, 5, 0, -2, -5, 3]], [[-2, 4, 4, -2, -2, -1, 3, 5, -5, 5]], [[4, -5, 1, -5, 2, 4, -1, 4, -1, 1]], [[4, 4, 2, -3, 1, 4, 3, 2, 0, -5, 2, -2, -2, -5]]], "outputs": [[[10, 7, 5, [[-5], 3]]], [[10, 7, 4, [[-2, -1, 5], 2]]], [[10, ...
INTRODUCTORY
PYTHON3
CODEWARS
3,292
def count_sel(lst):
389d32962484507ee44c8292f35764c4
UNKNOWN
Ask a small girl - "How old are you?". She always says strange things... Lets help her! For correct answer program should return int from 0 to 9. Assume test input string always valid and may look like "1 year old" or "5 years old", etc.. The first char is number only.
["def get_age(age):\n return int(age[0])", "import re\n\ndef get_age(age):\n return int(re.search(r\"\\d+\", age).group())", "def get_age(age):\n for x in age:\n if x.isdigit():\n return int(x) \n", "def get_age(age):\n return int(age.split()[0])", "def get_age(age):\n #your code here\n...
{"fn_name": "get_age", "inputs": [["1 year old"], ["2 years old"], ["3 years old"], ["4 years old"], ["5 years old"], ["6 years old"], ["7 years old"], ["8 years old"], ["9 years old"]], "outputs": [[1], [2], [3], [4], [5], [6], [7], [8], [9]]}
INTRODUCTORY
PYTHON3
CODEWARS
10,708
def get_age(age):
523dccb5c766675c07dd445f2f0025a4
UNKNOWN
The number ```12``` is the first number in having six divisors, they are: ```1, 2, 3, 4, 6 and 12.``` Your challenge for this kata is to find the minimum number that has a certain number of divisors. For this purpose we have to create the function ```find_min_num() or findMinNum() or similar in the other languages```...
["def find_min_num(d, n=1):\n while div_num(n) != d:\n n += 1\n return n\n\ndef div_num(n):\n s = n**0.5\n return sum(2 for k in range(1, int(s)+1) if n % k == 0) - (s % 1 == 0)", "from collections import Counter\n\ndef number_of_div(n):\n i = 2\n factors = []\n while i * i <= n:\n if...
{"fn_name": "find_min_num", "inputs": [[6], [10], [12], [13]], "outputs": [[12], [48], [60], [4096]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,044
def find_min_num(d, n=1):
b1252265ae34e3fca433d6081405f1c8
UNKNOWN
Your job is to write function last_digits(n,d) which return the last `d` digits of an integer `n` as a list. `n` will be from 0 to 10^10 Examples: `last_digits(1,1) --> [1]` `last_digits(1234,2) --> [3,4]` `last_digits(637547,6) --> [6,3,7,5,4,7]` Special cases: If `d` > the number of digits, just return th...
["def solution(n, d):\n return [int(c) for c in str(n)[-d:]] if d > 0 else []", "def solution(n,d):\n s = str(n)\n return list(map(int,s))[-d if d>0 else len(s):]", "def solution(n,d):\n if d <= 0:\n return []\n else:\n return ([int(i) for i in str(n)][-d:])", "def solution(n,d):\n retur...
{"fn_name": "solution", "inputs": [[1, 1], [123767, 4], [0, 1], [34625647867585, 10], [1234, 0], [24134, -4], [1343, 5]], "outputs": [[[1]], [[3, 7, 6, 7]], [[0]], [[5, 6, 4, 7, 8, 6, 7, 5, 8, 5]], [[]], [[]], [[1, 3, 4, 3]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,182
def solution(n,d):
6a773e4fb491de34813c2be4203b47b2
UNKNOWN
Here you will create the classic [Pascal's triangle](https://en.wikipedia.org/wiki/Pascal%27s_triangle). Your function will be passed the depth of the triangle and you code has to return the corresponding pascal triangle up to that depth. The triangle should be returned as a nested array. for example: ```python pasca...
["def pascal(p):\n triangle = [[1]]\n for _ in range(p - 1):\n to_sum = list(zip([0] + triangle[-1], triangle[-1] + [0]))\n triangle.append(list(map(sum, to_sum)))\n return triangle\n", "def pascal(p):\n def create_row(n):\n row = [1]\n for k in range(n):\n row.append(...
{"fn_name": "pascal", "inputs": [[1], [5], [10]], "outputs": [[[[1]]], [[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]], [[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1], [1, 6, 15, 20, 15, 6, 1], [1, 7, 21, 35, 35, 21, 7, 1], [1, 8, 28, 56, 70, 56, 28, 8, 1], [1, 9, 36, 84, 126, 1...
INTRODUCTORY
PYTHON3
CODEWARS
1,861
def pascal(p):
6e0ca89ec07258760af7fb09afeb5159
UNKNOWN
A `bouncy number` is a positive integer whose digits neither increase nor decrease. For example, 1235 is an increasing number, 5321 is a decreasing number, and 2351 is a bouncy number. By definition, all numbers under 100 are non-bouncy, and 101 is the first bouncy number. Determining if a number is bouncy is easy, bu...
["def bouncy_count(m):\n num = den = 1\n for i in range(1, 11):\n num *= m + i + i * (i == 10)\n den *= i\n return 10 ** m - num // den + 10 * m + 1", "def bouncy_count(n):\n k = m = 1\n for i in range(1, 11):\n k *= n + i*(1+(i == 10))\n m *= i\n return 10*(10**(n-1)+n)- k...
{"fn_name": "bouncy_count", "inputs": [[0], [1], [2], [3], [4], [5], [6], [10], [20], [50]], "outputs": [[0], [0], [0], [525], [8325], [95046], [987048], [9999722967], [99999999999959940181], [99999999999999999999999999999999999999912040301674]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,991
def bouncy_count(n):
a25557f926a1abbb3f328925e1179ab4
UNKNOWN
In this kata, the number 0 is infected. You are given a list. Every turn, any item in the list that is adjacent to a 0 becomes infected and transforms into a 0. How many turns will it take for the whole list to become infected? ``` [0,1,1,0] ==> [0,0,0,0] All infected in 1 turn. [1,1,0,1,1] --> [1,0,0,0,1] --> [0,0,...
["def infected_zeroes(s):\n m=0; l=0\n for i,n in enumerate(s):\n if n==0: m=i if l==0 else max(m, (i-l+1)//2); l=i+1\n return max(m,len(s)-l)", "def infected_zeroes(lst):\n left, *enclosed, right = \"\".join(str(digit) for digit in lst).split(\"0\")\n return max(len(left), len(right), *((len(ones...
{"fn_name": "infected_zeroes", "inputs": [[[0]], [[0, 1, 1, 0]], [[0, 1, 1, 1, 0]], [[1, 1, 0, 1, 1]], [[0, 1, 1, 1]], [[1, 1, 1, 0]]], "outputs": [[0], [1], [2], [2], [3], [3]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,027
def infected_zeroes(lst):
a934490c52864090bedf6726cf810e2d
UNKNOWN
## **Task** Four mirrors are placed in a way that they form a rectangle with corners at coordinates `(0, 0)`, `(max_x, 0)`, `(0, max_y)`, and `(max_x, max_y)`. A light ray enters this rectangle through a hole at the position `(0, 0)` and moves at an angle of 45 degrees relative to the axes. Each time it hits one of th...
["def reflections(n, m):\n x = y = 0\n dx = dy = 1\n while 1:\n x += dx\n y += dy\n if x == y == 0 or x == n and y == m: return 1\n if 0 in (x, y) and (x == n or y == m): return 0\n if x in (0, n): dx *= -1\n if y in (0, m): dy *= -1", "from math import gcd\n\ndef refl...
{"fn_name": "reflections", "inputs": [[10, 10], [10, 20], [12, 23], [5, 25]], "outputs": [[true], [false], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,372
def reflections(max_x, max_y):
ae3eb52078df93082a175f2112eb2542
UNKNOWN
You are given a set of `n` segments on the axis `Ox`, each segment has integer endpoints between `0` and `m` inclusive.  Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers li and ri — coordinates of the left and of the right endpoints.  Consider all integer ...
["def segments(m, arr):\n return [i for i in range(m+1) if not any(a<=i<=b for a,b in arr)]", "def segments(m, a):\n vals = set(range(m+1))\n for st, en in a:\n vals -= set(range(st, en+1))\n return sorted(vals)\n", "def segments(m, a):\n return [p for p in range(m+1) if all(not x[0]<=p<=x[1] for ...
{"fn_name": "segments", "inputs": [[7, [[0, 7]]], [2, []], [0, []], [0, [[0, 0]]]], "outputs": [[[]], [[0, 1, 2]], [[0]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,778
def segments(m, a):
49c98ba3dfa87c3378ce785c8e0742d8
UNKNOWN
Your task is to create function```isDivideBy``` (or ```is_divide_by```) to check if an integer number is divisible by each out of two arguments. A few cases: ``` (-12, 2, -6) -> true (-12, 2, -5) -> false (45, 1, 6) -> false (45, 5, 15) -> true (4, 1, 4) -> true (15, -5, 3) -> true ```
["def is_divide_by(number, a, b):\n return number % a == 0 and number % b == 0", "def is_divide_by(n, a, b):\n return n%a == 0 == n%b", "def is_divide_by(number, a, b):\n return not (number%a or number%b)", "def is_divide_by(number, a, b):\n return number % a == 0 == number % b ", "def is_divide_by(number, a...
{"fn_name": "is_divide_by", "inputs": [[8, 2, 4], [12, -3, 4], [8, 3, 4], [48, 2, -5], [-100, -25, 10], [10000, 5, -3], [4, 4, 2], [5, 2, 3], [-96, 25, 17], [33, 1, 33]], "outputs": [[true], [true], [false], [false], [true], [false], [true], [false], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
14,634
def is_divide_by(number, a, b):
fee80faea80a635b208708e74161ae6a
UNKNOWN
Your task is to ___Reverse and Combine Words___. It's not too difficult, but there are some things you have to consider... ### So what to do? Input: String containing different "words" separated by spaces ``` 1. More than one word? Reverse each word and combine first with second, third with fourth and so on... (...
["from itertools import zip_longest\n\ndef reverse_and_combine_text(text):\n words = text.split(' ')\n while len(words) > 1:\n it = map(lambda w: w[::-1], words)\n words = [a + b for a, b in zip_longest(it, it, fillvalue='')]\n return words[0]", "def reverse_and_combine_text(s):\n while ' ' in...
{"fn_name": "reverse_and_combine_text", "inputs": [["abc def"], ["abc def ghi jkl"], ["dfghrtcbafed"], ["234hh54 53455 sdfqwzrt rtteetrt hjhjh lllll12 44"], ["sdfsdf wee sdffg 342234 ftt"]], "outputs": [["cbafed"], ["defabcjklghi"], ["dfghrtcbafed"], ["trzwqfdstrteettr45hh4325543544hjhjh21lllll"], ["gffds432243fdsfdse...
INTRODUCTORY
PYTHON3
CODEWARS
2,903
def reverse_and_combine_text(text):
bd2ee8aaa309c4f6538af811cc651041
UNKNOWN
The odd and even numbers are fighting against each other! You are given a list of positive integers. The odd numbers from the list will fight using their `1` bits from their binary representation, while the even numbers will fight using their `0` bits. If present in the list, number `0` will be neutral, hence not figh...
["def bits_battle(nums):\n binary = '{:b}'.format\n evens = odds = 0\n for num in nums:\n if num % 2:\n odds += binary(num).count('1')\n else:\n evens += binary(num).count('0')\n if odds == evens:\n return 'tie'\n return '{} win'.format('odds' if odds > evens el...
{"fn_name": "bits_battle", "inputs": [[[5, 3, 14]], [[3, 8, 22, 15, 78]], [[]], [[1, 13, 16]]], "outputs": [["odds win"], ["evens win"], ["tie"], ["tie"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,268
def bits_battle(numbers):
b9c2f058b7e280b5816f4a0332be3c78
UNKNOWN
The Monty Hall problem is a probability puzzle base on the American TV show "Let's Make A Deal". In this show, you would be presented with 3 doors: One with a prize behind it, and two without (represented with goats). After choosing a door, the host would open one of the other two doors which didn't include a prize, ...
["def monty_hall(door, guesses):\n return round(100.0 * (len(guesses)-guesses.count(door))/len(guesses))", "def monty_hall(c, p):\n print((c, p))\n return round((1 - (p.count(c) / len(p))) * 100)\n # Your code here!\n", "def monty_hall(correct, guesses):\n return round(sum([correct != x for x in guesses]...
{"fn_name": "monty_hall", "inputs": [[1, [1, 2, 2, 2, 3, 2, 1, 3, 1, 3]], [2, [2, 1, 2, 1, 2, 3, 1, 1, 2, 2, 3]], [3, [1, 1, 1, 2, 2, 3, 2, 2, 1, 3, 3, 2, 3, 1, 1, 2]]], "outputs": [[70], [55], [75]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,372
def monty_hall(correct_door_number, participant_guesses):
d61abd7013ed3d4636086d74f0ef9d2a
UNKNOWN
# Task You are a magician. You're going to perform a trick. You have `b` black marbles and `w` white marbles in your magic hat, and an infinite supply of black and white marbles that you can pull out of nowhere. You ask your audience to repeatedly remove a pair of marbles from your hat and, for each pair removed...
["def not_so_random(b,w):\n return ['White', 'Black'][b % 2]", "def not_so_random(b,w):\n return ('White', 'Black')[b % 2]", "def not_so_random(b,w):\n if b % 2 == 0 and w % 2 == 0:\n return \"White\"\n elif b % 2 == 1 and w % 2 == 0:\n return \"Black\"\n elif b % 2 == 1 and w % 2 == 1:\n ...
{"fn_name": "not_so_random", "inputs": [[1, 1], [2, 1], [1, 2], [2, 2], [6, 9], [10000, 10000], [11111, 22222]], "outputs": [["Black"], ["White"], ["Black"], ["White"], ["White"], ["White"], ["Black"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,340
def not_so_random(b,w):
ac13e21db049e16cd4314f54dd9f8c76
UNKNOWN
Given a string made up of letters a, b, and/or c, switch the position of letters a and b (change a to b and vice versa). Leave any incidence of c untouched. Example: 'acb' --> 'bca' 'aabacbaa' --> 'bbabcabb'
["def switcheroo(s):\n return s.translate(str.maketrans('ab','ba'))", "def switcheroo(string):\n return string.translate(str.maketrans('ab','ba'))", "def switcheroo(string):\n return ((string.replace('a','x')).replace('b','a')).replace('x','b')", "def switcheroo(string):\n #your code here\n result = ''\n...
{"fn_name": "switcheroo", "inputs": [["abc"], ["aaabcccbaaa"], ["ccccc"], ["abababababababab"], ["aaaaa"]], "outputs": [["bac"], ["bbbacccabbb"], ["ccccc"], ["babababababababa"], ["bbbbb"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,041
def switcheroo(string):
8b8b32b5ee064a75bd0170d7e5bd1295
UNKNOWN
Complete the function that takes two numbers as input, ```num``` and ```nth``` and return the `nth` digit of `num` (counting from right to left). ## Note - If ```num``` is negative, ignore its sign and treat it as a positive value - If ```nth``` is not positive, return `-1` - Keep in mind that `42 = 00042`. This means...
["def find_digit(num, nth):\n if nth <= 0:\n return -1\n try:\n return int(str(num).lstrip('-')[-nth])\n except IndexError:\n return 0", "def find_digit(num, nth):\n num = str(num)\n if nth<=0: return -1\n elif nth> len(num): return 0\n else:\n num = num[::-1]\n r...
{"fn_name": "find_digit", "inputs": [[5673, 4], [129, 2], [-2825, 3], [0, 20], [65, 0], [24, -8], [-456, 5], [-1234, 2], [-5540, 1], [678998, 0], [-67854, -57], [0, -3]], "outputs": [[5], [2], [8], [0], [-1], [-1], [0], [3], [0], [-1], [-1], [-1]]}
INTRODUCTORY
PYTHON3
CODEWARS
17,805
def find_digit(num, nth):
41b293dac0b02cbf6a261604111e7f12
UNKNOWN
## Your Job Find the sum of all multiples of `n` below `m` ## Keep in Mind * `n` and `m` are natural numbers (positive integers) * `m` is **excluded** from the multiples ## Examples
["def sum_mul(n, m):\n if m>0 and n>0:\n return sum(range(n, m, n))\n else:\n return 'INVALID'", "def sum_mul(n, m):\n return sum(x for x in range(n, m, n)) if m > 0 and n > 0 else 'INVALID'", "xrange = range\n\ndef sum_mul(n, m):\n if m <= 0 or n <= 0:\n return \"INVALID\"\n k = (m ...
{"fn_name": "sum_mul", "inputs": [[4, 123], [123, 4567], [2, 10], [2, 2], [7, 7], [7, 2], [21, 3], [0, 2], [2, 0], [4, -7], [-7, 4]], "outputs": [[1860], [86469], [20], [0], [0], [0], [0], ["INVALID"], ["INVALID"], ["INVALID"], ["INVALID"]]}
INTRODUCTORY
PYTHON3
CODEWARS
16,598
def sum_mul(n, m):
394950bd33964013ac5c23a680c12fc7
UNKNOWN
Everybody know that you passed to much time awake during night time... Your task here is to define how much coffee you need to stay awake after your night. You will have to complete a function that take an array of events in arguments, according to this list you will return the number of coffee you need to stay awake...
["cs={'cw':1,'CW':2,'cat':1,'CAT':2,'dog':1,'DOG':2,'movie':1,'MOVIE':2}\n\ndef how_much_coffee(events):\n c=sum(cs.get(e,0) for e in events)\n return 'You need extra sleep' if c>3 else c", "def how_much_coffee(events):\n activities = [\"cw\", \"cat\", \"dog\", \"movie\"]\n coffee = 0\n for e in events:\...
{"fn_name": "how_much_coffee", "inputs": [[[]], [["cw"]], [["CW"]], [["cw", "CAT"]], [["cw", "CAT", "DOG"]], [["cw", "CAT", "cw=others"]]], "outputs": [[0], [1], [2], [3], ["You need extra sleep"], [3]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,753
def how_much_coffee(events):
a8b44101f1ac446a56361005a7c2a89a
UNKNOWN
The rgb function is incomplete. Complete it so that passing in RGB decimal values will result in a hexadecimal representation being returned. Valid decimal values for RGB are 0 - 255. Any values that fall out of that range must be rounded to the closest valid value. Note: Your answer should always be 6 characters long...
["def rgb(r, g, b):\n round = lambda x: min(255, max(x, 0))\n return (\"{:02X}\" * 3).format(round(r), round(g), round(b))", "def limit(num):\n if num < 0:\n return 0\n if num > 255:\n return 255\n return num\n\n\ndef rgb(r, g, b):\n return \"{:02X}{:02X}{:02X}\".format(limit(r), limit(g...
{"fn_name": "rgb", "inputs": [[0, 0, 0], [1, 2, 3], [255, 255, 255], [254, 253, 252], [-20, 275, 125]], "outputs": [["000000"], ["010203"], ["FFFFFF"], ["FEFDFC"], ["00FF7D"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,676
def rgb(r, g, b):
1a77fd1a507438cbbb9df0c25d5be2b2
UNKNOWN
You are a *khm*mad*khm* scientist and you decided to play with electron distribution among atom's shells. You know that basic idea of electron distribution is that electrons should fill a shell untill it's holding the maximum number of electrons. --- Rules: - Maximum number of electrons in a shell is distribute...
["def atomic_number(electrons):\n result = []\n i = 1\n while electrons > 0:\n result.append(min(2 * (i ** 2), electrons))\n electrons -= result[-1]\n i += 1\n return result", "def atomic_number(electrons):\n level, shells = 1, []\n while electrons:\n shells.append(min(2 * ...
{"fn_name": "atomic_number", "inputs": [[1], [10], [11], [22], [23], [47], [50], [52], [60], [61]], "outputs": [[[1]], [[2, 8]], [[2, 8, 1]], [[2, 8, 12]], [[2, 8, 13]], [[2, 8, 18, 19]], [[2, 8, 18, 22]], [[2, 8, 18, 24]], [[2, 8, 18, 32]], [[2, 8, 18, 32, 1]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,179
def atomic_number(electrons):
15be3a6f1a0390a745edc52c66826389
UNKNOWN
### Description As hex values can include letters `A` through to `F`, certain English words can be spelled out, such as `CAFE`, `BEEF`, or `FACADE`. This vocabulary can be extended by using numbers to represent other letters, such as `5EAF00D`, or `DEC0DE5`. Given a string, your task is to return the decimal sum of al...
["def hex_word_sum(s):\n return sum(int(w, 16) for w in s.translate(str.maketrans('OS', '05')).split() if set(w) <= set('0123456789ABCDEF'))", "def hex_word_sum(string):\n sum = 0\n for word in string.upper().replace('S', '5').replace('O', '0').split(' '):\n try:\n sum += int(word.strip(), 16...
{"fn_name": "hex_word_sum", "inputs": [["DEFACE"], ["SAFE"], ["CODE"], ["BUGS"], [""], ["DO YOU SEE THAT BEE DRINKING DECAF COFFEE"], ["ASSESS ANY BAD CODE AND TRY AGAIN"]], "outputs": [[14613198], [23294], [49374], [0], [0], [13565769], [10889952]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,102
def hex_word_sum(s):
5d93bb585c8c40096b642f7ca133bac4
UNKNOWN
## Task Let's say we have a positive integer, `$n$`. You have to find the smallest possible positive integer that when multiplied by `$n$`, becomes a perfect power of integer `$k$`. A perfect power of `$k$` is any positive integer that can be represented as `$a^k$`. For example if `$k = 2$`, then `$36$` is a perfect p...
["from collections import Counter\nfrom math import ceil\n\nPRIMES = [2] + [n for n in range(3, 1000, 2) if all(n%d for d in range(3, int(n**0.5) +1, 2))]\n\ndef get_factors(n):\n factors = []\n for p in PRIMES:\n if p > n: break\n while n % p == 0:\n factors.append(p)\n n //= ...
{"fn_name": "mul_power", "inputs": [[100, 3], [36, 2], [72, 4], [5, 2], [1152, 3]], "outputs": [[10], [1], [18], [5], [12]]}
INTRODUCTORY
PYTHON3
CODEWARS
675,297
def mul_power(n, k):
145bfc3e952e6bf7e2f80c815af88c0b
UNKNOWN
# Invalid Login - Bug Fixing #11 Oh NO! Timmy has moved divisions... but now he's in the field of security. Timmy, being the top coder he is, has allowed some bad code through. You must help Timmy and filter out any injected code! ## Task Your task is simple, search the password string for any injected code (Injecte...
["def validate(username, password):\n print (username, password)\n if username == 'Timmy' and password == 'password':\n return 'Successfully Logged in!'\n elif username == 'Alice' and password == 'alice':\n return 'Successfully Logged in!'\n elif username == 'Johny' and password == 'Hf7FAbf6':...
{"fn_name": "validate", "inputs": [["Timmy", "password"], ["Timmy", "h4x0r"], ["Alice", "alice"], ["Timmy", "password\"||\"\"==\""], ["Admin", "gs5bw\"||1==1//"]], "outputs": [["Successfully Logged in!"], ["Wrong username or password!"], ["Successfully Logged in!"], ["Wrong username or password!"], ["Wrong username or ...
INTRODUCTORY
PYTHON3
CODEWARS
1,474
def validate(username, password):
c51d3d88772f74efa0daa2eb8a00f481
UNKNOWN
## Task: You have to create a function `isPronic` to check whether the argument passed is a Pronic Number and return true if it is & false otherwise. ### Description: `Pronic Number` -A pronic number, oblong number, rectangular number or heteromecic number, is a number which is the product of two consecutive integers...
["import math\ndef is_pronic(n):\n return n >= 0 and math.sqrt(1 + 4 * n) % 1 == 0", "import math\n\n\ndef is_pronic(n):\n \"\"\"Return True if given number is pronic, else False.\"\"\"\n if n == 0: return True\n if n < 0: return False\n first_int = int(math.sqrt(n))\n second_int = first_int + 1\n ...
{"fn_name": "is_pronic", "inputs": [[2], [3], [4], [5], [6], [-3], [-27]], "outputs": [[true], [false], [false], [false], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
911
def is_pronic(n):
dab3baed89df9a2f715dc804d4eaf099
UNKNOWN
```if:python Create a function `args_count`, that returns the count of passed arguments ``` ```if:kotlin Create a function `argsCount`, that returns the count of passed arguments ``` ```if:ruby Create a method `args_count`, that returns the count of passed arguments ``` ```if:julia Create a method `argscount`, that ret...
["def args_count(*args, **kwargs):\n return len(args) + len(kwargs)", "args_count=lambda*a,**b:len(a)+len(b)", "# Create a function args_count, that returns count of passed argument\ndef args_count(*args, **kwargs):\n return len(args) + len(kwargs)\n", "def args_count(*arg, **kwarg):\n return len(arg) + len(kw...
{"fn_name": "args_count", "inputs": [[100], [100, 2, 3]], "outputs": [[1], [3]]}
INTRODUCTORY
PYTHON3
CODEWARS
14,917
def args_count(*args, **kwargs):
e97e3becafd895a550fe126459fd2b2f
UNKNOWN
It's Friday night, and Chuck is bored. He's already run 1,000 miles, stopping only to eat a family sized bag of Heatwave Doritos and a large fistful of M&Ms. He just can't stop thinking about kicking something! There is only one thing for it, Chuck heads down to his local MMA gym and immediately challenges every figh...
["def head_smash(arr):\n try:\n return [a.replace('O', ' ') for a in arr] or 'Gym is empty'\n except TypeError:\n return \"This isn't the gym!!\"\n", "def head_smash(arr):\n try:\n return [x.replace('O', ' ') for x in arr] or 'Gym is empty'\n except:\n return 'This isn\\'t the gy...
{"fn_name": "head_smash", "inputs": [[["*****************************************", "** _O_ * _O_ * _O_ * _O_ **", "** /(.)J * C(.)J * /(.)J * C(.)J **", "** _| |_ * _| |_ * _( )_ * _( )_ *"]], [["*** _O_ ** _O_ ** _O_ ** _O_ ***", "*** /(.)J ** /(.)J ** C(.)J ** C(.)J ***"...
INTRODUCTORY
PYTHON3
CODEWARS
1,985
def head_smash(arr):
0464fa17067557bcc0b7ec362d51f54e
UNKNOWN
We have a set of consecutive numbers from ```1``` to ```n```. We want to count all the subsets that do not contain consecutive numbers. E.g. If our set ```S1``` is equal to ```[1,2,3,4,5]``` The subsets that fulfill these property are: ``` [1],[2],[3],[4],[5],[1,3],[1,4],[1,5],[2,4],[2,5],[3,5],[1,3,5] ``` A total of ...
["def f(n):\n a, b = 0, 1\n for _ in range(n):\n a, b = b, a + b + 1\n return a", "def f(n):\n a, b = 1, 2\n for _ in range(n):\n a, b = b, a + b\n return a - 1", "f=lambda n,a=0,b=1:f(n-1,b,a+b) if n!=-2 else a-1 ", "def f(n):\n xs = [0, 1, 2]\n for i in range(n - len(xs) + 1):\n ...
{"fn_name": "f", "inputs": [[5], [3], [2], [20]], "outputs": [[12], [4], [2], [17710]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,022
def f(n):
3749c4bad10cacf046f4917e4ce5e96e
UNKNOWN
Reducing Problems - Bug Fixing #8 Oh no! Timmy's reduce is causing problems, Timmy's goal is to calculate the two teams scores and return the winner but timmy has gotten confused and sometimes teams don't enter their scores, total the scores out of 3! Help timmy fix his program! Return true if team 1 wins or false if...
["def calculate_total(team1, team2):\n return sum(team1) > sum(team2)", "def calculate_total(t1, t2):\n return sum(t1) > sum(t2)", "def calculate_total(t1, t2):\n if sum(t1) > sum(t2):\n return True\n else:\n return False", "def calculate_total(t1s, t2s):\n return sum(t1s) > sum(t2s)", "def...
{"fn_name": "calculate_total", "inputs": [[[1, 2, 2], [1, 0, 0]], [[6, 45, 1], [1, 55, 0]], [[57, 2, 1], []], [[], [3, 4, 3]], [[], []]], "outputs": [[true], [false], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
592
def calculate_total(t1, t2):
0543dbe03273313a55427f678df1388b
UNKNOWN
Let's say we have a number, `num`. Find the number of values of `n` such that: there exists `n` consecutive **positive** values that sum up to `num`. A positive number is `> 0`. `n` can also be 1. ```python #Examples num = 1 #1 return 1 num = 15 #15, (7, 8), (4, 5, 6), (1, 2, 3, 4, 5) return 4 num = 48 #48, (15, 16,...
["def consecutive_sum(num):\n upper_limit = 1\n while True:\n if upper_limit * (upper_limit + 1) // 2 > num:\n break\n upper_limit += 1\n return sum([1 if i % 2 and not num % i else 1 if not i % 2 and num % i == i//2 else 0 for i in range(1, upper_limit)])", "from math import sqrt\ndef...
{"fn_name": "consecutive_sum", "inputs": [[1], [15], [48], [97]], "outputs": [[1], [4], [2], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,411
def consecutive_sum(num):
babb7e803107b633332a85745be37458
UNKNOWN
In this Kata your task will be to return the count of pairs that have consecutive numbers as follows: ```Haskell pairs([1,2,5,8,-4,-3,7,6,5]) = 3 The pairs are selected as follows [(1,2),(5,8),(-4,-3),(7,6),5] --the first pair is (1,2) and the numbers in the pair are consecutive; Count = 1 --the second pair is (5,8) an...
["def pairs(ar):\n count = 0\n for i in range(0, len(ar), 2):\n try:\n a, b = ar[i], ar[i+1]\n except IndexError:\n return count\n \n if abs(a-b) == 1: \n count +=1\n \n return count", "def pairs(arr):\n return sum( abs(a-b)==1 for a,b in z...
{"fn_name": "pairs", "inputs": [[[1, 2, 5, 8, -4, -3, 7, 6, 5]], [[21, 20, 22, 40, 39, -56, 30, -55, 95, 94]], [[81, 44, 80, 26, 12, 27, -34, 37, -35]], [[-55, -56, -7, -6, 56, 55, 63, 62]], [[73, 72, 8, 9, 73, 72]]], "outputs": [[3], [2], [0], [4], [3]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,364
def pairs(ar):
9002c922d0fed2f0e2c297fbb3fe08e1
UNKNOWN
Complete the solution so that it takes the object (JavaScript/CoffeeScript) or hash (ruby) passed in and generates a human readable string from its key/value pairs. The format should be "KEY = VALUE". Each key/value pair should be separated by a comma except for the last pair. **Example:** ```python solution({"a": 1...
["def solution(pairs):\n return ','.join(sorted('{} = {}'.format(k, pairs[k]) for k in pairs))", "def solution(pairs):\n return ','.join(['{} = {}'.format(*a) for a in sorted(pairs.items())])", "solution=lambda d:\",\".join(\"{} = {}\".format(*p)for p in sorted(d.items()))", "def solution(pairs):\n return ','....
{"fn_name": "solution", "inputs": [[{"a": 1, "b": 2}], [{"a": "b", "b": "a"}], [{"0": "a", "b": 2}], [{"b": 1, "c": 2, "e": 3}], [{}]], "outputs": [["a = 1,b = 2"], ["a = b,b = a"], ["0 = a,b = 2"], ["b = 1,c = 2,e = 3"], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,080
def solution(pairs):
f013e7edbd938a8b78023b0e1e592043
UNKNOWN
# Task You have some people who are betting money, and they all start with the same amount of money (this number>0). Find out if the given end-state of amounts is possible after the betting is over and money is redistributed. # Input/Output - `[input]` integer array arr the proposed end-state showing final a...
["def learn_charitable_game(arr):\n return sum(arr) % len(arr) == 0 and sum(arr) > 0", "def learn_charitable_game(arr):\n t = sum(arr)\n return t and t % len(arr) == 0", "from statistics import mean\n\ndef learn_charitable_game(arr):\n m = mean(arr)\n return int(m)==m and m>0", "from statistics import mean...
{"fn_name": "learn_charitable_game", "inputs": [[[100, 100, 100, 90, 1, 0, 0]], [[0, 0, 0, 0]], [[0, 56, 100]], [[33, 19, 38, 87, 93, 4]], [[11]]], "outputs": [[false], [false], [true], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,225
def learn_charitable_game(arr):
551ca06c857ae67048e972140fc70e32
UNKNOWN
In this Kata you need to write the method SharedBits that returns true if 2 integers share at least two '1' bits. For simplicity assume that all numbers are positive For example int seven = 7; //0111 int ten = 10; //1010 int fifteen = 15; //1111 SharedBits(seven, ten); //false SharedBits(seven, fifteen); //...
["def shared_bits(a, b):\n return bin(a & b).count('1') > 1", "def shared_bits(a, b):\n return bool(a & b & (a & b) - 1)", "def shared_bits(a, b):\n num = a & b\n count = bin(num).count(\"1\")\n if count >= 2:\n return True\n return False", "def shared_bits(a, b):\n return len(bin(a&b).strip...
{"fn_name": "shared_bits", "inputs": [[1, 2], [16, 8], [1, 1], [2, 3], [7, 10], [43, 77], [7, 15], [23, 7]], "outputs": [[false], [false], [false], [false], [false], [true], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,166
def shared_bits(a, b):
66fffcd18292f63d2dc7762aeeb6c10d
UNKNOWN
# Task Given an integer `n`, find the maximal number you can obtain by deleting exactly one digit of the given number. # Example For `n = 152`, the output should be `52`; For `n = 1001`, the output should be `101`. # Input/Output - `[input]` integer `n` Constraints: `10 ≤ n ≤ 1000000.` - `[output]` ...
["def delete_digit(n):\n s = str(n)\n return int(max(s[:i] + s[i+1:] for i in range(len(s))))", "def delete_digit(n):\n # we just need to remove the last digit of a decreasing sequense of digits\n liststrn = list(str(n))\n for i in range(len(liststrn)):\n try:\n if liststrn[i+1] > lists...
{"fn_name": "delete_digit", "inputs": [[152], [1001], [10]], "outputs": [[52], [101], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,838
def delete_digit(n):
c7af10949efe402732c6a1599ad6ccce
UNKNOWN
Simple transposition is a basic and simple cryptography technique. We make 2 rows and put first a letter in the Row 1, the second in the Row 2, third in Row 1 and so on until the end. Then we put the text from Row 2 next to the Row 1 text and thats it. Complete the function that receives a string and encrypt it with t...
["def simple_transposition(text):\n return text[::2] + text[1::2]", "def simple_transposition(text):\n text1=text[0::2]\n text2=text[1::2]\n return text1+text2", "def simple_transposition(text):\n rowOne = True\n one = \"\"\n two = \"\"\n for x in text:\n if(rowOne):\n one += x...
{"fn_name": "simple_transposition", "inputs": [["Sample text"], ["Simple transposition"], ["All that glitters is not gold"], ["The better part of valor is discretion"], ["Conscience does make cowards of us all"], ["Imagination is more important than knowledge"]], "outputs": [["Sml etapetx"], ["Sml rnpstoipetasoiin"], [...
INTRODUCTORY
PYTHON3
CODEWARS
1,706
def simple_transposition(text):
a5c6c367d4716b8ba0b0e7b0201c5283
UNKNOWN
Given a credit card number we can determine who the issuer/vendor is with a few basic knowns. ```if:python Complete the function `get_issuer()` that will use the values shown below to determine the card issuer for a given card number. If the number cannot be matched then the function should return the string `Unknown`...
["def get_issuer(number):\n s = str(number)\n return (\"AMEX\" if len(s)==15 and s[:2] in (\"34\",\"37\") else\n \"Discover\" if len(s)==16 and s.startswith(\"6011\") else\n \"Mastercard\" if len(s)==16 and s[0]==\"5\" and s[1] in \"12345\" else\n \"VISA\" if len(s) ...
{"fn_name": "get_issuer", "inputs": [[4111111111111111], [4111111111111], [4012888888881881], [41111111111111], [411111111111111], [378282246310005], [348282246310005], [6011111111111117], [5105105105105100], [5105105105105106], [5205105105105106], [5305105105105106], [5405105105105106], [5505105105105106], [9111111111...
INTRODUCTORY
PYTHON3
CODEWARS
46,250
def get_issuer(number):
517d7284aba9cbbf103d2633a3d02e67
UNKNOWN
Check if given chord is minor or major. _____________________________________________________________ Rules: 1. Basic minor/major chord have three elements. 2. Chord is minor when interval between first and second element equals 3 and between second and third -> 4. 3. Chord is major when interval between first and ...
["from itertools import product\n\nNOTES = [['C'], ['C#', 'Db'], ['D'], ['D#', 'Eb'], ['E'], ['F'], ['F#', 'Gb'], ['G'], ['G#', 'Ab'], ['A'], ['A#', 'Bb'], ['B']]*2\nconfig = [('Major', 4), ('Minor', 3)]\n\nDCT_CHORDS = {c: mode for mode, offset in config\n for i in range(len(NOTES)//2)\n ...
{"fn_name": "minor_or_major", "inputs": [["C E G"], ["Db F Ab"], ["D F# A"], ["Eb G Bb"], ["E G# B"], ["F A C"], ["F# A# C#"], ["Gb Bb Db"], ["G B D"], ["Ab C Eb"], ["A C# E"], ["Bb D F"], ["B D# F#"], ["C Eb G"], ["C# E G#"], ["D F A"], ["D# F# A#"], ["Eb Gb Bb"], ["E G B"], ["F Ab C"], ["F# A C#"], ["G Bb D"], ["G# B...
INTRODUCTORY
PYTHON3
CODEWARS
3,444
def minor_or_major(chord):
148f26d1bf551868e908c166b35eb7ec
UNKNOWN
# Task Vanya gets bored one day and decides to enumerate a large pile of rocks. He first counts the rocks and finds out that he has `n` rocks in the pile, then he goes to the store to buy labels for enumeration. Each of the labels is a digit from 0 to 9 and each of the `n` rocks should be assigned a unique number ...
["from math import log10\n\ndef rocks(n):\n return (n + 1) * int(log10(n) + 1) - (10 ** int(log10(n) + 1) - 1) // 9", "def rocks(n):\n ini, c = '9'*(len(str(n)[:-1])), 0\n while ini:\n c += (n-int(ini))*len(str(n))\n n, ini = int(ini), ini[:-1]\n return c+n", "def rocks(n):\n cost = 0\n ...
{"fn_name": "rocks", "inputs": [[1], [10], [13], [100], [36123011]], "outputs": [[1], [11], [17], [192], [277872985]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,250
def rocks(n):
36e05a44e743ab0f5b46198a91732faa
UNKNOWN
Kate likes to count words in text blocks. By words she means continuous sequences of English alphabetic characters (from a to z ). Here are examples: `Hello there, little user5453 374 ())$. I’d been using my sphere as a stool. Slow-moving target 839342 was hit by OMGd-63 or K4mp.` contains "words" `['Hello', 'there', ...
["from re import compile, finditer\n\nOMIT = {'a', 'the', 'on', 'at', 'of', 'upon', 'in', 'as'}\nREGEX = compile(r'[a-z]+')\n\n\ndef word_count(s):\n return sum(a.group() not in OMIT for a in finditer(REGEX, s.lower()))\n", "def word_count(s):\n return sum(1 for w in \"\".join(c if c.isalpha() else \" \" for c in...
{"fn_name": "word_count", "inputs": [["hello there"], ["hello there and a hi"], ["I'd like to say goodbye"], ["Slow-moving user6463 has been here"], ["%^&abc!@# wer45tre"], ["abc123abc123abc"], ["Really2374239847 long ^&#$&(*@# sequence"], ["Hello there, little user5453 374 ())$."]], "outputs": [[2], [4], [6], [6], [3]...
INTRODUCTORY
PYTHON3
CODEWARS
1,847
def word_count(s):
20b486ba47230bc592d8a65f0b34b478
UNKNOWN
**This Kata is intended as a small challenge for my students** All Star Code Challenge #18 Create a function called that accepts 2 string arguments and returns an integer of the count of occurrences the 2nd argument is found in the first one. If no occurrences can be found, a count of 0 should be returned. Notes: *...
["def str_count(strng, letter):\n counter = 0\n \n for chr in strng:\n if chr == letter:\n counter += 1\n \n return counter", "def str_count(strng, letter):\n return (strng.count(letter))", "def str_count(string, letter):\n return string.count(letter)", "str_count = lambda str...
{"fn_name": "str_count", "inputs": [["hello", "l"], ["hello", "e"], ["codewars", "c"], ["ggggg", "g"], ["hello world", "o"]], "outputs": [[2], [1], [1], [5], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
14,245
def str_count(strng, letter):
c8f699ede547fd0d21466bccf1797672
UNKNOWN
Kontti language is a finnish word play game. You add `-kontti` to the end of each word and then swap their characters until and including the first vowel ("aeiouy"); For example the word `tame` becomes `kome-tantti`; `fruity` becomes `koity-fruntti` and so on. If no vowel is present, the word stays the same. Write...
["import re\n\ndef kontti(s):\n return \" \".join( [ re.sub(\"([^aeiouy]*[aeiouy])(.*)\", r\"ko\\2-\\1ntti\", w, flags = re.I) for w in s.split() ] )", "from re import sub\nfrom functools import partial\nkontti = partial(sub, r'(?i)(\\S*?[aeiouy])(\\S*)', r'ko\\2-\\1ntti')", "import re\n\ndef kontti(s):\n return...
{"fn_name": "kontti", "inputs": [["lamppu"], ["lamppu sofia"], ["silly game"], ["aeiou"], ["xyz lamppu"], [""], ["lAmppU"], ["silly grrr"]], "outputs": [["komppu-lantti"], ["komppu-lantti kofia-sontti"], ["kolly-sintti kome-gantti"], ["koeiou-antti"], ["koz-xyntti komppu-lantti"], [""], ["komppU-lAntti"], ["kolly-sintt...
INTRODUCTORY
PYTHON3
CODEWARS
2,097
def kontti(s):
17b99d553133a2cf9842d0b90d499057
UNKNOWN
The queen can be moved any number of unoccupied squares in a straight line vertically, horizontally, or diagonally, thus combining the moves of the rook and bishop. The queen captures by occupying the square on which an enemy piece sits. (wikipedia: https://en.wikipedia.org/wiki/Queen_(chess)). ## Task: Write a functi...
["from itertools import product\n\nBOARD = set(map(\"\".join,product(\"ABCDEFGH\", \"12345678\")))\n\ndef available_moves(position):\n if isinstance(position, str) and position in BOARD :\n\n return sorted(p for p in BOARD-{position} \n if abs(ord(p[0])-ord(position[0])) == abs(int(p[1])...
{"fn_name": "available_moves", "inputs": [[7]], "outputs": [[[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
9,653
def available_moves(position):
efa22799d11da889723d9ad0de9d379b
UNKNOWN
In this kata, your job is to return the two distinct highest values in a list. If there're less than 2 unique values, return as many of them, as possible. The result should also be ordered from highest to lowest. Examples: ``` [4, 10, 10, 9] => [10, 9] [1, 1, 1] => [1] [] => [] ```
["def two_highest(ls):\n result = sorted(list(set(ls)), reverse=True)[:2]\n return result if isinstance(ls, (list)) else False", "def two_highest(list):\n return False if isinstance(list, str) else sorted(set(list), reverse=True)[0:2]", "import heapq\ndef two_highest(list_):\n return heapq.nlargest(2, set(l...
{"fn_name": "two_highest", "inputs": [[[]], [[15]], [[15, 20, 20, 17]]], "outputs": [[[]], [[15]], [[20, 17]]]}
INTRODUCTORY
PYTHON3
CODEWARS
17,147
def two_highest(arg1):
c22d0c7c92cf3d4cad1697fa7878a75f
UNKNOWN
# Task "AL-AHLY" and "Zamalek" are the best teams in Egypt, but "AL-AHLY" always wins the matches between them. "Zamalek" managers want to know what is the best match they've played so far. The best match is the match they lost with the minimum goal difference. If there is more than one match with the same differen...
["def best_match(goals1, goals2):\n return min( (a-b, -b, i) for i,(a,b) in enumerate(zip(goals1, goals2)) )[2]", "def best_match(goals1, goals2):\n bestDiff = goals1[0] - goals2[0]\n bestIndex = 0\n for i in range(len(goals1)):\n if goals1[i] - goals2[i] < bestDiff:\n bestIndex = i\n bestD...
{"fn_name": "best_match", "inputs": [[[6, 4], [1, 2]], [[1], [0]], [[1, 2, 3, 4, 5], [0, 1, 2, 3, 4]], [[3, 4, 3], [1, 1, 2]], [[4, 3, 4], [1, 1, 1]]], "outputs": [[1], [0], [4], [2], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,247
def best_match(goals1, goals2):
03d0df9534c7734e17a21a397ecaae9f
UNKNOWN
Make a program that filters a list of strings and returns a list with only your friends name in it. If a name has exactly 4 letters in it, you can be sure that it has to be a friend of yours! Otherwise, you can be sure he's not... Ex: Input = ["Ryan", "Kieran", "Jason", "Yous"], Output = ["Ryan", "Yous"] i.e. Note:...
["def friend(x):\n return [f for f in x if len(f) == 4]", "def friend(x):\n #Code\n names = []\n for name in x:\n if len(name) == 4:\n names.append(name)\n return names", "def friend(x):\n return [i for i in x if len(i) == 4]", "def friend(x):\n myFriends = [] # ...
{"fn_name": "friend", "inputs": [[["Ryan", "Kieran", "Mark"]], [["Ryan", "Jimmy", "123", "4", "Cool Man"]], [["Jimm", "Cari", "aret", "truehdnviegkwgvke", "sixtyiscooooool"]], [["Love", "Your", "Face", "1"]], [["Hell", "Is", "a", "badd", "word"]], [["Issa", "Issac", "Issacs", "ISISS"]], [["Robot", "Your", "MOMOMOMO"]],...
INTRODUCTORY
PYTHON3
CODEWARS
7,550
def friend(x):
ef7784e96b29536aa22842c1a0a01de5
UNKNOWN
Write a function that gets a sequence and value and returns `true/false` depending on whether the variable exists in a multidimentional sequence. Example: ``` locate(['a','b',['c','d',['e']]],'e'); // should return true locate(['a','b',['c','d',['e']]],'a'); // should return true locate(['a','b',['c','d',['e']]],'f');...
["def locate(seq, value): \n for s in seq:\n if s == value or (isinstance(s,list) and locate(s, value)): \n return True\n return False", "def locate(seq, value): \n f = 0\n for e in seq:\n if type(e) == list and not f:\n f = locate(e, value)\n elif e == value:\n ...
{"fn_name": "locate", "inputs": [[["a", "b", ["c", "d", ["e"]]], "a"], [["a", "b", ["c", "d", ["e"]]], "d"], [["a", "b", ["c", "d", ["e"]]], "e"], [["a", "b", ["c", "d", ["e"]]], "f"], [["a", "b", ["c", "d", ["e", ["a", "b", ["c", "d", ["e4"]]]]]], "e4"], [["a", "b", ["c", "d", ["e", ["a", "b", ["c", "d", ["e", ["a", "...
INTRODUCTORY
PYTHON3
CODEWARS
1,792
def locate(seq, value):
65f9bfe3cd462e85413976b08dadebfd
UNKNOWN
Given a board of `NxN`, distributed with tiles labeled `0` to `N² - 1`(inclusive): A solved grid will have the tiles in order of label, left to right, top to bottom. Return `true` if the board state is currently solved, and `false` if the board state is unsolved. Input will always be a square 2d array. For example...
["def is_solved(board):\n curr = 0;\n for r in board:\n for c in r:\n if c != curr:\n return False;\n curr+=1;\n return True;", "def is_solved(board):\n board = sum(board, [])\n return board == sorted(board)", "def is_solved(board):\n return all( v==w for x,...
{"fn_name": "is_solved", "inputs": [[[[1, 0], [3, 2]]], [[[1, 0, 4], [3, 2, 7], [8, 5, 6]]], [[[6, 7, 8], [0, 1, 2], [3, 4, 5]]]], "outputs": [[false], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,268
def is_solved(board):
80d411b54c10a382e99f9fb9537e916e
UNKNOWN
Take an integer `n (n >= 0)` and a digit `d (0 <= d <= 9)` as an integer. Square all numbers `k (0 <= k <= n)` between 0 and n. Count the numbers of digits `d` used in the writing of all the `k**2`. Call `nb_dig` (or nbDig or ...) the function taking `n` and `d` as parameters and returning this count. #Examples: ``` ...
["def nb_dig(n, d):\n return sum(str(i*i).count(str(d)) for i in range(n+1))", "def nb_dig(n, d):\n return str([n**2 for n in range(n + 1)]).count(str(d))\n", "def nb_dig(n, d):\n return ''.join(str(a ** 2) for a in range(n + 1)).count(str(d))\n", "def nb_dig(n, d):\n \n tot_occur = 0;\n \n for i in ...
{"fn_name": "nb_dig", "inputs": [[5750, 0], [11011, 2], [12224, 8], [11549, 1], [14550, 7], [8304, 7], [10576, 9], [12526, 1], [7856, 4], [14956, 1]], "outputs": [[4700], [9481], [7733], [11905], [8014], [3927], [7860], [13558], [7132], [17267]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,600
def nb_dig(n, d):
adf9b3bf921bf4393b2c42fb46226cae
UNKNOWN
Your task is very simple. Just write a function `isAlphabetic(s)`, which takes an input string `s` in lowercase and returns `true`/`false` depending on whether the string is in alphabetical order or not. For example, `isAlphabetic('kata')` is False as 'a' comes after 'k', but `isAlphabetic('ant')` is True. Good luck ...
["def alphabetic(s):\n return sorted(s) == list(s)\n", "def alphabetic(s):\n return all(a<=b for a,b in zip(s, s[1:]))", "def alphabetic(s):\n for i in range(1, len(s)):\n if s[i - 1] > s[i]:\n return False\n return True", "def alphabetic(s):\n return s == ''.join(sorted(s)) ", "def ...
{"fn_name": "alphabetic", "inputs": [["asd"], ["codewars"], ["door"], ["cell"], ["z"], [""]], "outputs": [[false], [false], [true], [true], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
897
def alphabetic(s):
bb6e3e6098044c3daedff3cefd9627a0
UNKNOWN
The objective of this Kata is to write a function that creates a dictionary of factors for a range of numbers. The key for each list in the dictionary should be the number. The list associated with each key should possess the factors for the number. If a number possesses no factors (only 1 and the number itself), the...
["def factorsRange(n, m):\n return {i: [j for j in range(2, i) if i % j == 0] or ['None'] for i in range(n, m + 1)}", "def factorsRange(n, m):\n res = {}\n \n for num in range(n, m+1):\n factors = []\n \n for div in range(2, num // 2 + 1):\n if num % div == 0:\n ...
{"fn_name": "factorsRange", "inputs": [[2, 6], [5, 20], [2, 100], [10, 30], [200, 220]], "outputs": [[{"2": ["None"], "3": ["None"], "4": [2], "5": ["None"], "6": [2, 3]}], [{"5": ["None"], "6": [2, 3], "7": ["None"], "8": [2, 4], "9": [3], "10": [2, 5], "11": ["None"], "12": [2, 3, 4, 6], "13": ["None"], "14": [2, 7],...
INTRODUCTORY
PYTHON3
CODEWARS
2,392
def factorsRange(n, m):
7c5247ca16ce4333008e60b675dade38
UNKNOWN
Task ======= Make a custom esolang interpreter for the language Tick. Tick is a descendant of [Ticker](https://www.codewars.com/kata/esolang-ticker) but also very different data and command-wise. Syntax/Info ======== Commands are given in character format. Non-command characters should be ignored. Tick has an potent...
["def interpreter(tape):\n memory, ptr, output = {}, 0, \"\"\n \n for command in tape:\n if command == \">\": ptr += 1\n elif command == \"<\": ptr -= 1\n elif command == \"+\": memory[ptr] = (memory.get(ptr, 0) + 1) % 256\n elif command == \"*\": output += chr(memory[ptr])\n ...
{"fn_name": "interpreter", "inputs": [["++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++...
INTRODUCTORY
PYTHON3
CODEWARS
5,048
def interpreter(tape):
fcd6fa11883fac05196aab0a877162d9
UNKNOWN
In mathematics, a matrix (plural matrices) is a rectangular array of numbers. Matrices have many applications in programming, from performing transformations in 2D space to machine learning. One of the most useful operations to perform on matrices is matrix multiplication, which takes a pair of matrices and produces ...
["import numpy as np\n\ndef getMatrixProduct(a, b):\n try:\n return np.matmul(a, b).tolist()\n except:\n return - 1", "def getMatrixProduct(a, b):\n if len(a[0]) != len(b):\n return -1\n result = [[0 for i in range(len(b[0]))] for j in range(len(a))]\n for i in range(len(a)):\n ...
{"fn_name": "getMatrixProduct", "inputs": [[[[2, -2], [5, 3]], [[-1, 4], [7, -6]]], [[[1]], [[3]]], [[[1, 2], [3, 4]], [[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[7, 3], [2, 5], [6, 8], [9, 0]], [[7, 4, 9], [8, 1, 5]]], [[[1, 0.5], [-0.5, 1]], [[5, 0.25], [2, 0.5]]]], "outputs": [[[[-16, 20], [16, 2]]], [[[3]]], [-1], [[[73...
INTRODUCTORY
PYTHON3
CODEWARS
2,588
def getMatrixProduct(a, b):
c5fcd9976dce1d5e96b0895af258535a
UNKNOWN
# Task Consider the following algorithm for constructing 26 strings S(1) .. S(26): ``` S(1) = "a"; For i in [2, 3, ..., 26]: S(i) = S(i - 1) + character(i) + S(i - 1).``` For example: ``` S(1) = "a" S(2) = S(1) + "b" + S(1) = "a" + "b" + "a" = "aba" S(3) = S(2) + "c" + S(2) = "aba" + "c" +"aba" = "abacaba" ... S(26)...
["def abacaba(k):\n return next(chr(97+i) for i,d in enumerate(f'{k:b}'[::-1]) if d=='1')", "def abacaba(k):\n return chr(96 + (k & -k).bit_length())", "def abacaba(k):\n return chr((k & -k).bit_length() + 96)", "def abacaba(k):\n n = 26\n if k % 2: return 'a'\n while k % pow(2, n) != 0: n -= 1\n r...
{"fn_name": "abacaba", "inputs": [[1], [2], [3], [4], [5], [6], [7], [8], [12], [16]], "outputs": [["a"], ["b"], ["a"], ["c"], ["a"], ["b"], ["a"], ["d"], ["c"], ["e"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,153
def abacaba(k):
5943cfbb8fc96ddf9fe2a5c47c600d2a
UNKNOWN
# Task CodeBots decided to make a gift for CodeMaster's birthday. They got a pack of candies of various sizes from the store, but instead of giving the whole pack they are trying to make the biggest possible candy from them. On each turn it is possible: ``` to pick any two candies of the same size and merge them ...
["from collections import Counter\ndef obtain_max_number(arr):\n c = Counter(arr)\n while 1:\n find = next((k for k in c if c[k] > 1), None)\n if not find:return max(c)\n c[find] -= 2\n c[find*2] = c.get(find*2,0) + 1", "from bisect import insort\n\ndef obtain_max_number(arr):\n arr...
{"fn_name": "obtain_max_number", "inputs": [[[2, 4, 8, 1, 1, 15]], [[2, 2, 4, 8, 1, 1, 15]], [[2, 4, 8, 1, 1, 15, 15, 7, 7, 7, 7, 7, 7, 7]], [[2, 4, 8, 1, 1, 30, 30, 15, 15, 7, 7]], [[2, 4, 8, 1, 1, 119, 30, 30, 15, 15, 7, 7]], [[2, 4, 8, 1, 1, 32, 8, 8, 64, 30, 30, 15, 15, 7, 7]]], "outputs": [[16], [16], [30], [60], ...
INTRODUCTORY
PYTHON3
CODEWARS
3,560
def obtain_max_number(arr):
511bc086de6f6e4b0d05022060b3182b
UNKNOWN
In this Kata, you will be given a string and your task is to return the most valuable character. The value of a character is the difference between the index of its last occurrence and the index of its first occurrence. Return the character that has the highest value. If there is a tie, return the alphabetically lowest...
["def solve(st):\n return sorted((st.find(c) - st.rfind(c), c) for c in set(st))[0][1]", "def solve(st):\n return min(set(st), key=lambda c: (st.index(c)-st.rindex(c), c))", "def solve(s):\n d = {}\n for i,c in enumerate(s):\n if c not in d: d[c] = [i,i]\n else: d[c][-1] = i\n retu...
{"fn_name": "solve", "inputs": [["a"], ["aa"], ["bcd"], ["axyzxyz"], ["dcbadcba"], ["aabccc"], ["efgefg"], ["efghijefghi"], ["acefacef"], ["acefacefacef"]], "outputs": [["a"], ["a"], ["b"], ["x"], ["a"], ["c"], ["e"], ["e"], ["a"], ["a"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,838
def solve(st):
46f090392cef0de7c42bdc898d3413af
UNKNOWN
*This kata is inspired by [Project Euler Problem #387](https://projecteuler.net/problem=387)* --- A [Harshad number](https://en.wikipedia.org/wiki/Harshad_number) (or Niven number) is a number that is divisible by the sum of its digits. A *right truncatable Harshad number* is any Harshad number that, when recursively...
["def gen(n):\n if n >= 10**16: return\n for i in range(10):\n x = 10*n + i\n if x % sum(map(int, str(x))): continue\n yield x\n for y in gen(x): yield y\nL = sorted(x for n in range(1, 10) for x in gen(n))\n\nfrom bisect import bisect_left as bl, bisect_right as br\ndef rthn_between(a...
{"fn_name": "rthn_between", "inputs": [[0, 20], [30, 100], [90, 200], [200, 210], [1000, 2000], [2200, 2300], [9000002182976, 9000195371842]], "outputs": [[[10, 12, 18, 20]], [[30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90, 100]], [[90, 100, 102, 108, 120, 126, 180, 200]], [[200, 201, 204, 207, 209, 21...
INTRODUCTORY
PYTHON3
CODEWARS
536,645
def rthn_between(a, b):
71ba674783130f62191baf24d9be9f76
UNKNOWN
# Description "It's the end of trick-or-treating and we have a list/array representing how much candy each child in our group has made out with. We don't want the kids to start arguing, and using our parental intuition we know trouble is brewing as many of the children in the group have received different amounts of ca...
["def candies(s):\n if not s or len(s) == 1:\n return -1\n return len(s) * max(s) - sum(s)\n", "def candies(s):\n return sum([max(s) - x for x in s]) if len(s) > 1 else -1", "def candies(s):\n return max(s) * len(s) - sum(s) if len(s) > 1 else -1", "def candies(s):\n return sum([max(s)-i for i in ...
{"fn_name": "candies", "inputs": [[[5, 8, 6, 4]], [[1, 2, 4, 6]], [[1, 2]], [[4, 2]], [[1, 3, 3, 7]], [[7, 7, 7, 7]], [[17, 20, 50, 61, 42, 44]], [[0]], [[]], [[4]], [[null]]], "outputs": [[9], [11], [1], [2], [14], [0], [132], [-1], [-1], [-1], [-1]]}
INTRODUCTORY
PYTHON3
CODEWARS
895
def candies(s):
25d40ab18bc57d6d389c0b1c6dfda40c
UNKNOWN
Create a function that takes any sentence and redistributes the spaces (and adds additional spaces if needed) so that each word starts with a vowel. The letters should all be in the same order but every vowel in the sentence should be the start of a new word. The first word in the new sentence may start without a vowel...
["from re import sub\ndef vowel_start(st):\n return sub(r'(?<=.)([aeiou])', r' \\1', sub(r'[^a-z0-9]', '', st.lower()))\n", "def vowel_start(s): \n r = ''\n for letter in s:\n if letter in 'aeiouAEIOU':\n r+=' '+letter.lower()\n elif letter.isalnum():\n r+=letter.lower()\n ...
{"fn_name": "vowel_start", "inputs": [["It is beautiful weather today!"], ["Coding is great"], ["my number is 0208-533-2325"], ["oranges, apples, melon, pineapple"], ["under_score"]], "outputs": [["it isb e a ut if ulw e ath ert od ay"], ["c od ing isgr e at"], ["myn umb er is02085332325"], ["or ang es appl esm el onp ...
INTRODUCTORY
PYTHON3
CODEWARS
1,605
def vowel_start(st):
352f72f6cdf6cc3bf5c3bc65f7c8fb77
UNKNOWN
Given some positive integers, I wish to print the integers such that all take up the same width by adding a minimum number of leading zeroes. No leading zeroes shall be added to the largest integer. For example, given `1, 23, 2, 17, 102`, I wish to print out these numbers as follows: ```python 001 023 002 017 102 ```...
["def print_nums(*arr):\n if not arr: return ''\n ln = len(str(max(arr)))\n return '\\n'.join(str(c).zfill(ln) for c in arr)", "def print_nums(*num):\n return \"\\n\".join([str(x).zfill(len(str(max(num)))) for x in num])\n", "def print_nums(*args):\n return \"\\n\".join(\"{:0{}}\".format(n, len(str(max(a...
{"fn_name": "print_nums", "inputs": [[2], [1, 12, 34], [1009, 2], [1, 1, 13], [2, 5, 8], [1, 8, 27]], "outputs": [["2"], ["01\n12\n34"], ["1009\n0002"], ["01\n01\n13"], ["2\n5\n8"], ["01\n08\n27"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,304
def print_nums(*args):
69c3ac7dfddc387a39e6abd138ad7915
UNKNOWN
In this Kata, you will be given a string and your task is to determine if that string can be a palindrome if we rotate one or more characters to the left. ```Haskell solve("4455") = true, because after 1 rotation, we get "5445" which is a palindrome solve("zazcbaabc") = true, because after 3 rotations, we get "abczazc...
["def solve(s):\n return any(s[i+1:] + s[:i+1] == s[i::-1] + s[:i:-1] for i in range(len(s)))", "def solve(s):\n for i in range(len(s)):\n xs = s[i:] + s[:i]\n if xs == xs[::-1]:\n return True\n return False\n", "def solve(s):\n for i in range(len(s)):\n if s == s[::-1]:\n ...
{"fn_name": "solve", "inputs": [["aaab"], ["abcabc"], ["4455"], ["zazcbaabc"], ["223456776543"], ["432612345665"], ["qponmlkjihgfeeiefghijklmnopqrsttsr"]], "outputs": [[false], [false], [true], [true], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,677
def solve(s):
193c6a630e3c1a227f665bdb93c6cf83
UNKNOWN
Given 2 elevators (named "left" and "right") in a building with 3 floors (numbered `0` to `2`), write a function `elevator` accepting 3 arguments (in order): - `left` - The current floor of the left elevator - `right` - The current floor of the right elevator - `call` - The floor that called an elevator It should re...
["def elevator(left, right, call):\n return \"left\" if abs(call - left) < abs(call - right) else \"right\"", "def elevator(left, right, call):\n if abs(left-call) >= abs(right-call):\n return \"right\"\n else:\n return \"left\"", "def elevator(left, right, call):\n return \"left\" if abs(left...
{"fn_name": "elevator", "inputs": [[0, 1, 0], [0, 1, 1], [0, 1, 2], [0, 0, 0], [0, 2, 1], [0, 0, 1], [0, 0, 2], [0, 2, 0], [0, 2, 2], [1, 0, 0], [1, 0, 1], [1, 0, 2], [1, 1, 0], [1, 1, 1], [1, 1, 2], [1, 2, 0], [1, 2, 1], [1, 2, 2], [2, 0, 0], [2, 0, 1], [2, 0, 2], [2, 1, 0], [2, 1, 1], [2, 1, 2], [2, 2, 0], [2, 2, 1],...
INTRODUCTORY
PYTHON3
CODEWARS
20,365
def elevator(left, right, call):
251ccf707913b375c6207b898af764d7
UNKNOWN
Given a positive integer `n`, return first n dgits of Thue-Morse sequence, as a string (see examples). Thue-Morse sequence is a binary sequence with 0 as the first element. The rest of the sequece is obtained by adding the Boolean (binary) complement of a group obtained so far. ``` For example: 0 01 0110 01101001 an...
["thue_morse=lambda n: \"0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100...
{"fn_name": "thue_morse", "inputs": [[1], [2], [5], [10], [100]], "outputs": [["0"], ["01"], ["01101"], ["0110100110"], ["0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110"]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,616
def thue_morse(n):
4173156b07adae86ba6ecd2029ff1846
UNKNOWN
Write ```python function repeating_fractions(numerator, denominator) ``` that given two numbers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part has repeated digits, replace those digits with a single digit in parentheses. For example: ```python re...
["import re\ndef repeating_fractions(n, d):\n (i, d) = str(n * 1.0 / d).split('.')\n return i + '.' + re.sub(r'([0-9])\\1+', r'(\\1)', d)", "repeating_fractions = lambda n,d: __import__('re').sub(r\"(\\d)(\\1+)(?!\\.)\",r\"(\\1)\",str(n/float(d)))", "import re\n\ndef repeating_fractions(num, den):\n d, f = str(num...
{"fn_name": "repeating_fractions", "inputs": [[0, 1], [18018018, 80000000000], [1, 1], [1, 2], [1, 3], [1554, 70]], "outputs": [["0.0"], ["0.(0)(2)5(2)5(2)5"], ["1.0"], ["0.5"], ["0.(3)"], ["22.2"]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,192
def repeating_fractions(n,d):
a32c43ade4ad06928763d7c9373d0cc4
UNKNOWN
Write a function that replaces 'two', 'too' and 'to' with the number '2'. Even if the sound is found mid word (like in octopus) or not in lowercase grandma still thinks that should be replaced with a 2. Bless her. ```text 'I love to text' becomes 'I love 2 text' 'see you tomorrow' becomes 'see you 2morrow' 'look at th...
["import re\n\ndef textin(txt ):\n return re.sub(r'(two|too|to)', '2', txt, flags=re.I)", "import re\n\ndef textin(str):\n return re.sub('(?i)t[wo]?o','2',str)", "textin = lambda s: __import__(\"re\").sub(r\"(?i)t[wo]?o\", \"2\", s)", "import re\n\n\ndef textin(stg):\n return re.sub(r\"too|two|to\", \"2\", stg, ...
{"fn_name": "textin", "inputs": [["I love to text"], ["see you tomorrow"], ["look at that octopus"], ["BECAUSE I WANT TO"]], "outputs": [["I love 2 text"], ["see you 2morrow"], ["look at that oc2pus"], ["BECAUSE I WANT 2"]]}
INTRODUCTORY
PYTHON3
CODEWARS
934
def textin(st):
27f6fd8d5effff66d4bc6e02f744d21f
UNKNOWN
### Description: Remove all exclamation marks from sentence except at the end. ### Examples ``` remove("Hi!") == "Hi!" remove("Hi!!!") == "Hi!!!" remove("!Hi") == "Hi" remove("!Hi!") == "Hi!" remove("Hi! Hi!") == "Hi Hi!" remove("Hi") == "Hi" ```
["def remove(s):\n return s.replace('!', '')+ '!'*(len(s)- len(s.rstrip('!')))", "import re\n\ndef remove(s):\n return re.sub(r'!+(?!!*$)', '', s)", "def remove(s):\n end_i = len(s.rstrip('!'))\n return s[:end_i].replace('!', '') + s[end_i:]", "def remove(s):\n num = 0\n for letter in s[::-1]:\n ...
{"fn_name": "remove", "inputs": [["Hi!"], ["Hi!!!"], ["!Hi"], ["!Hi!"], ["Hi! Hi!"], ["Hi"]], "outputs": [["Hi!"], ["Hi!!!"], ["Hi"], ["Hi!"], ["Hi Hi!"], ["Hi"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,236
def remove(s):
b8090e13311472626950566ea8b8190a
UNKNOWN
Create a function `close_compare` that accepts 3 parameters: `a`, `b`, and an optional `margin`. The function should return whether `a` is lower than, close to, or higher than `b`. `a` is "close to" `b` if `margin` is higher than or equal to the difference between `a` and `b`. When `a` is lower than `b`, return `-1`. ...
["def close_compare(a, b, margin = 0):\n return 0 if abs(a - b) <= margin else -1 if b > a else 1", "def close_compare(a, b, margin=0):\n if a == b or abs(a - b) <= margin:\n return 0\n if a < b:\n return -1\n if a > b:\n return 1", "def close_compare(a, b, margin=0):\n if a-b>margin...
{"fn_name": "close_compare", "inputs": [[4, 5], [5, 5], [6, 5], [2, 5, 3], [5, 5, 3], [8, 5, 3], [8.1, 5, 3], [1.99, 5, 3]], "outputs": [[-1], [0], [1], [0], [0], [0], [1], [-1]]}
INTRODUCTORY
PYTHON3
CODEWARS
18,399
def close_compare(a, b, margin=0):
b124f50b341922a5f4d4bcae04ac6233
UNKNOWN
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: 2332 110011 54322345 You'll be given 2 numbers as arguments: ```(num,s)```. Write a function which returns an array of ```s``` number of numerical palindromes tha...
["def palindrome(num,s):\n if not (type(num) == type(s) == int) or num < 0 or s < 0:\n return \"Not valid\"\n \n ans, num = [], max(num, 11)\n while len(ans) != s:\n if num == int(str(num)[::-1]):\n ans.append(num)\n num += 1\n return ans", "def palindrome(num, s):\n if...
{"fn_name": "palindrome", "inputs": [[6, 4], [75, 1], [19, 3], [101, 2], ["ACCDDCCA", 3], [773, "1551"], [-4505, 15]], "outputs": [[[11, 22, 33, 44]], [[77]], [[22, 33, 44]], [[101, 111]], ["Not valid"], ["Not valid"], ["Not valid"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,186
def palindrome(num,s):
43ef69dbc419357a2478b14487bb890c
UNKNOWN
A **bouncy number** is a positive integer whose digits neither increase nor decrease. For example, `1235` is an increasing number, `5321` is a decreasing number, and `2351` is a bouncy number. By definition, all numbers under `100` are non-bouncy, and `101` is the first bouncy number. To complete this kata, you must wr...
["def is_bouncy(n):\n return sorted(str(n)) != list(str(n)) and sorted(str(n)) != list(str(n))[::-1]", "def is_bouncy(n):\n s = str(n)\n decrease = increase = False\n for a, b in zip(s, s[1:]):\n if a < b:\n increase = True\n elif a > b:\n decrease = True\n return decr...
{"fn_name": "is_bouncy", "inputs": [[0], [99], [101], [120], [122], [221], [2379], [29340], [234689], [98874], [92722983], [129347924210]], "outputs": [[false], [false], [true], [true], [false], [false], [false], [true], [false], [false], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,343
def is_bouncy(number):
a6477b0eb301c7954b747ae973bb15fd
UNKNOWN
In recreational mathematics, a magic square is an arrangement of distinct numbers (i.e., each number is used once), usually integers, in a square grid, where the numbers in each row, and in each column, and the numbers in the main and secondary diagonals, all add up to the same number, called the "magic constant." For...
["def is_magical(sq):\n return sum(sq[2:7:2])==sum(sq[::4])==sum(sq[::3])==sum(sq[1::3])==sum(sq[2::3])==sum(sq[:3])==sum(sq[3:6])==sum(sq[6:])", "def is_magical(sq):\n return len(set( [sum(sq[i*3:(i+1)*3]) for i in range(3)] # lines\n + [sum(sq[i::3]) for i in range(3)] ...
{"fn_name": "is_magical", "inputs": [[[4, 9, 2, 3, 5, 7, 8, 1, 6]], [[4, 9, 2, 3, 5, 7, 8, 6, 1]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[9, 4, 7, 3, 5, 2, 8, 6, 1]], [[8, 1, 6, 3, 5, 7, 4, 9, 2]]], "outputs": [[true], [false], [false], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,925
def is_magical(sq):
da9ed17730cc8b458d1dc8b191ab9391
UNKNOWN
You have an award-winning garden and everyday the plants need exactly 40mm of water. You created a great piece of JavaScript to calculate the amount of water your plants will need when you have taken into consideration the amount of rain water that is forecast for the day. Your jealous neighbour hacked your computer an...
["def rain_amount(mm):\n if mm < 40:\n return \"You need to give your plant \" + str(40 - mm) + \"mm of water\"\n else:\n return \"Your plant has had more than enough water for today!\"", "def rain_amount(mm):\n if mm < 40:\n return 'You need to give your plant {}mm of water'.for...
{"fn_name": "rain_amount", "inputs": [[100], [40], [39], [5], [0]], "outputs": [["Your plant has had more than enough water for today!"], ["Your plant has had more than enough water for today!"], ["You need to give your plant 1mm of water"], ["You need to give your plant 35mm of water"], ["You need to give your plant 4...
INTRODUCTORY
PYTHON3
CODEWARS
21,765
def rain_amount(mm):
fa5c77bdd6e101f2a7139c268c0f4df4
UNKNOWN
In the board game Talisman, when two players enter combat the outcome is decided by a combat score, equal to the players power plus any modifiers plus the roll of a standard 1-6 dice. The player with the highest combat score wins and the opposing player loses a life. In the case of a tie combat ends with neither player...
["def get_required(player,enemy):\n p_sum = sum(player)\n e_sum = sum(enemy)\n \n diff = p_sum - e_sum\n \n if diff == 0:\n return 'Random'\n \n if diff > 5:\n return 'Auto-win'\n \n if diff < -5:\n return 'Auto-lose'\n \n if diff == -5:\n return 'Pray for...
{"fn_name": "get_required", "inputs": [[[8, 1], [3, 0]], [[2, 0], [8, 1]], [[4, 0], [4, 0]], [[6, 0], [8, 0]], [[8, 0], [6, 0]], [[4, 3], [6, 0]], [[1, 0], [5, 0]], [[3, 3], [5, 3]], [[1, 10], [1, 4]], [[3, 3], [6, 0]], [[7, 2], [6, 8]]], "outputs": [["Auto-win"], ["Auto-lose"], ["Random"], ["(1..3)"], ["(5..6)"], ["(6...
INTRODUCTORY
PYTHON3
CODEWARS
4,012
def get_required(player,enemy):
ce784118f40ec339271b5103e5904a0a
UNKNOWN
Complete the function to find the count of the most frequent item of an array. You can assume that input is an array of integers. For an empty array return `0` ## Example ```python input array: [3, -1, -1, -1, 2, 3, -1, 3, -1, 2, 4, 9, 3] ouptut: 5 ``` The most frequent number in the array is `-1` and it occurs `5` t...
["def most_frequent_item_count(collection):\n if collection:\n return max([collection.count(item) for item in collection])\n return 0", "from collections import Counter\n\n\ndef most_frequent_item_count(collection):\n return Counter(collection).most_common(1)[0][1] if collection else 0\n", "def most_fre...
{"fn_name": "most_frequent_item_count", "inputs": [[[3, -1, -1]], [[3, -1, -1, -1, 2, 3, -1, 3, -1, 2, 4, 9, 3]], [[]], [[9]]], "outputs": [[2], [5], [0], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,666
def most_frequent_item_count(collection):