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
021c83a2c065d01106c7e0444d7b562c
UNKNOWN
The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single `100`, `50` or `25` dollar bill. An "Avengers" ticket costs `25 dollars`. Vasya is currently working as a clerk. He wants to sell a ticket to every single person in thi...
["def tickets(people):\n till = {100.0:0, 50.0:0, 25.0:0}\n\n for paid in people:\n till[paid] += 1\n change = paid-25.0\n \n for bill in (50,25):\n while (bill <= change and till[bill] > 0):\n till[bill] -= 1\n change -= bill\n\n if change != 0:\n return 'NO'\n \n retur...
{"fn_name": "tickets", "inputs": [[[25, 25, 50]], [[25, 25, 50, 100]], [[25, 100]], [[25, 25, 25, 25, 25, 25, 25, 25, 25, 25]], [[50, 50, 50, 50, 50, 50, 50, 50, 50, 50]], [[100, 100, 100, 100, 100, 100, 100, 100, 100, 100]], [[25, 25, 25, 25, 50, 100, 50]], [[50, 100, 100]], [[25, 25, 100]], [[25, 25, 25, 25, 25, 25, ...
INTRODUCTORY
PYTHON3
CODEWARS
4,937
def tickets(people):
3f858f12749f83a1ccecd67a17d4444f
UNKNOWN
###Instructions Write a function that takes a negative or positive integer, which represents the number of minutes before (-) or after (+) Sunday midnight, and returns the current day of the week and the current time in 24hr format ('hh:mm') as a string. ```python day_and_time(0) should return 'Sunday 00:00' d...
["from datetime import timedelta, datetime\ndef day_and_time(mins):\n return \"{:%A %H:%M}\".format(datetime(2017, 1, 1) + timedelta(minutes = mins))", "def day_and_time(mins):\n dow = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']\n return \"{} {:02d}:{:02d}\".format(dow[(mins // 144...
{"fn_name": "day_and_time", "inputs": [[0], [-3], [45], [759], [1236], [1447], [7832], [18876], [259180], [-349000]], "outputs": [["Sunday 00:00"], ["Saturday 23:57"], ["Sunday 00:45"], ["Sunday 12:39"], ["Sunday 20:36"], ["Monday 00:07"], ["Friday 10:32"], ["Saturday 02:36"], ["Thursday 23:40"], ["Tuesday 15:20"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,521
def day_and_time(mins):
e1091b7aaf7701c101abf72b27c22a67
UNKNOWN
## Task You will receive a string consisting of lowercase letters, uppercase letters and digits as input. Your task is to return this string as blocks separated by dashes (`"-"`). The elements of a block should be sorted with respect to the hierarchy listed below, and each block cannot contain multiple instances of th...
["from collections import Counter\n\ndef blocks(s):\n sort = lambda c: (c.isdigit(), c.isupper(), c)\n answer, counter = [], Counter(s)\n while counter:\n block = ''.join(sorted(counter, key=sort))\n answer.append(block)\n counter = counter - Counter(block)\n return '-'.join(answer)", "...
{"fn_name": "blocks", "inputs": [["heyitssampletestkk"], ["dasf6ds65f45df65gdf651vdf5s1d6g5f65vqweAQWIDKsdds"], ["SDF45648374RHF8BFVYg378rg3784rf87g3278bdqG"], [""], ["aaaaaaaaaa"]], "outputs": [["aehiklmpsty-ekst-est"], ["adefgqsvwADIKQW1456-dfgsv156-dfs56-dfs56-dfs56-df56-d5-d"], ["bdfgqrBDFGHRSVY2345678-grF3478-gF34...
INTRODUCTORY
PYTHON3
CODEWARS
3,428
def blocks(s):
66ce51d068b05c18bd7dded04dcf207e
UNKNOWN
Given a string of words (x), you need to return an array of the words, sorted alphabetically by the final character in each. If two words have the same last letter, they returned array should show them in the order they appeared in the given string. All inputs will be valid.
["def last(s):\n return sorted(s.split(), key=lambda x: x[-1])", "def last(s):\n return sorted(s.split(), key = lambda word: word[-1])", "from operator import itemgetter\n\ndef last(s):\n return sorted(s.split(), key=itemgetter(-1))", "def last(s):\n return sorted(s.split(\" \"), key=lambda w: w[-1])", "las...
{"fn_name": "last", "inputs": [["man i need a taxi up to ubud"], ["what time are we climbing up the volcano"], ["take me to semynak"], ["massage yes massage yes massage"], ["take bintang and a dance please"]], "outputs": [[["a", "need", "ubud", "i", "taxi", "man", "to", "up"]], [["time", "are", "we", "the", "climbing",...
INTRODUCTORY
PYTHON3
CODEWARS
1,067
def last(s):
21d587631d96c88daad6fbe4c337dd4d
UNKNOWN
## The story you are about to hear is true Our cat, Balor, sadly died of cancer in 2015. While he was alive, the three neighborhood cats Lou, Mustache Cat, and Raoul all recognized our house and yard as Balor's territory, and would behave respectfully towards him and each other when they would visit. But after Balor...
["from itertools import combinations\nfrom math import hypot\n\ndef peaceful_yard(yard, d):\n cats = ((i, j) for i,r in enumerate(yard) for j,c in enumerate(r) if c in 'LMR')\n return all(hypot(q[0] - p[0], q[1] - p[1]) >= d for p,q in combinations(cats, 2))", "def peaceful_yard(yard, min_distance):\n # Extract ca...
{"fn_name": "peaceful_yard", "inputs": [[["------------", "------------", "-L----------", "------------", "------------", "------------"], 10], [["------------", "---M--------", "------------", "------------", "-------R----", "------------"], 6], [["-----------L", "--R---------", "------------", "------------", "------...
INTRODUCTORY
PYTHON3
CODEWARS
4,936
def peaceful_yard(yard, min_distance):
58e017b856f724634e90e703a06201ee
UNKNOWN
Create a function that takes a list of one or more non-negative integers, and arranges them such that they form the largest possible number. Examples: `largestArrangement([4, 50, 8, 145])` returns 8504145 (8-50-4-145) `largestArrangement([4, 40, 7])` returns 7440 (7-4-40) `largestArrangement([4, 46, 7])` returns 74...
["from functools import cmp_to_key\n\ncmp = lambda a, b: int('%i%i' % (b, a)) - int('%i%i' % (a, b))\nlargest_arrangement = lambda n: int(''.join(str(i) for i in sorted(n, key = cmp_to_key(cmp))))", "def largest_arrangement(numbers):\n numbers = list(map(str, numbers))\n for x in range(len(numbers)):\n for...
{"fn_name": "largest_arrangement", "inputs": [[[50, 2, 1, 9]], [[3655, 89]], [[8]], [[12, 13, 89, 155, 8, 26, 0]], [[76, 4, 3, 81, 514, 6, 716]], [[817, 6879, 163, 348, 8, 22, 47]], [[411, 742, 89, 691, 284]], [[587, 625, 638, 898, 122]], [[797, 535, 210, 87]], [[5, 2, 1, 9, 50, 56]], [[197, 853, 819]], [[23044, 2, 762...
INTRODUCTORY
PYTHON3
CODEWARS
2,542
def largest_arrangement(numbers):
c3de43d71f3ef5698221a35efe5f6c2e
UNKNOWN
You are given an array that of arbitrary depth that needs to be nearly flattened into a 2 dimensional array. The given array's depth is also non-uniform, so some parts may be deeper than others. All of lowest level arrays (most deeply nested) will contain only integers and none of the higher level arrays will contain ...
["def near_flatten(a):\n r = []\n for x in a:\n if isinstance(x[0], int): r.append(x)\n else: r.extend(near_flatten(x))\n return sorted(r)", "def near_flatten(xs):\n def f(xs):\n if all(not isinstance(x, list) for x in xs):\n yield xs\n return\n for x in xs:...
{"fn_name": "near_flatten", "inputs": [[[[1]]], [[[1, 2, 3], [4, 5, 6]]], [[[1, 2, 3], [[4, 5], [[6], [7, 8]]]]], [[[[1, 2, 3], [9, 10]], [[4, 5], [6, 7, 8]]]]], "outputs": [[[[1]]], [[[1, 2, 3], [4, 5, 6]]], [[[1, 2, 3], [4, 5], [6], [7, 8]]], [[[1, 2, 3], [4, 5], [6, 7, 8], [9, 10]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,329
def near_flatten(nested):
93d5aea0adaca1cc5ac81bb9f88fcc12
UNKNOWN
An Ironman Triathlon is one of a series of long-distance triathlon races organized by the World Triathlon Corporaion (WTC). It consists of a 2.4-mile swim, a 112-mile bicycle ride and a marathon (26.2-mile) (run, raced in that order and without a break. It hurts... trust me. Your task is to take a distance that an ath...
["def i_tri(s):\n total = 2.4 + 112 + 26.2\n to_go = '%.2f to go!' % (total - s)\n \n return ( 'Starting Line... Good Luck!' if s == 0 else\n {'Swim': to_go} if s < 2.4 else\n {'Bike': to_go} if s < 2.4 + 112 else\n {'Run': to_go} if s < total - 10 else\n {'Run':...
{"fn_name": "i_tri", "inputs": [[36], [103], [0], [2], [151]], "outputs": [[{"Bike": "104.60 to go!"}], [{"Bike": "37.60 to go!"}], ["Starting Line... Good Luck!"], [{"Swim": "138.60 to go!"}], ["You're done! Stop running!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,912
def i_tri(s):
717c6cfb98ad1ba5f0ed994ab27cb959
UNKNOWN
Find the sum of the odd numbers within an array, after cubing the initial integers. The function should return `undefined`/`None`/`nil`/`NULL` if any of the values aren't numbers. ~~~if:java,csharp Note: There are ONLY integers in the JAVA and C# versions of this Kata. ~~~ ~~~if:python Note: Booleans should not be c...
["def cube_odd(arr):\n return sum( n**3 for n in arr if n % 2 ) if all(type(n) == int for n in arr) else None", "def cube_odd(arr):\n if any(type(x) is not int for x in arr):\n return None\n return sum(x ** 3 for x in arr if x % 2 != 0)", "def cube_odd(arr):\n if len(set(map(type,arr))) < 2:\n ...
{"fn_name": "cube_odd", "inputs": [[[1, 2, 3, 4]], [[-3, -2, 2, 3]], [["a", 12, 9, "z", 42]], [[true, false, 2, 4, 1]]], "outputs": [[28], [0], [null], [null]]}
INTRODUCTORY
PYTHON3
CODEWARS
20,942
def cube_odd(arr):
dbda2f128a8c89e9ca664b306074e4d5
UNKNOWN
# Scenario With **_Cereal crops_** like wheat or rice, before we can eat the grain kernel, we need to remove that inedible hull, or *to separate the wheat from the chaff*. ___ # Task **_Given_** a *sequence of n integers* , **_separate_** *the negative numbers (chaff) from positive ones (wheat).* ___ # Notes * *...
["def wheat_from_chaff(values):\n i, j = 0, len(values)-1\n while True:\n while i < j and values[i] < 0: i += 1\n while i < j and values[j] > 0: j -= 1\n if i >= j: return values\n values[i], values[j] = values[j], values[i]", "def wheat_from_chaff(values):\n i, j = 0, len(values) -...
{"fn_name": "wheat_from_chaff", "inputs": [[[2, -4, 6, -6]], [[7, -3, -10]], [[7, -8, 1, -2]], [[8, 10, -6, -7, 9]], [[-3, 4, -10, 2, -6]], [[2, -6, -4, 1, -8, -2]], [[16, 25, -48, -47, -37, 41, -2]], [[-30, -11, 36, 38, 34, -5, -50]], [[-31, -5, 11, -42, -22, -46, -4, -28]], [[46, 39, -45, -2, -5, -6, -17, -32, 17]], ...
INTRODUCTORY
PYTHON3
CODEWARS
3,681
def wheat_from_chaff(values):
d585f0251e4c401a80ec53d0623839d8
UNKNOWN
The "Russian Peasant Method" is an old algorithm used by Russian peasants (and before them ancient Egyptians) to perform multiplication. Consider that X and Y are two numbers. X can be any number but Y must be a positive integer. To multiply X and Y: 1. Let the product = 0 2. If Y is odd, then the product = product ...
["def russian_peasant_multiplication(x, y):\n product = 0\n while y != 0:\n if y % 2 == 1:\n product += x\n x += x\n y //= 2\n \n return product", "def russian_peasant_multiplication(x, y, product=0):\n product += x if y % 2 else 0\n x += x\n y //= 2\n if y:\n...
{"fn_name": "russian_peasant_multiplication", "inputs": [[10, 5], [1.001, 2], [175, 18], [-2, 2], [2500, 123]], "outputs": [[50], [2.002], [3150], [-4], [307500]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,736
def russian_peasant_multiplication(x, y):
b7e25db3f509c1c2f26677e40a41d047
UNKNOWN
Given a string and an array of index numbers, return the characters of the string rearranged to be in the order specified by the accompanying array. Ex: scramble('abcd', [0,3,1,2]) -> 'acdb' The string that you will be returning back will have: 'a' at index 0, 'b' at index 3, 'c' at index 1, 'd' at index 2, because...
["def scramble(string, array):\n return \"\".join(v for _, v in sorted(zip(array, string)))", "def scramble(string, array):\n res = array[:]\n for (i,a) in enumerate(array):\n res[a]=string[i]\n return \"\".join(res)\n", "def scramble(string, lst):\n result = [None] * len(string)\n for char, in...
{"fn_name": "scramble", "inputs": [["abcd", [0, 3, 1, 2]], ["sc301s", [4, 0, 3, 1, 5, 2]], ["bskl5", [2, 1, 4, 3, 0]]], "outputs": [["acdb"], ["c0s3s1"], ["5sblk"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,244
def scramble(string, array):
ceac04708a252e6392dda4d8c8fcbf24
UNKNOWN
Program a function `sumAverage(arr)` where `arr` is an array containing arrays full of numbers, for example: ```python sum_average([[1, 2, 2, 1], [2, 2, 2, 1]]) ``` First, determine the average of each array. Then, return the sum of all the averages. - All numbers will be less than 100 and greater than -100. - `arr`...
["from statistics import mean\nfrom math import floor\n\ndef sum_average(arr):\n return floor(sum(map(mean, arr)))", "from statistics import mean\nfrom math import floor\n\ndef sum_average(arr):\n return floor(sum(mean(lst) for lst in arr))", "import math\n\ndef sum_average(arr):\n return math.floor(sum([sum(a...
{"fn_name": "sum_average", "inputs": [[[[1, 2, 2, 1], [2, 2, 2, 1]]], [[[52, 64, 84, 21, 54], [44, 87, 46, 90, 43]]], [[[44, 76, 12], [96, 12, 34, 53, 76, 34, 56, 86, 21], [34, 65, 34, 76, 34, 87, 34]]], [[[41, 16, 99, 93, 59, 18, 35, 23, 55, 45, 38, 39, 74, 60, 95, 44, 59, 70, 44, 89, 90, 19, 23, 67, 65, 66, 41, 89, 4...
INTRODUCTORY
PYTHON3
CODEWARS
1,586
def sum_average(arr):
5dc47a5cc04de57a9348415dc9eac3f5
UNKNOWN
Create a function that interprets code in the esoteric language **Poohbear** ## The Language Poohbear is a stack-based language largely inspired by Brainfuck. It has a maximum integer value of 255, and 30,000 cells. The original intention of Poohbear was to be able to send messages that would, to most, be completely ...
["from operator import add, mul, floordiv as fdiv, pow\n\ndef poohbear(s):\n \n def updateMem(func, v): mem[p] = func(mem.get(p, 0), v) % 256\n\n braces, stack = {}, []\n for i,c in enumerate(s):\n if c == 'W': stack.append(i)\n if c == 'E':\n braces[i] = stack[-1]\n brac...
{"fn_name": "poohbear", "inputs": [["LQTcQAP>pQBBTAI-PA-PPL+P<BVPAL+T+P>PL+PBLPBP<DLLLT+P"], ["LLQT+P >LLLc+QIT-P AAAP P"], ["LLQT>+WN+<P>E"], ["cW>LQQT+P<pE"], ["+W>LQQT+P<-E"], ["+LTQII>+WN<P>+E"], ["+LTQIITTIWP-E"], ["LILcABNBpYDYYYYLLL+P-+W-EQNW-ELLQUTTTT+P"], ["++W-NE"], ["W>UQLIPNPPP45vSDFJLLIPNPqwVMT<E"], ["LLIL...
INTRODUCTORY
PYTHON3
CODEWARS
14,860
def poohbear(s):
6f5822827272f6dacddca682a0acc763
UNKNOWN
The Tower of Hanoi problem involves 3 towers. A number of rings decreasing in size are placed on one tower. All rings must then be moved to another tower, but at no point can a larger ring be placed on a smaller ring. Your task: Given a number of rings, return the MINIMUM number of moves needed to move all the ring...
["def tower_of_hanoi(rings):\n return 2**rings - 1", "def tower_of_hanoi(rings):\n moves = 2**rings - 1\n return moves", "def tower_of_hanoi(rings):\n answer = 1\n for i in range(rings-1):\n answer = (answer *2) +1\n return answer", "def tower_of_hanoi(r):\n return ~(-1<<r)", "def tower_of_h...
{"fn_name": "tower_of_hanoi", "inputs": [[4], [5], [10], [50]], "outputs": [[15], [31], [1023], [1125899906842623]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,006
def tower_of_hanoi(rings):
8be46c06fd9ac537471dbcbadceac9e9
UNKNOWN
Check if it is a vowel(a, e, i, o, u,) on the ```n``` position in a string (the first argument). Don't forget about uppercase. A few cases: ``` { checkVowel('cat', 1) -> true // 'a' is a vowel checkVowel('cat', 0) -> false // 'c' is not a vowel checkVowel('cat', 4) -> false // this position doesn't exist } `...
["def check_vowel(s,i):\n return 0 <= i < len(s) and s[i] in \"aieouAEIOU\"", "def check_vowel(string, position):\n return 0 <= position < len(string) and string[position].lower() in \"aeiou\"", "def check_vowel(string, position):\n if position < 0:\n return False\n try:\n return string[position]...
{"fn_name": "check_vowel", "inputs": [["cat", 1], ["cat", 0], ["cat", 4], ["Amanda", -2], ["Amanda", 0], ["Amanda", 2]], "outputs": [[true], [false], [false], [false], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,364
def check_vowel(string, position):
18fcec2f8ec1520475c0303cf11ed342
UNKNOWN
We are given a sequence of coplanar points and see all the possible triangles that may be generated which all combinations of three points. We have the following list of points with the cartesian coordinates of each one: ``` Points [x, y] A [1, 2] B [3, 3] C [4, 1] D [1, 1] E [4, -1] ``` With ...
["from itertools import combinations\n\n\ndef isRect(a,b,c):\n X,Y,Z = sorted( sum( (q-p)**2 for p,q in zip(p1,p2)) for p1,p2 in [(a,b), (a,c), (b,c)] )\n return X+Y == Z\n\ndef count_rect_triang(points):\n return sum( isRect(*c) for c in combinations(set(map(tuple, points)), 3) )", "from itertools import comb...
{"fn_name": "count_rect_triang", "inputs": [[[[1, 2], [3, 3], [4, 1], [1, 1], [4, -1]]], [[[1, 2], [4, -1], [3, 3], [4, -1], [4, 1], [1, 1], [4, -1], [4, -1], [3, 3], [1, 2]]]], "outputs": [[3], [3]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,076
def count_rect_triang(points):
66143dd39ccd47e4f3ec466c089268a2
UNKNOWN
Given: an array containing hashes of names Return: a string formatted as a list of names separated by commas except for the last two names, which should be separated by an ampersand. Example: ``` ruby list([ {name: 'Bart'}, {name: 'Lisa'}, {name: 'Maggie'} ]) # returns 'Bart, Lisa & Maggie' list([ {name: 'Bart'}, {...
["def namelist(names):\n if len(names) > 1:\n return '{} & {}'.format(', '.join(name['name'] for name in names[:-1]), \n names[-1]['name'])\n elif names:\n return names[0]['name']\n else:\n return ''", "def namelist(names):\n if len(names)==0: return ''\n ...
{"fn_name": "namelist", "inputs": [[[{"name": "Bart"}, {"name": "Lisa"}, {"name": "Maggie"}, {"name": "Homer"}, {"name": "Marge"}]], [[{"name": "Bart"}, {"name": "Lisa"}, {"name": "Maggie"}]], [[{"name": "Bart"}, {"name": "Lisa"}]], [[{"name": "Bart"}]], [[]]], "outputs": [["Bart, Lisa, Maggie, Homer & Marge"], ["Bart,...
INTRODUCTORY
PYTHON3
CODEWARS
1,994
def namelist(names):
1976333b1af9eaf38be3e122b8492ec1
UNKNOWN
In this Kata, you will be given an array and your task will be to determine if an array is in ascending or descending order and if it is rotated or not. Consider the array `[1,2,3,4,5,7,12]`. This array is sorted in `Ascending` order. If we rotate this array once to the left, we get `[12,1,2,3,4,5,7]` and twice-rotat...
["def solve(lst):\n a, b, c = lst[0] < lst[1], lst[1] < lst[2], lst[-1] < lst[0]\n m = a if a == b else c\n return ('R' if c == m else '') + ('A' if m else 'D')", "def solve(arr):\n if sorted(arr) == arr:\n return \"A\"\n if sorted(arr)[::-1] == arr:\n return \"D\"\n return \"RA\" if arr...
{"fn_name": "solve", "inputs": [[[1, 2, 3, 4, 5, 7]], [[7, 1, 2, 3, 4, 5]], [[2, 3, 4, 5, 7, 12]], [[7, 12, 1, 2, 3, 4, 5]], [[4, 5, 6, 1, 2, 3]], [[9, 8, 7, 6, 5]], [[5, 9, 8, 7, 6]], [[6, 5, 9, 8, 7]], [[9, 6, 7]], [[10, 12, 11]], [[13, 10, 11]]], "outputs": [["A"], ["RA"], ["A"], ["RA"], ["RA"], ["D"], ["RD"], ["RD"...
INTRODUCTORY
PYTHON3
CODEWARS
1,870
def solve(arr):
412a52fb1e41b492f732b5fb6e5c769e
UNKNOWN
# Task You are given a positive integer `n`. We intend to make some ascending sequences according to the following rules: 1. Make a sequence of length 1: [ n ] 2. Or, insert a number to the left side of the sequence. But this number can not exceed half of the first number of the sequence. 3. Follow rule 2, cont...
["from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef make_sequences(n):\n return 1 + sum(map(make_sequences, range(1, n//2+1)))", "RESULTS = [1,1,2,2,4,4,6,6,10,10,14,14,20,20,26,26,36,36,46,46,60,60,74,74,94,94,114,114,140,140,166,166,202,202,238,238,284,284,330,330,390,390,450,450,524,524,598,598,692...
{"fn_name": "make_sequences", "inputs": [[6], [10], [1000]], "outputs": [[6], [14], [1981471878]]}
INTRODUCTORY
PYTHON3
CODEWARS
9,908
def make_sequences(n):
e3d8a929ca42750088e51f6b8fe67823
UNKNOWN
Write a method that will search an array of strings for all strings that contain another string, ignoring capitalization. Then return an array of the found strings. The method takes two parameters, the query string and the array of strings to search, and returns an array. If the string isn't contained in any of the...
["def word_search(query, seq):\n return [x for x in seq if query.lower() in x.lower()] or [\"None\"]", "def word_search(query, seq):\n query = query.lower()\n result = [x for x in seq if query in x.lower()]\n return result if result else ['None']", "import re\n\ndef word_search(query, seq):\n return [w f...
{"fn_name": "word_search", "inputs": [["ab", ["za", "ab", "abc", "zab", "zbc"]], ["aB", ["za", "ab", "abc", "zab", "zbc"]], ["ab", ["za", "aB", "Abc", "zAB", "zbc"]], ["abcd", ["za", "aB", "Abc", "zAB", "zbc"]]], "outputs": [[["ab", "abc", "zab"]], [["ab", "abc", "zab"]], [["aB", "Abc", "zAB"]], [["None"]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,368
def word_search(query, seq):
fba492a3e68e6bc657c429a923a33e88
UNKNOWN
Given a sorted array of numbers, return the summary of its ranges. ## Examples ```python summary_ranges([1, 2, 3, 4]) == ["1->4"] summary_ranges([1, 1, 1, 1, 1]) == ["1"] summary_ranges([0, 1, 2, 5, 6, 9]) == ["0->2", "5->6", "9"] summary_ranges([0, 1, 2, 3, 3, 3, 4, 5, 6, 7]) == ["0->7"] summary_ranges([0, 1, 2, 3, 3...
["def summary_ranges(nums):\n ret, s = [], float('-inf')\n for e, n in zip([s] + nums, nums + [-s]):\n if n - e > 1:\n ret.append(['{}', '{}->{}'][s<e].format(s,e))\n s = n\n return ret[1:]", "def summary_ranges(nums):\n if not nums:\n return []\n ranges = []\n firs...
{"fn_name": "summary_ranges", "inputs": [[[]], [[1, 1, 1, 1]], [[1, 2, 3, 4]], [[0, 1, 2, 5, 6, 9]], [[0, 1, 2, 3, 4, 5, 6, 7]], [[0, 1, 2, 3, 5, 6, 7]], [[0, 1, 2, 3, 4, 5, 6, 7, 9, 10]], [[-2, 0, 1, 2, 3, 4, 5, 6, 7, 9, 10, 12]], [[-3, -2, -1, 0, 2, 3]], [[-2]]], "outputs": [[[]], [["1"]], [["1->4"]], [["0->2", "5->6...
INTRODUCTORY
PYTHON3
CODEWARS
2,857
def summary_ranges(nums):
6305ee20aedd744c4e55ab21ef920dfb
UNKNOWN
KISS stands for Keep It Simple Stupid. It is a design principle for keeping things simple rather than complex. You are the boss of Joe. Joe is submitting words to you to publish to a blog. He likes to complicate things. Define a function that determines if Joe's work is simple or complex. Input will be non emtpy st...
["def is_kiss(words):\n wordsL = words.split(' ')\n l = len(wordsL)\n for word in wordsL:\n if len(word) > l: return \"Keep It Simple Stupid\"\n return \"Good work Joe!\"", "def is_kiss(words):\n words = words.split(\" \")\n return \"Keep It Simple Stupid\" if any(len(word)>len(words) for word ...
{"fn_name": "is_kiss", "inputs": [["Joe had a bad day"], ["Joe had some bad days"], ["Joe is having no fun"], ["Sometimes joe cries for hours"], ["Joe is having lots of fun"], ["Joe is working hard a lot"], ["Joe listened to the noise and it was an onamonapia"], ["Joe listened to the noises and there were some onamonap...
INTRODUCTORY
PYTHON3
CODEWARS
1,645
def is_kiss(words):
84abaeeb2e152b98244892d163025422
UNKNOWN
Oh no! You have stumbled upon a mysterious signal consisting of beeps of various lengths, and it is of utmost importance that you find out the secret message hidden in the beeps. There are long and short beeps, the longer ones roughly three times as long as the shorter ones. Hmm... that sounds familiar. That's righ...
["lm = ['.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-', '-.--', '--..', '-----', '.----', '..---', '...--', '....-', '.....', '-....', '--...', '---..', '----.']\nll = \"abcdefghijklmnopqrstuvwxyz01...
{"fn_name": "decode", "inputs": [[".... . .-.. .-.. --- .-- --- .-. .-.. -.."], [".---- ... - .- -. -.. ..--- -. -.."], [".. .- -- .- - . ... -"], [".- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. ----- .---- ..--- ...-- ....- ..... -.... --... ---.. ---...
INTRODUCTORY
PYTHON3
CODEWARS
897
def decode(s):
f0246c9e3fc6dbd7b180b44822e3a9b9
UNKNOWN
Return a new array consisting of elements which are multiple of their own index in input array (length > 1). Some cases: ``` [22, -6, 32, 82, 9, 25] => [-6, 32, 25] [68, -1, 1, -7, 10, 10] => [-1, 10] [-56,-85,72,-26,-14,76,-27,72,35,-21,-67,87,0,21,59,27,-92,68] => [-85, 72, 0, 68] ```
["def multiple_of_index(l):\n return [l[i] for i in range(1, len(l)) if l[i] % i == 0]", "def multiple_of_index(arr):\n return [val for index, val in enumerate(arr) if index and val % index == 0]\n\n", "def multiple_of_index(arr):\n return [arr[i] for i in range(1,len(arr)) if arr[i] % i == 0]\n", "def multipl...
{"fn_name": "multiple_of_index", "inputs": [[[22, -6, 32, 82, 9, 25]], [[68, -1, 1, -7, 10, 10]], [[11, -11]], [[-56, -85, 72, -26, -14, 76, -27, 72, 35, -21, -67, 87, 0, 21, 59, 27, -92, 68]], [[28, 38, -44, -99, -13, -54, 77, -51]], [[-1, -49, -1, 67, 8, -60, 39, 35]]], "outputs": [[[-6, 32, 25]], [[-1, 10]], [[-11]]...
INTRODUCTORY
PYTHON3
CODEWARS
16,233
def multiple_of_index(arr):
a8ca829b27f7f399bcf18a4d3149471c
UNKNOWN
The number `1035` is the smallest integer that exhibits a non frequent property: one its multiples, `3105 = 1035 * 3`, has its same digits but in different order, in other words, `3105`, is one of the permutations of `1035`. The number `125874` is the first integer that has this property when the multiplier is `2`, th...
["from bisect import bisect\n\nmemo = {3: [3105, 7425, 30105, 31050, 37125, 42741, 44172, 71253, 72441, 74142, 74250, 74628, 74925, 82755, 85725],\n 4: [7128, 8712, 67128, 70416, 71208, 71280, 71328, 71928, 72108, 78912, 79128, 80712, 86712, 87120, 87132, 87192, 87912, 95832],\n 5: [],\n 6: [8316, ...
{"fn_name": "search_permMult", "inputs": [[10000, 7], [5000, 7], [10000, 4], [8000, 4], [5000, 3], [10000, 3]], "outputs": [[1], [0], [2], [1], [1], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,278
def search_permMult(nMax, k):
c367e96d7e45ae6178eeae4de40b93d5
UNKNOWN
Your users passwords were all stole in the Yahoo! hack, and it turns out they have been lax in creating secure passwords. Create a function that checks their new password (passed as a string) to make sure it meets the following requirements: Between 8 - 20 characters Contains only the following characters: (and at ...
["import re;\ndef check_password(s):\n if re.search('^(?=.*?[a-z])(?=.*?[A-Z])(?=.*?\\d)(?=.*?[!@#$%^&*?])[a-zA-Z\\d!@#$%^&*?]{8,20}$', s) :\n return 'valid'\n else:\n return 'not valid'", "import re\n\ndef check_password(s):\n m = re.match(r'(?=.{8,20}$)(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%...
{"fn_name": "check_password", "inputs": [[""], ["password"], ["P1@p"], ["P1@pP1@p"], ["P1@pP1@pP1@pP1@pP1@pP1@p"]], "outputs": [["not valid"], ["not valid"], ["not valid"], ["valid"], ["not valid"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,831
def check_password(s):
22f5cb5c57c2b6a7eeb8bdb8b1f44801
UNKNOWN
## Welcome to my (amazing) kata! You are given a gigantic number to decode. Each number is a code that alternates in a pattern between encoded text and a smaller, encoded number. The pattern's length varies with every test, but the alternation between encoded text and an encoded number will always be there. Followi...
["def decode(number):\n return ', '.join(\n str(int(w, 2)) if i % 2 else\n ''.join( chr(int(w[x:x+3])-4) for x in range(0, len(w), 3) )\n for i, w in enumerate( str(number).strip('98').split('98') )\n )", "def decode(number):\n split = str(number).replace('98', ' ').split()\n split[...
{"fn_name": "decode", "inputs": [[103115104105123101118119981001098], [103115104105123101118119981001098103115104105123101118119981001098103115104105123101118119981001098], [10910111611511211510710912610510611511810811512311912012111610910412010810911911110112010110911998100109810512210511412010811512110710810912011910...
INTRODUCTORY
PYTHON3
CODEWARS
3,108
def decode(number):
c944d59bf4f1e5df3c506ad5447fdd70
UNKNOWN
```if-not:ruby Create a function, that accepts an arbitrary number of arrays and returns a single array generated by alternately appending elements from the passed in arguments. If one of them is shorter than the others, the result should be padded with empty elements. ``` ```if:ruby Create a function, that accepts an ...
["from itertools import chain, zip_longest\n\ndef interleave(*args):\n return list(chain.from_iterable(zip_longest(*args)))", "def interleave(*args):\n max_len = max(map(len,args))\n interleaved = []\n \n for i in range(max_len):\n for arr in args:\n if i < len(arr):\n in...
{"fn_name": "interleave", "inputs": [[[1, 2, 3], ["c", "d", "e"]], [[1, 2, 3], [4, 5]], [[1, 2], [3, 4, 5]], [[null], [null, null], [null, null, null]], [[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[]]], "outputs": [[[1, "c", 2, "d", 3, "e"]], [[1, 4, 2, 5, 3, null]], [[1, 3, 2, 4, null, 5]], [[null, null, null, null, null, nul...
INTRODUCTORY
PYTHON3
CODEWARS
1,464
def interleave(*args):
ffa81c079ff3238485771880beb16c25
UNKNOWN
How many licks does it take to get to the tootsie roll center of a tootsie pop? A group of engineering students from Purdue University reported that its licking machine, modeled after a human tongue, took an average of 364 licks to get to the center of a Tootsie Pop. Twenty of the group's volunteers assumed the lickin...
["def total_licks(env):\n d = 252\n vm = 0\n for k,v in env.items():\n d+=v\n if v > vm:\n vm, km = v, k\n return 'It took ' + str(d) + ' licks to get to the tootsie roll center of a tootsie pop.' + (' The toughest challenge was ' + km + '.' if vm > 0 else '')", "from operator impor...
{"fn_name": "total_licks", "inputs": [[{"freezing temps": 10, "clear skies": -2}], [{"happiness": -5, "clear skies": -2}], [{}], [{"dragons": 100, "evil wizards": 110, "trolls": 50}], [{"white magic": -250}]], "outputs": [["It took 260 licks to get to the tootsie roll center of a tootsie pop. The toughest challenge was...
INTRODUCTORY
PYTHON3
CODEWARS
3,943
def total_licks(env):
e996eefbbe84a0d55cb2f1fda2c65eb1
UNKNOWN
Find the length between 2 co-ordinates. The co-ordinates are made of integers between -20 and 20 and will be given in the form of a 2D array: (0,0) and (5,-7) would be [ [ 0 , 0 ] , [ 5, -7 ] ] The function must return the answer rounded to 2 decimal places in the form of a string. ```python length_of_line([[0, 0],...
["from math import sqrt\ndef length_of_line(array):\n x1, y1, x2, y2 = array[0][0], array[0][1], array[1][0], array[1][1]\n return '{:.2f}'.format((sqrt((x2-x1)**2 + (y2-y1)**2)))", "import math\ndef length_of_line(array):\n return \"{:.02f}\".format(math.sqrt((array[1][0] - array[0][0])**2 + (array[1][1] - array[...
{"fn_name": "length_of_line", "inputs": [[[[0, 0], [1, 1]]], [[[0, 0], [-5, -6]]], [[[0, 0], [10, 15]]], [[[0, 0], [5, 1]]], [[[0, 0], [5, 4]]], [[[0, 0], [-7, 4]]], [[[0, 0], [0, 0]]], [[[-3, 4], [10, 5]]]], "outputs": [["1.41"], ["7.81"], ["18.03"], ["5.10"], ["6.40"], ["8.06"], ["0.00"], ["13.04"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,264
def length_of_line(array):
623f76d343b8e55c9bb6ec8eec680491
UNKNOWN
You are working at a lower league football stadium and you've been tasked with automating the scoreboard. The referee will shout out the score, you have already set up the voice recognition module which turns the ref's voice into a string, but the spoken score needs to be converted into a pair for the scoreboard! e.g...
["def scoreboard(string):\n scores = {'nil': 0, 'one': 1, 'two': 2, 'three': 3, 'four': 4, 'five': 5, 'six': 6, 'seven': 7, 'eight': 8, 'nine': 9}\n return [scores[x] for x in string.split() if x in scores]", "PTS = {w:i for i,w in enumerate('nil one two three four five six seven eight nine'.split())}\n\ndef scor...
{"fn_name": "scoreboard", "inputs": [["The score is four nil"], ["new score: two three"], ["two two"], ["Arsenal just conceded another goal, two nil"]], "outputs": [[[4, 0]], [[2, 3]], [[2, 2]], [[2, 0]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,193
def scoreboard(string):
47f9d623b8649ffc2e1365c445238ef4
UNKNOWN
In mathematics, a [Diophantine equation](https://en.wikipedia.org/wiki/Diophantine_equation) is a polynomial equation, usually with two or more unknowns, such that only the integer solutions are sought or studied. In this kata we want to find all integers `x, y` (`x >= 0, y >= 0`) solutions of a diophantine equation o...
["import math\ndef sol_equa(n):\n res = []\n for i in range(1, int(math.sqrt(n)) + 1):\n if n % i == 0:\n j = n // i\n if (i + j) % 2 == 0 and (j - i) % 4 == 0:\n x = (i + j) // 2\n y = (j - i) // 4\n res.append([x, y])\n \n r...
{"fn_name": "sol_equa", "inputs": [[5], [12], [13], [16], [17], [20], [9001], [9004], [9005], [9008], [90001], [90002], [90004], [90005], [90009], [900001], [900004], [900005], [9000001], [9000004], [90000001], [90000004], [900000012], [9000000041]], "outputs": [[[[3, 1]]], [[[4, 1]]], [[[7, 3]]], [[[4, 0]]], [[[9, 4]]...
INTRODUCTORY
PYTHON3
CODEWARS
3,288
def sol_equa(n):
27266cee1d8d64280d95303d6637177d
UNKNOWN
We are interested in collecting the triples of positive integers ```(a, b, c)``` that fulfill the following equation: ```python a² + b² = c³ ``` The first triple with the lowest values that satisfies the equation we have above is (2, 2 ,2). In effect: ```python 2² + 2² = 2³ 4 + 4 = 8 ``` The first pair of triples tha...
["from bisect import bisect_right as bisect\n\nRES = [[] for _ in range(11)]\n\nfor c in range(1,1001):\n c3 = c**3\n nSol = sum( ((c3-a**2)**.5).is_integer() for a in range(1,int((c3//2)**.5+1)))\n if 0 < nSol < 11: RES[nSol].append(c)\n \n\ndef find_abc_sumsqcube(c_max, nSol):\n return RES[nSol][:bisec...
{"fn_name": "find_abc_sumsqcube", "inputs": [[5, 1], [5, 2], [10, 2], [20, 8], [100, 8], [100, 3], [100, 2]], "outputs": [[[2]], [[5]], [[5, 10]], [[]], [[65, 85]], [[25, 100]], [[5, 10, 13, 17, 20, 26, 29, 34, 37, 40, 41, 45, 52, 53, 58, 61, 68, 73, 74, 80, 82, 89, 90, 97]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,509
def find_abc_sumsqcube(c_max, num_sol):
40590eed802ed16bcf300567f550386e
UNKNOWN
Cascading Style Sheets (CSS) is a style sheet language used for describing the look and formatting of a document written in a markup language. A style sheet consists of a list of rules. Each rule or rule-set consists of one or more selectors, and a declaration block. Selector describes which element it matches. Someti...
["import re\n\ndef compare(a, b):\n return a if specificity(a) > specificity(b) else b\n \ndef specificity(s):\n return [len(re.findall(r, s)) for r in (r'#\\w+', r'\\.\\w+', r'(^| )\\w+')]", "import re\ndef compare(a, b):\n\n def scoreCSS(s):\n d = {'#':0, '.':0, ' ':0}\n for c in re.findall(\"[#\\. ](?=...
{"fn_name": "compare", "inputs": [["body p", "div"], ["body", "html"], ["p a", "span"], ["div p span a", "div p span a b"], ["strong", "p b"], [".first", ".last"], [".foo.bar", ".x .y"], [".x .y", ".foo.bar"], [".red.apple", ".red"], [".test1 .test2.test3", ".test1 .test4 .test5 .test6"], [".box.box-first", ".box"], ["...
INTRODUCTORY
PYTHON3
CODEWARS
3,787
def compare(a, b):
f662ebc54999db784520bb76424fadfc
UNKNOWN
The number `198` has the property that `198 = 11 + 99 + 88, i.e., if each of its digits is concatenated twice and then summed, the result will be the original number`. It turns out that `198` is the only number with this property. However, the property can be generalized so that each digit is concatenated `n` times and...
["def check_concatenated_sum(n, r):\n return abs(n) == sum(int(e*r) for e in str(abs(n)) if r) ", "def check_concatenated_sum(number, n):\n return (10**n - 1)//9 * sum(map(int, str(abs(number)))) == abs(number)", "def check_concatenated_sum(num, n):\n return n and num % int('1' * n) == 0", "def check_concatena...
{"fn_name": "check_concatenated_sum", "inputs": [[2997, 3], [-198, 2], [-13332, 4], [-9, 1], [198, 0], [123, 2], [123456789, 2]], "outputs": [[true], [true], [true], [true], [false], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
928
def check_concatenated_sum(num, n):
ecaa7b69e6867a50f96c8fbfb9fceb43
UNKNOWN
DNA sequencing data can be stored in many different formats. In this Kata, we will be looking at SAM formatting. It is a plain text file where every line (excluding the first header lines) contains data about a "read" from whatever sample the file comes from. Rather than focusing on the whole read, we will take two pie...
["import re\n\ndef is_matched(read):\n total = sum([int(num) for num in re.findall(r'\\d+', read[0])])\n \n if read[0] == str(len(read[1])) + 'M':\n return True\n elif len(read[1]) != total:\n return 'Invalid cigar'\n else:\n return False\n", "import re\n\ndef is_matched(read):\n ...
{"fn_name": "is_matched", "inputs": [[["36M", "CATAATACTTTACCTACTCTCAACAAATGCGGGAGA"]], [["10M6H", "GAGCGAGTGCGCCTTAC"]], [["12S", "TGTTTCTCCAAG"]]], "outputs": [[true], ["Invalid cigar"], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,387
def is_matched(read):
59466f6f3d17bc6c29683a27d8a85413
UNKNOWN
Consider a sequence generation that follows the following steps. We will store removed values in variable `res`. Assume `n = 25`: ```Haskell -> [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25] Let's remove the first number => res = [1]. We get.. -> [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21...
["def solve(n):\n zoznam = [int(i) for i in range (2,n+1)]\n res=[1]\n while zoznam != []:\n res.append(zoznam[0])\n del zoznam[0::zoznam[0]] \n return sum(res)", "def solve(n):\n presum, arr = 1, list(range(2, n + 1))\n while arr[0] < len(arr):\n presum += arr[0]\n d...
{"fn_name": "solve", "inputs": [[7], [25], [50], [100], [1000], [10000]], "outputs": [[18], [107], [304], [993], [63589], [4721110]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,269
def solve(n):
a7c95ad6cba1441c62f971b15805f3e6
UNKNOWN
# Task Consider the following ciphering algorithm: ``` For each character replace it with its code. Concatenate all of the obtained numbers. ``` Given a ciphered string, return the initial one if it is known that it consists only of lowercase letters. Note: here the character's code means its `decimal ASCII code`, t...
["def decipher(cipher):\n out = \"\"\n while cipher:\n l = 2 if cipher[0] == \"9\" else 3\n out += chr(int(cipher[:l]))\n cipher = cipher[l:]\n return out", "import re\n\ndef decipher(cipher):\n return re.sub(r'1?\\d\\d', lambda m: chr(int(m.group())), cipher)\n", "import re\ndef deciph...
{"fn_name": "decipher", "inputs": [["10197115121"], ["98"], ["122"]], "outputs": [["easy"], ["b"], ["z"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,903
def decipher(cipher):
37e57c7c03fcbab58b6a9a0e0bbe9d39
UNKNOWN
One suggestion to build a satisfactory password is to start with a memorable phrase or sentence and make a password by extracting the first letter of each word. Even better is to replace some of those letters with numbers (e.g., the letter `O` can be replaced with the number `0`): * instead of including `i` or `I` p...
["SWAP = {'i': '1', 'I': '1', 'o': '0', 'O': '0', 's': '5', 'S': '5'}\n\n\ndef make_password(phrase):\n return ''.join(SWAP.get(a[0], a[0]) for a in phrase.split())\n", "def make_password(phrase):\n new = \"\"\n phrase = phrase.replace(\"i\", \"1\").replace(\"I\", \"1\")\n phrase = phrase.replace(\"o\", \"0...
{"fn_name": "make_password", "inputs": [["Give me liberty or give me death"], ["Keep Calm and Carry On"]], "outputs": [["Gml0gmd"], ["KCaC0"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,649
def make_password(phrase):
21a3c3d0357383a8f072ebd640530088
UNKNOWN
Hofstadter sequences are a family of related integer sequences, among which the first ones were described by an American professor Douglas Hofstadter in his book Gödel, Escher, Bach. ### Task Today we will be implementing the rather chaotic recursive sequence of integers called Hofstadter Q. The Hofstadter Q is defin...
["def hofstadter_Q(n):\n try:\n return hofstadter_Q.seq[n]\n except IndexError:\n ans = hofstadter_Q(n - hofstadter_Q(n - 1)) + hofstadter_Q(n - hofstadter_Q(n - 2))\n hofstadter_Q.seq.append(ans)\n return ans\nhofstadter_Q.seq = [None, 1, 1]", "def hofstadter_Q(n):\n q = [1, 1]\n ...
{"fn_name": "hofstadter_Q", "inputs": [[1], [3], [7], [10], [100], [1000]], "outputs": [[1], [2], [5], [6], [56], [502]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,923
def hofstadter_Q(n):
6034b68de1ee14776b32ababaee812cc
UNKNOWN
It's 3AM and you get the dreaded call from a customer: the program your company sold them is hanging. You eventually trace the problem down to a call to a function named `mystery`. Usually, `mystery` works fine and produces an integer result for an integer input. However, on certain inputs, the `mystery` function just ...
["def mystery_solved(n):\n \"\"\"\nRecreated mystery function from bytecode using the dis module.\n How to print the bytecode: import dis\n print(dis.dis(mystery)) \n Apparently, \n the function is a wrong implementation of the 5n+1 problem -> \n https://math.s...
{"fn_name": "wrap_mystery", "inputs": [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [18], [19], [20], [21], [22], [23], [24], [25], [26], [28], [29], [30], [31], [32], [33], [35], [36], [37], [38], [39], [40], [41], [42], [44], [45], [46], [47], [48], [49], [50], [51], [52], [5...
INTRODUCTORY
PYTHON3
CODEWARS
1,635
def wrap_mystery(n):
73ba538a2edea489652239b1e724acaf
UNKNOWN
Mr. Scrooge has a sum of money 'P' that he wants to invest. Before he does, he wants to know how many years 'Y' this sum 'P' has to be kept in the bank in order for it to amount to a desired sum of money 'D'. The sum is kept for 'Y' years in the bank where interest 'I' is paid yearly. After paying taxes 'T' for the ye...
["def calculate_years(principal, interest, tax, desired):\n years = 0\n \n while principal < desired:\n principal += (interest * principal) * (1 - tax)\n years += 1\n \n return years\n", "from math import ceil, log\n\ndef calculate_years(principal, interest, tax, desired):\n if princ...
{"fn_name": "calculate_years", "inputs": [[1000, 0.05, 0.18, 1100], [1000, 0.01625, 0.18, 1200], [1000, 0.05, 0.18, 1000]], "outputs": [[3], [14], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,477
def calculate_years(principal, interest, tax, desired):
68cc6edebe66ade2a9d402ce0cd1731c
UNKNOWN
### Background We **all** know about "balancing parentheses" (plus brackets, braces and chevrons) and even balancing characters that are identical. Read that last sentence again, I balanced different characters and identical characters twice and you didn't even notice... :) ### Kata Your challenge in this kata is ...
["def is_balanced(s, caps):\n stack = []\n openers, closers = caps[::2], caps[1::2]\n for char in s:\n if char in openers:\n if char in closers and stack and stack[-1] == char:\n stack.pop()\n else:\n stack.append(char)\n elif char in closers:\n...
{"fn_name": "is_balanced", "inputs": [["(Sensei says yes!)", "()"], ["(Sensei says no!", "()"], ["(Sensei [says] yes!)", "()[]"], ["(Sensei [says) no!]", "()[]"], ["Sensei says -yes-!", "--"], ["Sensei -says no!", "--"], ["Hello Mother can you hear me?", "()"], ["(Hello Mother can you hear me?)", "()"], ["(Hello Mother...
INTRODUCTORY
PYTHON3
CODEWARS
2,551
def is_balanced(source, caps):
e7aad9f87dd58ed47d4d4eb6525b2b49
UNKNOWN
You probably know the "like" system from Facebook and other pages. People can "like" blog posts, pictures or other items. We want to create the text that should be displayed next to such an item. Implement a function `likes :: [String] -> String`, which must take in input array, containing the names of people who like...
["def likes(names):\n n = len(names)\n return {\n 0: 'no one likes this',\n 1: '{} likes this', \n 2: '{} and {} like this', \n 3: '{}, {} and {} like this', \n 4: '{}, {} and {others} others like this'\n }[min(4, n)].format(*names[:3], others=n-2)", "def likes(names):\n i...
{"fn_name": "likes", "inputs": [[[]], [["Peter"]], [["Jacob", "Alex"]], [["Max", "John", "Mark"]], [["Alex", "Jacob", "Mark", "Max"]]], "outputs": [["no one likes this"], ["Peter likes this"], ["Jacob and Alex like this"], ["Max, John and Mark like this"], ["Alex, Jacob and 2 others like this"]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,069
def likes(names):
85786e3c2fd8817e5938896821374b51
UNKNOWN
Your task is to convert a given number into a string with commas added for easier readability. The number should be rounded to 3 decimal places and the commas should be added at intervals of three digits before the decimal point. There does not need to be a comma at the end of the number. You will receive both positi...
["def commas(num):\n return \"{:,.3f}\".format(num).rstrip(\"0\").rstrip(\".\")", "def commas(num):\n return f'{num:,.3f}'.rstrip('0').rstrip('.')", "import re\n\ndef commas(num):\n if isinstance(num, int):\n return format(num, ',')\n else:\n return re.sub('\\.?0+$', '', format(round(num, 3), ...
{"fn_name": "commas", "inputs": [[1], [1000], [100.2346], [1000000000.23], [9123.212], [-1], [-1000000.123], [-2000.0], [-999.9999], [-1234567.0001236]], "outputs": [["1"], ["1,000"], ["100.235"], ["1,000,000,000.23"], ["9,123.212"], ["-1"], ["-1,000,000.123"], ["-2,000"], ["-1,000"], ["-1,234,567"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,240
def commas(num):
789a83217f3d64b4828e0e4e830d20e6
UNKNOWN
Consider the following expansion: ```Haskell solve("3(ab)") = "ababab" -- "ab" repeats 3 times solve("2(a3(b))" = "abbbabbb" -- "a3(b)" == "abbb" repeats twice. ``` Given a string, return the expansion of that string. Input will consist of only lowercase letters and numbers (1 to 9) in valid parenthesis. There will ...
["def solve(s):\n s1 = s[::-1]\n s2 = ''\n for i in s1:\n if i.isalpha():\n s2 += i\n elif i.isdigit():\n s2 = s2*int(i)\n return s2[::-1]", "import re\n\ndef solve(s):\n ops, parts = [], ['']\n for c in re.findall(r'\\d*\\(|\\)|[a-z]+', s):\n if c == ')':\n ...
{"fn_name": "solve", "inputs": [["3(ab)"], ["2(a3(b))"], ["3(b(2(c)))"], ["k(a3(b(a2(c))))"]], "outputs": [["ababab"], ["abbbabbb"], ["bccbccbcc"], ["kabaccbaccbacc"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,447
def solve(st):
47cfc6e0a0cb418833945af71d2506d6
UNKNOWN
A faro shuffle of a deck of playing cards is a shuffle in which the deck is split exactly in half and then the cards in the two halves are perfectly interwoven, such that the original bottom card is still on the bottom and the original top card is still on top. For example, faro shuffling the list ```python ['ace', 't...
["def faro_cycles(n):\n x, cnt = 2, 1\n while x != 1 and n > 3:\n cnt += 1\n x = x*2 % (n-1)\n return cnt", "def faro_cycles(deck_size):\n arr, count = list(range(deck_size)), 0\n original_arr = arr\n while True:\n arr = arr[0:deck_size:2] + arr[1:deck_size:2]\n count += 1\...
{"fn_name": "faro_cycles", "inputs": [[2], [52], [542], [1250], [1954]], "outputs": [[1], [8], [540], [156], [30]]}
INTRODUCTORY
PYTHON3
CODEWARS
7,206
def faro_cycles(deck_size):
4212dc99a19a4842b6d7a098caf5d6ee
UNKNOWN
In his publication Liber Abaci Leonardo Bonacci, aka Fibonacci, posed a problem involving a population of idealized rabbits. These rabbits bred at a fixed rate, matured over the course of one month, had unlimited resources, and were immortal. Beginning with one immature pair of these idealized rabbits that produce b p...
["def fib_rabbits(n, b):\n (i, a) = (1, 0)\n for m in range(n):\n (i, a) = (a * b, a + i)\n return a\n", "def fib_rabbits(n, b):\n x, y = 0, 1\n for _ in range(n):\n x, y = y, x * b + y\n return x", "def fib_rabbits(n, m):\n a,b = 0,1\n for i in range(n):\n a,b = b, b+a*m\n ...
{"fn_name": "fib_rabbits", "inputs": [[0, 4], [1, 4], [4, 0], [6, 3], [8, 12], [7, 4], [9, 8], [10, 2], [11, 33], [100, 3], [40, 6], [4, 100]], "outputs": [[0], [1], [1], [40], [8425], [181], [10233], [341], [58212793], [465790837923166086127602033842234887], [2431532871909060205], [201]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,485
def fib_rabbits(n, b):
71168ae59ea872e0a04c19ddb180c8ef
UNKNOWN
Chingel is practicing for a rowing competition to be held on this saturday. He is trying his best to win this tournament for which he needs to figure out how much time it takes to cover a certain distance. **Input** You will be provided with the total distance of the journey, speed of the boat and whether he is goin...
["def time(distance,boat_speed,stream):\n return round(distance/(boat_speed+int(stream.split()[-1])),2) if stream[0]==\"D\" else round(distance/(boat_speed-int(stream.split()[-1])), 2)", "def time(d, v, s):\n return round(d / (v + int(s.split()[1]) * (1 if s[0] == \"D\" else -1)), 2)", "def time(d, v, s):\n r...
{"fn_name": "time", "inputs": [[24, 10, "Downstream 2"], [24, 14, "Upstream 2"], [54, 28, "Downstream 3"], [60, 45, "Upstream 15"], [60, 45, "Downstream 15"]], "outputs": [[2], [2], [1.74], [2], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,143
def time(distance, boat_speed, stream):
029d69a67efb5dce730a5470306e8dc3
UNKNOWN
## Grade book Complete the function so that it finds the mean of the three scores passed to it and returns the letter value associated with that grade. Numerical Score | Letter Grade --- | --- 90 <= score <= 100 | 'A' 80 <= score < 90 | 'B' 70 <= score < 80 | 'C' 60 <= score < 70 | 'D' 0 <= s...
["def get_grade(s1, s2, s3):\n m = (s1 + s2 + s3) / 3.0\n if 90 <= m <= 100:\n return 'A'\n elif 80 <= m < 90:\n return 'B'\n elif 70 <= m < 80:\n return 'C'\n elif 60 <= m < 70:\n return 'D'\n return \"F\"\n", "def get_grade(s1, s2, s3):\n mean = sum([s1,s2,s3])/3\n ...
{"fn_name": "get_grade", "inputs": [[95, 90, 93], [100, 85, 96], [92, 93, 94], [100, 100, 100], [70, 70, 100], [82, 85, 87], [84, 79, 85], [70, 70, 70], [75, 70, 79], [60, 82, 76], [65, 70, 59], [66, 62, 68], [58, 62, 70], [44, 55, 52], [48, 55, 52], [58, 59, 60], [0, 0, 0]], "outputs": [["A"], ["A"], ["A"], ["A"], ["B...
INTRODUCTORY
PYTHON3
CODEWARS
24,181
def get_grade(s1, s2, s3):
619338178385ab04c6e1f33eb0223489
UNKNOWN
Here we have a function that help us spam our hearty laughter. But is not working! I need you to find out why... Expected results: ```python spam(1) ==> "hue" spam(6) ==> "huehuehuehuehuehue" spam(14) ==> "huehuehuehuehuehuehuehuehuehuehuehuehuehue" ```
["#fix this code!\ndef spam(number):\n return 'hue' * number", "def spam(number):\n return ''.join(['hue' for i in range(number)])", "def spam(number):\n return number * 'hue'", "def spam(i):\n return 'hue' * int(i)", "#fix this code!\ndef spam(n):\n return 'hue'*n", "#fix this code!\ndef spam(number):\n...
{"fn_name": "spam", "inputs": [[1], [6], [14]], "outputs": [["hue"], ["huehuehuehuehuehue"], ["huehuehuehuehuehuehuehuehuehuehuehuehuehue"]]}
INTRODUCTORY
PYTHON3
CODEWARS
497
def spam(number):
c7da3057598919f491d15af2d0b206f8
UNKNOWN
# Task Let's define a `parameter` of number `n` as the least common multiple (LCM) of the sum of its digits and their product. Calculate the parameter of the given number `n`. # Input/Output `[input]` integer `n` A positive integer. It is guaranteed that no zero appears in `n`. `[output]` an integer The paramet...
["from fractions import Decimal, gcd\nfrom operator import mul\nfrom functools import reduce\n\nlcm = lambda a, b=1: a * b // gcd(a, b)\n\ndef parameter(n):\n digits = Decimal(n).as_tuple().digits\n return lcm(sum(digits), reduce(mul, digits))", "from math import gcd\n\ndef parameter(n):\n s, p = 0, 1\n for...
{"fn_name": "parameter", "inputs": [[1234], [1], [2], [22], [11], [239], [999999999], [91], [344], [123456789]], "outputs": [[120], [1], [2], [4], [2], [378], [387420489], [90], [528], [362880]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,367
def parameter(n):
494ba9191ea7d9f0b79d6efaa7ca2c85
UNKNOWN
If I give you a date, can you tell me what day that date is? For example, december 8th, 2015 is a tuesday. Your job is to write the function ```day(d)``` which takes a string representation of a date as input, in the format YYYYMMDD. The example would be "20151208". The function needs to output the string representati...
["import datetime\nimport calendar\n\ndef day(date):\n return calendar.day_name[datetime.datetime.strptime(date,\"%Y%m%d\").weekday()]", "from datetime import datetime\n\nWEEKDAYS = ('Monday', 'Tuesday', 'Wednesday', 'Thursday',\n 'Friday', 'Saturday', 'Sunday')\n\n\ndef day(date):\n return WEEKDAYS[da...
{"fn_name": "day", "inputs": [["20151208"], ["20140728"], ["20160229"], ["20160301"], ["19000228"], ["19000301"]], "outputs": [["Tuesday"], ["Monday"], ["Monday"], ["Tuesday"], ["Wednesday"], ["Thursday"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,368
def day(date):
7038f3ba405060dacb59ae77e75aecaf
UNKNOWN
You're familiar with [list slicing](https://docs.python.org/3/library/functions.html#slice) in Python and know, for example, that: ```python >>> ages = [12, 14, 63, 72, 55, 24] >>> ages[2:4] [63, 72] >>> ages[2:] [63, 72, 55, 24] >>> ages[:3] [12, 14, 63] ``` write a function `inverse_slice()` that takes three argume...
["def inverse_slice(items, a, b):\n return items[:a] + items[b:]", "def inverse_slice(items, a, b):\n del items[a:b]\n return items", "def inverse_slice(items, a, b):\n part1 = items[:a]\n part2 = items[b:]\n return (part1+part2)", "def inverse_slice(items, a, b):\n return [v for i,v in enumerate(ite...
{"fn_name": "inverse_slice", "inputs": [[[12, 14, 63, 72, 55, 24], 2, 4], [[12, 14, 63, 72, 55, 24], 0, 3], [["Intuition", "is", "a", "poor", "guide", "when", "facing", "probabilistic", "evidence"], 5, 13]], "outputs": [[[12, 14, 55, 24]], [[72, 55, 24]], [["Intuition", "is", "a", "poor", "guide"]]]}
INTRODUCTORY
PYTHON3
CODEWARS
888
def inverse_slice(items, a, b):
58bedeb7b2a9aafd4b60e2593de5c3a1
UNKNOWN
Write a function that returns a sequence (index begins with 1) of all the even characters from a string. If the string is smaller than two characters or longer than 100 characters, the function should return "invalid string". For example: ````` "abcdefghijklm" --> ["b", "d", "f", "h", "j", "l"] "a" --> "i...
["def even_chars(st):\n if len(st) < 2 or len(st)> 100:\n return 'invalid string'\n else:\n return [st[i] for i in range(1, len(st), 2)]\n", "def even_chars(st): \n return list(st[1::2]) if 2<=len(st)<=100 else \"invalid string\" ", "def even_chars(stg): \n return list(stg[1::2]) if 1 < len(st...
{"fn_name": "even_chars", "inputs": [["a"], ["abcdefghijklm"], ["aBc_e9g*i-k$m"], [""], ["ab"], ["aiqbuwbjqwbckjdwbwkqbefhglqhfjbwqejbcadn.bcaw.jbhwefjbwqkvbweevkj.bwvwbhvjk.dsvbajdv.hwuvghwuvfhgw.vjhwncv.wecnaw.ecnvw.kejvhnw.evjkhweqv.kjhwqeev.kjbhdjk.vbaewkjva"]], "outputs": [["invalid string"], [["b", "d", "f", "h",...
INTRODUCTORY
PYTHON3
CODEWARS
1,240
def even_chars(st):
0b88c824f5328f7dcd78c62248d994b4
UNKNOWN
Write function bmi that calculates body mass index (bmi = weight / height ^ 2). if bmi <= 18.5 return "Underweight" if bmi <= 25.0 return "Normal" if bmi <= 30.0 return "Overweight" if bmi > 30 return "Obese"
["def bmi(weight, height):\n bmi = weight / height ** 2\n if bmi <= 18.5:\n return \"Underweight\"\n elif bmi <= 25:\n return \"Normal\"\n elif bmi <= 30:\n return \"Overweight\"\n else:\n return \"Obese\"", "def bmi(weight, height):\n b = weight / height ** 2\n return [...
{"fn_name": "bmi", "inputs": [[50, 1.8], [80, 1.8], [90, 1.8], [110, 1.8], [50, 1.5]], "outputs": [["Underweight"], ["Normal"], ["Overweight"], ["Obese"], ["Normal"]]}
INTRODUCTORY
PYTHON3
CODEWARS
25,008
def bmi(weight, height):
77f4ccfa95d152e5fef470a00c51bea4
UNKNOWN
In this Kata, you will be given an array of strings and your task is to remove all consecutive duplicate letters from each string in the array. For example: * `dup(["abracadabra","allottee","assessee"]) = ["abracadabra","alote","asese"]`. * `dup(["kelless","keenness"]) = ["keles","kenes"]`. Strings will be ...
["from itertools import groupby\n\ndef dup(arry):\n return [\"\".join(c for c, grouper in groupby(i)) for i in arry]", "import re\n\ndef dup(arry):\n return list(map(lambda s: re.sub(r'(\\w)\\1+', r'\\1', s), arry))", "def dup(arry):\n array_new = []\n for string in arry:\n string_new = \"\"\n ...
{"fn_name": "dup", "inputs": [[["ccooddddddewwwaaaaarrrrsssss", "piccaninny", "hubbubbubboo"]], [["abracadabra", "allottee", "assessee"]], [["kelless", "keenness"]], [["Woolloomooloo", "flooddoorroommoonlighters", "chuchchi"]], [["adanac", "soonness", "toolless", "ppellee"]], [["callalloo", "feelless", "heelless"]], [[...
INTRODUCTORY
PYTHON3
CODEWARS
1,729
def dup(arry):
5d416f6d009a8ef2ab6d74580ff3b1de
UNKNOWN
Trigrams are a special case of the n-gram, where n is 3. One trigram is a continious sequence of 3 chars in phrase. [Wikipedia](https://en.wikipedia.org/wiki/Trigram) - return all trigrams for the given phrase - replace spaces with \_ - return an empty string for phrases shorter than 3 Example: trigrams('the qu...
["def trigrams(phrase):\n phrase = phrase.replace(\" \", \"_\")\n return \" \".join([phrase[i:i+3]for i in range(len(phrase)-2)])\n", "def trigrams(phrase):\n solution = ''\n if len(phrase) < 3:\n return solution\n phrase = phrase.replace(' ','_')\n for i in range(len(phrase)-2):\n solut...
{"fn_name": "trigrams", "inputs": [["the quick red"], ["Hi"]], "outputs": [["the he_ e_q _qu qui uic ick ck_ k_r _re red"], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,790
def trigrams(phrase):
c80c726accda7f21c95b697fe73ebc09
UNKNOWN
The citizens of Codeland read each word from right to left, meaning that lexicographical comparison works differently in their language. Namely, string ```a``` is lexicographically smaller than string ```b``` if either: ```a``` is a suffix of ```b``` (in common sense, i.e. ```b``` ends with a substring equal to ```a```...
["def unusual_lex_order(a):\n return sorted(a, key=lambda k: k[::-1])", "def unusual_lex_order(arr):\n return sorted(arr, key=lambda s: s[::-1])", "def unusual_lex_order(arr):\n return sorted(arr, key = lambda x: x[::-1])", "def unusual_lex_order(arr):\n return sorted(arr, key = lambda word: word[::-1])", "...
{"fn_name": "unusual_lex_order", "inputs": [[["nigeb", "ta", "eht", "gninnigeb"]], [["a", "b", "a", "d", "c"]]], "outputs": [[["ta", "nigeb", "gninnigeb", "eht"]], [["a", "a", "b", "c", "d"]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,175
def unusual_lex_order(arr):
8cd90d99ef3d5edeedcc550c8746a976
UNKNOWN
# Your Task The city of Darkishland has a strange hotel with infinite rooms. The groups that come to this hotel follow the following rules: * At the same time only members of one group can rent the hotel. * Each group comes in the morning of the check-in day and leaves the hotel in the evening of the check-out day. ...
["from math import floor\ndef group_size(S, D):\n return floor((2*D+S*(S-1))**.5+.5)", "from math import sqrt, ceil\n\n# 1st group spends in the hotel s days,\n# 2nd group - s + 1 days,\n# 3rd group - s + 2 days,\n# ...,\n# nth group - s + n - 1 days.\n#\n# The total number of days for n groups: n * (s + s + n -...
{"fn_name": "group_size", "inputs": [[1, 6], [3, 10], [3, 14], [10, 1000], [1, 1000], [5, 4], [5, 7], [10000, 1000000000000000], [2, 20000000000000], [10, 900000000000000000], [34545, 565], [234234, 6577], [10, 10]], "outputs": [[3], [5], [6], [46], [45], [5], [6], [44721361], [6324555], [1341640786], [34545], [234234]...
INTRODUCTORY
PYTHON3
CODEWARS
1,784
def group_size(S, D):
f0e69e970130d011433cb1ca8cbf8924
UNKNOWN
Philip's just turned four and he wants to know how old he will be in various years in the future such as 2090 or 3044. His parents can't keep up calculating this so they've begged you to help them out by writing a programme that can answer Philip's endless questions. Your task is to write a function that takes two par...
["def calculate_age(year_of_birth, current_year):\n diff = abs(current_year - year_of_birth)\n plural = '' if diff == 1 else 's'\n if year_of_birth < current_year:\n return 'You are {} year{} old.'.format(diff, plural)\n elif year_of_birth > current_year:\n return 'You will be born in {} year{...
{"fn_name": "calculate_age", "inputs": [[2012, 2016], [1989, 2016], [2000, 2090], [2000, 1990], [2000, 2000], [900, 2900], [2010, 1990], [2010, 1500], [2011, 2012], [2000, 1999]], "outputs": [["You are 4 years old."], ["You are 27 years old."], ["You are 90 years old."], ["You will be born in 10 years."], ["You were bo...
INTRODUCTORY
PYTHON3
CODEWARS
41,154
def calculate_age(year_of_birth, current_year):
caae82e36089515fff264b4f3d4e729f
UNKNOWN
The cockroach is one of the fastest insects. Write a function which takes its speed in km per hour and returns it in cm per second, rounded down to the integer (= floored). For example: ```python cockroach_speed(1.08) == 30 ``` Note! The input is a Real number (actual type is language dependent) and is >= 0. The res...
["def cockroach_speed(s):\n return s // 0.036", "def cockroach_speed(s):\n cm_per_km = 100000\n sec_per_hour = 3600\n return int(s * cm_per_km / sec_per_hour)", "def cockroach_speed(s):\n cm_per_km = 100000\n sec_per_hour = 3600\n return s * cm_per_km // sec_per_hour\n", "def cockroach_speed(s):\n ...
{"fn_name": "cockroach_speed", "inputs": [[1.08], [1.09], [0]], "outputs": [[30], [30], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
10,284
def cockroach_speed(s):
ea406eae81395f7ca618d605e966cc67
UNKNOWN
Create a function which answers the question "Are you playing banjo?". If your name starts with the letter "R" or lower case "r", you are playing banjo! The function takes a name as its only argument, and returns one of the following strings: ``` name + " plays banjo" name + " does not play banjo" ``` Names given a...
["def areYouPlayingBanjo(name):\n return name + (' plays' if name[0].lower() == 'r' else ' does not play') + \" banjo\";", "def areYouPlayingBanjo(name):\n if name[0].lower() == 'r':\n return name + ' plays banjo'\n else:\n return name + ' does not play banjo'", "def areYouPlayingBanjo(name):\n ...
{"fn_name": "areYouPlayingBanjo", "inputs": [["Adam"], ["Paul"], ["Ringo"], ["bravo"], ["rolf"]], "outputs": [["Adam does not play banjo"], ["Paul does not play banjo"], ["Ringo plays banjo"], ["bravo does not play banjo"], ["rolf plays banjo"]]}
INTRODUCTORY
PYTHON3
CODEWARS
17,678
def areYouPlayingBanjo(name):
ea11c4f8c164ba643e16e04728cc7a66
UNKNOWN
Mobile Display Keystrokes Do you remember the old mobile display keyboards? Do you also remember how inconvenient it was to write on it? Well, here you have to calculate how much keystrokes you have to do for a specific word. This is the layout: Return the amount of keystrokes of input str (! only letters, digits ...
["def mobile_keyboard(s):\n lookup = {\n c: i \n for s in \"1,2abc,3def,4ghi,5jkl,6mno,7pqrs,8tuv,9wxyz,*,0,#\".split(\",\") \n for i, c in enumerate(s, start=1)\n }\n return sum(lookup[c] for c in s)", "def mobile_keyboard(s):\n return sum((x+1) for x in range(5) for c in s if c in ['0...
{"fn_name": "mobile_keyboard", "inputs": [[""], ["123"], ["codewars"], ["zruf"], ["thisisasms"], ["longwordwhichdontreallymakessense"]], "outputs": [[0], [3], [26], [16], [37], [107]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,740
def mobile_keyboard(s):
b30166120be2e0e5a2231b41a98abad2
UNKNOWN
# altERnaTIng cAsE <=> ALTerNAtiNG CaSe Define `String.prototype.toAlternatingCase` (or a similar function/method *such as* `to_alternating_case`/`toAlternatingCase`/`ToAlternatingCase` in your selected language; **see the initial solution for details**) such that each lowercase letter becomes uppercase and each upper...
["def to_alternating_case(string):\n return string.swapcase()", "def to_alternating_case(string):\n return ''.join([c.upper() if c.islower() else c.lower() for c in string])", "to_alternating_case = str.swapcase", "def to_alternating_case(string):\n strn = \"\"\n for i in string:\n if i.isupper():\n ...
{"fn_name": "to_alternating_case", "inputs": [["hello world"], ["HELLO WORLD"], ["hello WORLD"], ["HeLLo WoRLD"], ["12345"], ["1a2b3c4d5e"], ["String.prototype.toAlternatingCase"]], "outputs": [["HELLO WORLD"], ["hello world"], ["HELLO world"], ["hEllO wOrld"], ["12345"], ["1A2B3C4D5E"], ["sTRING.PROTOTYPE.TOaLTERNATIN...
INTRODUCTORY
PYTHON3
CODEWARS
22,327
def to_alternating_case(string):
a52660790c959dbe8b592667550c601b
UNKNOWN
You're in ancient Greece and giving Philoctetes a hand in preparing a training exercise for Hercules! You've filled a pit with two different ferocious mythical creatures for Hercules to battle! The formidable **"Orthus"** is a 2 headed dog with 1 tail. The mighty **"Hydra"** has 5 heads and 1 tail. Before Hercules ...
["def beasts(heads, tails):\n orthus = (5 * tails - heads) / 3\n hydra = tails - orthus\n return [orthus, hydra] if orthus >= 0 and hydra >= 0 else 'No solutions'", "def beasts(h,t):\n out= [(5*t-h)/3, (h-2*t)/3]\n return all(x.is_integer() and x>=0 for x in out) and out or 'No solutions'", "def beasts(h...
{"fn_name": "beasts", "inputs": [[123, 39], [371, 88], [24, 12], [113, 37], [635, 181], [25, 555], [12, 25], [54, 956], [5455, 54956], [0, 0], [-1, -1], [-45, 5], [99, 0], [0, 99], [5, -55]], "outputs": [[[24, 15]], [[23, 65]], [[12, 0]], [[24, 13]], [[90, 91]], ["No solutions"], ["No solutions"], ["No solutions"], ["N...
INTRODUCTORY
PYTHON3
CODEWARS
1,848
def beasts(heads, tails):
8b7c257451a3ef2557b1afcf4170f75c
UNKNOWN
Two fishing vessels are sailing the open ocean, both on a joint ops fishing mission. On a high stakes, high reward expidition - the ships have adopted the strategy of hanging a net between the two ships. The net is **40 miles long**. Once the straight-line distance between the ships is greater than 40 miles, the net ...
["from math import sin, radians\n\ndef find_time_to_break(bearing_A, bearing_B):\n a = radians(abs(bearing_A - bearing_B) / 2)\n return 40 / (3 * sin(a)) if a else float(\"inf\")", "def find_time_to_break(bearing_A, bearing_B):\n import math\n if bearing_A == bearing_B:\n return float(\"inf\")\n r...
{"fn_name": "find_time_to_break", "inputs": [[90, 90]], "outputs": [[Infinity]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,043
def find_time_to_break(bearing_A, bearing_B):
aebb8ba02c9c8abaa49c0e9f1011b73d
UNKNOWN
< PREVIOUS KATA NEXT KATA > ## Task: You have to write a function `pattern` which returns the following Pattern(See Examples) upto desired number of rows. * Note:```Returning``` the pattern is not the same as ```Printing``` the pattern. ### Parameters: pattern( n , x , y...
["def pattern(n, x=1, y=1, *args):\n if n < 1:\n return \"\"\n result = []\n for i in range(1, n + 1):\n line = \" \" * (i - 1) + str(i % 10) + \" \" * (n - i)\n result.append((line + line[::-1][1:]) + (line[1:] + line[::-1][1:]) * (x - 1))\n return \"\\n\".join((result + result[::-1][1...
{"fn_name": "pattern", "inputs": [[4, 2, 3], [3, -29, 4], [5, -28, 0], [7, 2], [10, -2999], [5], [4, 2, 3, 5, 7, -8], [-3, -5, 0], [-11, 1, 3], [-25, 5, -9], [-25, -11, 9], [-3, -5], [-11, 3], [-9999999], [-25, 5, -9, 55, -8, -7, 8], [0, 1, 2], [0, -1, 0], [0, -1, 2], [0, 1, -2], [0, 1], [0, -1], [0], [0, -5, 8, -7, 10...
INTRODUCTORY
PYTHON3
CODEWARS
3,698
def pattern(n, x=1, y=1, *args):
3904664406920ee9b6db69f49969d5dd
UNKNOWN
*Based on this Numberphile video: https://www.youtube.com/watch?v=Wim9WJeDTHQ* --- Multiply all the digits of a nonnegative integer `n` by each other, repeating with the product until a single digit is obtained. The number of steps required is known as the **multiplicative persistence**. Create a function that calcu...
["def per(n):\n r = []\n while n>=10:\n p=1\n for i in str(n):\n p=p*int(i)\n r.append(p)\n n = p\n return r", "from functools import reduce\n\ndef per(n):\n r = []\n p = reduce(lambda a, b: a*b, map(int, str(n)))\n return r if p == n else [p] + per(p)", "from fu...
{"fn_name": "per", "inputs": [[1234567890], [123456789], [12345678], [1234567], [123456], [12345], [2379], [777], [25], [277777788888899], [3778888999]], "outputs": [[[0]], [[362880, 0]], [[40320, 0]], [[5040, 0]], [[720, 0]], [[120, 0]], [[378, 168, 48, 32, 6]], [[343, 36, 18, 8]], [[10, 0]], [[4996238671872, 43893964...
INTRODUCTORY
PYTHON3
CODEWARS
1,812
def per(n):
dfbfe1815d230e6d02a775edf669ce55
UNKNOWN
# Task You are given a string consisting of `"D", "P" and "C"`. A positive integer N is called DPC of this string if it satisfies the following properties: ``` For each i = 1, 2, ... , size of the string: If i-th character is "D", then N can be divided by i If i-th character is "P", then N and i should be rela...
["from fractions import gcd\n\ndef DPC_sequence(s):\n n=1\n for i,c in enumerate(s,1):\n if c=='D':\n n=(n*i)//gcd(n,i)\n elif c=='P':\n if gcd(n,i)!=1: return -1\n elif c=='C':\n if gcd(n,i) in (1,i): return -1\n return n\n", "from fractions import gcd\n\n...
{"fn_name": "DPC_sequence", "inputs": [["DDPDD"], ["DDDDPDDCCCDDPDCCPCDCDDPCPCCDDCD"], ["DPCPDPPPDCPDPDPC"], ["DDDDDDCD"], ["CDDDPDDD"], ["DDDDDDPCCDPDPP"]], "outputs": [[20], [15782844], [-1], [-1], [-1], [-1]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,407
def DPC_sequence(s):
05a0a8a4f47ce868d0b0341da0d9ccae
UNKNOWN
# Task Christmas is coming, and your task is to build a custom Christmas tree with the specified characters and the specified height. # Inputs: - `chars`: the specified characters. - `n`: the specified height. A positive integer greater than 2. # Output: - A multiline string. Each line is separated by `\n`. A tree ...
["def custom_christmas_tree(chars, n):\n from itertools import cycle\n it = cycle(chars)\n tree = [' '.join(next(it) for j in range(i)).center(2 * n).rstrip() for i in range(1, n + 1)]\n tree.extend('|'.center(2 * n).rstrip() for _ in range(n // 3))\n return '\\n'.join(tree)", "from itertools import cycl...
{"fn_name": "custom_christmas_tree", "inputs": [["*@o", 3], ["*@o", 6], ["1234", 6], ["123456789", 3]], "outputs": [[" *\n @ o\n* @ o\n |"], [" *\n @ o\n * @ o\n * @ o *\n @ o * @ o\n* @ o * @ o\n |\n |"], [" 1\n 2 3\n 4 1 2\n 3 4 1 2\n 3 4 1 2 3\n4 1 2 3 4 1\n |\n |"], [" 1\n 2 3...
INTRODUCTORY
PYTHON3
CODEWARS
4,704
def custom_christmas_tree(chars, n):
f8322e7becac031ca6759141e432362d
UNKNOWN
The Fibonacci numbers are the numbers in the following integer sequence (Fn): >0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, ... such as >F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1. Given a number, say prod (for product), we search two Fibonacci numbers F(n) and F(n+1) verifying >F(n) * F(n+1) = prod. ...
["def productFib(prod):\n a, b = 0, 1\n while prod > a * b:\n a, b = b, a + b\n return [a, b, prod == a * b]", "def productFib(prod):\n a,b = 0,1\n while a*b < prod:\n a,b = b, b+a\n return [a, b, a*b == prod]", "def productFib(prod):\n a, b = 0, 1\n rez = 0\n while rez < prod:\n a...
{"fn_name": "productFib", "inputs": [[4895], [5895], [74049690], [84049690], [193864606], [447577], [602070], [602070602070], [1120149658760], [256319508074468182850], [203023208030065646654504166904697594722575], [203023208030065646654504166904697594722576], [0], [1], [2], [3], [4], [5], [6], [7], [105]], "outputs": [...
INTRODUCTORY
PYTHON3
CODEWARS
4,041
def productFib(prod):
fd52bd482c9ae3e239d90ee6503631dc
UNKNOWN
# Task Imagine a standard chess board with only two white and two black knights placed in their standard starting positions: the white knights on b1 and g1; the black knights on b8 and g8. There are two players: one plays for `white`, the other for `black`. During each move, the player picks one of his knights and m...
["def whose_turn(positions):\n return sum(ord(c) for c in positions.replace(\";\", \"\")) % 2 == 0", "def whose_turn(positions):\n return sum(ord(c) for c in positions) & 1 == 1", "tbl = str.maketrans('', '', 'aceg1357;')\n\ndef whose_turn(positions):\n return not len(positions.translate(tbl)) % 2\n", "def who...
{"fn_name": "whose_turn", "inputs": [["b1;g1;b8;g8"], ["c3;g1;b8;g8"], ["g1;g2;g3;g4"], ["f8;h1;f3;c2"]], "outputs": [[true], [false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,406
def whose_turn(positions):
9fe5816264388d0dbe4b5cf4dd896dc0
UNKNOWN
# Convert number to reversed array of digits Given a random non-negative number, you have to return the digits of this number within an array in reverse order. ## Example: ``` 348597 => [7,9,5,8,4,3] ```
["def digitize(n):\n return [int(x) for x in str(n)[::-1]]", "def digitize(n):\n return [int(x) for x in reversed(str(n))]", "def digitize(n):\n result = []\n while n >= 1:\n result.append(n%10)\n n //= 10\n return result", "def digitize(n):\n return [int(c) for c in str(n)[::-1]]", "def...
{"fn_name": "digitize", "inputs": [[35231], [23582357], [984764738], [45762893920], [548702838394]], "outputs": [[[1, 3, 2, 5, 3]], [[7, 5, 3, 2, 8, 5, 3, 2]], [[8, 3, 7, 4, 6, 7, 4, 8, 9]], [[0, 2, 9, 3, 9, 8, 2, 6, 7, 5, 4]], [[4, 9, 3, 8, 3, 8, 2, 0, 7, 8, 4, 5]]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,097
def digitize(n):
efa00cc2d853f6409a1678ec70a106ff
UNKNOWN
Consider the word `"abode"`. We can see that the letter `a` is in position `1` and `b` is in position `2`. In the alphabet, `a` and `b` are also in positions `1` and `2`. Notice also that `d` and `e` in `abode` occupy the positions they would occupy in the alphabet, which are positions `4` and `5`. Given an array of ...
["def solve(arr):\n return [ sum(c == chr(97+i) for i,c in enumerate(w[:26].lower())) for w in arr ]", "from string import ascii_lowercase as alphabet\n\ndef solve(arr):\n return [sum(c == alphabet[i] for i,c in enumerate(word[:26].lower())) for word in arr]", "from operator import eq\nfrom string import ascii_lo...
{"fn_name": "solve", "inputs": [[["abode", "ABc", "xyzD"]], [["abide", "ABc", "xyz"]], [["IAMDEFANDJKL", "thedefgh", "xyzDEFghijabc"]], [["encode", "abc", "xyzD", "ABmD"]]], "outputs": [[[4, 3, 1]], [[4, 3, 0]], [[6, 5, 7]], [[1, 3, 1, 3]]]}
INTRODUCTORY
PYTHON3
CODEWARS
22,060
def solve(arr):
5e52140a283a50908fa2d8da6033403d
UNKNOWN
Binary with 0 and 1 is good, but binary with only 0 is even better! Originally, this is a concept designed by Chuck Norris to send so called unary messages. Can you write a program that can send and receive this messages? Rules The input message consists of ASCII characters between 32 and 127 (7-bit) The encoded out...
["from re import compile\n\nREGEX1 = compile(r\"0+|1+\").findall\nREGEX2 = compile(r\"(0+) (0+)\").findall\nbinary = \"{:07b}\".format\n\ndef send(s):\n temp = ''.join(binary(ord(c)) for c in s)\n return ' '.join(\"0 \" + '0'*len(x) if x[0] == '1' else \"00 \" + x for x in REGEX1(temp))\n\ndef receive(s):\n te...
{"fn_name": "send", "inputs": [["C"], ["CC"], ["%"], ["Chuck Norris' keyboard has 2 keys: 0 and white space."], ["abcdefghijklmnopqrstuvwxyz"], ["!\"#$&"], ["Chuck Norris can divide by zero."], ["Chuck Norris counted to infinity - three times."]], "outputs": [["0 0 00 0000 0 00"], ["0 0 00 0000 0 000 00 0000 0 00"], ["...
INTRODUCTORY
PYTHON3
CODEWARS
5,789
def send(s):
f00e49ea22767c1d6ee3bc71137bc678
UNKNOWN
##Task: You have to write a function **pattern** which creates the following pattern upto n number of rows. * If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string. * If any odd number is passed as argument then the pattern should last upto the largest even number which is smaller th...
["def pattern(n):\n return '\\n'.join([str(i) * i for i in range(2, n + 1, 2)])\n", "def pattern(n):\n return \"\\n\".join(str(i) * i for i in range(2, n + 1, 2))", "def pattern(n):\n # Happy Coding ^_^\n result = []\n \n #If it's one return nothing\n if n == 1:\n return ''\n\n #just go t...
{"fn_name": "pattern", "inputs": [[2], [1], [5], [6], [0], [-25]], "outputs": [["22"], [""], ["22\n4444"], ["22\n4444\n666666"], [""], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,088
def pattern(n):
a04dae898b26b4584f31eab9aefd8707
UNKNOWN
Given an array of numbers (in string format), you must return a string. The numbers correspond to the letters of the alphabet in reverse order: a=26, z=1 etc. You should also account for `'!'`, `'?'` and `' '` that are represented by '27', '28' and '29' respectively. All inputs will be valid.
["def switcher(arr):\n d = {str(i): chr(123-i) for i in range(1,27)}\n d.update({'27':'!'})\n d.update({'28':'?'})\n d.update({'29':' '})\n d.update({'0':''})\n return ''.join([d[str(i)] for i in arr])", "import string\n\nletters = string.ascii_lowercase[::-1] + '!? '\ndef switcher(arr):\n return '...
{"fn_name": "switcher", "inputs": [[["24", "12", "23", "22", "4", "26", "9", "8"]], [["25", "7", "8", "4", "14", "23", "8", "25", "23", "29", "16", "16", "4"]], [["4", "24"]], [["12"]], [["12", "28", "25", "21", "25", "7", "11", "22", "15"]]], "outputs": [["codewars"], ["btswmdsbd kkw"], ["wc"], ["o"], ["o?bfbtpel"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,916
def switcher(arr):
dc9bcab46e9d9db9f02cf3c1865282a6
UNKNOWN
Triangular number is the amount of points that can fill equilateral triangle. Example: the number 6 is a triangular number because all sides of a triangle has the same amount of points. ``` Hint! T(n) = n * (n + 1) / 2, n - is the size of one side. T(n) - is the triangular number. ``` Given a number 'T' from interv...
["def is_triangular(t):\n x = int((t*2)**0.5)\n return t == x*(x+1)/2", "def is_triangular(t):\n return (8 * t + 1)**.5 % 1 == 0\n", "def is_triangular(t):\n return (8 * t + 1) ** 0.5 % 1 == 0", "def is_triangular(n):\n a = int((n * 2)**0.5)\n return n * 2 == a * (a + 1)\n", "TRIANGULAR = { x*(x+1)/2 ...
{"fn_name": "is_triangular", "inputs": [[1], [3], [6], [10], [15], [21], [28], [2], [7], [14], [27]], "outputs": [[true], [true], [true], [true], [true], [true], [true], [false], [false], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
816
def is_triangular(t):
0976fba4a4aba48f15b92b631e4c776f
UNKNOWN
Your task is to make a program takes in a sentence (without puncuation), adds all words to a list and returns the sentence as a string which is the positions of the word in the list. Casing should not matter too. Example ----- `"Ask not what your COUNTRY can do for you ASK WHAT YOU CAN DO FOR YOUR country"` becomes...
["def compress(sentence):\n ref = []\n for i in sentence.lower().split():\n if i not in ref:\n ref.append(i)\n return ''.join([str(ref.index(n)) for n in sentence.lower().split()])", "def compress(sentence):\n memo = {}\n return ''.join(map(str, (memo.setdefault(s, len(memo)) for s in s...
{"fn_name": "compress", "inputs": [["The bumble bee"], ["SILLY LITTLE BOYS silly little boys"], ["Ask not what your COUNTRY can do for you ASK WHAT YOU CAN DO FOR YOUR country"], ["The number 0 is such a strange number Strangely it has zero meaning"]], "outputs": [["012"], ["012012"], ["01234567802856734"], ["012345617...
INTRODUCTORY
PYTHON3
CODEWARS
1,923
def compress(sentence):
f89382e099b6bbb33dbca302bb6ff28a
UNKNOWN
In this kata, you will do addition and subtraction on a given string. The return value must be also a string. **Note:** the input will not be empty. ## Examples ``` "1plus2plus3plus4" --> "10" "1plus2plus3minus4" --> "2" ```
["def calculate(s):\n return str(sum(int(n) for n in s.replace(\"minus\", \"plus-\").split(\"plus\")))\n \n # I heard here and there that using eval is a very bad practice\u2026\n #return str(eval(s.replace(\"plus\", \"+\").replace(\"minus\", \"-\")))\n", "calculate = lambda s: str(eval(s.replace(\"plus\",\...
{"fn_name": "calculate", "inputs": [["1plus2plus3plus4"], ["1minus2minus3minus4"], ["1plus2plus3minus4"], ["1minus2plus3minus4"], ["1plus2minus3plus4minus5"]], "outputs": [["10"], ["-8"], ["2"], ["-2"], ["-1"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,915
def calculate(s):
6fbb5acdc3958b089c1eeb450453fd0d
UNKNOWN
The goal of this exercise is to convert a string to a new string where each character in the new string is `"("` if that character appears only once in the original string, or `")"` if that character appears more than once in the original string. Ignore capitalization when determining if a character is a duplicate. ##...
["def duplicate_encode(word):\n return \"\".join([\"(\" if word.lower().count(c) == 1 else \")\" for c in word.lower()])", "from collections import Counter\n\ndef duplicate_encode(word):\n word = word.lower()\n counter = Counter(word)\n return ''.join(('(' if counter[c] == 1 else ')') for c in word)\n", "#T...
{"fn_name": "duplicate_encode", "inputs": [["din"], ["recede"], ["Success"], ["CodeWarrior"], ["Supralapsarian"], ["iiiiii"], ["(( @"], [" ( ( )"]], "outputs": [["((("], ["()()()"], [")())())"], ["()(((())())"], [")()))()))))()("], ["))))))"], ["))(("], [")))))("]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,359
def duplicate_encode(word):
2b027d9124f2f45faa8d2baed31f0fe3
UNKNOWN
This kata is part of the collection [Mary's Puzzle Books](https://www.codewars.com/collections/marys-puzzle-books). Mary brought home a "spot the differences" book. The book is full of a bunch of problems, and each problem consists of two strings that are similar. However, in each string there are a few characters tha...
["def spot_diff(s1, s2):\n return [i for i in range(len(s1)) if s1[i] != s2[i]]", "def spot_diff(s1, s2):\n return [k for k in range(len(s1)) if s1[k] != s2[k]]", "def spot_diff(s1, s2):\n r=[]\n for i in range (len(s1)):\n if s1[i]!=s2[i]: r.append(i)\n return r", "def spot_diff(s1, s2):\n return [i for i...
{"fn_name": "spot_diff", "inputs": [["abcdefg", "abcqetg"], ["Hello World!", "hello world."], ["FixedGrey", "FixedGrey"], ["HACKER", "H4CK3R"], ["This is a really long sentence.", "That is a_really long sentence,"], ["", ""], ["abcdefghijklmnopqrstuvwxyz", "zyxwvutsrqponmlkjihgfedcba"], ["YOLO lol", "ROLO mom"], ["www....
INTRODUCTORY
PYTHON3
CODEWARS
1,029
def spot_diff(s1, s2):
2d3610cf98404c48aa9f25047b7d8709
UNKNOWN
Today was a sad day. Having bought a new beard trimmer, I set it to the max setting and shaved away at my joyous beard. Stupidly, I hadnt checked just how long the max setting was, and now I look like Ive just started growing it! Your task, given a beard represented as an arrayof arrays, is to trim the beard as follow...
["def trim(beard):\n return [[h.replace(\"J\", \"|\") for h in b] for b in beard[:-1]] + [[\"...\"]*len(beard[0])]", "def trim(beard):\n beard = [[\"|\" if p in \"|J\" else \"...\" for p in hair] for hair in beard]\n beard[-1] = [\"...\" for _ in beard[-1]]\n return beard", "def trim(a):\n return [[\"|\"...
{"fn_name": "trim", "inputs": [[[["J", "|"], ["J", "|"], ["...", "|"]]], [[["J", "|", "J"], ["J", "|", "|"], ["...", "|", "J"]]], [[["J", "|", "J", "J"], ["J", "|", "|", "J"], ["...", "|", "J", "|"]]]], "outputs": [[[["|", "|"], ["|", "|"], ["...", "..."]]], [[["|", "|", "|"], ["|", "|", "|"], ["...", "...", "..."]]], ...
INTRODUCTORY
PYTHON3
CODEWARS
1,581
def trim(beard):
58aa62fd08b240aae35dcea581d527c6
UNKNOWN
In this kata, you'll be given an integer of range `0 <= x <= 99` and have to return that number spelt out in English. A few examples: ```python name_that_number(4) # returns "four" name_that_number(19) # returns "nineteen" name_that_number(99) # returns "ninety nine" ``` Words should be separated by only spaces a...
["WORDS = (\n (90, 'ninety'), (80, 'eighty'), (70, 'seventy'), (60, 'sixty'),\n (50, 'fifty'), (40, 'forty'), (30, 'thirty'), (20, 'twenty'),\n (19, 'nineteen'), (18, 'eighteen'), (17, 'seventeen'), (16, 'sixteen'),\n (15, 'fifteen'), (14, 'fourteen'), (13, 'thirteen'), (12, 'twelve'),\n (11, 'eleven'), ...
{"fn_name": "name_that_number", "inputs": [[1], [52], [21], [99], [0], [53], [23], [76]], "outputs": [["one"], ["fifty two"], ["twenty one"], ["ninety nine"], ["zero"], ["fifty three"], ["twenty three"], ["seventy six"]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,499
def name_that_number(x):
ed308855ea9e9f490dc691d528f60c44
UNKNOWN
Given an array, find the duplicates in that array, and return a new array of those duplicates. The elements of the returned array should appear in the order when they first appeared as duplicates. __*Note*__: numbers and their corresponding string representations should not be treated as duplicates (i.e., `"1" != 1`)....
["def duplicates(array):\n seen = []\n dups = []\n for char in array:\n if char not in seen:\n seen.append(char)\n elif char not in dups:\n dups.append(char)\n \n return dups\n", "def duplicates(arr):\n res = []\n for i, x in enumerate(arr):\n if arr[:i ...
{"fn_name": "duplicates", "inputs": [[[1, 2, 4, 4, 3, 3, 1, 5, 3, "5"]], [[0, 1, 2, 3, 4, 5]], [[1, 1, 2, 3, 4, 5, 4]]], "outputs": [[[4, 3, 1]], [[]], [[1, 4]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,658
def duplicates(array):
b6d5249d6781c256d59dc713a7a43e1a
UNKNOWN
*This is the second Kata in the Ciphers series. This series is meant to test our coding knowledge.* ## Ciphers #2 - The reversed Cipher This is a lame method I use to write things such that my friends don't understand. It's still fairly readable if you think about it. ## How this cipher works First, you need to rever...
["def encode(s):\n return ' '.join( w[-2::-1] + w[-1] for w in s.split() )", "def encode(s):\n s, sub_s = s.split(' '), ''\n for char in s:\n sub_s += char[::-1][1:] + char[-1] + ' '\n return sub_s[:-1]", "encode=lambda s:\" \".join([i[::-1][1:]+i[::-1][0] for i in s.split()])", "import re\n\ndef enc...
{"fn_name": "encode", "inputs": [["Hello World!"]], "outputs": [["lleHo dlroW!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,025
def encode(s):
7db5ea3bff2a8bc3e41d3e629808c784
UNKNOWN
A Magic Square contains the integers 1 to n^(2), arranged in an n by n array such that the columns, rows and both main diagonals add up to the same number.For doubly even positive integers (multiples of 4) the following method can be used to create a magic square. Fill an array with the numbers 1 to n^(2) in succession...
["def even_magic(n):\n return [ [ n*n-(y*n+x) if x%4==y%4 or (x%4+y%4)%4==3 else y*n+x+1 for x in range(n)] for y in range(n) ]", "def even_magic(n):\n l = list(range(1,n*n+1))\n for i in range(n*n//2):\n y,x = (i//n)%4,(i%n)%4\n if y==x or x+y==3: l[i],l[n*n-1-i] = l[n*n-1-i], l[i]\n return [...
{"fn_name": "even_magic", "inputs": [[4], [8]], "outputs": [[[[16, 2, 3, 13], [5, 11, 10, 8], [9, 7, 6, 12], [4, 14, 15, 1]]], [[[64, 2, 3, 61, 60, 6, 7, 57], [9, 55, 54, 12, 13, 51, 50, 16], [17, 47, 46, 20, 21, 43, 42, 24], [40, 26, 27, 37, 36, 30, 31, 33], [32, 34, 35, 29, 28, 38, 39, 25], [41, 23, 22, 44, 45, 19, 1...
INTRODUCTORY
PYTHON3
CODEWARS
2,955
def even_magic(n):
402e9385311d14663386b0e3bd0b288d
UNKNOWN
Write a function that when given a number >= 0, returns an Array of ascending length subarrays. ``` pyramid(0) => [ ] pyramid(1) => [ [1] ] pyramid(2) => [ [1], [1, 1] ] pyramid(3) => [ [1], [1, 1], [1, 1, 1] ] ``` **Note:** the subarrays should be filled with `1`s
["def pyramid(n):\n return [[1]*x for x in range(1, n+1)]", "def pyramid(n):\n return [ [1] * i for i in range(1, n+1) ]", "def pyramid(n):\n result = []\n for i in range (1, n + 1):\n result.append(i * [1])\n return result", "pyramid=lambda n:[-~i*[1]for i in range(n)]", "def pyramid(n):\n res...
{"fn_name": "pyramid", "inputs": [[0], [1], [2], [3]], "outputs": [[[]], [[[1]]], [[[1], [1, 1]]], [[[1], [1, 1], [1, 1, 1]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,062
def pyramid(n):
3ffe6d9807d94d761f90bacdcd0b3c2a
UNKNOWN
A [Power Law](https://en.wikipedia.org/wiki/Power_law) distribution occurs whenever "a relative change in one quantity results in a proportional relative change in the other quantity." For example, if *y* = 120 when *x* = 1 and *y* = 60 when *x* = 2 (i.e. *y* halves whenever *x* doubles) then when *x* = 4, *y* = 30 and...
["from math import log\n\ndef power_law(p1, p2, x3):\n (x1, y1), (x2, y2) = p1, p2\n x1 += 1e-9; y1 += 1e-9\n return round(y1 * (y2 / y1) ** log(x3 / x1, x2 / x1))", "from math import log\n\ndef power_law(x1y1, x2y2, x3):\n a, b, c = x2y2[0]/x1y1[0], x2y2[1]/x1y1[1], x3/x1y1[0]\n try:\n return ro...
{"fn_name": "power_law", "inputs": [[[1, 120], [2, 60], 4], [[1, 120], [2, 60], 8], [[1, 120], [4, 30], 8], [[1, 120], [3, 60], 9], [[1, 120], [3, 60], 27], [[1, 120], [9, 30], 27], [[1, 81], [2, 27], 4], [[1, 81], [2, 27], 8], [[1, 81], [4, 9], 8], [[1, 81], [5, 27], 25], [[1, 81], [5, 27], 125], [[1, 81], [25, 9], 12...
INTRODUCTORY
PYTHON3
CODEWARS
2,104
def power_law(x1y1, x2y2, x3):
0be723f9b786039c2e746687659fee3b
UNKNOWN
# SpeedCode #2 - Array Madness ## Objective Given two **integer arrays** ```a, b```, both of ```length >= 1```, create a program that returns ```true``` if the **sum of the squares** of each element in ```a``` is **strictly greater than** the **sum of the cubes** of each element in ```b```. E.g. ```python array_madn...
["def array_madness(a,b):\n return sum(x ** 2 for x in a) > sum(x **3 for x in b)", "def array_madness(a,b):\n return sum(map(lambda a: a ** 2, a)) > sum(map(lambda b: b ** 3, b))", "def array_madness(a,b):\n sa=0\n sb=0\n for i in range(0,len(a)):\n sa+=a[i]**2\n for i in range(0,len(b)):\n ...
{"fn_name": "array_madness", "inputs": [[[4, 5, 6], [1, 2, 3]]], "outputs": [[true]]}
INTRODUCTORY
PYTHON3
CODEWARS
18,969
def array_madness(a,b):
e81d1f5ba214a724f11ecae63c18f1af
UNKNOWN
Simple enough this one - you will be given an array. The values in the array will either be numbers or strings, or a mix of both. You will not get an empty array, nor a sparse one. Your job is to return a single array that has first the numbers sorted in ascending order, followed by the strings sorted in alphabetic or...
["def db_sort(arr): \n return sorted(arr, key=lambda x: (isinstance(x,str),x))", "def db_sort(arr): \n n=[]\n s=[]\n for i in arr:\n if type(i) ==type( 'a'):\n s.append(i)\n else:\n n.append(i)\n return sorted(n)+sorted(s)", "def db_sort(arr): \n ints, strg = [], []...
{"fn_name": "db_sort", "inputs": [[[6, 2, 3, 4, 5]], [[14, 32, 3, 5, 5]], [[1, 2, 3, 4, 5]], [["Banana", "Orange", "Apple", "Mango", 0, 2, 2]], [["C", "W", "W", "W", 1, 2, 0]], [["Hackathon", "Katathon", "Code", "CodeWars", "Laptop", "Macbook", "JavaScript", 1, 5, 2]], [[66, "t", 101, 0, 1, 1]], [[78, 117, 110, 99, 104...
INTRODUCTORY
PYTHON3
CODEWARS
2,473
def db_sort(arr):
dfb6725e3220cf57e7ba4b4749826a55
UNKNOWN
Given a sequence of numbers, find the largest pair sum in the sequence. For example ``` [10, 14, 2, 23, 19] --> 42 (= 23 + 19) [99, 2, 2, 23, 19] --> 122 (= 99 + 23) ``` Input sequence contains minimum two elements and every element is an integer.
["def largest_pair_sum(numbers): \n return sum(sorted(numbers)[-2:])", "from heapq import nlargest\n\ndef largest_pair_sum(a):\n return sum(nlargest(2, a))", "def largest_pair_sum(a): \n return a.pop(a.index(max(a))) + a.pop(a.index(max(a)))", "def largest_pair_sum(numbers): \n return sorted(numbers)[-2]+ma...
{"fn_name": "largest_pair_sum", "inputs": [[[10, 14, 2, 23, 19]], [[-100, -29, -24, -19, 19]], [[1, 2, 3, 4, 6, -1, 2]], [[-10, -8, -16, -18, -19]]], "outputs": [[42], [0], [10], [-18]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,718
def largest_pair_sum(numbers):
c2eaa998f6a416b37e7266191e5534a7
UNKNOWN
# Task You are given an array `a` of positive integers a. You may choose some integer `X` and update `a` several times, where to update means to perform the following operations: ``` pick a contiguous subarray of length not greater than the given k; replace all elements in the picked subarray with the chosen X. ``` Wh...
["def array_equalization(a, k):\n totals, ends = {}, {}\n for i, n in enumerate(a):\n if n not in ends: totals[n], ends[n] = 0, -1\n if i < ends[n]: continue\n count = (i - ends[n] - 1 + k - 1) // k\n totals[n] += count\n ends[n] = max(i, ends[n] + count * k)\n return min(t +...
{"fn_name": "array_equalization", "inputs": [[[1, 2, 2, 1, 2, 1, 2, 2, 2, 1, 1, 1], 2], [[5, 2, 3, 5, 2, 2, 3, 5, 1, 2, 5, 1, 2, 5, 3], 7], [[1, 2, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1], 9]], "outputs": [[4], [2], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,146
def array_equalization(a, k):
1bdf333f6b9fcf1189ba58d729db5715
UNKNOWN
In this kata you are given an array to sort but you're expected to start sorting from a specific position of the array (in ascending order) and optionally you're given the number of items to sort. #### Examples: ```python sect_sort([1, 2, 5, 7, 4, 6, 3, 9, 8], 2) //=> [1, 2, 3, 4, 5, 6, 7, 8, 9] sect_sort([9, 7, 4, 2...
["def sect_sort(lst, start, length=0):\n end = start + length if length else len(lst)\n return lst[:start] + sorted(lst[start:end]) + lst[end:]", "def sect_sort(arr, start, num=0):\n out = arr[:]\n s = slice(start, None if not num else start + num)\n out[s] = sorted(out[s])\n return out", "def sect_so...
{"fn_name": "sect_sort", "inputs": [[[1, 2, 5, 7, 4, 6, 3, 9, 8], 2], [[1, 2, 5, 7, 4, 6, 3, 9, 8], 8], [[9, 7, 4, 2, 5, 3, 1, 8, 6], 2, 5], [[1, 2, 5, 7, 4, 6, 3, 9, 8], 8, 3], [[], 0]], "outputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[1, 2, 5, 7, 4, 6, 3, 9, 8]], [[9, 7, 1, 2, 3, 4, 5, 8, 6]], [[1, 2, 5, 7, 4, 6, 3, 9, 8...
INTRODUCTORY
PYTHON3
CODEWARS
1,687
def sect_sort(lst, start, length=0):
878974ac2629b9124463bfc75745fa11
UNKNOWN
"Point reflection" or "point symmetry" is a basic concept in geometry where a given point, P, at a given position relative to a mid-point, Q has a corresponding point, P1, which is the same distance from Q but in the opposite direction. ## Task Given two points P and Q, output the symmetric point of point P about Q. ...
["def symmetric_point(p, q):\n return [2*q[0] - p[0], 2*q[1] - p[1]]", "symmetric_point = lambda p, q: [2 * b - a for a, b in zip(p, q)]", "def symmetric_point(p, q):\n # your code here\n p1x = (q[0] - p[0]) + q[0]\n p1y = (q[1] - p[1]) + q[1]\n return [p1x, p1y]", "symmetric_point = lambda p,q: [2*q[0] ...
{"fn_name": "symmetric_point", "inputs": [[[0, 0], [1, 1]], [[2, 6], [-2, -6]], [[10, -10], [-10, 10]], [[1, -35], [-12, 1]], [[1000, 15], [-7, -214]], [[0, 0], [0, 0]]], "outputs": [[[2, 2]], [[-6, -18]], [[-30, 30]], [[-25, 37]], [[-1014, -443]], [[0, 0]]]}
INTRODUCTORY
PYTHON3
CODEWARS
13,833
def symmetric_point(p, q):
9307d9b350a1f4aa9f79cc5510542447
UNKNOWN
Consider a sequence made up of the consecutive prime numbers. This infinite sequence would start with: ```python "2357111317192329313741434753596167717379..." ``` You will be given two numbers: `a` and `b`, and your task will be to return `b` elements starting from index `a` in this sequence. ``` For example: solve(1...
["def solve(a, b):\n primes = \"235711131719232931374143475359616771737983899710110310710911312713113713914915115716316717317918119119319719921122322722923323924125125726326927127728128329330731131331733133734734935335936737337938338939740140941942143143343944344945746146346747948749149950350952152354154755756356957...
{"fn_name": "solve", "inputs": [[2, 2], [10, 5], [10, 3], [20, 9], [30, 12], [40, 8], [50, 6], [10000, 5], [20000, 5]], "outputs": [["57"], ["19232"], ["192"], ["414347535"], ["616771737983"], ["83899710"], ["031071"], ["02192"], ["09334"]]}
INTRODUCTORY
PYTHON3
CODEWARS
436,630
def solve(a, b):
7dbc4e200e62c3fa0bd487d202729897
UNKNOWN
Cheesy Cheeseman just got a new monitor! He is happy with it, but he just discovered that his old desktop wallpaper no longer fits. He wants to find a new wallpaper, but does not know which size wallpaper he should be looking for, and alas, he just threw out the new monitor's box. Luckily he remembers the width and the...
["def find_screen_height(width, ratio): \n a, b = map(int, ratio.split(\":\"))\n return f\"{width}x{int(width / a * b)}\"", "def find_screen_height(width, ratio): \n #Turns the string ratio into a list with the two numbers as elements\n z = ratio.split(\":\")\n \n #calculates the height value\n hei...
{"fn_name": "find_screen_height", "inputs": [[1024, "4:3"], [1280, "16:9"], [3840, "32:9"], [1600, "4:3"], [1280, "5:4"], [2160, "3:2"], [1920, "16:9"], [5120, "32:9"]], "outputs": [["1024x768"], ["1280x720"], ["3840x1080"], ["1600x1200"], ["1280x1024"], ["2160x1440"], ["1920x1080"], ["5120x1440"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,756
def find_screen_height(width, ratio):
3b6a9ae3b21f0824670c79825e334fac
UNKNOWN
Peter can see a clock in the mirror from the place he sits in the office. When he saw the clock shows 12:22 1 2 3 4 5 6 7 8 9 10 11 12 He knows that the time is 11:38 1 2 3 4 5 6 7 8 9 10 11 12 in the same manner: 05:25 --> 06:35 01:50 --> 10:10 11:58 --> 12:02 12:01 --> 11:59 Please complete the fun...
["def what_is_the_time(time_in_mirror):\n h, m = map(int, time_in_mirror.split(':'))\n return '{:02}:{:02}'.format(-(h + (m != 0)) % 12 or 12, -m % 60)", "def what_is_the_time(time_in_mirror):\n array = time_in_mirror.split(\":\")\n a = int(array[0])\n b = int(array[1])\n \n if a == 11: a = 12\n ...
{"fn_name": "what_is_the_time", "inputs": [["06:35"], ["11:59"], ["12:02"], ["04:00"], ["06:00"], ["12:00"]], "outputs": [["05:25"], ["12:01"], ["11:58"], ["08:00"], ["06:00"], ["12:00"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,549
def what_is_the_time(time_in_mirror):