problem_id stringlengths 32 32 | name stringclasses 1
value | problem stringlengths 200 14k | solutions stringlengths 12 1.12M | test_cases stringlengths 37 74M | difficulty stringclasses 3
values | language stringclasses 1
value | source stringclasses 7
values | num_solutions int64 12 1.12M | starter_code stringlengths 0 956 |
|---|---|---|---|---|---|---|---|---|---|
79d5c9550cb1c41da9caec7bc626715c | UNKNOWN | # Task
Given an array of integers, sum consecutive even numbers and consecutive odd numbers. Repeat the process while it can be done and return the length of the final array.
# Example
For `arr = [2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]`
The result should be `6`.
```
[2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7... | ["from itertools import groupby\n\ndef sum_groups(arr):\n newarr = [sum(j) for i,j in groupby(arr, key = lambda x: x % 2 == 0)]\n return len(newarr) if newarr == arr else sum_groups(newarr)", "def sum_groups(arr):\n lenArr, arr = -1, arr[:]\n while lenArr != len(arr):\n parity, lenArr, next = -1, len... | {"fn_name": "sum_groups", "inputs": [[[2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]], [[2, 1, 2, 2, 6, 5, 0, 2, 0, 3, 3, 3, 9, 2]], [[2]], [[1, 2]], [[1, 1, 2, 2]]], "outputs": [[6], [5], [1], [2], [1]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,469 |
def sum_groups(arr):
|
38ce6b5d46294db156a2a14994362278 | UNKNOWN | In this kata you're expected to sort an array of 32-bit integers in ascending order of the number of **on** bits they have.
E.g Given the array **[7, 6, 15, 8]**
- 7 has **3 on** bits (000...0**111**)
- 6 has **2 on** bits (000...00**11**)
- 15 has **4 on** bits (000...**1111**)
- 8 has **1 on** bit (000...**1**0... | ["def sort_by_bit(arr): \n return sorted(arr, key=lambda x: (bin(x).count(\"1\"), x))", "def sort_by_bit(a):\n return sorted(a, key=lambda x: (bin(x).count(\"1\"), x))", "def sort_by_bit(arr): \n return sorted(arr, key=lambda n: (bin(n).count(\"1\"), n))", "def sort_by_bit(lst): \n return sorted(lst, key=la... | {"fn_name": "sort_by_bit", "inputs": [[[3, 8, 3, 6, 5, 7, 9, 1]], [[9, 4, 5, 3, 5, 7, 2, 56, 8, 2, 6, 8, 0]]], "outputs": [[[1, 8, 3, 3, 5, 6, 9, 7]], [[0, 2, 2, 4, 8, 8, 3, 5, 5, 6, 9, 7, 56]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,295 |
def sort_by_bit(arr):
|
c6fc557e02cc1975dd66d59bf6f1e768 | UNKNOWN | A palindrome is a series of characters that read the same forwards as backwards such as "hannah", "racecar" and "lol".
For this Kata you need to write a function that takes a string of characters and returns the length, as an integer value, of longest alphanumeric palindrome that could be made by combining the charact... | ["from collections import Counter\n\ndef longest_palindrome(s):\n c = Counter(filter(str.isalnum, s.lower()))\n return sum(v//2*2 for v in c.values()) + any(v%2 for v in c.values())", "from collections import Counter\nimport re\n\ndef longest_palindrome(s):\n n, odds, c = 0, 0, Counter(re.sub(r'\\W+|_', '', s.... | {"fn_name": "longest_palindrome", "inputs": [["A"], ["Hannah"], ["xyz__a_/b0110//a_zyx"], ["$aaabbbccddd_!jJpqlQx_.///yYabababhii_"], [""]], "outputs": [[1], [6], [13], [25], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,243 |
def longest_palindrome(s):
|
0f30985584ac39ea4bf25a8e15ffb656 | UNKNOWN | Write a function
```python
vowel_2_index```
that takes in a string and replaces all the vowels [a,e,i,o,u] with their respective positions within that string.
E.g:
```python
vowel_2_index('this is my string') == 'th3s 6s my str15ng'
vowel_2_index('Codewars is the best site in the world') == 'C2d4w6rs 10s th15 b18... | ["def vowel_2_index(string):\n vowels = 'aeiouAEIOU'\n return ''.join(x if x not in vowels else str(n + 1) for n,x in enumerate(string))", "import re\n\ndef vowel_2_index(string):\n return re.sub(\"[aeiou]\",lambda m:str(m.end()),string,0,re.I)", "def vowel_2_index(string):\n vowels = frozenset('aeiouAEIOU')\... | {"fn_name": "vowel_2_index", "inputs": [["this is my string"], ["Codewars is the best site in the world"], ["Tomorrow is going to be raining"], [""], ["90's cornhole Austin, pickled butcher yr messenger bag gastropub next level leggings listicle meditation try-hard Vice. Taxidermy gastropub gentrify, meh fap organic en... | INTRODUCTORY | PYTHON3 | CODEWARS | 3,201 |
def vowel_2_index(string):
|
21701f3f384ccbbb4ab6321829b4846d | UNKNOWN | You have managed to intercept an important message and you are trying to read it.
You realise that the message has been encoded and can be decoded by switching each letter with a corresponding letter.
You also notice that each letter is paired with the letter that it coincides with when the alphabet is reversed.
For... | ["from string import ascii_lowercase as alphabet\n\n\ndef decode(message):\n return message.translate(str.maketrans(alphabet, alphabet[::-1]))", "def decode(message):\n return message.translate(str.maketrans('abcdefghijklmnopqrstuvwxyz','zyxwvutsrqponmlkjihgfedcba'))", "def decode(message):\n return ''.join([c... | {"fn_name": "decode", "inputs": [["sr"], ["svool"], ["r slkv mlylwb wvxlwvh gsrh nvhhztv"], ["qzezxirkg rh z srts ovevo wbmznrx fmgbkvw zmw rmgvikivgvw kiltiznnrmt ozmtfztv rg szh yvvm hgzmwziwravw rm gsv vxnzxirkg ozmtfztv hkvxrurxzgrlm zolmthrwv sgno zmw xhh rg rh lmv lu gsv gsivv vhhvmgrzo gvxsmloltrvh lu dliow drwv... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,983 |
def decode(message):
|
545536ee5498cd4d231fb6649344f89f | UNKNOWN | Jump is a simple one-player game:
You are initially at the first cell of an array of cells containing non-negative integers;
At each step you can jump ahead in the array as far as the integer at the current cell, or any smaller number of cells.
You win if there is a path that allows you to jump from one cell to anoth... | ["def can_jump(arr):\n if arr[0] == 0 or len(arr) == 1:\n return False\n \n if arr[0] >= len(arr):\n return True\n \n for jump in range(1, arr[0] +1):\n if can_jump(arr[jump:]):\n return True\n \n return False\n", "def can_jump(arr):\n last = len(arr)\n for i i... | {"fn_name": "can_jump", "inputs": [[[11, 6, 11, 0, 2, 1, 14, 3, 7, 6, 2, 1, 10, 6, 0, 0, 8, 10, 2, 12, 13, 11, 14, 6, 1, 4, 14, 3, 10, 4, 14, 2, 3, 10, 8, 13, 14, 8, 2, 13, 11, 14, 0, 1, 6, 2, 1, 6, 8, 2, 0, 12, 4, 9, 2, 6, 8, 14, 4, 14, 4, 10, 8, 7, 12, 11, 0, 3, 8, 0, 13, 9, 9, 11, 10, 13, 12, 1, 0, 10, 14, 6, 1, 11,... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,056 |
def can_jump(arr):
|
36c76937fb2a12cd28cd9a9dc1068f18 | UNKNOWN | Your task is to calculate logical value of boolean array. Test arrays are one-dimensional and their size is in the range 1-50.
Links referring to logical operations: [AND](https://en.wikipedia.org/wiki/Logical_conjunction), [OR](https://en.wikipedia.org/wiki/Logical_disjunction) and [XOR](https://en.wikipedia.org/wiki... | ["import operator\nfrom functools import reduce\n\nOPS = {\n \"AND\": operator.and_,\n \"OR\" : operator.or_,\n \"XOR\": operator.xor\n}\n\ndef logical_calc(array, op):\n return reduce(OPS[op], array)\n", "from operator import and_, or_, xor\nfrom functools import reduce\n\nOPERATOR = {'AND': and_, 'OR': or... | {"fn_name": "logical_calc", "inputs": [[[true, true, true, false], "AND"], [[true, true, true, false], "OR"], [[true, true, true, false], "XOR"], [[true, true, false, false], "AND"], [[true, true, false, false], "OR"], [[true, true, false, false], "XOR"], [[true, false, false, false], "AND"], [[true, false, false, fals... | INTRODUCTORY | PYTHON3 | CODEWARS | 24,875 |
def logical_calc(array, op):
|
bd2a4df7738ac1e393d36813d1c84b90 | UNKNOWN | You need to write a function, that returns the first non-repeated character in the given string.
For example for string `"test"` function should return `'e'`.
For string `"teeter"` function should return `'r'`.
If a string contains all unique characters, then return just the first character of the string.
Exa... | ["def first_non_repeated(s):\n return next((c for c in s if s.count(c) == 1), None)", "def first_non_repeated(s):\n for c in s:\n if s.count(c) == 1: return c", "from collections import Counter\n\ndef first_non_repeated(s):\n return next((k for k,v in Counter(s).items() if v==1), None)", "def first_non_... | {"fn_name": "first_non_repeated", "inputs": [["test"], ["teeter"], ["1122321235121222"], ["rend"]], "outputs": [["e"], ["r"], ["5"], ["r"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,210 |
def first_non_repeated(s):
|
f9d7ccacf9c6790b3153be5237dec6a8 | UNKNOWN | Similarly to the [previous kata](https://www.codewars.com/kata/string-subpattern-recognition-i/), you will need to return a boolean value if the base string can be expressed as the repetition of one subpattern.
This time there are two small changes:
* if a subpattern has been used, it will be repeated at least twice,... | ["from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\ndef has_subpattern(string):\n return reduce(gcd, Counter(string).values()) != 1", "from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\ndef has_subpattern(s):\n return reduce(gcd, Counter(s).... | {"fn_name": "has_subpattern", "inputs": [["a"], ["aaaa"], ["abcd"], ["babababababababa"], ["ababababa"], ["123a123a123a"], ["123A123a123a"], ["12aa13a21233"], ["12aa13a21233A"], ["abcdabcaccd"]], "outputs": [[false], [true], [false], [true], [false], [true], [false], [true], [false], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,346 |
def has_subpattern(string):
|
aba6a37d04996f4d179cdddf7da04815 | UNKNOWN | # Task
Your task is to find the sum for the range `0 ... m` for all powers from `0 ... n.
# Example
For `m = 2, n = 3`, the result should be `20`
`0^0+1^0+2^0 + 0^1+1^1+2^1 + 0^2+1^2+2^2 + 0^3+1^3+2^3 = 20`
Note, that no output ever exceeds 2e9.
# Input/Output
- `[input]` integer m
`0 <= m <= 50000`
... | ["def S2N(m, n):\n return sum(i**j for i in range(m+1) for j in range(n+1))", "def S2N(m,n):\n return sum((a**(n+1)-1)//(a-1) if a!=1 else n+1 for a in range(m+1))", "def S2N(m, n):\n result = 0\n for x in range(n+1):\n for y in range(m+1):\n result += y**x\n return result", "def S2N(m,n):\n ret... | {"fn_name": "S2N", "inputs": [[2, 3], [3, 5], [10, 9], [1, 1], [0, 0], [300, 2], [567, 2], [37, 4], [36, 4]], "outputs": [[20], [434], [1762344782], [3], [1], [9090501], [61083856], [15335280], [13409059]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,758 |
def S2N(m, n):
|
8a7e7b73be50c096312383379b0fc261 | UNKNOWN | For this problem you must create a program that says who ate the last cookie. If the input is a string then "Zach" ate the cookie. If the input is a float or an int then "Monica" ate the cookie. If the input is anything else "the dog" ate the cookie. The way to return the statement is:
"Who ate the last cookie? It was ... | ["def cookie(x):\n return \"Who ate the last cookie? It was %s!\" % {str:\"Zach\", float:\"Monica\", int:\"Monica\"}.get(type(x), \"the dog\")", "def cookie(x):\n try:\n who = {int: 'Monica', float: 'Monica', str: 'Zach'}[type(x)]\n except KeyError:\n who = 'the dog'\n return 'Who ate the last... | {"fn_name": "cookie", "inputs": [["Ryan"], [2.3], [26], [true], ["True"], [false], [1.98528462]], "outputs": [["Who ate the last cookie? It was Zach!"], ["Who ate the last cookie? It was Monica!"], ["Who ate the last cookie? It was Monica!"], ["Who ate the last cookie? It was the dog!"], ["Who ate the last cookie? It w... | INTRODUCTORY | PYTHON3 | CODEWARS | 26,281 |
def cookie(x):
|
3fb433326a8c5939b6a8174b508197f0 | UNKNOWN | For this kata, you are given three points ```(x1,y1,z1)```, ```(x2,y2,z2)```, and ```(x3,y3,z3)``` that lie on a straight line in 3-dimensional space.
You have to figure out which point lies in between the other two.
Your function should return 1, 2, or 3 to indicate which point is the in-between one. | ["def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):\n return sorted(((x1, y1, z1, 1), (x2, y2, z2, 2), (x3, y3, z3, 3)))[1][3]\n", "def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):\n return max(\n ((x2-x3)**2 + (y2-y3)**2 + (z2-z3)**2, 1),\n ((x1-x3)**2 + (y1-y3)**2 + (z1-z3)**2, 2),\n ... | {"fn_name": "middle_point", "inputs": [[1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 0, 6, -2, 8, 3, 0, 4], [0.25, 0.5, 0.75, 3.25, -0.5, -0.25, 1.0, 0.25, 0.5], [1, 0, 4, 5, 0, 6, -7, 0, 0], [-1, 0, 2, -2, 4, -1, -3, 8, -4]], "outputs": [[2], [3], [3], [1], [2]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,648 |
def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):
|
86753815a40dc1315890b986850ec6b2 | UNKNOWN | # Task
Find the integer from `a` to `b` (included) with the greatest number of divisors. For example:
```
divNum(15, 30) ==> 24
divNum(1, 2) ==> 2
divNum(0, 0) ==> 0
divNum(52, 156) ==> 120
```
If there are several numbers that have the same (maximum) number of divisors, the smallest among them should be ... | ["import numpy as np\ns = np.ones(100000)\nfor i in range(2, 100000):\n s[i::i] += 1\n\ndef div_num(a, b):\n return max(range(a, b+1), key=lambda i: (s[i], -i), default='Error')", "def div_num(a, b):\n return 'Error' if a > b else sorted([i for i in range(a, b + 1)], key=lambda k:(-divisors(k), k))[0]\n \nd... | {"fn_name": "div_num", "inputs": [[15, 30], [1, 2], [52, 156], [159, 4], [15, 48]], "outputs": [[24], [2], [120], ["Error"], [48]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,351 |
def div_num(a, b):
|
294036a2657f504b5c65195a9b96c7b7 | UNKNOWN | ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but **exactly** 4 digits or exactly 6 digits.
If the function is passed a valid PIN string, return `true`, else return `false`.
## Examples
```
"1234" --> true
"12345" --> false
"a234" --> false
``` | ["def validate_pin(pin):\n return len(pin) in (4, 6) and pin.isdigit()", "def validate_pin(pin):\n return len(pin) in [4, 6] and pin.isdigit()\n", "validate_pin = lambda pin: len(pin) in (4, 6) and pin.isdigit()", "def merge(array1,array2):\n array3 = []\n i = 0\n j = 0\n while (i < len(array1) and j ... | {"fn_name": "validate_pin", "inputs": [["1"], ["12"], ["123"], ["12345"], ["1234567"], ["-1234"], ["-12345"], ["1.234"], ["00000000"], ["a234"], [".234"], ["1234"], ["0000"], ["1111"], ["123456"], ["098765"], ["000000"], ["090909"]], "outputs": [[false], [false], [false], [false], [false], [false], [false], [false], [f... | INTRODUCTORY | PYTHON3 | CODEWARS | 5,368 |
def validate_pin(pin):
|
22ff1ba096aaab41b98da07eafc8bb4a | UNKNOWN | Lot of junior developer can be stuck when they need to change the access permission to a file or a directory in an Unix-like operating systems.
To do that they can use the `chmod` command and with some magic trick they can change the permissionof a file or a directory. For more information about the `chmod` command yo... | ["def chmod_calculator(perm):\n perms = { \"r\": 4, \"w\": 2, \"x\": 1 }\n value = \"\"\n for permission in [\"user\", \"group\", \"other\"]:\n value += str(sum(perms.get(x, 0) for x in perm.get(permission, \"\")))\n \n return value", "def chmod_calculator(perm): \n return str(sum([wbin(... | {"fn_name": "chmod_calculator", "inputs": [[{"user": "rwx", "group": "r-x", "other": "r-x"}], [{"user": "rwx", "group": "r--", "other": "r--"}], [{"user": "r-x", "group": "r-x", "other": "---"}], [{"group": "rwx"}], [{}]], "outputs": [["755"], ["744"], ["550"], ["070"], ["000"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,663 |
def chmod_calculator(perm):
|
a1fa69b5c854d76380802d4fb8c59cbc | UNKNOWN | Your task is very simple. Given an input string s, case\_sensitive(s), check whether all letters are lowercase or not. Return True/False and a list of all the entries that are not lowercase in order of their appearance in s.
For example, case\_sensitive('codewars') returns [True, []], but case\_sensitive('codeWaRs') r... | ["def case_sensitive(s):\n return [s.islower() or not s, [c for c in s if c.isupper()]]", "l,case_sensitive=lambda s:[not any(s),s],lambda s:l([x for x in s if x.isupper()])", "def case_sensitive(s):l=list(filter(str.isupper,s));return[not l,l]", "def case_sensitive(s):\n return [not s or s.islower(), [c for c in... | {"fn_name": "case_sensitive", "inputs": [["asd"], ["cellS"], ["z"], [""]], "outputs": [[[true, []]], [[false, ["S"]]], [[true, []]], [[true, []]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 947 |
def case_sensitive(s):
|
1dddb3ea6b79511d4019f7e2496ce659 | UNKNOWN | You throw a ball vertically upwards with an initial speed `v (in km per hour)`. The height `h` of the ball at each time `t`
is given by `h = v*t - 0.5*g*t*t` where `g` is Earth's gravity `(g ~ 9.81 m/s**2)`. A device is recording at every **tenth
of second** the height of the ball.
For example with `v = 15 km/h` the de... | ["\"\"\"\nh = vt-0.5gt^2\nlet h = 0 [that is, when the ball has returned to the ground]\n=> 0 = vt-0.5gt^2\n=> 0.5gt^2 = vt\n=> 0.5gt = v\n=> t = 2v/g - the total time the ball is in the air.\n=> t at max height = v/g\n\"\"\"\n\ndef max_ball(v0):\n return round(10*v0/9.81/3.6)", "def max_ball(v0):\n return round... | {"fn_name": "max_ball", "inputs": [[37], [45], [99], [85], [136], [52], [16], [127], [137], [14]], "outputs": [[10], [13], [28], [24], [39], [15], [5], [36], [39], [4]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,927 |
def max_ball(v0):
|
50c493931f5032e9cb385817fb7b3930 | UNKNOWN | An abundant number or excessive number is a number for which the sum of its proper divisors is greater than the number itself.
The integer 12 is the first abundant number. Its proper divisors are 1, 2, 3, 4 and 6 for a total of 16 (> 12).
Derive function `abundantNumber(num)/abundant_number(num)` which returns `true... | ["def abundant_number(num):\n return (sum([e for e in range(1,num) if num%e==0]) > num)", "def abundant_number(n):\n return sum(m for m in range(1, n) if n % m == 0) > n", "def abundant_number(num):\n return sum(i for i in range(1, num//2 + 1) if not num % i) > num", "def abundant_number(num):\n # O(sqrt(nu... | {"fn_name": "abundant_number", "inputs": [[12], [18], [37], [120], [77], [118], [5830], [11410], [14771], [11690]], "outputs": [[true], [true], [false], [true], [false], [false], [true], [true], [false], [true]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,065 |
def abundant_number(num):
|
e9959c0ca431d164a9ebe269ae14aa7a | UNKNOWN | [Haikus](https://en.wikipedia.org/wiki/Haiku_in_English) are short poems in a three-line format, with 17 syllables arranged in a 5–7–5 pattern. Your task is to check if the supplied text is a haiku or not.
### About syllables
[Syllables](https://en.wikipedia.org/wiki/Syllable) are the phonological building blocks of... | ["import re\n\nPATTERN = re.compile(r'[aeyuio]+[^aeyuio ]*((?=e\\b)e)?', flags=re.I)\n\n\ndef is_haiku(text):\n return [5,7,5] == [check(s) for s in text.split(\"\\n\")]\n \ndef check(s):\n return sum(1 for _ in PATTERN.finditer(s))\n", "import re\n\ndef is_haiku(text):\n def count_syllables(line):\n ... | {"fn_name": "is_haiku", "inputs": [["An old silent pond...\nA frog jumps into the pond,\nsplash! Silence again."], ["An old silent pond...\nA frog jumps into the pond, splash!\nSilence again."], ["An old silent pond...\nA frog jumps into the pond,\nsplash!\nSilence again."], ["An old silent pond... A frog jumps into th... | INTRODUCTORY | PYTHON3 | CODEWARS | 8,266 |
def is_haiku(text):
|
424c055834c29c9acc2b5b35f708f549 | UNKNOWN | # Task
Consider a string of lowercase Latin letters and space characters (" ").
First, rearrange the letters in each word `alphabetically`.
And then rearrange the words in ascending order of the sum of their characters' `ASCII` values.
If two or more words have the same `ASCII` value, rearrange them by the... | ["def revamp(s):\n words = [''.join(sorted(word)) for word in s.split()]\n words.sort(key=lambda word: (sum(map(ord, word)), len(word), word))\n return ' '.join(words)", "def revamp(s):\n words = [\"\".join(sorted(word)) for word in s.split()]\n return \" \".join(sorted(words, key = lambda word: (sum(ord... | {"fn_name": "revamp", "inputs": [["batman is bruce wayne"], ["peter parker is spiderman"], ["codewars is great"], ["airplanes in the night sky"]], "outputs": [["is bceru aenwy aabmnt"], ["is eeprt aekprr adeimnprs"], ["is aegrt acdeorsw"], ["in eht ksy ghint aaeilnprs"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,548 |
def revamp(s):
|
9aaeb6093966c33c03cb2879aff237e1 | UNKNOWN | I need some help with my math homework. I have a number of problems I need to return the derivative for.
They will all be of the form:
ax^b,
A and B are both integers, but can be positive or negative.
Note:
- if b is 1, then the equation will be ax.
- if b is 0, then the equation will be 0.
Examples:
... | ["def get_derivative(s):\n if '^' in s:\n f,t = map(int, s.split('x^'))\n return '{}x'.format(f*t) if t==2 else '{}x^{}'.format(f*t, t-1)\n elif 'x' in s: return s[:-1]\n else: return '0'", "def get_derivative(s):\n if 'x' not in s: return '0'\n if '^' not in s: return s.replace('x', '')\n ... | {"fn_name": "get_derivative", "inputs": [["3x^3"], ["3x^2"], ["3x"], ["3"], ["3x^-1"], ["-3x^-1"], ["-3x^10"], ["-954x^2"]], "outputs": [["9x^2"], ["6x"], ["3"], ["0"], ["-3x^-2"], ["3x^-2"], ["-30x^9"], ["-1908x"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,534 |
def get_derivative(s):
|
664a2270714db6cca611dd9743c61077 | UNKNOWN | There are some stones on Bob's table in a row, and each of them can be red, green or blue, indicated by the characters `R`, `G`, and `B`.
Help Bob find the minimum number of stones he needs to remove from the table so that the stones in each pair of adjacent stones have different colours.
Examples:
```
"RGBRGBRGGB" ... | ["def solution(s):\n st=[1 for i in range(1,len(s)) if s[i-1]==s[i]]\n return sum(st)", "def solution(s):\n return sum(1 for i in range(len(s)) if i and s[i-1]==s[i])", "def solution(s):\n r = s\n for i in range(9):\n r = r.replace('RR', 'R').replace('GG', 'G').replace('BB', 'B')\n\n return len... | {"fn_name": "solution", "inputs": [["RRGGBB"], ["RGBRGB"], ["BGRBBGGBRRR"], ["GBBBGGRRGRB"], ["GBRGGRBBBBRRGGGB"]], "outputs": [[3], [0], [4], [4], [7]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,439 |
def solution(stones):
|
f1a43e21fe2bc21d937d2c952bfde87d | UNKNOWN | Create the function ```consecutive(arr)``` that takes an array of integers and return the minimum number of integers needed to make the contents of ```arr``` consecutive from the lowest number to the highest number.
For example: If ```arr``` contains [4, 8, 6] then the output should be 2 because two numbers need to be... | ["def consecutive(arr):\n return max(arr) - min(arr) + 1 - len(arr) if arr else 0", "def consecutive(arr):\n #your code here\n if len(arr) == 1 or len(arr) == 0:\n return 0\n mn, mx = min(arr), max(arr)\n s = set(arr)\n return mx - mn - len(s) + 1", "consecutive=lambda a:len(a)and-~max(a)-min(a... | {"fn_name": "consecutive", "inputs": [[[4, 8, 6]], [[1, 2, 3, 4]], [[]], [[1]], [[-10]], [[1, -1]], [[-10, -9]], [[0]], [[10, -10]], [[-10, 10]]], "outputs": [[2], [0], [0], [0], [0], [1], [0], [0], [19], [19]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,091 |
def consecutive(arr):
|
f716c06d359c30deb4ae09cae947d2da | UNKNOWN | I have the `par` value for each hole on a golf course and my stroke `score` on each hole. I have them stored as strings, because I wrote them down on a sheet of paper. Right now, I'm using those strings to calculate my golf score by hand: take the difference between my actual `score` and the `par` of the hole, and add... | ["def golf_score_calculator(par, score):\n return sum(int(b) - int(a) for a, b in zip(par, score))", "def golf_score_calculator(p, s):\n return sum([int(s[i])-int(p[i]) for i in range(len(p))])", "def golf_score_calculator(par, score):\n return sum(map(int, score)) - sum(map(int, par))", "def golf_score_calcul... | {"fn_name": "golf_score_calculator", "inputs": [["443454444344544443", "353445334534445344"], ["123456123456123456", "123456123456123456"]], "outputs": [[-1], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,620 |
def golf_score_calculator(par_string, score_string):
|
51148a1275020a006fe12620420646eb | UNKNOWN | The written representation of a number (with 4 or more digits) can be split into three parts in various different ways. For example, the written number 1234 can be split as [1 | 2 | 34] or [1 | 23 | 4] or [12 | 3 | 4].
Given a written number, find the highest possible product from splitting it into three parts and mul... | ["from functools import reduce\nfrom operator import mul\n\ndef maximum_product_of_parts(n):\n s = str(n)\n return max(reduce(mul, map(int, (s[:i], s[i:j], s[j:])))\n for i in range(1,len(s)-1) for j in range(i+1,len(s)))", "from functools import reduce, partial\nfrom operator import mul\nproduct = ... | {"fn_name": "maximum_product_of_parts", "inputs": [[1234], [4321], [4224]], "outputs": [[144], [252], [352]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,298 |
def maximum_product_of_parts(n):
|
34e703b88b577df692021d55d285865f | UNKNOWN | # Summary:
Given a number, `num`, return the shortest amount of `steps` it would take from 1, to land exactly on that number.
# Description:
A `step` is defined as either:
- Adding 1 to the number: `num += 1`
- Doubling the number: `num *= 2`
You will always start from the number `1` and you will have to return the s... | ["def shortest_steps_to_num(num):\n steps = 0\n \n while num != 1:\n if num % 2:\n num -= 1\n else:\n num //= 2\n \n steps += 1\n \n return steps", "def shortest_steps_to_num(num):\n return num.bit_length() + bin(num).count('1') - 2", "def shortest_ste... | {"fn_name": "shortest_steps_to_num", "inputs": [[2], [3], [4], [5], [6], [7], [8], [9], [10], [20], [30], [40], [50], [11], [24], [37], [19], [48], [59], [65], [73], [83], [64], [99], [100], [10000], [1500], [1534], [1978], [2763], [9999], [2673], [4578], [9876], [2659], [7777], [9364], [7280], [4998], [9283], [8234], ... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,389 |
def shortest_steps_to_num(num):
|
e7d515f09add7c8a8d6a22628d72bdf9 | UNKNOWN | Prior to having fancy iPhones, teenagers would wear out their thumbs sending SMS
messages on candybar-shaped feature phones with 3x4 numeric keypads.
------- ------- -------
| | | ABC | | DEF |
| 1 | | 2 | | 3 |
------- ------- -------
------- ------- -------
| GHI | | JKL | | MNO |
... | ["BUTTONS = [ '1', 'abc2', 'def3',\n 'ghi4', 'jkl5', 'mno6',\n 'pqrs7', 'tuv8', 'wxyz9',\n '*', ' 0', '#' ]\ndef presses(phrase):\n return sum(1 + button.find(c) for c in phrase.lower() for button in BUTTONS if c in button)", "def presses(phrase):\n x = 0\n for letter i... | {"fn_name": "presses", "inputs": [["LOL"], ["HOW R U"], ["WHERE DO U WANT 2 MEET L8R"], ["lol"], ["0"], ["ZER0"], ["1"], ["IS NE1 OUT THERE"], ["#"], ["#codewars #rocks"]], "outputs": [[9], [13], [47], [9], [2], [11], [1], [31], [1], [36]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,043 |
def presses(phrase):
|
ae98c5c2ac38994cc34f165cc6d0bac1 | UNKNOWN | Consider integer coordinates x, y in the Cartesian plan and three functions f, g, h
defined by:
```
f: 1 <= x <= n, 1 <= y <= n --> f(x, y) = min(x, y)
g: 1 <= x <= n, 1 <= y <= n --> g(x, y) = max(x, y)
h: 1 <= x <= n, 1 <= y <= n --> h(x, y) = x + y
```
where n is a given integer (n >= 1, guaranteed) and x, y are in... | ["def sumin(n):\n return n * (n + 1) * (2 * n + 1) // 6\n \ndef sumax(n):\n return n * (n + 1) * (4 * n - 1) // 6\n \ndef sumsum(n):\n return n * n * (n + 1)\n\n", "def sumin(n):\n# return sum(min(x+1,y+1) for y in range(n) for x in range(n))\n return sum((i+1)*(2*(n-i)-1) for i in range(n))\n ... | {"fn_name": "sumin", "inputs": [[5], [6], [8], [15], [100], [365], [730], [4000]], "outputs": [[55], [91], [204], [1240], [338350], [16275715], [129938905], [21341334000]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,082 |
def sumin(n):
|
9940105db597562f4090bc06b0ddbc62 | UNKNOWN | In this kata, your task is to create a function that takes a single list as an argument and returns a flattened list. The input list will have a maximum of one level of nesting (list(s) inside of a list).
```python
# no nesting
[1, 2, 3]
# one level of nesting
[1, [2, 3]]
```
---
# Examples
```python
>>> flatten_me... | ["def flatten_me(lst):\n res = []\n for l in lst:\n if isinstance(l, list):\n res.extend(l)\n else:\n res.append(l)\n return res\n", "def flatten_me(nput):\n output = []\n for itm in nput:\n if isinstance(itm, list):\n output += flatten_me(itm)\n ... | {"fn_name": "flatten_me", "inputs": [[[1, [2, 3], 4]], [[["a", "b"], "c", ["d"]]], [["!", "?"]]], "outputs": [[[1, 2, 3, 4]], [["a", "b", "c", "d"]], [["!", "?"]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,742 |
def flatten_me(lst):
|
7b215d4f965f30bea76903ed8be6eb04 | UNKNOWN | Have you heard about Megamind? Megamind and Metro Man are two aliens who came to earth. Megamind wanted to destroy the earth, while Metro Man wanted to stop him and protect mankind. After a lot of fighting, Megamind finally threw Metro Man up into the sky. Metro Man was defeated and was never seen again. Megamind wante... | ["from math import ceil\n\ndef mega_mind(hp, dps, shots, regen):\n if dps*shots >= hp: return ceil(hp / dps)\n if dps*shots <= regen: return -1\n\n number_of_regenerations = ceil((hp - dps*shots) / (dps*shots - regen))\n return ceil((hp + regen*number_of_regenerations) / dps)", "from math import ceil\n\ndef... | {"fn_name": "mega_mind", "inputs": [[12, 4, 3, 2], [9, 4, 2, 7], [13, 4, 3, 1], [13, 4, 3, 50], [36, 4, 3, 2], [15, 4, 3, 12], [100000, 99999, 100000, 100000], [100000, 100000, 100000, 100000], [100000, 1, 50000, 49999], [100000, 1, 1000, 999], [17, 4, 4, 16], [23, 4, 4, 13], [1, 4, 4, 15], [22, 4, 4, 13], [16, 4, 4, 1... | INTRODUCTORY | PYTHON3 | CODEWARS | 4,073 |
def mega_mind(hp, dps, shots, regen):
|
f55e6297f9374ccae592583b34371528 | UNKNOWN | A new task for you!
You have to create a method, that corrects a given time string.
There was a problem in addition, so many of the time strings are broken.
Time-Format is european. So from "00:00:00" to "23:59:59".
Some examples:
"09:10:01" -> "09:10:01"
"11:70:10" -> "12:10:10"
"19:99:99" -> "20:40:39"
"24:01:01"... | ["def time_correct(t):\n if not t: return t\n try:\n h, m, s = map(int, t.split(':'))\n if s >= 60: s -= 60; m += 1\n if m >= 60: m -= 60; h += 1\n return '%02d:%02d:%02d' % (h % 24, m, s)\n except: pass", "import re\n\n\ndef time_correct(t):\n if not t:\n return t\n \n... | {"fn_name": "time_correct", "inputs": [[null], [""], ["001122"], ["00;11;22"], ["0a:1c:22"], ["09:10:01"], ["11:70:10"], ["19:99:99"], ["24:01:01"], ["52:01:01"], ["14:59:94"]], "outputs": [[null], [""], [null], [null], [null], ["09:10:01"], ["12:10:10"], ["20:40:39"], ["00:01:01"], ["04:01:01"], ["15:00:34"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 45,820 |
def time_correct(t):
|
c74b221d1d33cf0acc898087cfd7d028 | UNKNOWN | Complete the function which returns the weekday according to the input number:
* `1` returns `"Sunday"`
* `2` returns `"Monday"`
* `3` returns `"Tuesday"`
* `4` returns `"Wednesday"`
* `5` returns `"Thursday"`
* `6` returns `"Friday"`
* `7` returns `"Saturday"`
* Otherwise returns `"Wrong, please enter a number betwee... | ["WEEKDAY = {\n 1: 'Sunday',\n 2: 'Monday',\n 3: 'Tuesday',\n 4: 'Wednesday',\n 5: 'Thursday',\n 6: 'Friday',\n 7: 'Saturday' }\nERROR = 'Wrong, please enter a number between 1 and 7'\n\n\ndef whatday(n):\n return WEEKDAY.get(n, ERROR)\n", "def whatday(num):\n switcher = {\n 1:'Sunday',\n ... | {"fn_name": "whatday", "inputs": [[1], [2], [3], [4], [5], [6], [7], [0], [8], [20]], "outputs": [["Sunday"], ["Monday"], ["Tuesday"], ["Wednesday"], ["Thursday"], ["Friday"], ["Saturday"], ["Wrong, please enter a number between 1 and 7"], ["Wrong, please enter a number between 1 and 7"], ["Wrong, please enter a number... | INTRODUCTORY | PYTHON3 | CODEWARS | 27,810 |
def whatday(num):
|
591c6cfb7095b09c0f0617df013ea315 | UNKNOWN | # Task
You are given n rectangular boxes, the ith box has the length lengthi, the width widthi and the height heighti.
Your task is to check if it is possible to pack all boxes into one so that inside each box there is no more than one another box (which, in turn, can contain at most one another box, and so on).
... | ["def boxes_packing(l, w, h):\n boxes = sorted(sorted(t) for t in zip(l, w, h))\n return all( s < l for b1,b2 in zip(boxes[:-1], boxes[1:]) for s,l in zip(b1,b2))", "def boxes_packing(length, width, height):\n boxes = sorted([sorted(b) for b in zip(length, width, height)])\n return all(all(x < y for x, y in... | {"fn_name": "boxes_packing", "inputs": [[[1, 3, 2], [1, 3, 2], [1, 3, 2]], [[1, 1], [1, 1], [1, 1]], [[3, 1, 2], [3, 1, 2], [3, 2, 1]], [[2], [3], [4]], [[5, 7, 4, 1, 2], [4, 10, 3, 1, 4], [6, 5, 5, 1, 2]], [[6, 4], [5, 3], [4, 5]], [[6, 3], [5, 4], [4, 5]], [[6, 3], [5, 5], [4, 4]], [[883, 807], [772, 887], [950, 957]... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,925 |
def boxes_packing(length, width, height):
|
4e8c10d9b15cadd6bedbeffd1fcc2848 | UNKNOWN | Welcome.
In this kata you are required to, given a string, replace every letter with its position in the alphabet.
If anything in the text isn't a letter, ignore it and don't return it.
`"a" = 1`, `"b" = 2`, etc.
## Example
```python
alphabet_position("The sunset sets at twelve o' clock.")
```
Should return `"20 8... | ["def alphabet_position(text):\n return ' '.join(str(ord(c) - 96) for c in text.lower() if c.isalpha())", "def alphabet_position(s):\n return \" \".join(str(ord(c)-ord(\"a\")+1) for c in s.lower() if c.isalpha())\n", "alphabet = 'abcdefghijklmnopqrstuvwxyz'\n\ndef alphabet_position(text):\n if type(text) == str:... | {"fn_name": "alphabet_position", "inputs": [["-.-'"]], "outputs": [[""]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,491 |
def alphabet_position(text):
|
c4cad86a3420097aa60978f496b279c4 | UNKNOWN | All of the animals are having a feast! Each animal is bringing one dish. There is just one rule: the dish must start and end with the same letters as the animal's name. For example, the great blue heron is bringing garlic naan and the chickadee is bringing chocolate cake.
Write a function `feast` that takes the animal... | ["def feast(beast, dish):\n return beast[0]==dish[0] and dish[-1]==beast[-1]", "def feast(beast, dish):\n return beast[0] == dish[0] and beast[-1] == dish[-1] ", "def feast(beast, dish):\n return beast.startswith(dish[0]) and beast.endswith(dish[-1])", "def feast(beast, dish):\n \"\"\" (str, str) -> bool... | {"fn_name": "feast", "inputs": [["great blue heron", "garlic naan"], ["chickadee", "chocolate cake"], ["brown bear", "bear claw"], ["marmot", "mulberry tart"], ["porcupine", "pie"], ["cat", "yogurt"], ["electric eel", "lasagna"], ["slow loris", "salsas"], ["ox", "orange lox"], ["blue-footed booby", "blueberry"], ["frui... | INTRODUCTORY | PYTHON3 | CODEWARS | 16,315 |
def feast(beast, dish):
|
7aec952afdf5f849964667cdb63544fe | UNKNOWN | Write a function that rearranges an integer into its largest possible value.
```python
super_size(123456) # 654321
super_size(105) # 510
super_size(12) # 21
```
``` haskell
superSize 123456 `shouldBe` 654321
superSize 105 `shouldBe` 510
superSize 12 `shouldBe` 21
```
If the argument passed throu... | ["def super_size(n):\n return int(''.join(sorted(str(n), reverse = True)))", "def super_size(n):\n b = list(str(n))\n b.sort(reverse=True)\n return int(\"\".join(b))\n", "def super_size(n):\n return int(''.join(sorted(str(n)))[::-1])", "super_size=lambda n: int(\"\".join(sorted(str(n),reverse=True)))", "... | {"fn_name": "super_size", "inputs": [[69], [513], [2017], [414], [608719], [123456789], [700000000001], [666666], [2], [0]], "outputs": [[96], [531], [7210], [441], [987610], [987654321], [710000000000], [666666], [2], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 16,406 |
def super_size(n):
|
b5a673ea731c28216a0d44e8dac5bf87 | UNKNOWN | # Task
**Your task** is to implement function `printNumber` (`print_number` in C/C++ and Python `Kata.printNumber` in Java) that returns string that represents given number in text format (see examples below).
Arguments:
- `number` — Number that we need to print (`num` in C/C++/Java)
- `char` — Character for buildi... | ["L = (\n (' #### ', ' ## ', ' #### ', ' #### ', '## ##', '######', ' ## ', '######', ' #### ', ' #### ').__getitem__,\n ('## ##', ' ### ', '## ##', '## ##', '## ##', '## ', ' ## ', '## ##', '## ##', '## ##').__getitem__,\n ('## ##', '# ## ', ' ## ', ' ## ', '## ##', '##### ', ' ###... | {"fn_name": "print_number", "inputs": [[99, "$"], [12345, "*"], [67890, "@"]], "outputs": [["$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n$ $\n$ $$$$ $$$$ $$$$ $$$$ $$$$ $\n$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $\n$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $\n$ $$ $$ $$ $$ ... | INTRODUCTORY | PYTHON3 | CODEWARS | 15,622 |
def print_number(number, char):
|
767bcde33579fe51c6c8da91bd77bdb3 | UNKNOWN | Write a function that takes a string and returns an array of the repeated characters (letters, numbers, whitespace) in the string.
If a charater is repeated more than once, only show it once in the result array.
Characters should be shown **by the order of their first repetition**. Note that this may be different fro... | ["def remember(str_):\n seen = set()\n res = []\n for i in str_: \n res.append(i) if i in seen and i not in res else seen.add(i)\n return res\n", "from collections import Counter\n\ndef remember(str_):\n seen, lst = Counter(), []\n for c in str_:\n if seen[c] == 1: lst.append(c)\n ... | {"fn_name": "remember", "inputs": [["apple"], ["limbojackassin the garden"], ["11pinguin"], ["Claustrophobic"], ["apPle"], ["11 pinguin"], ["pippi"], ["Pippi"], ["kamehameha"], [""]], "outputs": [[["p"]], [["a", "s", "i", " ", "e", "n"]], [["1", "i", "n"]], [["o"]], [[]], [["1", "i", "n"]], [["p", "i"]], [["p", "i"]], ... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,848 |
def remember(str_):
|
ee35bf5c0bbf6b5664c3e35f5b22ab53 | UNKNOWN | ## Task
Given a positive integer as input, return the output as a string in the following format:
Each element, corresponding to a digit of the number, multiplied by a power of 10 in such a way that with the sum of these elements you can obtain the original number.
## Examples
Input | Output
--- | ---
0 | ""... | ["def simplify(n): \n output = []\n exp = 0\n \n while n:\n n, r = divmod(n, 10)\n if r:\n output.append(f\"{r}*{10**exp}\" if exp else f\"{r}\")\n exp += 1\n \n return \"+\".join(output[::-1])", "def simplify(number):\n num = str(number)\n result = []\n for i,... | {"fn_name": "simplify", "inputs": [[8964631], [56], [999], [11], [991], [47], [234], [196587], [660], [600], [9090], [10104], [80008], [90000], [0]], "outputs": [["8*1000000+9*100000+6*10000+4*1000+6*100+3*10+1"], ["5*10+6"], ["9*100+9*10+9"], ["1*10+1"], ["9*100+9*10+1"], ["4*10+7"], ["2*100+3*10+4"], ["1*100000+9*100... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,565 |
def simplify(n):
|
52bc32f29db9ac68523324d06844c893 | UNKNOWN | A Narcissistic Number is a number of length n in which the sum of its digits to the power of n is equal to the original number. If this seems confusing, refer to the example below.
Ex: 153, where n = 3 (number of digits in 153)
1^(3) + 5^(3) + 3^(3) = 153
Write a method is_narcissistic(i) (in Haskell: isNarcissistic ... | ["def is_narcissistic(n):\n num = str(n)\n length = len(num)\n return sum(int(a) ** length for a in num) == n\n", "def is_narcissistic(i):\n return sum([int(n)**len(str(i)) for n in str(i)])==i", "def is_narcissistic(n):\n t = str(n)\n l = len(t)\n \n return n == sum(int(d) ** l for d in t)", "is_narcis... | {"fn_name": "is_narcissistic", "inputs": [[153], [370], [371], [407], [1634], [8208], [9474], [54748], [92727], [93084], [548834], [1741725], [4210818], [9800817], [9926315], [24678050], [88593477], [146511208], [472335975], [534494836], [912985153], [4679307774], [115132219018763992565095597973971522401]], "outputs": ... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,236 |
def is_narcissistic(i):
|
d9ad2599df958a610ef478da0c934432 | UNKNOWN | In a small town the population is `p0 = 1000` at the beginning of a year. The population
regularly increases by `2 percent` per year and moreover `50` new inhabitants per year
come to live in the town.
How many years does the town need to see its population
greater or equal to `p = 1200` inhabitants?
```
At the end o... | ["def nb_year(population, percent, aug, target):\n year = 0\n while population < target:\n population += population * percent / 100. + aug\n year += 1\n return year", "def nb_year(p0, percent, aug, p, years = 0):\n if p0 < p:\n return nb_year(p0 + int(p0 * percent / 100) + aug, percent,... | {"fn_name": "nb_year", "inputs": [[1500, 5, 100, 5000], [1500000, 2.5, 10000, 2000000], [1500000, 0.25, 1000, 2000000], [1500000, 0.25, -1000, 2000000], [1500000, 0.25, 1, 2000000], [1500000, 0.0, 10000, 2000000]], "outputs": [[15], [10], [94], [151], [116], [50]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,716 |
def nb_year(p0, percent, aug, p):
|
3ba88417db6ad015fcfb7b5e34d8e785 | UNKNOWN | # Task
N lamps are placed in a line, some are switched on and some are off. What is the smallest number of lamps that need to be switched so that on and off lamps will alternate with each other?
You are given an array `a` of zeros and ones - `1` mean switched-on lamp and `0` means switched-off.
Your task is to find ... | ["def lamps(a):\n n = sum(1 for i, x in enumerate(a) if x != i % 2)\n return min(n, len(a) - n)", "def lamps(a):\n return min(sum(1 for i, n in enumerate(a) if n == i % 2), sum(1 for i, n in enumerate(a) if n != i % 2))", "def lamps(a):\n case1c = 0\n case2c = 0\n for i in range(len(a)):\n if i %... | {"fn_name": "lamps", "inputs": [[[1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1]], [[1, 0, 1]], [[1, 0, 1, 0]], [[0, 1, 0, 1, 0]], [[1, 0, 1, 0, 0, 1, 0, 1]], [[1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0]]], "outputs": [[5], [0], [0], [0], [4], [5]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,992 |
def lamps(a):
|
30b6c79ed53021e97d7357de65bb53d6 | UNKNOWN | A population of bears consists of black bears, brown bears, and white bears.
The input is an array of two elements.
Determine whether the offspring of the two bears will return `'black'`, `'brown'`, `'white'`, `'dark brown'`, `'grey'`, `'light brown'`, or `'unknown'`.
Elements in the the array will always be a stri... | ["DEFAULT = 'unknown'\nCOLORS = {'black'+'brown': 'dark brown',\n 'black'+'white': 'grey',\n 'brown'+'white': 'light brown'}\n\ndef bear_fur(bears):\n b1,b2 = sorted(bears)\n return b1 if b1==b2 else COLORS.get(b1+b2, DEFAULT)\n", "def bear_fur(bears):\n return {('black', 'black') : 'blac... | {"fn_name": "bear_fur", "inputs": [[["black", "black"]], [["white", "white"]], [["brown", "brown"]], [["black", "brown"]], [["black", "white"]], [["white", "brown"]], [["pink", "black"]]], "outputs": [["black"], ["white"], ["brown"], ["dark brown"], ["grey"], ["light brown"], ["unknown"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,032 |
def bear_fur(bears):
|
1aad64b8894cf1816a03fd7d324988c1 | UNKNOWN | In this Kata you are a game developer and have programmed the #1 MMORPG(Massively Multiplayer Online Role Playing Game) worldwide!!! Many suggestions came across you to make the game better, one of which you are interested in and will start working on at once.
Players in the game have levels from 1 to 170, XP(short fo... | ["def xp_to_target_lvl(*args):\n if len(args) < 2:\n return 'Input is invalid.'\n \n current_xp, target_lvl = args\n \n if not isinstance(target_lvl, int):\n return 'Input is invalid.'\n \n if not (0 < target_lvl < 171):\n return 'Input is invalid.'\n \n if current_xp... | {"fn_name": "xp_to_target_lvl", "inputs": [[0, 5], [12345, 17], [313, 2], [832696988485, 170], [769832696988484, 170], [10395, 11], [31428, "47"], [1, 171], [7392984749, 900], [123, 0], [-987654321, 99], [999999, [101]], [10396, 11], [0, 1], [2017, 4], [769832696988485, 170]], "outputs": [[1808], [29535], [1], [7690000... | INTRODUCTORY | PYTHON3 | CODEWARS | 6,251 |
def xp_to_target_lvl(current_xp=None, target_lvl=None):
|
85b7f2a10bd6a46a521023d94c9b957d | UNKNOWN | Timothy (age: 16) really likes to smoke. Unfortunately, he is too young to buy his own cigarettes and that's why he has to be extremely efficient in smoking.
It's now your task to create a function that calculates how many cigarettes Timothy can smoke out of the given amounts of `bars` and `boxes`:
- a bar has 10 box... | ["def start_smoking(bars, boxes):\n return int(22.5 * (10 * bars + boxes) - 0.5)", "def start_smoking(bars, boxes):\n return ((10 * bars + boxes) * 90 - bool(bars + boxes)) // 4", "def start_smoking(bars,boxes):\n total = bars * 10 * 18 + boxes * 18\n n = total\n while total >= 1: \n total /= 5\n ... | {"fn_name": "start_smoking", "inputs": [[0, 1], [1, 0], [1, 1]], "outputs": [[22], [224], [247]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,005 |
def start_smoking(bars,boxes):
|
8f2b7bcd7e180f7acdff32b2ace99fc1 | UNKNOWN | Find the closest prime number under a certain integer ```n``` that has the maximum possible amount of even digits.
For ```n = 1000```, the highest prime under ```1000``` is ```887```, having two even digits (8 twice)
Naming ```f()```, the function that gives that prime, the above case and others will be like the foll... | ["from bisect import bisect_left as bisect\n\nn = 5000000\nsieve, PED, PED_DATA = [0]*((n>>1)+1), [], []\nfor i in range(3, n+1, 2):\n if not sieve[i>>1]:\n for j in range(i**2>>1, (n+1)>>1, i): sieve[j] = 1\n s = str(i)\n nEveD = sum(s.count(d) for d in \"02468\")\n if nEveD:\n ... | {"fn_name": "f", "inputs": [[1000], [10000], [500], [487]], "outputs": [[887], [8887], [487], [467]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 5,625 |
def f(n):
|
24212bad088fc4d24da53129fb217c75 | UNKNOWN | Given a number, write a function to output its reverse digits. (e.g. given 123 the answer is 321)
Numbers should preserve their sign; i.e. a negative number should still be negative when reversed.
### Examples
```
123 -> 321
-456 -> -654
1000 -> 1
``` | ["def reverse_number(n):\n \"\"\"\n Reverse a number, preserve negative sign\n \"\"\"\n s = str(n)\n ret = int(\"-{}\".format(s[:0:-1]) if \"-\" in s else s[::-1])\n return ret", "def reverse_number(n):\n rev = 0\n temp = n\n dig = 0\n if( n < 0):\n n = abs(n)\n while(n > 0):\n ... | {"fn_name": "reverse_number", "inputs": [[123], [-123], [1000], [4321234], [5], [0], [98989898]], "outputs": [[321], [-321], [1], [4321234], [5], [0], [89898989]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 17,095 |
def reverse_number(n):
|
a412fe6099e8cc8e96d099622aed2d0d | UNKNOWN | Hello everyone.
I have a simple challenge for you today. In mathematics, the formula for finding the sum to infinity of a geometric sequence is:
**ONLY IF** `-1 < r < 1`
where:
* `a` is the first term of the sequence
* `r` is the common ratio of the sequence (calculated by dividing one term in the sequence by th... | ["def sum_to_infinity(sequence):\n return round(sequence[0]/(1-(sequence[1]/sequence[0])), 3) if abs(sequence[1]/sequence[0]) < 1 else \"No Solutions\"", "def sum_to_infinity(sequence):\n sequence = [float(x) for x in sequence]\n a, r = sequence[0], sequence[1] / sequence[0]\n if -1 < r < 1:\n return... | {"fn_name": "sum_to_infinity", "inputs": [[[1, 0.5, 0.25, 0.125]], [[250, 100, 40, 16]], [[21, 4.2, 0.84, 0.168]], [[5, -2.5, 1.25, -0.625]]], "outputs": [[2], [416.667], [26.25], [3.333]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,508 |
def sum_to_infinity(sequence):
|
2afabb831774bebd7511fd1ecdf1c2a6 | UNKNOWN | Given an array (or list or vector) of arrays (or, guess what, lists or vectors) of integers, your goal is to return the sum of a specific set of numbers, starting with elements whose position is equal to the main array length and going down by one at each step.
Say for example the parent array (etc, etc) has 3 sub-arr... | ["def elements_sum(arr, d=0):\n return sum(r[i] if i<len(r) else d for i,r in enumerate(reversed(arr)))", "def elements_sum(arr, d=0):\n a=len(arr) \n res=0\n for i in arr:\n if len(i)>=a:\n res+=i[a-1]\n else:\n res+=d\n a-=1\n return res", "def elements_sum... | {"fn_name": "elements_sum", "inputs": [[[[3, 2, 1, 0], [4, 6, 5, 3, 2], [9, 8, 7, 4]]], [[[3], [4, 6, 5, 3, 2], [9, 8, 7, 4]]], [[[3, 2, 1, 0], [4, 6, 5, 3, 2], []]], [[[3, 2, 1, 0], [4, 6, 5, 3, 2], []], 5], [[[3, 2], [4], []]]], "outputs": [[16], [15], [7], [12], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,619 |
def elements_sum(arr, d=0):
|
b96b81384380c91dbfb0a953ec179e81 | UNKNOWN | Write a simple parser that will parse and run Deadfish.
Deadfish has 4 commands, each 1 character long:
* `i` increments the value (initially `0`)
* `d` decrements the value
* `s` squares the value
* `o` outputs the value into the return array
Invalid characters should be ignored.
```python
parse("iiisdoso") ==> ... | ["def parse(data):\n value = 0\n res=[]\n for c in data:\n if c==\"i\": value+=1\n elif c==\"d\": value-=1\n elif c==\"s\": value*=value\n elif c==\"o\": res.append(value)\n return res", "def parse(data):\n arr = []\n value = 0\n for c in data:\n if c == \"i\":\n ... | {"fn_name": "parse", "inputs": [["ooo"], ["ioioio"], ["idoiido"], ["isoisoiso"], ["codewars"]], "outputs": [[[0, 0, 0]], [[1, 2, 3]], [[0, 1]], [[1, 4, 25]], [[0]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,011 |
def parse(data):
|
35641894764fccae30d8cdb54703e990 | UNKNOWN | Imagine there's a big cube consisting of n^3 small cubes. Calculate, how many small cubes are not visible from outside.
For example, if we have a cube which has 4 cubes in a row, then the function should return 8, because there are 8 cubes inside our cube (2 cubes in each dimension) | ["def not_visible_cubes(n):\n return max(n - 2, 0) ** 3", "def not_visible_cubes(n):\n return max(0,(n-2)) ** 3", "def not_visible_cubes(n):\n if n > 1:\n return (n-2)**3\n else:\n return 0", "def not_visible_cubes(n):\n if 0 <= n <= 2: return 0\n return (n - 2)**3", "import math\ndef no... | {"fn_name": "not_visible_cubes", "inputs": [[0], [1], [2], [3], [4], [5], [7], [12], [18], [10002]], "outputs": [[0], [0], [0], [1], [8], [27], [125], [1000], [4096], [1000000000000]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,012 |
def not_visible_cubes(n):
|
ff265649e6e1a3012b373fbd3e8d21e8 | UNKNOWN | # Task
Given array of integers `sequence` and some integer `fixedElement`, output the number of `even` values in sequence before the first occurrence of `fixedElement` or `-1` if and only if `fixedElement` is not contained in sequence.
# Input/Output
`[input]` integer array `sequence`
A non-empty array of positiv... | ["def even_numbers_before_fixed(s, f):\n return len([x for x in s[:s.index(f)] if x%2 == 0]) if f in s else -1", "def even_numbers_before_fixed(sequence, fixed_element):\n ans = 0\n for s in sequence:\n if s == fixed_element:\n return ans\n ans += (s % 2 == 0)\n return -1", "def eve... | {"fn_name": "even_numbers_before_fixed", "inputs": [[[1, 4, 2, 6, 3, 1], 6], [[2, 2, 2, 1], 3], [[2, 3, 4, 3], 3], [[1, 3, 4, 3], 3]], "outputs": [[2], [-1], [1], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,663 |
def even_numbers_before_fixed(sequence, fixed_element):
|
54b34315e11a42c24b84772d44437f29 | UNKNOWN | ## Description
You are a *Fruit Ninja*, your skill is cutting fruit. All the fruit will be cut in half by your knife. For example:
```
[ "apple", "pear", "banana" ] --> ["app", "le", "pe", "ar", "ban", "ana"]
```
As you see, all fruits are cut in half. You should pay attention to `"apple"`: if you cannot cu... | ["FRUIT_NAMES = {'blueberry', 'pear', 'durian', 'ginkgo', 'peach', 'apple', 'cantaloupe', 'fig', 'mangosteen', 'watermelon', 'pineapple', 'cherry', 'pomegranate', 'carambola', 'hawthorn', 'persimmon', 'apricot', 'plum', 'litchi', 'mango', 'jujube', 'lemon', 'orange', 'tomato', 'banana', 'coconut', 'grape', 'pitaya'}\nd... | {"fn_name": "cut_fruits", "inputs": [[["apple", "pear", "banana"]], [["apple", "pear", "banana", "bomb"]], [[]]], "outputs": [[["app", "le", "pe", "ar", "ban", "ana"]], [["app", "le", "pe", "ar", "ban", "ana", "bomb"]], [[]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 5,778 |
def cut_fruits(fruits):
|
d7e360425030ca997fbc82f73ae897e2 | UNKNOWN | Write a function called calculate that takes 3 values. The first and third values are numbers. The second value is a character. If the character is "+" , "-", "*", or "/", the function will return the result of the corresponding mathematical function on the two numbers. If the string is not one of the specified charact... | ["def calculate(num1, operation, num2): \n # your code here\n try :\n return eval(\"{} {} {}\".format(num1, operation, num2))\n except (ZeroDivisionError, SyntaxError):\n return None", "def calculate(num1, operation, num2):\n ops = {\"+\": (lambda x, y: x + y), \"-\": (lambda x, y: x - y), \"*... | {"fn_name": "calculate", "inputs": [[3.2, "+", 8], [3.2, "-", 8], [3.2, "/", 8], [3.2, "*", 8], [-3, "+", 0], [-3, "-", 0], [-2, "/", -2], [-3, "*", 0], [-3, "/", 0], [-3, "w", 0], [-3, "w", 1]], "outputs": [[11.2], [-4.8], [0.4], [25.6], [-3], [-3], [1], [0], [null], [null], [null]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,266 |
def calculate(num1, operation, num2):
|
f110b0501d3cfca302a4ef9705536d5e | UNKNOWN | Create a function that takes a string and an integer (`n`).
The function should return a string that repeats the input string `n` number of times.
If anything other than a string is passed in you should return `"Not a string"`
## Example
```
"Hi", 2 --> "HiHi"
1234, 5 --> "Not a string"
``` | ["def repeat_it(string,n):\n return string * n if isinstance(string,str) else 'Not a string'", "def repeat_it(string,n):\n if type(string) is not str:\n return 'Not a string'\n return string * n", "repeat_it = lambda s, m: s*m if type(s) is str else \"Not a string\"", "def repeat_it(s, n):\n return s... | {"fn_name": "repeat_it", "inputs": [["*", 3], ["Hello", 11], ["243624", 22], [[], 3], [24, 3], [true, 3], ["Hello", 0]], "outputs": [["***"], ["HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello"], ["2436242436242436242436242436242436242436242436242436242436242436242436242436242436242436242436242436242436242436242... | INTRODUCTORY | PYTHON3 | CODEWARS | 13,441 |
def repeat_it(string,n):
|
41bf9a5c8cf037f78d421e4788e9772a | UNKNOWN | Write a function that takes a single array as an argument (containing multiple strings and/or positive numbers and/or arrays), and returns one of four possible string values, depending on the ordering of the lengths of the elements in the input array:
Your function should return...
- “Increasing” - if the lengths of ... | ["def order_type(arr):\n if not arr : return 'Constant'\n arr = list( map(len, [str(elt) if type(elt)==int else elt for elt in arr] ))\n cmp =sorted(arr)\n if arr == [arr[0]]*len(arr) : s='Constant'\n elif arr == cmp : s='Increasing'\n elif arr == cmp[::-1] : s='Decreasing'\n else... | {"fn_name": "order_type", "inputs": [[[1, "b", ["p"], 2]], [[123, 1234, 12345, 123456]], [["a", "abc", "abcde", "ab"]], [[[1, 2, 3, 4], [5, 6, 7], [8, 9]]], [[1, 2, 3, 4, 56]], [[["ab", "cdef", "g"], ["hi", "jk", "lmnopq"], ["rst", "uv", "wx"], ["yz"]]], [[[1, 23, 456, 78910], ["abcdef", "ghijklmno", "pqrstuvwxy"], [[1... | INTRODUCTORY | PYTHON3 | CODEWARS | 3,541 |
def order_type(arr):
|
4452938ac724d7fa47b59e507cb46975 | UNKNOWN | `Description:`
Given an input array (`arr`) of positive integers, the objective is to return an output array where each index represents the amount of times an element appeared (frequency) in the input array.
More specifically, the element at each index of the output array will be an array (bucket) containing intege... | ["from collections import Counter\n\ndef bucketize(*arr):\n c = Counter(arr)\n c = {i: sorted([k for k, v in list(c.items()) if v == i]) for i in list(c.values())}\n return [c[e] if e in c else None for e in range(len(arr) + 1)]\n", "from collections import Counter\n\ndef bucketize(*a):\n D = {}\n for k,... | {"fn_name": "bucketize", "inputs": [[2, 2, 4, 4, 6, 6, 9, 9, 9, 9], [3, 3, 3, 3, 2], [5, 5, 5, 5, 5], [77, 3, 40, 40, 40], [16, 7, 5, 3, 6, 23]], "outputs": [[[null, null, [2, 4, 6], null, [9], null, null, null, null, null, null]], [[null, [2], null, null, [3], null]], [[null, null, null, null, null, [5]]], [[null, [3,... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,281 |
def bucketize(*arr):
|
e10aa6bc0fb4390a76f1f45e2fd18409 | UNKNOWN | You are given a list/array which contains only integers (positive and negative). Your job is to sum only the numbers that are the same and consecutive. The result should be one list.
Extra credit if you solve it in one line. You can assume there is never an empty list/array and there will always be an integer.
Same ... | ["from itertools import groupby\n\ndef sum_consecutives(s):\n return [sum(group) for c, group in groupby(s)]", "def sum_consecutives(s):\n prev = None\n x = []\n for i in s:\n if i == prev:\n x[-1] += i\n else:\n x.append(i)\n prev = i\n return x", "from itertoo... | {"fn_name": "sum_consecutives", "inputs": [[[1, 4, 4, 4, 0, 4, 3, 3, 1]], [[1, 1, 7, 7, 3]], [[-5, -5, 7, 7, 12, 0]], [[3, 3, 3, 3, 1]], [[2, 2, -4, 4, 5, 5, 6, 6, 6, 6, 6, 1]], [[1, 1, 1, 1, 1, 3]], [[1, -1, -2, 2, 3, -3, 4, -4]], [[0, 1, 1, 2, 2]]], "outputs": [[[1, 12, 0, 4, 6, 1]], [[2, 14, 3]], [[-10, 14, 12, 0]],... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,569 |
def sum_consecutives(s):
|
cad00c6cab7d1559476e660cfd4bb7ff | UNKNOWN | In this Kata, you will be given two strings `a` and `b` and your task will be to return the characters that are not common in the two strings.
For example:
```Haskell
solve("xyab","xzca") = "ybzc"
--The first string has 'yb' which is not in the second string.
--The second string has 'zc' which is not in the first s... | ["def solve(a,b):\n s = set(a)&set(b)\n return ''.join(c for c in a+b if c not in s)", "def solve(a,b):\n return \"\".join([c for c in a if not c in b]+[c for c in b if not c in a])", "def solve(a,b):\n unique=[]\n for i in a:\n if i not in b:\n unique.append(i)\n for i in b:\n ... | {"fn_name": "solve", "inputs": [["xyab", "xzca"], ["xyabb", "xzca"], ["abcd", "xyz"], ["xxx", "xzca"]], "outputs": [["ybzc"], ["ybbzc"], ["abcdxyz"], ["zca"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,441 |
def solve(a,b):
|
9303bdecc79e2bb61dcd2e243360fdff | UNKNOWN | You're looking through different hex codes, and having trouble telling the difference between #000001 and #100000
We need a way to tell which is red, and which is blue!
That's where you create ```hex_color()```!
It should read an RGB input, and return whichever value (red, blue, or green) is of greatest concentr... | ["colors = {\n (1, 0, 0): 'red',\n (0, 1, 0): 'green',\n (0, 0, 1): 'blue',\n (1, 0, 1): 'magenta',\n (1, 1, 0): 'yellow',\n (0, 1, 1): 'cyan',\n (1, 1, 1): 'white',\n}\n\ndef hex_color(codes):\n codes = codes or '0 0 0'\n items = [int(c) for c in codes.split()]\n m = max(items)\n retur... | {"fn_name": "hex_color", "inputs": [[""], ["000 000 000"], ["121 245 255"], ["027 100 100"], ["021 021 021"], ["255 000 000"], ["000 147 000"], ["212 103 212"], ["101 101 092"]], "outputs": [["black"], ["black"], ["blue"], ["cyan"], ["white"], ["red"], ["green"], ["magenta"], ["yellow"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,026 |
def hex_color(codes):
|
f85c55302146608e0b34f35f657db0bb | UNKNOWN | Our football team finished the championship.
The result of each match look like "x:y". Results of all matches are recorded in the collection.
For example:
```["3:1", "2:2", "0:1", ...]```
Write a function that takes such collection and counts the points of our team in the championship.
Rules for counting points for e... | ["def points(games):\n count = 0\n for score in games:\n res = score.split(':')\n if res[0]>res[1]:\n count += 3\n elif res[0] == res[1]:\n count += 1\n return count", "def points(a):\n return sum((x >= y) + 2 * (x > y) for x, y in (s.split(\":\") for s in a))", "d... | {"fn_name": "points", "inputs": [[["1:0", "2:0", "3:0", "4:0", "2:1", "3:1", "4:1", "3:2", "4:2", "4:3"]], [["1:1", "2:2", "3:3", "4:4", "2:2", "3:3", "4:4", "3:3", "4:4", "4:4"]], [["0:1", "0:2", "0:3", "0:4", "1:2", "1:3", "1:4", "2:3", "2:4", "3:4"]], [["1:0", "2:0", "3:0", "4:0", "2:1", "1:3", "1:4", "2:3", "2:4", ... | INTRODUCTORY | PYTHON3 | CODEWARS | 11,932 |
def points(games):
|
f8267498539980210317f7d649142a40 | UNKNOWN | I've got a crazy mental illness.
I dislike numbers a lot. But it's a little complicated:
The number I'm afraid of depends on which day of the week it is...
This is a concrete description of my mental illness:
Monday --> 12
Tuesday --> numbers greater than 95
Wednesday --> 34
Thursday --> 0
Friday -->... | ["def am_I_afraid(day,num):\n return {\n 'Monday': num == 12,\n 'Tuesday': num > 95,\n 'Wednesday': num == 34,\n 'Thursday': num == 0,\n 'Friday': num % 2 == 0,\n 'Saturday': num == 56,\n 'Sunday': num == 666 or num == -666,\n }[day]\n", "afraid = {\n 'Monday'... | {"fn_name": "am_I_afraid", "inputs": [["Monday", 13], ["Monday", 12], ["Tuesday", 0], ["Tuesday", 100], ["Tuesday", 95], ["Wednesday", 35], ["Wednesday", 34], ["Thursday", 2], ["Thursday", 0], ["Friday", 5], ["Friday", 4], ["Saturday", 55], ["Saturday", 56], ["Sunday", 55], ["Sunday", 666], ["Sunday", -666]], "outputs"... | INTRODUCTORY | PYTHON3 | CODEWARS | 3,463 |
def am_I_afraid(day,num):
|
16fb1d946f0fc044c99a5121412cfe46 | UNKNOWN | The hamming distance of two equal-length strings is the number of positions, in which the two string differ. In other words, the number of character substitutions required to transform one string into the other.
For this first Kata, you will write a function ```hamming_distance(a, b)``` with two equal-length strings ... | ["def hamming_distance(a, b):\n return sum(c != d for c, d in zip(a, b))\n", "def hamming_distance(a, b): return sum(ch1 != ch2 for ch1, ch2 in zip(a, b))", "def hamming_distance(a, b):\n result=0\n for i in range(len(a)):\n if a[i]!=b[i]:\n result+=1;\n return result;\n", "def hamming_dis... | {"fn_name": "hamming_distance", "inputs": [["100101", "101001"], ["1010", "0101"], ["100101011011010010010", "101100010110010110101"]], "outputs": [[2], [4], [9]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 883 |
def hamming_distance(a, b):
|
cc4d93a167d76e8327a0beadc3213e97 | UNKNOWN | Given an array of one's and zero's that represents a positive binary number convert the number to two's complement value.
Two's complement is the way most computers represent positive or negative integers. The most significant bit is negative.
Examples:
-8 4 2 1
[1,1,1,1] = -1
[1,0,0,0] = -8
[1,1,0,1] = -3
To ... | ["def positive_to_negative(binary):\n return [1 - d if 1 in binary[i:] else d for i, d in enumerate(binary, 1)]\n", "def positive_to_negative(b):\n last = next((i for i in range(len(b) - 1, -1, -1) if b[i]), 0)\n return [1 - d for d in b[:last]] + b[last:]", "def positive_to_negative(arr):\n flip = [0 if n ... | {"fn_name": "positive_to_negative", "inputs": [[[0, 0, 0, 0]], [[0, 0, 1, 0]], [[0, 0, 1, 1]], [[0, 1, 0, 0]]], "outputs": [[[0, 0, 0, 0]], [[1, 1, 1, 0]], [[1, 1, 0, 1]], [[1, 1, 0, 0]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,208 |
def positive_to_negative(binary):
|
5bfbd1ae7c417b3a0e2a74f1887e1381 | UNKNOWN | Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral.
Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost digit and skip... | ["def solution(roman):\n dict = {\n \"M\": 1000,\n \"D\": 500,\n \"C\": 100,\n \"L\": 50,\n \"X\": 10,\n \"V\": 5,\n \"I\": 1\n }\n\n last, total = 0, 0\n for c in list(roman)[::-1]:\n if last == 0:\n total += dict[c]\n elif last > di... | {"fn_name": "solution", "inputs": [["XXI"], ["I"], ["IV"], ["MMVIII"], ["MDCLXVI"]], "outputs": [[21], [1], [4], [2008], [1666]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 101,707 |
def solution(roman):
|
fb6b977a8713db52be416090680d2511 | UNKNOWN | You get any card as an argument. Your task is to return a suit of this card.
Our deck (is preloaded):
```python
DECK = ['2S','3S','4S','5S','6S','7S','8S','9S','10S','JS','QS','KS','AS',
'2D','3D','4D','5D','6D','7D','8D','9D','10D','JD','QD','KD','AD',
'2H','3H','4H','5H','6H','7H','8H','9H','10H','JH... | ["def define_suit(card):\n d = {'C': 'clubs', 'S':'spades', 'D':'diamonds','H':'hearts'}\n return d[card[-1]]\n", "def define_suit(card):\n return {'C':'clubs', 'S':'spades', 'D':'diamonds', 'H':'hearts'}[card[-1]]", "def define_suit(card):\n return {'C':'clubs','D':'diamonds','H':'hearts','S':'spades'}[car... | {"fn_name": "define_suit", "inputs": [["3C"], ["QS"], ["9D"], ["JH"]], "outputs": [["clubs"], ["spades"], ["diamonds"], ["hearts"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 18,687 |
def define_suit(card):
|
2e74b5aa21a23ebe0f79fd70c1da5bdf | UNKNOWN | You are given a string of words (x), for each word within the string you need to turn the word 'inside out'. By this I mean the internal letters will move out, and the external letters move toward the centre.
If the word is even length, all letters will move. If the length is odd, you are expected to leave the 'middl... | ["import re\n\ndef inside_out(s):\n return re.sub(r'\\S+', lambda m: inside_out_word(m.group()), s)\n\ndef inside_out_word(s):\n i, j = len(s) // 2, (len(s) + 1) // 2\n return s[:i][::-1] + s[i:j] + s[j:][::-1]", "def swap(word):\n m = len(word) // 2\n if len(word) % 2 == 0:\n return word[:m][::-1... | {"fn_name": "inside_out", "inputs": [["man i need a taxi up to ubud"], ["what time are we climbing up the volcano"], ["take me to semynak"], ["massage yes massage yes massage"], ["take bintang and a dance please"]], "outputs": [["man i ende a atix up to budu"], ["hwta item are we milcgnib up the lovcona"], ["atek me to... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,701 |
def inside_out(s):
|
776a5de18027904dc26b2a868a7e8f0c | UNKNOWN | Well met with Fibonacci bigger brother, AKA Tribonacci.
As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won't get to hear non-native Italian speakers trying to pronounce it :(
... | ["def tribonacci(signature, n):\n res = signature[:n]\n for i in range(n - 3): res.append(sum(res[-3:]))\n return res", "def tribonacci(signature,n):\n while len(signature) < n:\n signature.append(sum(signature[-3:]))\n \n return signature[:n]", "def tribonacci(signature, n):\n s = signature.copy(... | {"fn_name": "tribonacci", "inputs": [[[1, 1, 1], 10], [[0, 0, 1], 10], [[0, 1, 1], 10], [[1, 0, 0], 10], [[0, 0, 0], 10], [[1, 2, 3], 10], [[3, 2, 1], 10], [[1, 1, 1], 1], [[300, 200, 100], 0], [[0.5, 0.5, 0.5], 30]], "outputs": [[[1, 1, 1, 3, 5, 9, 17, 31, 57, 105]], [[0, 0, 1, 1, 2, 4, 7, 13, 24, 44]], [[0, 1, 1, 2, ... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,667 |
def tribonacci(signature,n):
|
1d5586b3a4acdae746616e79af3b15aa | UNKNOWN | When you want to get the square of a binomial of two variables x and y, you will have:
`$(x+y)^2 = x^2 + 2xy + y ^2$`
And the cube:
`$(x+y)^3 = x^3 + 3x^2y + 3xy^2 +y^3$`
It is known from many centuries ago that for an exponent n, the result of a binomial x + y raised to the n-th power is:
Or using the sumation no... | ["def f(n):\n return [2**i for i in range(n+1)]+[(2**(n+1))-1]", "def f(n):\n return [1 << i for i in range(n+1)] + [(1 << (n+1)) - 1]", "def f(n):\n result = [1]\n for i in range(n):\n result.append(result[-1]*2)\n result.append(sum(result))\n return result", "f=lambda n:[2**x for x in range(n... | {"fn_name": "f", "inputs": [[0], [1], [2], [3], [6], [10]], "outputs": [[[1, 1]], [[1, 2, 3]], [[1, 2, 4, 7]], [[1, 2, 4, 8, 15]], [[1, 2, 4, 8, 16, 32, 64, 127]], [[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2047]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 950 |
def f(n):
|
b23451659eb9835174e0d391d95cad7c | UNKNOWN | Share price
===========
You spent all your saved money to buy some shares.
You bought it for `invested`, and want to know how much it's worth, but all the info you can quickly get are just the change the shares price made in percentages.
Your task:
----------
Write the function `sharePrice()` that calculates, and re... | ["def share_price(invested, changes):\n for change in changes:\n invested = invested * (100 + change) / 100.0\n return format(invested, '.2f')", "def share_price(invested, changes):\n sum=float(invested)\n for i in changes:\n sum=sum+(sum/100*i)\n return str('{:.2f}'.format(float(sum)))", "... | {"fn_name": "share_price", "inputs": [[100, []], [100, [-50, 50]], [100, [-50, 100]], [100, [-20, 30]], [1000, [0, 2, 3, 6]]], "outputs": [["100.00"], ["75.00"], ["100.00"], ["104.00"], ["1113.64"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,076 |
def share_price(invested, changes):
|
bf1202b2a6bdbc70bb5eb6c1b5285bf5 | UNKNOWN | Create an identity matrix of the specified size( >= 0).
Some examples:
```
(1) => [[1]]
(2) => [ [1,0],
[0,1] ]
[ [1,0,0,0,0],
[0,1,0,0,0],
(5) => [0,0,1,0,0],
[0,0,0,1,0],
[0,0,0,0,1] ]
``` | ["def get_matrix(n):\n return [[1 if i==j else 0 for i in range(n)] for j in range(n)]", "import numpy\ndef get_matrix(n):\n return numpy.eye(n, dtype=int).tolist()", "get_matrix=lambda n: [[int(i==j) for j in range(n)] for i in range(n)]", "def get_matrix(n):\n return [[int(i == j) for j in range(n)] for i i... | {"fn_name": "get_matrix", "inputs": [[0], [1], [2], [3], [5]], "outputs": [[[]], [[[1]]], [[[1, 0], [0, 1]]], [[[1, 0, 0], [0, 1, 0], [0, 0, 1]]], [[[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 992 |
def get_matrix(n):
|
8e9f88863fa6692f5b616c26b6d52c83 | UNKNOWN | In your class, you have started lessons about geometric progression.
Since you are also a programmer, you have decided to write a function that will print first `n` elements of the sequence with the given constant `r` and first element `a`.
Result should be separated by comma and space.
### Example
```python
geometr... | ["def geometric_sequence_elements(a, r, n):\n return ', '.join(str(a * r ** i) for i in range(n))\n", "def geometric_sequence_elements(a, r, n):\n l = []\n for _ in range(n):\n l.append(str(a))\n a *= r\n return \", \".join(l)\n", "def geometric_sequence_elements(a, r, n):\n return \", \".j... | {"fn_name": "geometric_sequence_elements", "inputs": [[2, 3, 5], [2, 2, 10], [1, -2, 10]], "outputs": [["2, 6, 18, 54, 162"], ["2, 4, 8, 16, 32, 64, 128, 256, 512, 1024"], ["1, -2, 4, -8, 16, -32, 64, -128, 256, -512"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,329 |
def geometric_sequence_elements(a, r, n):
|
b693103876dd194b61164647313598e8 | UNKNOWN | Create a function that accepts 3 inputs, a string, a starting location, and a length. The function needs to simulate the string endlessly repeating in both directions and return a substring beginning at the starting location and continues for length.
Example:
```python
endless_string('xyz', -23, 6) == 'yzxyzx'
```
To... | ["from itertools import cycle, islice\n\ndef endless_string(string, start, length):\n i = (start + (length + 1 if length < 0 else 0)) % len(string)\n return ''.join(islice(cycle(string), i, i + abs(length)))", "from itertools import cycle, islice\n\ndef endless_string(stg, i, l):\n i = min(i, i+l) % len(stg) +... | {"fn_name": "endless_string", "inputs": [["xyz", -23, 6], ["xyz", 0, 4], ["xyz", 19, 2], ["xyz", -4, -4], ["abcdefghijklmnopqrstuvwxyz", 29, 1], ["Hello! How are you?", -14, 27], ["1x2x3x4x", 1532, 100], ["1x2x3x4x", -1532, -100], ["112233", 0, 0], ["112233", -1, 0], ["112233", 15824, 0]], "outputs": [["yzxyzx"], ["xyz... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,508 |
def endless_string(string, start, length):
|
b578e70a12366a00fda84eee4b114c20 | UNKNOWN | Your task is to validate rhythm with a meter.
_________________________________________________
Rules:
1. Rhythmic division requires that in one whole note (1) there are two half notes (2) or four quarter notes (4) or eight eighth notes (8).
Examples: 1 = 2 + 2, 1 = 4 + 4 + 4 + 4 ...
Note that: 2 = 4 + 4, 4 = 8 + 8... | ["def is_valid_bar(bar, meter):\n total = 0\n for n in bar:\n n = int(n)\n if n & (n - 1):\n return False\n total += 1.0 / n\n return total == meter\n\ndef validate_rhythm(meter, score):\n n, d = meter\n if d & (d - 1):\n return \"Invalid rhythm\"\n bars = score.... | {"fn_name": "validate_rhythm", "inputs": [[[8, 8], "1|22|4444|88888888"], [[4, 4], "1|22|4444|88888888"], [[2, 2], "1|22|4444|88888888"], [[1, 1], "1|22|4444|88888888"], [[3, 4], "24|444|888888"], [[4, 8], "2|44|8888"], [[2, 4], "2|44|8888"], [[1, 2], "2|44|8888"], [[10, 8], "14|444488|888824"], [[6, 4], "222|444444|88... | INTRODUCTORY | PYTHON3 | CODEWARS | 6,057 |
def validate_rhythm(meter, score):
|
da710fbb1fa49c253b721a3f1095c495 | UNKNOWN | Complete the function/method so that it takes CamelCase string and returns the string in snake_case notation. Lowercase characters can be numbers. If method gets number, it should return string.
Examples:
``` javascript
// returns test_controller
toUnderscore('TestController');
// returns movies_and_books
toUndersc... | ["import re\n\ndef to_underscore(string):\n return re.sub(r'(.)([A-Z])', r'\\1_\\2', str(string)).lower() \n", "def to_underscore(string):\n string = str(string)\n camel_case = string[0].lower()\n for c in string[1:]:\n camel_case += '_{}'.format(c.lower()) if c.isupper() else c\n return camel_... | {"fn_name": "to_underscore", "inputs": [["TestController"], ["ThisIsBeautifulDay"], ["Am7Days"], ["My3CodeIs4TimesBetter"], [5]], "outputs": [["test_controller"], ["this_is_beautiful_day"], ["am7_days"], ["my3_code_is4_times_better"], ["5"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,439 |
def to_underscore(string):
|
eed742fda4d1b5e989af5b2a0b96aac6 | UNKNOWN | Write a function that will check whether the permutation of an input string is a palindrome. Bonus points for a solution that is efficient and/or that uses _only_ built-in language functions. Deem yourself **brilliant** if you can come up with a version that does not use _any_ function whatsoever.
# Example
`madam... | ["def permute_a_palindrome (input): \n return sum( input.count(c)%2 for c in set(input) ) < 2\n", "def permute_a_palindrome (txt): \n return len([txt.count(c) for c in txt if txt.count(c) % 2]) < 2\n", "def permute_a_palindrome(stg): \n return sum(stg.count(c) % 2 for c in set(stg)) == len(stg) % 2\n", "def perm... | {"fn_name": "permute_a_palindrome", "inputs": [["a"], ["aa"], ["baa"], ["aab"], ["baabcd"], ["racecars"], ["abcdefghba"], [""]], "outputs": [[true], [true], [true], [true], [false], [false], [false], [true]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,130 |
def permute_a_palindrome(stg):
|
ae19d63f4c48693d8d50cf0dcdcc85ab | UNKNOWN | Consider the following series:
`0,1,2,3,4,5,6,7,8,9,10,22,11,20,13,24...`There is nothing special between numbers `0` and `10`.
Let's start with the number `10` and derive the sequence. `10` has digits `1` and `0`. The next possible number that does not have a `1` or a `0` is `22`. All other numbers between `10` and... | ["masks = [0] * 10\nfor i in range(10 ** 4):\n for c in str(i):\n masks[int(c)] |= 1 << i\n\ndef find_num(n):\n seq, x = 1, 0\n for j in range(n):\n M = seq\n for m in masks:\n if x & m:\n M |= m\n x = ~M & (M+1)\n seq |= x\n return x.bit_length()... | {"fn_name": "find_num", "inputs": [[1], [5], [11], [100], [500]], "outputs": [[1], [5], [22], [103], [476]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 5,438 |
def find_num(n):
|
1752251612f4cb87ea24a47f030fb960 | UNKNOWN | You will be given an array of numbers.
For each number in the array you will need to create an object.
The object key will be the number, as a string. The value will be the corresponding character code, as a string.
Return an array of the resulting objects.
All inputs will be arrays of numbers. All character codes... | ["def num_obj(s):\n return [{str(i) : chr(i)} for i in s]", "def num_obj(s):\n return [{str(n) : chr(n)} for n in s]", "def num_obj(s):\n return [{str(nb) : chr(nb)} for nb in s]", "def num_obj(s):\n return [{str(a): chr(a)} for a in s]", "def num_obj(s):\n return [{str(c): chr(c)} for c in s]", "def num... | {"fn_name": "num_obj", "inputs": [[[118, 117, 120]], [[101, 121, 110, 113, 113, 103]], [[118, 103, 110, 109, 104, 106]], [[107, 99, 110, 107, 118, 106, 112, 102]], [[100, 100, 116, 105, 117, 121]]], "outputs": [[[{"118": "v"}, {"117": "u"}, {"120": "x"}]], [[{"101": "e"}, {"121": "y"}, {"110": "n"}, {"113": "q"}, {"113... | INTRODUCTORY | PYTHON3 | CODEWARS | 666 |
def num_obj(s):
|
4bba1b6ead1caaaed9f83f165ba1cc2c | UNKNOWN | In this Kata you must convert integers numbers from and to a negative-base binary system.
Negative-base systems can accommodate all the same numbers as standard place-value systems, but both positive and negative numbers are represented without the use of a minus sign (or, in computer representation, a sign bit); this... | ["def int_to_negabinary(i):\n ds = []\n while i != 0:\n ds.append(i & 1)\n i = -(i >> 1)\n return ''.join(str(d) for d in reversed(ds)) if ds else '0'\n \ndef negabinary_to_int(s):\n i = 0\n for c in s:\n i = -(i << 1) + int(c)\n return i", "def int_to_negabinary(i):\n i, s ... | {"fn_name": "int_to_negabinary", "inputs": [[0], [6], [-6], [45], [-45], [4587], [-4587], [65535], [65536], [-65536], [2147483648], [-2147483648]], "outputs": [["0"], ["11010"], ["1110"], ["1111101"], ["11010111"], ["1011000111111"], ["11001000010101"], ["10000000000000011"], ["10000000000000000"], ["110000000000000000... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,567 |
def int_to_negabinary(i):
|
2156b0fca2d3005b8cc51f29eb84e89e | UNKNOWN | Your task is to find the number couple with the greatest difference from a given array of number-couples.
All number couples will be given as strings and all numbers in them will be positive integers.
For instance: ['56-23','1-100']; in this case, you should identify '1-100' as the number couple with the greatest ... | ["def diff(arr):\n r = arr and max(arr, key = lambda x : abs(eval(x)))\n return bool(arr and eval(r)) and r", "def diff(arr):\n r = [abs(eval(s)) for s in arr]\n return arr[r.index(max(r))] if r and max(r) else False\n", "def diff(arr):\n r = [abs(int(w.split('-')[0])-int(w.split('-')[1])) for w in arr]\... | {"fn_name": "diff", "inputs": [[["43-45", "1021-55", "000-18888", "92-34", "76-32", "99-1", "1020-54"]], [["1-2", "2-4", "5-7", "8-9", "44-45"]], [["1-1000", "2-1000", "100-67", "98-45", "8-9"]], [["33-33", "77-77"]], [["23-67", "67-23", "88-88", "45-46"]], [["45896-2354", "4654-556767", "2455-423522", "3455-355", "34-... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,139 |
def diff(arr):
|
493d404dd3a950e1fae8b580d02a2c37 | UNKNOWN | Make a program that takes a value (x) and returns "Bang" if the number is divisible by 3, "Boom" if it is divisible by 5, "BangBoom" if it divisible by 3 and 5, and "Miss" if it isn't divisible by any of them.
Note: Your program should only return one value
Ex: Input: 105 --> Output: "BangBoom"
Ex: Input: 9 --> Output... | ["def multiple(x):\n return 'Bang' * (x % 3 == 0) + 'Boom' * (x % 5 == 0) or 'Miss'", "def multiple(x):\n if x % 15 == 0: return \"BangBoom\"\n if x % 5 == 0: return \"Boom\"\n if x % 3 == 0: return \"Bang\"\n return \"Miss\"", "def multiple(x):\n val = ''\n if x % 3 == 0:\n val += 'Bang'\n ... | {"fn_name": "multiple", "inputs": [[30], [3], [98], [65], [23], [15], [4], [2], [45], [90], [21], [7], [6], [10003823], [41535], [712], [985], [164523]], "outputs": [["BangBoom"], ["Bang"], ["Miss"], ["Boom"], ["Miss"], ["BangBoom"], ["Miss"], ["Miss"], ["BangBoom"], ["BangBoom"], ["Bang"], ["Miss"], ["Bang"], ["Miss"]... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,327 |
def multiple(x):
|
e27dde411f659c1fae2db98f90455458 | UNKNOWN | Complete the function that takes a string as an input, and return a list of all the unpaired characters (i.e. they show up an odd number of times in the string), in the order they were encountered as an array.
In case of multiple appearances to choose from, take the last occurence of the unpaired character.
**Notes:... | ["from collections import Counter\n\ndef odd_one_out(s):\n d = Counter(reversed(s))\n return [x for x in d if d[x] % 2][::-1]", "def odd_one_out(s):\n d = {}\n for i in s:\n if i in d:\n del d[i]\n else:\n d[i] = None\n return list(d.keys())", "from collections import ... | {"fn_name": "odd_one_out", "inputs": [["Hello World"], ["Codewars"], ["woowee"], ["wwoooowweeee"], ["racecar"], ["Mamma"], ["Mama"], ["\u00bc x 4 = 1"], ["\u00bc x 4 = 1 and \u00bd x 4 = 2"]], "outputs": [[["H", "e", " ", "W", "r", "l", "d"]], [["C", "o", "d", "e", "w", "a", "r", "s"]], [[]], [[]], [["e"]], [["M"]], [[... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,744 |
def odd_one_out(s):
|
f53ae9147275de4ae12331111b4916f3 | UNKNOWN | Write a function that returns the index of the first occurence of the word "Wally". "Wally" must not be part of another word, but it can be directly followed by a punctuation mark. If no such "Wally" exists, return -1.
Examples:
"Wally" => 0
"Where's Wally" => 8
"Where's Waldo" => -1
"DWally Wallyd .Wally" => -... | ["from re import compile\n\ndef wheres_wally(string):\n m = compile('(^|.*[\\s])(Wally)([\\.,\\s\\']|$)').match(string)\n return m.start(2) if m else -1", "import re\n\ndef wheres_wally(string):\n return next((m.start() for m in re.finditer(r'((?<= )W|^W)ally\\b', string)), -1)", "from re import search\ndef wh... | {"fn_name": "wheres_wally", "inputs": [[""], ["WAlly"], ["wAlly"], ["DWally"], [".Wally"], ["Wallyd"], ["wally mollyWally Wallybrolly 'Wally"], ["Walley ,Wally -Wally ;Wally +Wally :Wally"], ["Walley Wally, Wally- Wally: Wally+ Wally:"], ["12Wally Wally01 W.ally"], ["Where's Waldo"], ["Wally"], ["Wally Wally"], ["W all... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,683 |
def wheres_wally(string):
|
231ce720426055daac53ded7049eee95 | UNKNOWN | Rick wants a faster way to get the product of the largest pair in an array. Your task is to create a performant solution to find the product of the largest two integers in a unique array of positive numbers. All inputs will be valid.
Passing [2, 6, 3] should return 18, the product of [6, 3].
```Disclaimer: Mr. Roll wi... | ["import heapq\ndef max_product(a):\n x = heapq.nlargest(2,a)\n return x[0]*x[1]", "def max_product(a): \n first_max = 0\n second_max = 0\n for x in a:\n if x > first_max:\n second_max = first_max\n first_max = x\n elif x > second_max:\n second_max = x\n ... | {"fn_name": "max_product", "inputs": [[[56, 335, 195, 443, 6, 494, 252]], [[154, 428, 455, 346]], [[39, 135, 47, 275, 37, 108, 265, 457, 2, 133, 316, 330, 153, 253, 321, 411]], [[136, 376, 10, 146, 105, 63, 234]], [[354, 463, 165, 62, 472, 53, 347, 293, 252, 378, 420, 398, 255, 89]], [[346, 446, 26, 425, 432, 349, 123,... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,189 |
def max_product(a):
|
ec0a745d75630b47c5c7c2ea70ac0f6c | UNKNOWN | Vasya wants to climb up a stair of certain amount of steps (Input parameter 1). There are 2 simple rules that he has to stick to.
1. Vasya can climb 1 or 2 steps at each move.
2. Vasya wants the number of moves to be a multiple of a certain integer. (Input parameter 2).
### Task:
What is the `MINIMAL` number of moves... | ["def numberOfSteps(steps, m):\n if (steps < m):\n return -1\n \n \n if (steps % 2 == 0 and (steps / 2) % m == 0):\n return (steps / 2)\n \n \n return (steps / 2) + m - ((steps / 2) % m)\n", "def numberOfSteps(steps, m):\n return next((n for n in range((steps+1)//2, steps+1) if n % m =... | {"fn_name": "numberOfSteps", "inputs": [[10, 2], [3, 5], [29, 7], [2, 2], [1, 2], [10000, 2], [10000, 3], [10000, 10], [9999, 3], [9999, 2], [9999, 10], [9999, 9], [18, 10], [19, 10], [20, 10], [7688, 5], [4608, 5], [3979, 2], [5, 2]], "outputs": [[6], [-1], [21], [2], [-1], [5000], [5001], [5000], [5001], [5000], [500... | INTRODUCTORY | PYTHON3 | CODEWARS | 972 |
def numberOfSteps(steps, m):
|
7d252fc161256c1e8c0c7f478f3f0786 | UNKNOWN | **DESCRIPTION:**
Your strict math teacher is teaching you about right triangles, and the Pythagorean Theorem --> a^2 + b^2 = c^2 whereas a and b are the legs of the right triangle and c is the hypotenuse of the right triangle. On the test however, the question asks: What are the possible integer lengths for the othe... | ["def side_len(x, y):\n return [z for z in range(abs(x-y)+1,x+y) if z*z not in (abs(x*x-y*y), x*x+y*y)]", "def side_len(x, y):\n return [i for i in range(abs(x-y)+1, abs(x+y)) if i != (x*x+y*y)**0.5 and i != abs(y*y-x*x)**0.5]", "def side_len(x, y):\n return [i for i in range(y-x+1,x+y) if abs(i**2-y**2) != x*... | {"fn_name": "side_len", "inputs": [[1, 1], [3, 4], [4, 6], [5, 12], [8, 10]], "outputs": [[[1]], [[2, 3, 4, 6]], [[3, 4, 5, 6, 7, 8, 9]], [[8, 9, 10, 11, 12, 14, 15, 16]], [[3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,617 |
def side_len(x, y):
|
a418fa1decaad2980324f3cb8080087a | UNKNOWN | In this Kata, you will be given an integer `n` and your task will be to return `the largest integer that is <= n and has the highest digit sum`.
For example:
```
solve(100) = 99. Digit Sum for 99 = 9 + 9 = 18. No other number <= 100 has a higher digit sum.
solve(10) = 9
solve(48) = 48. Note that 39 is also an option, ... | ["def solve(n):\n x = str(n)\n res = [x] + [str(int(x[:i]) - 1) + '9' * (len(x) - i) for i in range(1, len(x))]\n return int(max(res, key=lambda x: (sum(map(int, x)), int(x))))", "def dig_sum(n):\n return sum(map(int, str(n)))\n\ndef solve(n):\n candidates = [n] + [ n // 10**i * 10**i - 1 for i in range(... | {"fn_name": "solve", "inputs": [[79320], [99004], [99088], [99737], [29652], [100], [48], [521], [1], [2], [3], [39188], [5], [10], [1000], [10000], [999999999992], [59195], [19930], [110], [1199], [120], [18], [2090], [72694]], "outputs": [[78999], [98999], [98999], [98999], [28999], [99], [48], [499], [1], [2], [3], ... | INTRODUCTORY | PYTHON3 | CODEWARS | 3,799 |
def solve(n):
|
100fe5b7805448b5c58b46f852b2bfd6 | UNKNOWN | A number is simply made up of digits.
The number 1256 is made up of the digits 1, 2, 5, and 6.
For 1256 there are 24 distinct permutations of the digits:
1256, 1265, 1625, 1652, 1562, 1526, 2156, 2165, 2615, 2651, 2561, 2516,
5126, 5162, 5216, 5261, 5621, 5612, 6125, 6152, 6251, 6215, 6521, 6512.
Your goal ... | ["from itertools import permutations\n\ndef permutation_average(n):\n perms = [float(''.join(e)) for e in permutations(str(n))]\n return int(round(sum(perms) / len(perms)))\n", "def permutation_average(n):\n n = str(n)\n n, l = sum(map(int, n)) / float(len(n)), len(n)\n \n n = n * ((10 ** l - 1) / 9)\... | {"fn_name": "permutation_average", "inputs": [[2], [25], [737]], "outputs": [[2], [38], [629]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,162 |
def permutation_average(n):
|
fb839e937eab342ba0055d3f19045dac | UNKNOWN | Given the number pledged for a year, current value and name of the month, return string that gives information about the challenge status:
- ahead of schedule
- behind schedule
- on track
- challenge is completed
Examples:
`(12, 1, "February")` - should return `"You are on track."`
`(12, 1, "March")` - should retur... | ["import calendar\n\nM = {calendar.month_name[i]: i - 1 for i in range(1, 13)}\n\n\ndef check_challenge(pledged, current, month):\n if pledged == current:\n return \"Challenge is completed.\"\n m = M[month]\n per_month, rest = divmod(pledged, 12)\n todo = per_month * m + (min(rest, m))\n delta = c... | {"fn_name": "check_challenge", "inputs": [[12, 5, "January"], [12, 1, "February"], [12, 1, "March"], [12, 12, "September"], [12, 5, "March"], [100, 5, "March"], [100, 52, "July"], [100, 51, "July"], [100, 53, "July"]], "outputs": [["You are on track."], ["You are on track."], ["You are 1 behind schedule."], ["Challenge... | INTRODUCTORY | PYTHON3 | CODEWARS | 5,244 |
def check_challenge(pledged, current, month):
|
c409b8ff46d3185a5f03ab8cd7a2c1eb | UNKNOWN | *SCHEDULE YOUR DA(RRA)Y*
The best way to have a productive day is to plan out your work schedule. Given the following three inputs, please create an an array of time alloted to work, broken up with time alloted with breaks:
Input 1: Hours - Number of hours available to you to get your work done!
Inpu... | ["def day_plan(hours, tasks, duration):\n td, hm, tmo = tasks * duration, hours * 60, tasks - 1\n if td > hm: return \"You're not sleeping tonight!\"\n arr = [0] * (tasks + tmo)\n arr[::2], arr[1::2] = [duration] * tasks, [round((hm - td) / (tmo or 1))] * tmo\n return arr\n", "def day_plan(hours, tasks, ... | {"fn_name": "day_plan", "inputs": [[8, 5, 30], [3, 5, 60], [2, 2, 60], [2, 1, 60], [2, 0, 60]], "outputs": [[[30, 82, 30, 82, 30, 82, 30, 82, 30]], ["You're not sleeping tonight!"], [[60, 0, 60]], [[60]], [[]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,146 |
def day_plan(hours, tasks, duration):
|
3dcc2ef1a4f79b58335a0f9d24986908 | UNKNOWN | Steve and Josh are bored and want to play something. They don't want to think too much, so they come up with a really simple game. Write a function called winner and figure out who is going to win.
They are dealt the same number of cards. They both flip the card on the top of their deck. Whoever has a card with higher... | ["def winner(deck_Steve, deck_Josh):\n deck = ['2','3','4','5','6','7','8','9','T','J','Q','K','A']\n Steve = 0\n Josh = 0\n for i in range(len(deck_Steve)):\n if deck.index(deck_Steve[i]) > deck.index(deck_Josh[i]):\n Steve += 1\n elif deck.index(deck_Steve[i]) < deck.index(deck_Jo... | {"fn_name": "winner", "inputs": [[["A", "7", "8"], ["K", "5", "9"]], [["T"], ["T"]], [["T", "9"], ["T", "8"]], [[], []]], "outputs": [["Steve wins 2 to 1"], ["Tie"], ["Steve wins 1 to 0"], ["Tie"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,922 |
def winner(deck_steve, deck_josh):
|
bf765bd40d465b482d44cf6832a0eb8e | UNKNOWN | ## Your task
You are given a dictionary/hash/object containing some languages and your test results in the given languages. Return the list of languages where your test score is at least `60`, in descending order of the results.
Note: the scores will always be unique (so no duplicate values)
## Examples
```python
{... | ["def my_languages(results):\n return sorted((l for l,r in results.items() if r>=60), reverse=True, key=results.get)", "# def my_languages(dict):\n# store = []\n# for key, value in dict.items():\n# if value >= 60:\n# store.append((key, value))\n# store.sort(key=lambda x: x[-1])\n# ... | {"fn_name": "my_languages", "inputs": [[{"Java": 10, "Ruby": 80, "Python": 65}], [{"Hindi": 60, "Greek": 71, "Dutch": 93}], [{"C++": 50, "ASM": 10, "Haskell": 20}]], "outputs": [[["Ruby", "Python"]], [["Dutch", "Greek", "Hindi"]], [[]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 21,068 |
def my_languages(results):
|
d93ea0c8f1e1589f0fe1f3901776f273 | UNKNOWN | Truncate the given string (first argument) if it is longer than the given maximum length (second argument). Return the truncated string with a `"..."` ending.
Note that inserting the three dots to the end will add to the string length.
However, if the given maximum string length num is less than or equal to 3, then t... | ["def truncate_string(s,n):\n return s if len(s)<=n else s[:n if n<=3 else n-3]+'...'", "def truncate_string(s, n):\n return s if n>=len(s) else s[:n]+'...' if n<=3 else s[:n-3]+'...'", "def truncate_string(str,n):\n if len(str) <= n:\n return str\n if n <= 3:\n return str[0:n] + \"...\"\n ... | {"fn_name": "truncate_string", "inputs": [["pippi", 3], ["Peter Piper picked a peck of pickled peppers", 14], ["A-tisket a-tasket A green and yellow basket", 43], ["A-tisket a-tasket A green and yellow basket", 45], ["A-", 1], ["Chingel loves his Angel so much!!!", 27], ["I like ice-cream.Do you?", 19], ["Seems like yo... | INTRODUCTORY | PYTHON3 | CODEWARS | 1,173 |
def truncate_string(str,n):
|
e73de9160f40ad54859da6dbd0d70ce3 | UNKNOWN | Write a function `consonantCount`, `consonant_count` or `ConsonantCount` that takes a string of English-language text and returns the number of consonants in the string.
Consonants are all letters used to write English excluding the vowels `a, e, i, o, u`. | ["def consonant_count(str):\n return sum(1 for c in str if c.isalpha() and c.lower() not in \"aeiou\")\n", "import re\n\ndef consonant_count(s):\n return len(re.sub(r'[aeiou\\d\\s\\W\\_]', '', s))", "import re\n\ndef consonant_count(s):\n return len(re.sub(r'[^b-df-hj-np-tv-z]', '', s, flags=re.I))", "VOWELS =... | {"fn_name": "consonant_count", "inputs": [[""], ["aaaaa"], ["helLo world"], ["h^$&^#$&^elLo world"], ["0123456789"], ["012345_Cb"]], "outputs": [[0], [0], [7], [7], [0], [2]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,080 |
def consonant_count(s):
|
acbdbe433d96faffa47b5900b0222718 | UNKNOWN | Convert integers to binary as simple as that. You would be given an integer as a argument and you have to return its binary form.
To get an idea about how to convert a decimal number into a binary number, visit here.
**Notes**: negative numbers should be handled as two's complement; assume all numbers are integers sto... | ["def to_binary(n):\n return \"{:0b}\".format(n & 0xffffffff)", "def to_binary(n):\n return bin(n if n >= 0 else 2 ** 32 + n)[2:]", "def to_binary(n):\n return bin(n % 2**32)[2:]", "def to_binary(n):\n return format(n & 0xffffffff, 'b')", "def to_binary(n):\n return bin(n & (2**32 - 1))[2:]", "def to_bin... | {"fn_name": "to_binary", "inputs": [[2], [3], [4], [5], [7], [10], [-3], [0], [1000], [-15], [-1000], [-999999], [999999]], "outputs": [["10"], ["11"], ["100"], ["101"], ["111"], ["1010"], ["11111111111111111111111111111101"], ["0"], ["1111101000"], ["11111111111111111111111111110001"], ["111111111111111111111100000110... | INTRODUCTORY | PYTHON3 | CODEWARS | 725 |
def to_binary(n):
|
5f388f5bbed99b4b65ec9cc221b5d49d | UNKNOWN | Basic regex tasks. Write a function that takes in a numeric code of any length. The function should check if the code begins with 1, 2, or 3 and return `true` if so. Return `false` otherwise.
You can assume the input will always be a number. | ["def validate_code(code):\n return str(code).startswith(('1', '2', '3'))\n", "def validate_code(code):\n return str(code)[0] in '123'", "def validate_code(code):\n import re\n return bool(re.match(r\"^[123]\\d*$\",str(code)))\n", "def validate_code(code):\n import re\n return bool(re.match('[123]',st... | {"fn_name": "validate_code", "inputs": [[123], [248], [8], [321], [9453]], "outputs": [[true], [true], [false], [true], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,619 |
def validate_code(code):
|
95d5a588a2698a205661bb10f825f0e7 | UNKNOWN | The image shows how we can obtain the Harmonic Conjugated Point of three aligned points A, B, C.
- We choose any point L, that is not in the line with A, B and C. We form the triangle ABL
- Then we draw a line from point C that intersects the sides of this triangle at points M and N respectively.
- We draw the diago... | ["def harmon_pointTrip(xA, xB, xC):\n a, b, c = list(map(float, [xA, xB, xC]))\n # Yay for algebra!\n d = ((a * c) + (b * c) - (2 * a * b)) / (2 * c - a - b)\n return round(d, 4)\n", "def harmon_pointTrip(xA, xB, xC):\n return round((xA*xC + xB*xC - 2*xA*xB) / (2*xC - xA - xB), 4)", "def harmon_pointTrip... | {"fn_name": "harmon_pointTrip", "inputs": [[2, 10, 20], [3, 9, 18], [6, 10, 11], [4, 12, 24], [5, 17, 20]], "outputs": [[7.1429], [6.75], [9.3333], [9.0], [15.0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,115 |
def harmon_pointTrip(xA, xB, xC):
|
d658e6dbd34fa1e2fbd6f5375d2a0f85 | UNKNOWN | We have the number ```12385```. We want to know the value of the closest cube but higher than 12385. The answer will be ```13824```.
Now, another case. We have the number ```1245678```. We want to know the 5th power, closest and higher than that number. The value will be ```1419857```.
We need a function ```find_next... | ["def find_next_power(val, pow_):\n return int(val ** (1.0 / pow_) + 1) ** pow_", "import math\n\ndef find_next_power(val, pow_):\n next_power_value = math.floor( 1 + val ** (1/pow_))\n return next_power_value ** pow_", "def find_next_power(val, pow_):\n return int(val ** (1 / pow_) + 1) ** pow_", "def find... | {"fn_name": "find_next_power", "inputs": [[12385, 3], [1245678, 5], [1245678, 6]], "outputs": [[13824], [1419857], [1771561]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,022 |
def find_next_power(val, pow_):
|
577b24e6bae070216293e7580d7fdf96 | UNKNOWN | The goal of this Kata is to remind/show you, how Z-algorithm works and test your implementation.
For a string str[0..n-1], Z array is of same length as string. An element Z[i] of Z array stores length of the longest substring starting from str[i] which is also a prefix of str[0..n-1]. The first entry of Z array is mea... | ["def prefix1(a, b):\n cnt = 0\n for i, j in zip(a, b):\n if i == j:\n cnt += 1\n else:\n return cnt\n return cnt \ndef prefix2(a, b, num):\n for i in range(num, -1, -1):\n if b.startswith(a[:i]):\n return i\ndef zfunc(str_):\n z = []\n k = len(... | {"fn_name": "zfunc", "inputs": [["ababcaba"], [""], ["aaaaaaaa"], ["ababababab"], ["aaaa$aaaa"], ["abracadabra"]], "outputs": [[[8, 0, 2, 0, 0, 3, 0, 1]], [[]], [[8, 7, 6, 5, 4, 3, 2, 1]], [[10, 0, 8, 0, 6, 0, 4, 0, 2, 0]], [[9, 3, 2, 1, 0, 4, 3, 2, 1]], [[11, 0, 0, 1, 0, 1, 0, 4, 0, 0, 1]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 6,962 |
def zfunc(str_):
|
cf5b2c799fecf00980c789e744f1ad1c | UNKNOWN | Create a function that takes an input String and returns a String, where all the uppercase words of the input String are in front and all the lowercase words at the end.
The order of the uppercase and lowercase words should be the order in which they occur.
If a word starts with a number or special character, skip the... | ["def capitals_first(string):\n return ' '.join([word for word in string.split() if word[0].isupper()] + [word for word in string.split() if word[0].islower()])\n", "def capitals_first(string):\n # biggies first...\n words = string.split()\n st1 = []\n st2 = []\n for word in words:\n if word[0]... | {"fn_name": "capitals_first", "inputs": [["hey You, Sort me Already"], ["sense Does to That Make you?"], ["i First need Thing In coffee The Morning"], ["123 baby You and Me"], ["Life gets Sometimes pretty !Hard"]], "outputs": [["You, Sort Already hey me"], ["Does That Make sense to you?"], ["First Thing In The Morning ... | INTRODUCTORY | PYTHON3 | CODEWARS | 2,116 |
def capitals_first(text):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.