problem_id int64 2.36k 5k | question stringlengths 52 14k | solutions stringlengths 79 675k | input_output stringlengths 37 505k | difficulty stringclasses 1
value | url stringlengths 36 94 | starter_code stringlengths 0 952 |
|---|---|---|---|---|---|---|
4,064 | Create a function with two arguments that will return an array of the first (n) multiples of (x).
Assume both the given number and the number of times to count will be positive numbers greater than 0.
Return the results as an array (or list in Python, Haskell or Elixir).
Examples:
```python
count_by(1,10) #should... | ["def count_by(x, n):\n return [i * x for i in range(1, n + 1)]", "def count_by(x, n):\n \"\"\"\n Return a sequence of numbers counting by `x` `n` times.\n \"\"\"\n return [i * x for i in range(1, n+1)]\n", "def count_by(x, n):\n return [x * i for i in range(1, n+1)]", "def count_by(x, n):\n \"\"\"... | {"fn_name": "count_by", "inputs": [[1, 5], [2, 5], [3, 5], [50, 5], [100, 5]], "outputs": [[[1, 2, 3, 4, 5]], [[2, 4, 6, 8, 10]], [[3, 6, 9, 12, 15]], [[50, 100, 150, 200, 250]], [[100, 200, 300, 400, 500]]]} | introductory | https://www.codewars.com/kata/5513795bd3fafb56c200049e |
def count_by(x, n):
|
4,065 | In mathematics, a **pandigital number** is a number that in a given base has among its significant digits each digit used in the base at least once. For example, 1234567890 is a pandigital number in base 10.
For simplification, in this kata, we will consider pandigital numbers in *base 10* and with all digits used *ex... | ["def get_sequence(o,s,st=1023456789):\n li = []\n for i in range([st,o][o>0 and o>st],9876543211):\n i = str(i)\n if i[0]!='0' and len(set(i))==10 : li.append(int(i))\n if len(li)==s : break\n return li ", "from itertools import permutations\nfrom bisect import bisect_left\n\nmemo = [int(... | {"fn_name": "get_sequence", "inputs": [[0, 5], [5432160879, 3], [9876543000, 5], [9999999999, 1], [-123456789, 1], [-9999999999, 25]], "outputs": [[[1023456789, 1023456798, 1023456879, 1023456897, 1023456978]], [[5432160879, 5432160897, 5432160978]], [[9876543012, 9876543021, 9876543102, 9876543120, 9876543201]], [[]],... | introductory | https://www.codewars.com/kata/5ac69d572f317bdfc3000124 |
def get_sequence(offset, size):
|
4,066 | Write a function to split a string and convert it into an array of words. For example:
```python
"Robin Singh" ==> ["Robin", "Singh"]
"I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"]
``` | ["def string_to_array(string):\n return string.split(\" \")", "def string_to_array(string=''):\n return string.split() if string else ['']", "def string_to_array(s):\n return s.split(' ')", "def string_to_array(string):\n array = string.split(' ')\n return array", "def string_to_array(string):\n retur... | {"fn_name": "string_to_array", "inputs": [["Robin Singh"], ["CodeWars"], ["I love arrays they are my favorite"], ["1 2 3"], [""]], "outputs": [[["Robin", "Singh"]], [["CodeWars"]], [["I", "love", "arrays", "they", "are", "my", "favorite"]], [["1", "2", "3"]], [[""]]]} | introductory | https://www.codewars.com/kata/57e76bc428d6fbc2d500036d |
def string_to_array(s):
|
4,067 | Bob is preparing to pass IQ test. The most frequent task in this test is `to find out which one of the given numbers differs from the others`. Bob observed that one number usually differs from the others in **evenness**. Help Bob — to check his answers, he needs a program that among the given numbers finds one that is ... | ["def iq_test(numbers):\n e = [int(i) % 2 == 0 for i in numbers.split()]\n\n return e.index(True) + 1 if e.count(True) == 1 else e.index(False) + 1\n", "def iq_test(n):\n n = [int(i)%2 for i in n.split()]\n if n.count(0)>1:\n return n.index(1)+1\n else:\n return n.index(0)+1\n", "def iq_tes... | {"fn_name": "iq_test", "inputs": [["2 4 7 8 10"], ["1 2 2"], ["88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46"], ["100 99 100"], ["5 3 2"], ["43 28 1 91"], ["20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36"], ["79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 ... | introductory | https://www.codewars.com/kata/552c028c030765286c00007d |
def iq_test(numbers):
|
4,068 | # Task
Mr.Nam has `n` candies, he wants to put one candy in each cell of a table-box. The table-box has `r` rows and `c` columns.
Each candy was labeled by its cell number. The cell numbers are in range from 1 to N and the direction begins from right to left and from bottom to top.
Nam wants to know the position o... | ["def get_candy_position(n, r, c, candy):\n if candy > n: return [-1,-1,-1]\n \n linIdx = r*c - ( (candy-1) % (r*c) + 1 )\n return [(candy-1)//(r*c) + 1, linIdx//c, linIdx%c]", "def get_candy_position(n, r, c, candy):\n if candy > n:\n return [-1, -1, -1]\n label = (candy + r * c - 1) // (r * c... | {"fn_name": "get_candy_position", "inputs": [[6, 2, 2, 3], [6, 2, 2, 5], [6, 2, 2, 7], [8, 4, 2, 3], [15, 3, 3, 1], [15, 3, 3, 5], [15, 3, 3, 7], [15, 3, 3, 14], [15, 3, 3, 18]], "outputs": [[[1, 0, 1]], [[2, 1, 1]], [[-1, -1, -1]], [[1, 2, 1]], [[1, 2, 2]], [[1, 1, 1]], [[1, 0, 2]], [[2, 1, 1]], [[-1, -1, -1]]]} | introductory | https://www.codewars.com/kata/58b626ee2da07adf3e00009c |
def get_candy_position(n, r, c, candy):
|
4,069 | I love Fibonacci numbers in general, but I must admit I love some more than others.
I would like for you to write me a function that when given a number (n) returns the n-th number in the Fibonacci Sequence.
For example:
```python
nth_fib(4) == 2
```
Because 2 is the 4th number in the Fibonacci Sequence.
For ... | ["def nth_fib(n):\n a, b = 0, 1\n for i in range(n-1):\n a, b = b, a + b\n return a", "def nth_fib(n):\n a, b = (0, 1)\n for _ in range(n-1):\n a, b = b, a + b\n return a", "def nth_fib(n):\n if n==1:\n return 0\n elif n==2:\n return 1\n else:\n return nth_fib(n-1)+nth_fib(n-2)\n", "from m... | {"fn_name": "nth_fib", "inputs": [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25]], "outputs": [[0], [1], [1], [2], [3], [5], [8], [13], [21], [34], [55], [89], [144], [233], [377], [610], [987], [1597], [2584], [4181], [6765], ... | introductory | https://www.codewars.com/kata/522551eee9abb932420004a0 |
def nth_fib(n):
|
4,070 | The magic sum of 3s is calculated on an array by summing up odd numbers which include the digit `3`. Write a function `magic_sum` which accepts an array of integers and returns the sum.
*Example:* `[3, 12, 5, 8, 30, 13]` results in `16` (`3` + `13`)
If the sum cannot be calculated, `0` should be returned. | ["def magic_sum(arr):\n return arr and sum(x for x in arr if x%2 and '3' in str(x)) or 0", "def magic_sum(arr):\n if arr == None: return 0 \n return sum(list(filter(lambda x: x % 2 == 1 and '3' in str(x),arr)))", "def magic_sum(arr):\n def check(x):\n return x % 2 and '3' in str(x)\n return sum(x ... | {"fn_name": "magic_sum", "inputs": [[[3]], [[3, 13]], [[30, 34, 330]], [[3, 12, 5, 8, 30, 13]], [[]], [null]], "outputs": [[3], [16], [0], [16], [0], [0]]} | introductory | https://www.codewars.com/kata/57193a349906afdf67000f50 |
def magic_sum(arr):
|
4,071 | # Scenario
*You're saying good-bye your best friend* , **_See you next happy year_** .
**_Happy Year_** *is the year with only distinct digits* , (e.g) **_2018_**
___
# Task
**_Given_** a year, **_Find_** **_The next happy year_** or **_The closest year You'll see your best friend_** :\n year += 1\n \n while len(set(str(year))) != 4:\n year += 1\n \n return year", "def next_happy_year(year):\n for n in range(year+1, 9999):\n if len(set(str(n))) == 4:\n return n", "def next_happy_year(year):\n while True:\n year+=1\n ... | {"fn_name": "next_happy_year", "inputs": [[1001], [1123], [2001], [2334], [3331], [1987], [5555], [7712], [8088], [8999]], "outputs": [[1023], [1203], [2013], [2340], [3401], [2013], [5601], [7801], [8091], [9012]]} | introductory | https://www.codewars.com/kata/5ae7e3f068e6445bc8000046 |
def next_happy_year(year):
|
4,072 | #Permutation position
In this kata you will have to permutate through a string of lowercase letters, each permutation will start at ```a``` and you must calculate how many iterations it takes to reach the current permutation.
##examples
```
input: 'a'
result: 1
input: 'c'
result: 3
input: 'z'
result: 26
input: 'fo... | ["from functools import reduce\ndef permutation_position(perm):\n return reduce(lambda t,c:t*26+ord(c)-97,perm,0)+1\n", "trans_table = str.maketrans('abcdefghijklmnopqrstuvwxyz',\n '0123456789abcdefghijklmnop')\n\ndef permutation_position(perm):\n return int(perm.translate(trans_table),... | {"fn_name": "permutation_position", "inputs": [["a"], ["z"], ["aaa"], ["aaab"], ["foo"]], "outputs": [[1], [26], [1], [2], [3759]]} | introductory | https://www.codewars.com/kata/57630df805fea67b290009a3 |
def permutation_position(perm):
|
4,073 | # Task
Given a rectangular `matrix` and integers `a` and `b`, consider the union of the ath row and the bth (both 0-based) column of the `matrix`. Return sum of all elements of that union.
# Example
For
```
matrix = [[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 3]]
a = 1 and b = 3 ```
the output shou... | ["def crossing_sum(matrix, row, col):\n return sum(matrix[row]) + sum(line[col] for line in matrix) - matrix[row][col]", "def crossing_sum(a, b, c):\n return sum(a[b]) + sum(x[c] for x in a) - a[b][c]", "def crossing_sum(matrix, row, col):\n return sum(matrix[row]) + sum(i[col] for i in matrix[:row] + matrix[r... | {"fn_name": "crossing_sum", "inputs": [[[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]], 1, 3], [[[1, 1], [3, 3], [1, 1], [2, 2]], 3, 0], [[[100]], 0, 0], [[[1, 2, 3, 4, 5]], 0, 0], [[[1], [2], [3], [4], [5]], 0, 0]], "outputs": [[12], [9], [100], [15], [15]]} | introductory | https://www.codewars.com/kata/5889ab4928c08c08da00009b |
def crossing_sum(matrix, row, col):
|
4,074 | Given an array of numbers, return the difference between the largest and smallest values.
For example:
`[23, 3, 19, 21, 16]` should return `20` (i.e., `23 - 3`).
`[1, 434, 555, 34, 112]` should return `554` (i.e., `555 - 1`).
The array will contain a minimum of two elements. Input data range guarantees that `max-m... | ["def between_extremes(numbers):\n return max(numbers) - min(numbers)", "def between_extremes(ns):\n return max(ns) - min(ns)", "def between_extremes(a):\n return max(a) - min(a)", "# Naive method: 2 iterations\ndef between_extremes(numbers):\n return max(numbers) - min(numbers)\n\n# Faster method: 1 iterat... | {"fn_name": "between_extremes", "inputs": [[[1, 1]], [[-1, -1]], [[1, -1]], [[21, 34, 54, 43, 26, 12]], [[-1, -41, -77, -100]]], "outputs": [[0], [0], [2], [42], [99]]} | introductory | https://www.codewars.com/kata/56d19b2ac05aed1a20000430 |
def between_extremes(numbers):
|
4,075 | We have the following recursive function:
The 15-th term; ```f(14)``` is the first term in having more that 100 digits.
In fact,
```
f(14) = 2596253046576879973769082409566059879570061514363339324718953988724415850732046186170181072783243503881471037546575506836249417271830960970629933033088
It has 151 digits.
``... | ["from functools import reduce\ndef product(ar):\n return reduce(lambda x,y:x*y, ar)\n\ndef something_acci(num_digits):\n seq = [1, 1, 2, 2, 3, 3]\n \n while(len(str(seq[-1])) < num_digits):\n seq.append(product(seq[-3:]) - product(seq[-6:-3]))\n \n return (len(seq), len(str(seq[-1])))\n", "def... | {"fn_name": "something_acci", "inputs": [[5], [10], [20], [100]], "outputs": [[[10, 8]], [[11, 14]], [[12, 25]], [[15, 151]]]} | introductory | https://www.codewars.com/kata/5683838837b2d1db32000021 |
def something_acci(num_digits):
|
4,076 | Error Handling is very important in coding and seems to be overlooked or not implemented properly.
#Task
Your task is to implement a function which takes a string as input and return an object containing the properties
vowels and consonants. The vowels property must contain the total count of vowels {a,e,i,o,u}, and ... | ["def get_count(words=\"\"):\n if not isinstance(words, str):\n return {'vowels':0,'consonants':0}\n letter = \"\".join([c.lower() for c in words if c.isalpha()])\n vowel = \"\".join([c for c in letter if c in 'aeiou'])\n consonant = \"\".join([c for c in letter if c not in 'aeiou']) \n return {'v... | {"fn_name": "get_count", "inputs": [["Test"], ["Here is some text"], ["To be a Codewarrior or not to be"], ["To Kata or not to Kata"], ["aeiou"], ["TEst"], ["HEre Is sOme text"], [["To Kata or not to Kata"]], [null], ["Test "], ["Here is some text "], [" "], [{"jjjjj": "jjjjj"}]],... | introductory | https://www.codewars.com/kata/55e6125ad777b540d9000042 |
def get_count(words=''):
|
4,077 | The new football league season is coming and the Football Association need some help resetting the league standings. Normally the initial league standing is done in alphabetical order (from A to Z) but this year the FA have decided to freshen it up.
It has been decided that team who finished first last season will be... | ["def premier_league_standings(teams):\n dct = {1: teams[1]}\n dct.update({i:t for i,t in enumerate(sorted(set(teams.values())-{teams[1]}), 2)})\n return dct", "def premier_league_standings(teams):\n order = [teams[1]] + sorted(team for place,team in teams.items() if place!=1)\n return {place:team for pl... | {"fn_name": "premier_league_standings", "inputs": [[{"1": "Arsenal"}], [{"2": "Arsenal", "3": "Accrington Stanley", "1": "Leeds United"}], [{"1": "Leeds United", "2": "Liverpool", "3": "Manchester City", "4": "Coventry", "5": "Arsenal"}]], "outputs": [{"1": "Arsenal"}, {"3": "Arsenal", "2": "Accrington Stanley", "1": "... | introductory | https://www.codewars.com/kata/58de08d376f875dbb40000f1 |
def premier_league_standings(teams):
|
4,078 | Your task is to write a function that does just what the title suggests (so, fair warning, be aware that you are not getting out of it just throwing a lame bas sorting method there) with an array/list/vector of integers and the expected number `n` of smallest elements to return.
Also:
* the number of elements to be r... | ["def first_n_smallest(arr, n):\n lst = sorted(enumerate(arr), key=lambda it: it[1])[:n]\n lst.sort(key=lambda it:it[0])\n return [v for _,v in lst]", "def first_n_smallest(arr, n):\n m = sorted(arr)[:n]\n return [m.pop(m.index(i)) for i in arr if i in m]", "from operator import itemgetter\ndef first_n_s... | {"fn_name": "first_n_smallest", "inputs": [[[1, 2, 3, 4, 5], 3], [[5, 4, 3, 2, 1], 3], [[1, 2, 3, 1, 2], 3], [[1, 2, 3, -4, 0], 3], [[1, 2, 3, 4, 5], 0], [[1, 2, 3, 4, 5], 5], [[1, 2, 3, 4, 2], 4], [[2, 1, 2, 3, 4, 2], 2], [[2, 1, 2, 3, 4, 2], 3], [[2, 1, 2, 3, 4, 2], 4]], "outputs": [[[1, 2, 3]], [[3, 2, 1]], [[1, 2, ... | introductory | https://www.codewars.com/kata/5aec1ed7de4c7f3517000079 |
def first_n_smallest(arr, n):
|
4,079 | This is a follow up from my kata The old switcheroo
Write
```python
def encode(str)
```
that takes in a string ```str``` and replaces all the letters with their respective positions in the English alphabet.
```python
encode('abc') == '123' # a is 1st in English alpabet, b is 2nd and c is 3rd
encode('codewars') == '... | ["def encode(string):\n return ''.join(str(ord(c.upper())-64) if c.isalpha() else c for c in string)", "def encode(string):\n return ''.join(str(ord(c)-96) if c.isalpha() else c for c in string.lower())", "def encode(s):\n return ''.join(str(ord(x) - ord('a') + 1) if x.isalpha() else x for x in s.lower())", "fro... | {"fn_name": "encode", "inputs": [["abc"], ["ABCD"], ["ZzzzZ"], ["abc-#@5"], ["this is a long string!! Please [encode] @C0RrEctly"]], "outputs": [["123"], ["1234"], ["2626262626"], ["123-#@5"], ["208919 919 1 1215147 1920189147!! 161251195 [51431545] @30181853201225"]]} | introductory | https://www.codewars.com/kata/55d6a0e4ededb894be000005 |
def encode(string):
|
4,080 | Is every value in the array an array?
This should only test the second array dimension of the array. The values of the nested arrays don't have to be arrays.
Examples:
```python
[[1],[2]] => true
['1','2'] => false
[{1:1},{2:2}] => false
``` | ["def arr_check(arr):\n return all(isinstance(el, list) for el in arr)", "def arr_check(arr):\n return all(isinstance(a, list) for a in arr)", "def arr_check(arr):\n return all(type(ele) is list for ele in arr)", "def arr_check(arr):\n return all(type(i) == list for i in arr)", "def arr_check(arr):\n ret... | {"fn_name": "arr_check", "inputs": [[[]], [[["string"]]], [[[], {}]], [[[1], [2], [3]]], [["A", "R", "R", "A", "Y"]]], "outputs": [[true], [true], [false], [true], [false]]} | introductory | https://www.codewars.com/kata/582c81d982a0a65424000201 |
def arr_check(arr):
|
4,081 | Baby is getting his frst tooth. This means more sleepless nights, but with the fun of feeling round his gums and trying to guess which will be first out!
Probably best have a sweepstake with your friends - because you have the best chance of knowing. You can feel the gums and see where the raised bits are - most rais... | ["def first_tooth(lst):\n gums = lst[:1] + lst + lst[-1:]\n diff = [gums[i+1]*2 - gums[i] - gums[i+2] for i in range(len(lst))]\n m = max(diff)\n return diff.index(m) if diff.count(m) == 1 else -1\n", "def first_tooth(array):\n array = [array[0]]+array+[array[-1]]\n diffs = [2*array[i]-array[i-1]-arra... | {"fn_name": "first_tooth", "inputs": [[[1, 2, 3, 4]], [[1, 2, 6, 4]], [[1, 2, 5, 7, 1, 0, 9]], [[9, 2, 8, 1]], [[1, 1, 1, 1]], [[20, 9, 16, 19]], [[15]]], "outputs": [[3], [2], [6], [2], [-1], [0], [0]]} | introductory | https://www.codewars.com/kata/5bcac5a01cbff756e900003e |
def first_tooth(array):
|
4,082 | A series or sequence of numbers is usually the product of a function and can either be infinite or finite.
In this kata we will only consider finite series and you are required to return a code according to the type of sequence:
|Code|Type|Example|
|-|-|-|
|`0`|`unordered`|`[3,5,8,1,14,3]`|
|`1`|`strictly increasing`... | ["def sequence_classifier(arr):\n if all(arr[i] == arr[i+1] for i in range(len(arr)-1)): return 5\n if all(arr[i] < arr[i+1] for i in range(len(arr)-1)): return 1\n if all(arr[i] <= arr[i+1] for i in range(len(arr)-1)): return 2\n if all(arr[i] > arr[i+1] for i in range(len(arr)-1)): return 3\n if all(... | {"fn_name": "sequence_classifier", "inputs": [[[3, 5, 8, 1, 14, 3]], [[3, 5, 8, 9, 14, 23]], [[3, 5, 8, 8, 14, 14]], [[14, 9, 8, 5, 3, 1]], [[14, 14, 8, 8, 5, 3]], [[8, 8, 8, 8, 8, 8]], [[8, 9]], [[8, 8, 8, 8, 8, 9]], [[9, 8]], [[9, 9, 9, 8, 8, 8]], [[3, 5, 8, 1, 14, 2]]], "outputs": [[0], [1], [2], [3], [4], [5], [1],... | introductory | https://www.codewars.com/kata/5921c0bc6b8f072e840000c0 |
def sequence_classifier(arr):
|
4,083 | This challenge is based on [the kata](https://www.codewars.com/kata/n-smallest-elements-in-original-order) by GiacomoSorbi. Before doing this one it is advisable to complete the non-performance version first.
___
# Task
You will be given an array of random integers and a number `n`. You have to extract `n` smallest ... | ["from collections import Counter\nfrom itertools import count, islice\n\ndef performant_smallest(arr, n):\n cnts = Counter(arr)\n total = 0\n for i, c in sorted(cnts.items()):\n total += c\n if total >= n:\n break\n available = count(c + n - total, -1)\n it = (x for x in arr if ... | {"fn_name": "performant_smallest", "inputs": [[[1, 2, 3, 4, 5], 3], [[5, 4, 3, 2, 1], 3], [[1, 2, 3, 4, 1], 3], [[2, 1, 3, 2, 3], 3]], "outputs": [[[1, 2, 3]], [[3, 2, 1]], [[1, 2, 1]], [[2, 1, 2]]]} | introductory | https://www.codewars.com/kata/5aeed69804a92621a7000077 |
def performant_smallest(arr, n):
|
4,084 | Alex is transitioning from website design to coding and wants to sharpen his skills with CodeWars.
He can do ten kata in an hour, but when he makes a mistake, he must do pushups. These pushups really tire poor Alex out, so every time he does them they take twice as long. His first set of redemption pushups takes 5 mi... | ["from math import log\n\ndef alex_mistakes(n, time):\n return int(log((time - n * 6) / 5 +1, 2))\n", "def alex_mistakes(katas, time):\n mistakes = 0\n pushup_time = 5\n time_left = time - katas * 6\n \n while time_left >= pushup_time:\n time_left -= pushup_time\n pushup_time *= 2\n ... | {"fn_name": "alex_mistakes", "inputs": [[10, 120], [11, 120], [3, 45], [8, 120], [6, 60], [9, 180], [20, 120], [20, 125], [20, 130], [20, 135]], "outputs": [[3], [3], [2], [3], [2], [4], [0], [1], [1], [2]]} | introductory | https://www.codewars.com/kata/571640812ad763313600132b |
def alex_mistakes(number_of_katas, time_limit):
|
4,085 | One of the first chain emails I ever received was about a supposed Cambridge University study that suggests your brain can read words no matter what order the letters are in, as long as the first and last letters of each word are correct.
Your task is to **create a function that can take any string and randomly jumbl... | ["import re\nfrom random import sample\n\ndef mix_words(string):\n return re.sub(\n r'(?<=[a-zA-Z])([a-zA-Z]{2,})(?=[a-zA-Z])',\n lambda match: ''.join(sample(match.group(1), len(match.group(1)))),\n string)\n", "from re import sub\nfrom random import shuffle\n\ndef scramble(m):\n s = list(m.... | {"fn_name": "mix_words", "inputs": [["Hi"], ["Hi!"], ["Hey"], ["Hey?"]], "outputs": [["Hi"], ["Hi!"], ["Hey"], ["Hey?"]]} | introductory | https://www.codewars.com/kata/564e48ebaaad20181e000024 |
def mix_words(s):
|
4,086 | Your task is to find the first element of an array that is not consecutive.
By not consecutive we mean not exactly 1 larger than the previous element of the array.
E.g. If we have an array `[1,2,3,4,6,7,8]` then `1` then `2` then `3` then `4` are all consecutive but `6` is not, so that's the first non-consecutive num... | ["def first_non_consecutive(arr):\n if not arr: return 0\n for i, x in enumerate(arr[:-1]):\n if x + 1 != arr[i + 1]:\n return arr[i + 1]", "def first_non_consecutive(a):\n i = a[0]\n for e in a:\n if e != i:\n return e\n i += 1\n return None", "def first_non_co... | {"fn_name": "first_non_consecutive", "inputs": [[[1, 2, 3, 4, 6, 7, 8]], [[1, 2, 3, 4, 5, 6, 7, 8]], [[4, 6, 7, 8, 9, 11]], [[4, 5, 6, 7, 8, 9, 11]], [[31, 32]], [[-3, -2, 0, 1]], [[-5, -4, -3, -1]]], "outputs": [[6], [null], [6], [11], [null], [0], [-1]]} | introductory | https://www.codewars.com/kata/58f8a3a27a5c28d92e000144 |
def first_non_consecutive(arr):
|
4,087 | Write a function which takes a number and returns the corresponding ASCII char for that value.
Example:
~~~if-not:java,racket
```
get_char(65) # => 'A'
```
~~~
~~~if:java
~~~
~~~if:racket
~~~
For ASCII table, you can refer to http://www.asciitable.com/ | ["def get_char(c):\n return chr(c)", "get_char=chr", "def get_char(value):\n '''Return the ASCII char for a given value'''\n return chr(value)", "get_char = lambda c: chr(c)", "def get_char(num_of_char):\n return chr(num_of_char)", "def get_char(c):\n c = chr(c)\n return c", "def get_char(c: int) -> str:\n ... | {"fn_name": "get_char", "inputs": [[65], [33], [34], [35], [36], [37], [38]], "outputs": [["A"], ["!"], ["\""], ["#"], ["$"], ["%"], ["&"]]} | introductory | https://www.codewars.com/kata/55ad04714f0b468e8200001c |
def get_char(c):
|
4,088 | # Fun fact
Tetris was the first video game played in outer space
In 1993, Russian cosmonaut Aleksandr A. Serebrov spent 196 days on the Mir space station with a very special distraction: a gray Game Boy loaded with Tetris. During that time the game orbited the Earth 3,000 times and became the first video game played i... | ["pos = {\"L4\":0, \"L3\":1, \"L2\":2, \"L1\":3, \"L0\":4, \"R0\":4, \"R1\":5, \"R2\":6, \"R3\":7, \"R4\":8}\n\ndef tetris(arr):\n current, res = [0]*9, 0\n for x in arr:\n p = pos[x[1:]]\n current[p] += int(x[0])\n if current[p] >= 30: break\n y = min(current)\n if y: current, ... | {"fn_name": "tetris", "inputs": [[["1R4", "2L3", "3L2", "4L1", "1L0", "2R1", "3R2", "4R3", "1L4"]], [["1L2", "4R2", "3L3", "3L1", "1L4", "1R4"]], [["4R4", "4L3", "4L2", "4L1", "4L0", "4R1", "4R2", "4R3", "3L4"]]], "outputs": [[1], [0], [3]]} | introductory | https://www.codewars.com/kata/5db8a241b8d7260011746407 |
def tetris(arr):
|
4,089 | The number 45 is the first integer in having this interesting property:
the sum of the number with its reversed is divisible by the difference between them(absolute Value).
```
45 + 54 = 99
abs(45 - 54) = 9
99 is divisible by 9.
```
The first terms of this special sequence are :
```
n a(n)
1 ... | ["MEMO = []\n\ndef sum_dif_rev(n):\n i = MEMO[-1] if MEMO else 0\n \n while len(MEMO) < n:\n i += 1\n r = int(str(i)[::-1])\n if i % 10 and r != i and (i + r) % abs(r - i) == 0:\n MEMO.append(i)\n\n return MEMO[n-1]", "from itertools import count\n\n# It's not worth it to mem... | {"fn_name": "sum_dif_rev", "inputs": [[1], [3], [4], [5], [6]], "outputs": [[45], [495], [594], [4356], [4545]]} | introductory | https://www.codewars.com/kata/5603a9585480c94bd5000073 |
def sum_dif_rev(n):
|
4,090 | Farmer Bob have a big farm, where he growths chickens, rabbits and cows. It is very difficult to count the number of animals for each type manually, so he diceded to buy a system to do it. But he bought a cheap system that can count only total number of heads, total number of legs and total number of horns of animals o... | ["def get_animals_count(legs, heads, horns):\n cows = horns // 2\n rabbits = legs // 2 - cows - heads\n chickens = heads - cows - rabbits\n return dict(cows=cows, rabbits=rabbits, chickens=chickens)", "def get_animals_count(ln, hn, horn):\n c,ln,hn = horn//2, ln - 2*horn, hn - horn//2\n return {\"rabb... | {"fn_name": "get_animals_count", "inputs": [[34, 11, 6], [154, 42, 10], [74, 20, 34], [152, 38, 34], [56, 17, 0]], "outputs": [[{"rabbits": 3, "chickens": 5, "cows": 3}], [{"rabbits": 30, "chickens": 7, "cows": 5}], [{"rabbits": 0, "chickens": 3, "cows": 17}], [{"rabbits": 21, "chickens": 0, "cows": 17}], [{"rabbits": ... | introductory | https://www.codewars.com/kata/5a02037ac374cbab41000089 |
def get_animals_count(legs, heads, horns):
|
4,091 | You're continuing to enjoy your new piano, as described in Piano Kata, Part 1. You're also continuing the exercise where you start on the very first (leftmost, lowest in pitch) key on the 88-key keyboard, which (as shown below) is the note A, with the little finger on your left hand, then the second key, which is the b... | ["def which_note(count):\n return \"A A# B C C# D D# E F F# G G#\".split()[(count - 1) % 88 % 12]", "keyboard = \"A A# B C C# D D# E F F# G G#\".split()\n\ndef which_note(count):\n return keyboard[(count - 1) % 88 % 12]", "NOTES = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#']\nNUMBER_OF_KEYS =... | {"fn_name": "which_note", "inputs": [[1], [5], [12], [42], [88], [89], [92], [100], [111], [200], [2017]], "outputs": [["A"], ["C#"], ["G#"], ["D"], ["C"], ["A"], ["C"], ["G#"], ["G"], ["G#"], ["F"]]} | introductory | https://www.codewars.com/kata/589631d24a7323d18d00016f |
def which_note(key_press_count):
|
4,092 | # Grasshopper - Function syntax debugging
A student was working on a function and made some syntax mistakes while coding. Help them find their mistakes and fix them. | ["def main(verb, noun): \n return verb + noun", "def main (verb, noun):\n # This function has three problems: square brackets instead of parenthesis,\n # a colon after the parenthesis and the return command inside the\n # function is not indented.\n return verb + noun", "def main(*a):\n return ''.join... | {"fn_name": "main", "inputs": [["take ", "item"], ["use ", "sword"]], "outputs": [["take item"], ["use sword"]]} | introductory | https://www.codewars.com/kata/56dae9dc54c0acd29d00109a |
def main(verb, noun):
|
4,093 | In an infinite array with two rows, the numbers in the top row are denoted
`. . . , A[−2], A[−1], A[0], A[1], A[2], . . .`
and the numbers in the bottom row are denoted
`. . . , B[−2], B[−1], B[0], B[1], B[2], . . .`
For each integer `k`, the entry `A[k]` is directly above
the entry `B[k]` in the array, as shown:
... | ["def find_a(lst,n):\n if n<0: return find_a(lst[::-1], 3-n)\n if n<4: return lst[n]\n a,b,c,d = lst\n for _ in range(n-3):\n a,b,c,d = b, c, d, 6*d-10*c+6*b-a\n return d", "def find_a(A, n):\n if 0 <= n < 4: return A[n]\n if n < 0:\n A, n = A[::-1], abs(n) + 3\n B = [0] * 4\n B... | {"fn_name": "find_a", "inputs": [[[1, 2, 3, 4], 2], [[38, 200, -18, 45], 1], [[1, 0, 0, 1], 5], [[0, 2, 0, 3], -2], [[-20, 1, -3, 14], -5], [[1, 2, 3, 5], 100], [[0, 4, 6, 13], 100]], "outputs": [[3], [200], [20], [-126], [-44402], [60560100487003612846322657690093088848428068520476594299], [335254562473098582210532865... | introductory | https://www.codewars.com/kata/5d1eb2db874bdf9bf6a4b2aa |
def find_a(array, n):
|
4,094 | Given an array of integers.
Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers.
If the input array is empty or null, return an empty array.
# Example
For input `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]`, you should return `[10... | ["def count_positives_sum_negatives(arr):\n if not arr: return []\n pos = 0\n neg = 0\n for x in arr:\n if x > 0:\n pos += 1\n if x < 0:\n neg += x\n return [pos, neg]", "def count_positives_sum_negatives(arr):\n pos = sum(1 for x in arr if x > 0)\n neg = sum(x for x in ... | {"fn_name": "count_positives_sum_negatives", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]], [[0, 2, 3, 0, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14]], [[1]], [[-1]], [[0, 0, 0, 0, 0, 0, 0, 0, 0]], [[]]], "outputs": [[[10, -65]], [[8, -50]], [[1, 0]], [[0, -1]], [[0, 0]], [[]]]} | introductory | https://www.codewars.com/kata/576bb71bbbcf0951d5000044 |
def count_positives_sum_negatives(arr):
|
4,095 | Given two strings, the first being a random string and the second being the same as the first, but with three added characters somewhere in the string (three same characters),
Write a function that returns the added character
### E.g
```
string1 = "hello"
string2 = "aaahello"
// => 'a'
```
The above is just an exa... | ["from collections import Counter\n\ndef added_char(s1, s2): \n return next((Counter(s2) - Counter(s1)).elements())", "def added_char(s1, s2): \n for i in s2:\n if s1.count(i) != s2.count(i):\n return i", "from functools import reduce\nfrom operator import xor\n\ndef added_char(s1, s2): \n retur... | {"fn_name": "added_char", "inputs": [["hello", "checlclo"], ["aabbcc", "aacccbbcc"], ["abcde", "2db2a2ec"]], "outputs": [["c"], ["c"], ["2"]]} | introductory | https://www.codewars.com/kata/5971b219d5db74843a000052 |
def added_char(s1, s2):
|
4,096 | Write a function called that takes a string of parentheses, and determines if the order of the parentheses is valid. The function should return `true` if the string is valid, and `false` if it's invalid.
## Examples
```
"()" => true
")(()))" => false
"(" => false
"(())((()())())... | ["def valid_parentheses(string):\n cnt = 0\n for char in string:\n if char == '(': cnt += 1\n if char == ')': cnt -= 1\n if cnt < 0: return False\n return True if cnt == 0 else False", "def valid_parentheses(string):\n count = 0\n for i in string:\n if i == \"(\":\n ... | {"fn_name": "valid_parentheses", "inputs": [[")"], ["("], [""], ["hi)("], ["hi(hi)"], ["hi(hi)("], ["((())()())"], ["(c(b(a)))(d)"], ["hi(hi))("], ["())(()"]], "outputs": [[false], [false], [true], [false], [true], [false], [true], [true], [false], [false]]} | introductory | https://www.codewars.com/kata/52774a314c2333f0a7000688 |
def valid_parentheses(string):
|
4,097 | Hi guys, welcome to introduction to DocTesting.
The kata is composed of two parts; in part (1) we write three small functions, and in part (2) we write a few doc tests for those functions.
Lets talk about the functions first...
The reverse_list function takes a list and returns the reverse of it.
If given an... | ["def reverse_list(x):\n \"\"\"Takes an list and returns the reverse of it. \n If x is empty, return [].\n \n >>> reverse_list([1, 2, 3, 4])\n [4, 3, 2, 1]\n >>> reverse_list([])\n []\n \"\"\" \n \n return x[::-1]\n\ndef sum_list(x):\n \"\"\"Takes a list, and returns the sum of that lis... | {"fn_name": "reverse_list", "inputs": [[[1, 2, 3]], [[]]], "outputs": [[[3, 2, 1]], [[]]]} | introductory | https://www.codewars.com/kata/58e4033b5600a17be1000103 |
def reverse_list(x):
|
4,098 | # Task
Your Informatics teacher at school likes coming up with new ways to help you understand the material. When you started studying numeral systems, he introduced his own numeral system, which he's convinced will help clarify things. His numeral system has base 26, and its digits are represented by English capital ... | ["def new_numeral_system(n):\n a = [c for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' if c <= n]\n return ['{} + {}'.format(a[i], a[-1-i]) for i in range((len(a) + 1) // 2)]", "new_numeral_system=lambda n:['%c + %c'%(65+i,ord(n)-i)for i in range(ord(n)-63>>1)]", "def new_numeral_system(number):\n return [(chr(65+i) + ' ... | {"fn_name": "new_numeral_system", "inputs": [["G"], ["A"], ["D"], ["E"], ["O"]], "outputs": [[["A + G", "B + F", "C + E", "D + D"]], [["A + A"]], [["A + D", "B + C"]], [["A + E", "B + D", "C + C"]], [["A + O", "B + N", "C + M", "D + L", "E + K", "F + J", "G + I", "H + H"]]]} | introductory | https://www.codewars.com/kata/5888445107a0d57711000032 |
def new_numeral_system(number):
|
4,099 | Your work is to write a method that takes a value and an index, and returns the value with the bit at given index flipped.
The bits are numbered from the least significant bit (index 1).
Example:
```python
flip_bit(15, 4) == 7 # 15 in binary is 1111, after flipping 4th bit, it becomes 0111, i.e. 7
flip_bit(15, 5) == ... | ["def flip_bit(value, bit_index):\n return value ^ (1 << (bit_index-1))", "flip_bit=lambda n,k:n^1<<k-1", "def flip_bit(value, bit_index):\n return value ^ 2 ** (bit_index-1)", "def flip_bit(v, b):\n return 1<<b-1 ^ v", "flip_bit=lambda v, i: int(\"\".join([l if 64-i!=k else \"0\" if l==\"1\" else \"1\" for k,... | {"fn_name": "flip_bit", "inputs": [[0, 16], [2147483647, 31], [127, 8]], "outputs": [[32768], [1073741823], [255]]} | introductory | https://www.codewars.com/kata/560e80734267381a270000a2 |
def flip_bit(value, bit_index):
|
4,100 | Reverse every other word in a given string, then return the string. Throw away any leading or trailing whitespace, while ensuring there is exactly one space between each word. Punctuation marks should be treated as if they are a part of the word in this kata. | ["def reverse_alternate(string):\n return \" \".join(y[::-1] if x%2 else y for x,y in enumerate(string.split()))", "def reverse_alternate(s):\n return ' '.join(w[::-1] if i % 2 else w for i, w in enumerate(s.split()))", "def reverse_alternate(string):\n #your code here\n if string == \"\":\n return \"\"\n e... | {"fn_name": "reverse_alternate", "inputs": [["Did it work?"], ["I really hope it works this time..."], ["Reverse this string, please!"], ["Have a beer"], [" "], ["This is not a test "], ["This is a test "]], "outputs": [["Did ti work?"], ["I yllaer hope ti works siht time..."], ["Reverse siht string, !esaelp"]... | introductory | https://www.codewars.com/kata/58d76854024c72c3e20000de |
def reverse_alternate(string):
|
4,101 | Write a function that solves an algebraic expression given as a string.
* The expression can include only sums and products.
* The numbers in the expression are in standard notation (NOT scientific).
* In contrast, the function should return a string with the calculated value given in scientific notation with 5 de... | ["def sum_prod(strexpression):\n return \"%.5e\" %(eval(strexpression))", "def sum_prod(strexpression):\n # resisting using the dreaded eval :-)\n # split things up into numbers and operators\n strexpression = strexpression.replace(\"*\", \" * \").replace(\"+\", \" + \")\n equation = [float(x) if x[0].is... | {"fn_name": "sum_prod", "inputs": [["5*4+6"], ["5+4*6"], ["3*8+6*5"], ["5*8+6*3*2"], ["5.4*4.0+6.2+8.0"], ["0.5*1.2*56+9.6*5*81+1"], ["1"], ["1.333333333*1.23456789+0.003*0.002"]], "outputs": [["2.60000e+01"], ["2.90000e+01"], ["5.40000e+01"], ["7.60000e+01"], ["3.58000e+01"], ["3.92260e+03"], ["1.00000e+00"], ["1.6461... | introductory | https://www.codewars.com/kata/5759513c94aba6a30900094d |
def sum_prod(strexpression):
|
4,102 | For "x", determine how many positive integers less than or equal to "x" are odd but not prime. Assume "x" is an integer between 1 and 10000.
Example: 5 has three odd numbers (1,3,5) and only the number 1 is not prime, so the answer is 1
Example: 10 has five odd numbers (1,3,5,7,9) and only 1 and 9 are not prime, so t... | ["def not_prime(x):\n if x == 1: return True\n for y in range(2, int(x ** 0.5) + 1):\n if x % y == 0:\n return True\n return False\ndef odd_not_prime(n):\n return sum(not_prime(x) for x in range(1, n + 1, 2))", "def odd_not_prime(n):\n return 1 + sum( any(not x%y for y in range(3,int(x*... | {"fn_name": "odd_not_prime", "inputs": [[5], [10], [99]], "outputs": [[1], [2], [26]]} | introductory | https://www.codewars.com/kata/5a9996fa8e503f2b4a002e7a |
def odd_not_prime(n):
|
4,103 | Santa is coming to town and he needs your help finding out who's been naughty or nice. You will be given an entire year of JSON data following this format:
Your function should return `"Naughty!"` or `"Nice!"` depending on the total number of occurrences in a given year (whichever one is greater). If both are equal, r... | ["def naughty_or_nice(data):\n nice = 0\n for month in data:\n for day in data[month]:\n nice += 1 if data[month][day] == \"Nice\" else -1\n return \"Nice!\" if nice >= 0 else \"Naughty!\"\n", "import json\n\ndef naughty_or_nice(data):\n parsed_data = json.dumps(data)\n return \"Nice!\"... | {"fn_name": "naughty_or_nice", "inputs": [[{"January": {"1": "Naughty", "2": "Nice", "3": "Naughty", "4": "Nice", "5": "Naughty", "6": "Nice", "7": "Naughty", "8": "Nice", "9": "Naughty", "10": "Nice", "11": "Naughty", "12": "Nice", "13": "Naughty", "14": "Nice", "15": "Naughty", "16": "Nice", "17": "Naughty", "18": "N... | introductory | https://www.codewars.com/kata/5662b14e0a1fb8320a00005c |
def naughty_or_nice(data):
|
4,104 | # Task
**_Given_** an *array/list [] of n integers* , *find maximum triplet sum in the array* **_Without duplications_** .
___
# Notes :
* **_Array/list_** size is *at least 3* .
* **_Array/list_** numbers could be a *mixture of positives , negatives and zeros* .
* **_Repetition_** of numbers in *the array/list ... | ["def max_tri_sum(numbers):\n return sum(sorted(set(numbers))[-3:])", "from heapq import nlargest\n\ndef max_tri_sum(numbers):\n return sum(nlargest(3, set(numbers)))", "def max_tri_sum(n):\n return sum(sorted(set(n))[-3:])", "def max_tri_sum(nums): return sum(sorted(set(nums))[-3:])\n", "max_tri_sum=lambda l:... | {"fn_name": "max_tri_sum", "inputs": [[[3, 2, 6, 8, 2, 3]], [[2, 9, 13, 10, 5, 2, 9, 5]], [[2, 1, 8, 0, 6, 4, 8, 6, 2, 4]], [[-3, -27, -4, -2, -27, -2]], [[-14, -12, -7, -42, -809, -14, -12]], [[-13, -50, 57, 13, 67, -13, 57, 108, 67]], [[-7, 12, -7, 29, -5, 0, -7, 0, 0, 29]], [[-2, 0, 2]], [[-2, -4, 0, -9, 2]], [[-5, ... | introductory | https://www.codewars.com/kata/5aa1bcda373c2eb596000112 |
def max_tri_sum(numbers):
|
4,105 | We have the first value of a certain sequence, we will name it ```initVal```.
We define pattern list, ```patternL```, an array that has the differences between contiguous terms of the sequence.
``` E.g: patternL = [k1, k2, k3, k4]```
The terms of the sequence will be such values that:
```python
term1 = initVal
term2... | ["from itertools import cycle\n\ndef sumDig_nthTerm(initVal, patternL, nthTerm):\n \n for c, i in enumerate(cycle(patternL), 2):\n initVal += i\n \n if c == nthTerm:\n return sum(int(v) for v in str(initVal))", "def sumDig_nthTerm(base, cycle, k):\n loop, remaining = divmod(k - ... | {"fn_name": "sumDig_nthTerm", "inputs": [[10, [2, 1, 3], 6], [10, [2, 1, 3], 15], [10, [2, 1, 3], 50], [10, [2, 1, 3], 78], [10, [2, 1, 3], 157], [10, [2, 2, 5, 8], 6], [10, [2, 2, 5, 8], 15], [10, [2, 2, 5, 8], 50], [10, [2, 2, 5, 8], 78], [10, [2, 2, 5, 8], 157], [100, [2, 2, 5, 8], 6], [100, [2, 2, 5, 8], 15], [100,... | introductory | https://www.codewars.com/kata/55ffb44050558fdb200000a4 |
def sumDig_nthTerm(initVal, patternL, nthTerm):
|
4,106 | ### self_converge
`Goal`: Given a number (with a minimum of 3 digits), return the number of iterations it takes to arrive at a derived number that converges on to itself, as per the following [Kaprekar][Kaprekar] routine. As a learning exercise, come up with a solution that uses recursion. The
following steps would be ... | ["def self_converge(number):\n n, cycle = str(number), set()\n while n not in cycle:\n cycle.add(n)\n s = ''.join(sorted(n))\n n = '%0*d' % (len(n), int(s[::-1]) - int(s))\n return -1 if not int(n) else len(cycle)", "def self_converge(n, seen=None):\n s, seen = \"\".join(sorted(str(n)))... | {"fn_name": "self_converge", "inputs": [[4321], [2111], [211], [90900], [992299229]], "outputs": [[4], [6], [7], [9], [22]]} | introductory | https://www.codewars.com/kata/54ab259e15613ce0c8001bab |
def self_converge(number):
|
4,107 | # Task
Given the birthdates of two people, find the date when the younger one is exactly half the age of the other.
# Notes
* The dates are given in the format YYYY-MM-DD and are not sorted in any particular order
* Round **down** to the nearest day
* Return the result as a string, like the input dates | ["from dateutil.parser import parse\n\ndef half_life(*persons):\n p1,p2 = sorted(map(parse, persons))\n return str( p2+(p2-p1) )[:10]", "from datetime import datetime as dt\n\ndef half_life(p1, p2):\n d1, d2 = (dt.strptime(p, \"%Y-%m-%d\") for p in sorted((p1, p2)))\n return (d2 + (d2 - d1)).strftime(\"%Y-%... | {"fn_name": "half_life", "inputs": [["1990-12-06", "2000-02-29"], ["2012-03-31", "1990-06-09"], ["1984-08-14", "1990-04-17"], ["2000-06-30", "1978-03-17"], ["1969-12-20", "2000-10-07"]], "outputs": [["2009-05-24"], ["2034-01-21"], ["1995-12-19"], ["2022-10-14"], ["2031-07-26"]]} | introductory | https://www.codewars.com/kata/5d472159d4f8c3001d81b1f8 |
def half_life(person1, person2):
|
4,108 | # Task
Write a function named `sumEvenNumbers`, taking a sequence of numbers as single parameter. Your function must return the sum of **the even values** of this sequence.
Only numbers without decimals like `4` or `4.0` can be even.
## Input
* sequence of numbers: those numbers could be integers and/or floats.
... | ["def sum_even_numbers(seq): \n return sum(n for n in seq if not n % 2)", "def sum_even_numbers(seq): \n return sum(x for x in seq if x%2==0)", "def sum_even_numbers(seq): \n return sum(filter(lambda n: n%2==0, seq))", "def sum_even_numbers(seq): \n # your code here\n nums = []\n b = 0\n for i in r... | {"fn_name": "sum_even_numbers", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[]], [[1337, 374, 849, 22.5, 19, 16, 0, 0, 16, 32]], [[-16, -32, 20, 21, 41, 42]], [[15397, 12422, 10495, 22729, 23921, 18326, 27955, 24073, 23690, 15002, 11615, 15682, 24346, 16725, 17252, 20467, 20493, 17807, 13041, 25861, 22471, 22747, 24... | introductory | https://www.codewars.com/kata/586beb5ba44cfc44ed0006c3 |
def sum_even_numbers(seq):
|
4,109 | In this kata you will create a function that takes a list of non-negative integers and strings and returns a new list with the strings filtered out.
### Example
```python
filter_list([1,2,'a','b']) == [1,2]
filter_list([1,'a','b',0,15]) == [1,0,15]
filter_list([1,2,'aasf','1','123',123]) == [1,2,123]
``` | ["def filter_list(l):\n 'return a new list with the strings filtered out'\n return [i for i in l if not isinstance(i, str)]\n", "def filter_list(l):\n 'return a new list with the strings filtered out'\n return [x for x in l if type(x) is not str]", "def filter_list(l):\n 'return a new list with the strings filtere... | {"fn_name": "filter_list", "inputs": [[[1, 2, "a", "b"]], [[1, "a", "b", 0, 15]], [[1, 2, "aasf", "1", "123", 123]], [["a", "b", "1"]]], "outputs": [[[1, 2]], [[1, 0, 15]], [[1, 2, 123]], [[]]]} | introductory | https://www.codewars.com/kata/53dbd5315a3c69eed20002dd |
def filter_list(l):
|
4,110 | Given a name, turn that name into a perfect square matrix (nested array with the amount of arrays equivalent to the length of each array).
You will need to add periods (`.`) to the end of the name if necessary, to turn it into a matrix.
If the name has a length of 0, return `"name must be at least one letter"`
## ... | ["from math import ceil\n\ndef matrixfy(s):\n if not s: return \"name must be at least one letter\"\n x = ceil(len(s)**.5)\n it = iter(s.ljust(x*x,'.'))\n return [ [next(it) for _ in range(x)] for _ in range(x)]", "def matrixfy(st):\n if not st:\n return 'name must be at least one letter'\n n ... | {"fn_name": "matrixfy", "inputs": [[""], ["G"], ["Beyonce"], ["Franklin"], ["Bill"], ["Frank"]], "outputs": [["name must be at least one letter"], [[["G"]]], [[["B", "e", "y"], ["o", "n", "c"], ["e", ".", "."]]], [[["F", "r", "a"], ["n", "k", "l"], ["i", "n", "."]]], [[["B", "i"], ["l", "l"]]], [[["F", "r", "a"], ["n",... | introductory | https://www.codewars.com/kata/5a91e0793e9156ccb0003f6e |
def matrixfy(st):
|
4,111 | Learning to code around your full time job is taking over your life. You realise that in order to make significant steps quickly, it would help to go to a coding bootcamp in London.
Problem is, many of them cost a fortune, and those that don't still involve a significant amount of time off work - who will pay your mor... | ["def sabb(stg, value, happiness):\n sabbatical = (value + happiness + sum(1 for c in stg if c in \"sabbatical\")) > 22\n return \"Sabbatical! Boom!\" if sabbatical else \"Back to your desk, boy.\"", "def sabb(s, value, happiness):\n score = sum(c in \"sabticl\" for c in s.lower()) + value + happiness\n ret... | {"fn_name": "sabb", "inputs": [["Can I have a sabbatical?", 5, 5], ["Why are you shouting?", 7, 2], ["What do you mean I cant learn to code??", 8, 9], ["Please calm down", 9, 1], ["I can?! Nice. FaC..Im coming :D", 9, 9]], "outputs": [["Sabbatical! Boom!"], ["Back to your desk, boy."], ["Sabbatical! Boom!"], ["Back to ... | introductory | https://www.codewars.com/kata/57fe50d000d05166720000b1 |
def sabb(s, value, happiness):
|
4,112 | Find the second-to-last element of a list.
Example:
```python
penultimate([1,2,3,4]) # => 3
penultimate(["Python is dynamic"]) # => 'i'
(courtesy of [haskell.org](http://www.haskell.org/haskellwiki/99_questions/1_to_10))
``` | ["def penultimate(a):\n return a[-2]\n", "def penultimate(a):\n # implement here\n try:\n return a[-2]\n except:\n return None", "def penultimate(a):\n try:\n return a[-2]\n except IndexError:\n pass", "def penultimate(a):\n return a[len(a)-2]", "from operator import itemgetter\npenul... | {"fn_name": "penultimate", "inputs": [[[1, 2, 3, 4]], ["hello"]], "outputs": [[3], ["l"]]} | introductory | https://www.codewars.com/kata/54162d1333c02486a700011d |
def penultimate(a):
|
4,113 | Write a function that takes an integer and returns an array `[A, B, C]`, where `A` is the number of multiples of 3 (but not 5) below the given integer, `B` is the number of multiples of 5 (but not 3) below the given integer and `C` is the number of multiples of 3 and 5 below the given integer.
For example, `solution(... | ["def solution(number):\n A = (number - 1) // 3\n B = (number - 1) // 5\n C = (number - 1) // 15 \n return [A - C, B - C, C]", "def solution(number):\n n = number - 1\n a, b, c = n // 3, n // 5, n // 15\n return [a - c, b - c, c]", "def solution(n):\n n -= 1\n return [n//3-n//15, n//5-n//15, n... | {"fn_name": "solution", "inputs": [[20], [2020], [4], [2], [30], [300], [14], [141], [1415], [91415]], "outputs": [[[5, 2, 1]], [[539, 269, 134]], [[1, 0, 0]], [[0, 0, 0]], [[8, 4, 1]], [[80, 40, 19]], [[4, 2, 0]], [[37, 19, 9]], [[377, 188, 94]], [[24377, 12188, 6094]]]} | introductory | https://www.codewars.com/kata/51dda84f91f5b5608b0004cc |
def solution(number):
|
4,114 | A category page displays a set number of products per page, with pagination at the bottom allowing the user to move from page to page.
Given that you know the page you are on, how many products are in the category in total, and how many products are on any given page, how would you output a simple string showing which... | ["def pagination_text(page_number, page_size, total_products):\n first = page_size * (page_number - 1) + 1\n last = min(total_products, first + page_size - 1)\n return \"Showing %d to %d of %d Products.\" % (first, last, total_products)", "def pagination_text(page_number, page_size, total_products):\n lower... | {"fn_name": "pagination_text", "inputs": [[1, 10, 30], [3, 10, 26], [1, 10, 8], [2, 30, 350], [1, 23, 30], [2, 23, 30], [43, 15, 3456]], "outputs": [["Showing 1 to 10 of 30 Products."], ["Showing 21 to 26 of 26 Products."], ["Showing 1 to 8 of 8 Products."], ["Showing 31 to 60 of 350 Products."], ["Showing 1 to 23 of 3... | introductory | https://www.codewars.com/kata/545cff101288c1d2da0006fb |
def pagination_text(page_number, page_size, total_products):
|
4,115 | You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer `N`. Write a method that takes the array as an argument and returns this "outlier" `N`.
... | ["def find_outlier(int):\n odds = [x for x in int if x%2!=0]\n evens= [x for x in int if x%2==0]\n return odds[0] if len(odds)<len(evens) else evens[0]\n", "def find_outlier(integers):\n even, odd = 0, 0\n for i in integers:\n if i % 2:\n even += 1\n last_even = i\n else:\n odd += 1\n ... | {"fn_name": "find_outlier", "inputs": [[[0, 1, 2]], [[1, 2, 3]]], "outputs": [[1], [2]]} | introductory | https://www.codewars.com/kata/5526fc09a1bbd946250002dc |
def find_outlier(integers):
|
4,116 | *Are you a file extension master? Let's find out by checking if Bill's files are images or audio files. Please use regex if available natively for your language.*
You will create 2 string methods:
- **isAudio/is_audio**, matching 1 or + uppercase/lowercase letter(s) (combination possible), with the extension .mp3, .f... | ["def is_audio(filename):\n name, ext = filename.split('.')\n return name.isalpha() and ext in {'mp3', 'flac', 'alac', 'aac'}\n\n\ndef is_img(filename):\n name, ext = filename.split('.')\n return name.isalpha() and ext in {'jpg', 'jpeg', 'png', 'bmp', 'gif'}", "import re\ndef is_audio(file_name):\n retur... | {"fn_name": "is_audio", "inputs": [["Nothing Else Matters.mp3"], ["NothingElseMatters.mp3"], ["DaftPunk.FLAC"], ["DaftPunk.flac"], ["AmonTobin.aac"], [" Amon Tobin.alac"], ["tobin.alac"]], "outputs": [[false], [true], [false], [true], [true], [false], [true]]} | introductory | https://www.codewars.com/kata/574bd867d277832448000adf |
def is_audio(file_name):
|
4,117 | Given a random string consisting of numbers, letters, symbols, you need to sum up the numbers in the string.
Note:
- Consecutive integers should be treated as a single number. eg, `2015` should be treated as a single number `2015`, NOT four numbers
- All the numbers should be treaded as positive integer. eg, `11-14`... | ["import re\ndef sum_from_string(string):\n d = re.findall(\"\\d+\",string)\n return sum(int(i) for i in d)", "import re\ndef sum_from_string(s):\n return sum(map(int, re.findall(r'\\d+', s)))", "from re import findall\n\n\ndef sum_from_string(string):\n return sum(int(a) for a in findall(r'\\d+', string))\... | {"fn_name": "sum_from_string", "inputs": [["In 2015, I want to know how much does iPhone 6+ cost?"], ["1+1=2"], ["e=mc^2"], ["aHR0cDovL3d3dy5jb2Rld2Fycy5jb20va2F0YS9uZXcvamF2YXNjcmlwdA=="], ["a30561ff4fb19170aa598b1431b52edad1fcc3e0"], ["x1KT CmZ__\rYouOY8Uqu-ETtz"], ["x1KT-8&*@\"CmZ__\rYouO __Y8Uq\\u-ETtz"], [""], ... | introductory | https://www.codewars.com/kata/55da6c52a94744b379000036 |
def sum_from_string(string):
|
4,118 | The characters of Chima need your help. Their weapons got mixed up! They need you to write a program that accepts the name of a character in Chima then tells which weapon he/she owns.
For example: for the character `"Laval"` your program should return the solution `"Laval-Shado Valious"`
You must complete the followi... | ["def identify_weapon(character):\n tbl = {\n \"Laval\" : \"Laval-Shado Valious\",\n \"Cragger\" : \"Cragger-Vengdualize\",\n \"Lagravis\" : \"Lagravis-Blazeprowlor\",\n \"Crominus\" : \"Crominus-Grandorius\",\n \"Tormak\" : \"Tormak-Tygafyre\",\n \"LiElla\" : \"LiElla-Roarburn\... | {"fn_name": "identify_weapon", "inputs": [["Laval"], ["Crominus"], ["Lagravis"], ["Cragger"], ["Tormak"], ["LiElla"], ["G'loona"], ["Stinkin gorillas"], ["qwertyuiopasdfghjklzxcvbnm"]], "outputs": [["Laval-Shado Valious"], ["Crominus-Grandorius"], ["Lagravis-Blazeprowlor"], ["Cragger-Vengdualize"], ["Tormak-Tygafyre"],... | introductory | https://www.codewars.com/kata/5470ae03304c1250b4000e57 |
def identify_weapon(character):
|
4,119 | ## Emotional Sort ( ︶︿︶)
You'll have a function called "**sortEmotions**" that will return an array of **emotions** sorted. It has two parameters, the first parameter called "**arr**" will expect an array of **emotions** where an **emotion** will be one of the following:
- **:D** -> Super Happy
- **:)** -> Happy
- **... | ["def sort_emotions(arr, order):\n return sorted(arr, key=[':D',':)',':|',':(','T_T'].index, reverse=not order)", "def get_face(face):\n faces = { ':D':0, ':)':1, ':|':2, ':(':3, 'T_T':4 }\n return faces[face]\n\ndef sort_emotions(arr, order):\n return sorted(arr, key=get_face, reverse= not order)\n", "def ... | {"fn_name": "sort_emotions", "inputs": [[[":D", "T_T", ":D", ":("], true], [["T_T", ":D", ":(", ":("], true], [[":)", "T_T", ":)", ":D", ":D"], true], [[":D", "T_T", ":D", ":("], false], [["T_T", ":D", ":(", ":("], false], [[":)", "T_T", ":)", ":D", ":D"], false], [[], false], [[], true]], "outputs": [[[":D", ":D", ":(... | introductory | https://www.codewars.com/kata/5a86073fb17101e453000258 |
def sort_emotions(arr, order):
|
4,120 | Python dictionaries are inherently unsorted. So what do you do if you need to sort the contents of a dictionary?
Create a function that returns a sorted list of `(key, value)` tuples (Javascript: arrays of 2 items).
The list must be sorted by the `value` and be sorted **largest to smallest**.
## Examples
```python
... | ["def sort_dict(d):\n return sorted(d.items(), key=lambda x: x[1], reverse=True)", "from operator import itemgetter\n\ndef sort_dict(d):\n 'return a sorted list of tuples from the dictionary'\n return sorted(d.items(), key=itemgetter(1), reverse=True)", "def sort_dict(d):\n 'return a sorted list of tuples from the ... | {"fn_name": "sort_dict", "inputs": [[{"1": 3, "2": 2, "3": 1}], [{"1": 2, "2": 4, "3": 6}], [{"1": 5, "3": 10, "2": 2, "6": 3, "8": 8}], [{"a": 6, "b": 2, "c": 4}]], "outputs": [[[[1, 3], [2, 2], [3, 1]]], [[[3, 6], [2, 4], [1, 2]]], [[[3, 10], [8, 8], [1, 5], [6, 3], [2, 2]]], [[["a", 6], ["c", 4], ["b", 2]]]]} | introductory | https://www.codewars.com/kata/53da6a7e112bd15cbc000012 |
def sort_dict(d):
|
4,121 | You are making your very own boardgame. The game is played by two opposing players, featuring a 6 x 6 tile system, with the players taking turns to move their pieces (similar to chess). The design is finished, now it's time to actually write and implement the features. Being the good programmer you are, you carefully p... | ["def fight_resolve(d, a):\n return -1 if d.islower() == a.islower() else d if d.lower() + a.lower() in \"ka sp as pk\" else a", "def fight_resolve(d, a):\n return -1 if d.islower() == a.islower() else d if f\"{d}{a}\".lower() in \"aspka\" else a", "def fight_resolve(defender, attacker):\n res = attacker\n ... | {"fn_name": "fight_resolve", "inputs": [["K", "A"], ["S", "A"], ["k", "s"], ["a", "a"], ["k", "A"], ["K", "a"]], "outputs": [[-1], [-1], [-1], [-1], ["k"], ["K"]]} | introductory | https://www.codewars.com/kata/58558673b6b0e5a16b000028 |
def fight_resolve(defender, attacker):
|
4,122 | This is the simple version of Shortest Code series. If you need some challenges, please try the [challenge version](http://www.codewars.com/kata/56f928b19982cc7a14000c9d)
## Task:
Every uppercase letter is Father, The corresponding lowercase letters is the Son.
Give you a string ```s```, If the father and s... | ["def sc(strng):\n seen = set(strng)\n return ''.join(a for a in strng if a.swapcase() in seen)\n", "def sc(s):\n return \"\".join(ch for ch in s if ch.upper() in s and ch.lower() in s);", "def sc(s):\n xs = set(s)\n return ''.join(c for c in s if c.swapcase() in xs)", "def sc(s):\n return ''.join([e ... | {"fn_name": "sc", "inputs": [["Aab"], ["AabBc"], ["SONson"], ["FfAaTtHhEeRr"], ["SONsonfather"], ["sonfather"], ["DONKEYmonkey"], ["monkeyDONKEY"], ["BANAna"]], "outputs": [["Aa"], ["AabB"], ["SONson"], ["FfAaTtHhEeRr"], ["SONson"], [""], ["ONKEYonkey"], ["onkeyONKEY"], ["ANAna"]]} | introductory | https://www.codewars.com/kata/56fe9a0c11086cd842000008 |
def sc(s):
|
4,123 | A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible
pairs. For example `12` is the LCM of `(1, 12), (2, 12), (3,4)` etc. For a given positive integer N, the number of different integer pairs with LCM is equal to N can be called the LCM cardinality of that number N. In this ka... | ["from itertools import combinations\nfrom math import gcd\n\n\ndef lcm_cardinality(n):\n return 1 + sum(1 for a, b in combinations(divisors(n), 2) if lcm(a, b) == n)\n \ndef divisors(n):\n d = {1, n}\n for k in range(2, int(n**0.5) + 1):\n if n % k == 0:\n d.add(k)\n d.add(... | {"fn_name": "lcm_cardinality", "inputs": [[1], [12], [24], [25], [101101291], [12345676], [1251562], [625], [9801], [30858025]], "outputs": [[1], [8], [11], [3], [5], [68], [41], [5], [23], [63]]} | introductory | https://www.codewars.com/kata/5c45bef3b6adcb0001d3cc5f |
def lcm_cardinality(n):
|
4,124 | Write a program to determine if a string contains only unique characters.
Return true if it does and false otherwise.
The string may contain any of the 128 ASCII characters.
Characters are case-sensitive, e.g. 'a' and 'A' are considered different characters. | ["def has_unique_chars(s):\n return len(s) == len(set(s))", "def has_unique_chars(str):\n return len(set(str))==len(str)", "def has_unique_chars(s):\n return len(set(s)) == len(s)", "def has_unique_chars(s):\n return len(s) <= 128 and len(s) == len(set(s))", "def has_unique_chars(str):\n return len(str) == len... | {"fn_name": "has_unique_chars", "inputs": [[" nAa"], ["abcdef"], ["++-"]], "outputs": [[false], [true], [false]]} | introductory | https://www.codewars.com/kata/553e8b195b853c6db4000048 |
def has_unique_chars(str):
|
4,125 | You would like to get the 'weight' of a name by getting the sum of the ascii values. However you believe that capital letters should be worth more than mere lowercase letters. Spaces, numbers, or any other character are worth 0.
Normally in ascii
a has a value of 97
A has a value of 65
' ' has a value of ... | ["def get_weight(name):\n return sum(ord(a) for a in name.swapcase() if a.isalpha())", "def get_weight(name):\n return sum(ord(c.swapcase()) for c in name if c.isalpha())", "import string as q\n\ndef get_weight(name):\n return sum(ord(char.swapcase()) for char in name if char in q.ascii_letters)", "def get_wei... | {"fn_name": "get_weight", "inputs": [["Joe"], ["CJ"], ["cj"], ["George Washington"], ["Billy Bob Joe"], ["King George II"], ["r2d2"], ["R2D2"], ["C3PO"]], "outputs": [[254], [205], [141], [1275], [909], [1012], [150], [214], [322]]} | introductory | https://www.codewars.com/kata/582cb3a637c5583f2200005d |
def get_weight(name):
|
4,126 | # Story
Due to lack of maintenance the minute-hand has fallen off Town Hall clock face.
And because the local council has lost most of our tax money to a Nigerian email scam there are no funds to fix the clock properly.
Instead, they are asking for volunteer programmers to write some code that tell the time by only... | ["def what_time_is_it(angle):\n hr = int(angle // 30)\n mn = int((angle % 30) * 2)\n if hr == 0:\n hr = 12\n return '{:02d}:{:02d}'.format(hr, mn)", "def what_time_is_it(angle):\n angle %= 360\n h, m = divmod(angle, 30)\n return '{:02}:{:02}'.format(int(h or 12), int(m * 2))", "import time\n... | {"fn_name": "what_time_is_it", "inputs": [[0], [360], [90], [180], [270], [30], [40], [45], [50], [60]], "outputs": [["12:00"], ["12:00"], ["03:00"], ["06:00"], ["09:00"], ["01:00"], ["01:20"], ["01:30"], ["01:40"], ["02:00"]]} | introductory | https://www.codewars.com/kata/59752e1f064d1261cb0000ec |
def what_time_is_it(angle):
|
4,127 | The integers 14 and 15, are contiguous (1 the difference between them, obvious) and have the same number of divisors.
```python
14 ----> 1, 2, 7, 14 (4 divisors)
15 ----> 1, 3, 5, 15 (4 divisors)
```
The next pair of contiguous integers with this property is 21 and 22.
```python
21 -----> 1, 3, 7, 21 (4 divisors)
22 --... | ["def count_pairs_int(d, m):\n return sum(1 for i in range(1, m - d) if divisors(i) == divisors(i + d))\n\ndef divisors(n):\n return sum(1 + (n // k != k) for k in range(1, int(n**0.5) + 1) if n % k == 0)\n", "import numpy as np\n\nN = 100001\nxs = np.ones(N)\nxs[:2] = 0\nfor i in range(2, N//2):\n xs[i*2::i] ... | {"fn_name": "count_pairs_int", "inputs": [[1, 50], [3, 100], [3, 200], [6, 350], [6, 1000], [7, 1500], [7, 2500], [7, 3000], [9, 4000], [9, 5000], [11, 5000]], "outputs": [[8], [7], [18], [86], [214], [189], [309], [366], [487], [622], [567]]} | introductory | https://www.codewars.com/kata/55f1614853ddee8bd4000014 |
def count_pairs_int(diff, n_max):
|
4,128 | In order to prove it's success and gain funding, the wilderness zoo needs to prove to environmentalists that it has x number of mating pairs of bears.
You must check within string (s) to find all of the mating pairs, and return a string containing only them. Line them up for inspection.
Rules:
Bears are either 'B' (... | ["import re\n\ndef bears(n, s):\n a = re.findall(r\"B8|8B\", s)\n return [\"\".join(a), len(a) >= n]", "import re\ndef bears(x,s):\n r = re.findall(r'8B|B8', s)\n return [''.join(r),len(r)>=x]", "from regex import findall\n\ndef bears(x, s):\n res = findall(r\"(B8|8B)\", s)\n return [''.join(res), len... | {"fn_name": "bears", "inputs": [[7, "8j8mBliB8gimjB8B8jlB"], [3, "88Bifk8hB8BB8BBBB888chl8BhBfd"], [8, "8"], [1, "j8BmB88B88gkBBlf8hg8888lbe88"], [0, "8j888aam"]], "outputs": [[["B8B8B8", false]], [["8BB8B8B88B", true]], [["", false]], [["8BB88B", true]], [["", true]]]} | introductory | https://www.codewars.com/kata/57d165ad95497ea150000020 |
def bears(x,s):
|
4,129 | You managed to send your friend to queue for tickets in your stead, but there is a catch: he will get there only if you tell him how much that is going to take. And everybody can only take one ticket at a time, then they go back in the last position of the queue if they need more (or go home if they are fine).
Each ti... | ["def queue(queuers,pos):\n return sum(min(queuer, queuers[pos] - (place > pos)) for place, queuer in enumerate(queuers))", "def queue(queuers,pos):\n friendWait = queuers[pos]\n # Divide the line into the front of the line (up to the friend)\n # and back of the line (behind the friend):\n frontOfLine = ... | {"fn_name": "queue", "inputs": [[[2, 5, 3, 6, 4], 0], [[2, 5, 3, 6, 4], 1], [[2, 5, 3, 6, 4], 2], [[2, 5, 3, 6, 4], 3], [[2, 5, 3, 6, 4], 4]], "outputs": [[6], [18], [12], [20], [17]]} | introductory | https://www.codewars.com/kata/5b538734beb8654d6b00016d |
def queue(queuers,pos):
|
4,130 | # Valid HK Phone Number
## Overview
In Hong Kong, a valid phone number has the format ```xxxx xxxx``` where ```x``` is a decimal digit (0-9). For example:
## Task
Define two functions, ```isValidHKPhoneNumber``` and ```hasValidHKPhoneNumber```, that ```return```s whether a given string is a valid HK phone number a... | ["import re\n\nHK_PHONE_NUMBER = '\\d{4} \\d{4}'\n\ndef is_valid_HK_phone_number(number):\n return bool(re.match(HK_PHONE_NUMBER+'\\Z',number))\n\ndef has_valid_HK_phone_number(number):\n return bool(re.search(HK_PHONE_NUMBER,number))", "from re import match, search\n\nis_valid_HK_phone_number = lambda n: match('... | {"fn_name": "is_valid_HK_phone_number", "inputs": [["1234 5678"], ["2359 1478"], ["85748475"], ["3857 4756"], ["sklfjsdklfjsf"], [" 1234 5678 "], ["abcd efgh"], ["9684 2396"], ["836g 2986"], ["0000 0000"], ["123456789"], [" 987 634 "], [" 6 "], ["8A65 2986"], ["8368 2aE6"], ["8c65 2i86"]], "outputs": [[tru... | introductory | https://www.codewars.com/kata/56f54d45af5b1fec4b000cce |
def is_valid_HK_phone_number(number):
|
4,131 | My washing machine uses ```water``` amount of water to wash ```clothes``` amount of clothes. You are given a ```load``` amount of clothes to wash. For each single item of load above the standard amount of clothes, the washing machine will use 10% more water (multiplicative) to clean.
For example, if the amount of clot... | ["def how_much_water(water, clothes, load):\n if load > 2 * clothes:\n return \"Too much clothes\"\n\n if load < clothes:\n return \"Not enough clothes\"\n\n for i in range(load - clothes):\n water *= 1.1\n\n return round(water, 2)", "def how_much_water(l, x, n):\n return \"Too much ... | {"fn_name": "how_much_water", "inputs": [[10, 10, 21], [10, 10, 2], [10, 11, 20], [50, 15, 29], [50, 15, 15]], "outputs": [["Too much clothes"], ["Not enough clothes"], [23.58], [189.87], [50]]} | introductory | https://www.codewars.com/kata/575fa9afee048b293e000287 |
def how_much_water(water, load, clothes):
|
4,132 | Some new animals have arrived at the zoo. The zoo keeper is concerned that perhaps the animals do not have the right tails. To help her, you must correct the broken function to make sure that the second argument (tail), is the same as the last letter of the first argument (body) - otherwise the tail wouldn't fit!
If t... | ["def correct_tail(body, tail):\n return body.endswith(tail)\n", "def correct_tail(body, tail):\n return body[-1] == tail", "def correct_tail(body, tail):\n sub = body[len(body)-len(tail)]\n if sub == tail:\n return True\n else:\n return False", "correct_tail = str.endswith", "def correct_t... | {"fn_name": "correct_tail", "inputs": [["Fox", "x"], ["Rhino", "o"], ["Meerkat", "t"], ["Emu", "t"], ["Badger", "s"], ["Giraffe", "d"]], "outputs": [[true], [true], [true], [false], [false], [false]]} | introductory | https://www.codewars.com/kata/56f695399400f5d9ef000af5 |
def correct_tail(body, tail):
|
4,133 | # Task
John is a programmer. He treasures his time very much. He lives on the `n` floor of a building. Every morning he will go downstairs as quickly as possible to begin his great work today.
There are two ways he goes downstairs: walking or taking the elevator.
When John uses the elevator, he will go through the f... | ["def shortest_time(n, m, speeds):\n lift, open, close, walk = speeds\n return min(\n # taking the elevator\n abs(m - n) * lift + open + close + (n - 1) * lift + open,\n # walking\n (n - 1) * walk\n )", "def shortest_time(n, m, speeds):\n a, b, c, d = spee... | {"fn_name": "shortest_time", "inputs": [[5, 6, [1, 2, 3, 10]], [1, 6, [1, 2, 3, 10]], [5, 5, [1, 2, 3, 10]], [2, 2, [1, 2, 3, 10]], [2, 2, [2, 3, 4, 10]], [5, 4, [1, 2, 3, 10]], [5, 4, [2, 3, 4, 5]], [1, 6, [0, 0, 0, 0]], [1, 6, [0, 2, 0, 0]], [1, 6, [20, 0, 10, 0]]], "outputs": [[12], [0], [11], [8], [10], [12], [20],... | introductory | https://www.codewars.com/kata/5950a4bfc6bf4f433f000031 |
def shortest_time(n, m, speeds):
|
4,134 | You've purchased a ready-meal from the supermarket.
The packaging says that you should microwave it for 4 minutes and 20 seconds, based on a 600W microwave.
Oh no, your microwave is 800W! How long should you cook this for?!
___
# Input
You'll be given 4 arguments:
## 1. needed power
The power of the needed microw... | ["import math\n\ndef cooking_time(needed_power, minutes, seconds, power):\n t = math.ceil((60 * minutes + seconds) * int(needed_power[:-1]) / int(power[:-1]))\n return '%d minutes %d seconds' %(t // 60, t - t // 60 * 60)", "cooking_time=lambda n,m,s,p:'{} minutes {} seconds'.format(*divmod(-(-(m*60+s)*int(n[:-1])... | {"fn_name": "cooking_time", "inputs": [["600W", 4, 20, "800W"], ["800W", 3, 0, "1200W"], ["100W", 8, 45, "50W"], ["7500W", 0, 5, "600W"], ["450W", 3, 25, "950W"], ["21W", 64, 88, "25W"], ["83W", 61, 80, "26W"], ["38W", 95, 22, "12W"]], "outputs": [["3 minutes 15 seconds"], ["2 minutes 0 seconds"], ["17 minutes 30 secon... | introductory | https://www.codewars.com/kata/5aefd0a686d075d5f3000091 |
def cooking_time(needed_power, minutes, seconds, power):
|
4,135 | In this Kata, we are going to determine if the count of each of the characters in a string can be equal if we remove a single character from that string.
For example:
```
solve('abba') = false -- if we remove any character, the count of each character will not be equal.
solve('abbba') = true -- if we remove one b, the... | ["from collections import Counter\n\ndef solve(s):\n return any(len(set(Counter(s.replace(c, '', 1)).values())) == 1 for c in s)", "from collections import Counter\n\ndef solve(s):\n c = Counter(s).values()\n cVal, mi, ma = Counter(c), min(c), max(c)\n return len(cVal) <= 2 and (len(cVal) == 1 and (1 in cVa... | {"fn_name": "solve", "inputs": [["aaaa"], ["abba"], ["abbba"], ["aabbcc"], ["aaaabb"], ["aabbccddd"], ["aabcde"], ["abcde"], ["aaabcde"], ["abbccc"]], "outputs": [[true], [false], [true], [false], [false], [true], [true], [true], [false], [false]]} | introductory | https://www.codewars.com/kata/5a1a514effe75fd63b0000f2 |
def solve(s):
|
4,136 | # Task
A cake is sliced with `n` straight lines. Your task is to calculate the maximum number of pieces the cake can have.
# Example
For `n = 0`, the output should be `1`.
For `n = 1`, the output should be `2`.
For `n = 2`, the output should be `4`.
For `n = 3`, the output should be `7`.
See the followin... | ["def cake_slice(n):\n return (n ** 2 + n + 2) // 2", "def cake_slice(n):\n return 0.5*n**2+0.5*n+1", "def cake_slice(n):\n return (n**2 + n) // 2 + 1", "cake_slice = lambda n: sum(range(n + 1)) + 1", "def cake_slice(n):\n #coding and coding...\n sum = 1\n for i in range(n):\n sum += i+1\n ret... | {"fn_name": "cake_slice", "inputs": [[0], [1], [2], [3], [10]], "outputs": [[1], [2], [4], [7], [56]]} | introductory | https://www.codewars.com/kata/58c8a41bedb423240a000007 |
def cake_slice(n):
|
4,137 | ## A square of squares
You like building blocks. You especially like building blocks that are squares. And what you even like more, is to arrange them into a square of square building blocks!
However, sometimes, you can't arrange them into a square. Instead, you end up with an ordinary rectangle! Those blasted things!... | ["import math\ndef is_square(n):\n return n > -1 and math.sqrt(n) % 1 == 0;", "import math\n\ndef is_square(n): \n\n if n < 0:\n return False\n\n sqrt = math.sqrt(n)\n \n return sqrt.is_integer()", "def is_square(n): \n return n >= 0 and (n**0.5) % 1 == 0", "import math\ndef is_square(n):... | {"fn_name": "is_square", "inputs": [[-1], [25], [26]], "outputs": [[false], [true], [false]]} | introductory | https://www.codewars.com/kata/54c27a33fb7da0db0100040e |
def is_square(n):
|
4,138 | Consider a game, wherein the player has to guess a target word. All the player knows is the length of the target word.
To help them in their goal, the game will accept guesses, and return the number of letters that are in the correct position.
Write a method that, given the correct word and the player's guess, return... | ["def count_correct_characters(c, g):\n if len(c) != len(g): raise Exception('Error')\n return sum(1 for i,j in zip(c,g) if i==j)", "def count_correct_characters(s, t):\n assert len(s) == len(t)\n return sum(a == b for a, b in zip(s, t))", "def count_correct_characters(correct, guess):\n if len(correct) ... | {"fn_name": "count_correct_characters", "inputs": [["dog", "car"], ["dog", "god"], ["dog", "cog"], ["dog", "cod"], ["dog", "bog"], ["dog", "dog"], ["abcde", "abcde"], ["same", "same"], ["z", "z"]], "outputs": [[0], [1], [2], [1], [2], [3], [5], [4], [1]]} | introductory | https://www.codewars.com/kata/5912ded3f9f87fd271000120 |
def count_correct_characters(correct, guess):
|
4,139 | After a hard quarter in the office you decide to get some rest on a vacation. So you will book a flight for you and your girlfriend and try to leave all the mess behind you.
You will need a rental car in order for you to get around in your vacation. The manager of the car rental makes you some good offers.
Every day ... | ["def rental_car_cost(d):\n result = d * 40\n if d >= 7:\n result -= 50\n elif d >= 3:\n result -= 20\n return result", "def rental_car_cost(d):\n return d * 40 - (d > 2) * 20 - (d > 6) * 30", "def rental_car_cost(d):\n discount = 0\n if d >= 7:\n discount = 50\n elif d >= 3:\... | {"fn_name": "rental_car_cost", "inputs": [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]], "outputs": [[40], [80], [100], [140], [180], [220], [230], [270], [310], [350]]} | introductory | https://www.codewars.com/kata/568d0dd208ee69389d000016 |
def rental_car_cost(d):
|
4,140 | # Bubblesort Algorithm
## Overview
The Bubblesort Algorithm is one of many algorithms used to sort a list of similar items (e.g. all numbers or all letters) into either ascending order or descending order. Given a list (e.g.):
```python
[9, 7, 5, 3, 1, 2, 4, 6, 8]
```
To sort this list in ascending order using Bub... | ["def bubblesort_once(l):\n l = l[:]\n for i in range(len(l)-1):\n if l[i] > l[i+1]:\n l[i], l[i+1] = l[i+1], l[i]\n return l", "def bubblesort_once(L):\n if len(L)<=1 : return L\n if L[0]<=L[1]: return [L[0]] + bubblesort_once(L[1:])\n return [L[1]] + bubblesort_once([L[0]]+L[2:])",... | {"fn_name": "bubblesort_once", "inputs": [[[9, 7, 5, 3, 1, 2, 4, 6, 8]], [[1, 2]], [[2, 1]], [[1, 3]], [[3, 1]], [[24, 57]], [[89, 36]], [[1, 2, 3]], [[2, 4, 1]], [[17, 5, 11]], [[25, 16, 9]], [[103, 87, 113]], [[1032, 3192, 2864]], [[1, 2, 3, 4]], [[2, 3, 4, 1]], [[3, 4, 1, 2]], [[4, 1, 2, 3]], [[7, 5, 3, 1]], [[5, 3,... | introductory | https://www.codewars.com/kata/56b97b776ffcea598a0006f2 |
def bubblesort_once(l):
|
4,141 | A special type of prime is generated by the formula `p = 2^m * 3^n + 1` where `m` and `n` can be any non-negative integer.
The first `5` of these primes are `2, 3, 5, 7, 13`, and are generated as follows:
```Haskell
2 = 2^0 * 3^0 + 1
3 = 2^1 * 3^0 + 1
5 = 2^2 * 3^0 + 1
7 = 2^1 * 3^1 + 1
13 = 2^2 * 3^1 + 1
..and so on... | ["sb_primes = [2, 3, 5, 7, 13, 17, 19, 37, 73, 97, 109, 163, 193, 257, 433, 487, 577, 769, 1153, 1297, 1459, 2593, 2917, 3457, 3889, 10369, 12289, 17497, 18433, 39367, 52489, 65537, 139969, 147457, 209953, 331777, 472393, 629857, 746497, 786433, 839809, 995329, 1179649, 1492993]\n\ndef solve(x, y):\n return sum(x <=... | {"fn_name": "solve", "inputs": [[0, 10], [0, 15], [0, 100], [100, 1000], [340, 500], [3400, 5000], [20000, 60000], [750000, 1000000], [300000, 900000], [100, 1000000], [500000, 1000000], [1000000, 1500000], [0, 1500000]], "outputs": [[4], [5], [10], [8], [2], [2], [2], [3], [6], [32], [5], [2], [44]]} | introductory | https://www.codewars.com/kata/5a1502db46d84395ab00008a |
def solve(x, y):
|
4,142 | In this Kata, you will be given a list of strings and your task will be to find the strings that have the same characters and return the sum of their positions as follows:
```Haskell
solve(["abc","abbc", "ab", "xyz", "xy", "zzyx"]) = [1,8]
-- we see that the elements at indices 0 and 1 have the same characters, as do... | ["from collections import defaultdict\n\ndef solve(arr):\n dct = defaultdict(list)\n for i,fs in enumerate(map(frozenset, arr)):\n dct[fs].append(i)\n return sorted(sum(lst) for lst in dct.values() if len(lst) > 1)", "def solve(lst):\n seen, result = set(), []\n for i, st1 in enumerate(lst):\n ... | {"fn_name": "solve", "inputs": [[["abc", "abbc", "ab", "xyz", "xy", "zzyx"]], [["wkskkkkkk", "fokoo", "wkskk", "uizzzz", "fokooff", "wkskkkk", "uizzzzzzz"]], [["xhuhhh", "dghgg", "dghgghh", "mrerrrrrr", "xhuhhhhhh", "mrerrr"]], [["uczcccccc", "idffffiii", "pnjjjjjjj", "pnjjjj", "idffff", "uczcccc", "uczcc"]], [["rvjvvv... | introductory | https://www.codewars.com/kata/5a296b571f7f70b0b3000100 |
def solve(arr):
|
4,143 | [Generala](https://en.wikipedia.org/wiki/Generala) is a dice game popular in South America. It's very similar to [Yahtzee](https://en.wikipedia.org/wiki/Yahtzee) but with a different scoring approach. It is played with 5 dice, and the possible results are:
| Result | Points | Rules ... | ["def points(dice):\n dice = sorted([int(d) for d in dice])\n counts = [dice.count(i) for i in range(1, 7)]\n if 5 in counts:\n # GENERALA\n return 50\n if 4 in counts:\n # POKER\n return 40\n if 3 in counts and 2 in counts:\n # FULLHOUSE\n return 30\n if coun... | {"fn_name": "points", "inputs": [["55555"], ["44444"], ["44441"], ["33233"], ["22262"], ["12121"], ["44455"], ["66116"], ["12345"], ["23456"], ["34561"], ["13564"], ["62534"], ["44421"], ["61623"], ["12346"]], "outputs": [[50], [50], [40], [40], [40], [30], [30], [30], [20], [20], [20], [20], [20], [0], [0], [0]]} | introductory | https://www.codewars.com/kata/5f70c55c40b1c90032847588 |
def points(dice):
|
4,144 | In number theory, an **[abundant](https://en.wikipedia.org/wiki/Abundant_number)** number or an **[excessive](https://en.wikipedia.org/wiki/Abundant_number)** number is one for which the sum of it's **[proper divisors](http://mathworld.wolfram.com/ProperDivisor.html)** is greater than the number itself. The integer *... | ["def abundant(h):\n for n in range(h,0,-1):\n s = sum(i for i in range(1,n) if n % i == 0)\n if s > h:\n return [[n],[s-n]]", "from operator import itemgetter\nfrom bisect import bisect\n\nLIMIT = 2000\n\nmemo, result = [0]*LIMIT, {}\nfor x in range(1, LIMIT):\n if memo[x] > x:\n ... | {"fn_name": "abundant", "inputs": [[15], [19], [100], [999], [200], [250], [300], [350], [400], [450], [500], [555], [600], [666], [707], [777], [800], [900], [1111]], "outputs": [[[[12], [4]]], [[[18], [3]]], [[[100], [17]]], [[[996], [360]]], [[[200], [65]]], [[[246], [12]]], [[[300], [268]]], [[[350], [44]]], [[[400... | introductory | https://www.codewars.com/kata/57f3996fa05a235d49000574 |
def abundant(h):
|
4,145 | # Problem Statement
Write a function that takes two string parameters, an IP (v4) address and a subnet mask, and returns two strings: the network block, and the host identifier.
The function does not need to support CIDR notation.
# Description
A single IP address with subnet mask actually specifies several addresses... | ["def ipv4__parser(addr, mask):\n return tuple(\".\".join(str(n) for n in a) for a in zip(*(((a & m), (a & ~m)) for a, m in zip((int(n) for n in addr.split(\".\")), (int(n) for n in mask.split(\".\"))))))", "from socket import inet_aton, inet_ntoa\nfrom struct import Struct\n\nAddr = Struct('>I')\n\ndef ipv4__parser... | {"fn_name": "ipv4__parser", "inputs": [["192.168.50.1", "255.255.255.0"], ["192.168.50.129", "255.255.255.192"], ["192.168.50.153", "255.255.255.225"], ["65.196.188.53", "255.255.240.0"], ["65.196.188.53", "0.0.0.0"]], "outputs": [[["192.168.50.0", "0.0.0.1"]], [["192.168.50.128", "0.0.0.1"]], [["192.168.50.129", "0.0.... | introductory | https://www.codewars.com/kata/556d120c7c58dacb9100008b |
def ipv4__parser(ip_addr, mask):
|
4,146 | Complete the method which accepts an array of integers, and returns one of the following:
* `"yes, ascending"` - if the numbers in the array are sorted in an ascending order
* `"yes, descending"` - if the numbers in the array are sorted in a descending order
* `"no"` - otherwise
You can assume the array will always ... | ["def is_sorted_and_how(arr):\n if arr == sorted(arr):\n return 'yes, ascending' \n elif arr == sorted(arr)[::-1]:\n return 'yes, descending'\n else:\n return 'no'", "def is_sorted_and_how(arr):\n if arr == sorted(arr):\n return 'yes, ascending'\n elif arr == sorted(arr, reverse=Tru... | {"fn_name": "is_sorted_and_how", "inputs": [[[1, 2]], [[15, 7, 3, -8]], [[4, 2, 30]]], "outputs": [["yes, ascending"], ["yes, descending"], ["no"]]} | introductory | https://www.codewars.com/kata/580a4734d6df748060000045 |
def is_sorted_and_how(arr):
|
4,147 | Everyone knows passphrases. One can choose passphrases from poems, songs, movies names and so on but frequently
they can be guessed due to common cultural references.
You can get your passphrases stronger by different means. One is the following:
choose a text in capital letters including or not digits and non alphab... | ["def play_pass(s, n):\n\n # Step 1, 2, 3\n shiftText = \"\"\n for char in s:\n if char.isdigit():\n shiftText += str(9 - int(char))\n elif char.isalpha():\n shifted = ord(char.lower()) + n\n shiftText += chr(shifted) if shifted <= ord('z') else chr(shifted - 26)\... | {"fn_name": "play_pass", "inputs": [["I LOVE YOU!!!", 1], ["I LOVE YOU!!!", 0], ["AAABBCCY", 1], ["MY GRANMA CAME FROM NY ON THE 23RD OF APRIL 2015", 2], ["TO BE HONEST WITH YOU I DON'T USE THIS TEXT TOOL TOO OFTEN BUT HEY... MAYBE YOUR NEEDS ARE DIFFERENT.", 5], ["IN 2012 TWO CAMBRIDGE UNIVERSITY RESEARCHERS ANALYSED ... | introductory | https://www.codewars.com/kata/559536379512a64472000053 |
def play_pass(s, n):
|
4,148 | Write a function named sumDigits which takes a number as input and returns the sum of the absolute value of each of the number's decimal digits. For example:
```python
sum_digits(10) # Returns 1
sum_digits(99) # Returns 18
sum_digits(-32) # Returns 5
```
Let's assume that all numbers in the input will be int... | ["def sum_digits(number):\n return sum(map(int, str(abs(number))))", "def sum_digits(n):\n return eval('+'.join(str(abs(n))))", "def sum_digits(number):\n num_string = str(abs(number))\n total = 0\n \n for char in num_string:\n total += int(char)\n \n return total", "def sum_digits(number... | {"fn_name": "sum_digits", "inputs": [[10], [99], [-32], [1234567890], [0], [666], [100000002], [800000009]], "outputs": [[1], [18], [5], [45], [0], [18], [3], [17]]} | introductory | https://www.codewars.com/kata/52f3149496de55aded000410 |
def sum_digits(number):
|
4,149 | You are asked to write a simple cypher that rotates every character (in range [a-zA-Z], special chars will be ignored by the cipher) by 13 chars. As an addition to the original ROT13 cipher, this cypher will also cypher numerical digits ([0-9]) with 5 chars.
Example:
"The quick brown fox jumps over the 2 lazy dog... | ["trans = \"abcdefghijklmnopqrstuvwxyz\" * 2\ntrans += trans.upper() + \"0123456789\" * 2\n\ndef ROT135(input):\n output = []\n for c in input:\n if c.isalpha():\n c = trans[trans.index(c) + 13]\n elif c.isdigit():\n c = trans[trans.index(c) + 5]\n output.append(c)\n ... | {"fn_name": "ROT135", "inputs": [["The quick brown fox jumps over the 2 lazy dogs"], ["Gur dhvpx oebja sbk whzcf bire gur 7 ynml qbtf"], ["1234567890"], ["12_-56789."]], "outputs": [["Gur dhvpx oebja sbk whzcf bire gur 7 ynml qbtf"], ["The quick brown fox jumps over the 2 lazy dogs"], ["6789012345"], ["67_-01234."]]} | introductory | https://www.codewars.com/kata/5894986e2ddc8f6805000036 |
def ROT135(input):
|
4,150 | How can you tell an extrovert from an
introvert at NSA? Va gur ryringbef,
gur rkgebireg ybbxf ng gur BGURE thl'f fubrf.
I found this joke on USENET, but the punchline is scrambled. Maybe you can decipher it?
According to Wikipedia, ROT13 (http://en.wikipedia.org/wiki/ROT13) is frequently used to obfuscate jokes on USE... | ["def rot13(message):\n def decode(c):\n if 'a' <= c <= 'z':\n base = 'a'\n elif 'A' <= c <= 'Z':\n base = 'A'\n else:\n return c\n return chr((ord(c) - ord(base) + 13) % 26 + ord(base))\n return \"\".join(decode(c) for c in message)", "def rot13(messag... | {"fn_name": "rot13", "inputs": [["EBG13 rknzcyr."], ["How can you tell an extrovert from an\nintrovert at NSA? Va gur ryringbef,\ngur rkgebireg ybbxf ng gur BGURE thl'f fubrf."], ["123"], ["Guvf vf npghnyyl gur svefg xngn V rire znqr. Gunaxf sbe svavfuvat vg! :)"], ["@[`{"]], "outputs": [["ROT13 example."], ["Ubj pna l... | introductory | https://www.codewars.com/kata/52223df9e8f98c7aa7000062 |
def rot13(message):
|
4,151 | To celebrate today's launch of my Hero's new book: Alan Partridge: Nomad, We have a new series of kata arranged around the great man himself.
Given an array of terms, if any of those terms relate to Alan Partridge, return Mine's a Pint!
The number of ! after the t should be determined by the number of Alan related te... | ["def part(arr):\n l = [\"Partridge\", \"PearTree\", \"Chat\", \"Dan\", \"Toblerone\", \"Lynn\", \"AlphaPapa\", \"Nomad\"]\n s = len([i for i in arr if i in l])\n return \"Mine's a Pint\"+\"!\"*s if s>0 else 'Lynn, I\\'ve pierced my foot on a spike!!'", "def part(arr):\n terms = {'Partridge', 'PearTree', 'C... | {"fn_name": "part", "inputs": [[["Grouse", "Partridge", "Pheasant"]], [["Pheasant", "Goose", "Starling", "Robin"]], [["Grouse", "Partridge", "Partridge", "Partridge", "Pheasant"]], [[]], [["Grouse", "Partridge", "Pheasant", "Goose", "Starling", "Robin", "Thrush", "Emu", "PearTree", "Chat", "Dan", "Square", "Toblerone",... | introductory | https://www.codewars.com/kata/5808c8eff0ed4210de000008 |
def part(arr):
|
4,152 | Find the greatest common divisor of two positive integers. The integers can be large, so you need to find a clever solution.
The inputs `x` and `y` are always greater or equal to 1, so the greatest common divisor will always be an integer that is also greater or equal to 1. | ["#Try to make your own gcd method without importing stuff\ndef mygcd(x,y):\n #GOOD LUCK\n while y:\n x,y=y,x%y\n return x", "def mygcd(x,y):\n return x if y == 0 else mygcd(y, x % y)\n", "def mygcd(x,y):\n if x%y == 0:\n return y\n else:\n return mygcd(y,x%y)\n\n# reference: http:/... | {"fn_name": "mygcd", "inputs": [[1, 3], [60, 12], [2672, 5678], [10927782, 6902514], [1590771464, 1590771620]], "outputs": [[1], [12], [334], [846], [4]]} | introductory | https://www.codewars.com/kata/5500d54c2ebe0a8e8a0003fd |
def mygcd(x,y):
|
4,153 | ## Task
Find the sum of the first `n` elements in the Recamán Sequence.
Input range:
```python
1000 tests
0 <= n <= 2,500,000
```
___
## Sequence
The sequence is formed using the next formula:
* We start with `0`
* At each step `i`, we subtract `i` from the previous number
* If the result is not negative, and not... | ["S, SS, SUM = [0], {0}, [0]\n\ndef rec(n):\n while len(S)<=n:\n v = S[-1] - len(S)\n if v<= 0 or v in SS: v += 2*len(S)\n S.append(v)\n SS.add(v)\n SUM.append(SUM[-1]+v)\n return SUM[n-1]", "# precaclulate results\nLIMIT = 2500000\nRECA_SUM = [0, 0]\nseen = {0}\nlast = 0\ntotal... | {"fn_name": "rec", "inputs": [[0], [1], [2], [5], [100], [200], [1000], [10000]], "outputs": [[0], [0], [1], [12], [7496], [36190], [837722], [82590002]]} | introductory | https://www.codewars.com/kata/5b8c055336332fce3d00000e |
def rec(x):
|
4,154 | Implement a method that accepts 3 integer values a, b, c. The method should return true if a triangle can be built with the sides of given length and false in any other case.
(In this case, all triangles must have surface greater than 0 to be accepted). | ["def is_triangle(a, b, c):\n return (a<b+c) and (b<a+c) and (c<a+b)\n", "def is_triangle(a, b, c):\n a, b, c = sorted([a, b, c])\n return a + b > c\n", "def is_triangle(a, b, c):\n return (a + b) > c and (a + c) > b and (b + c) > a\n", "def is_triangle(a, b, c):\n \"\"\"Determine if three sides of given... | {"fn_name": "is_triangle", "inputs": [[1, 2, 2], [7, 2, 2], [1, 2, 3], [1, 3, 2], [3, 1, 2], [5, 1, 2], [1, 2, 5], [2, 5, 1], [4, 2, 3], [5, 1, 5], [2, 2, 2], [-1, 2, 3], [1, -2, 3], [1, 2, -3], [0, 2, 3]], "outputs": [[true], [false], [false], [false], [false], [false], [false], [false], [true], [true], [true], [false... | introductory | https://www.codewars.com/kata/56606694ec01347ce800001b |
def is_triangle(a, b, c):
|
4,155 | Consider the numbers `6969` and `9116`. When you rotate them `180 degrees` (upside down), these numbers remain the same. To clarify, if we write them down on a paper and turn the paper upside down, the numbers will be the same. Try it and see! Some numbers such as `2` or `5` don't yield numbers when rotated.
Given a r... | ["REV = {'6':'9', '9':'6'}\nBASE = set(\"01869\")\n\ndef isReversible(n):\n s = str(n)\n return ( not (set(s) - BASE) # contains only reversible characters\n and (not len(s)%2 or s[len(s)//2] not in \"69\") # does n... | {"fn_name": "solve", "inputs": [[0, 10], [10, 100], [100, 1000], [1000, 10000], [10000, 15000], [15000, 20000], [60000, 70000], [60000, 130000]], "outputs": [[3], [4], [12], [20], [6], [9], [15], [55]]} | introductory | https://www.codewars.com/kata/59f7597716049833200001eb |
def solve(a, b):
|
4,156 | A rectangle can be split up into a grid of 1x1 squares, the amount of which being equal to the product of the two dimensions of the rectangle. Depending on the size of the rectangle, that grid of 1x1 squares can also be split up into larger squares, for example a 3x2 rectangle has a total of 8 squares, as there are 6 d... | ["def findSquares(x,y):\n return sum( (x-i) * (y-i) for i in range(y) )", "def findSquares(x,y):\n if x > y:\n x, y = y, x\n return x*(x+1)*(2*x+1)/6 + (y-x)*x*(x+1)/2", "def findSquares(x,y):\n return sum((x-i)*(y-i) for i in range(min(x,y)))", "def findSquares(x,y):\n squares = 0\n while y >... | {"fn_name": "findSquares", "inputs": [[3, 2], [4, 3], [11, 4]], "outputs": [[8], [20], [100]]} | introductory | https://www.codewars.com/kata/5a62da60d39ec5d947000093 |
def findSquares(x,y):
|
4,157 | In English and programming, groups can be made using symbols such as `()` and `{}` that change meaning. However, these groups must be closed in the correct order to maintain correct syntax.
Your job in this kata will be to make a program that checks a string for correct grouping. For instance, the following groups are... | ["BRACES = { '(': ')', '[': ']', '{': '}' }\n\ndef group_check(s):\n stack = []\n for b in s:\n c = BRACES.get(b)\n if c:\n stack.append(c)\n elif not stack or stack.pop() != b:\n return False\n return not stack", "def group_check(s):\n while \"{}\" in s or \"()\" ... | {"fn_name": "group_check", "inputs": [["({})"], ["[[]()]"], ["[{()}]"], ["()"], ["([])"], ["{}([])"], ["{[{}[]()[]{}{}{}{}{}{}()()()()()()()()]{{{[[[((()))]]]}}}}(())[[]]{{}}[][][][][][][]({[]})"], [""], ["{(})"], ["[{}{}())"], ["{)[}"], ["[[[]])"], ["()[]{]"], ["{([]})"], ["([]"], ["[])"], ["([]))"], ["{{{{{{{{{{{((((... | introductory | https://www.codewars.com/kata/54b80308488cb6cd31000161 |
def group_check(s):
|
4,158 | Write a function that checks if all the letters in the second string are present in the first one at least once, regardless of how many times they appear:
```
["ab", "aaa"] => true
["trances", "nectar"] => true
["compadres", "DRAPES"] => true
["parses", "parsecs"] => false
```
Function should not be cas... | ["def letter_check(arr): \n return set(arr[1].lower()) <= set(arr[0].lower())", "def letter_check(arr): \n a,b = (set(s.lower()) for s in arr)\n return b <= a", "def letter_check(arr): \n for i in arr[1]:\n if i.lower()not in arr[0].lower():\n return False\n return True", "def letter_ch... | {"fn_name": "letter_check", "inputs": [[["abcd", "aaa"]], [["trances", "nectar"]], [["THE EYES", "they see"]], [["assert", "staring"]], [["arches", "later"]], [["dale", "caller"]], [["parses", "parsecs"]], [["replays", "adam"]], [["mastering", "streaming"]], [["drapes", "compadres"]], [["deltas", "slated"]], [["deltas"... | introductory | https://www.codewars.com/kata/57470efebf81fea166001627 |
def letter_check(arr):
|
4,159 | *** Nova polynomial multiply***
This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8807940ff3001140 ) [#4](http://www.codewars.com/kata/571a2e2df24bdf... | ["def poly_multiply(p1, p2):\n if not p1 or not p2: return []\n n = len(p1) + len(p2) - 1\n p = [0]*n\n for i,a in enumerate(p1):\n for j,b in enumerate(p2):\n p[i + j] += a*b\n return p", "from numpy import polymul\n\ndef poly_multiply(p1, p2):\n res = list(polymul(p1, p2))\n return res if any(res) ... | {"fn_name": "poly_multiply", "inputs": [[[], []], [[1, 2, 3, 4, 5, 6], []], [[], [1, 2, 3, 4, 5, 6]]], "outputs": [[[]], [[]], [[]]]} | introductory | https://www.codewars.com/kata/570eb07e127ad107270005fe |
def poly_multiply(p1, p2):
|
4,160 | Every day we can send from the server a certain limit of e-mails.
Task:
Write a function that will return the integer number of e-mails sent in the percentage of the limit.
Example:
```
limit - 1000;
emails sent - 101;
return - 10%; // becouse integer from 10,1 = 10
```
Arguments:
Integer, limit;
Integer... | ["def get_percentage(sent, limit = 1000):\n if not sent:\n return \"No e-mails sent\"\n elif sent >= limit:\n return \"Daily limit is reached\"\n return \"{}%\".format(int(sent * 100 / limit))", "def get_percentage(a, b=1000):\n return \"No e-mails sent\" if not a else \"Daily limit is reached... | {"fn_name": "get_percentage", "inputs": [[101, 1000], [256, 500], [259], [0], [1000, 1000]], "outputs": [["10%"], ["51%"], ["25%"], ["No e-mails sent"], ["Daily limit is reached"]]} | introductory | https://www.codewars.com/kata/58a369fa5b3daf464200006c |
def get_percentage(sent, limit=1000):
|
4,161 | Here's a way to construct a list containing every positive rational number:
Build a binary tree where each node is a rational and the root is `1/1`, with the following rules for creating the nodes below:
* The value of the left-hand node below `a/b` is `a/a+b`
* The value of the right-hand node below `a/b` is `a+b/b`
... | ["def rat_at(n):\n if n == 0:\n return 1, 1\n a, b = rat_at((n - 1) // 2)\n return (a, a + b) if n % 2 else (a + b, b)\n\ndef index_of(a, b):\n if a == b == 1:\n return 0\n return 2 * index_of(a, b - a) + 1 if b > a else 2 * index_of(a - b, b) + 2", "from math import ceil\ndef rat_at(n):\n ... | {"fn_name": "rat_at", "inputs": [[0], [3], [4], [10], [1000000000]], "outputs": [[[1, 1]], [[1, 3]], [[3, 2]], [[5, 2]], [[73411, 65788]]]} | introductory | https://www.codewars.com/kata/5e529a6fb95d280032d04389 |
def rat_at(n):
|
4,162 | Andrzej was given a task:
There are n jars with pills. In every jar there is a different type of pill and the amount of pills in each jar is infinite. One type of pill makes a person glow about 30 minutes after taking and none of the other types has any effect.
His job is to determine, in which jar are the pills that m... | ["def friends(n):\n return len(str(bin(n-1)))-3 if n >1 else 0", "def friends(n):\n return (n-1 or 1).bit_length()-1", "def friends(n):\n return 0 if n < 2 else (n - 1).bit_length() - 1", "from math import log2\n\ndef friends(n):\n return int(log2(max(2, n) - 1))", "from math import log2\n\ndef friends(n):\... | {"fn_name": "friends", "inputs": [[0], [1], [2], [4], [3], [16]], "outputs": [[0], [0], [0], [1], [1], [3]]} | introductory | https://www.codewars.com/kata/5ad29cd95e8240dd85000b54 |
def friends(n):
|
4,163 | An array is called `centered-N` if some `consecutive sequence` of elements of the array sum to `N` and this sequence is preceded and followed by the same number of elements.
Example:
```
[3,2,10,4,1,6,9] is centered-15
because the sequence 10,4,1 sums to 15 and the sequence
is preceded by two elements [3,2] and foll... | ["def is_centered(arr,n):\n l = int(len(arr)/2) if len(arr)%2==0 else int((len(arr)-1)/2)\n return any(sum(arr[i:-i])==n for i in range(1, l+1)) or sum(arr)==n", "from itertools import accumulate\n\ndef is_centered(arr, n):\n xs = [0] + list(accumulate(arr))\n return any(b-a==n for a, b in zip(xs[:len(arr)/... | {"fn_name": "is_centered", "inputs": [[[0, 0, 0], 0], [[3, 2, 10, 4, 1, 6, 9], 15], [[2, 10, 4, 1, 6, 9], 15], [[3, 2, 10, 4, 1, 6], 15], [[1, 1, 8, 3, 1, 1], 15], [[1, 1, 8, 3, 1, 1], 11], [[1, 1, 8, 3, 1, 1], 13], [[9, 0, 6], 0], [[], 25], [[25], 25], [[25, 26, 23, 24], 0], [[2, 1, 2], 0], [[1, 1, 15, -1, -1], 15], [... | introductory | https://www.codewars.com/kata/59b06d83cf33953dbb000010 |
def is_centered(arr,n):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.