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 |
|---|---|---|---|---|---|---|---|---|---|
f71239deabb7fc6c2368c1de2cab76b6 | UNKNOWN | You'll be given a list of two strings, and each will contain exactly one colon (`":"`) in the middle (but not at beginning or end). The length of the strings, before and after the colon, are random.
Your job is to return a list of two strings (in the same order as the original list), but with the characters after each... | ["def tail_swap(strings):\n head0, tail0 = strings[0].split(':')\n head1, tail1 = strings[1].split(':')\n return [head0 + ':' + tail1, head1 + ':' + tail0]", "def tail_swap(arr):\n fmt = '{}:{}'.format\n (head, tail), (head_2, tail_2) = (a.split(':') for a in arr)\n return [fmt(head, tail_2), fmt(head... | {"fn_name": "tail_swap", "inputs": [[["abc:123", "cde:456"]], [["a:12345", "777:xyz"]]], "outputs": [[["abc:456", "cde:123"]], [["a:xyz", "777:12345"]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,356 |
def tail_swap(strings):
|
82810a916e8d2170716efc6ef8986341 | UNKNOWN | Adding tip to a restaurant bill in a graceful way can be tricky, thats why you need make a function for it.
The function will receive the restaurant bill (always a positive number) as an argument. You need to 1) **add at least 15%** in tip, 2) round that number up to an *elegant* value and 3) return it.
What is an *e... | ["from math import ceil, log10\n\ndef graceful_tipping(bill):\n bill *= 1.15\n if bill < 10:\n return ceil(bill)\n e = int(log10(bill))\n unit = (10 ** e) / 2\n return ceil(bill / unit) * unit", "import math\ndef graceful_tipping(bill):\n c = bill * 115 / 100\n m = 1 if c < 10 else 5 * 10 **... | {"fn_name": "graceful_tipping", "inputs": [[1], [7], [12], [86], [99], [1149], [983212]], "outputs": [[2], [9], [15], [100], [150], [1500], [1500000]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,449 |
def graceful_tipping(bill):
|
102b6b9b666f8c662e824af6365ad1f4 | UNKNOWN | Given a triangle of consecutive odd numbers:
```
1
3 5
7 9 11
13 15 17 19
21 23 25 27 29
...
```
find the triangle's row knowing its index (the rows are 1-indexed), e.g.:
```
odd_row(1) == [1]
odd_row(2) == [3, 5]
odd_row(3) == [7, 9, 11]
```
**... | ["odd_row = lambda n:list(range(n*(n-1)+1,n*(n+1),2))\n", "def odd_row(n):\n m = (n - 1) * n + 1\n return [*range(m, m + n * 2, 2)]", "def odd_row(n):\n return [x for x in range(n**2-n+1, (n+1)**2-n,2)]", "def odd_row(n):\n return [x for x in range(n*n-n, n*n+n) if (x)%2!=0]", "def odd_row(n):\n return l... | {"fn_name": "odd_row", "inputs": [[1], [2], [13], [19], [41], [93]], "outputs": [[[1]], [[3, 5]], [[157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181]], [[343, 345, 347, 349, 351, 353, 355, 357, 359, 361, 363, 365, 367, 369, 371, 373, 375, 377, 379]], [[1641, 1643, 1645, 1647, 1649, 1651, 1653, 1655, 1657... | INTRODUCTORY | PYTHON3 | CODEWARS | 878 |
def odd_row(n):
|
f81fda052a04ba5a0fba45084dc499f4 | UNKNOWN | You might know some pretty large perfect squares. But what about the NEXT one?
Complete the `findNextSquare` method that finds the next integral perfect square after the one passed as a parameter. Recall that an integral perfect square is an integer n such that sqrt(n) is also an integer.
If the parameter is itse... | ["def find_next_square(sq):\n root = sq ** 0.5\n if root.is_integer():\n return (root + 1)**2\n return -1\n", "def find_next_square(sq):\n x = sq**0.5 \n return -1 if x % 1 else (x+1)**2\n", "import math\n\n\ndef find_next_square(sq):\n return (math.sqrt(sq) + 1) ** 2 if (math.sqrt(sq)).is_i... | {"fn_name": "find_next_square", "inputs": [[121], [625], [319225], [15241383936], [155], [342786627]], "outputs": [[144], [676], [320356], [15241630849], [-1], [-1]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,548 |
def find_next_square(sq):
|
bff37517e2ffdd9ab92d4479e28d0ce6 | UNKNOWN | It's pretty straightforward. Your goal is to create a function that removes the first and last characters of a string. You're given one parameter, the original string. You don't have to worry with strings with less than two characters. | ["def remove_char(s):\n return s[1 : -1]", "def remove_char(s):\n return '' if len(s) <= 2 else s[1:-1]", "def remove_char(s):\n return s[1:len(s)-1]", "remove_char=lambda s: s[1:-1]", "def remove_char(s):\n if s == \"eloquent\": #confirming the s variable equals the word \"eloquent\"\n retur... | {"fn_name": "remove_char", "inputs": [["eloquent"], ["country"], ["person"], ["place"], ["ok"], ["ooopsss"]], "outputs": [["loquen"], ["ountr"], ["erso"], ["lac"], [""], ["oopss"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,323 |
def remove_char(s):
|
60fe3c2a9bcc93ba5de895e70af5e8fe | UNKNOWN | Write a function that returns the number of '2's in the factorization of a number.
For example,
```python
two_count(24)
```
should return 3, since the factorization of 24 is 2^3 x 3
```python
two_count(17280)
```
should return 7, since the factorization of 17280 is 2^7 x 5 x 3^3
The number passed to two_count (twoC... | ["def two_count(n):\n res = 0\n while not n & 1:\n res += 1\n n >>= 1\n return res\n", "def two_count(n):\n return bin(n)[::-1].index('1')", "def two_count(n):\n return n.bit_length() - len(bin(n).rstrip('0')) + 2", "def two_count(n):\n i = 0\n while True:\n n, r = divmod(n, 2)\n ... | {"fn_name": "two_count", "inputs": [[24], [17280], [222222222222], [256], [1], [2], [482848428248882482], [7], [7777777777777777], [84934656]], "outputs": [[3], [7], [1], [8], [0], [1], [1], [0], [0], [20]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 885 |
def two_count(n):
|
d3cdb5914dc3c80c3772aa89f070f707 | UNKNOWN | #Find the missing letter
Write a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array.
You will always get an valid array. And it will be always exactly one letter be missing. The length of the array will always be at least 2.
The array will always c... | ["def find_missing_letter(chars):\n n = 0\n while ord(chars[n]) == ord(chars[n+1]) - 1:\n n += 1\n return chr(1+ord(chars[n]))\n\n", "def find_missing_letter(input):\n alphabet = list(\"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\")\n start = alphabet.index(input[0])\n for i in range(l... | {"fn_name": "find_missing_letter", "inputs": [[["a", "b", "c", "d", "f"]], [["O", "Q", "R", "S"]], [["b", "d"]]], "outputs": [["e"], ["P"], ["c"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,916 |
def find_missing_letter(chars):
|
d3acf3e20d59e27d11600cde701dec8b | UNKNOWN | Cluster analysis - Unweighted pair-group average
Clustering is a task of grouping a set of objects in such a way that the objects in the same class are similar to each other and the objects in different classes are distinct. Cluster analysis is employed in many fields such as machine learning, pattern recognition, ima... | ["from sklearn.cluster import KMeans\n\n# Doesn't work for big tests, too bad\ndef cluster_kmeans(points, n):\n kmeans = KMeans(n_clusters=n)\n kmeans.fit(points)\n res = [[] for _ in range(n)]\n for i,p in zip(kmeans.labels_, points):\n res[i].append(p)\n return sorted(map(sorted, res))\n\n\nfrom... | {"fn_name": "cluster", "inputs": [[[[100, 100]], 1]], "outputs": [[[[[100, 100]]]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 9,693 |
def cluster(points, n):
|
05d36dfc31c21d9b2d5bccf8543dc958 | UNKNOWN | This function should test if the `factor` is a factor of `base`.
Return `true` if it is a factor or `false` if it is not.
## About factors
Factors are numbers you can multiply together to get another number.
2 and 3 are factors of 6 because: `2 * 3 = 6`
- You can find a factor by dividing numbers. If the remainder ... | ["def check_for_factor(base, factor):\n return base % factor == 0", "def check_for_factor(b,f):\n return not b%f", "def check_for_factor(base, factor):\n return not (base % factor)", "def check_for_factor(base, factor):\n return True if base%factor == 0 else False", "check_for_factor = lambda base, factor: ... | {"fn_name": "check_for_factor", "inputs": [[10, 2], [63, 7], [2450, 5], [24612, 3], [9, 2], [653, 7], [2453, 5], [24617, 3]], "outputs": [[true], [true], [true], [true], [false], [false], [false], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 12,597 |
def check_for_factor(base, factor):
|
84a4a9dd2e8dca3ac9440be924907284 | UNKNOWN | The aim of this Kata is to write a function which will reverse the case of all consecutive duplicate letters in a string. That is, any letters that occur one after the other and are identical.
If the duplicate letters are lowercase then they must be set to uppercase, and if they are uppercase then they need to be cha... | ["import re\n\ndef reverse(s):\n return re.sub(r'(.)\\1+', lambda m: m.group().swapcase(), s)", "import re\n\ndef reverse(strng): return re.sub(r'(\\w)\\1+', lambda m: m.group().swapcase(), strng)", "import re\n\ndef reverse(stg):\n return re.sub(r\"(([a-zA-Z])\\2+)\", lambda m: m.group(1).swapcase(), stg)", "fro... | {"fn_name": "reverse", "inputs": [["hello world"], ["HELLO WORLD"], ["HeLlo World"], ["WWW"], ["parallel universe"], ["shhh"], ["bookkeeper"]], "outputs": [["heLLo world"], ["HEllO WORLD"], ["HeLlo World"], ["www"], ["paraLLel universe"], ["sHHH"], ["bOOKKEEper"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,689 |
def reverse(s):
|
dd1d66216738a6ae058f178f84bafbf2 | UNKNOWN | In your class, you have started lessons about "arithmetic progression". Because you are also a programmer, you have decided to write a function.
This function, arithmetic_sequence_sum(a, r, n), should return the sum of the first (n) elements of a sequence in which each element is the sum of the given integer (a), and ... | ["def arithmetic_sequence_sum(a, r, n):\n return n * (a + a + ( n - 1) * r) / 2 ", "def arithmetic_sequence_sum(a, r, n):\n return a * n + r * n * (n - 1) / 2;", "def arithmetic_sequence_sum(a, r, n):\n result = 0\n for i in range(n):\n result += a + i*r\n return result", "def arithmetic_sequence... | {"fn_name": "arithmetic_sequence_sum", "inputs": [[3, 2, 20], [2, 2, 10], [1, -2, 10]], "outputs": [[440], [110], [-80]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 975 |
def arithmetic_sequence_sum(a, r, n):
|
40d0cce2555f7ec61c8299eacc5a4077 | UNKNOWN | You are the "computer expert" of a local Athletic Association (C.A.A.).
Many teams of runners come to compete. Each time you get a string of
all race results of every team who has run.
For example here is a string showing the individual results of a team of 5 runners:
` "01|15|59, 1|47|6, 01|17|20, 1|32|34, 2|3|17" `... | ["def stat(strg):\n\n def get_time(s):\n '''Returns the time, in seconds, represented by s.'''\n hh, mm, ss = [int(v) for v in s.split('|')]\n return hh * 3600 + mm * 60 + ss\n \n def format_time(time):\n '''Returns the given time as a string in the form \"hh|mm|ss\".'''\n hh... | {"fn_name": "stat", "inputs": [["01|15|59, 1|47|16, 01|17|20, 1|32|34, 2|17|17"], ["02|15|59, 2|47|16, 02|17|20, 2|32|34, 2|17|17, 2|22|00, 2|31|41"], ["02|15|59, 2|47|16, 02|17|20, 2|32|34, 2|32|34, 2|17|17"], ["0|15|59, 0|16|16, 0|17|20, 0|22|34, 0|19|34, 0|15|0"], ["11|15|59, 10|16|16, 12|17|20, 9|22|34, 13|19|34, 1... | INTRODUCTORY | PYTHON3 | CODEWARS | 4,829 |
def stat(strg):
|
70b60ff999ff6d05e2964a7a471935a0 | UNKNOWN | If you have completed the Tribonacci sequence kata, you would know by now that mister Fibonacci has at least a bigger brother. If not, give it a quick look to get how things work.
Well, time to expand the family a little more: think of a Quadribonacci starting with a signature of 4 elements and each following element ... | ["def Xbonacci(signature,n):\n output, x = signature[:n], len(signature)\n while len(output) < n:\n output.append(sum(output[-x:]))\n return output", "def Xbonacci(signature,n):\n length = len(signature)\n while len(signature) < n:\n signature.append(sum(signature[-length:]))\n return si... | {"fn_name": "Xbonacci", "inputs": [[[0, 1], 10], [[1, 1], 10], [[0, 0, 0, 0, 1], 10], [[1, 0, 0, 0, 0, 0, 1], 10], [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], 20], [[0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10], [[0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0], 20], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 20], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 9], [[1, 2, 3, 4... | INTRODUCTORY | PYTHON3 | CODEWARS | 3,569 |
def Xbonacci(signature,n):
|
4f73a88930bdb76fe5c2114bde9612eb | UNKNOWN | If you like Taco Bell, you will be familiar with their signature doritos locos taco. They're very good.
Why can't everything be a taco? We're going to attempt that here, turning every word we find into the taco bell recipe with each ingredient.
We want to input a word as a string, and return a list representing tha... | ["import re\n\nTACODICT = {\n 't':'tomato', \n 'l':'lettuce',\n 'c':'cheese',\n 'g':'guacamole',\n 's':'salsa'\n }\n\ndef tacofy(word):\n return ['shell'] + [TACODICT.get(c, 'beef') for c in re.sub('[^aeioutlcgs]+' ,'', word.lower())] + ['shell']"... | {"fn_name": "tacofy", "inputs": [[""], ["a"], ["ogl"], ["alel"], ["MaXwElL"], ["ggg"], ["Alex is Super Cool"], ["ydjkpwqrzto"], ["abtlcgs"]], "outputs": [[["shell", "shell"]], [["shell", "beef", "shell"]], [["shell", "beef", "guacamole", "lettuce", "shell"]], [["shell", "beef", "lettuce", "beef", "lettuce", "shell"]], ... | INTRODUCTORY | PYTHON3 | CODEWARS | 3,013 |
def tacofy(word):
|
d8771266bc1553126c90c1a0397f6148 | UNKNOWN | You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return `-1`.
__For example:__
Let's say you are given the array `{1... | ["def find_even_index(arr):\n for i in range(len(arr)):\n if sum(arr[:i]) == sum(arr[i+1:]):\n return i\n return -1\n", "def find_even_index(lst):\n left_sum = 0\n right_sum = sum(lst)\n for i, a in enumerate(lst):\n right_sum -= a\n if left_sum == right_sum:\n ... | {"fn_name": "find_even_index", "inputs": [[[1, 2, 3, 4, 3, 2, 1]], [[1, 100, 50, -51, 1, 1]], [[1, 2, 3, 4, 5, 6]], [[20, 10, 30, 10, 10, 15, 35]], [[20, 10, -80, 10, 10, 15, 35]], [[10, -80, 10, 10, 15, 35, 20]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 2... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,339 |
def find_even_index(arr):
|
2db875cc0ada5533652756cc1a55b357 | UNKNOWN | We need to write some code to return the original price of a product, the return type must be of type decimal and the number must be rounded to two decimal places.
We will be given the sale price (discounted price), and the sale percentage, our job is to figure out the original price.
### For example:
Given an item... | ["def discover_original_price(discounted_price, sale_percentage):\n return round(discounted_price / ((100 - sale_percentage) * 0.01), 2)\n", "def discover_original_price(discounted_price, sale_percentage):\n #your code here\n return round(discounted_price / (1 - (sale_percentage / 100.00)), 2)", "def discover_... | {"fn_name": "discover_original_price", "inputs": [[75, 25], [25, 75], [75.75, 25], [373.85, 11.2], [458.2, 17.13]], "outputs": [[100], [100], [101], [421], [552.91]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,296 |
def discover_original_price(discounted_price, sale_percentage):
|
30db26d2eff5976cf63a3ccdcf4a0e43 | UNKNOWN | Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.
Examples:
spinWords( ... | ["def spin_words(sentence):\n # Your code goes here\n return \" \".join([x[::-1] if len(x) >= 5 else x for x in sentence.split(\" \")])", "def spin_words(sentence):\n words = [word for word in sentence.split(\" \")]\n words = [word if len(word) < 5 else word[::-1] for word in words]\n return \" \".join(w... | {"fn_name": "spin_words", "inputs": [["Welcome"], ["to"], ["CodeWars"], ["Hey fellow warriors"], ["This sentence is a sentence"]], "outputs": [["emocleW"], ["to"], ["sraWedoC"], ["Hey wollef sroirraw"], ["This ecnetnes is a ecnetnes"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,672 |
def spin_words(sentence):
|
1f21d6bfc08f331130f3ae0847951fa7 | UNKNOWN | ## The galactic games have begun!
It's the galactic games! Beings of all worlds come together to compete in several interesting sports, like nroogring, fredling and buzzing (the beefolks love the last one). However, there's also the traditional marathon run.
Unfortunately, there have been cheaters in the last years, ... | ["def summ(number, d):\n n = (number - 1) // d\n return n * (n + 1) * d // 2\n\ndef solution(number):\n return summ(number, 3) + summ(number, 5) - summ(number, 15)\n", "def solution(number):\n a = (number - 1) // 5\n b = (number - 1) // 3\n c = (number - 1) // 15\n \n sum_a = ((a * (a + 1)) // 2... | {"fn_name": "solution", "inputs": [[10], [100], [1000], [10000], [16], [20], [200], [1000000], [50000000], [50000000000000000000000000000000000000000]], "outputs": [[23], [2318], [233168], [23331668], [60], [78], [9168], [233333166668], [583333291666668], [583333333333333333333333333333333333333291666666666666666666666... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,004 |
def solution(number):
|
d22e9f8c8ac12e3652b01d6d2d86f3ec | UNKNOWN | This function takes two numbers as parameters, the first number being the coefficient, and the second number being the exponent.
Your function should multiply the two numbers, and then subtract 1 from the exponent. Then, it has to print out an expression (like 28x^7). `"^1"` should not be truncated when exponent = 2.
... | ["def derive(coefficient, exponent): \n return f'{coefficient * exponent}x^{exponent - 1}'", "def derive(coefficient, exponent): \n a=coefficient*exponent\n b=exponent-1\n txt=\"{}x^{}\"\n return txt.format(a,b)", "def derive(coefficient, exponent): \n return(\"{}x^{}\".format(coefficient*exponent, ex... | {"fn_name": "derive", "inputs": [[7, 8], [5, 9]], "outputs": [["56x^7"], ["45x^8"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 13,681 |
def derive(coefficient, exponent):
|
657b8f494b59a7b6648d78c4906f1214 | UNKNOWN | Complete the method which returns the number which is most frequent in the given input array. If there is a tie for most frequent number, return the largest number among them.
Note: no empty arrays will be given.
## Examples
```
[12, 10, 8, 12, 7, 6, 4, 10, 12] --> 12
[12, 10, 8, 12, 7, 6, 4, 10, 12, ... | ["from collections import Counter\n\ndef highest_rank(arr):\n if arr:\n c = Counter(arr)\n m = max(c.values())\n return max(k for k,v in c.items() if v==m)", "def highest_rank(arr):\n return sorted(arr,key=lambda x: (arr.count(x),x))[-1]", "def highest_rank(arr):\n return max(sorted(arr,re... | {"fn_name": "highest_rank", "inputs": [[[12, 10, 8, 12, 7, 6, 4, 10, 12]], [[12, 10, 8, 12, 7, 6, 4, 10, 10]], [[12, 10, 8, 12, 7, 6, 4, 10, 12, 10]], [[12, 10, 8, 8, 3, 3, 3, 3, 2, 4, 10, 12, 10]], [[1, 2, 3]], [[1, 1, 2, 3]], [[1, 1, 2, 2, 3]]], "outputs": [[12], [10], [12], [3], [3], [1], [2]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,955 |
def highest_rank(arr):
|
d32bc2fc4c686414b91d420ed183d4ba | UNKNOWN | A happy number is a number defined by the following process: starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1.
Those numbers for which this pro... | ["def is_happy(n):\n seen = set()\n while n!=1:\n n = sum(int(d)**2 for d in str(n))\n if n not in seen: seen.add(n)\n else: return False\n return True", "def is_happy(n):\n while n > 4:\n n = sum(int(d)**2 for d in str(n))\n return n == 1\n", "def is_happy(n):\n ... | {"fn_name": "is_happy", "inputs": [[1], [7], [16]], "outputs": [[true], [true], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,509 |
def is_happy(n):
|
cf313df971f2b833e7581e4737b85828 | UNKNOWN | Given an array, return the difference between the count of even numbers and the count of odd numbers. `0` will be considered an even number.
```
For example:
solve([0,1,2,3]) = 0 because there are two even numbers and two odd numbers. Even - Odd = 2 - 2 = 0.
```
Let's now add two letters to the last example:
```
... | ["def solve(a):\n return sum(1 if v % 2 == 0 else -1 for v in a if type(v) == int)", "def solve(a):\n return sum( isinstance(x, int) and [1, -1][x % 2] for x in a )", "def solve(a):\n diff = 0\n for e in a:\n if type(e) == int:\n if e % 2:\n diff -= 1\n else:\n ... | {"fn_name": "solve", "inputs": [[[0, 1, 2, 3]], [[0, 1, 2, 3, "a", "b"]], [[0, 15, "z", 16, "m", 13, 14, "c", 9, 10, 13, "u", 4, 3]], [[13, 6, 8, 15, 4, 8, 13]], [[1, "a", 17, 8, "e", 3, "i", 12, 1]], [[5, 15, 16, 10, 6, 4, 16, "t", 13, "n", 14, "k", "n", 0, "q", "d", 7, 9]]], "outputs": [[0], [0], [0], [1], [-2], [2]]... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,314 |
def solve(a):
|
21586cb7d761f8ec0a796c62161d10b8 | UNKNOWN | Everybody knows the classic ["half your age plus seven"](https://en.wikipedia.org/wiki/Age_disparity_in_sexual_relationships#The_.22half-your-age-plus-seven.22_rule) dating rule that a lot of people follow (including myself). It's the 'recommended' age range in which to date someone.
```minimum age <= your age <= ... | ["def dating_range(age):\n if age <= 14:\n min = age - 0.10 * age\n max = age + 0.10 * age\n else:\n min = (age/2)+7\n max = (age-7)*2\n \n return str(int(min))+'-'+str(int(max))", "def dating_range(age):\n if age <= 14:\n return \"{}-{}\".format(int(age-0.1*age), i... | {"fn_name": "dating_range", "inputs": [[17], [40], [15], [35], [10], [53], [19], [12], [7], [33]], "outputs": [["15-20"], ["27-66"], ["14-16"], ["24-56"], ["9-11"], ["33-92"], ["16-24"], ["10-13"], ["6-7"], ["23-52"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 19,793 |
def dating_range(age):
|
e49dfc42a8979b377710b23d902ed4cb | UNKNOWN | Write a method `alternate_sq_sum()` (JS: `alternateSqSum` ) that takes an array of integers as input and finds the sum of squares of the elements at even positions (*i.e.,* 2nd, 4th, *etc.*) plus the sum of the rest of the elements at odd position.
NOTE:
The values at even *position* need to be squared. For a language... | ["def alternate_sq_sum(arr):\n return sum([ x**2 if i % 2 == 1 else x for i, x in enumerate(arr) ])", "def alternate_sq_sum(arr):\n return sum(x * x for x in arr[1::2]) + sum(arr[::2])", "def alternate_sq_sum(arr):\n return sum(n * (n if i % 2 else 1) for i, n in enumerate(arr))", "def alternate_sq_sum(arr):\n... | {"fn_name": "alternate_sq_sum", "inputs": [[[]], [[-1, 0, -3, 0, -5, 3]], [[-1, 2, -3, 4, -5]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]], "outputs": [[0], [0], [11], [245]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 885 |
def alternate_sq_sum(arr):
|
7e359a1861039c430555c18d8ded003a | UNKNOWN | Consider the string `"1 2 36 4 8"`. Lets take pairs of these numbers, concatenate each pair and determine how many of them of divisible by `k`.
```Pearl
If k = 3, we get following numbers ['12', '18', '21', '24', '42', '48', '81', '84'], all divisible by 3.
Note:
-- 21 and 12 are different pairs.
-- Elements mus... | ["from itertools import permutations\n\ndef solve(s,k):\n return sum(not v%k for v in map(int, map(''.join, permutations(s.split(),2))))", "from itertools import permutations\n\ndef solve(stg, k):\n return sum(1 for m, n in permutations(stg.split(), 2) if int(f\"{m}{n}\") % k == 0)", "from itertools import permut... | {"fn_name": "solve", "inputs": [["1 2 36 4 8", 2], ["1 2 36 4 8", 3], ["1 2 36 4 8", 4], ["1 2 36 4 8", 8]], "outputs": [[16], [8], [11], [4]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,449 |
def solve(s,k):
|
e963066e92739e1f1ece219fa055cabf | UNKNOWN | Write the following function:
```python
def area_of_polygon_inside_circle(circle_radius, number_of_sides):
```
It should calculate the area of a regular polygon of `numberOfSides`, `number-of-sides`, or `number_of_sides` sides inside a circle of radius `circleRadius`, `circle-radius`, or `circle_radius` which passes ... | ["from math import sin, pi\n\ndef area_of_polygon_inside_circle(r, n):\n return round(0.5 * n * r ** 2 * sin(2 * pi / n), 3)", "from math import sin, pi\n\ndef area_of_polygon_inside_circle(r, n):\n return round(n*r*r*sin(2*pi/n)/2, 3)", "import math\ndef area_of_polygon_inside_circle(circle_radius, number_of_sid... | {"fn_name": "area_of_polygon_inside_circle", "inputs": [[3, 3], [2, 4], [2.5, 5]], "outputs": [[11.691], [8], [14.86]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,531 |
def area_of_polygon_inside_circle(r, n):
|
e9491890cb38597852d1a8e564df184f | UNKNOWN | Your job is to return the volume of a cup when given the diameter of the top, the diameter of the bottom and the height.
You know that there is a steady gradient from the top to the bottom.
You want to return the volume rounded to 2 decimal places.
Exmples:
```python
cup_volume(1, 1, 1)==0.79
cup_volume(10, 8, 10)=... | ["from math import pi\n\ndef cup_volume(d1, d2, h):\n return round(h / 12.0 * pi * (d1**2 + d1*d2 + d2**2), 2)", "from math import pi\ndef cup_volume(d1, d2, height):\n r1, r2 = d1 / 2.0, d2 / 2.0\n return round(pi * height * (pow(r1, 2) + r1 * r2 + pow(r2, 2)) / 3.0, 2)", "from math import pi\n\ndef cup_volum... | {"fn_name": "cup_volume", "inputs": [[1, 1, 1], [10, 8, 10], [1000, 1000, 1000], [13.123, 123.12, 1], [5, 12, 31]], "outputs": [[0.79], [638.79], [785398163.4], [4436.57], [1858.51]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,288 |
def cup_volume(d1, d2, height):
|
1223dae011ac36aa0c3160eae9158df8 | UNKNOWN | This is now a little serie :)
Funny Dots
You will get two Integer n (width) and m (height) and your task is to draw following pattern. Each line is seperated with '\n'.
Both integers are equal or greater than 1. No need to check for invalid parameters.
e.g.:
+---+---+---... | ["def dot(n, m):\n sep = '+---' * n + '+'\n dot = '| o ' * n + '|'\n return '\\n'.join([sep, dot] * m + [sep])", "def dot(n,m):\n result = [(\"+---\" * n) + \"+\" + \"\\n\" + (\"| o \" * n) + \"|\" for i in range(m)]\n result.append((\"+---\" * n) + \"+\")\n return \"\\n\".join(result)", "def dot(n,m)... | {"fn_name": "dot", "inputs": [[1, 1], [3, 2]], "outputs": [["+---+\n| o |\n+---+"], ["+---+---+---+\n| o | o | o |\n+---+---+---+\n| o | o | o |\n+---+---+---+"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,484 |
def dot(n,m):
|
e38c6f5157ec4ea5c00aa823560f081b | UNKNOWN | Roma is programmer and he likes memes about IT,
Maxim is chemist and he likes memes about chemistry,
Danik is designer and he likes memes about design,
and Vlad likes all other memes.
___
You will be given a meme (string), and your task is to identify its category, and send it to the right receiver: `IT - 'Roma... | ["import re\nfrom itertools import accumulate\n\n\npatterns = [\n (re.compile('.*'.join('bug'), flags=re.I), 'Roma'),\n (re.compile('.*'.join('boom'), flags=re.I), 'Maxim'),\n (re.compile('.*'.join('edits'), flags=re.I), 'Danik'),\n]\n\ndef memesorting(meme):\n return next((who for m in accumulate(meme) for... | {"fn_name": "memesorting", "inputs": [["This is programmer meme ecause it has bug"], ["This is also programbur meme gecause it has needed key word"], ["This is edsigner meme cause it has key word"], ["This could be chemistry meme but our gey word boom is too late"], ["This is meme"]], "outputs": [["Roma"], ["Roma"], ["... | INTRODUCTORY | PYTHON3 | CODEWARS | 4,324 |
def memesorting(meme):
|
f4aa26f7feb060f3820d7a4dacf4e005 | UNKNOWN | # Description
Write a function that accepts the current position of a knight in a chess board, it returns the possible positions that it will end up after 1 move. The resulted should be sorted.
## Example
"a1" -> ["b3", "c2"] | ["def possible_positions(p):\n r, c = ord(p[0])-96, int(p[1])\n moves = [(-2,-1), (-2,1), (-1,-2), (-1,2), (1,-2), (1,2), (2,-1), (2,1)]\n return [''.join((chr(r+i+96), str(c+j))) for i, j in moves if 1 <= r+i <= 8 and 1 <= c+j <= 8]", "def possible_positions(pos):\n col = \"abcdefgh\"\n row = \"12345678... | {"fn_name": "possible_positions", "inputs": [["a1"], ["f7"], ["c3"]], "outputs": [[["b3", "c2"]], [["d6", "d8", "e5", "g5", "h6", "h8"]], [["a2", "a4", "b1", "b5", "d1", "d5", "e2", "e4"]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,213 |
def possible_positions(pos):
|
d0223dbe1478c9a2aa9789715bb3714c | UNKNOWN | Find the first character that repeats in a String and return that character.
```python
first_dup('tweet') => 't'
first_dup('like') => None
```
*This is not the same as finding the character that repeats first.*
*In that case, an input of 'tweet' would yield 'e'.* | ["def first_dup(s):\n for x in s:\n if s.count(x) > 1:\n return x\n return None", "def first_dup(s):\n return next((x for x in s if s.count(x) > 1),None)", "from collections import Counter, OrderedDict\n\nclass OC(Counter,OrderedDict): pass\n\ndef first_dup(s):\n return next((c for c,n in ... | {"fn_name": "first_dup", "inputs": [["tweet"], ["Ode to Joy"], ["ode to joy"], ["bar"]], "outputs": [["t"], [" "], ["o"], [null]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,100 |
def first_dup(s):
|
5719ce5e3346be74a0d918234aba05d4 | UNKNOWN | Write a function that reverses the bits in an integer.
For example, the number `417` is `110100001` in binary. Reversing the binary is `100001011` which is `267`.
You can assume that the number is not negative. | ["def reverse_bits(n):\n return int(bin(n)[:1:-1],2)", "def reverse_bits(n):\n return int(f'{n:b}'[::-1],2)", "def reverse_bits(n):\n return int(bin(n)[-1:1:-1], 2)", "def reverse_bits(n):\n listbin = [bin(n)]\n listbin.sort(reverse = True)\n pleasework = list(''.join(listbin))\n comeonguy = ''.jo... | {"fn_name": "reverse_bits", "inputs": [[417], [267], [0], [2017], [1023], [1024]], "outputs": [[267], [417], [0], [1087], [1023], [1]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 972 |
def reverse_bits(n):
|
15346767d41c637a5d4f80f0b936b921 | UNKNOWN | Your task is to create a function that does four basic mathematical operations.
The function should take three arguments - operation(string/char), value1(number), value2(number).
The function should return result of numbers after applying the chosen operation.
### Examples
```python
basic_op('+', 4, 7) # O... | ["def basic_op(operator, value1, value2):\n if operator=='+':\n return value1+value2\n if operator=='-':\n return value1-value2\n if operator=='/':\n return value1/value2\n if operator=='*':\n return value1*value2", "def basic_op(operator, value1, value2):\n return eval(\"{}{}... | {"fn_name": "basic_op", "inputs": [["+", 4, 7], ["-", 15, 18], ["*", 5, 5], ["/", 49, 7]], "outputs": [[11], [-3], [25], [7]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 22,087 |
def basic_op(operator, value1, value2):
|
75b495066d40c765ce0f6bce162917f5 | UNKNOWN | # Task
Given an array `arr`, find the maximal value of `k` such `a[i] mod k` = `a[j] mod k` for all valid values of i and j.
If it's impossible to find such number (there's an infinite number of `k`s), return `-1` instead.
# Input/Output
`[input]` integer array `arr`
A non-empty array of positive integer.
`2 <= a... | ["def finding_k(arr):\n for n in range(max(arr)-1, 0, -1):\n if len({ x%n for x in arr }) == 1: return n\n return -1", "from itertools import repeat\nfrom functools import reduce\nfrom operator import sub\nfrom math import gcd\n\ndef finding_k(arr):\n return reduce(gcd, filter(None, map(sub, set(arr), r... | {"fn_name": "finding_k", "inputs": [[[1, 2, 3]], [[1, 1, 1]], [[5, 2, 8]], [[4, 1, 7]], [[1, 7, 13]], [[4, 5, 4]], [[5, 6, 7, 8]], [[10, 100]], [[64, 8, 1]], [[2, 9, 30]]], "outputs": [[1], [-1], [3], [3], [6], [1], [1], [90], [7], [7]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,781 |
def finding_k(arr):
|
bc7074edd7ad782ac97b6e0bf6f2240a | UNKNOWN | Given a string containing a list of integers separated by commas, write the function string_to_int_list(s) that takes said string and returns a new list containing all integers present in the string, preserving the order.
For example, give the string "-1,2,3,4,5", the function string_to_int_list() should return [-1,2,... | ["def string_to_int_list(s):\n return [int(n) for n in s.split(\",\") if n]", "def string_to_int_list(s):\n return [int(x) for x in s.split(',') if x != '']", "def string_to_int_list(s):\n return [int(x) for x in s.split(',') if x]", "import re\nnumber_pattern = re.compile(\"-?[0-9]+\")\n\ndef string_to_int_li... | {"fn_name": "string_to_int_list", "inputs": [["1,2,3,4,5"], ["21,12,23,34,45"], ["-1,-2,3,-4,-5"], ["1,2,3,,,4,,5,,,"], [",,,,,1,2,3,,,4,,5,,,"], [""], [",,,,,,,,"]], "outputs": [[[1, 2, 3, 4, 5]], [[21, 12, 23, 34, 45]], [[-1, -2, 3, -4, -5]], [[1, 2, 3, 4, 5]], [[1, 2, 3, 4, 5]], [[]], [[]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 927 |
def string_to_int_list(s):
|
ac5a81578e046d7bec6381301d498229 | UNKNOWN | Given an integer, take the (mean) average of each pair of consecutive digits. Repeat this process until you have a single integer, then return that integer. e.g.
Note: if the average of two digits is not an integer, round the result **up** (e.g. the average of 8 and 9 will be 9)
## Examples
```
digitsAverage(246) =... | ["def digits_average(input):\n digits = [int(c) for c in str(input)]\n while len(digits) > 1:\n digits = [(a + b + 1) // 2 for a, b in zip(digits, digits[1:])]\n return digits[0]", "digits_average=a=lambda n:n>9and a(int(''.join(str(-~int(a)+int(b)>>1)for a,b in zip(str(n),str(n)[1:]))))or n", "import m... | {"fn_name": "digits_average", "inputs": [[246], [89], [2], [245], [345], [346], [3700]], "outputs": [[4], [9], [2], [4], [5], [5], [4]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,610 |
def digits_average(input):
|
3b6b7dfe0d228a931028e4dc08364978 | UNKNOWN | # Task
Given some sticks by an array `V` of positive integers, where V[i] represents the length of the sticks, find the number of ways we can choose three of them to form a triangle.
# Example
For `V = [2, 3, 7, 4]`, the result should be `1`.
There is only `(2, 3, 4)` can form a triangle.
For `V = [5, 6, 7, 8]`... | ["from itertools import combinations\n\ndef counting_triangles(v):\n v.sort()\n return sum(a+b>c for a,b,c in combinations(v,3))", "counting_triangles=lambda V:sum(a+b>c for a,b,c in __import__('itertools').combinations(sorted(V),3))", "import itertools\ndef counting_triangles(V):\n count = 0\n for x in ite... | {"fn_name": "counting_triangles", "inputs": [[[2, 3, 7, 4]], [[5, 6, 7, 8]], [[2, 2, 2, 2]], [[1, 2, 5]], [[1, 2, 3, 10, 20, 30, 4]], [[1, 2, 3]]], "outputs": [[1], [4], [4], [0], [1], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,591 |
def counting_triangles(V):
|
779a0b9074e86cafefe4532f9cf43592 | UNKNOWN | # How many urinals are free?
In men's public toilets with urinals, there is this unwritten rule that you leave at least one urinal free
between you and the next person peeing.
For example if there are 3 urinals and one person is already peeing in the left one, you will choose the
urinal on the right and not the one in... | ["def get_free_urinals(urinals):\n return -1 if '11' in urinals else sum(((len(l)-1)//2 for l in f'0{urinals}0'.split('1')))", "def get_free_urinals(urinals):\n if '11' in urinals: return -1\n if urinals == '0': return 1\n free = 0\n i = 0\n while (i < len(urinals)):\n if i == 0 and urinals[i:i... | {"fn_name": "get_free_urinals", "inputs": [["10001"], ["1001"], ["00000"], ["0000"], ["01000"], ["00010"], ["10000"], ["1"], ["0"], ["10"], ["110"], ["1011000001"]], "outputs": [[1], [0], [3], [2], [1], [1], [2], [0], [1], [0], [-1], [-1]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,141 |
def get_free_urinals(urinals):
|
1c9b10c86dafbef34aee68b19982097f | UNKNOWN | ### Background
In classical cryptography, the Hill cipher is a polygraphic substitution cipher based on linear algebra. It was invented by Lester S. Hill in 1929.
### Task
This cipher involves a text key which has to be turned into a matrix and text which needs to be encoded. The text key can be of any perfect squ... | ["import numpy as np\nfrom itertools import zip_longest\nfrom string import ascii_lowercase as lower, ascii_uppercase as upper\n\nD = {c:i%26 for i,c in enumerate(lower+upper)}\n\ndef encrypt(text, key):\n result = []\n text = ''.join(filter(str.isalpha, text))\n key = np.array(([D[key[0]], D[key[1]]], [D[key[... | {"fn_name": "encrypt", "inputs": [["", "azyb"], ["hello", "hill"], ["This is a good day", "bbaa"], ["CODEWARS IS GREAT", "wxyz"], ["Five + Seven = Twelve", "math"], ["+-*/ &*%^$", "azyb"]], "outputs": [[""], ["DRJIMN"], ["AAAAAAGACAGAYA"], ["CICQQIIASSDXKSFP"], ["IVSLIGSLAQEECSWR"], [""]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 8,885 |
def encrypt(text,key):
|
b630fdae43279059fef73aab97869f2b | UNKNOWN | Write a function that takes an arbitrary number of strings and interlaces them (combines them by alternating characters from each string).
For example `combineStrings('abc', '123')` should return `'a1b2c3'`.
If the strings are different lengths the function should interlace them until each string runs out, continuing... | ["from itertools import zip_longest\n\ndef combine_strings(*args):\n return ''.join(''.join(x) for x in zip_longest(*args, fillvalue=''))", "from itertools import zip_longest, chain\ndef combine_strings(*args):\n return ''.join(chain(*zip_longest(*args, fillvalue = '')))", "from itertools import zip_longest\ncomb... | {"fn_name": "combine_strings", "inputs": [["abc"], ["abc", "123"], ["abcd", "123"], ["abc", "1234"], ["abc", "123", "$%"], ["abcd", "123", "$%"], ["abcd", "123", "$%^&"], ["abcd", "123", "$%^&", "qwertyuiop"], ["abcd", "123", "$%^&", "qwertyuiop", "X"]], "outputs": [["abc"], ["a1b2c3"], ["a1b2c3d"], ["a1b2c34"], ["a1$b... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,456 |
def combine_strings(*args):
|
2bdd03681bb26e13a6f275000078cc17 | UNKNOWN | # Story
You and a group of friends are earning some extra money in the school holidays by re-painting the numbers on people's letterboxes for a small fee.
Since there are 10 of you in the group each person just concentrates on painting one digit! For example, somebody will paint only the ```1```'s, somebody else will... | ["def paint_letterboxes(start, finish):\n xs = [0] * 10\n for n in range(start, finish+1):\n for i in str(n):\n xs[int(i)] += 1\n return xs", "from collections import Counter\n\ndef paint_letterboxes(s, f):\n a = Counter(\"\".join(map(str, range(s, f+1))))\n return [a[x] for x in \"0123... | {"fn_name": "paint_letterboxes", "inputs": [[125, 132], [1001, 1001]], "outputs": [[[1, 9, 6, 3, 0, 1, 1, 1, 1, 1]], [[2, 2, 0, 0, 0, 0, 0, 0, 0, 0]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,698 |
def paint_letterboxes(start, finish):
|
a9e10f3a819e256436955297a2f16093 | UNKNOWN | Mike and Joe are fratboys that love beer and games that involve drinking. They play the following game: Mike chugs one beer, then Joe chugs 2 beers, then Mike chugs 3 beers, then Joe chugs 4 beers, and so on. Once someone can't drink what he is supposed to drink, he loses.
Mike can chug at most A beers in total (other... | ["def game(maxMike, maxJoe):\n roundsMike = int(maxMike**.5)\n roundsJoe = (-1 + (1 + 4*maxJoe)**.5) // 2\n return (\"Non-drinkers can't play\" if not maxMike or not maxJoe else\n \"Joe\" if roundsMike <= roundsJoe else \n \"Mike\")", "def game(a, b):\n if a * b:\n c = int(a **... | {"fn_name": "game", "inputs": [[3, 2], [4, 2], [9, 1000], [0, 1]], "outputs": [["Joe"], ["Mike"], ["Joe"], ["Non-drinkers can't play"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,259 |
def game(a, b):
|
2a9384efd2614a69843ac37d00c248ea | UNKNOWN | Make multiple functions that will return the sum, difference, modulus, product, quotient, and the exponent respectively.
Please use the following function names:
addition = **add**
multiply = **multiply**
division = **divide** (both integer and float divisions are accepted)
modulus = **mod**
exponential = **expo... | ["add = lambda a, b: a + b\nmultiply = lambda a, b: a * b\ndivide = lambda a, b: a / b\nmod = lambda a, b: a % b\nexponent = lambda a, b: a ** b\nsubt = lambda a, b:a - b\n", "def add(a,b):\n return a + b \ndef multiply(a,b):\n return a * b\ndef divide(a,b):\n return a / b\ndef mod(a,b):\n return a % b\ndef exponen... | {"fn_name": "add", "inputs": [[1, 2], [5, 7]], "outputs": [[3], [12]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 26,127 |
def add(a,b):
|
db00545c4be8240fb0355052a1863518 | UNKNOWN | You received a whatsup message from an unknown number. Could it be from that girl/boy with a foreign accent you met yesterday evening?
Write a simple regex to check if the string contains the word hallo in different languages.
These are the languages of the possible people you met the night before:
* hello - english... | ["def validate_hello(greetings):\n return any(x in greetings.lower() for x in ['hello','ciao','salut','hallo','hola','ahoj','czesc'])", "from re import compile, search, I\n\nREGEX = compile(r'hello|ciao|salut|hallo|hola|ahoj|czesc', I)\n\n\ndef validate_hello(greeting):\n return bool(search(REGEX, greeting))\n", ... | {"fn_name": "validate_hello", "inputs": [["hello"], ["ciao bella!"], ["salut"], ["hallo, salut"], ["hombre! Hola!"], ["Hallo, wie geht's dir?"], ["AHOJ!"], ["czesc"], ["meh"], ["Ahoj"]], "outputs": [[true], [true], [true], [true], [true], [true], [true], [true], [false], [true]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 20,297 |
def validate_hello(greetings):
|
75430eeb545e7e3e65c4b975b6f72f4b | UNKNOWN | # Task
Elections are in progress!
Given an array of numbers representing votes given to each of the candidates, and an integer which is equal to the number of voters who haven't cast their vote yet, find the number of candidates who still have a chance to win the election.
The winner of the election must secure stri... | ["def elections_winners(votes, k):\n m = max(votes)\n return sum(x + k > m for x in votes) or votes.count(m) == 1", "def elections_winners(votes, k):\n best = max(votes)\n if k == 0 and votes.count(best) == 1:\n return 1\n return len([x for x in votes if x + k > best])", "def elections_winners(votes, k):\... | {"fn_name": "elections_winners", "inputs": [[[2, 3, 5, 2], 3], [[1, 3, 3, 1, 1], 0], [[5, 1, 3, 4, 1], 0], [[1, 1, 1, 1], 1], [[1, 1, 1, 1], 0], [[3, 1, 1, 3, 1], 2]], "outputs": [[2], [0], [1], [4], [0], [2]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,422 |
def elections_winners(votes, k):
|
b1fa1ec95065934ba90558db1abb9e42 | UNKNOWN | # A History Lesson
Soundex is an interesting phonetic algorithm developed nearly 100 years ago for indexing names as they are pronounced in English. The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling.
Reference: https://en.wikipedia.or... | ["import re\n\nREPLACMENTS = [\"BFPV\", \"CGJKQSXZ\", \"DT\",\"L\",\"MN\",\"R\"]\nER1, ER2 = \"HW\", \"AEIOUY\"\n\nTABLE_ERASE1 = str.maketrans(\"\", \"\", ER1)\nTABLE_NUMS = str.maketrans( ''.join(REPLACMENTS), ''.join( str(n)*len(elt) for n,elt in enumerate(REPLACMENTS, 1)) )\nTABLE_ERASE2 = str.maketrans(\"\"... | {"fn_name": "soundex", "inputs": [["Sarah Connor"], ["Sara Conar"], ["Serah Coner"], ["Sarh Connor"], ["Sayra Cunnarr"], ["Tim"], ["Joe"], ["Bob"], ["Robert"], ["Rupert"], ["Rubin"], ["Ashcraft"], ["Ashcroft"], ["Tymczak"], ["Pfister"], ["zxqurlwbx"], ["uryrtkzp"]], "outputs": [["S600 C560"], ["S600 C560"], ["S600 C560... | INTRODUCTORY | PYTHON3 | CODEWARS | 7,221 |
def soundex(name):
|
0f767fc79c0fb603cfc35318bd22e517 | UNKNOWN | Given a string of words, you need to find the highest scoring word.
Each letter of a word scores points according to its position in the alphabet: `a = 1, b = 2, c = 3` etc.
You need to return the highest scoring word as a string.
If two words score the same, return the word that appears earliest in the original str... | ["def high(x):\n return max(x.split(), key=lambda k: sum(ord(c) - 96 for c in k))", "def high(x):\n words=x.split(' ')\n list = []\n for i in words:\n scores = [sum([ord(char) - 96 for char in i])]\n list.append(scores)\n return words[list.index(max(list))]", "def high(x):\n scoreboard=[... | {"fn_name": "high", "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 two bintang and a dance please"]], "outputs": [["taxi"], ["volcano"], ["semynak"], ["massage"], ["bintang"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,809 |
def high(x):
|
7f4406d71bbfb5814b22cf50512d3808 | UNKNOWN | In this kata, you have to define a function named **func** that will take a list as input.
You must try and guess the pattern how we get the output number and return list - **[output number,binary representation,octal representation,hexadecimal representation]**, but **you must convert that specific number without bui... | ["def func(l):\n n = sum(l) // len(l)\n return [n] + [format(n, f) for f in \"box\"]", "from statistics import mean\n\nDIGITS = '0123456789abcdef'\n\ndef to(n, base):\n result = []\n while n:\n n, r = divmod(n, base)\n result.append(DIGITS[r])\n return ''.join(reversed(result))\n\ndef func(... | {"fn_name": "func", "inputs": [[[1, 4, 9, 16, 25, 36, 49]], [[2, 31, 3, 56, 46, 3, 467, 33]], [[9, 99, 999, 9999]], [[1, 12, 123, 1234, 12345]], [[1, 2, 6, 3, 1, 577, 12]]], "outputs": [[[20, "10100", "24", "14"]], [[80, "1010000", "120", "50"]], [[2776, "101011011000", "5330", "ad8"]], [[2743, "101010110111", "5267", ... | INTRODUCTORY | PYTHON3 | CODEWARS | 3,083 |
def func(l):
|
e1714122694fb2877eb9a31d89cb890d | UNKNOWN | ### Preface
You are currently working together with a local community to build a school teaching children how to code. First plans have been made and the community wants to decide on the best location for the coding school.
In order to make this decision data about the location of students and potential locations is co... | ["def optimum_location(students, locations):\n m = min(locations, key = lambda loc: sum(abs(loc['x'] - s[0]) + abs(loc['y'] - s[1]) for s in students))\n return \"The best location is number %d with the coordinates x = %d and y = %d\" % (m['id'], m['x'], m['y'])\n", "def manhattan(p1,p2): return sum(abs(b-a) for ... | {"fn_name": "optimum_location", "inputs": [[[[3, 7], [2, 2], [14, 1]], [{"id": 1, "x": 3, "y": 4}, {"id": 2, "x": 8, "y": 2}]], [[[54, 7], [1, 211], [14, 44], [12, 5], [14, 7]], [{"id": 1, "x": 44, "y": 55}, {"id": 2, "x": 12, "y": 57}, {"id": 3, "x": 23, "y": 66}]], [[[152, 7], [1, 211], [14, 56], [12, 4], [142, 7]], ... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,794 |
def optimum_location(students, locations):
|
68edc0ed452af945b58cfe11224421de | UNKNOWN | Build a function `sumNestedNumbers`/`sum_nested_numbers` that finds the sum of all numbers in a series of nested arrays raised to the power of their respective nesting levels. Numbers in the outer most array should be raised to the power of 1.
For example,
should return `1 + 2*2 + 3 + 4*4 + 5*5*5 === 149` | ["def sum_nested_numbers(a, depth=1):\n return sum(sum_nested_numbers(e, depth+1) if type(e) == list else e**depth for e in a)", "def sum_nested_numbers(arr,m=1):\n total = 0\n for element in arr:\n if isinstance(element, int): \n total += element**m\n else:\n total += sum_n... | {"fn_name": "sum_nested_numbers", "inputs": [[[0]], [[1, 2, 3, 4, 5]], [[1, [2], 3, [4, [5]]]], [[6, [5], [[4]], [[[3]]], [[[[2]]]], [[[[[1]]]]]]], [[1, [-1], [[1]], [[[-1]]], [[[[1]]]]]]], "outputs": [[0], [15], [149], [209], [5]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,675 |
def sum_nested_numbers(a, depth=1):
|
39210cf5c6d12aced460d255d8f7821e | UNKNOWN | # A History Lesson
The Pony Express was a mail service operating in the US in 1859-60.
It reduced the time for messages to travel between the Atlantic and Pacific coasts to about 10 days, before it was made obsolete by the transcontinental telegraph.
# How it worked
There were a number of *stations*, where:
*... | ["def riders(stations, lost):\n stations = stations[:lost-1] + stations[lost-2:]\n rider, dist = 1, 0\n for i,d in enumerate(stations):\n rider += (dist+d > 100) + (i == lost-2)\n dist = dist * (dist+d <= 100 and i != lost-2) + d\n return rider", "LIMIT = 100\n\ndef riders(stations, station_... | {"fn_name": "riders", "inputs": [[[43, 23, 40, 13], 4], [[18, 15], 2], [[43, 23, 40, 13], 3], [[33, 8, 16, 47, 30, 30, 46], 5], [[6, 24, 6, 8, 28, 8, 23, 47, 17, 29, 37, 18, 40, 49], 2], [[50, 50], 2], [[50, 50, 25, 50, 24], 3], [[50, 51, 25, 50, 25], 3], [[50, 100, 25, 50, 26], 3], [[100], 2], [[50, 50], 3], [[50, 51]... | INTRODUCTORY | PYTHON3 | CODEWARS | 3,984 |
def riders(stations, station_x):
|
f63cb005c69284e2a2b23305d40d97f7 | UNKNOWN | Complete the solution so that it returns the number of times the search_text is found within the full_text.
```python
search_substr( fullText, searchText, allowOverlap = true )
```
so that overlapping solutions are (not) counted. If the searchText is empty, it should return `0`. Usage examples:
```python
search_subs... | ["import re\n\ndef search_substr(full_text, search_text, allow_overlap=True):\n if not full_text or not search_text: return 0\n return len(re.findall(f'(?=({search_text}))' if allow_overlap else search_text, full_text))", "import re\n\ndef search_substr(origin, target, overlap=True):\n if not target: return 0\... | {"fn_name": "search_substr", "inputs": [["aa_bb_cc_dd_bb_e", "bb"], ["aaabbbcccc", "bbb"], ["aaacccbbbcccc", "cc"], ["aaa", "aa"], ["aaa", "aa", false], ["aaabbbaaa", "bb", false], ["a", ""], ["", "a"], ["", ""], ["", "", false]], "outputs": [[2], [1], [5], [2], [1], [1], [0], [0], [0], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,791 |
def search_substr(full_text, search_text, allow_overlap=True):
|
f126c597f1183fdfaaa7d803f63036f0 | UNKNOWN | Implement a function which
creates a **[radix tree](https://en.wikipedia.org/wiki/Radix_tree)** (a space-optimized trie [prefix tree])
in which each node that is the only child is merged with its parent [unless a word from the input ends there])
from a given list of words
using dictionaries (aka hash maps or hash t... | ["from itertools import groupby\nfrom operator import itemgetter\nfrom os.path import commonprefix\n\nfirst = itemgetter(0)\n\ndef radix_tree(*words):\n words = [w for w in words if w]\n result = {}\n for key, grp in groupby(sorted(words), key=first):\n lst = list(grp)\n prefix = commonprefix(lst... | {"fn_name": "radix_tree", "inputs": [[""], ["abc", "def", "ghi", "jklm", "nop"], ["ape", "apple"], ["ape", "appendix", "apel"], ["ape", "apple", "applet", "appendix"], ["romane", "romanus", "romulus"], ["test", "tester", "testers"], ["test", "tester", "testers", "tester"], ["testers", "tester", "test"]], "outputs": [[{... | INTRODUCTORY | PYTHON3 | CODEWARS | 4,660 |
def radix_tree(*words):
|
d44b29392f5fd425c28c895af1a64820 | UNKNOWN | Consider the number triangle below, in which each number is equal to the number above plus the number to the left. If there is no number above, assume it's a `0`.
The triangle has `5` rows and the sum of the last row is `sum([1,4,9,14,14]) = 42`.
You will be given an integer `n` and your task will be to return the su... | ["# https://oeis.org/A000108\nfrom math import factorial as fac\ndef solve(n): return fac(2*n)//fac(n)//fac(n+1)", "def binomial_coefficient (n, k):\n if not n >= k >= 0:\n return None\n lower_k = min(k, n-k)\n coeff = 1\n for i in range(lower_k):\n coeff *= n - i\n coeff //= i + 1\n ... | {"fn_name": "solve", "inputs": [[4], [5], [6], [7], [8], [20]], "outputs": [[14], [42], [132], [429], [1430], [6564120420]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,910 |
def solve(n):
|
a5144ea84a931b47e7a00af1a623d567 | UNKNOWN | An AI has infected a text with a character!!
This text is now **fully mutated** to this character.
If the text or the character are empty, return an empty string.
There will never be a case when both are empty as nothing is going on!!
**Note:** The character is a string of length 1 or an empty string.
# Example
... | ["def contamination(text, char):\n return char*len(text)", "def contamination(text, char):\n return len(text) * char", "import re\ndef contamination(text, char):\n return re.sub(\".\", char, text)", "import re\n\ndef contamination(text, char):\n if text == '' or char == '':\n return \"\"\n else:\n ... | {"fn_name": "contamination", "inputs": [["abc", "z"], ["", "z"], ["abc", ""], ["_3ebzgh4", "&"], ["//case", " "]], "outputs": [["zzz"], [""], [""], ["&&&&&&&&"], [" "]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 12,171 |
def contamination(text, char):
|
eb04091547560be6d446dff47d529e34 | UNKNOWN | Create a function that takes a string and returns that
string with the first half lowercased and the last half uppercased.
eg: foobar == fooBAR
If it is an odd number then 'round' it up to find which letters to uppercase. See example below.
sillycase("brian")
// --^-- midpoint
// bri ... | ["def sillycase(silly):\n half = (len(silly) + 1) // 2\n return silly[:half].lower() + silly[half:].upper()", "def sillycase(s):\n l = len(s)\n return s[:l//2+l%2].lower() + s[l//2+l%2:].upper()", "from math import ceil\ndef sillycase(silly):\n return silly[:ceil(len(silly)/2)].lower() + silly[ceil(len(s... | {"fn_name": "sillycase", "inputs": [["foobar"], ["codewars"], ["jAvASCript"], ["brian"], ["jabberwock"], ["SCOTland"], ["WeLlDoNe"]], "outputs": [["fooBAR"], ["codeWARS"], ["javasCRIPT"], ["briAN"], ["jabbeRWOCK"], ["scotLAND"], ["wellDONE"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,589 |
def sillycase(silly):
|
1df8458fdf23e46e193ddb0e8f5b7147 | UNKNOWN | Given 2 strings, your job is to find out if there is a substring that appears in both strings. You will return true if you find a substring that appears in both strings, or false if you do not. We only care about substrings that are longer than one letter long.
#Examples:
````
*Example 1*
SubstringTest("Something","F... | ["def substring_test(first, second):\n first = first.lower()\n second = second.lower()\n\n for i in range(len(first) - 2):\n if first[i:i+2] in second:\n return True\n return False", "def substring_test(str1, str2):\n str1 = str1.lower()\n str2 = str2.lower()\n return any(\n ... | {"fn_name": "substring_test", "inputs": [["Something", "Home"], ["Something", "Fun"], ["Something", ""], ["", "Something"], ["BANANA", "banana"], ["test", "lllt"], ["", ""], ["1234567", "541265"], ["supercalifragilisticexpialidocious", "SoundOfItIsAtrocious"], ["LoremipsumdolorsitametconsecteturadipiscingelitAeneannona... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,688 |
def substring_test(str1, str2):
|
7afe3976a3ea6007578ebcd2f8debd67 | UNKNOWN | How many days are we represented in a foreign country?
My colleagues make business trips to a foreign country. We must find the number of days our company is represented in a country. Every day that one or more colleagues are present in the country is a day that the company is represented. A single day cannot count fo... | ["def days_represented(a):\n return len({i for x, y in a for i in range(x, y + 1)})", "def days_represented(trips):\n L=[]\n for i in trips:\n for j in range(i[0],i[1]+1):\n L.append(j)\n a=set(L)\n return len(a)", "def days_represented(trips):\n return len({i for (start, stop) in tr... | {"fn_name": "days_represented", "inputs": [[[[10, 15], [25, 35]]], [[[2, 8], [220, 229], [10, 16]]]], "outputs": [[17], [24]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,900 |
def days_represented(trips):
|
457b2b72b501b2e775c1293ef92bda0e | UNKNOWN | When a warrior wants to talk with another one about peace or war he uses a smartphone. In one distinct country warriors who spent all time in training kata not always have enough money. So if they call some number they want to know which operator serves this number.
Write a function which **accepts number and retu... | ["OPERATORS = {\n '039': 'Golden Telecom', '050': 'MTS', '063': 'Life:)', '066': 'MTS',\n '067': 'Kyivstar', '068': 'Beeline', '093': 'Life:)', '095': 'MTS',\n '096': 'Kyivstar', '097': 'Kyivstar', '098': 'Kyivstar', '099': 'MTS'}\n\n\ndef detect_operator(num):\n return OPERATORS.get(str(num)[1:4], 'no info... | {"fn_name": "detect_operator", "inputs": [["80661111841"], ["80671991111"], ["80631551111"], ["80931551111"], ["80111551111"]], "outputs": [["MTS"], ["Kyivstar"], ["Life:)"], ["Life:)"], ["no info"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,135 |
def detect_operator(num):
|
1bac18b89ab9579abf41c60888c5da4e | UNKNOWN | # Task
Given a position of a knight on the standard chessboard, find the number of different moves the knight can perform.
The knight can move to a square that is two squares horizontally and one square vertically, or two squares vertically and one square horizontally away from it. The complete move therefore looks ... | ["def chess_knight(cell):\n x, y = (ord(c) - ord(origin) for c, origin in zip(cell, 'a1'))\n return sum(0 <= x + dx < 8 and 0 <= y + dy < 8 for dx, dy in (\n (-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1)))", "moves = {(-2, -1), (-2, 1), (-1, 2), (1, 2), (2, 1), (2, -1), (1, -2), (-... | {"fn_name": "chess_knight", "inputs": [["a1"], ["c2"], ["d4"], ["g6"]], "outputs": [[2], [6], [8], [6]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,777 |
def chess_knight(cell):
|
ea40d0d6c22563cd617aff19301e218d | UNKNOWN | # Fourier transformations are hard. Fouriest transformations are harder.
This Kata is based on the SMBC Comic on fourier transformations.
A fourier transformation on a number is one that converts the number to a base in which it has more `4`s ( `10` in base `6` is `14`, which has `1` four as opposed to none, hence, f... | ["def transform(num, base):\n digits = []\n \n while num > 0:\n num, remainder = divmod(num, base)\n digits.append( remainder if remainder < 10 else \"x\" )\n \n return digits\n\n\ndef fouriest(i):\n max_fours, base, best = 0, 5, [None, None]\n \n while i >= base**(max_fours):\n ... | {"fn_name": "fouriest", "inputs": [[30], [15], [9999], [35353], [100], [1000000243], [142042158218941532125212890], [2679388715912901287113185885289513476], [640614569414659959863091616350016384446719891887887380], [25791111079649870250475363614833123853740082482826554016752110339267820069204152249134948096885813148788... | INTRODUCTORY | PYTHON3 | CODEWARS | 6,436 |
def fouriest(i):
|
597a074d3864be5d1d4ff2419ae0b54d | UNKNOWN | Complete the function that takes an array of words.
You must concatenate the `n`th letter from each word to construct a new word which should be returned as a string, where `n` is the position of the word in the list.
For example:
```
["yoda", "best", "has"] --> "yes"
^ ^ ^
n=0 n=1 n=2
``... | ["def nth_char(words):\n return ''.join(w[i] for i,w in enumerate(words))\n", "def nth_char(words):\n return \"\".join( word[i] for i,word in enumerate(words))\n", "def nth_char(words):\n result = \"\"\n\n for index, word in enumerate(words):\n result += word[index]\n\n return result\n", "def nth_... | {"fn_name": "nth_char", "inputs": [[["yoda", "best", "has"]], [[]], [["X-ray"]], [["No", "No"]], [["Chad", "Morocco", "India", "Algeria", "Botswana", "Bahamas", "Ecuador", "Micronesia"]]], "outputs": [["yes"], [""], ["X"], ["No"], ["Codewars"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 837 |
def nth_char(words):
|
f6de22babeca524e42bff861d0a3d9b9 | UNKNOWN | Given a string S.
You have to return another string such that even-indexed and odd-indexed characters of S are grouped and groups are space-separated (see sample below)
Note:
0 is considered to be an even index.
All input strings are valid with no spaces
input:
'CodeWars'
output
'CdWr oeas'
S[0] = 'C'
S[1] = 'o'... | ["def sort_my_string(s):\n return '{} {}'.format(s[::2], s[1::2])", "def sort_my_string(s):\n return s[::2] + ' ' + s[1::2]", "def sort_my_string(S):\n return (S[0::2] + \" \" + S[1::2])", "def sort_my_string(S):\n return str(S[0::2] + ' ' + S[1::2])", "def sort_my_string(s):\n return f'{s[::2]} {s[1::2]... | {"fn_name": "sort_my_string", "inputs": [["Wolfeschlegelsteinhausenbergerdorff"], ["METHIONYLTHREONYLTHREONYGLUTAMINYLARGINYL"], ["PNEUMONOULTRAMICROSCOPICSILICOVOLCANOCONIOSIS"], ["PSEUDOPSEUDOHYPOPARATHYROIDISM"], ["FLOCCINAUCINIHILIPILIFICATION"], ["SUBDERMATOGLYPHIC"]], "outputs": [["Wleclgltihuebredrf ofsheesenasn... | INTRODUCTORY | PYTHON3 | CODEWARS | 883 |
def sort_my_string(s):
|
1da9e40545122d4a273ac1bdde4b7473 | UNKNOWN | # Task
John won the championship of a TV show. He can get some bonuses.
He needs to play a game to determine the amount of his bonus.
Here are `n` rows and `m` columns of cards were placed on the ground. A non-negative number is written on each card.
The rules of the game are:
- Player starts from the top-left con... | ["def calc(gamemap):\n nr, nc = len(gamemap), len(gamemap[0])\n def _i(ra, rb):\n return ra*nr + rb\n vs, ws = [0] * nr**2, [0] * nr**2\n for s in range(nr + nc - 1):\n for ra in range(max(0, s - nc + 1), min(s + 1, nr)):\n for rb in range(ra, min(s + 1, nr)):\n ws[_i... | {"fn_name": "calc", "inputs": [[[[1, 3, 9], [2, 8, 5], [5, 7, 4]]], [[[11, 72, 38], [80, 69, 65], [68, 96, 99]]], [[[1, 5, 1, 1], [1, 5, 5, 1], [5, 5, 5, 1], [1, 1, 5, 1]]], [[[0, 0, 2, 3, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 4, 0, 0], [0, 0,... | INTRODUCTORY | PYTHON3 | CODEWARS | 9,720 |
def calc(gamemap):
|
c644a46841187f36ae13a4488dcb5ea5 | UNKNOWN | Let's say take 2 strings, A and B, and define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings `abc` and `abd` is 2, while the similarity of strings `aaa` and `aaab` is 3.
write a function that calculates the sum of similarities of a st... | ["from os.path import commonprefix\n\ndef string_suffix(s):\n return sum(len(commonprefix([s, s[i:]])) for i in range(len(s)))", "def similarity(strng1, strng2):\n result = 0\n for c1, c2 in zip(strng1, strng2):\n if c1 != c2:\n break\n result += 1\n return result\n\ndef string_suff... | {"fn_name": "string_suffix", "inputs": [["aa"], ["abc"], ["ababaa"], ["aaaa"], ["aaaaa"], ["aaaaaa"], ["mnsomn"], ["apple"], ["a"], ["pippi"]], "outputs": [[3], [3], [11], [10], [15], [21], [8], [5], [1], [8]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,478 |
def string_suffix(s):
|
f964652cff2405ca0e8c5f1dde4e7edc | UNKNOWN | Your team is writing a fancy new text editor and you've been tasked with implementing the line numbering.
Write a function which takes a list of strings and returns each line prepended by the correct number.
The numbering starts at 1. The format is `n: string`. Notice the colon and space in between.
**Examples:**
`... | ["def number(lines):\n return ['%d: %s' % v for v in enumerate(lines, 1)]", "def number(lines):\n return [f\"{n}: {ligne}\" for n, ligne in enumerate(lines, 1)]\n", "def number(lines):\n return ['{}: {}'.format(n, s) for (n, s) in enumerate(lines, 1)]", "def number(lines):\n return [f\"{counter}: {line}\" for c... | {"fn_name": "number", "inputs": [[[]], [["a", "b", "c"]], [["", "", "", "", ""]], [["", "b", "", "", ""]]], "outputs": [[[]], [["1: a", "2: b", "3: c"]], [["1: ", "2: ", "3: ", "4: ", "5: "]], [["1: ", "2: b", "3: ", "4: ", "5: "]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 14,378 |
def number(lines):
|
7677c111d193ddfe0a64f3167fb17880 | UNKNOWN | # Explanation
It's your first day in the robot factory and your supervisor thinks that you should start with an easy task. So you are responsible for purchasing raw materials needed to produce the robots.
A complete robot weights `50` kilogram. Iron is the only material needed to create a robot. All iron is inserted ... | ["from math import ceil\n\ndef calculate_scrap(arr,n):\n x = 50\n for i in arr:\n x /= (1-i/100)\n return ceil(n*x)", "from functools import reduce\nfrom operator import mul\nfrom math import ceil\n\ndef calculate_scrap(scraps, number_of_robots):\n return ceil(50 * number_of_robots * 100**len(scraps)... | {"fn_name": "calculate_scrap", "inputs": [[[10], 90], [[20, 10], 55], [[0], 90], [[0, 0, 0], 90], [[10, 0], 90], [[0, 10], 90], [[10, 0, 0, 10], 81], [[0, 10, 0, 10], 81], [[0, 10, 10, 0], 81], [[10, 20, 30, 40, 50, 60, 70, 80, 90], 25], [[90, 80, 70, 60, 50, 40, 30, 20, 10], 20], [[10, 0, 30, 0, 50, 0, 70, 0, 90], 25]... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,135 |
def calculate_scrap(scraps, number_of_robots):
|
c5d5b86fa7a763da8c3198061465a895 | UNKNOWN | ```if-not:rust
Your task is to write a function `toLeetSpeak` that converts a regular english sentence to Leetspeak.
```
```if:rust
Your task is to write a function `to_leet_speak` that converts a regular english sentence to Leetspeak.
```
More about LeetSpeak You can read at wiki -> https://en.wikipedia.org/wiki/Leet... | ["def to_leet_speak(str):\n return str.translate(str.maketrans(\"ABCEGHILOSTZ\", \"@8(36#!10$72\"))", "def to_leet_speak(str):\n leet = {\n 'A' : '@',\n 'B' : '8',\n 'C' : '(',\n 'D' : 'D',\n 'E' : '3',\n 'F' : 'F',\n 'G' : '6',\n 'H': '#',\n 'I' : '!',\n 'J' : 'J',\n 'K' : 'K',\n 'L' : '1',\n 'M' : ... | {"fn_name": "to_leet_speak", "inputs": [["LEET"], ["CODEWARS"], ["HELLO WORLD"], ["LOREM IPSUM DOLOR SIT AMET"], ["THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"]], "outputs": [["1337"], ["(0D3W@R$"], ["#3110 W0R1D"], ["10R3M !P$UM D010R $!7 @M37"], ["7#3 QU!(K 8R0WN F0X JUMP$ 0V3R 7#3 1@2Y D06"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 42,050 |
def to_leet_speak(str):
|
3cfa9ebe1fc614de0163426daed9bf54 | UNKNOWN | Task:
Make a function that converts a word to pig latin. The rules of pig latin are:
```
If the word has more than 3 letters:
1. Take the first letter of a word and move it to the end
2. Add -ay to the word
Otherwise leave the word alone.
```
Example: `hello` = `ellohay` | ["def pig_latin(word):\n return word[1:]+word[0]+'ay' if len(word)>3 else word", "def pig_latin(word):\n return word if len(word) < 4 else word[1:]+word[0]+\"ay\"", "def pig_latin(word):\n return f\"{word[1:]}{word[0]}ay\" if len(word) > 3 else word", "def pig_latin(word):\n if len(word) > 3:\n ay = wo... | {"fn_name": "pig_latin", "inputs": [["hello"], ["hi"]], "outputs": [["ellohay"], ["hi"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,020 |
def pig_latin(word):
|
b9c8829e29757aa0972584b00656203c | UNKNOWN | You take your son to the forest to see the monkeys. You know that there are a certain number there (n), but your son is too young to just appreciate the full number, he has to start counting them from 1.
As a good parent, you will sit and count with him. Given the number (n), populate an array with all numbers up to a... | ["def monkey_count(n):\n return list(range(1,n+1))", "def monkey_count(n):\n return [i+1 for i in range(n)]", "def monkey_count(n):\n return [i for i in range(1, n+1)]", "def monkey_count(n):\n #your code here\n list = []\n for i in range(1,n+1):\n list.append(i)\n return list", "def monkey_... | {"fn_name": "monkey_count", "inputs": [[5], [3], [9], [10], [20]], "outputs": [[[1, 2, 3, 4, 5]], [[1, 2, 3]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 10,931 |
def monkey_count(n):
|
9a355af393d6dab2304cfed588830b26 | UNKNOWN | Laura really hates people using acronyms in her office and wants to force her colleagues to remove all acronyms before emailing her. She wants you to build a system that will edit out all known acronyms or else will notify the sender if unknown acronyms are present.
Any combination of three or more letters in upper ca... | ["import re\nfrom functools import reduce\n\n_ACRONYMS = {\n 'KPI': 'key performance indicators',\n 'EOD': 'the end of the day',\n 'EOP': 'the end of the day', # snafu in the tests?\n 'TBD': 'to be decided',\n 'WAH': 'work at home',\n 'IAM': 'in a meeting',\n 'OOO': 'out of office',\n ... | {"fn_name": "acronym_buster", "inputs": [["BRB I need to go into a KPI meeting before EOD"], ["I am IAM so will be OOO until EOD"], ["Going to WAH today. NRN. OOO"], ["We're looking at SMB on SM DMs today"], ["OOO"], ["KPI"], ["EOD"], ["TBD"], ["TBD by EOD"], ["BRB I am OOO"], ["WAH"], ["IAM"], ["NRN"], ["CTA"], ["Hi P... | INTRODUCTORY | PYTHON3 | CODEWARS | 9,152 |
def acronym_buster(message):
|
ca00cf3d1ac593bea2de207dc0dd0749 | UNKNOWN | You wrote all your unit test names in camelCase.
But some of your colleagues have troubles reading these long test names.
So you make a compromise to switch to underscore separation.
To make these changes fast you wrote a class to translate a camelCase name
into an underscore separated name.
Implement the ToUnderscor... | ["import re\n\ndef toUnderScore(name):\n return re.sub(\"(?<=[^_-])_?(?=[A-Z])|(?<=[^\\\\d_])_?(?=\\\\d)\", \"_\" , name)", "from re import sub\n\ndef toUnderScore(name):\n return sub('([a-zA-Z](?=[A-Z0-9])|\\d(?=[A-Z]))', r'\\1_', name)", "def toUnderScore(name):\n if len(name) ==0:\n return \"\"\n ... | {"fn_name": "toUnderScore", "inputs": [["ThisIsAUnitTest"], ["ThisShouldBeSplittedCorrectIntoUnderscore"], ["Calculate1Plus1Equals2"], ["Calculate15Plus5Equals20"], ["Calculate500DividedBy5Equals100"], ["Adding_3To_3ShouldBe_6"], ["This_Is_Already_Splitted_Correct"], ["ThisIs_Not_SplittedCorrect"], ["_IfATestStartAndEn... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,186 |
def toUnderScore(name):
|
8caf2f1a1f001e74d1cd895a13af65a8 | UNKNOWN | You will be given the prime factors of a number as an array.
E.g: ```[2,2,2,3,3,5,5,13]```
You need to find the number, n, to which that prime factorization belongs.
It will be:
```
n = 2³.3².5².13 = 23400
```
Then, generate the divisors of this number.
Your function ```get_num() or getNum()``` will receive an array ... | ["def get_num(arr):\n c,n,r=1,1,{}\n arr.sort()\n for a in arr: n*=a; r[a]= r[a]+1 if a in r else 1\n for a in r: c*=r[a]+1 \n return [n,c-1,arr[0],n//arr[0]]", "from collections import Counter\nfrom functools import reduce\nfrom operator import mul\n\ndef get_num(arr):\n n, small = reduce(mul, arr), ... | {"fn_name": "get_num", "inputs": [[[2, 3, 5, 5]], [[2, 3, 3, 3, 7]], [[3, 3, 3, 11]], [[2, 13, 2, 5, 2, 5, 3, 3]]], "outputs": [[[150, 11, 2, 75]], [[378, 15, 2, 189]], [[297, 7, 3, 99]], [[23400, 71, 2, 11700]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,118 |
def get_num(arr):
|
91dced88dfcaf14edae02625663993e1 | UNKNOWN | I'm sure you're familiar with factorials – that is, the product of an integer and all the integers below it.
For example, `5! = 120`, as `5 * 4 * 3 * 2 * 1 = 120`
Your challenge is to create a function that takes any number and returns the number that it is a factorial of. So, if your function receives `120`, it sho... | ["def reverse_factorial(num):\n c = f = 1\n while f < num:\n c += 1\n f *= c\n return 'None' if f > num else \"%d!\" %c", "def reverse_factorial(num):\n n = 1\n f = 1\n while f < num:\n n += 1\n f = f * n\n return f\"{n}!\" if f == num else \"None\"\n \n \n", "... | {"fn_name": "reverse_factorial", "inputs": [[120], [3628800], [150]], "outputs": [["5!"], ["10!"], ["None"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,782 |
def reverse_factorial(num):
|
5f44e15597384573eb1bbb6dc7feb368 | UNKNOWN | **This Kata is intended as a small challenge for my students**
All Star Code Challenge #23
There is a certain multiplayer game where players are assessed at the end of the game for merit. Players are ranked according to an internal scoring system that players don't see.
You've discovered the formula for the scoring ... | ["def scoring(array):\n res = {}\n \n for e in array:\n score = e[\"norm_kill\"] * 100 + e[\"assist\"] * 50 + e[\"damage\"] // 2 +\\\n e[\"healing\"] + 2 ** e[\"streak\"] + e[\"env_kill\"] * 500\n \n res[e[\"name\"]] = score\n \n return sorted(res, key=res.get, reverse=True)",... | {"fn_name": "scoring", "inputs": [[[]]], "outputs": [[[]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,719 |
def scoring(array):
|
8a8c4905ed1af5ef5ef922c0a62267e7 | UNKNOWN | Given that
```
f0 = '0'
f1 = '01'
f2 = '010' = f1 + f0
f3 = '01001' = f2 + f1
```
You will be given a number and your task is to return the `nth` fibonacci string. For example:
```
solve(2) = '010'
solve(3) = '01001'
```
More examples in test cases. Good luck!
If you like sequence Katas, you will enjoy this Kata: ... | ["def solve(n):\n a,b = '01'\n for _ in range(n): a,b = a+b,a\n return a", "def solve(n):\n return \"0\" if n == 0 else \"01\" if n == 1 else solve(n-1) + solve(n-2)", "def solve(n):\n a, b = \"0\", \"01\"\n for i in range(0, n):\n a = b + a\n a, b = b, a\n return a\n pass", "def s... | {"fn_name": "solve", "inputs": [[0], [1], [2], [3], [5]], "outputs": [["0"], ["01"], ["010"], ["01001"], ["0100101001001"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,259 |
def solve(n):
|
bb854054325abad3cd37b332d9171ef2 | UNKNOWN | # Leaderboard climbers
In this kata you will be given a leaderboard of unique names for example:
```python
['John',
'Brian',
'Jim',
'Dave',
'Fred']
```
Then you will be given a list of strings for example:
```python
['Dave +1', 'Fred +4', 'Brian -1']
```
Then you sort the leaderboard.
The steps for our exampl... | ["def leaderboard_sort(leaderboard, changes):\n for change in changes:\n name, delta = change.split()\n idx = leaderboard.index(name)\n leaderboard.insert(idx - int(delta), leaderboard.pop(idx))\n return leaderboard", "def leaderboard_sort(lbd, changes):\n lbd = lbd[:]\n for name,n in m... | {"fn_name": "leaderboard_sort", "inputs": [[["John", "Brian", "Jim", "Dave", "Fred"], ["Dave +1", "Fred +4", "Brian -1"]], [["Bob", "Larry", "Kevin", "Jack", "Max"], ["Max +3", "Kevin -1", "Kevin +3"]]], "outputs": [[["Fred", "John", "Dave", "Brian", "Jim"]], [["Bob", "Kevin", "Max", "Larry", "Jack"]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 7,082 |
def leaderboard_sort(leaderboard, changes):
|
bbb9f97a4e831e381383f8550e6cfc31 | UNKNOWN | Complete the function that determines the score of a hand in the card game [Blackjack](https://en.wikipedia.org/wiki/Blackjack) (aka 21).
The function receives an array of strings that represent each card in the hand (`"2"`, `"3",` ..., `"10"`, `"J"`, `"Q"`, `"K"` or `"A"`) and should return the score of the hand (int... | ["def score_hand(a):\n n = sum(11 if x == \"A\" else 10 if x in \"JQK\" else int(x) for x in a)\n for _ in range(a.count(\"A\")):\n if n > 21:\n n -= 10\n return n", "def score_hand(cards):\n total = 0\n number_of_aces = 0\n for i in cards:\n if i == \"A\":\n total ... | {"fn_name": "score_hand", "inputs": [[["2", "3"]], [["4", "5", "6"]], [["7", "7", "8"]], [["9", "2", "10"]], [["4", "7", "8"]], [["J", "3"]], [["J", "Q"]], [["K", "J", "Q"]], [["A", "3"]], [["A", "J"]], [["A", "A", "A", "J"]], [["A", "2", "A", "9", "9"]], [["A", "A"]], [["8", "A", "A"]], [["5", "4", "A", "A"]], [["A", ... | INTRODUCTORY | PYTHON3 | CODEWARS | 3,778 |
def score_hand(cards):
|
c54be797d49f5275289ea7df55a3a7da | UNKNOWN | # Task
`N` candles are placed in a row, some of them are initially lit. For each candle from the 1st to the Nth the following algorithm is applied: if the observed candle is lit then states of this candle and all candles before it are changed to the opposite. Which candles will remain lit after applying the algorithm ... | ["def switch_lights(initial_states):\n states = list(initial_states)\n parity = 0\n for i in reversed(range(len(states))):\n parity ^= initial_states[i]\n states[i] ^= parity\n return states", "def switch_lights(a):\n n = sum(a)\n for i, x in enumerate(a):\n if n % 2:\n ... | {"fn_name": "switch_lights", "inputs": [[[1, 1, 1, 1, 1]], [[0, 0]], [[1, 0, 0, 1, 0, 1, 0, 1]], [[1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1]]], "outputs": [[[0, 1, 0, 1, 0]], [[0, 0]], [[1, 1, 1, 0, 0, 1, 1, 0]], [[1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,743 |
def switch_lights(a):
|
9cfa5f8f9cd296bad443aa88a8aff49b | UNKNOWN | # Background
My pet bridge-maker ants are marching across a terrain from left to right.
If they encounter a gap, the first one stops and then next one climbs over him, then the next, and the next, until a bridge is formed across the gap.
What clever little things they are!
Now all the other ants can walk over the ... | ["import re\n\ndef ant_bridge(ants, terrain):\n nGap = sum( 2 + len(gap) - (free == '-') for free,gap in re.findall(r'(-+)(\\.+)', '-'+terrain) ) % len(ants)\n return ants[-nGap:] + ants[:-nGap]", "def ant_bridge(ants, terrain):\n n_ants = len(ants)\n \n terrain = terrain.replace('-.', '..')\n terrain... | {"fn_name": "ant_bridge", "inputs": [["GFEDCBA", "-----------------------"], ["GFEDCBA", "------------...-----------"], ["GFEDCBA", "------------.....---------"], ["GFEDCBA", "------.....------.....---------"], ["GFEDCBA", "------------...-----..----"], ["CBA", "--.--.---"], ["GFEDCBA", "------....-.---"], ["EDCBA", "-... | INTRODUCTORY | PYTHON3 | CODEWARS | 9,197 |
def ant_bridge(ants, terrain):
|
e96b7b85f9d802a4ab0f1515a347b3a5 | UNKNOWN | Consider the sequence `a(1) = 7, a(n) = a(n-1) + gcd(n, a(n-1)) for n >= 2`:
`7, 8, 9, 10, 15, 18, 19, 20, 21, 22, 33, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 69, 72, 73...`.
Let us take the differences between successive elements of the sequence and
get a second sequence `g: 1, 1, 1, 5, 3, 1, 1, 1, 1, 11, 3, 1,... | ["from fractions import gcd\n\ndef seq():\n i, a, g = 1, 7, 1\n while 1:\n yield i, a, g\n i += 1\n g = gcd(i, a)\n a += g\n\ndef count_ones(n):\n return sum(g == 1 for _, (i, a, g) in zip(range(n), seq()))\n\ndef p(n):\n seen = set()\n for i, a, g in seq():\n if not n:... | {"fn_name": "count_ones", "inputs": [[1], [10], [100], [200], [1000], [10000], [100000]], "outputs": [[1], [8], [90], [184], [975], [9968], [99955]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 5,258 |
def count_ones(n):
|
649011d3c319ad621e0b70ed7c747d6f | UNKNOWN | An element in an array is dominant if it is greater than all elements to its right. You will be given an array and your task will be to return a list of all dominant elements. For example:
```Haskell
solve([1,21,4,7,5]) = [21,7,5] because 21, 7 and 5 are greater than elments to their right.
solve([5,4,3,2,1]) = [5,4,3... | ["def solve(arr):\n r = []\n for v in arr[::-1]:\n if not r or r[-1] < v: r.append(v)\n return r[::-1]", "def solve(arr):\n return [a for i,a in enumerate(arr) if all(x < a for x in arr[i+1:])]", "def solve(arr):\n return [a for i,a in enumerate(arr) if a > max(arr[i+1:]+[0])]", "def solve(arr):\n... | {"fn_name": "solve", "inputs": [[[16, 17, 14, 3, 14, 5, 2]], [[92, 52, 93, 31, 89, 87, 77, 105]], [[75, 47, 42, 56, 13, 55]], [[67, 54, 27, 85, 66, 88, 31, 24, 49]], [[76, 17, 25, 36, 29]], [[104, 18, 37, 9, 36, 47, 28]]], "outputs": [[[17, 14, 5, 2]], [[105]], [[75, 56, 55]], [[88, 49]], [[76, 36, 29]], [[104, 47, 28]... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,213 |
def solve(arr):
|
835982749feccdbf16106fab4e082f91 | UNKNOWN | Mr. E Ven only likes even length words.
Please create a translator so that he doesn't have to hear those pesky odd length words.
For some reason he also hates punctuation, he likes his sentences to flow.
Your translator should take in a string and output it with all odd length words having an extra letter (the last le... | ["def evenize_word(w):\n return w + w[-1] if len(w) % 2 else w\n\ndef evenator(s):\n s = \"\".join(c for c in s if c.isspace() or c.isalnum())\n return \" \".join(evenize_word(w) for w in s.split())", "def evenator(s):\n return \" \".join([w+w[-1] if len(w)&1 else w for w in \"\".join([c for c in s if c.isa... | {"fn_name": "evenator", "inputs": [["I got a hole in 1!"], ["tHiS sEnTeNcE iS eVeN."], ["underscore is not considered a word..in this case,"], ["hi. how are you? Bye!!"], ["lorem is so ipsum. why bother?"], ["_under the seA!"]], "outputs": [["II gott aa hole in 11"], ["tHiS sEnTeNcE iS eVeN"], ["underscore is nott cons... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,443 |
def evenator(s):
|
b3c3c08a6d33a425daaab267763a8911 | UNKNOWN | Create a function with two arguments that will return an array of the first (n) multiples of (x).
Assume both the given number and the number of times to count will be positive numbers greater than 0.
Return the results as an array (or list in Python, Haskell or Elixir).
Examples:
```python
count_by(1,10) #should... | ["def count_by(x, n):\n return [i * x for i in range(1, n + 1)]", "def count_by(x, n):\n \"\"\"\n Return a sequence of numbers counting by `x` `n` times.\n \"\"\"\n return [i * x for i in range(1, n+1)]\n", "def count_by(x, n):\n return [x * i for i in range(1, n+1)]", "def count_by(x, n):\n \"\"\"... | {"fn_name": "count_by", "inputs": [[1, 5], [2, 5], [3, 5], [50, 5], [100, 5]], "outputs": [[[1, 2, 3, 4, 5]], [[2, 4, 6, 8, 10]], [[3, 6, 9, 12, 15]], [[50, 100, 150, 200, 250]], [[100, 200, 300, 400, 500]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 14,873 |
def count_by(x, n):
|
c88add7585af883db751c26fdadd2273 | UNKNOWN | In mathematics, a **pandigital number** is a number that in a given base has among its significant digits each digit used in the base at least once. For example, 1234567890 is a pandigital number in base 10.
For simplification, in this kata, we will consider pandigital numbers in *base 10* and with all digits used *ex... | ["def get_sequence(o,s,st=1023456789):\n li = []\n for i in range([st,o][o>0 and o>st],9876543211):\n i = str(i)\n if i[0]!='0' and len(set(i))==10 : li.append(int(i))\n if len(li)==s : break\n return li ", "from itertools import permutations\nfrom bisect import bisect_left\n\nmemo = [int(... | {"fn_name": "get_sequence", "inputs": [[0, 5], [5432160879, 3], [9876543000, 5], [9999999999, 1], [-123456789, 1], [-9999999999, 25]], "outputs": [[[1023456789, 1023456798, 1023456879, 1023456897, 1023456978]], [[5432160879, 5432160897, 5432160978]], [[9876543012, 9876543021, 9876543102, 9876543120, 9876543201]], [[]],... | INTRODUCTORY | PYTHON3 | CODEWARS | 3,258 |
def get_sequence(offset, size):
|
0782d5a1f3a5f97043cd87321fbd1834 | UNKNOWN | Write a function to split a string and convert it into an array of words. For example:
```python
"Robin Singh" ==> ["Robin", "Singh"]
"I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"]
``` | ["def string_to_array(string):\n return string.split(\" \")", "def string_to_array(string=''):\n return string.split() if string else ['']", "def string_to_array(s):\n return s.split(' ')", "def string_to_array(string):\n array = string.split(' ')\n return array", "def string_to_array(string):\n retur... | {"fn_name": "string_to_array", "inputs": [["Robin Singh"], ["CodeWars"], ["I love arrays they are my favorite"], ["1 2 3"], [""]], "outputs": [[["Robin", "Singh"]], [["CodeWars"]], [["I", "love", "arrays", "they", "are", "my", "favorite"]], [["1", "2", "3"]], [[""]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 11,709 |
def string_to_array(s):
|
ab2d43dae7162a0394766c6fa37db162 | UNKNOWN | Bob is preparing to pass IQ test. The most frequent task in this test is `to find out which one of the given numbers differs from the others`. Bob observed that one number usually differs from the others in **evenness**. Help Bob — to check his answers, he needs a program that among the given numbers finds one that is ... | ["def iq_test(numbers):\n e = [int(i) % 2 == 0 for i in numbers.split()]\n\n return e.index(True) + 1 if e.count(True) == 1 else e.index(False) + 1\n", "def iq_test(n):\n n = [int(i)%2 for i in n.split()]\n if n.count(0)>1:\n return n.index(1)+1\n else:\n return n.index(0)+1\n", "def iq_tes... | {"fn_name": "iq_test", "inputs": [["2 4 7 8 10"], ["1 2 2"], ["88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46"], ["100 99 100"], ["5 3 2"], ["43 28 1 91"], ["20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36"], ["79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 ... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,258 |
def iq_test(numbers):
|
8536ea1565272c975cc9e66b0dbecf99 | UNKNOWN | # Task
Mr.Nam has `n` candies, he wants to put one candy in each cell of a table-box. The table-box has `r` rows and `c` columns.
Each candy was labeled by its cell number. The cell numbers are in range from 1 to N and the direction begins from right to left and from bottom to top.
Nam wants to know the position o... | ["def get_candy_position(n, r, c, candy):\n if candy > n: return [-1,-1,-1]\n \n linIdx = r*c - ( (candy-1) % (r*c) + 1 )\n return [(candy-1)//(r*c) + 1, linIdx//c, linIdx%c]", "def get_candy_position(n, r, c, candy):\n if candy > n:\n return [-1, -1, -1]\n label = (candy + r * c - 1) // (r * c... | {"fn_name": "get_candy_position", "inputs": [[6, 2, 2, 3], [6, 2, 2, 5], [6, 2, 2, 7], [8, 4, 2, 3], [15, 3, 3, 1], [15, 3, 3, 5], [15, 3, 3, 7], [15, 3, 3, 14], [15, 3, 3, 18]], "outputs": [[[1, 0, 1]], [[2, 1, 1]], [[-1, -1, -1]], [[1, 2, 1]], [[1, 2, 2]], [[1, 1, 1]], [[1, 0, 2]], [[2, 1, 1]], [[-1, -1, -1]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,692 |
def get_candy_position(n, r, c, candy):
|
06d2f0a88dbf55210c8c181d9b67bcfa | UNKNOWN | I love Fibonacci numbers in general, but I must admit I love some more than others.
I would like for you to write me a function that when given a number (n) returns the n-th number in the Fibonacci Sequence.
For example:
```python
nth_fib(4) == 2
```
Because 2 is the 4th number in the Fibonacci Sequence.
For ... | ["def nth_fib(n):\n a, b = 0, 1\n for i in range(n-1):\n a, b = b, a + b\n return a", "def nth_fib(n):\n a, b = (0, 1)\n for _ in range(n-1):\n a, b = b, a + b\n return a", "def nth_fib(n):\n if n==1:\n return 0\n elif n==2:\n return 1\n else:\n return nth_fib(n-1)+nth_fib(n-2)\n", "from m... | {"fn_name": "nth_fib", "inputs": [[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]], "outputs": [[0], [1], [1], [2], [3], [5], [8], [13], [21], [34], [55], [89], [144], [233], [377], [610], [987], [1597], [2584], [4181], [6765], ... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,449 |
def nth_fib(n):
|
73186ebd54c6ec3512842dc5daffaef8 | UNKNOWN | The magic sum of 3s is calculated on an array by summing up odd numbers which include the digit `3`. Write a function `magic_sum` which accepts an array of integers and returns the sum.
*Example:* `[3, 12, 5, 8, 30, 13]` results in `16` (`3` + `13`)
If the sum cannot be calculated, `0` should be returned. | ["def magic_sum(arr):\n return arr and sum(x for x in arr if x%2 and '3' in str(x)) or 0", "def magic_sum(arr):\n if arr == None: return 0 \n return sum(list(filter(lambda x: x % 2 == 1 and '3' in str(x),arr)))", "def magic_sum(arr):\n def check(x):\n return x % 2 and '3' in str(x)\n return sum(x ... | {"fn_name": "magic_sum", "inputs": [[[3]], [[3, 13]], [[30, 34, 330]], [[3, 12, 5, 8, 30, 13]], [[]], [null]], "outputs": [[3], [16], [0], [16], [0], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,148 |
def magic_sum(arr):
|
8f5420f89152fc00677e212062995f15 | UNKNOWN | #Permutation position
In this kata you will have to permutate through a string of lowercase letters, each permutation will start at ```a``` and you must calculate how many iterations it takes to reach the current permutation.
##examples
```
input: 'a'
result: 1
input: 'c'
result: 3
input: 'z'
result: 26
input: 'fo... | ["from functools import reduce\ndef permutation_position(perm):\n return reduce(lambda t,c:t*26+ord(c)-97,perm,0)+1\n", "trans_table = str.maketrans('abcdefghijklmnopqrstuvwxyz',\n '0123456789abcdefghijklmnop')\n\ndef permutation_position(perm):\n return int(perm.translate(trans_table),... | {"fn_name": "permutation_position", "inputs": [["a"], ["z"], ["aaa"], ["aaab"], ["foo"]], "outputs": [[1], [26], [1], [2], [3759]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,675 |
def permutation_position(perm):
|
5faba06fb904d5fb6e3c7f31a396d1bd | UNKNOWN | # Task
Given a rectangular `matrix` and integers `a` and `b`, consider the union of the ath row and the bth (both 0-based) column of the `matrix`. Return sum of all elements of that union.
# Example
For
```
matrix = [[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 3]]
a = 1 and b = 3 ```
the output shou... | ["def crossing_sum(matrix, row, col):\n return sum(matrix[row]) + sum(line[col] for line in matrix) - matrix[row][col]", "def crossing_sum(a, b, c):\n return sum(a[b]) + sum(x[c] for x in a) - a[b][c]", "def crossing_sum(matrix, row, col):\n return sum(matrix[row]) + sum(i[col] for i in matrix[:row] + matrix[r... | {"fn_name": "crossing_sum", "inputs": [[[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]], 1, 3], [[[1, 1], [3, 3], [1, 1], [2, 2]], 3, 0], [[[100]], 0, 0], [[[1, 2, 3, 4, 5]], 0, 0], [[[1], [2], [3], [4], [5]], 0, 0]], "outputs": [[12], [9], [100], [15], [15]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,206 |
def crossing_sum(matrix, row, col):
|
1cb053c9530e06de398d9534e4472dd5 | UNKNOWN | Given an array of numbers, return the difference between the largest and smallest values.
For example:
`[23, 3, 19, 21, 16]` should return `20` (i.e., `23 - 3`).
`[1, 434, 555, 34, 112]` should return `554` (i.e., `555 - 1`).
The array will contain a minimum of two elements. Input data range guarantees that `max-m... | ["def between_extremes(numbers):\n return max(numbers) - min(numbers)", "def between_extremes(ns):\n return max(ns) - min(ns)", "def between_extremes(a):\n return max(a) - min(a)", "# Naive method: 2 iterations\ndef between_extremes(numbers):\n return max(numbers) - min(numbers)\n\n# Faster method: 1 iterat... | {"fn_name": "between_extremes", "inputs": [[[1, 1]], [[-1, -1]], [[1, -1]], [[21, 34, 54, 43, 26, 12]], [[-1, -41, -77, -100]]], "outputs": [[0], [0], [2], [42], [99]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,211 |
def between_extremes(numbers):
|
0db13efd39c2257ce5cac2c92ad24d38 | UNKNOWN | We have the following recursive function:
The 15-th term; ```f(14)``` is the first term in having more that 100 digits.
In fact,
```
f(14) = 2596253046576879973769082409566059879570061514363339324718953988724415850732046186170181072783243503881471037546575506836249417271830960970629933033088
It has 151 digits.
``... | ["from functools import reduce\ndef product(ar):\n return reduce(lambda x,y:x*y, ar)\n\ndef something_acci(num_digits):\n seq = [1, 1, 2, 2, 3, 3]\n \n while(len(str(seq[-1])) < num_digits):\n seq.append(product(seq[-3:]) - product(seq[-6:-3]))\n \n return (len(seq), len(str(seq[-1])))\n", "def... | {"fn_name": "something_acci", "inputs": [[5], [10], [20], [100]], "outputs": [[[10, 8]], [[11, 14]], [[12, 25]], [[15, 151]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,252 |
def something_acci(num_digits):
|
8bb348cb1df9f5489a203aa96e0f56ab | UNKNOWN | Error Handling is very important in coding and seems to be overlooked or not implemented properly.
#Task
Your task is to implement a function which takes a string as input and return an object containing the properties
vowels and consonants. The vowels property must contain the total count of vowels {a,e,i,o,u}, and ... | ["def get_count(words=\"\"):\n if not isinstance(words, str):\n return {'vowels':0,'consonants':0}\n letter = \"\".join([c.lower() for c in words if c.isalpha()])\n vowel = \"\".join([c for c in letter if c in 'aeiou'])\n consonant = \"\".join([c for c in letter if c not in 'aeiou']) \n return {'v... | {"fn_name": "get_count", "inputs": [["Test"], ["Here is some text"], ["To be a Codewarrior or not to be"], ["To Kata or not to Kata"], ["aeiou"], ["TEst"], ["HEre Is sOme text"], [["To Kata or not to Kata"]], [null], ["Test "], ["Here is some text "], [" "], [{"jjjjj": "jjjjj"}]],... | INTRODUCTORY | PYTHON3 | CODEWARS | 3,183 |
def get_count(words=''):
|
65bcf14b2a926d81323d1648cc440fce | UNKNOWN | The new football league season is coming and the Football Association need some help resetting the league standings. Normally the initial league standing is done in alphabetical order (from A to Z) but this year the FA have decided to freshen it up.
It has been decided that team who finished first last season will be... | ["def premier_league_standings(teams):\n dct = {1: teams[1]}\n dct.update({i:t for i,t in enumerate(sorted(set(teams.values())-{teams[1]}), 2)})\n return dct", "def premier_league_standings(teams):\n order = [teams[1]] + sorted(team for place,team in teams.items() if place!=1)\n return {place:team for pl... | {"fn_name": "premier_league_standings", "inputs": [[{"1": "Arsenal"}], [{"2": "Arsenal", "3": "Accrington Stanley", "1": "Leeds United"}], [{"1": "Leeds United", "2": "Liverpool", "3": "Manchester City", "4": "Coventry", "5": "Arsenal"}]], "outputs": [{"1": "Arsenal"}, {"3": "Arsenal", "2": "Accrington Stanley", "1": "... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,957 |
def premier_league_standings(teams):
|
abc3881f1559d866848a5ab466cfbe38 | UNKNOWN | Your task is to write a function that does just what the title suggests (so, fair warning, be aware that you are not getting out of it just throwing a lame bas sorting method there) with an array/list/vector of integers and the expected number `n` of smallest elements to return.
Also:
* the number of elements to be r... | ["def first_n_smallest(arr, n):\n lst = sorted(enumerate(arr), key=lambda it: it[1])[:n]\n lst.sort(key=lambda it:it[0])\n return [v for _,v in lst]", "def first_n_smallest(arr, n):\n m = sorted(arr)[:n]\n return [m.pop(m.index(i)) for i in arr if i in m]", "from operator import itemgetter\ndef first_n_s... | {"fn_name": "first_n_smallest", "inputs": [[[1, 2, 3, 4, 5], 3], [[5, 4, 3, 2, 1], 3], [[1, 2, 3, 1, 2], 3], [[1, 2, 3, -4, 0], 3], [[1, 2, 3, 4, 5], 0], [[1, 2, 3, 4, 5], 5], [[1, 2, 3, 4, 2], 4], [[2, 1, 2, 3, 4, 2], 2], [[2, 1, 2, 3, 4, 2], 3], [[2, 1, 2, 3, 4, 2], 4]], "outputs": [[[1, 2, 3]], [[3, 2, 1]], [[1, 2, ... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,780 |
def first_n_smallest(arr, n):
|
90a0f82c2055d46b5f843c293c12baf4 | UNKNOWN | This is a follow up from my kata The old switcheroo
Write
```python
def encode(str)
```
that takes in a string ```str``` and replaces all the letters with their respective positions in the English alphabet.
```python
encode('abc') == '123' # a is 1st in English alpabet, b is 2nd and c is 3rd
encode('codewars') == '... | ["def encode(string):\n return ''.join(str(ord(c.upper())-64) if c.isalpha() else c for c in string)", "def encode(string):\n return ''.join(str(ord(c)-96) if c.isalpha() else c for c in string.lower())", "def encode(s):\n return ''.join(str(ord(x) - ord('a') + 1) if x.isalpha() else x for x in s.lower())", "fro... | {"fn_name": "encode", "inputs": [["abc"], ["ABCD"], ["ZzzzZ"], ["abc-#@5"], ["this is a long string!! Please [encode] @C0RrEctly"]], "outputs": [["123"], ["1234"], ["2626262626"], ["123-#@5"], ["208919 919 1 1215147 1920189147!! 161251195 [51431545] @30181853201225"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,460 |
def encode(string):
|
5b0b7224398ac559c949dc83aa764aec | UNKNOWN | Is every value in the array an array?
This should only test the second array dimension of the array. The values of the nested arrays don't have to be arrays.
Examples:
```python
[[1],[2]] => true
['1','2'] => false
[{1:1},{2:2}] => false
``` | ["def arr_check(arr):\n return all(isinstance(el, list) for el in arr)", "def arr_check(arr):\n return all(isinstance(a, list) for a in arr)", "def arr_check(arr):\n return all(type(ele) is list for ele in arr)", "def arr_check(arr):\n return all(type(i) == list for i in arr)", "def arr_check(arr):\n ret... | {"fn_name": "arr_check", "inputs": [[[]], [[["string"]]], [[[], {}]], [[[1], [2], [3]]], [["A", "R", "R", "A", "Y"]]], "outputs": [[true], [true], [false], [true], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 750 |
def arr_check(arr):
|
99fdd21f1de453904be767dfc603b122 | UNKNOWN | Baby is getting his frst tooth. This means more sleepless nights, but with the fun of feeling round his gums and trying to guess which will be first out!
Probably best have a sweepstake with your friends - because you have the best chance of knowing. You can feel the gums and see where the raised bits are - most rais... | ["def first_tooth(lst):\n gums = lst[:1] + lst + lst[-1:]\n diff = [gums[i+1]*2 - gums[i] - gums[i+2] for i in range(len(lst))]\n m = max(diff)\n return diff.index(m) if diff.count(m) == 1 else -1\n", "def first_tooth(array):\n array = [array[0]]+array+[array[-1]]\n diffs = [2*array[i]-array[i-1]-arra... | {"fn_name": "first_tooth", "inputs": [[[1, 2, 3, 4]], [[1, 2, 6, 4]], [[1, 2, 5, 7, 1, 0, 9]], [[9, 2, 8, 1]], [[1, 1, 1, 1]], [[20, 9, 16, 19]], [[15]]], "outputs": [[3], [2], [6], [2], [-1], [0], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,092 |
def first_tooth(array):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.