problem_id int64 2.36k 5k | question stringlengths 52 14k | solutions stringlengths 79 675k | input_output stringlengths 37 505k | difficulty stringclasses 1
value | url stringlengths 36 94 | starter_code stringlengths 0 952 |
|---|---|---|---|---|---|---|
2,862 | ```if:python
Note: Python may currently have some performance issues. If you find them, please let me know and provide suggestions to improve the Python version! It's my weakest language... any help is much appreciated :)
```
Artlessly stolen and adapted from Hackerrank.
Kara Danvers is new to CodeWars, and eager to... | ["def leaderboard_climb(arr, kara):\n scores = sorted(set(arr), reverse=True)\n position = len(scores)\n ranks = []\n \n for checkpoint in kara:\n while position >= 1 and checkpoint >= scores[position - 1]:\n position -= 1\n ranks.append(position + 1) \n \n return ranks"... | {"fn_name": "leaderboard_climb", "inputs": [[[100, 90, 90, 80], [70, 80, 105]], [[982, 490, 339, 180], [180, 250, 721, 2500]], [[1982, 490, 339, 180], [180, 250, 721, 880]], [[1079, 490, 339, 180], [180, 250, 1200, 1980]]], "outputs": [[[4, 3, 1]], [[4, 4, 2, 1]], [[4, 4, 2, 2]], [[4, 4, 1, 1]]]} | introductory | https://www.codewars.com/kata/5b19f34c7664aacf020000ec |
def leaderboard_climb(arr, kara):
|
2,863 | Alan's child can be annoying at times.
When Alan comes home and tells his kid what he has accomplished today, his kid never believes him.
Be that kid.
Your function 'AlanAnnoyingKid' takes as input a sentence spoken by Alan (a string). The sentence contains the following structure:
"Today I " + [action_verb] +... | ["OUTPUT = \"I don't think you {} today, I think you {} {} {}!\".format\n\n\ndef alan_annoying_kid(phrase):\n words = phrase.split()\n action = ' '.join(words[2:]).rstrip('.')\n if \"didn't\" in phrase:\n return OUTPUT(action, 'did', words[3], 'it')\n return OUTPUT(action, \"didn't\", words[2][:-2], ... | {"fn_name": "alan_annoying_kid", "inputs": [["Today I played football."], ["Today I didn't play football."], ["Today I didn't attempt to hardcode this Kata."], ["Today I cleaned the kitchen."], ["Today I learned to code like a pro."]], "outputs": [["I don't think you played football today, I think you didn't play at al... | introductory | https://www.codewars.com/kata/570957fc20a35bd2df0004f9 |
def alan_annoying_kid(s):
|
2,864 | # Task
You have two sorted arrays `a` and `b`, merge them to form new array of unique items.
If an item is present in both arrays, it should be part of the resulting array if and only if it appears in both arrays the same number of times.
# Example
For `a = [1, 3, 40, 40, 50, 60, 60, 60]` and `b = [2, 40, 40, 50... | ["def merge_arrays(a, b):\n out = []\n for n in a+b:\n if n in a and n in b:\n if a.count(n) == b.count(n):\n out.append(n)\n else:\n out.append(n)\n return sorted(set(out))", "from collections import Counter\n\ndef merge_arrays(a, b):\n ca, cb = Counter(a)... | {"fn_name": "merge_arrays", "inputs": [[[10, 10, 10, 15, 20, 20, 25, 25, 30, 7000], [10, 15, 20, 20, 27, 7200]], [[500, 550, 1000, 1000, 1400, 3500], [2, 2, 2, 2, 3, 1500]], [[5], [5, 5, 7]]], "outputs": [[[15, 20, 25, 27, 30, 7000, 7200]], [[2, 3, 500, 550, 1000, 1400, 1500, 3500]], [[7]]]} | introductory | https://www.codewars.com/kata/58b665c891e710a3ec00003f |
def merge_arrays(a, b):
|
2,865 | Complete the solution so that it reverses the string passed into it.
```
'world' => 'dlrow'
``` | ["def solution(str):\n return str[::-1]", "def solution(string):\n return string[::-1]", "def solution(string):\n # Pythonic way :)\n return string[::-1]\n \n # For beginners it's good practise \n # to know how reverse() or [::-1]\n # works on the surface\n #for char in range(len(string)-1,-1,-... | {"fn_name": "solution", "inputs": [["world"], ["hello"], [""], ["h"]], "outputs": [["dlrow"], ["olleh"], [""], ["h"]]} | introductory | https://www.codewars.com/kata/5168bb5dfe9a00b126000018 |
def solution(string):
|
2,866 | # Task
Mobius function - an important function in number theory. For each given n, it only has 3 values:
```
0 -- if n divisible by square of a prime. Such as: 4, 8, 9
1 -- if n not divisible by any square of a prime
and have even number of prime factor. Such as: 6, 10, 21
-1 -- otherwise. Such as: 3, 5, 7,... | ["def mobius(n):\n sP, p = set(), 2\n while n>1 and p <= n**.5:\n while not n%p:\n if p in sP: return 0\n sP.add(p)\n n //= p\n p += 1 + (p!=2)\n return (-1)**((len(sP) + (n!= 1)) % 2)", "def mobius(n):\n s, p, m = 0, 2, n ** .5\n while p <= m:\n if n... | {"fn_name": "mobius", "inputs": [[10], [9], [8], [100000000001], [7], [5]], "outputs": [[1], [0], [0], [0], [-1], [-1]]} | introductory | https://www.codewars.com/kata/58aa5d32c9eb04d90b000107 |
def mobius(n):
|
2,867 | # Task
You are given an array of integers. Your task is to determine the minimum number of its elements that need to be changed so that elements of the array will form an arithmetic progression. Note that if you swap two elements, you're changing both of them, for the purpose of this kata.
Here an arithmetic progres... | ["from collections import defaultdict\n\ndef fix_progression(arr):\n res = 0\n for i in range(len(arr)):\n D = defaultdict(int)\n for j in range(i):\n q, r = divmod(arr[i]-arr[j], i-j)\n if not r:\n D[q] += 1\n res = max(res, D[q])\n return len(... | {"fn_name": "fix_progression", "inputs": [[[1, 2, 3]], [[1, 3, 0, 7, 9]], [[1, 10, 2, 12, 3, 14, 4, 16, 5]], [[7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7]], [[2, -1, -4, 12, 1, -13, -16, -19, -6, -25]], [[-1, 2, 5, 8, 11, 14, 17, -6, 23, 26, -25, 32]], [[-10, -21, -20, -25, -13, 14, 2, 6, -50, -55, -... | introductory | https://www.codewars.com/kata/58a65c82586e98266200005b |
def fix_progression(arr):
|
2,868 | A `Nice array` is defined to be an array where for every value `n` in the array, there is also an element `n-1` or `n+1` in the array.
example:
```
[2,10,9,3] is Nice array because
2=3-1
10=9+1
3=2+1
9=10-1
```
Write a function named `isNice`/`IsNice` that returns `true` if its array argument is a Nice array, else `... | ["def is_nice(arr):\n s = set(arr)\n return bool(arr) and all( n+1 in s or n-1 in s for n in s)", "def is_nice(arr):\n return all(x+1 in arr or x-1 in arr for x in arr) and len(arr)>0", "def is_nice(arr):\n for x in arr:\n if x + 1 not in arr and x - 1 not in arr:\n return False\n retur... | {"fn_name": "is_nice", "inputs": [[[2, 10, 9, 3]], [[3, 4, 5, 7]], [[0, 2, 19, 4, 4]], [[3, 2, 1, 0]], [[3, 2, 10, 4, 1, 6]], [[1, 1, 8, 3, 1, 1]], [[0, 1, 2, 3]], [[1, 2, 3, 4]], [[0, -1, 1]], [[0, 2, 3]], [[0]], [[]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 3, -2, 5, 4]], [[0, -1, -2, -3, -4]], [[1, -1, 3]], [[1, -... | introductory | https://www.codewars.com/kata/59b844528bcb7735560000a0 |
def is_nice(arr):
|
2,869 | Define a function that removes duplicates from an array of numbers and returns it as a result.
The order of the sequence has to stay the same. | ["def distinct(seq):\n return sorted(set(seq), key = seq.index)", "def distinct(seq):\n result = []\n seen = set()\n for a in seq:\n if a not in seen:\n result.append(a)\n seen.add(a)\n return result", "# Using Set:\n# Time complexity | O(N)\ndef distinct(seq):\n result = ... | {"fn_name": "distinct", "inputs": [[[1]], [[1, 2]], [[1, 1, 2]], [[1, 1, 1, 2, 3, 4, 5]], [[1, 2, 2, 3, 3, 4, 4, 5, 6, 7, 7, 7]]], "outputs": [[[1]], [[1, 2]], [[1, 2]], [[1, 2, 3, 4, 5]], [[1, 2, 3, 4, 5, 6, 7]]]} | introductory | https://www.codewars.com/kata/57a5b0dfcf1fa526bb000118 |
def distinct(seq):
|
2,870 | Given two arrays, the purpose of this Kata is to check if these two arrays are the same. "The same" in this Kata means the two arrays contains arrays of 2 numbers which are same and not necessarily sorted the same way. i.e. [[2,5], [3,6]] is same as [[5,2], [3,6]] or [[6,3], [5,2]] or [[6,3], [2,5]] etc
[[2,5], [3,6]]... | ["def same(arr_a, arr_b):\n return sorted(map(sorted, arr_a)) == sorted(map(sorted, arr_b))", "def same(arr_a, arr_b):\n return sorted(sorted(a) for a in arr_a) == sorted(sorted(b) for b in arr_b)\n", "same=lambda a,b:sorted(sum(a,[])) == sorted(sum(b,[]))", "def same(arr_a, arr_b):\n return sorted(sorted(x) for... | {"fn_name": "same", "inputs": [[[[2, 5], [3, 6]], [[5, 2], [3, 6]]], [[[2, 5], [3, 6]], [[6, 3], [5, 2]]], [[[2, 5], [3, 6]], [[6, 3], [2, 5]]], [[[2, 5], [3, 5], [6, 2]], [[2, 6], [5, 3], [2, 5]]], [[[2, 5], [3, 5], [6, 2]], [[3, 5], [6, 2], [5, 2]]], [[], []], [[[2, 3], [3, 4]], [[4, 3], [2, 4]]], [[[2, 3], [3, 2]], ... | introductory | https://www.codewars.com/kata/558c04ecda7fb8f48b000075 |
def same(arr_a, arr_b):
|
2,871 | Challenge:
Given two null-terminated strings in the arguments "string" and "prefix", determine if "string" starts with the "prefix" string. Return 1 (or any other "truthy" value) if true, 0 if false.
Example:
```
startsWith("hello world!", "hello"); // should return 1.
startsWith("hello world!", "HELLO"); // should re... | ["starts_with = str.startswith", "def starts_with(st, prefix): \n return st.startswith(prefix)", "def starts_with(st, prefix): \n return 1 if st[:len(prefix)] == prefix else 0", "def starts_with(st, prefix): \n x = len(prefix)\n if len(prefix) > len(st):\n return False\n if st[:x] == prefix:\n ... | {"fn_name": "starts_with", "inputs": [["hello world!", "hello"], ["hello world!", "HELLO"], ["nowai", "nowaisir"], ["", ""], ["abc", ""], ["", "abc"]], "outputs": [[true], [false], [false], [true], [true], [false]]} | introductory | https://www.codewars.com/kata/5803a6d8db07c59fff00015f |
def starts_with(st, prefix):
|
2,872 | In this kata you will be given an **integer n**, which is the number of times that is thown a coin. You will have to return an array of string for all the possibilities (heads[H] and tails[T]). Examples:
```coin(1) should return {"H", "T"}```
```coin(2) should return {"HH", "HT", "TH", "TT"}```
```coin(3) should return... | ["from itertools import product\n\ndef coin(n):\n return list(map(''.join, product(*([\"HT\"]*n))))", "from itertools import product\n\ndef coin(n):\n return list(map(''.join, product('HT', repeat=n)))", "from itertools import product\n\ndef coin(n):\n return [''.join(xs) for xs in product('HT', repeat=n)]", "... | {"fn_name": "coin", "inputs": [[1], [2], [3]], "outputs": [[["H", "T"]], [["HH", "HT", "TH", "TT"]], [["HHH", "HHT", "HTH", "HTT", "THH", "THT", "TTH", "TTT"]]]} | introductory | https://www.codewars.com/kata/5ad6266b673f2f067b000004 |
def coin(n):
|
2,873 | In this kata you have to correctly return who is the "survivor", ie: the last element of a Josephus permutation.
Basically you have to assume that n people are put into a circle and that they are eliminated in steps of k elements, like this:
```
josephus_survivor(7,3) => means 7 people in a circle;
one every 3 is eli... | ["def josephus_survivor(n, k):\n v = 0\n for i in range(1, n + 1): v = (v + k) % i\n return v + 1", "def josephus_survivor(n,k):\n soldiers = [int(i) for i in range(1, n + 1)]\n counter = -1\n while len(soldiers) != 1:\n counter += k\n while counter >= len(soldiers):\n counter... | {"fn_name": "josephus_survivor", "inputs": [[7, 3], [11, 19], [40, 3], [14, 2], [100, 1], [1, 300], [2, 300], [5, 300], [7, 300], [300, 300]], "outputs": [[4], [10], [28], [13], [100], [1], [1], [1], [7], [265]]} | introductory | https://www.codewars.com/kata/555624b601231dc7a400017a |
def josephus_survivor(n,k):
|
2,874 | JavaScript provides a built-in parseInt method.
It can be used like this:
- `parseInt("10")` returns `10`
- `parseInt("10 apples")` also returns `10`
We would like it to return `"NaN"` (as a string) for the second case because the input string is not a valid number.
You are asked to write a `myParseInt` method with... | ["def my_parse_int(s):\n try:\n return int(s)\n except ValueError:\n return 'NaN'", "def my_parse_int(string):\n try:\n return int(string)\n except ValueError:\n return 'NaN'\n", "def my_parse_int(s):\n return int(s) if s.strip().isdigit() else \"NaN\"\n", "def my_parse_int(st... | {"fn_name": "my_parse_int", "inputs": [["9"], ["09"], ["009"], [" 9"], [" 9 "], ["\t9\n"], ["5 friends"], ["5friends"], ["I <3 u"], ["17.42"], ["0x10"], ["123~~"], ["1 1"], ["1 2 3"], ["1.0"]], "outputs": [[9], [9], [9], [9], [9], [9], ["NaN"], ["NaN"], ["NaN"], ["NaN"], ["NaN"], ["NaN"], ["NaN"], ["NaN"], ["NaN"]]} | introductory | https://www.codewars.com/kata/54fdadc8762e2e51e400032c |
def my_parse_int(string):
|
2,875 | You are standing on top of an amazing Himalayan mountain. The view is absolutely breathtaking! you want to take a picture on your phone, but... your memory is full again! ok, time to sort through your shuffled photos and make some space...
Given a gallery of photos, write a function to sort through your pictures.
You ... | ["def sort_photos(lst):\n lst = [[int(d) for d in f.split(\".img\")] for f in lst]\n s, l = sorted(lst), min(len(lst), 5)\n return [f\"{y}.img{n+(i==l)}\" for i, (y, n) in enumerate(s[-5:]+s[-1:])]\n", "def sort_photos(pics):\n tmp = sorted((pic[:8], int(pic[8:])) for pic in pics)\n return [x+str(y) for ... | {"fn_name": "sort_photos", "inputs": [[["2016.img1", "2016.img2", "2016.img3", "2016.img4", "2016.img5"]], [["2016.img4", "2016.img5", "2016.img1", "2016.img3", "2016.img2"]], [["2012.img2", "2016.img1", "2016.img3", "2016.img4", "2016.img5"]], [["2016.img1", "2013.img3", "2016.img2", "2015.img3", "2012.img7", "2016.im... | introductory | https://www.codewars.com/kata/56c9f47b0844d85f81000fc2 |
def sort_photos(pics):
|
2,876 | *** No Loops Allowed ***
You will be given an array (a) and a value (x). All you need to do is check whether the provided array contains the value, without using a loop.
Array can contain numbers or strings. X can be either. Return true if the array contains the value, false if not. With strings you will need to acco... | ["def check(a, x): \n return x in a", "check=lambda a,x:x in a", "check = list.__contains__", "from operator import contains as check", "def check(a, x): \n return a.count(x) > 0", "check = lambda x,a: a in x", "def check(a, x): \n#My first solution\n\n# if x in a:\n# return True\n# else:\n# ... | {"fn_name": "check", "inputs": [[[66, 101], 66], [[80, 117, 115, 104, 45, 85, 112, 115], 45], [["t", "e", "s", "t"], "e"], [["what", "a", "great", "kata"], "kat"], [[66, "codewars", 11, "alex loves pushups"], "alex loves pushups"], [["come", "on", 110, "2500", 10, "!", 7, 15], "Come"], [["when's", "the", "next", "Katat... | introductory | https://www.codewars.com/kata/57cc40b2f8392dbf2a0003ce |
def check(a, x):
|
2,877 | Given an array of integers `a` and integers `t` and `x`, count how many elements in the array you can make equal to `t` by **increasing** / **decreasing** it by `x` (or doing nothing).
*EASY!*
```python
# ex 1
a = [11, 5, 3]
t = 7
x = 2
count(a, t, x) # => 3
```
- you can make 11 equal to 7 by subtracting 2 twice
- ... | ["def count(a, t, x):\n return sum(not (t-v)%x if x else t==v for v in a)", "def count(a, t, y):\n return sum(not (x-t) % y if y else x == t for x in a)", "count=lambda a,t,x:sum(x and not(e-t)%x or e-t==0for e in a)", "def count(a, t, x):\n return sum((t-i)%x==0 for i in a) if x else sum(i==t for i in a)", "def... | {"fn_name": "count", "inputs": [[[11, 5, 3], 7, 2], [[-4, 6, 8], -7, -3]], "outputs": [[3], [2]]} | introductory | https://www.codewars.com/kata/5d1e1560c193ae0015b601a2 |
def count(a, t, x):
|
2,878 | Given a string `S` and a character `C`, return an array of integers representing the shortest distance from the current character in `S` to `C`.
### Notes
* All letters will be lowercase.
* If the string is empty, return an empty array.
* If the character is not present, return an empty array.
## Examples
```python... | ["def shortest_to_char(s, c):\n if not s or not c:\n return []\n\n indexes = [i for i, ch in enumerate(s) if ch == c]\n if not indexes:\n return []\n \n return [ min(abs(i - ic) for ic in indexes) for i in range(len(s)) ]\n", "def shortest_to_char(s, c):\n L = [i for i,x in enumerate... | {"fn_name": "shortest_to_char", "inputs": [["lovecodewars", "e"], ["aaaaa", "a"], ["aabbaabb", "a"], ["aaaabbbb", "b"], ["aaaaa", "b"], ["lovecoding", ""], ["", ""]], "outputs": [[[3, 2, 1, 0, 1, 2, 1, 0, 1, 2, 3, 4]], [[0, 0, 0, 0, 0]], [[0, 0, 1, 1, 0, 0, 1, 2]], [[4, 3, 2, 1, 0, 0, 0, 0]], [[]], [[]], [[]]]} | introductory | https://www.codewars.com/kata/5c8bf3ec5048ca2c8e954bf3 |
def shortest_to_char(s, c):
|
2,879 | The objective is to disambiguate two given names: the original with another
This kata is slightly more evolved than the previous one: [Author Disambiguation: to the point!](https://www.codewars.com/kata/580a429e1cb4028481000019).
The function ```could_be``` is still given the original name and another one to test
aga... | ["import re\nimport unicodedata\n\nNAME = re.compile(\"[\\w-]+\")\n\ndef decompose(name):\n standarized = unicodedata.normalize('NFKD', name.lower()) \\\n .encode('ascii', 'ignore') if type(name) != str \\\n else name.lower()\n return re.findall(NAME, standarized)\n\ndef could_be(original, another):... | {"fn_name": "could_be", "inputs": [["Carlos Ray Norris", "Carlos Ray Norris"], ["Carlos Ray Norris", "Carlos Ray"], ["Carlos Ray Norris", "Ray Norris"], ["Carlos Ray Norris", "Carlos Norris"], ["Carlos Ray Norris", "Norris"], ["Carlos Ray Norris", "Carlos"], ["Carlos Ray Norris", "Norris Carlos"], ["Carlos Ray Norris",... | introductory | https://www.codewars.com/kata/580a8f039a90a3654b000032 |
def could_be(original, another):
|
2,880 | A number m of the form 10x + y is divisible by 7 if and only if x − 2y is divisible by 7. In other words, subtract twice the last digit
from the number formed by the remaining digits. Continue to do this until a number known to be divisible or not by 7 is obtained;
you can stop when this number has *at most* 2 digits... | ["def seven(m, step = 0):\n if m < 100: return (m, step)\n x, y, step = m // 10, m % 10, step + 1\n res = x - 2 * y\n return seven(res, step)", "def seven(m):\n steps = 0\n while m > 99:\n q, r = divmod(m, 10)\n m = q - (2 * r)\n steps += 1\n return m, steps\n", "seven = lambda m,s=0: ... | {"fn_name": "seven", "inputs": [[1021], [477557101], [477557102], [2340029794923400297949], [1603], [371], [1369851], [483], [483595], [0], [170232833617690725]], "outputs": [[[10, 2]], [[28, 7]], [[47, 7]], [[14, 20]], [[7, 2]], [[35, 1]], [[0, 5]], [[42, 1]], [[28, 4]], [[0, 0]], [[0, 16]]]} | introductory | https://www.codewars.com/kata/55e6f5e58f7817808e00002e |
def seven(m):
|
2,881 | In this Kata, you will implement the [Luhn Algorithm](http://en.wikipedia.org/wiki/Luhn_algorithm), which is used to help validate credit card numbers.
Given a positive integer of up to 16 digits, return ```true``` if it is a valid credit card number, and ```false``` if it is not.
Here is the algorithm:
* Double e... | ["def validate(n):\n digits = [int(x) for x in str(n)]\n even = [x*2 if x*2 <= 9 else x*2 - 9 for x in digits[-2::-2]]\n odd = [x for x in digits[-1::-2]]\n return (sum(even + odd)%10) == 0\n", "import numpy as np\ndef validate(cc_number):\n # split integer into array of digits\n arr = np.array([int(... | {"fn_name": "validate", "inputs": [[123], [1], [2121], [1230], [8675309], [4111111111111111], [26], [2626262626262626], [91], [92], [912030], [922030]], "outputs": [[false], [false], [true], [true], [false], [true], [true], [true], [true], [false], [true], [false]]} | introductory | https://www.codewars.com/kata/5418a1dd6d8216e18a0012b2 |
def validate(n):
|
2,882 | Imagine a triangle of numbers which follows this pattern:
* Starting with the number "1", "1" is positioned at the top of the triangle. As this is the 1st row, it can only support a single number.
* The 2nd row can support the next 2 numbers: "2" and "3"
* Likewise, the 3rd row, can only support the next 3 numbers:... | ["def cumulative_triangle(n):\n return n*(n*n+1)/2", "def cumulative_triangle(n):\n return (n**3+n)/2", "def cumulative_triangle(n):\n return n*(n*n+1)//2", "cumulative_triangle=lambda n:(n**3+n)/2", "def cumulative_triangle(n):\n start = sum(range(n)) + 1\n return sum(range(start, start + n))", "def cum... | {"fn_name": "cumulative_triangle", "inputs": [[1], [2], [3], [4], [15], [150], [100], [500], [1000], [10000]], "outputs": [[1], [5], [15], [34], [1695], [1687575], [500050], [62500250], [500000500], [500000005000]]} | introductory | https://www.codewars.com/kata/5301329926d12b90cc000908 |
def cumulative_triangle(n):
|
2,883 | ##Overview
Write a helper function that takes in a Time object and converts it to a more human-readable format. You need only go up to '_ weeks ago'.
```python
to_pretty(0) => "just now"
to_pretty(40000) => "11 hours ago"
```
##Specifics
- The output will be an amount of time, t, included in one of the following phr... | ["def to_pretty(s):\n if not s: return \"just now\"\n for t, w in (60, \"seconds\"), (60, \"minutes\"), (24, \"hours\"), (7, \"days\"), (53, \"weeks\"):\n s, r = divmod(s, t)\n if not s: return (r > 1 and str(r) + \" \" + w or (\"a \", \"an \")[t == 24] + w[:-1]) + \" ago\"", "def to_pretty(seconds)... | {"fn_name": "to_pretty", "inputs": [[0], [1], [30], [90], [180], [4000], [40000], [140000], [400000], [1000000], [10000000]], "outputs": [["just now"], ["a second ago"], ["30 seconds ago"], ["a minute ago"], ["3 minutes ago"], ["an hour ago"], ["11 hours ago"], ["a day ago"], ["4 days ago"], ["a week ago"], ["16 weeks ... | introductory | https://www.codewars.com/kata/53988ee02c2414dbad000baa |
def to_pretty(seconds):
|
2,884 | # Convert a linked list to a string
## Related Kata
Although this Kata is not part of an official Series, you may also want to try out [Parse a linked list from a string](https://www.codewars.com/kata/582c5382f000e535100001a7) if you enjoyed this Kata.
## Preloaded
Preloaded for you is a class, struct or derived da... | ["def stringify(list):\n return 'None' if list == None else str(list.data) + ' -> ' + stringify(list.next)", "def stringify(ll):\n r = []\n while ll:\n r, ll = r + [str(ll.data)], ll.next\n return ' -> '.join(r + ['None'])", "def stringify(head):\n if head is None:\n return \"None\"\n re... | {"fn_name": "stringify", "inputs": [[null]], "outputs": [["None"]]} | introductory | https://www.codewars.com/kata/582c297e56373f0426000098 |
def stringify(node):
|
2,885 | Ho ho! So you think you know integers, do you? Well then, young wizard, tell us what the Nth digit of the [Champernowne constant](https://en.wikipedia.org/wiki/Champernowne_constant) is!
The constant proceeds like this: `0.12345678910111213141516...`
I hope you see the pattern!
Conjure a function that will accept an... | ["def champernowne_digit(n):\n if not type(n) is int or n < 1:\n return float(\"NaN\")\n i, l = 1, 11\n while l <= n:\n i, l = i + 1, l + 9 * (i + 1) * 10**i\n return ((n - l) // (i * 10**(i - 1 - (n - l) % i))) % 10\n\nchampernowneDigit = champernowne_digit\n", "DIGIT_CNTS = [1] + [(10**i - 1... | {"fn_name": "champernowneDigit", "inputs": [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [20], [35], [36], [37], [100], [101], [102], [103], [104], [105], [190], [2890], [38890], [488890], [5888890], [3678608], [3678609], [3678610], [3678611], [3678612], [3678613], [3678614], [3897249], [3897189], [38... | introductory | https://www.codewars.com/kata/5ac53c71376b11df7e0001a9 |
def champernowneDigit(n):
|
2,886 | # Description:
Find the longest successive exclamation marks and question marks combination in the string. A successive exclamation marks and question marks combination must contains two part: a substring of "!" and a substring "?", they are adjacent.
If more than one result are found, return the one which at lef... | ["import re\n\ndef find(stg):\n matches = re.findall(r\"(!+|\\?+)\", stg)\n return max((f\"{a}{b}\" for a, b in zip(matches, matches[1:])), key=len, default=\"\")", "from itertools import groupby\n\ndef find(s):\n L = [k*len(list(v)) for k,v in groupby(s)]\n return max((x + y for x,y in zip(L, L[1:])), key=... | {"fn_name": "find", "inputs": [["!!"], ["!??"], ["!?!!"], ["!!???!????"], ["!!???!?????"], ["!????!!!?"], ["!?!!??!!!?"]], "outputs": [[""], ["!??"], ["?!!"], ["!!???"], ["!?????"], ["????!!!"], ["??!!!"]]} | introductory | https://www.codewars.com/kata/57fb3c839610ce39f7000023 |
def find(s):
|
2,887 | Everyone Knows AdFly and their Sister Sites.
If we see the Page Source of an ad.fly site we can see this perticular line:
Believe it or not This is actually the Encoded url which you would skip to.
The Algorithm is as Follows:
```
1) The ysmm value is broken like this
ysmm = 0 1 2 3 4 5 6 7 8 9 = "0123456789"
cod... | ["import base64\nimport binascii\nimport math\nfrom itertools import zip_longest\n\n\ndef adFly_decoder(sc):\n code1 = \"\"\n code2 = \"\"\n flip = False\n for c in sc:\n if flip:\n code2 += c\n else:\n code1 += c\n flip = not flip\n\n try:\n url = base64... | {"fn_name": "adFly_decoder", "inputs": [["O=T0ZToPdRHJRmwdcOz1oGvTL22lFzkRZhih5GsbezSw9kndbvyR50wYawHIAF/SdhT1"], ["N=z0dDoMdyHIRmwac1zMolvWLz2RFmkMZiiZ5HsZeySw9kndbvyR50wYawHIAF/SdhT1"], ["lololol"]], "outputs": [["http://yahoo.com"], ["http://google.com"], ["Invalid"]]} | introductory | https://www.codewars.com/kata/56896d1d6ba4e91b8c00000d |
def adFly_decoder(sc):
|
2,888 | ## Description:
Remove all exclamation marks from the end of words. Words are separated by spaces in the sentence.
### Examples
```
remove("Hi!") === "Hi"
remove("Hi!!!") === "Hi"
remove("!Hi") === "!Hi"
remove("!Hi!") === "!Hi"
remove("Hi! Hi!") === "Hi Hi"
remove("!!!Hi !!hi!!! !hi") === "!!!Hi !!hi !hi"
``` | ["def remove(s):\n return ' '.join(w.rstrip('!') or w for w in s.split())", "from re import sub\ndef remove(s):\n return sub('(\\w+)!+(\\s+|$)','\\\\1\\\\2', s)\n", "def remove(s):\n return \" \".join(x.rstrip(\"!\") for x in s.split())", "import re\n\ndef remove(s):\n return re.sub(r'\\b!+(?= |$)', '', s)"... | {"fn_name": "remove", "inputs": [["Hi!"], ["Hi!!!"], ["!Hi"], ["!Hi!"], ["Hi! Hi!"]], "outputs": [["Hi"], ["Hi"], ["!Hi"], ["!Hi"], ["Hi Hi"]]} | introductory | https://www.codewars.com/kata/57faf32df815ebd49e000117 |
def remove(s):
|
2,889 | Bob has ladder. He wants to climb this ladder, but being a precocious child, he wonders about exactly how many ways he could to climb this `n` size ladder using jumps of up to distance `k`.
Consider this example...
n = 5\
k = 3
Here, Bob has ladder of length 5, and with each jump, he can ascend up to 3 steps (he can... | ["from collections import deque\n\ndef count_ways(n, k):\n s,d = 1,deque([0]*k)\n for i in range(n):\n d.append(s)\n s = 2*s-d.popleft()\n return s-d.pop()", "from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef count_ways(n, k):\n if n < 0:\n return 0\n elif n <= 1:\n ... | {"fn_name": "count_ways", "inputs": [[1, 3], [3, 3], [2, 3], [5, 3], [4, 3], [10, 6], [14, 7]], "outputs": [[1], [4], [2], [13], [7], [492], [7936]]} | introductory | https://www.codewars.com/kata/5eea52f43ed68e00016701f3 |
def count_ways(n, k):
|
2,890 | Implement a function, `multiples(m, n)`, which returns an array of the first `m` multiples of the real number `n`. Assume that `m` is a positive integer.
Ex.
```
multiples(3, 5.0)
```
should return
```
[5.0, 10.0, 15.0]
``` | ["def multiples(m, n):\n return [i * n for i in range(1, m+1)]", "def multiples(m, n):\n return [k * n for k in range(1, m+1)]", "multiples=lambda m,n:[n*e for e in range(1,m+1)]", "def multiples(m, n):\n array_multiples = []\n for i in range(1,m+1):\n array_multiples.append(float(i*n))\n return a... | {"fn_name": "multiples", "inputs": [[3, 5], [1, 3.14], [5, -1]], "outputs": [[[5, 10, 15]], [[3.14]], [[-1, -2, -3, -4, -5]]]} | introductory | https://www.codewars.com/kata/593c9175933500f33400003e |
def multiples(m, n):
|
2,891 | # Introduction
Digital Cypher assigns a unique number to each letter of the alphabet:
```
a b c d e f g h i j k l m n o p q r s t u v w x y z
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
```
In the encrypted word we write the corresponding numbers instead o... | ["def find_the_key(message, code):\n diffs = \"\".join( str(c - ord(m) + 96) for c, m in zip(code, message) )\n for size in range(1, len(code) +1):\n key = diffs[:size]\n if (key * len(code))[:len(code)] == diffs:\n return int(key)", "def find_the_key(message, code):\n key = \"\".join(... | {"fn_name": "find_the_key", "inputs": [["scout", [20, 12, 18, 30, 21]], ["masterpiece", [14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8]], ["nomoretears", [15, 17, 14, 17, 19, 7, 21, 7, 2, 20, 20]], ["notencrypted", [14, 15, 20, 5, 14, 3, 18, 25, 16, 20, 5, 4]], ["tenthousand", [21, 5, 14, 20, 8, 16, 21, 19, 1, 14, 5]], ["one... | introductory | https://www.codewars.com/kata/5930d8a4b8c2d9e11500002a |
def find_the_key(message, code):
|
2,892 | We’ve all seen katas that ask for conversion from snake-case to camel-case, from camel-case to snake-case, or from camel-case to kebab-case — the possibilities are endless.
But if we don’t know the case our inputs are in, these are not very helpful.
### Task:
So the task here is to implement a function (called `id` ... | ["import re\n\nCASES = [\n ('snake', re.compile(r'\\A[a-z]+(_[a-z]+)+\\Z')),\n ('kebab', re.compile(r'\\A[a-z]+(-[a-z]+)+\\Z')),\n ('camel', re.compile(r'\\A[a-z]+([A-Z][a-z]*)+\\Z')),\n ('none', re.compile(r'')),\n]\n\ndef case_id(c_str):\n for case, pattern in CASES:\n if pattern.match(c_str): r... | {"fn_name": "case_id", "inputs": [["hello-world"], ["hello-to-the-world"], ["hello_world"], ["hello_to_the_world"], ["helloWorld"], ["helloToTheWorld"], ["hello-World"], ["hello-To-The-World"], ["good-Night"], ["he--llo"], ["good-night"], ["good_night"], ["goodNight"], ["hello_World"], ["hello_To_The_World"], ["he_lloW... | introductory | https://www.codewars.com/kata/5819a6fdc929bae4f5000a33 |
def case_id(c_str):
|
2,893 | # Task
Lonerz got some crazy growing plants and he wants to grow them nice and well.
Initially, the garden is completely barren.
Each morning, Lonerz can put any number of plants into the garden to grow.
And at night, each plant mutates into two plants.
Lonerz really hopes to see `n` plants in his garde... | ["def plant_doubling(n):\n return bin(n).count(\"1\")", "def plant_doubling(n):\n p = 0\n while n:\n if n % 2 == 1:\n n -= 1\n p += 1\n n //= 2\n return p", "def plant_doubling(n):\n return bin(n)[2:].count(\"1\")", "import math\ndef plant_doubling(n):\n times = 0\n... | {"fn_name": "plant_doubling", "inputs": [[5], [8], [536870911], [1]], "outputs": [[2], [1], [29], [1]]} | introductory | https://www.codewars.com/kata/58bf97cde4a5edfd4f00008d |
def plant_doubling(n):
|
2,894 | # Triple Trouble
Create a function that will return a string that combines all of the letters of the three inputed strings in groups. Taking the first letter of all of the inputs and grouping them next to each other. Do this for every letter, see example below!
**E.g. Input: "aa", "bb" , "cc" => Output: "abcabc"** ... | ["def triple_trouble(one, two, three):\n return ''.join(''.join(a) for a in zip(one, two, three))\n", "def triple_trouble(one, two, three):\n return \"\".join(a+b+c for a,b,c in zip(one,two,three))", "def triple_trouble(*args):\n return \"\".join(\"\".join(a) for a in zip(*args))", "def triple_trouble(one,... | {"fn_name": "triple_trouble", "inputs": [["aaa", "bbb", "ccc"], ["aaaaaa", "bbbbbb", "cccccc"], ["burn", "reds", "roll"], ["Bm", "aa", "tn"], ["LLh", "euo", "xtr"]], "outputs": [["abcabcabc"], ["abcabcabcabcabcabc"], ["brrueordlnsl"], ["Batman"], ["LexLuthor"]]} | introductory | https://www.codewars.com/kata/5704aea738428f4d30000914 |
def triple_trouble(one, two, three):
|
2,895 | # Introduction
Ka ka ka cypher is a cypher used by small children in some country. When a girl wants to pass something to the other girls and there are some boys nearby, she can use Ka cypher. So only the other girls are able to understand her.
She speaks using KA, ie.:
`ka thi ka s ka bo ka y ka i ka s ka u ka gly... | ["import re\n\nKA_PATTERN = re.compile(r'(?![aeiou]+$)([aeiou]+)', re.I)\n\ndef ka_co_ka_de_ka_me(word):\n return 'ka' + KA_PATTERN.sub(r'\\1ka', word)", "from functools import partial\nfrom re import compile\n\nka_co_ka_de_ka_me = partial(compile(r\"(?i)^|(?<=[aeiou])(?![aeiou]|$)\").sub, \"ka\")", "def ka_co_ka_de... | {"fn_name": "ka_co_ka_de_ka_me", "inputs": [["ka"], ["a"], ["aa"], ["z"], ["Abbaa"], ["maintenance"], ["Woodie"], ["Incomprehensibilities"]], "outputs": [["kaka"], ["kaa"], ["kaaa"], ["kaz"], ["kaAkabbaa"], ["kamaikantekanakance"], ["kaWookadie"], ["kaIkancokamprekahekansikabikalikatiekas"]]} | introductory | https://www.codewars.com/kata/5934d648d95386bc8200010b |
def ka_co_ka_de_ka_me(word):
|
2,896 | A carpet shop sells carpets in different varieties. Each carpet can come in a different roll width and can have a different price per square meter.
Write a function `cost_of_carpet` which calculates the cost (rounded to 2 decimal places) of carpeting a room, following these constraints:
* The carpeting has to be don... | ["def cost_of_carpet(room_length, room_width, roll_width, roll_cost):\n x, y = sorted((room_length, room_width))\n if y == 0 or x > roll_width: return \"error\"\n if y < roll_width: return round(x * roll_width * roll_cost, 2)\n return round(y * roll_width * roll_cost, 2)", "def cost_of_carpet(room_length, r... | {"fn_name": "cost_of_carpet", "inputs": [[3, 5, 4, 10], [4, 5, 4, 10], [0, 0, 4, 10], [3, 2, 4, 10], [3.9, 2, 4, 10], [5, 6, 4, 10], [3, 2, 4, 0], [3, 2, 2, 10]], "outputs": [[200], [200], ["error"], [80], [80], ["error"], [0], [60]]} | introductory | https://www.codewars.com/kata/592c6d71d2c6d91643000009 |
def cost_of_carpet(room_length, room_width, roll_width, roll_cost):
|
2,897 | Given an integer `n` return `"odd"` if the number of its divisors is odd. Otherwise return `"even"`.
**Note**: big inputs will be tested.
## Examples:
All prime numbers have exactly two divisors (hence `"even"`).
For `n = 12` the divisors are `[1, 2, 3, 4, 6, 12]` – `"even"`.
For `n = 4` the divisors are `[1, 2, 4... | ["def oddity(n):\n #your code here\n return 'odd' if n**0.5 == int(n**0.5) else 'even'", "oddity=lambda n: [\"odd\",\"even\"][n**.5%1!=0]", "import math\ndef oddity(n):\n return math.sqrt(n) % 1 == 0 and 'odd' or 'even'", "import math\ndef oddity(n):\n \n return \"even\" if math.sqrt(n)%1 else \"odd\"\n"... | {"fn_name": "oddity", "inputs": [[1], [5], [16], [27], [121]], "outputs": [["odd"], ["even"], ["odd"], ["even"], ["odd"]]} | introductory | https://www.codewars.com/kata/55830eec3e6b6c44ff000040 |
def oddity(n):
|
2,898 | You are given two arrays `arr1` and `arr2`, where `arr2` always contains integers.
Write the function `find_array(arr1, arr2)` such that:
For `arr1 = ['a', 'a', 'a', 'a', 'a']`, `arr2 = [2, 4]`
`find_array returns ['a', 'a']`
For `arr1 = [0, 1, 5, 2, 1, 8, 9, 1, 5]`, `arr2 = [1, 4, 7]`
`find_array returns [1, 1, 1]`... | ["def find_array(arr1, arr2):\n return [ arr1[i] for i in arr2 if i< len(arr1) ]", "def find_array(arr1, arr2):\n return [arr1[i] for i in arr2 if i <= len(arr1)]", "def find_array(arr1, arr2):\n arr = []\n try:\n for i in arr2:\n if len(arr1) == 0 or len(arr2) == 0:\n retur... | {"fn_name": "find_array", "inputs": [[["a", "a", "a", "a", "a"], [2, 4]], [[0, 1, 5, 2, 1, 8, 9, 1, 5], [1, 4, 7]], [[1, 2, 3, 4, 5], [0]], [["this", "is", "test"], [0, 1, 2]], [[0, 3, 4], [2, 6]], [[1], []], [[], [2]], [[], []]], "outputs": [[["a", "a"]], [[1, 1, 1]], [[1]], [["this", "is", "test"]], [[4]], [[]], [[]]... | introductory | https://www.codewars.com/kata/59a2a3ba5eb5d4e609000055 |
def find_array(arr1, arr2):
|
2,899 | # Task
You are given a binary string (a string consisting of only '1' and '0'). The only operation that can be performed on it is a Flip operation.
It flips any binary character ( '0' to '1' and vice versa) and all characters to the `right` of it.
For example, applying the Flip operation to the 4th character of ... | ["def bin_str(s):\n return s.count(\"10\") * 2 + (s[-1] == \"1\")", "def bin_str(input):\n flips_needed = 0\n last_seen = '0'\n for c in input:\n if last_seen != c:\n flips_needed += 1\n last_seen = c\n return flips_needed", "import re\n\ndef bin_str(s):\n return len(re.fi... | {"fn_name": "bin_str", "inputs": [["0101"], ["10000"], ["0000000000"], ["1111111111"], ["10101010101010"], ["11111000011111"], ["000001111100000"], ["111000000000"], ["00000000111111111"], ["1010101011111111111111000000000"]], "outputs": [[3], [2], [0], [1], [14], [3], [2], [2], [1], [10]]} | introductory | https://www.codewars.com/kata/58c218efd8d3cad11c0000ef |
def bin_str(s):
|
2,900 | Given a string, return a new string that has transformed based on the input:
* Change case of every character, ie. lower case to upper case, upper case to lower case.
* Reverse the order of words from the input.
**Note:** You will have to handle multiple spaces, and leading/trailing spaces.
For example:
```
"Exampl... | ["def string_transformer(s):\n return ' '.join(s.swapcase().split(' ')[::-1])", "def string_transformer(s):\n return ' ' .join(s.split(' ')[::-1]).swapcase()", "def string_transformer(s):\n #1st step: split the string (done)\n x = []\n s = s.split(\" \")\n for i in range(1, 2 * len(s) - 1, 2):\n ... | {"fn_name": "string_transformer", "inputs": [["Example string"], ["Example Input"], ["To be OR not to be That is the Question"], [""], ["You Know When THAT Hotline Bling"], [" A b C d E f G "]], "outputs": [["STRING eXAMPLE"], ["iNPUT eXAMPLE"], ["qUESTION THE IS tHAT BE TO NOT or BE tO"], [""], ["bLING hOTLINE that... | introductory | https://www.codewars.com/kata/5878520d52628a092f0002d0 |
def string_transformer(s):
|
2,901 | Following from the previous kata and taking into account how cool psionic powers are compare to the Vance spell system (really, the idea of slots to dumb down the game sucks, not to mention that D&D became a smash hit among geeks, so...), your task in this kata is to create a function that returns how many power points... | ["psion_power_points=lambda l,s: [0,2,6,11,17,25,35,46,58,72,88,106,126,147,170,195,221,250,280,311,343][min(l,20)]+(s-10)//2*l//2 if l and s>10 else 0", "powers = [0,2,6,11,17,25,35,46,58,72,88,106,126,147,170,195,221,250,280,311,343]\ndef psion_power_points(level, score):\n score = max(score - 10, 0)\n return l... | {"fn_name": "psion_power_points", "inputs": [[1, 0], [1, 10], [1, 11], [0, 11], [1, 20], [21, 30]], "outputs": [[0], [0], [2], [0], [4], [448]]} | introductory | https://www.codewars.com/kata/596b1d44224071b9f5000010 |
def psion_power_points(level,score):
|
2,902 | Very simple, given a number, find its opposite.
Examples:
```
1: -1
14: -14
-34: 34
```
~~~if:sql
You will be given a table: `opposite`, with a column: `number`. Return a table with a column: `res`.
~~~ | ["def opposite(number):\n return -number", "def opposite(number):\n return number * -1", "def opposite(number):\n return number * (-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1-1+1... | {"fn_name": "opposite", "inputs": [[1], [25.6], [0], [1425.2222], [-3.1458], [-95858588225]], "outputs": [[-1], [-25.6], [0], [-1425.2222], [3.1458], [95858588225]]} | introductory | https://www.codewars.com/kata/56dec885c54a926dcd001095 |
def opposite(number):
|
2,903 | Find the volume of a cone whose radius and height are provided as parameters to the function `volume`. Use the value of PI provided by your language (for example: `Math.PI` in JS, `math.pi` in Python or `Math::PI` in Ruby) and round down the volume to an Interger.
If you complete this kata and there are no issues, ple... | ["from math import pi\n\ndef volume(r,h):\n return pi * r**2 * h // 3", "from math import pi\n\n\ndef volume(r, h):\n return int(pi * r ** 2 * h / 3)", "from math import pi,floor\n\ndef volume(r,h):\n return floor(h/3 * pi * r ** 2)", "from math import pi\ndef volume(r,h):\n return (pi*h*r**2)//3", "import ... | {"fn_name": "volume", "inputs": [[7, 3], [56, 30], [0, 10], [10, 0], [0, 0]], "outputs": [[153], [98520], [0], [0], [0]]} | introductory | https://www.codewars.com/kata/57b2e428d24156b312000114 |
def volume(r,h):
|
2,904 | Write a function taking in a string like `WOW this is REALLY amazing` and returning `Wow this is really amazing`. String should be capitalized and properly spaced. Using `re` and `string` is not allowed.
Examples:
```python
filter_words('HELLO CAN YOU HEAR ME') #=> Hello can you hear me
filter_words('now THI... | ["def filter_words(st):\n return ' '.join(st.capitalize().split())", "def filter_words(st):\n return \" \".join(st.split()).capitalize()\n", "def filter_words(st):\n st1 = st.lower()\n st2 = st1.capitalize()\n st3 = \" \".join(st2.split())\n return st3", "def filter_words(s):\n return ' '.join(s.spli... | {"fn_name": "filter_words", "inputs": [["HELLO world!"], ["This will not pass "], ["NOW THIS is a VERY EXCITING test!"]], "outputs": [["Hello world!"], ["This will not pass"], ["Now this is a very exciting test!"]]} | introductory | https://www.codewars.com/kata/587a75dbcaf9670c32000292 |
def filter_words(st):
|
2,905 | Nickname Generator
Write a function, `nicknameGenerator` that takes a string name as an argument and returns the first 3 or 4 letters as a nickname.
If the 3rd letter is a consonant, return the first 3 letters.
If the 3rd letter is a vowel, return the first 4 letters.
If the string is less than 4 characters, retur... | ["def nickname_generator(name):\n return \"Error: Name too short\" if len(name) < 4 else name[:3+(name[2] in \"aeiuo\")]", "def nickname_generator(name):\n return name[:3+(name[2] in 'aeiou')] if len(name) > 3 else 'Error: Name too short'", "def nickname_generator(name):\n return \"Error: Name too short\" if l... | {"fn_name": "nickname_generator", "inputs": [["Jimmy"], ["Samantha"], ["Sam"], ["Kayne"], ["Melissa"], ["James"], ["Gregory"], ["Jeannie"], ["Kimberly"], ["Timothy"], ["Dani"], ["Saamy"], ["Saemy"], ["Saimy"], ["Saomy"], ["Saumy"], ["Boyna"], ["Kiyna"], ["Sayma"], ["Ni"], ["Jam"], ["Suv"]], "outputs": [["Jim"], ["Sam"]... | introductory | https://www.codewars.com/kata/593b1909e68ff627c9000186 |
def nickname_generator(name):
|
2,906 | At the start of each season, every player in a football team is assigned their own unique squad number. Due to superstition or their history certain numbers are more desirable than others.
Write a function generateNumber() that takes two arguments, an array of the current squad numbers (squad) and the new player's des... | ["def generate_number(squad, n):\n if n not in squad: return n\n for i in range(1, 10):\n for j in range(1, 10):\n if i + j == n and i * 10 + j not in squad:\n return i * 10 + j", "def generate_number(lst, n):\n lst = set(lst)\n return (n if n not in lst else\n ne... | {"fn_name": "generate_number", "inputs": [[[1, 2, 3, 4, 6, 9, 10, 15, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 29, 69], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 29, 38, 47, 56, 65, 69, 74, 83, 92], 11], [[1, 2, 3, 4, 6, 9, 10, 11, 15, 18, 23, 69], 18], [[1, 2, 3, 4, 6, 9, 10, 15, ... | introductory | https://www.codewars.com/kata/5d62961d18198b000e2f22b3 |
def generate_number(squad, n):
|
2,907 | This kata is an extension of "Combinations in a Set Using Boxes":https://www.codewars.com/kata/5b5f7f7607a266914200007c
The goal for this kata is to get all the possible combinations (or distributions) (with no empty boxes) of a certain number of balls, but now, **with different amount of boxes.** In the previous kata... | ["MAX_BALL = 2+1800\nDP,lst = [None], [0,1]\nfor _ in range(MAX_BALL):\n DP.append([sum(lst), *max( (v,i) for i,v in enumerate(lst) )])\n lst.append(0)\n lst = [ v*i + lst[i-1] for i,v in enumerate(lst) ]\n \ncombs_non_empty_boxesII = DP.__getitem__\n", "# this is [A000110, A002870, A024417]\n\n# Stirling n... | {"fn_name": "combs_non_empty_boxesII", "inputs": [[4], [3], [2], [20]], "outputs": [[[15, 7, 2]], [[5, 3, 2]], [[2, 1, 2]], [[51724158235372, 15170932662679, 8]]]} | introductory | https://www.codewars.com/kata/5b61e9306d0db7d097000632 |
def combs_non_empty_boxesII(n):
|
2,908 | ###Story
Sometimes we are faced with problems when we have a big nested dictionary with which it's hard to work. Now, we need to solve this problem by writing a function that will flatten a given dictionary.
###Info
Python dictionaries are a convenient data type to store and process configurations. They allow you to s... | ["def flatten(dictionary):\n stack = [((), dictionary)]\n result = {}\n while stack:\n path, current = stack.pop()\n for k, v in current.items():\n if v == {}:\n result[\"/\".join((path + (k,)))] = \"\";\n if isinstance(v, dict):\n stack.append(... | {"fn_name": "flatten", "inputs": [[{"key": "value"}], [{"key": {"deeper": {"more": {"enough": "value"}}}}], [{"empty": {}}], [{"additional": {"place": {"cell": "2", "zone": "1"}}, "job": "scout", "name": {"last": "Drone", "first": "One"}, "recent": {}}], [{"job": {"1": "scout", "2": "worker", "3": "writer", "4": "reade... | introductory | https://www.codewars.com/kata/572cc218aedd20cc83000679 |
def flatten(dictionary):
|
2,909 | Theory
This section does not need to be read and can be skipped, but it does provide some clarity into the inspiration behind the problem.
In music theory, a major scale consists of seven notes, or scale degrees, in order (with tonic listed twice for demonstrative purposes):
Tonic, the base of the scale and the note ... | ["def is_tune(notes):\n return bool(notes) and any(\n all((n + i) % 12 in {0, 2, 4, 5, 7, 9, 11} for n in notes)\n for i in range(12)\n )", "def is_tune(notes):\n if not notes: return False \n for j in range(12):\n if set((i + j) % 12 for i in notes).issubset({0, 2, 4, 5, 7, 9, 11}):\n ... | {"fn_name": "is_tune", "inputs": [[[1, 3, 6, 8, 10, 12]], [[1, 3, 6, 8, 10, 12, 13, 15]], [[1, 6, 3]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]], [[1, 3, 5, 6, 8, 10, 12]], [[3, 5, 6, 8, 10, 12]], [[]], [[1]], [[-11, -9, -7, -6, -4, -2, 0, 1, 3, 6, 8, 10, 12, 13, 15]], [[-4, -2, 0, 1, 3, 6, 8, 10, 12, 13, 15]]], "outpu... | introductory | https://www.codewars.com/kata/5b8dc84b8ce20454bd00002e |
def is_tune(notes):
|
2,910 | *** No Loops Allowed ***
You will be given an array (a) and a limit value (limit). You must check that all values in the array are below or equal to the limit value. If they are, return true. Else, return false.
You can assume all values in the array are numbers.
Do not use loops. Do not modify input array.
Looking... | ["def small_enough(a, limit): \n return max(a) <= limit", "def small_enough(a, limit): \n if max(a) <= limit:\n return True\n else:\n return False", "def small_enough(a, limit): \n if a[0] > limit:\n return False\n \n if len(a) > 1:\n return small_enough(a[1:], limit)\n... | {"fn_name": "small_enough", "inputs": [[[66, 101], 200], [[78, 117, 110, 99, 104, 117, 107, 115], 100], [[101, 45, 75, 105, 99, 107], 107], [[80, 117, 115, 104, 45, 85, 112, 115], 120]], "outputs": [[true], [false], [true], [true]]} | introductory | https://www.codewars.com/kata/57cc4853fa9fc57a6a0002c2 |
def small_enough(a, limit):
|
2,911 | Write a function `count_vowels` to count the number of vowels in a given string.
### Notes:
- Return `nil` or `None` for non-string inputs.
- Return `0` if the parameter is omitted.
### Examples:
```python
count_vowels("abcdefg") => 2
count_vowels("aAbcdeEfg") => 4
count_vowels(12) => None
``` | ["def count_vowels(s = ''):\n return sum(x.lower() in 'aeoui' for x in s) if type(s) == str else None", "import re\n\ndef count_vowels(s = ''):\n if isinstance(s, str):\n return sum(1 for _ in re.finditer(r'[aeiou]',s, flags=re.I))", "def count_vowels(s = ''):\n if type(s) != str: \n return None\... | {"fn_name": "count_vowels", "inputs": [["abcdefg"], ["asdfdsafdsafds"], [""], ["asdfdsaf asdfsdaf 13243242 dsafdsafds"], ["aeiouAEIOU"], ["1213"], ["12 3"], ["ewqriwetruituofdsajflsd23423r5043"], ["asdfviosdfopsiewrwwer asdf asdfdsaf)(asdflkajdsf "], ["asdfdsaf asdfsasdfdsafgjlsdjf asdfdsf daf 13243242... | introductory | https://www.codewars.com/kata/55b105503da095817e0000b6 |
def count_vowels(s = ''):
|
2,912 | In this simple exercise, you will build a program that takes a value, `integer `, and returns a list of its multiples up to another value, `limit `. If `limit` is a multiple of ```integer```, it should be included as well. There will only ever be positive integers passed into the function, not consisting of 0. The limi... | ["def find_multiples(integer, limit):\n return list(range(integer, limit+1, integer))", "def find_multiples(integer, limit):\n arr = []\n count = integer\n while count <= limit:\n arr.append(count)\n count += integer\n return arr", "find_multiples = lambda a, b: list(range(a, b + 1, a))", "... | {"fn_name": "find_multiples", "inputs": [[5, 25], [1, 2], [5, 7], [4, 27], [11, 54]], "outputs": [[[5, 10, 15, 20, 25]], [[1, 2]], [[5]], [[4, 8, 12, 16, 20, 24]], [[11, 22, 33, 44]]]} | introductory | https://www.codewars.com/kata/58ca658cc0d6401f2700045f |
def find_multiples(integer, limit):
|
2,913 | This will probably be a little series :)
X-Shape
You will get an odd Integer n (>= 3) and your task is to draw a X. Each line is separated with '\n'.
Use the following characters: ■ □
For Ruby, Crystal and PHP: whitespace and o
e.g.:
■□□□■
■□■ ... | ["def x(n):\n ret = [['\u25a1' for _ in range(n)] for _ in range(n)]\n for i in range(len(ret)):\n ret[i][i] = '\u25a0';\n ret[i][-1 - i] = '\u25a0';\n return '\\n'.join(''.join(row) for row in ret)", "f, e = \"\u25a0\u25a1\"\n\n\ndef x(n):\n l = n // 2\n middle = [f\"{e * l}{f}{e * l}\"]\n... | {"fn_name": "x", "inputs": [[3], [7]], "outputs": [["\u25a0\u25a1\u25a0\n\u25a1\u25a0\u25a1\n\u25a0\u25a1\u25a0"], ["\u25a0\u25a1\u25a1\u25a1\u25a1\u25a1\u25a0\n\u25a1\u25a0\u25a1\u25a1\u25a1\u25a0\u25a1\n\u25a1\u25a1\u25a0\u25a1\u25a0\u25a1\u25a1\n\u25a1\u25a1\u25a1\u25a0\u25a1\u25a1\u25a1\n\u25a1\u25a1\u25a0\u25a1\u2... | introductory | https://www.codewars.com/kata/5906436806d25f846400009b |
def x(n):
|
2,914 | Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.
It should remove all values from list `a`, which are present in list `b`.
```python
array_diff([1,2],[1]) == [2]
```
If a value is present in `b`, all of its occurrences must be removed from th... | ["def array_diff(a, b):\n return [x for x in a if x not in b]", "def array_diff(a, b):\n return [x for x in a if x not in set(b)]", "def array_diff(a, b):\n set_b = set(b)\n return [i for i in a if i not in set_b]", "def array_diff(a, b):\n #your code here\n for i in range(len(b)):\n while b[i]... | {"fn_name": "array_diff", "inputs": [[[1, 2], [1]], [[1, 2, 2], [1]], [[1, 2, 2], [2]], [[1, 2, 2], []], [[], [1, 2]]], "outputs": [[[2]], [[2, 2]], [[1]], [[1, 2, 2]], [[]]]} | introductory | https://www.codewars.com/kata/523f5d21c841566fde000009 |
def array_diff(a, b):
|
2,915 | # The Problem
Dan, president of a Large company could use your help. He wants to implement a system that will switch all his devices into offline mode depending on his meeting schedule. When he's at a meeting and somebody texts him, he wants to send an automatic message informing that he's currently unavailable and th... | ["def check_availability(schedule, current_time):\n for tb, te in schedule:\n if tb <= current_time < te:\n return te\n return True", "def check_availability(schedule, current_time):\n for time in schedule:\n if time[0] <= current_time < time[1]:\n return time[1]\n return... | {"fn_name": "check_availability", "inputs": [[[["09:30", "10:15"], ["12:20", "15:50"]], "10:00"], [[["09:30", "10:15"], ["12:20", "15:50"]], "11:00"], [[["09:30", "10:15"], ["12:20", "15:50"]], "10:15"], [[], "10:15"], [[["12:13", "23:50"]], "10:15"], [[["12:13", "23:50"]], "23:55"], [[["12:13", "23:50"]], "17:43"]], "... | introductory | https://www.codewars.com/kata/5603002927a683441f0000cb |
def check_availability(schedule, current_time):
|
2,916 | The purpose of this series is developing understanding of stastical problems in AS and A level maths. Let's get started with a simple concept in statistics: Mutually exclusive events.
The probability of an OR event is calculated by the following rule:
`P(A || B) = P(A) + P(B) - P(A && B)`
The probability of event A ... | ["def mutually_exclusive(dice, call1, call2):\n dice = dict(dice)\n if abs(sum(dice.values()) - 1) < 1e-12:\n return '%0.2f' % (dice[call1] + dice[call2])", "def mutually_exclusive(dice, call1, call2):\n if sum(prob for _, prob in dice) != 1:\n return None\n x = dict(dice)\n return format(x... | {"fn_name": "mutually_exclusive", "inputs": [[[[3, 0.4], [4, 0.1], [1, 0.01], [2, 0.09], [5, 0.2], [6, 0.1]], 1, 6], [[[1, 0.1], [2, 0.14], [3, 0.16], [4, 0.2], [5, 0.15], [6, 0.25]], 1, 4], [[[1, 0.6], [2, 0.1001], [3, 0.0999], [4, 0.1], [5, 0.05], [6, 0.05]], 3, 4], [[[6, 0.25], [1, 0.1], [3, 0.16], [2, 0.14], [5, 0.... | introductory | https://www.codewars.com/kata/575eac1f484486d4600000b2 |
def mutually_exclusive(dice, call1, call2):
|
2,917 | # Task
The year of `2013` is the first year after the old `1987` with only distinct digits.
Now your task is to solve the following problem: given a `year` number, find the minimum year number which is strictly larger than the given one and has only distinct digits.
# Input/Output
- `[input]` integer `year`
`1... | ["def distinct_digit_year(year):\n year += 1\n while len(set(str(year))) != 4:\n year += 1\n return year\n #coding and coding..\n", "def distinct_digit_year(year):\n year += 1\n \n if len(set(str(year))) == len(str(year)):\n return year \n \n return distinct_digit_year(year)",... | {"fn_name": "distinct_digit_year", "inputs": [[1987], [2013]], "outputs": [[2013], [2014]]} | introductory | https://www.codewars.com/kata/58aa68605aab54a26c0001a6 |
def distinct_digit_year(year):
|
2,918 | Let us begin with an example:
A man has a rather old car being worth $2000.
He saw a secondhand car being worth $8000. He wants to keep his old car until he can buy the secondhand one.
He thinks he can save $1000 each month but the prices of his old
car and of the new one decrease of 1.5 percent per month.
Furtherm... | ["def nbMonths(oldCarPrice, newCarPrice, saving, loss):\n months = 0\n budget = oldCarPrice\n \n while budget < newCarPrice:\n months += 1\n if months % 2 == 0:\n loss += 0.5\n \n oldCarPrice *= (100 - loss) / 100\n newCarPrice *= (100 - loss) / 100\n bud... | {"fn_name": "nbMonths", "inputs": [[2000, 8000, 1000, 1.5], [8000, 12000, 500, 1], [18000, 32000, 1500, 1.25], [7500, 32000, 300, 1.55]], "outputs": [[[6, 766]], [[8, 597]], [[8, 332]], [[25, 122]]]} | introductory | https://www.codewars.com/kata/554a44516729e4d80b000012 |
def nbMonths(startPriceOld, startPriceNew, savingperMonth, percentLossByMonth):
|
2,919 | # Introduction
Digital Cypher assigns to each letter of the alphabet unique number. For example:
```
a b c d e f g h i j k l m
1 2 3 4 5 6 7 8 9 10 11 12 13
n o p q r s t u v w x y z
14 15 16 17 18 19 20 21 22 23 24 25 26
```
Instead of letters in encrypted word we write the corre... | ["from itertools import cycle\n\ndef encode(message, key):\n return [ord(a) - 96 + int(b) for a,b in zip(message,cycle(str(key)))]", "def encode(message, key):\n # initialize variables\n output = []\n i = 0\n \n # convert key to a list of integers\n key = [int(d) for d in str(key)]\n \n # enc... | {"fn_name": "encode", "inputs": [["scout", 1939], ["masterpiece", 1939]], "outputs": [[[20, 12, 18, 30, 21]], [[14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8]]]} | introductory | https://www.codewars.com/kata/592e830e043b99888600002d |
def encode(message, key):
|
2,920 | ##Task:
You have to write a function **pattern** which creates the following pattern upto n number of rows. *If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string.*
##Pattern:
(n)
(n)(n-1)
(n)(n-1)(n-2)
................
.................
(n)(n-1)(n-2)....4
... | ["def pattern(n):\n return '\\n'.join(''.join(str(i) for i in range(n, j, -1)) for j in range(n - 1, -1, -1))", "def pattern(n):\n return \"\\n\".join(\"\".join(str(j) for j in range(n, n-i, -1)) for i in range(1, n+1))", "def pattern(n):\n full = [str(x) for x in range(n, 0, -1)]\n take = lambda x: ''.join... | {"fn_name": "pattern", "inputs": [[1], [2], [5], [0], [-25]], "outputs": [["1"], ["2\n21"], ["5\n54\n543\n5432\n54321"], [""], [""]]} | introductory | https://www.codewars.com/kata/557341907fbf439911000022 |
def pattern(n):
|
2,921 | Just another day in the world of Minecraft, Steve is working on his new project -- building a beacon pyramid in front of his house.

Steve has already obtained the beacon (the glass wrapped blue thingy on the top), he just needs to ... | ["def blocks_to_collect(level):\n answer = {\n 'total': sum([(i+3+i)**2 for i in range(level)]),\n 'gold': sum([(i+3+i)**2 for i in range(0,level,4)]),\n 'diamond': sum([(i+3+i)**2 for i in range(1,level,4)]),\n 'emerald': sum([(i+3+i)**2 for i in range(2,level,4)]),\n 'iron': sum([(i+3+i)**2 for i in... | {"fn_name": "blocks_to_collect", "inputs": [[1], [2], [3]], "outputs": [[{"total": 9, "gold": 9, "diamond": 0, "emerald": 0, "iron": 0}], [{"total": 34, "gold": 9, "diamond": 25, "emerald": 0, "iron": 0}], [{"total": 83, "gold": 9, "diamond": 25, "emerald": 49, "iron": 0}]]} | introductory | https://www.codewars.com/kata/5839cd780426f5d0ec00009a |
def blocks_to_collect(level):
|
2,922 | You have stumbled across the divine pleasure that is owning a dog and a garden. Now time to pick up all the cr@p! :D
Given a 2D array to represent your garden, you must find and collect all of the dog cr@p - represented by '@'.
You will also be given the number of bags you have access to (bags), and the capactity of ... | ["def crap(garden, bags, cap):\n cap *= bags\n for turf in garden:\n if 'D' in turf: return 'Dog!!'\n cap -= turf.count('@')\n return 'Cr@p' if cap < 0 else 'Clean'", "from collections import Counter\nfrom itertools import chain\n\ndef crap(garden, bags, cap):\n c = Counter(chain(*garden))\n ... | {"fn_name": "crap", "inputs": [[[["_", "_", "_", "_"], ["_", "_", "_", "@"], ["_", "_", "@", "_"]], 2, 2], [[["_", "_", "_", "_"], ["_", "_", "_", "@"], ["_", "_", "@", "_"]], 1, 1], [[["_", "_"], ["_", "@"], ["D", "_"]], 2, 2], [[["_", "_", "_", "_"], ["_", "_", "_", "_"], ["_", "_", "_", "_"]], 2, 2], [[["@", "@"], [... | introductory | https://www.codewars.com/kata/57faa6ff9610ce181b000028 |
def crap(garden, bags, cap):
|
2,923 | Your dad doesn't really *get* punctuation, and he's always putting extra commas in when he posts. You can tolerate the run-on sentences, as he does actually talk like that, but those extra commas have to go!
Write a function called ```dadFilter``` that takes a string as argument and returns a string with the extraneou... | ["from re import compile, sub\n\nREGEX = compile(r',+')\n\n\ndef dad_filter(strng):\n return sub(REGEX, ',', strng).rstrip(' ,')\n", "import re\ndef dad_filter(string):\n return re.sub(r',+',r',',string).rstrip(', ')", "import re\ndef dad_filter(string):\n return re.sub(r'((?<=\\,)\\,+|[\\s,]+\\Z)','',string)"... | {"fn_name": "dad_filter", "inputs": [["all this,,,, used to be trees,,,,,,"], ["Listen,,,, kid,,,,,,"], ["Luke,,,,,,,,, I am your father,,,,,,,,, "], ["i,, don't believe this round earth,,, show me evadence!!"], ["Dead or alive,,,, you're coming with me,,, "]], "outputs": [["all this, used to be trees"], ["Listen, k... | introductory | https://www.codewars.com/kata/56a24b309f3671608b00003a |
def dad_filter(string):
|
2,924 | Write a program to determine if two numbers are coprime. A pair of numbers are coprime if their greatest shared factor is 1. For example:
```
20 and 27
Factors of 20: 1, 2, 4, 5, 10, 20
Factors of 27: 1, 3, 9, 27
Greatest shared factor: 1
20 and 27 are coprime```
An example of two numbers that are not coprime:
```
12 a... | ["from fractions import gcd\n\ndef are_coprime(n, m):\n return gcd(n, m) == 1", "def are_coprime(n, m):\n # All hail Euclid and his wonderful algorithm\n while m > 0:\n n, m = m, n % m\n return n == 1", "from math import gcd\n\ndef are_coprime(n , m):\n return gcd(n, m) == 1", "from fractions import... | {"fn_name": "are_coprime", "inputs": [[20, 27], [12, 39], [17, 34], [34, 17], [35, 10], [64, 27]], "outputs": [[true], [false], [false], [false], [false], [true]]} | introductory | https://www.codewars.com/kata/585c50e75d0930e6a7000336 |
def are_coprime(n, m):
|
2,925 | Jack really likes his number five: the trick here is that you have to multiply each number by 5 raised to the number of digits of each numbers, so, for example:
```python
multiply(3)==15
multiply(10)==250
multiply(200)==25000
multiply(0)==0
multiply(-3)==-15
``` | ["def multiply(n):\n return n*5**len(str(abs(n))) ", "def multiply(n):\n return 5 ** len(str(abs(n))) * n", "multiply=lambda n: n*5**len(str(abs(n)))", "def multiply(n):\n return n * 5 ** number_of_digits(n)\n\n\ndef number_of_digits(n: int):\n return 1 if -10 < n < 10 else 1 + number_of_digits(n // 10)", "de... | {"fn_name": "multiply", "inputs": [[10], [5], [200], [0], [-2]], "outputs": [[250], [25], [25000], [0], [-10]]} | introductory | https://www.codewars.com/kata/5708f682c69b48047b000e07 |
def multiply(n):
|
2,926 | ## Task
Given an array of strings, reverse them and their order in such way that their length stays the same as the length of the original inputs.
### Example:
```
Input: {"I", "like", "big", "butts", "and", "I", "cannot", "lie!"}
Output: {"!", "eilt", "onn", "acIdn", "ast", "t", "ubgibe", "kilI"}
```
Good luck! | ["def reverse(a):\n s=reversed(''.join(a))\n return [''.join(next(s) for _ in w) for w in a]", "def reverse(a):\n s = ''.join(a)[::-1]\n l, x = [], 0\n for i in a:\n l.append(s[x:x+len(i)])\n x += len(i)\n return l", "def reverse(a):\n s=list(''.join(a))\n return [''.join(s.pop() f... | {"fn_name": "reverse", "inputs": [[["I", "like", "big", "butts", "and", "I", "cannot", "lie!"]], [["?kn", "ipnr", "utotst", "ra", "tsn", "iksr", "uo", "yer", "ofebta", "eote", "vahu", "oyodpm", "ir", "hsyn", "amwoH"]]], "outputs": [[["!", "eilt", "onn", "acIdn", "ast", "t", "ubgibe", "kilI"]], [["How", "many", "shrimp"... | introductory | https://www.codewars.com/kata/5c3433a4d828182e420f4197 |
def reverse(a):
|
2,927 | I'm afraid you're in a rather unfortunate situation. You've injured your leg, and are unable to walk, and a number of zombies are shuffling towards you, intent on eating your brains. Luckily, you're a crack shot, and have your trusty rifle to hand.
The zombies start at `range` metres, and move at 0.5 metres per second... | ["def zombie_shootout(zombies, distance, ammo, shot=0):\n \n if not zombies:\n return f'You shot all {shot} zombies.'\n \n if distance <= 0:\n return f'You shot {shot} zombies before being eaten: overwhelmed.'\n \n if not ammo:\n return f'You shot {shot} zombies before being eaten... | {"fn_name": "zombie_shootout", "inputs": [[3, 10, 10], [100, 8, 200], [50, 10, 8], [10, 10, 10], [17, 8, 200], [9, 10, 8], [20, 10, 20], [100, 49, 200], [50, 10, 19], [50, 10, 49], [100, 10, 20], [19, 10, 20], [20, 10, 100], [20, 10, 19], [19, 15, 19], [19, 3, 19]], "outputs": [["You shot all 3 zombies."], ["You shot 1... | introductory | https://www.codewars.com/kata/5deeb1cc0d5bc9000f70aa74 |
def zombie_shootout(zombies, distance, ammo):
|
2,928 | # Introduction
There is a war and nobody knows - the alphabet war!
There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began.
# Task
Write a function that accepts `fight` string consists of only small letters and return who wins the fight. ... | ["def alphabet_war(fight):\n d = {'w':4,'p':3,'b':2,'s':1,\n 'm':-4,'q':-3,'d':-2,'z':-1}\n r = sum(d[c] for c in fight if c in d)\n \n return {r==0:\"Let's fight again!\",\n r>0:\"Left side wins!\",\n r<0:\"Right side wins!\"\n }[True]", "def alphabet_war(fight):\n ... | {"fn_name": "alphabet_war", "inputs": [["z"], ["zdqmwpbs"], ["wq"], ["zzzzs"], ["wwwwww"]], "outputs": [["Right side wins!"], ["Let's fight again!"], ["Left side wins!"], ["Right side wins!"], ["Left side wins!"]]} | introductory | https://www.codewars.com/kata/59377c53e66267c8f6000027 |
def alphabet_war(fight):
|
2,929 | #### Task:
Your job here is to implement a function `factors`, which takes a number `n`, and outputs an array of arrays comprised of two
parts, `sq` and `cb`. The part `sq` will contain all the numbers that, when squared, yield a number which is a factor of `n`,
while the `cb` part will contain all the numbers that, w... | ["def factors(n):\n sq = [a for a in range(2, n+1) if not n % (a**2)]\n cb = [b for b in range(2, n+1) if not n % (b**3)]\n return [sq, cb]", "def factors(n):\n sq = [i for i in range(2, int(n**0.5) + 2) if n%(i*i)==0]\n cb = [i for i in range(2, int(n**(1/3) + 2)) if n%(i*i*i)==0]\n return [sq, cb]",... | {"fn_name": "factors", "inputs": [[1], [4], [16], [81], [80], [100], [5], [120], [18], [8]], "outputs": [[[[], []]], [[[2], []]], [[[2, 4], [2]]], [[[3, 9], [3]]], [[[2, 4], [2]]], [[[2, 5, 10], []]], [[[], []]], [[[2], [2]]], [[[3], []]], [[[2], [2]]]]} | introductory | https://www.codewars.com/kata/582b0d73c190130d550000c6 |
def factors(n):
|
2,930 | # Summation
Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0.
For example:
```if-not:racket
~~~
summation(2) -> 3
1 + 2
summation(8) -> 36
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8
~~~
```
```if:racket
~~~racket
(summation 2) ; 3 (+ 1 2)
(summat... | ["def summation(num):\n return sum(range(num + 1))\n \n", "def summation(num):\n return (1+num) * num / 2", "def summation(num):\n return sum(range(1,num+1))\n \n", "def summation(num):\n return sum(range(num + 1))\n \n", "def summation(num):\n total = 0\n for i in range(0, num+1):\n t... | {"fn_name": "summation", "inputs": [[1], [8], [22], [100], [213]], "outputs": [[1], [36], [253], [5050], [22791]]} | introductory | https://www.codewars.com/kata/55d24f55d7dd296eb9000030 |
def summation(num):
|
2,931 | Consider having a cow that gives a child every year from her fourth year of life on and all her subsequent children do the same.
After n years how many cows will you have?
Return null if n is not an integer.
Note: Assume all the cows are alive after n years. | ["def count_cows(n):\n if not isinstance(n, int):\n return None\n return 1 if n < 3 else count_cows(n-1) + count_cows(n-3)", "def count_cows(n):\n if isinstance(n, int):\n a, b, c = 1, 0, 0\n for _ in range(n):\n a, b, c = c, a, b + c\n return a + b + c", "def count_cows(... | {"fn_name": "count_cows", "inputs": [[1], [3], [5]], "outputs": [[1], [2], [4]]} | introductory | https://www.codewars.com/kata/58311536e77f7d08de000085 |
def count_cows(n):
|
2,932 | Colour plays an important role in our lifes. Most of us like this colour better then another. User experience specialists believe that certain colours have certain psychological meanings for us.
You are given a 2D array, composed of a colour and its 'common' association in each array element. The function you will wri... | ["def colour_association(arr):\n return [{k: v} for k, v in arr]", "def colour_association(arr):\n return [{color: assoc} for color, assoc in arr]", "def colour_association(arr):\n result = []\n for association in arr:\n colour, value = association\n result.append({colour : value})\n return... | {"fn_name": "colour_association", "inputs": [[[["white", "goodness"], ["blue", "tranquility"]]], [[["red", "energy"], ["yellow", "creativity"], ["brown", "friendly"], ["green", "growth"]]], [[["pink", "compassion"], ["purple", "ambition"]]], [[["gray", "intelligence"], ["black", "classy"]]], [[["white", "goodness"], ["... | introductory | https://www.codewars.com/kata/56d6b7e43e8186c228000637 |
def colour_association(arr):
|
2,933 | This is a problem that involves adding numbers to items in a list.
In a list you will have to add the item's remainder when divided by a given divisor to each item.
For example if the item is 40 and the divisor is 3 you would have to add 1 since 40 minus the closest multiple of 3 which is 39 is 1. So the 40 in the lis... | ["def solve(nums,div):\n return [x + x % div for x in nums]\n\n", "def solve(nums,div): return [n+n%div for n in nums]", "solve = lambda n, d: [k + k%d for k in n]\n", "def solve(numbers, divisor):\n return [num + (num % divisor) for num in numbers]\n", "solve = lambda n, d: [i + i % d for i in n]", "def solve(nu... | {"fn_name": "solve", "inputs": [[[2, 7, 5, 9, 100, 34, 32, 0], 3], [[], 2], [[1000, 999, 998, 997], 5], [[0, 0, 0, 0], 5], [[4, 3, 2, 1], 5], [[33, 23, 45, 78, 65], 10]], "outputs": [[[4, 8, 7, 9, 101, 35, 34, 0]], [[]], [[1000, 1003, 1001, 999]], [[0, 0, 0, 0]], [[8, 6, 4, 2]], [[36, 26, 50, 86, 70]]]} | introductory | https://www.codewars.com/kata/5acc3634c6fde760ec0001f7 |
def solve(nums,div):
|
2,934 | Given a lowercase string that has alphabetic characters only and no spaces, return the highest value of consonant substrings. Consonants are any letters of the alphabet except `"aeiou"`.
We shall assign the following values: `a = 1, b = 2, c = 3, .... z = 26`.
For example, for the word "zodiacs", let's cross out the... | ["import re\n\ndef solve(s):\n return max(sum(ord(c)-96 for c in subs) for subs in re.split('[aeiou]+', s))", "def solve(s):\n max_ord = 0\n curr_ord = 0\n for char in s:\n if char not in 'aeiou':\n curr_ord += ord(char)-ord('a')+1\n else:\n if curr_ord > max_ord:\n ... | {"fn_name": "solve", "inputs": [["zodiac"], ["chruschtschov"], ["khrushchev"], ["strength"], ["catchphrase"], ["twelfthstreet"], ["mischtschenkoana"]], "outputs": [[26], [80], [38], [57], [73], [103], [80]]} | introductory | https://www.codewars.com/kata/59c633e7dcc4053512000073 |
def solve(s):
|
2,935 | Implement the function which should return `true` if given object is a vowel (meaning `a, e, i, o, u`), and `false` otherwise. | ["def is_vowel(s):\n return s.lower() in set(\"aeiou\")", "import re\ndef is_vowel(s): \n regex = r'^[aeiou]{1}$'\n return bool(re.match(regex, re.escape(s), re.IGNORECASE))", "import re\n\ndef is_vowel(stg): \n return bool(re.fullmatch(r\"[aeiou]\", stg, re.I))", "def is_vowel(s): \n return True if s.lo... | {"fn_name": "is_vowel", "inputs": [[""], ["a"], ["E"], ["ou"], ["z"], ["lol"]], "outputs": [[false], [true], [true], [false], [false], [false]]} | introductory | https://www.codewars.com/kata/567bed99ee3451292c000025 |
def is_vowel(s):
|
2,936 | A high school has a strange principal. On the first day, he has his students perform an odd opening day ceremony:
There are number of lockers "n" and number of students "n" in the school. The principal asks the first student to go to every locker and open it. Then he has the second student go to every second locker an... | ["# First, I coded a straightforward solution. It would work, but because it had to loop over all\n# students, and for every student over each locker, it had to do n^2 iterations. With numbers under\n# 10k this proved no problem, however the test cases apparently tested bigger numbers, since my\n# program kept getting ... | {"fn_name": "num_of_open_lockers", "inputs": [[0], [1], [4], [56], [128], [500], [562], [74864], [3991700], [950811894]], "outputs": [[0], [1], [2], [7], [11], [22], [23], [273], [1997], [30835]]} | introductory | https://www.codewars.com/kata/55fc061cc4f485a39900001f |
def num_of_open_lockers(n):
|
2,937 | Complete the function that takes two integers (`a, b`, where `a < b`) and return an array of all integers between the input parameters, **including** them.
For example:
```
a = 1
b = 4
--> [1, 2, 3, 4]
``` | ["def between(a,b):\n return list(range(a,b+1))", "def between(a,b):\n # good luck\n return list((x for x in range(a, b + 1)))\n # thanks\n", "def between(a,b):\n return [result for result in range(a,b+1)]\n", "between=lambda a,b:list(range(a,b+1))", "def between(a,b):\n arr = []\n for i in range(a... | {"fn_name": "between", "inputs": [[1, 4], [-2, 2], [-10, 10], [5, 100]], "outputs": [[[1, 2, 3, 4]], [[-2, -1, 0, 1, 2]], [[-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35... | introductory | https://www.codewars.com/kata/55ecd718f46fba02e5000029 |
def between(a,b):
|
2,938 | ###Task:
You have to write a function **pattern** which creates the following Pattern(See Examples) upto n(parameter) number of rows.
####Rules/Note:
* If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string.
* All the lines in the pattern have same length i.e equal to the number of char... | ["def pattern(n):\n output = []\n for i in range (1, n + 1):\n wing = ' ' * (n - i) + ''.join(str(d % 10) for d in range(1, i))\n output.append(wing + str(i % 10) + wing[::-1])\n return '\\n'.join(output)", "def pattern(n):\n result = []\n for i in range(1, n+1):\n string = \"\"\n ... | {"fn_name": "pattern", "inputs": [[7], [1], [4], [0], [-25]], "outputs": [[" 1 \n 121 \n 12321 \n 1234321 \n 123454321 \n 12345654321 \n1234567654321"], ["1"], [" 1 \n 121 \n 12321 \n1234321"], [""], [""]]} | introductory | https://www.codewars.com/kata/5575ff8c4d9c98bc96000042 |
def pattern(n):
|
2,939 | Create a function
```python
has_two_cube_sums(n)
```
which checks if a given number `n` can be written as the sum of two cubes in two different ways: `n = a³+b³ = c³+d³`.
All the numbers `a`, `b`, `c` and `d` should be different and greater than `0`.
E.g. 1729 = 9³+10³ = 1³+12³.
```python
has_two_cube_sums(1729); /... | ["def has_two_cube_sums(n):\n cubic_list = [i**3 for i in range(1, int((n)**(1./3.)) + 1)]\n return sum([(n != 2*c) and ((n-c) in cubic_list) for c in cubic_list]) > 3\n", "def has_two_cube_sums(n):\n x = 0\n for a in range(int(n**0.35)):\n for b in range(a,int(n**0.35)):\n if a**3+b**3 ==... | {"fn_name": "has_two_cube_sums", "inputs": [[1], [1729], [42], [4103], [4102], [4104], [4105], [4106], [0], [46163]], "outputs": [[false], [true], [false], [false], [false], [true], [false], [false], [false], [false]]} | introductory | https://www.codewars.com/kata/55fd4919ce2a1d7c0d0000f3 |
def has_two_cube_sums(n):
|
2,940 | In this Kata, you will be given an array of numbers in which two numbers occur once and the rest occur only twice. Your task will be to return the sum of the numbers that occur only once.
For example, `repeats([4,5,7,5,4,8]) = 15` because only the numbers `7` and `8` occur once, and their sum is `15`.
More examples ... | ["def repeats(arr):\n return sum([x for x in arr if arr.count(x) == 1])", "from collections import Counter\n\ndef repeats(arr):\n return sum(k for k, v in Counter(arr).items() if v == 1)", "def repeats(arr):\n return sum(n for n in arr if arr.count(n) == 1)", "def repeats(arr):\n single = [] #create a list to... | {"fn_name": "repeats", "inputs": [[[4, 5, 7, 5, 4, 8]], [[9, 10, 19, 13, 19, 13]], [[16, 0, 11, 4, 8, 16, 0, 11]], [[5, 17, 18, 11, 13, 18, 11, 13]], [[5, 10, 19, 13, 10, 13]]], "outputs": [[15], [19], [12], [22], [24]]} | introductory | https://www.codewars.com/kata/59f11118a5e129e591000134 |
def repeats(arr):
|
2,941 | This kata is all about adding numbers.
You will create a function named add. It will return the sum of all the arguments. Sounds easy, doesn't it?
Well Here's the Twist. The inputs will gradually decrease with their index as parameter to the function.
```python
add(3,4,6) #returns (3/1)+(4/2)+(6/3)=7
```
Remember... | ["def add(*args):\n return int(round(sum(float(a) / i for (i, a) in enumerate(args, 1))))", "def add(*args):\n return round(sum(x / i for i, x in enumerate(args, 1)))\n", "add = lambda *a: round(sum(e/i for i,e in enumerate(a,1)))", "def add(*args): \n return round(sum([args[i]/(i + 1) for i in range(len(args... | {"fn_name": "add", "inputs": [[100, 200, 300], [2], [4, -3, -2], [-1, -2, -3, -4]], "outputs": [[300], [2], [2], [-4]]} | introductory | https://www.codewars.com/kata/555de49a04b7d1c13c00000e |
def add(*args):
|
2,942 | Have you heard about the myth that [if you fold a paper enough times, you can reach the moon with it](http://scienceblogs.com/startswithabang/2009/08/31/paper-folding-to-the-moon/)? Sure you have, but exactly how many? Maybe it's time to write a program to figure it out.
You know that a piece of paper has a thickness ... | ["def fold_to(distance, thickness=0.0001, folds=0):\n if distance < 0:\n return\n \n while thickness < distance:\n thickness *= 2\n folds += 1\n \n return folds", "import math\ndef fold_to(d):\n if d<0:\n return None\n if d<0.0001:\n return 0\n return math.ceil... | {"fn_name": "fold_to", "inputs": [[384000000], [5e-05], [1e-07], [0], [-1]], "outputs": [[42], [0], [0], [0], [null]]} | introductory | https://www.codewars.com/kata/58f0ba42e89aa6158400000e |
def fold_to(distance):
|
2,943 | __Definition:__ According to Wikipedia, a [complete binary tree](https://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees) is a binary tree _"where every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible."_
The Wikipedia page referenced above also... | ["def complete_binary_tree(a):\n def in_order(n=0):\n if n < len(a):\n yield from in_order(2 * n + 1)\n yield n\n yield from in_order(2 * n + 2)\n\n result = [None] * len(a)\n for i, x in zip(in_order(), a):\n result[i] = x\n return result", "def mid(n):\n x... | {"fn_name": "complete_binary_tree", "inputs": [[[1]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]], "outputs": [[[1]], [[4, 2, 6, 1, 3, 5]], [[7, 4, 9, 2, 6, 8, 10, 1, 3, 5]]]} | introductory | https://www.codewars.com/kata/5c80b55e95eba7650dc671ea |
def complete_binary_tree(a):
|
2,944 | ## Introduction
Each chemical element in its neutral state has a specific number of electrons associated with it. This is represented by the **atomic number** which is noted by an integer number next to or above each element of the periodic table (as highlighted in the image above).
As we move from left to right, st... | ["ELEMENTS = ['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', ... | {"fn_name": "get_electron_configuration", "inputs": [["H"], ["Cr"], ["C"], ["Br"], ["V"]], "outputs": [["H -> 1s1"], ["Cr -> 1s2 2s2 2p6 3s2 3p6 3d5 4s1"], ["C -> 1s2 2s2 2p2"], ["Br -> 1s2 2s2 2p6 3s2 3p6 3d10 4s2 4p5"], ["V -> 1s2 2s2 2p6 3s2 3p6 3d3 4s2"]]} | introductory | https://www.codewars.com/kata/597737709e2c45882700009a |
ELEMENTS = ['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', '... |
2,945 | John has some amount of money of which he wants to deposit a part `f0` to the bank at the beginning
of year `1`. He wants to withdraw each year for his living an amount `c0`.
Here is his banker plan:
- deposit `f0` at beginning of year 1
- his bank account has an interest rate of `p` percent per year, constant over t... | ["def fortune(f, p, c, n, i):\n for _ in range(n-1):\n f = int(f * (100 + p) / 100 - c)\n c = int(c * (100 + i) / 100)\n if f < 0:\n return False\n return True", "def fortune(money, interest, withdraw, years, inflation):\n interest = 1 + (interest / 100)\n inflation = 1 + (in... | {"fn_name": "fortune", "inputs": [[100000, 1, 2000, 15, 1], [100000, 1, 9185, 12, 1], [100000000, 1, 100000, 50, 1], [100000000, 1.5, 10000000, 50, 1], [100000000, 5, 1000000, 50, 1], [9999, 61.8161, 10000.0, 3, 0], [9998.5, 61.8155, 10000.0, 3, 0], [10000.0, 0, 10000.0, 2, 0], [999.5, 61.87, 1000.0, 3, 0]], "outputs":... | introductory | https://www.codewars.com/kata/56445c4755d0e45b8c00010a |
def fortune(f0, p, c0, n, i):
|
2,946 | **This Kata is intended as a small challenge for my students**
All Star Code Challenge #29
Your friend Nhoj has dislexia, but can easily read messages if the words are written backwards.
Create a function called `reverseSentence()/reverse_sentence()` that accepts a string argument. The function returns a string of ... | ["def reverse_sentence(sentence):\n return ' '.join(w[::-1] for w in sentence.split())", "def reverse_sentence(sentence):\n return \" \".join(word[::-1] for word in sentence.split())", "def reverse_sentence(sentence):\n return ' '.join(reversed(sentence[::-1].split(' ')))\n", "def reverse_sentence(sentence):\n ... | {"fn_name": "reverse_sentence", "inputs": [["Hello !Nhoj Want to have lunch?"], ["1 2 3 4 5"], ["CodeWars"], ["CodeWars rules!"], [""]], "outputs": [["olleH johN! tnaW ot evah ?hcnul"], ["1 2 3 4 5"], ["sraWedoC"], ["sraWedoC !selur"], [""]]} | introductory | https://www.codewars.com/kata/5866ec8b2e8d9cec7e0000bb |
def reverse_sentence(sentence):
|
2,947 | # Task
Round the given number `n` to the nearest multiple of `m`.
If `n` is exactly in the middle of 2 multiples of m, return `n` instead.
# Example
For `n = 20, m = 3`, the output should be `21`.
For `n = 19, m = 3`, the output should be `18`.
For `n = 50, m = 100`, the output should be `50`.
# Input/Output... | ["def rounding(n, m):\n return n if n % m == m / 2 else m * round(n / m)", "def rounding(n,m):\n down, up = (n//m)*m, (n//m)*m+m\n if up-n < n-down : return up\n elif up-n == n-down : return n\n return down", "def rounding(n, m):\n return n if (n / m) % 1 == 0.5 else round(n / m) * m", "def rounding(n... | {"fn_name": "rounding", "inputs": [[20, 3], [19, 3], [1, 10], [50, 100], [123, 456]], "outputs": [[21], [18], [0], [50], [0]]} | introductory | https://www.codewars.com/kata/58bccdf56f25ff6b6d00002f |
def rounding(n, m):
|
2,948 | For an integer ```k``` rearrange all the elements of the given array in such way, that:
all elements that are less than ```k``` are placed before elements that are not less than ```k```;
all elements that are less than ```k``` remain in the same order with respect to each other;
all elements that are not less than ```... | ["def split_by_value(k, elements):\n return sorted(elements, key=lambda x: x >= k)", "def split_by_value(k, elements):\n return [x for x in elements if x < k] + [x for x in elements if x >= k]", "def split_by_value(k, elements):\n res = [[], []]\n for x in elements:\n res[k<=x].append(x)\n return ... | {"fn_name": "split_by_value", "inputs": [[5, [1, 3, 5, 7, 6, 4, 2]], [0, [5, 2, 7, 3, 2]], [6, [6, 4, 10, 10, 6]], [1, [3, 2, 8, 3, 2, 1]], [10, [9, 2, 4, 3, 4]]], "outputs": [[[1, 3, 4, 2, 5, 7, 6]], [[5, 2, 7, 3, 2]], [[4, 6, 10, 10, 6]], [[3, 2, 8, 3, 2, 1]], [[9, 2, 4, 3, 4]]]} | introductory | https://www.codewars.com/kata/5a433c7a8f27f23bb00000dc |
def split_by_value(k, elements):
|
2,949 | *Inspired by the [Fold an Array](https://www.codewars.com/kata/fold-an-array) kata. This one is sort of similar but a little different.*
---
## Task
You will receive an array as parameter that contains 1 or more integers and a number `n`.
Here is a little visualization of the process:
* Step 1: Split the array in t... | ["def split_and_add(numbers, n):\n for _ in range(n):\n middle = len(numbers) // 2\n left = numbers[:middle]\n right = numbers[middle:]\n numbers = [a + b for a, b in zip((len(right) - len(left)) * [0] + left, right)]\n if len(numbers) == 1:\n return numbers\n return ... | {"fn_name": "split_and_add", "inputs": [[[1, 2, 3, 4, 5], 2], [[1, 2, 3, 4, 5], 3], [[15], 3], [[1, 2, 3, 4], 1], [[1, 2, 3, 4, 5, 6], 20], [[32, 45, 43, 23, 54, 23, 54, 34], 2], [[32, 45, 43, 23, 54, 23, 54, 34], 0], [[3, 234, 25, 345, 45, 34, 234, 235, 345], 3], [[3, 234, 25, 345, 45, 34, 234, 235, 345, 34, 534, 45, ... | introductory | https://www.codewars.com/kata/5946a0a64a2c5b596500019a |
def split_and_add(numbers, n):
|
2,950 | In this Kata, you will be given an array of integers and your task is to return the number of arithmetic progressions of size `3` that are possible from that list. In each progression, the differences between the elements must be the same.
```
[1, 2, 3, 5, 7, 9] ==> 5
// [1, 2, 3], [1, 3, 5], [1, 5, 9], [3, 5, 7], and... | ["def solve(arr):\n return sum( y-x == z-y for i,x in enumerate(arr[:-2])\n for j,y in enumerate(arr[i+1:-1])\n for _,z in enumerate(arr[j+1:]))", "from itertools import combinations\n\ndef solve(xs):\n return sum(1 for a, b, c in combinations(xs, 3) if a - b ==... | {"fn_name": "solve", "inputs": [[[1, 2, 3, 4, 5]], [[1, 2, 3, 5, 7, 9]], [[0, 5, 8, 9, 11, 13, 14, 16, 17, 19]], [[0, 1, 2, 3, 5, 6, 7, 11, 13, 15, 17, 19]], [[0, 1, 4, 5, 7, 9, 10, 13, 15, 16, 18, 19]], [[0, 1, 2, 3, 5, 8, 11, 13, 14, 16, 18, 19]]], "outputs": [[4], [5], [10], [17], [15], [13]]} | introductory | https://www.codewars.com/kata/5a903c0557c562cd7500026f |
def solve(arr):
|
2,951 | I found this interesting interview question just today:
> *8 coins are given where all the coins have equal weight, except one. The odd one weights less than the others, not being of pure gold. In the worst case, how many iterations are actually needed to find the odd one out on a two plates scale*.
I am asking you t... | ["from math import ceil, log\n\ndef how_many_measurements(n):\n return ceil(log(n, 3))", "def how_many_measurements(n):\n if n>1: \n return 1 + how_many_measurements(n/3) \n return 0", "import math\n\ndef how_many_measurements(n):\n return math.ceil(math.log(n, 3))", "from math import log, ceil\n\ndef how_... | {"fn_name": "how_many_measurements", "inputs": [[1], [2], [3], [8], [100]], "outputs": [[0], [1], [1], [2], [5]]} | introductory | https://www.codewars.com/kata/59530d2401d6039f8600001f |
def how_many_measurements(n):
|
2,952 | A forest fire has been spotted at *fire*, a simple 2 element array with x, y coordinates.
The forest service has decided to send smoke jumpers in by plane and drop them in the forest.
The terrain is dangerous and surveyors have determined that there are three possible safe *dropzones*, an array of three simple arrays... | ["from math import hypot\n\ndef dropzone(fire, dropzones):\n return min(dropzones, key=lambda p: hypot(p[0]-fire[0], p[1]-fire[1]))", "def dropzone(p, dropzones):\n return min(dropzones, key=lambda q: (q[0]-p[0])**2 + (q[1]-p[1])**2)", "from scipy.spatial.distance import euclidean\ndef dropzone(p, dropzones):\n ... | {"fn_name": "dropzone", "inputs": [[[6, 8], [[3, 2], [6, 1], [7, 9]]], [[9, 2], [[1, 4], [9, 9], [5, 5]]]], "outputs": [[[7, 9]], [[5, 5]]]} | introductory | https://www.codewars.com/kata/5b6d065a1db5ce9b4c00003c |
def dropzone(p, dropzones):
|
2,953 | You are given an input string.
For each symbol in the string if it's the first character occurrence, replace it with a '1', else replace it with the amount of times you've already seen it...
But will your code be **performant enough**?
___
## Examples:
```
input = "Hello, World!"
result = "1112111121311... | ["def numericals(s):\n dictio = {}\n t = \"\"\n for i in s:\n dictio[i] = dictio.get(i,0) + 1 \n t += str(dictio[i])\n return t", "from collections import defaultdict\n\ndef numericals(s):\n d, lst = defaultdict(int), []\n for c in s:\n d[c] += 1\n lst.append(d[c])\n ret... | {"fn_name": "numericals", "inputs": [["Hello, World!"], ["Hello, World! It's me, JomoPipi!"], ["hello hello"], ["Hello"], ["11111"], ["hope you 123456789 expected numbers in the string"], ["In this string, I'll make sure the amounts of a character go over 9"]], "outputs": [["1112111121311"], ["1112111121311211113122413... | introductory | https://www.codewars.com/kata/5b4070144d7d8bbfe7000001 |
def numericals(s):
|
2,954 | # A History Lesson
The Pony Express was a mail service operating in the US in 1859-60.
It reduced the time for messages to travel between the Atlantic and Pacific coasts to about 10 days, before it was made obsolete by the [transcontinental telegraph](https://en.wikipedia.org/wiki/First_transcontinental_telegraph)... | ["def riders(stations):\n riders, travelled = 1, 0\n \n for dist in stations:\n if travelled + dist > 100:\n riders += 1\n travelled = dist\n else:\n travelled += dist\n \n return riders", "def riders(stations):\n n = 1\n acc = 0\n for x in stations... | {"fn_name": "riders", "inputs": [[[18, 15]], [[43, 23, 40, 13]], [[33, 8, 16, 47, 30, 30, 46]], [[6, 24, 6, 8, 28, 8, 23, 47, 17, 29, 37, 18, 40, 49]], [[50, 50]], [[50, 50, 25, 50, 24]], [[50, 50, 25, 50, 25]], [[50, 50, 25, 50, 26]], [[90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90... | introductory | https://www.codewars.com/kata/5b18e9e06aefb52e1d0001e9 |
def riders(stations):
|
2,955 | Some integral numbers are odd. All are more odd, or less odd, than others.
Even numbers satisfy `n = 2m` ( with `m` also integral ) and we will ( completely arbitrarily ) think of odd numbers as `n = 2m + 1`.
Now, some odd numbers can be more odd than others: when for some `n`, `m` is more odd than for another's. Re... | ["def oddity(n):\n while True:\n n, m = divmod(n, 2)\n yield m \n\ndef oddest(arr):\n res = arr[0]\n for n in arr[1:]:\n if next(b > a for a, b in zip(oddity(res), oddity(n)) if a != b):\n res = n\n return res", "from functools import cmp_to_key\n\ndef comp(x, y):\n ... | {"fn_name": "oddest", "inputs": [[[1, 2]], [[1, 3]], [[1, 5]], [[0]], [[1, 3, 5, 7]], [[2, 4]], [[-1]], [[-1, 0, 1]], [[-3, 3]], [[-5, 3]], [[-42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -... | introductory | https://www.codewars.com/kata/5d72704499ee62001a7068c7 |
def oddest(a):
|
2,956 | *Translations appreciated*
## Background information
The Hamming Code is used to correct errors, so-called bit flips, in data transmissions. Later in the description follows a detailed explanation of how it works.
In this Kata we will implement the Hamming Code with bit length 3, this has some advantages and disadvan... | ["def encode(stg):\n return \"\".join(digit * 3 for char in stg for digit in f\"{ord(char):08b}\")\n\n\ndef decode(binary):\n reduced = (get_digit(triplet) for triplet in chunks(binary, 3))\n return \"\".join(get_char(byte) for byte in chunks(\"\".join(reduced), 8))\n\n\ndef chunks(seq, size):\n return (seq... | {"fn_name": "encode", "inputs": [["hey"], ["The Sensei told me that i can do this kata"], ["T3st"], ["T?st!%"]], "outputs": [["000111111000111000000000000111111000000111000111000111111111111000000111"], ["0001110001110001110000000001111110001110000000000001111110000001110001110000001110000000000000000001110001110000001... | introductory | https://www.codewars.com/kata/5ef9ca8b76be6d001d5e1c3e |
def encode(string):
|
2,957 | Write a function `getDrinkByProfession`/`get_drink_by_profession()` that receives as input parameter a string, and produces outputs according to the following table:
Input
Output
"Jabroni"
"Patron Tequila"
"School Counselor"
"Anything with Alcohol"
"Programmer"
"Hipster Craft Beer"
"Bike Gang Member"
"Mo... | ["d = {\n \"jabroni\": \"Patron Tequila\",\n \"school counselor\": \"Anything with Alcohol\",\n \"programmer\": \"Hipster Craft Beer\",\n \"bike gang member\": \"Moonshine\",\n \"politician\": \"Your tax dollars\",\n \"rapper\": \"Cristal\"\n}\n\ndef get_drink_by_profession(s):\n return d.get(s.low... | {"fn_name": "get_drink_by_profession", "inputs": [["jabrOni"], ["scHOOl counselor"], ["prOgramMer"], ["bike ganG member"], ["poLiTiCian"], ["rapper"], ["pundit"], ["Pug"], ["jabrOnI"], ["scHOOl COUnselor"], ["prOgramMeR"], ["bike GanG member"], ["poLiTiCiAN"], ["RAPPer"], ["punDIT"], ["pUg"]], "outputs": [["Patron Tequ... | introductory | https://www.codewars.com/kata/568dc014440f03b13900001d |
def get_drink_by_profession(param):
|
2,958 | # Your Task
You have a cuboid with dimensions x,y,z ∈ ℕ. A subcuboid of this cuboid has dimensions length, width, height ∈ ℕ where 1≤length≤x, 1≤width≤y, 1≤height≤z. If two subcuboids have the same length, width, and height, but they are at different positions within the cuboid, they are distinct. Find the total number... | ["def subcuboids(x,y,z):\n return x*y*z*(x+1)*(y+1)*(z+1)//8", "def n(x):\n return x * (x+1) // 2\n\ndef subcuboids(x, y, z):\n return n(x) * n(y) * n(z)", "def subcuboids(x,y,z):\n return (x*(x+1)//2)*(y*(y+1)//2)*(z*(z+1)//2)", "def subcuboids(x,y,z):\n return (x + 1) * (y + 1) * (z + 1) * x * y * z //... | {"fn_name": "subcuboids", "inputs": [[1, 1, 1], [2, 2, 2], [2, 3, 3], [4, 5, 6], [3, 7, 11]], "outputs": [[1], [27], [108], [3150], [11088]]} | introductory | https://www.codewars.com/kata/5b9e29dc1d5ed219910000a7 |
def subcuboids(x,y,z):
|
2,959 | Coffee Vending Machine Problems [Part 1]
You have a vending machine, but it can not give the change back. You decide to implement this functionality. First of all, you need to know the minimum number of coins for this operation (i'm sure you don't want to return 100 pennys instead of 1$ coin).
So, find an optimal numb... | ["from functools import lru_cache\n\n\ndef optimal_number_of_coins(n, coins):\n @lru_cache(maxsize=None)\n def f(amount: int, idx: int) -> float:\n q, r = divmod(amount, coins[idx])\n if r == 0:\n return q\n elif amount < 0 or idx <= 0:\n return float(\"inf\")\n e... | {"fn_name": "optimal_number_of_coins", "inputs": [[1, [1, 2, 5, 10]], [5, [1, 2, 5, 10]], [6, [1, 3, 5, 10]], [10, [1, 2, 5, 10]], [12, [1, 3, 5, 10]], [53, [1, 2, 5, 25]], [7, [1, 1, 1, 25]], [76, [1, 3, 4, 10]], [33, [1, 6, 9, 10]], [63, [1, 2, 9, 10]], [239, [1, 2, 3, 10]], [333, [1, 1, 5, 25]], [543, [1, 3, 5, 25]]... | introductory | https://www.codewars.com/kata/586b1b91c66d181c2c00016f |
def optimal_number_of_coins(n, coins):
|
2,960 | In this kata you need to create a function that takes a 2D array/list of non-negative integer pairs and returns the sum of all the "saving" that you can have getting the [LCM](https://en.wikipedia.org/wiki/Least_common_multiple) of each couple of number compared to their simple product.
For example, if you are given:
... | ["from fractions import gcd\n\ndef sum_differences_between_products_and_LCMs(pairs):\n return sum(a*b - a*b//gcd(a,b) for a, b in pairs if a and b)", "from fractions import gcd\n\ndef lcm(x, y):\n return x * y / gcd(x, y) if gcd(x, y) else 0\n \ndef sum_differences_between_products_and_LCMs(pairs):\n return... | {"fn_name": "sum_differences_between_products_and_LCMs", "inputs": [[[[15, 18], [4, 5], [12, 60]]], [[[1, 1], [0, 0], [13, 91]]], [[[15, 7], [4, 5], [19, 60]]], [[[20, 50], [10, 10], [50, 20]]], [[]]], "outputs": [[840], [1092], [0], [1890], [0]]} | introductory | https://www.codewars.com/kata/56e56756404bb1c950000992 |
def sum_differences_between_products_and_LCMs(pairs):
|
2,961 | You are given an array of non-negative integers, your task is to complete the series from 0 to the highest number in the array.
If the numbers in the sequence provided are not in order you should order them, but if a value repeats, then you must return a sequence with only one item, and the value of that item must be ... | ["def complete_series(a):\n return list(range(max(a) + 1)) if len(a) == len(set(a)) else [0]", "def complete_series(seq): \n from collections import Counter\n if Counter(seq).most_common()[0][1] > 1:\n return [0]\n return [i for i in range(max(seq)+1)]", "def complete_series(seq): \n return [0] if... | {"fn_name": "complete_series", "inputs": [[[0, 1]], [[1, 4, 6]], [[3, 4, 5]], [[2, 1]], [[1, 4, 4, 6]]], "outputs": [[[0, 1]], [[0, 1, 2, 3, 4, 5, 6]], [[0, 1, 2, 3, 4, 5]], [[0, 1, 2]], [[0]]]} | introductory | https://www.codewars.com/kata/580a4001d6df740d61000301 |
def complete_series(seq):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.