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,565 | The code provided is supposed replace all the dots `.` in the specified String `str` with dashes `-`
But it's not working properly.
# Task
Fix the bug so we can all go home early.
# Notes
String `str` will never be null. | ["def replace_dots(string):\n return string.replace('.', '-')", "import re\ndef replace_dots(str):\n return re.sub(r\"\\.\", \"-\", str)\n # literally I had to only add a \\ infront of the dot.\n # this challenge is super hard for noobs and super easy for pros. it's not fair.\n", "import re\ndef replace_dot... | {"fn_name": "replace_dots", "inputs": [[""], ["no dots"], ["one.two.three"], ["........"]], "outputs": [[""], ["no dots"], ["one-two-three"], ["--------"]]} | introductory | https://www.codewars.com/kata/596c6eb85b0f515834000049 |
def replace_dots(str):
|
4,566 | You need count how many valleys you will pass.
Start is always from zero level.
Every time you go down below 0 level counts as an entry of a valley, and as you go up to 0 level from valley counts as an exit of a valley.
One passed valley is equal one entry and one exit of a valley.
```
s='FUFFDDFDUDFUFUF'
U=UP
F=FOR... | ["def counting_valleys(s): \n level = 0\n in_valley = False\n count = 0\n for c in s:\n if c =='U':\n level += 1\n elif c=='D':\n level -= 1\n if level >= 0 and in_valley:\n count += 1\n in_valley = level < 0\n return count", "def counting_... | {"fn_name": "counting_valleys", "inputs": [["UFFFD"], ["DFFFD"], ["UFFFU"], ["DFFFU"], ["UFFDDFDUDFUFU"], ["UFFDDFDUDFUFUUFFDDFDUDFUFU"], ["UFFDDFDUDFUFUUFFDDUFFDDUFFDDUDUDUDUDUDUUUUUUUUU"], ["UFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFU"], ["UFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFD... | introductory | https://www.codewars.com/kata/5da9973d06119a000e604cb6 |
def counting_valleys(s):
|
4,567 | Apparently "Put A Pillow On Your Fridge Day is celebrated on the 29th of May each year, in Europe and the U.S. The day is all about prosperity, good fortune, and having bit of fun along the way."
All seems very weird to me.
Nevertheless, you will be given an array of two strings (s). First find out if the first strin... | ["pillow=lambda s:('n','B')in zip(*s)", "def pillow(s):\n return ('n','B') in zip(*s)", "def pillow(arr):\n s1, s2 = arr\n return bool({i for i, a in enumerate(s1) if a == 'n'} &\n {i for i, b in enumerate(s2) if b == 'B'})", "def pillow(s):\n return ('n', 'B') in zip(s[0],s[1])", "def pillow... | {"fn_name": "pillow", "inputs": [[["EvH/KNikBiyxfeyK/miCMj", "I/HwjnHlFLlahMOKNadps"]], [["\\DjQ\\[zv]SpG]Z/[Qm\\eLL", "amwZArsaGRmibriXBgTRZp"]], [["n", "B"]], [["yF[CeAAiNihWEmKxJc/NRMVn", "rMeIa\\KAfbjuLiTnAQxNw[XB"]], [["inECnBMAA/u", "ABAaIUOUx/M"]]], "outputs": [[false], [false], [true], [true], [true]]} | introductory | https://www.codewars.com/kata/57d147bcc98a521016000320 |
def pillow(s):
|
4,568 | *This is the advanced version of the
[Minimum and Maximum Product of k Elements](https://www.codewars.com/kata/minimum-and-maximum-product-of-k-elements/) kata.*
---
Given a list of **integers** and a positive integer `k` (> 0), find the minimum and maximum possible product of `k` elements taken from the list.
If y... | ["from functools import reduce\n\ndef find_min_max_product(arr, k): \n if k <= len(arr):\n arr = sorted(arr, key=abs)\n lasts = arr[-k:]\n v1 = reduce(int.__mul__, lasts)\n v0 = reduce(int.__mul__, arr[:k])\n \n first_SameOrOpp = [next((v for v in lasts ... | {"fn_name": "find_min_max_product", "inputs": [[[0, 1, 2, 3, 4], 2], [[0, -1, -2, -3, -4], 2], [[0, -1, -2, -3, -4], 3], [[-1, -2, -3, -4], 2], [[-1, -2, -3, -4], 3], [[], 2], [[-4, -10, -1], 2], [[0, 6, 3, 5, 4], 4], [[5, 4, 3, 3, 6], 2]], "outputs": [[[0, 12]], [[0, 12]], [[-24, 0]], [[2, 12]], [[-24, -6]], [null], [... | introductory | https://www.codewars.com/kata/5b05867c87566a947a00001c |
def find_min_max_product(arr, k):
|
4,569 | Given a sequence of items and a specific item in that sequence, return the item immediately following the item specified. If the item occurs more than once in a sequence, return the item after the first occurence. This should work for a sequence of any type.
When the item isn't present or nothing follows it, the funct... | ["def next_item(xs, item):\n it = iter(xs)\n for x in it:\n if x == item:\n break\n return next(it, None)", "def next_item(xs, item):\n it = iter(xs)\n next(iter(x for x in it if x == item), None)\n return next(it, None)", "import itertools\ndef next_item(xs, item):\n try:\n xs =... | {"fn_name": "next_item", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8], 3], [["a", "b", "c"], "d"], [["a", "b", "c"], "c"], ["testing", "t"], ["Hello!", "o"], ["Hello!", "!"], ["Hello!", "x"]], "outputs": [[4], [null], [null], ["e"], ["!"], [null], [null]]} | introductory | https://www.codewars.com/kata/542ebbdb494db239f8000046 |
def next_item(xs, item):
|
4,570 | Assume `"#"` is like a backspace in string. This means that string `"a#bc#d"` actually is `"bd"`
Your task is to process a string with `"#"` symbols.
## Examples
```
"abc#d##c" ==> "ac"
"abc##d######" ==> ""
"#######" ==> ""
"" ==> ""
``` | ["def clean_string(s):\n stk = []\n for c in s:\n if c=='#' and stk: stk.pop()\n elif c!='#': stk.append(c)\n return ''.join(stk)", "def clean_string(s):\n result = []\n for c in s:\n if c == '#':\n if result:\n result.pop()\n else:\n ... | {"fn_name": "clean_string", "inputs": [["abjd####jfk#"], ["gfh#jds###d#dsd####dasdaskhj###dhkjs####df##s##d##"], ["831####jns###s#cas/*####-5##s##6+yqw87e##hfklsd-=-28##fds##"], ["######831###dhkj####jd#dsfsdnjkf###d####dasns"], [""], ["#######"], ["####gfdsgf##hhs#dg####fjhsd###dbs########afns#######sdanfl##db#####s#a... | introductory | https://www.codewars.com/kata/5727bb0fe81185ae62000ae3 |
def clean_string(s):
|
4,571 | Decompose a number `num` into an array (tuple in Haskell, array of arrays `long[][]` in C# or Java) of the form `[[k1,k2,k3...], r]`, `([k1,k2,k3...], r)` in Haskell, `[[k1,k2,k3...], [r]]` in C# or Java) such that:
1. each kn is more than one
2. eack kn is maximized (first maximizing for 2 then 3 then 4 and so on)
3... | ["from math import log\n\ndef decompose(n):\n i = 2\n result = []\n while n >= i*i:\n k = int(log(n, i))\n result.append(k)\n n -= i ** k\n i += 1\n \n return [result, n]\n", "from math import log\n\ndef decompose(num):\n i, res = 2, []\n while i**2 <= num:\n n = ... | {"fn_name": "decompose", "inputs": [[0], [4], [9], [25], [8330475], [9819938], [8331299], [8328441]], "outputs": [[[[], 0]], [[[2], 0]], [[[3], 1]], [[[4, 2], 0]], [[[22, 13, 10, 8, 7, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2], 0]], [[[23, 12, 9, 8, 6, 6, 5, 4, 4, 4, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2... | introductory | https://www.codewars.com/kata/55ec80d40d5de30631000025 |
def decompose(num):
|
4,572 | Given a string (`str`) containing a base-10 integer between `0` and `10000`, convert the integer to its binary representation. At that point, obtain a count of the maximum amount of consecutive 0s. From there, return the count in written form with a capital letter.
In the very first example, we have an argument of `"9... | ["import re\nls = [\"Zero\",\"One\",\"Two\",\"Three\",\"Four\",\"Five\",\"Six\",\"Seven\",\"Eight\",\"Nine\",\"Ten\",\"Eleven\",\"Twelve\",\"Thirteen\"]\ndef max_consec_zeros(n):\n return ls[max(map(lambda x:len(x),re.findall(r'0*',bin(int(n))[2:])))]", "import re\n\ndef max_consec_zeros(n):\n return 'zero one tw... | {"fn_name": "max_consec_zeros", "inputs": [["7"], ["33"], ["77"], ["100"], ["105"], ["113"], ["160"], ["180"], ["223"], ["256"], ["777"], ["992"], ["1024"], ["1037"], ["1088"], ["2017"], ["2048"], ["3050"], ["4096"], ["6144"], ["6656"], ["7188"], ["8192"], ["9999"], ["10000"]], "outputs": [["Zero"], ["Four"], ["Two"], ... | introductory | https://www.codewars.com/kata/59decdf40863c76ae3000080 |
def max_consec_zeros(n):
|
4,573 | ### Task
You've just moved into a perfectly straight street with exactly ```n``` identical houses on either side of the road. Naturally, you would like to find out the house number of the people on the other side of the street. The street looks something like this:
--------------------
### Street
```
1| |6
3| |4
5... | ["def over_the_road(address, n):\n '''\n Input: address (int, your house number), n (int, length of road in houses) \n Returns: int, number of the house across from your house. \n '''\n # this is as much a math problem as a coding one \n # if your house is [even/odd], the opposite house will be [odd/e... | {"fn_name": "over_the_road", "inputs": [[1, 3], [3, 3], [2, 3], [3, 5], [7, 11], [10, 22], [20, 3400], [9, 26], [20, 10]], "outputs": [[6], [4], [5], [8], [16], [35], [6781], [44], [1]]} | introductory | https://www.codewars.com/kata/5f0ed36164f2bc00283aed07 |
def over_the_road(address, n):
|
4,574 | In this Kata you are a builder and you are assigned a job of building a wall with a specific size (God knows why...).
Create a function called `build_a_wall` (or `buildAWall` in JavaScript) that takes `x` and `y` as integer arguments (which represent the number of rows of bricks for the wall and the number of bricks i... | ["# -*- coding: utf-8 -*-\ndef build_a_wall(x=0, y=0):\n if type(x) != int or type(y) != int or x < 1 or y < 1: return\n if x * y > 10000: return \"Naah, too much...here's my resignation.\"\n res = [[\"\u25a0\u25a0\"]*y if i&1^x&1 else [\"\u25a0\"] + [\"\u25a0\u25a0\"]*(y-1) + [\"\u25a0\"] for i in range(x)]\n... | {"fn_name": "build_a_wall", "inputs": [[4, 5], [10, 7], ["eight", [3]], [12, -4], [0, 9], [123, 987]], "outputs": [["\u25a0|\u25a0\u25a0|\u25a0\u25a0|\u25a0\u25a0|\u25a0\u25a0|\u25a0\n\u25a0\u25a0|\u25a0\u25a0|\u25a0\u25a0|\u25a0\u25a0|\u25a0\u25a0\n\u25a0|\u25a0\u25a0|\u25a0\u25a0|\u25a0\u25a0|\u25a0\u25a0|\u25a0\n\u2... | introductory | https://www.codewars.com/kata/5939b753942a2700860000df |
def build_a_wall(x=0, y=0):
|
4,575 | # Task
You're given a two-dimensional array of integers `matrix`. Your task is to determine the smallest non-negative integer that is not present in this array.
# Input/Output
- `[input]` 2D integer array `matrix`
A non-empty rectangular matrix.
`1 ≤ matrix.length ≤ 10`
`1 ≤ matrix[0].length ≤ 10`
- `[o... | ["def smallest_integer(matrix):\n nums = set(sum(matrix, []))\n n = 0\n while n in nums: n += 1\n return n", "from itertools import filterfalse, chain, count\n\ndef smallest_integer(matrix):\n return next(filterfalse(set(chain.from_iterable(matrix)).__contains__, count()))", "def smallest_integer(matrix)... | {"fn_name": "smallest_integer", "inputs": [[[[0, 2], [5, 1]]], [[[4, 5, 3, 21, 3, 8], [2, 2, 6, 5, 10, 9], [7, 5, 6, 8, 2, 6], [1, 4, 7, 8, 9, 0], [1, 3, 6, 5, 5, 1], [2, 7, 3, 4, 4, 3]]], [[[4, 5, 3, -4, 3, 8], [2, 0, 6, 5, 4, 9], [7, 5, 6, 8, 2, 6], [1, 4, 7, 8, 9, 11], [1, 3, 10, 5, 5, 1], [12, 7, 3, 4, 4, 3]]], [[[... | introductory | https://www.codewars.com/kata/58fd96a59a9f65c2e900008d |
def smallest_integer(matrix):
|
4,576 | You are given two positive integer lists with a random number of elements (1 <= n <= 100). Create a [GCD](https://en.wikipedia.org/wiki/Greatest_common_divisor) matrix and calculate the average of all values.
Return a float value rounded to 3 decimal places.
## Example
```
a = [1, 2, 3]
b = [4, 5, 6]
# a =... | ["from fractions import gcd\nfrom itertools import product, starmap\nfrom statistics import mean\n\ndef gcd_matrix(a, b):\n return round(mean(starmap(gcd, product(a, b))), 3)", "from fractions import gcd\n\ndef gcd_matrix(a, b):\n return round(sum(gcd(x, y) for x in a for y in b) / (len(a) * len(b)), 3)\n", "from... | {"fn_name": "gcd_matrix", "inputs": [[[1, 2, 3], [4, 5, 6]], [[5, 5, 5], [10, 10, 10]], [[4, 7, 2, 10, 99, 4], [55, 32, 1, 344, 35234, 3]]], "outputs": [[1.444], [5.0], [2.0]]} | introductory | https://www.codewars.com/kata/58a30be22d5b6ca8d9000012 |
def gcd_matrix(a,b):
|
4,577 | Take debugging to a whole new level:
Given a string, remove every *single* bug.
This means you must remove all instances of the word 'bug' from within a given string, *unless* the word is plural ('bugs').
For example, given 'obugobugobuoobugsoo', you should return 'ooobuoobugsoo'.
Another example: given 'obbugugo',... | ["import re\n\ndef debug(s):\n return re.sub(r'bug(?!s)', '', s)", "import re\n\ndef debug(string):\n return re.sub(\"bug(?!s)\", \"\", string)", "def debug(s):\n s=s.replace(\"bugs\", \"^\")\n s=s.replace(\"bug\", \"\")\n s=s.replace(\"^\", \"bugs\")\n return s", "def debug(s):\n return __import__... | {"fn_name": "debug", "inputs": [["obugobugobuoobugsoo"], ["obbugugo"], ["bugs bunny"], ["bugs buggy"], ["oaiwjefbugoijoijapsbugsdoibugbugjfoijasdfbugsbug"], ["bugbugbugiahweoifuhiaasnoidfhnbugbugs"], ["bugsbugswaoeifhiauwehfoiwubugshefjnviouah"], ["bugbugbugbug"], ["bugsbugsbugsbugs"], ["buggybugs"], ["oaisjdfowjefpoib... | introductory | https://www.codewars.com/kata/5a21f943c5e284d4340000cb |
def debug(s):
|
4,578 | Your wizard cousin works at a Quidditch stadium and wants you to write a function that calculates the points for the Quidditch scoreboard!
# Story
Quidditch is a sport with two teams. The teams score goals by throwing the Quaffle through a hoop, each goal is worth **10 points**.
The referee also deducts 30 points (... | ["def quidditch_scoreboard(teams, actions):\n teams = {i:0 for i in teams.split(' vs ')}\n for i in actions.split(', '):\n team, action = i.split(': ')\n if 'goal' in action:\n teams[team] += 10\n elif 'foul' in action:\n teams[team] -= 30\n elif 'Snitch' in actio... | {"fn_name": "quidditch_scoreboard", "inputs": [["Appleby Arrows vs Montrose Magpies", "Montrose Magpies: Quaffle goal, Montrose Magpies: Quaffle goal, Appleby Arrows: Quaffle goal, Appleby Arrows: Quaffle goal, Montrose Magpies: Haverstacking foul, Appleby Arrows: Quaffle goal, Appleby Arrows: Quaffle goal, Appleby Arr... | introductory | https://www.codewars.com/kata/5b62f8a5b17883e037000136 |
def quidditch_scoreboard(teams, actions):
|
4,579 | ## Task:
You have to write a function `pattern` which returns the following Pattern(See Examples) upto n number of rows.
* Note:```Returning``` the pattern is not the same as ```Printing``` the pattern.
### Rules/Note:
* The pattern should be created using only unit digits.
* If `n < 1` then it should return "" i.... | ["def pattern(n):\n return \"\\n\".join(\n \"\".join(\n str((n - min(j, i)) % 10) for j in range(n)\n )\n for i in range(max(n, 0))\n )", "def pattern(n):\n return '\\n'.join(''.join(str((n - min(i, j))%10) for j in range(n)) for i in range(n))", "def pattern(n):\n return \"\... | {"fn_name": "pattern", "inputs": [[1], [2], [3], [7], [17], [27], [0], [-89]], "outputs": [["1"], ["22\n21"], ["333\n322\n321"], ["7777777\n7666666\n7655555\n7654444\n7654333\n7654322\n7654321"], ["77777777777777777\n76666666666666666\n76555555555555555\n76544444444444444\n76543333333333333\n76543222222222222\n76543211... | introductory | https://www.codewars.com/kata/55ae997d1c40a199e6000018 |
def pattern(n):
|
4,580 | # Task
Some children are playing rope skipping game. Children skip the rope at roughly the same speed: `once per second`. If the child fails during the jump, he needs to tidy up the rope and continue. This will take `3 seconds`.
You are given an array `failedCount`, where each element is the jump count at the failed. ... | ["def tiaosheng(a):\n j, t = 0, 0\n for j in a:\n t += 3\n if j + t > 60:\n return min(j, 60-t+3)\n return 60-t", "def tiaosheng(failed_counter):\n count = 0\n jumps = 0\n\n while count < 60:\n count += 1\n jumps += 1\n if jumps in failed_counter:\n ... | {"fn_name": "tiaosheng", "inputs": [[[]], [[12, 23, 45]], [[17]], [[10, 20, 30, 40]], [[10, 20, 30, 40, 58]], [[10, 20, 30, 40, 47, 60]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]], "outputs": [[60], [51], [57], [48], [48], [47], [30]]} | introductory | https://www.codewars.com/kata/5925138effaed0de490000cf |
def tiaosheng(failed_counter):
|
4,581 | # Task
Two arrays are called similar if one can be obtained from another by swapping at most one pair of elements.
Given two arrays, check whether they are similar.
# Example
For `A = [1, 2, 3]` and `B = [1, 2, 3]`, the output should be `true;`
For `A = [1, 2, 3]` and `B = [2, 1, 3]`, the output should be `true;`
... | ["def are_similar(a, b):\n return sorted(a) == sorted(b) and sum(i != j for i, j in zip(a, b)) in [0, 2]", "from collections import Counter\ndef are_similar(a, b):\n return sum(a_ == b_ for a_, b_ in zip(a, b)) >= len(a) - 2 and Counter(a) == Counter(b)", "def are_similar(a, b):\n c = [a[i] - b[i] for i in ran... | {"fn_name": "are_similar", "inputs": [[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [2, 1, 3]], [[1, 2, 2], [2, 1, 1]], [[1, 2, 3], [1, 10, 2]], [[2, 3, 1], [1, 3, 2]], [[1, 1, 2], [1, 2, 2]]], "outputs": [[true], [true], [false], [false], [true], [false]]} | introductory | https://www.codewars.com/kata/588820169ab1e053240000e0 |
def are_similar(a, b):
|
4,582 | Sam is an avid collector of numbers. Every time he finds a new number he throws it on the top of his number-pile. Help Sam organise his collection so he can take it to the International Number Collectors Conference in Cologne.
Given an array of numbers, your function should return an array of arrays, where each subar... | ["group=lambda arr: [[n]*arr.count(n) for n in sorted(set(arr), key=arr.index)]", "from collections import Counter, OrderedDict\n\nclass OrderedCounter(Counter, OrderedDict): \n pass\n\ndef group(arr):\n return [[k] * v for k, v in OrderedCounter(arr).items()]", "from collections import OrderedDict\n\ndef group(a... | {"fn_name": "group", "inputs": [[[3, 2, 6, 2, 1, 3]], [[3, 2, 6, 2]], [[]], [[1, 100, 4, 2, 4]], [[-1, 1, -1]]], "outputs": [[[[3, 3], [2, 2], [6], [1]]], [[[3], [2, 2], [6]]], [[]], [[[1], [100], [4, 4], [2]]], [[[-1, -1], [1]]]]} | introductory | https://www.codewars.com/kata/5884b6550785f7c58f000047 |
def group(arr):
|
4,583 | There is no single treatment that works for every phobia, but some people cure it by being gradually exposed to the phobic situation or object. In this kata we will try curing arachnophobia by drawing primitive spiders.
Our spiders will have legs, body, eyes and a mouth. Here are some examples:
```
/\((OOwOO))/\
/╲(... | ["def draw_spider(leg_size, body_size, mouth, eye):\n lleg = ['', '^', '/\\\\', '/\u2572', '\u2571\u2572'][leg_size]\n rleg = ['', '^', '/\\\\', '\u2571\\\\', '\u2571\u2572'][leg_size]\n lbody = '(' * body_size\n rbody = ')' * body_size\n eye *= 2 ** (body_size - 1)\n return f'{lleg}{lbody}{eye}{mouth... | {"fn_name": "draw_spider", "inputs": [[1, 1, "W", "o"], [2, 2, "w", "O"], [3, 3, "w", "0"]], "outputs": [["^(oWo)^"], ["/\\((OOwOO))/\\"], ["/\u2572(((0000w0000)))\u2571\\"]]} | introductory | https://www.codewars.com/kata/5bc73331797b005d18000255 |
def draw_spider(leg_size, body_size, mouth, eye):
|
4,584 | Given a set of numbers, return the additive inverse of each. Each positive becomes negatives, and the negatives become positives.
~~~if-not:racket
```
invert([1,2,3,4,5]) == [-1,-2,-3,-4,-5]
invert([1,-2,3,-4,5]) == [-1,2,-3,4,-5]
invert([]) == []
```
~~~
```if:javascript,python,ruby,php,elixir,dart
You can assume th... | ["def invert(lst):\n return [-x for x in lst]", "def invert(lst):\n return list(map(lambda x: -x, lst));", "def invert(lst):\n i = 0\n inv = []\n while i < len(lst):\n inv.append(lst[i] * -1)\n i += 1\n return inv\n\n", "def invert(lst):\n return [i*-1 for i in lst]", "def invert(lst):... | {"fn_name": "invert", "inputs": [[[1, 2, 3, 4, 5]], [[1, -2, 3, -4, 5]], [[]], [[0]]], "outputs": [[[-1, -2, -3, -4, -5]], [[-1, 2, -3, 4, -5]], [[]], [[0]]]} | introductory | https://www.codewars.com/kata/5899dc03bc95b1bf1b0000ad |
def invert(lst):
|
4,585 | ## Task
You are given three non negative integers `a`, `b` and `n`, and making an infinite sequence just like fibonacci sequence, use the following rules:
- step 1: use `ab` as the initial sequence.
- step 2: calculate the sum of the last two digits of the sequence, and append it to the end of sequence.
- repeat step... | ["def find(a,b,n):\n strng = str(a) + str(b)\n #there are 10 and 4 long loops\n if (n > 20): n = n%20+20\n while len(strng) <= n:\n next_ch = int(strng[-1]) + int(strng[-2])\n strng = strng + str(next_ch)\n return int(strng[n])", "L = [\n(\"\", \"0\"),\n(\"0\", \"1123581347\"),\n(\"0224610\... | {"fn_name": "find", "inputs": [[7, 8, 9], [0, 0, 1000000]], "outputs": [[5], [0]]} | introductory | https://www.codewars.com/kata/5bc555bb62a4cec849000047 |
def find(a, b, n):
|
4,586 | # Background
My TV remote control has arrow buttons and an `OK` button.
I can use these to move a "cursor" on a logical screen keyboard to type "words"...
The screen "keyboard" layout looks like this
#tvkb {
width : 300px;
border: 5px solid gray; border-collapse: collapse;
}
#tvkb td {
color : or... | ["KEYBOARD = \"abcde123fghij456klmno789pqrst.@0uvwxyz_/\"\nMAP = {c: (i//8, i%8) for i,c in enumerate(KEYBOARD)}\n\ndef manhattan(*pts): return sum( abs(z2-z1) for z1,z2 in zip(*pts))\n\ndef tv_remote(word):\n return len(word) + sum( manhattan(MAP[was], MAP[curr]) for was,curr in zip('a'+word, word))", "def get... | {"fn_name": "tv_remote", "inputs": [["codewars"], ["does"], ["your"], ["solution"], ["work"], ["for"], ["these"], ["words"], ["mississippi"]], "outputs": [[36], [16], [23], [33], [20], [12], [27], [25], [35]]} | introductory | https://www.codewars.com/kata/5a5032f4fd56cb958e00007a |
def tv_remote(word):
|
4,587 | In this Kata you are to implement a function that parses a string which is composed from tokens of the form 'n1-n2,n3,n4-n5:n6' where 'nX' is a positive integer. Each token represent a different range:
'n1-n2' represents the range n1 to n2 (inclusive in both ends).
'n3' represents the single integer n3.
'n4-n5:n6' rep... | ["def range_parser(string):\n res = []\n for range_ in string.split(','):\n first_last, _, step = range_.partition(':')\n first, _, last = first_last.partition('-')\n res += range(int(first), int(last or first) + 1, int(step or 1))\n return res", "import re\n\ndef range_parser(s):\n ret... | {"fn_name": "range_parser", "inputs": [["1-10,14, 20-25:2"], ["5-10"], ["2"], ["1-10,3"], ["1-10:5"]], "outputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 20, 22, 24]], [[5, 6, 7, 8, 9, 10]], [[2]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3]], [[1, 6]]]} | introductory | https://www.codewars.com/kata/57d307fb9d84633c5100007a |
def range_parser(string):
|
4,588 | # Situation
You have been hired by a company making electric garage doors. Accidents with the present product line have resulted in numerous damaged cars, broken limbs and several killed pets. Your mission is to write a safer version of their controller software.
# Specification
We always start with a closed door. The... | ["def controller(events):\n\n out, state, dir, moving = [], 0, 1, False\n \n for c in events:\n if c == 'O': dir *= -1\n elif c == 'P': moving = not moving\n if moving: state += dir\n if state in [0,5]: moving, dir = False, 1 if state == 0 else -1\n out.... | {"fn_name": "controller", "inputs": [[""], [".........."], ["P.."], ["P...."], ["P......P......"], ["P.P.."], ["P.P.P...."], [".....P.P........P...."], [".....P......P.P..P...."], ["P.O...."], ["P......P.O...."], ["P..OP..P.."], ["P......P..OP..P..."], ["..P...O....."]], "outputs": [[""], ["0000000000"], ["123"], ["123... | introductory | https://www.codewars.com/kata/58b1ae711fcffa34090000ea |
def controller(events):
|
4,589 | Complete the solution. It should try to retrieve the value of the array at the index provided. If the index is out of the array's max bounds then it should return the default value instead.
Example:
```Haskell
solution [1..3] 1 1000 `shouldBe` 2
solution [1..5] (10) 1000 `shouldBe` 1000
-- negative values work as lon... | ["def solution(items, index, default_value):\n try:\n return items[index]\n except IndexError:\n return default_value", "def solution(items, index, default_value):\n return items[index] if -len(items) <= index < len(items) else default_value\n", "def solution(items, index, default_value):\n tr... | {"fn_name": "solution", "inputs": [[[null, null], 0, "a"]], "outputs": [[null]]} | introductory | https://www.codewars.com/kata/515ceaebcc1dde8870000001 |
def solution(items, index, default_value):
|
4,590 | Create an OR function, without use of the 'or' keyword, that takes an list of boolean values and runs OR against all of them.
Assume there will be between 1 and 6 variables, and return None for an empty list. | ["def alt_or(lst):\n return any(lst) if lst else None", "def alt_or(lst): return bool(sum(lst)) if lst else None", "def alt_or(a):\n return any(a) if a else None ", "def alt_or(lst):\n return eval(str(lst).replace(',', '|'))[0] if lst else None", "def alt_or(a):\n if a: return any(a)", "def alt_or(lst):\n ... | {"fn_name": "alt_or", "inputs": [[[]], [[false, false, false, false, false, false]], [[false, false, false, false, false, true]], [[false, false, false, false, true, false]], [[false, false, false, false, true, true]], [[false, false, false, true, false, false]], [[false, false, false, true, false, true]], [[false, fal... | introductory | https://www.codewars.com/kata/58f625e20290fb29c3000056 |
def alt_or(lst):
|
4,591 | The Spelling Bee bees are back...
# How many bees are in the beehive?
* bees can be facing UP, DOWN, LEFT, RIGHT, and now also _diagonally_ up/down/left/right
* bees can share parts of other bees
## Examples
Ex1
```
bee.bee
.e..e..
.b..eeb
```
_Answer: 5_
Ex2
```
beee..
eeb.e.
ebee.b
```
_Answer: 7_ | ["def how_many_bees(h):\n if not h: return 0\n v = list(zip(*h))\n b = [None] * len(h)\n sf = (b[i:] + l + b[:i] for i,l in enumerate(h))\n sb = (b[:i] + l + b[i:] for i,l in enumerate(h))\n df = [[n for n in l if n is not None] for l in zip(*sf)]\n db = [[n for n in l if n is not None] for l in zi... | {"fn_name": "how_many_bees", "inputs": [[null]], "outputs": [[0]]} | introductory | https://www.codewars.com/kata/58f290d0b48966547f00014c |
def how_many_bees(hive):
|
4,592 | Regular Tic-Tac-Toe is boring.
That's why in this Kata you will be playing Tic-Tac-Toe in **3D** using a 4 x 4 x 4 matrix!
# Kata Task
Play the game. Work out who wins.
Return a string
* `O wins after moves`
* `X wins after moves`
* `No winner`
# Rules
* Player `O` always goes first
* Input `moves` is list/... | ["from itertools import product\n\ndef winning_lines(size, dimension):\n if dimension == 1: return frozenset({frozenset({(n,) for n in range(size)})})\n lines = set()\n for line, idx, val in product(winning_lines(size, dimension - 1), range(dimension), range(size)):\n lines.add(frozenset({cell[:idx] + (... | {"fn_name": "play_OX_3D", "inputs": [[[]]], "outputs": [["No winner"]]} | introductory | https://www.codewars.com/kata/5aa67541373c2e69a20000c9 |
def play_OX_3D(moves):
|
4,593 | You are given two sorted arrays that contain only integers. Your task is to find a way to merge them into a single one, sorted in **ascending order**. Complete the function `mergeArrays(arr1, arr2)`, where `arr1` and `arr2` are the original sorted arrays.
You don't need to worry about validation, since `arr1` and `arr... | ["def merge_arrays(arr1, arr2):\n return sorted(set(arr1+arr2))", "merge_arrays = lambda a, b: sorted(list(set(a + b)))", "merge_arrays = lambda a1, a2: sorted(set(a1+a2))", "def merge_arrays(arr1, arr2):\n for arr in (arr1, arr2):\n if arr[0] > arr[-1]:\n arr.reverse()\n res = []\n i = 0\n k = 0\n whil... | {"fn_name": "merge_arrays", "inputs": [[[1, 2, 3, 4], [5, 6, 7, 8]], [[10, 8, 6, 4, 2], [9, 7, 5, 3, 1]], [[-20, 35, 36, 37, 39, 40], [-10, -5, 0, 6, 7, 8, 9, 10, 25, 38, 50, 62]], [[5, 6, 7, 8, 9, 10], [20, 18, 15, 14, 13, 12, 11, 4, 3, 2]], [[45, 30, 20, 15, 12, 5], [9, 10, 18, 25, 35, 50]], [[-8, -3, -2, 4, 5, 6, 7,... | introductory | https://www.codewars.com/kata/5899642f6e1b25935d000161 |
def merge_arrays(arr1, arr2):
|
4,594 | Write a function that outputs the transpose of a matrix - a new matrix
where the columns and rows of the original are swapped.
For example, the transpose of:
| 1 2 3 |
| 4 5 6 |
is
| 1 4 |
| 2 5 |
| 3 6 |
The input to your function will be an array of matrix rows. You can
assume that each row... | ["def transpose(matrix):\n return list(map(list, zip(*matrix)))", "def transpose(matrix):\n return [[row[i] for row in matrix] for i, col in enumerate(matrix[0])]", "import numpy as np\n\n# Take your pick\ndef transpose(matrix):\n return list(map(list, zip(*matrix)))\n return np.transpose(matrix).tolist()",... | {"fn_name": "transpose", "inputs": [[[[1]]], [[[1, 2, 3]]], [[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0]]]], "outputs": [[[[1]]], [[[1], [2], [3]]], [[[1, 4, 7], [2, 5, 8], [3, 6, 9]]], [[[1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]]]]} | introductory | https://www.codewars.com/kata/52fba2a9adcd10b34300094c |
def transpose(matrix):
|
4,595 | # Task
In the Land Of Chess, bishops don't really like each other. In fact, when two bishops happen to stand on the same diagonal, they immediately rush towards the opposite ends of that same diagonal.
Given the initial positions (in chess notation) of two bishops, `bishop1` and `bishop2`, calculate their future pos... | ["def bishop_diagonal(a, b):\n a, b = sorted([['abcdefgh'.index(f), '12345678'.index(r)] for f, r in [a, b]])\n m = int((b[1] - a[1])/(b[0] - a[0])) if abs(a[1] - b[1]) == abs(a[0] - b[0]) and abs(a[1] - b[1]) else 0\n if m:\n while all(0 < e < 7 for e in a): a = [a[0] - 1, a[1] - m]\n while all(... | {"fn_name": "bishop_diagonal", "inputs": [["d7", "f5"], ["d8", "b5"], ["a1", "h8"], ["g3", "e1"], ["b4", "e7"]], "outputs": [[["c8", "h3"]], [["b5", "d8"]], [["a1", "h8"]], [["e1", "h4"]], [["a3", "f8"]]]} | introductory | https://www.codewars.com/kata/5897e394fcc4b9c310000051 |
def bishop_diagonal(bishop1, bishop2):
|
4,596 | Write a function that takes a number or a string and gives back the number of **permutations without repetitions** that can generated using all of its element.; more on permutations [here](https://en.wikipedia.org/wiki/Permutation).
For example, starting with:
```
1
45
115
"abc"
```
You could respectively generate:
`... | ["from operator import mul\nfrom math import factorial\nfrom functools import reduce\nfrom collections import Counter\n\ndef perms(inp):\n return factorial(len(str(inp))) // reduce(mul, map(factorial, Counter(str(inp)).values()), 1)", "from math import factorial\ndef perms(e):\n e = str(e)\n n = factorial(len(... | {"fn_name": "perms", "inputs": [[2], [25], [342], [1397], [76853], ["a"], ["ab"], ["abc"], [737], [66666]], "outputs": [[1], [2], [6], [24], [120], [1], [2], [6], [3], [1]]} | introductory | https://www.codewars.com/kata/571bff6082661c8a11000823 |
def perms(element):
|
4,597 | Write
```python
function combine()
```
that combines arrays by alternatingly taking elements passed to it.
E.g
```python
combine(['a', 'b', 'c'], [1, 2, 3]) == ['a', 1, 'b', 2, 'c', 3]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5]) == ['a', 1, 'b', 2, 'c', 3, 4, 5]
combine(['a', 'b', 'c'], [1, 2, 3, 4, 5], [6, 7], [8]) ... | ["def combine(*args):\n out = list()\n for i in range(len(max(args, key=len))): #Sometimes you just have to love python\n for arr in args:\n if i < len(arr): out.append(arr[i])\n return out", "from itertools import chain, zip_longest\n\ndef combine(*args):\n return [x for x in chain.from_iterable(zip_long... | {"fn_name": "combine", "inputs": [[["a", "b", "c"], [1, 2, 3]], [["a", "b", "c"], [1, 2, 3, 4, 5]], [["a", "b", "c"], [1, 2, 3, 4, 5], [6, 7], [8]], [[{"a": 1}, {"b": 2}], [1, 2]], [[{"a": 2, "b": 1}, {"a": 1, "b": 2}], [1, 2, 3, 4], [5, 6], [7]]], "outputs": [[["a", 1, "b", 2, "c", 3]], [["a", 1, "b", 2, "c", 3, 4, 5]... | introductory | https://www.codewars.com/kata/55e529bf6c6497394a0000b5 |
def combine(*args):
|
4,598 | In this kata you need to write a function that will receive two strings (```n1``` and ```n2```), each representing an integer as a binary number. A third parameter will be provided (```o```) as a string representing one of the following operators: add, subtract, multiply.
Your task is to write the calculate function s... | ["def calculate(n1, n2, o):\n operators = {\n \"add\": (lambda x, y: x + y),\n \"subtract\": (lambda x, y: x - y),\n \"multiply\": (lambda x, y: x * y),\n }\n \n return \"{:b}\".format( operators[o]( int(n1, 2), int(n2, 2) ) )", "def calculate(n1, n2, o):\n def s2b(i):\n retur... | {"fn_name": "calculate", "inputs": [["1", "1", "add"], ["1", "1", "subtract"], ["1", "1", "multiply"], ["10", "10", "multiply"], ["100", "10", "subtract"]], "outputs": [["10"], ["0"], ["1"], ["100"], ["10"]]} | introductory | https://www.codewars.com/kata/546ba103f0cf8f7982000df4 |
def calculate(n1, n2, o):
|
4,599 | To pass the series of gates guarded by the owls, Kenneth needs to present them each with a highly realistic portrait of one. Unfortunately, he is absolutely rubbish at drawing, and needs some code to return a brand new portrait with a moment's notice.
All owl heads look like this:
''0v0''
Such beautiful eyes!
H... | ["import re\n\ndef owl_pic(text):\n str = re.sub('[^ 8,W,T,Y,U,I,O,A,H,X,V,M]', '', text.upper())\n return str+\"''0v0''\"+str[::-1]", "def owl_pic(text):\n plumage = \"\".join(c for c in text.upper() if c in \"8WTYUIOAHXVM\")\n return f\"{plumage}''0v0''{plumage[::-1]}\"", "plumm = '8WTYUIOAHXVM'\ndef owl_... | {"fn_name": "owl_pic", "inputs": [["xwe"], ["kuawd6r8q27y87t93r76352475437"], ["t6ggggggggWw"], ["xweWXo"]], "outputs": [["XW''0v0''WX"], ["UAW8Y8T''0v0''T8Y8WAU"], ["TWW''0v0''WWT"], ["XWWXO''0v0''OXWWX"]]} | introductory | https://www.codewars.com/kata/55aa7acc42216b3dd6000022 |
def owl_pic(text):
|
4,600 | Write an algorithm that takes an array and moves all of the zeros to the end, preserving the order of the other elements.
```python
move_zeros([False,1,0,1,2,0,1,3,"a"]) # returns[False,1,1,2,1,3,"a",0,0]
``` | ["def move_zeros(arr):\n l = [i for i in arr if isinstance(i, bool) or i!=0]\n return l+[0]*(len(arr)-len(l))", "def move_zeros(array):\n return sorted(array, key=lambda x: x==0 and type(x) is not bool)", "def move_zeros(array):\n return sorted(array, key=lambda x: x == 0 and x is not False)", "def move_zer... | {"fn_name": "move_zeros", "inputs": [[[1, 2, 0, 1, 0, 1, 0, 3, 0, 1]], [[9, 0.0, 0, 9, 1, 2, 0, 1, 0, 1, 0.0, 3, 0, 1, 9, 0, 0, 0, 0, 9]], [["a", 0, 0, "b", "c", "d", 0, 1, 0, 1, 0, 3, 0, 1, 9, 0, 0, 0, 0, 9]], [["a", 0, 0, "b", null, "c", "d", 0, 1, false, 0, 1, 0, 3, [], 0, 1, 9, 0, 0, {}, 0, 0, 9]], [[0, 1, null, 2,... | introductory | https://www.codewars.com/kata/52597aa56021e91c93000cb0 |
def move_zeros(array):
|
4,601 | The Mormons are trying to find new followers and in order to do that they embark on missions.
Each time they go on a mission, every Mormons converts a fixed number of people (reach) into followers. This continues and every freshly converted Mormon as well as every original Mormon go on another mission and convert the ... | ["def mormons(starting_number, reach, target):\n missions = 0\n while starting_number < target:\n starting_number += starting_number * reach\n missions += 1\n return missions\n\n\n# def mormons(start, reach, target, missions=0):\n# if start >= target:\n# return missions\n# return ... | {"fn_name": "mormons", "inputs": [[40, 2, 120], [40, 2, 121]], "outputs": [[1], [2]]} | introductory | https://www.codewars.com/kata/58373ba351e3b615de0001c3 |
def mormons(starting_number, reach, target):
|
4,602 | An **anagram** is the result of rearranging the letters of a word to produce a new word.
**Note:** anagrams are case insensitive
Complete the function to return `true` if the two arguments given are anagrams of each other; return `false` otherwise.
## Examples
* `"foefet"` is an anagram of `"toffee"`
* `"Buckethe... | ["def is_anagram(test, original):\n return sorted(original.lower()) == sorted(test.lower()) ", "def is_anagram(test, original):\n return sorted(test.lower()) == sorted(original.lower())", "from collections import Counter\n# write the function is_anagram\ndef is_anagram(test, original):\n return Counter(test.lo... | {"fn_name": "is_anagram", "inputs": [["foefet", "toffee"], ["Buckethead", "DeathCubeK"], ["Twoo", "WooT"], ["dumble", "bumble"], ["ound", "round"], ["apple", "pale"]], "outputs": [[true], [true], [true], [false], [false], [false]]} | introductory | https://www.codewars.com/kata/529eef7a9194e0cbc1000255 |
def is_anagram(test, original):
|
4,603 | The Ackermann function is a famous function that played a big role in computability theory as the first example of a total computable function that is not primitive recursive.
Since then the function has been a bit simplified but is still of good use. Due to its definition in terms of extremely deep recursion it can b... | ["from numbers import Number\ndef Ackermann(m,n):\n if isinstance(n, Number) and isinstance(m, Number):\n if m >= 0 and n >= 0:\n return Ackermann_Aux(m,n)\n \n return None\n\n \ndef Ackermann_Aux(m,n):\n \n if m == 0:\n return n + 1\n \n if m > 0:\n if n == 0... | {"fn_name": "Ackermann", "inputs": [[1, 1], [4, 0], [3, 3]], "outputs": [[3], [13], [61]]} | introductory | https://www.codewars.com/kata/53ad69892a27079b34000bd9 |
def Ackermann(m,n):
|
4,604 | A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are:
2332
110011
54322345
For this kata, single digit numbers will not be considered numerical palindromes.
For a given number ```num```, write a function to test if t... | ["def palindrome(num):\n if type(num) != int or num < 0: return \"Not valid\"\n s = str(num)\n for i in range(len(s)-2):\n if s[i] == s[i+1] or s[i] == s[i+2]: return True\n return len(s) != 1 and s[-1] == s[-2]", "def palindrome(num):\n return \"Not valid\" if type(num) != int or num < 0 else boo... | {"fn_name": "palindrome", "inputs": [[868], [1321], [1215], [2], [123322367], [1551], [13598], ["ACCDDCCA"], ["1551"], [-4505], [22.22]], "outputs": [[true], [false], [true], [false], [true], [true], [false], ["Not valid"], ["Not valid"], ["Not valid"], ["Not valid"]]} | introductory | https://www.codewars.com/kata/58de819eb76cf778fe00005c |
def palindrome(num):
|
4,605 | # Task
If string has more than one neighboring dashes(e.g. --) replace they with one dash(-).
Dashes are considered neighbors even if there is some whitespace **between** them.
# Example
For `str = "we-are- - - code----warriors.-"`
The result should be `"we-are- code-warriors.-"`
# Input/Output
- `[inpu... | ["import re\ndef replace_dashes_as_one(s):\n return re.sub(r'-[ -]+-|-+',r'-',s)", "import re\ndef replace_dashes_as_one(s):\n return re.sub(\"-[- ]*-\",\"-\",s)", "from re import sub\n\ndef replace_dashes_as_one(s):\n return sub(\"-[\\s-]*-\", '-', s)", "import re\n\ndef replace_dashes_as_one(s):\n return re... | {"fn_name": "replace_dashes_as_one", "inputs": [["we-are- - - code----warriors.-"], ["a---b- - -c"], ["a------"], ["Lorem - ipsum- - - dolor sit amet, consectetur adipiscing elit. Praesent tristique lectus non erat dapibus tincidunt. Integer non nibh fermentum, cursus-diam -------pharetra, mattis--risus.-------"]], "ou... | introductory | https://www.codewars.com/kata/58af9f7320a9ecedb30000f1 |
def replace_dashes_as_one(s):
|
4,606 | ## Task
Complete the function that receives an array of strings (`arr`) as an argument and returns all the valid Roman numerals.
Basic Roman numerals are denoted as:
```
I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000
```
For the purposes of this kata we will consider valid only the numbers in range 0 - 5000 (bot... | ["import re\n\nPATTERN = re.compile(\"^\"\n \"M{0,4}\" # thousands\n \"(CM|CD|D?C{,3})\" # hundreds\n \"(XC|XL|L?X{,3})\" # tens\n \"(IX|IV|V?I{,3})\" # units\n \"$\")\n\ndef valid_romans(arr):\n return [e for e in arr if e and PATTERN.match(e)]", "import re\n\n\ndef valid_romans(... | {"fn_name": "valid_romans", "inputs": [[["MMMCDLXVL", "MDLXXXVI", "DCLXII", "MMMMCLL", "MMDCCCLXXXIVCD"]], [["MMMMCCCXXXII", "MMDCCCXXVCD", "MMCCCXLV", "DCCLXVIIICD", "MMMMCXII"]], [["DCCLIVI", "MDCCXXXVVI", "MDLXXVI", "MDVIL", "MCCLXIII"]], [["DV", "", "CLVIII", "MDCCCXXCD", "MDCLXVI", "MMMDCCCLXXXVI"]], [["MMCDXVIII"... | introductory | https://www.codewars.com/kata/58334362c5637ad0bb0001c2 |
def valid_romans(arr):
|
4,607 | Given a certain number, how many multiples of three could you obtain with its digits?
Suposse that you have the number 362. The numbers that can be generated from it are:
```
362 ----> 3, 6, 2, 36, 63, 62, 26, 32, 23, 236, 263, 326, 362, 623, 632
```
But only:
```3, 6, 36, 63``` are multiple of three.
We need a fun... | ["from itertools import permutations\n\ndef find_mult_3(num):\n num_list = tuple(map(int, str(num)))\n \n poss = set()\n for i in range(1, len(num_list)+1):\n poss |= set(permutations(num_list, i))\n \n res = set()\n for p in poss:\n if p[0] != 0 and sum(p) % 3 == 0:\n res.... | {"fn_name": "find_mult_3", "inputs": [[362], [6063], [7766553322]], "outputs": [[[4, 63]], [[25, 6630]], [[55510, 766553322]]]} | introductory | https://www.codewars.com/kata/5828b9455421a4a4e8000007 |
def find_mult_3(num):
|
4,608 | I need to save some money to buy a gift. I think I can do something like that:
First week (W0) I save nothing on Sunday, 1 on Monday, 2 on Tuesday... 6 on Saturday,
second week (W1) 2 on Monday... 7 on Saturday and so on according to the table below where the days are numbered from 0 to 6.
Can you tell me how much I ... | ["def finance(n):\n return n * (n + 1) * (n + 2) / 2", "def finance(n):\n savings = 0\n for weeks in range(n+1):\n for days in range(weeks,n+1):\n savings += weeks + days\n return savings", "finance = lambda n: n * (n + 1) * (n + 2) / 2\n", "def finance(n):\n # For each n, there are (n ... | {"fn_name": "finance", "inputs": [[5], [6], [8], [15], [100], [365], [730], [999], [2000], [4000], [5000]], "outputs": [[105], [168], [360], [2040], [515100], [24513765], [195308580], [499999500], [4006002000], [32024004000], [62537505000]]} | introductory | https://www.codewars.com/kata/559ce00b70041bc7b600013d |
def finance(n):
|
4,609 | Ronald's uncle left him 3 fertile chickens in his will. When life gives you chickens, you start a business selling chicken eggs which is exactly what Ronald decided to do.
A chicken lays 300 eggs in its first year. However, each chicken's egg production decreases by 20% every following year (rounded down) until when ... | ["def egged(year, span): \n total = 0\n eggs_per_chicken = 300\n for i in range(min(span,year)):\n total += 3 * eggs_per_chicken\n eggs_per_chicken = int(eggs_per_chicken * 0.8)\n \n return total or \"No chickens yet!\"", "def egged(year, span, chickens = 3):\n production = [300, 2... | {"fn_name": "egged", "inputs": [[0, 5], [2, 1], [4, 8], [74, 10], [1, 15]], "outputs": [["No chickens yet!"], [900], [2655], [3984], [900]]} | introductory | https://www.codewars.com/kata/58c1446b61aefc34620000aa |
def egged(year, span):
|
4,610 | # Task
Initially a number `1` is written on a board. It is possible to do the following operations with it:
```
multiply the number by 3;
increase the number by 5.```
Your task is to determine that using this two operations step by step, is it possible to obtain number `n`?
# Example
For `n = 1`, the result should ... | ["def number_increasing(n):\n return n not in {2, 4, 7, 12, 17, 22} and n % 5 != 0\n", "from math import log\n\n\ndef number_increasing(n):\n return any(log(x,3).is_integer() for x in range(n, 0, -5))", "def number_increasing(n):\n return False if n in (2, 4, 7, 12, 17, 22) or not n % 5 else True", "def number... | {"fn_name": "number_increasing", "inputs": [[1], [2], [3], [4], [5], [6], [100], [101], [12345], [54321]], "outputs": [[true], [false], [true], [false], [false], [true], [false], [true], [false], [true]]} | introductory | https://www.codewars.com/kata/589d1e88e8afb7a85e00004e |
def number_increasing(n):
|
4,611 | #Description
Everybody has probably heard of the animal heads and legs problem from the earlier years at school. It goes:
```“A farm contains chickens and cows. There are x heads and y legs. How many chickens and cows are there?” ```
Where x <= 1000 and y <=1000
#Task
Assuming there are no other types of animals, ... | ["def animals(heads, legs):\n chickens, cows = 2*heads-legs/2, legs/2-heads\n if chickens < 0 or cows < 0 or not chickens == int(chickens) or not cows == int(cows):\n return \"No solutions\"\n return chickens, cows", "def animals(heads, legs):\n chickens = heads * 2 - legs / 2\n cows = heads - chi... | {"fn_name": "animals", "inputs": [[72, 200], [116, 282], [12, 24], [6, 24], [344, 872], [158, 616], [25, 555], [12, 25], [54, 956], [5455, 54956], [0, 0], [-1, -1], [500, 0], [0, 500], [-45, 5], [5, -55]], "outputs": [[[44, 28]], [[91, 25]], [[12, 0]], [[0, 6]], [[252, 92]], [[8, 150]], ["No solutions"], ["No solutions... | introductory | https://www.codewars.com/kata/574c5075d27783851800169e |
def animals(heads, legs):
|
4,612 | Math hasn't always been your best subject, and these programming symbols always trip you up!
I mean, does `**` mean *"Times, Times"* or *"To the power of"*?
Luckily, you can create the function `expression_out()` to write out the expressions for you!
The operators you'll need to use are:
```python
{ '+': 'Plus ',... | ["op = {'+': 'Plus ','-': 'Minus ','*': 'Times ', '/': 'Divided By ', '**': 'To The Power Of ', '=': 'Equals ', '!=': 'Does Not Equal '}\nnum = {'1': 'One', '2': 'Two', '3': 'Three', '4': 'Four', '5': 'Five', '6': 'Six', '7':'Seven', '8': 'Eight', '9': 'Nine', '10': 'Ten'}\n \ndef expression_out(e):\n a, b, c = e... | {"fn_name": "expression_out", "inputs": [["1 + 3"], ["2 - 10"], ["6 ** 9"], ["5 = 5"], ["7 * 4"], ["2 / 2"], ["8 != 5"]], "outputs": [["One Plus Three"], ["Two Minus Ten"], ["Six To The Power Of Nine"], ["Five Equals Five"], ["Seven Times Four"], ["Two Divided By Two"], ["Eight Does Not Equal Five"]]} | introductory | https://www.codewars.com/kata/57e2afb6e108c01da000026e |
def expression_out(exp):
|
4,613 | ##Task:
You have to write a function `add` which takes two binary numbers as strings and returns their sum as a string.
##Note:
* You are `not allowed to convert binary to decimal & vice versa`.
* The sum should contain `No leading zeroes`.
##Examples:
```
add('111','10'); => '1001'
add('1101','101'); => '10010'
add(... | ["def binary_string_to_int(string):\n return sum((d == '1') * 2**i for i, d in enumerate(string[::-1]))\n\ndef add(a, b):\n return '{:b}'.format(binary_string_to_int(a) + binary_string_to_int(b))", "from itertools import zip_longest\n\nADDER = {\n ('0', '0', '0'): ('0', '0'),\n ('0', '0', '1'): ('1', '0'),\... | {"fn_name": "add", "inputs": [["111", "10"], ["1101", "101"], ["1101", "10111"], ["10111", "001010101"], ["00", "0"]], "outputs": [["1001"], ["10010"], ["100100"], ["1101100"], ["0"]]} | introductory | https://www.codewars.com/kata/55c11989e13716e35f000013 |
def add(a,b):
|
4,614 | You are the judge at a competitive eating competition and you need to choose a winner!
There are three foods at the competition and each type of food is worth a different amount of points.
Points are as follows:
- Chickenwings: 5 points
- Hamburgers: 3 points
- Hotdogs: 2 points
Write a function that helps yo... | ["def scoreboard(who_ate_what):\n scores = {'chickenwings': 5, 'hamburgers': 3, 'hotdogs': 2}\n return sorted((\n {'name': person.pop('name'),\n 'score': sum(scores.get(k, 0) * v for k, v in list(person.items()))}\n for person in who_ate_what), key=lambda a: (-a['score'], a['name']))\n", "PT... | {"fn_name": "scoreboard", "inputs": [[[{"name": "Billy The Beast", "chickenwings": 17, "hamburgers": 7, "hotdogs": 8}, {"name": "Habanero Hillary", "chickenwings": 5, "hamburgers": 17, "hotdogs": 11}, {"name": "Joey Jaws", "chickenwings": 8, "hamburgers": 8, "hotdogs": 15}, {"name": "Big Bob", "chickenwings": 20, "hamb... | introductory | https://www.codewars.com/kata/571d2e9eeed4a150d30011e7 |
def scoreboard(who_ate_what):
|
4,615 | Our AAA company is in need of some software to help with logistics: you will be given the width and height of a map, a list of x coordinates and a list of y coordinates of the supply points, starting to count from the top left corner of the map as 0.
Your goal is to return a two dimensional array/list with every item ... | ["def logistic_map(width,height,xs,ys):\n return [ [ min([abs(x-x2)+abs(y-ys[i]) for (i,x2) in enumerate(xs)]) if len(xs) else None for x in range(width) ] for y in range(height) ]", "def logistic_map(w, h, xs, ys):\n md = lambda i, j: min((abs(x - i) + abs(y - j) for x, y in zip(xs, ys)), default=None)\n retu... | {"fn_name": "logistic_map", "inputs": [[3, 3, [0], [0]], [3, 3, [2], [2]], [1, 1, [0], [0]], [5, 2, [0, 4], [0, 0]], [2, 2, [], []]], "outputs": [[[[0, 1, 2], [1, 2, 3], [2, 3, 4]]], [[[4, 3, 2], [3, 2, 1], [2, 1, 0]]], [[[0]]], [[[0, 1, 2, 1, 0], [1, 2, 3, 2, 1]]], [[[null, null], [null, null]]]]} | introductory | https://www.codewars.com/kata/5779624bae28070489000146 |
def logistic_map(width,height,xs,ys):
|
4,616 | The goal of this Kata is to reduce the passed integer to a single digit (if not already) by converting the number to binary, taking the sum of the binary digits, and if that sum is not a single digit then repeat the process.
- n will be an integer such that 0 < n < 10^20
- If the passed integer is already a single dig... | ["def single_digit(n):\n while n > 9:\n n = bin(n).count(\"1\")\n return n", "def single_digit(n):\n while n > 9:\n n = int(bin(n).count('1'))\n return n", "def single_digit(n):\n return n if n<10 else single_digit(bin(n).count(\"1\"))", "def single_digit(n):\n if len(str(n)) == 1:\n ... | {"fn_name": "single_digit", "inputs": [[5], [999], [1234444123], [443566], [565656565], [9889345778311094737448], [4868872], [234234235], [567448], [10000000000]], "outputs": [[5], [8], [1], [2], [3], [2], [8], [2], [7], [3]]} | introductory | https://www.codewars.com/kata/5a7778790136a132a00000c1 |
def single_digit(n):
|
4,617 | Complete the function that takes a non-negative integer `n` as input, and returns a list of all the powers of 2 with the exponent ranging from 0 to `n` (inclusive).
## Examples
```python
n = 0 ==> [1] # [2^0]
n = 1 ==> [1, 2] # [2^0, 2^1]
n = 2 ==> [1, 2, 4] # [2^0, 2^1, 2^2]
``` | ["def powers_of_two(n):\n return [2**x for x in range(n+1)]", "def powers_of_two(n):\n return [1<<x for x in range(n + 1)]", "def powers_of_two(n): return [ 2 ** i for i in range(n+1) ]", "def powers_of_two(n):\n a = []\n for i in range(0, n + 1):\n a.append(2 ** i) \n return a", "from itertool... | {"fn_name": "powers_of_two", "inputs": [[0], [1], [4]], "outputs": [[[1]], [[1, 2]], [[1, 2, 4, 8, 16]]]} | introductory | https://www.codewars.com/kata/57a083a57cb1f31db7000028 |
def powers_of_two(n):
|
4,618 | You get an array of numbers, return the sum of all of the positives ones.
Example `[1,-4,7,12]` => `1 + 7 + 12 = 20`
Note: if there is nothing to sum, the sum is default to `0`. | ["def positive_sum(arr):\n return sum(x for x in arr if x > 0)\n", "def positive_sum(arr):\n sum = 0\n for e in arr:\n if e > 0:\n sum = sum + e\n return sum", "def positive_sum(arr):\n return sum(filter(lambda x: x > 0,arr))", "def positive_sum(arr):\n ''' I really hate these one li... | {"fn_name": "positive_sum", "inputs": [[[1, 2, 3, 4, 5]], [[1, -2, 3, 4, 5]], [[-1, 2, 3, 4, -5]], [[]], [[-1, -2, -3, -4, -5]]], "outputs": [[15], [13], [9], [0], [0]]} | introductory | https://www.codewars.com/kata/5715eaedb436cf5606000381 |
def positive_sum(arr):
|
4,619 | # Task
Two players - `"black"` and `"white"` are playing a game. The game consists of several rounds. If a player wins in a round, he is to move again during the next round. If a player loses a round, it's the other player who moves on the next round. Given whose turn it was on the previous round and whether he won, de... | ["def whoseMove(lastPlayer, win):\n return lastPlayer if win else 'white' if lastPlayer == 'black' else 'black'", "def whoseMove(lastPlayer, win):\n players = ['white', 'black']\n return lastPlayer if win else players[players.index(lastPlayer) - 1]", "def whoseMove(lastPlayer, win):\n return [\"white\", \"b... | {"fn_name": "whoseMove", "inputs": [["black", false], ["white", false], ["black", true], ["white", true]], "outputs": [["white"], ["black"], ["black"], ["white"]]} | introductory | https://www.codewars.com/kata/59126992f9f87fd31600009b |
def whoseMove(lastPlayer, win):
|
4,620 | Take an input string and return a string that is made up of the number of occurences of each english letter in the input followed by that letter, sorted alphabetically. The output string shouldn't contain chars missing from input (chars with 0 occurence); leave them out.
An empty string, or one with no letters, should... | ["from collections import Counter\n\ndef string_letter_count(s):\n cnt = Counter(c for c in s.lower() if c.isalpha())\n return ''.join(str(n)+c for c,n in sorted(cnt.items()))", "def string_letter_count(s):\n s = s.lower()\n m = ''\n for i in sorted(list(set(s))):\n if i.islower():\n m ... | {"fn_name": "string_letter_count", "inputs": [["The quick brown fox jumps over the lazy dog."], ["The time you enjoy wasting is not wasted time."], ["./4592#{}()"], ["This%Sentence\"is$$being^tested."], ["abccdefgdhijklmno_pqrsTuvwxYz"], [""], ["."], ["y"]], "outputs": [["1a1b1c1d3e1f1g2h1i1j1k1l1m1n4o1p1q2r1s2t2u1v1w1... | introductory | https://www.codewars.com/kata/59e19a747905df23cb000024 |
def string_letter_count(s):
|
4,621 | ---
# Story
The Pied Piper has been enlisted to play his magical tune and coax all the rats out of town.
But some of the rats are deaf and are going the wrong way!
# Kata Task
How many deaf rats are there?
# Legend
* ```P``` = The Pied Piper
* ```O~``` = Rat going left
* ```~O``` = Rat going right
# Example
* ... | ["def count_deaf_rats(town):\n return town.replace(' ', '')[::2].count('O')", "import re\ndef count_deaf_rats(town):\n return re.findall(r\"O~|~O\",town.split(\"P\")[0]).count(\"O~\") + re.findall(r\"O~|~O\",town.split(\"P\")[1]).count(\"~O\")", "import re\n\ndef count_deaf_rats(town):\n town = re.sub(\"(~O|O~... | {"fn_name": "count_deaf_rats", "inputs": [["~O~O~O~O P"], ["P O~ O~ ~O O~"], ["~O~O~O~OP~O~OO~"], ["O~~OO~~OO~~OO~P~OO~~OO~~OO~~O"], ["~OP"], ["PO~"], ["O~P"], ["P~O"], [" P"], ["P "], [" P "], ["P"]], "outputs": [[0], [1], [2], [8], [0], [0], [1], [1], [0], [0], [0], [0]]} | introductory | https://www.codewars.com/kata/598106cb34e205e074000031 |
def count_deaf_rats(town):
|
4,622 | Your job is to build a function which determines whether or not there are double characters in a string (including whitespace characters). For example ```aa```, ``!!`` or ``` ```.
You want the function to return true if the string contains double characters and false if not. The test should not be case sensitive; ... | ["import re\n\ndef double_check(str):\n return bool(re.search(r\"(.)\\1\", str.lower()))", "def double_check(str):\n str = str.lower()\n c1 = ''\n for c in str:\n if c == c1:\n return True\n c1 = c\n return False", "from itertools import groupby\n\n\ndef double_check(s):\n return any(... | {"fn_name": "double_check", "inputs": [["abca"], ["aabc"], ["a 11 c d"], ["AabBcC"], ["a b c"], ["a b c d e f g h i h k"], ["2020"], ["a!@\u20ac\u00a3#$%^&*()_-+=}]{[|':;?/>.<,~"]], "outputs": [[false], [true], [true], [true], [true], [false], [false], [false]]} | introductory | https://www.codewars.com/kata/56a24b4d9f3671584d000039 |
def double_check(strng):
|
4,623 | Make the 2D list by the sequential integers started by the ```head``` number.
See the example test cases for the expected output.
```
Note:
-10**20 < the head number <10**20
1 <= the number of rows <= 1000
0 <= the number of columms <= 1000
``` | ["def make_2d_list(head,row,col):\n return [[head + c + r*col for c in range(col)] for r in range(row)]", "import numpy as np\n\ndef make_2d_list(head,row,col):\n return np.array(list(range(head, head + row*col))).reshape(row, col).tolist()\n", "make_2d_list=lambda Q,R,C:[[Q + C * r + c for c in range(C)] for r i... | {"fn_name": "make_2d_list", "inputs": [[1, 2, 3], [2, 3, 4], [5, 6, 1], [7, 1, 1], [0, 1, 0], [-20, 2, 2], [10000000000, 2, 2]], "outputs": [[[[1, 2, 3], [4, 5, 6]]], [[[2, 3, 4, 5], [6, 7, 8, 9], [10, 11, 12, 13]]], [[[5], [6], [7], [8], [9], [10]]], [[[7]]], [[[]]], [[[-20, -19], [-18, -17]]], [[[10000000000, 1000000... | introductory | https://www.codewars.com/kata/5a8897d4ba1bb5f266000057 |
def make_2d_list(head,row,col):
|
4,624 | The four bases found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T).
In genetics, GC-content is the percentage of Guanine (G) and Cytosine (C) bases on a DNA molecule that are either guanine or cytosine.
Given a DNA sequence (a string) return the GC-content in percent, rounded up to 2 decimal digi... | ["def gc_content(seq):\n if not seq :\n return 0.0\n else:\n res = seq.count(\"C\")+seq.count(\"G\")\n return round(res*100/len(seq),2)\n", "def gc_content(seq):\n if not seq:\n return 0\n gc_cnt = total_chars = 0\n for a in seq:\n if a in 'GC':\n gc_cnt += 1... | {"fn_name": "gc_content", "inputs": [[""], ["A"], ["C"], ["CA"]], "outputs": [[0.0], [0.0], [100.0], [50.0]]} | introductory | https://www.codewars.com/kata/5747a9bbe2fab9a0c400012f |
def gc_content(seq):
|
4,625 | In this task you have to code process planner.
You will be given initial thing, target thing and a set of processes to turn one thing into another (in the form of _[process\_name, start\_thing, end\_thing]_). You must return names of shortest sequence of processes to turn initial thing into target thing, or empty seq... | ["def processes(start, end, processes):\n '''Dijkstra's shortest path algorithm'''\n q = [(start,[])]\n visited = set()\n \n while q:\n s, path = q.pop(0)\n if s == end: return path\n visited.add(s)\n for p in [x for x in processes if x[1] == s]:\n if not p[2] in visited:\n ... | {"fn_name": "processes", "inputs": [["a", "c", [["1", "a", "c"], ["2", "a", "b"], ["3", "b", "c"]]], ["a", "d", [["1", "a", "b"], ["2", "b", "c"], ["3", "c", "b"]]], ["a", "d", [["1", "a", "b"], ["2", "b", "c"], ["3", "c", "b"], ["4", "c", "d"]]]], "outputs": [[["1"]], [[]], [["1", "2", "4"]]]} | introductory | https://www.codewars.com/kata/542ea700734f7daff80007fc |
def processes(start, end, processes):
|
4,626 | You're hanging out with your friends in a bar, when suddenly one of them is so drunk, that he can't speak, and when he wants to say something, he writes it down on a paper. However, none of the words he writes make sense to you. He wants to help you, so he points at a beer and writes "yvvi". You start to understand wha... | ["def parse_character(char):\n if 65 <= ord(char) <= 90:\n return chr(155 - ord(char))\n elif 97 <= ord(char) <= 122:\n return chr(219 - ord(char))\n else:\n return char\n\ndef decode(string_):\n if not isinstance(string_, str):\n return \"Input is not a string\"\n return \"\"... | {"fn_name": "decode", "inputs": [["yvvi"], ["Blf zoivzwb szw 10 yvvih"], ["Ovg'h hdrn rm gsv ulfmgzrm!"], [{"brand": "Starobrno"}], ["Tl slnv, blf'iv wifmp"], ["Hfiv r xzm wzmxv lm xlk'h xzi, slow nb yvvi"], [true], ["Hvv? R'n mlg gszg wifmp, r xzm hgroo gzpv nb xolgsvh luu"], [123], [["Beer"]]], "outputs": [["beer"], ... | introductory | https://www.codewars.com/kata/558ffec0f0584f24250000a0 |
def decode(string_):
|
4,627 | Simply find the closest value to zero from the list. Notice that there are negatives in the list.
List is always not empty and contains only integers. Return ```None``` if it is not possible to define only one of such values. And of course, we are expecting 0 as closest value to zero.
Examples:
```code
[2, 4, -1, -3]... | ["def closest(lst):\n m = min(lst, key=abs)\n return m if m == 0 or -m not in lst else None", "def closest(lst):\n result = min(lst, key=abs)\n return result if not result or -result not in lst else None\n", "def closest(lst):\n m = min(lst, key=lambda x: abs(x))\n if not m or -m not in lst: return m"... | {"fn_name": "closest", "inputs": [[[10, 3, 9, 1]], [[2, 4, -1, -3]], [[5, 2, -2]], [[5, 2, 2]], [[13, 0, -6]], [[1]], [[5, 1, -1, 2, -10]], [[5, -5, -2, 5, -3]], [[27, 37, 48, -18, 42, 16, 5, 34, 35, 26, -34, 3, -43, 35, 0, -45, -7, 45, 34, -18, 44, 12, 6, -45, 33, 27, -2, 28, 12, 9]], [[11, -30, -18, 4, -13, 43, 12, -... | introductory | https://www.codewars.com/kata/59887207635904314100007b |
def closest(lst):
|
4,628 | ## Objective
Given a number `n` we will define it's sXORe to be `0 XOR 1 XOR 2 ... XOR n` where `XOR` is the [bitwise XOR operator](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
Write a function that takes `n` and returns it's sXORe.
## Examples
| n | sXORe n
|---------|--------
| 0 | 0
... | ["def sxore(n):\n return [n, 1, n + 1, 0][n % 4]", "def sxore(n):\n return (n,1,n+1,0)[n%4]", "def sxore(n):\n res = {0: n, 1: 1, 2: n + 1, 3: 0}\n return res[n % 4]", "sxore=lambda n:{n%4==0:n,n%4==1:1,n%4==2:n+1}.get(True,0)", "sxore=lambda n:(n,1,n+1,0)[n%4]", "def sxore(n):\n return (n >> 1) & 1 ^ ( ... | {"fn_name": "sxore", "inputs": [[0], [1], [2], [50], [1000000], [1000001], [9999999999999999999999999]], "outputs": [[0], [1], [3], [51], [1000000], [1], [0]]} | introductory | https://www.codewars.com/kata/56d3e702fc231fdf72001779 |
def sxore(n):
|
4,629 | You have been speeding on a motorway and a police car had to stop you. The policeman is a funny guy that likes to play games. Before issuing penalty charge notice he gives you a choice to change your penalty.
Your penalty charge is a combination of numbers like: speed of your car, speed limit in the area, speed of th... | ["def penalty(lst):\n lst, maxLen = list(map(str, lst)), max(map(len, lst))\n return ''.join(sorted(lst, key=lambda s: s.ljust(maxLen, s[-1])))", "#return str of the smallest value of the combined numbers in a_list\ndef penalty(a_list):\n return ''.join(sorted(a_list, key = lambda n: n + n[:1]))", "penalty=lambd... | {"fn_name": "penalty", "inputs": [[["45", "30", "50", "1"]], [["100", "10", "1"]], [["32", "3"]], [["70", "46", "4", "19"]], [["71", "82", "42", "34", "90"]], [["31", "97", "6", "78"]], [["72", "7", "7", "78", "79", "709", "94"]]], "outputs": [["1304550"], ["100101"], ["323"], ["1944670"], ["3442718290"], ["3167897"], ... | introductory | https://www.codewars.com/kata/5a05a4d206d5b61ba70000f9 |
def penalty(a_list):
|
4,630 | # Task
Smartphones software security has become a growing concern related to mobile telephony. It is particularly important as it relates to the security of available personal information.
For this reason, Ahmed decided to encrypt phone numbers of contacts in such a way that nobody can decrypt them. At first he tri... | ["def decrypt(s):\n return next((str(b // 11) for b in (int(str(a) + s) for a in range(1, 11)) if b % 11 == 0), 'impossible')", "def decrypt(s):\n for i in range(1,11):\n n = int(str(i)+s)\n if n//11*11==n : return str(n//11)\n return 'impossible'", "def decrypt(s):\n x, l = int(s), 10**len(s)\n ... | {"fn_name": "decrypt", "inputs": [["353"], ["444"], ["123456"], ["147"], ["4334"]], "outputs": [["123"], ["404"], ["738496"], ["377"], ["impossible"]]} | introductory | https://www.codewars.com/kata/58a3cb34623e8c119d0000d5 |
def decrypt(s):
|
4,631 | There are two lists of different length. The first one consists of keys, the second one consists of values. Write a function ```createDict(keys, values)``` that returns a dictionary created from keys and values. If there are not enough values, the rest of keys should have a ```None``` value. If there not enough keys, j... | ["def createDict(keys, values):\n while len(keys) > len(values):\n values.append(None)\n \n dictionary = dict(list(zip(keys, values))) \n return dictionary\n", "def createDict(keys, values):\n return dict(zip(keys, values + [None]*(len(keys) - len(values))))", "def createDict(keys, values):\n r... | {"fn_name": "createDict", "inputs": [[[], []], [[], [1]], [["a"], []], [["a", "b", "c"], [1, 2, 3]], [["a", "b", "c", "d", "e"], [1, 2]], [["a", "b"], [1, 2, 3, 4]]], "outputs": [[{}], [{}], [{"a": null}], [{"a": 1, "b": 2, "c": 3}], [{"a": 1, "b": 2, "c": null, "d": null, "e": null}], [{"a": 1, "b": 2}]]} | introductory | https://www.codewars.com/kata/5533c2a50c4fea6832000101 |
def createDict(keys, values):
|
4,632 | Fans of The Wire will appreciate this one.
For those that haven't seen the show, the Barksdale Organization has a simple method for encoding telephone numbers exchanged via pagers: "Jump to the other side of the 5 on the keypad, and swap 5's and 0's."
Here's a keypad for visualization.
```
┌───┬───┬───┐
│ 1 │ 2 │ 3 │... | ["def decode(s):\n return s.translate(str.maketrans(\"1234567890\", \"9876043215\"))", "def decode(string):\n return \"\".join([\"5987604321\"[int(char)] for char in string])", "def decode(string):\n return string.translate(str.maketrans(\"1234567890\",\"9876043215\"))", "def decode(string):\n key = {\n ... | {"fn_name": "decode", "inputs": [["4103432323"], ["4103438970"], ["4104305768"], ["4102204351"], ["4107056043"]], "outputs": [["6957678787"], ["6957672135"], ["6956750342"], ["6958856709"], ["6953504567"]]} | introductory | https://www.codewars.com/kata/573d498eb90ccf20a000002a |
def decode(string):
|
4,633 | You have to create a function that converts integer given as string into ASCII uppercase letters.
All ASCII characters have their numerical order in table.
For example,
```
from ASCII table, character of number 65 is "A".
```
Numbers will be next to each other, So you have to split given number to two digit long i... | ["def convert(number):\n return ''.join(chr(int(number[a:a + 2])) for a in range(0, len(number), 2))\n", "def convert(number):\n return \"\".join(chr(int(number[i:i + 2])) for i in range(0, len(number), 2))\n pass", "def convert(number):\n return \"\".join([chr(int(x)) for x in map(''.join, zip(*[iter(num... | {"fn_name": "convert", "inputs": [["65"], ["656667"], ["676584"], ["73327673756932858080698267658369"], ["32327332327679866932328380656769833232"], ["84726982693273833278793270857832737832657889327984726982326765836983"]], "outputs": [["A"], ["ABC"], ["CAT"], ["I LIKE UPPERCASE"], [" I LOVE SPACES "], ["THERE IS NO... | introductory | https://www.codewars.com/kata/589ebcb9926baae92e000001 |
def convert(number):
|
4,634 | # Task
Pac-Man got lucky today! Due to minor performance issue all his enemies have frozen. Too bad Pac-Man is not brave enough to face them right now, so he doesn't want any enemy to see him.
Given a gamefield of size `N` x `N`, Pac-Man's position(`PM`) and his enemies' positions(`enemies`), your task is to count... | ["def pac_man(size, pacman, enemies):\n px, py = pacman\n mx, my, Mx, My = -1, -1, size, size\n for x, y in enemies:\n if x < px and x > mx: mx = x\n if y < py and y > my: my = y\n if x > px and x < Mx: Mx = x\n if y > py and y < My: My = y\n return (Mx - mx - 1) * (My - my - 1) ... | {"fn_name": "pac_man", "inputs": [[1, [0, 0], []], [2, [0, 0], []], [3, [0, 0], []], [3, [1, 1], []], [2, [0, 0], [[1, 1]]], [3, [2, 0], [[1, 1]]], [3, [2, 0], [[0, 2]]], [10, [4, 6], [[0, 2], [5, 2], [5, 5]]], [8, [1, 1], [[5, 4]]], [8, [1, 5], [[5, 4]]], [8, [6, 1], [[5, 4]]]], "outputs": [[0], [3], [8], [8], [0], [0... | introductory | https://www.codewars.com/kata/58ad0e0a154165a1c80000ea |
def pac_man(N, PM, enemies):
|
4,635 | # YOUR MISSION
An [octahedron](https://en.wikipedia.org/wiki/Octahedron) is an 8-sided polyhedron whose faces are triangles.
Create a method that outputs a 3-dimensional array of an octahedron in which the height, width, and depth are equal to the provided integer `size`, which is equal to the length from one vertex... | ["def create_octahedron(size):\n if size <= 1 or size % 2 == 0:\n return []\n m = size // 2\n return [[[int(abs(x - m) + abs(y - m) + abs(z - m) <= m)\n for z in range(size)]\n for y in range(size)]\n for x in range(size)]", "def face(size, m, n):\n return [\n [abs(r-m) + ... | {"fn_name": "create_octahedron", "inputs": [[7], [0], [-7]], "outputs": [[[[[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0], [0, 0, 1, 1,... | introductory | https://www.codewars.com/kata/5bfb0d9b392c5bf79a00015a |
def create_octahedron(size):
|
4,636 | ---
# Hint
This Kata is an extension of the earlier ones in this series. Completing those first will make this task easier.
# Background
My TV remote control has arrow buttons and an `OK` button.
I can use these to move a "cursor" on a logical screen keyboard to type words...
# Keyboard
The screen "keyboard" la... | ["H, W = 6, 8\nKEYBOARD = [ \"abcde123fghij456klmno789pqrst.@0uvwxyz_/\\u000e \",\n \"ABCDE123FGHIJ456KLMNO789PQRST.@0UVWXYZ_/\\u000e \",\n \"^~?!'\\\"()-:;+&%*=<>\u20ac\u00a3$\u00a5\u00a4\\\\[]{},.@\u00a7#\u00bf\u00a1\\u000e\\u000e\\u000e_/\\u000e \"]\nMAP = [ {c: (i//W, i%W) for i,c i... | {"fn_name": "tv_remote", "inputs": [["Too Easy?"], ["does"], ["your"], ["solution"], ["work"], ["for"], ["these"], ["words"], ["DOES"], ["YOUR"], ["SOLUTION"], ["WORK"], ["FOR"], ["THESE"], ["WORDS"], ["^does^"], ["$your$"], ["#solution#"], ["\u00bfwork\u00bf"], ["{for}"], ["\u00a3these\u00a3"], ["?symbols?"], ["a"], [... | introductory | https://www.codewars.com/kata/5b3077019212cbf803000057 |
def tv_remote(words):
|
4,637 | Mary wrote a recipe book and is about to publish it, but because of a new European law, she needs to update and include all measures in grams.
Given all the measures in tablespoon (`tbsp`) and in teaspoon (`tsp`), considering `1 tbsp = 15g` and `1 tsp = 5g`, append to the end of the measurement the biggest equivalent ... | ["import re, math\n\ndef convert_recipe(recipe):\n \n def repl(m):\n ratio = 15 if m.group(2) == \"tbsp\" else 5\n return m.group(0) + \" (%sg)\" % math.ceil(eval(m.group(1)) * ratio)\n \n return re.sub(\"([0-9/]+) (tb?sp)\", repl, recipe)", "import re\nimport math\ndef convert_recipe(recipe):... | {"fn_name": "convert_recipe", "inputs": [["2 tbsp of butter"], ["Add to the mixing bowl and coat well with 1 tbsp of olive oil & 1/2 tbsp of dried dill"], ["1/2 tsp of baking powder"], ["In another bowl, add 2 tsp of vanilla extract, 3 tsp of baking soda and 1/2 tsp of salt"], ["10 tbsp of cocoa powder"], ["1/8 tbsp of... | introductory | https://www.codewars.com/kata/5acfab8d23c81836c90000eb |
def convert_recipe(recipe):
|
4,638 | ## Your story
You've always loved both Fizz Buzz katas and cuckoo clocks, and when you walked by a garage sale and saw an ornate cuckoo clock with a missing pendulum, and a "Beyond-Ultimate Raspberry Pi Starter Kit" filled with all sorts of sensors and motors and other components, it's like you were suddenly hit by a b... | ["def fizz_buzz_cuckoo_clock(t):\n h, m = list(map(int, t.split(':')))\n h = h-12 if h > 12 else h+12 if h == 0 else h\n \n if m == 0:\n return ' '.join('Cuckoo' for i in range(h))\n if m == 30:\n return 'Cuckoo'\n if m%3 == 0 and m%5 == 0:\n return 'Fizz Buzz'\n if m%3 == 0:\n... | {"fn_name": "fizz_buzz_cuckoo_clock", "inputs": [["13:34"], ["21:00"], ["11:15"], ["03:03"], ["14:30"], ["08:55"], ["00:00"], ["12:00"]], "outputs": [["tick"], ["Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo"], ["Fizz Buzz"], ["Fizz"], ["Cuckoo"], ["Buzz"], ["Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo C... | introductory | https://www.codewars.com/kata/58485a43d750d23bad0000e6 |
def fizz_buzz_cuckoo_clock(time):
|
4,639 | Complete the function `power_of_two`/`powerOfTwo` (or equivalent, depending on your language) that determines if a given non-negative integer is a [power of two](https://en.wikipedia.org/wiki/Power_of_two). From the corresponding Wikipedia entry:
> *a power of two is a number of the form 2^(n) where **n** is an integ... | ["def power_of_two(x):\n return x != 0 and ((x & (x - 1)) == 0)", "def power_of_two(num):\n return bin(num).count('1') == 1\n", "def power_of_two(x):\n return x and (not(x&(x-1)))", "def power_of_two(x):\n # your code here\n return x > 0 and (x & (x-1)) == 0", "def power_of_two(x):\n # your code here\n ret... | {"fn_name": "power_of_two", "inputs": [[0], [1], [536870912]], "outputs": [[false], [true], [true]]} | introductory | https://www.codewars.com/kata/534d0a229345375d520006a0 |
def power_of_two(x):
|
4,640 | Write a function that accepts two arguments: an array/list of integers and another integer (`n`).
Determine the number of times where two integers in the array have a difference of `n`.
For example:
```
[1, 1, 5, 6, 9, 16, 27], n=4 --> 3 # (1,5), (1,5), (5,9)
[1, 1, 3, 3], n=2 --> 4 # (1,3), (1,3), ... | ["def int_diff(arr, n):\n num=0\n for i in range(len(arr)):\n for j in range(i+1,len(arr)):\n if abs(arr[i]-arr[j])==n:\n num+=1\n return num", "int_diff=lambda l,n:sum(n==abs(a-b)for i,a in enumerate(l)for b in l[:i])", "import itertools\n\ndef int_diff(arr, n):\n return su... | {"fn_name": "int_diff", "inputs": [[[1, 1, 5, 6, 9, 16, 27], 4], [[1, 1, 3, 3], 2], [[4, 8, 12, 12, 3, 6, 2], 6], [[1, 2, 3, 4, 5, 6, 7], 7], [[1, 6, 2, 3, 7, 8, 7], 0], [[1, 2, 3, 4], 0], [[1, 1, 1, 1], 0], [[], 3]], "outputs": [[3], [4], [3], [0], [1], [0], [6], [0]]} | introductory | https://www.codewars.com/kata/57741d8f10a0a66915000001 |
def int_diff(arr, n):
|
4,641 | Implement the function unique_in_order which takes as argument a sequence and returns a list of items without any elements with the same value next to each other and preserving the original order of elements.
For example:
```python
unique_in_order('AAAABBBCCDAABBB') == ['A', 'B', 'C', 'D', 'A', 'B']
unique_in_order('... | ["def unique_in_order(iterable):\n result = []\n prev = None\n for char in iterable[0:]:\n if char != prev:\n result.append(char)\n prev = char\n return result", "from itertools import groupby\n\ndef unique_in_order(iterable):\n return [k for (k, _) in groupby(iterable)]", "d... | {"fn_name": "unique_in_order", "inputs": [[""], ["A"], ["AA"], ["AAAABBBCCDAABBB"], ["AADD"], ["AAD"], ["ADD"], ["ABBCcAD"], [[1, 2, 3, 3]], [["a", "b", "b"]]], "outputs": [[[]], [["A"]], [["A"]], [["A", "B", "C", "D", "A", "B"]], [["A", "D"]], [["A", "D"]], [["A", "D"]], [["A", "B", "C", "c", "A", "D"]], [[1, 2, 3]], ... | introductory | https://www.codewars.com/kata/54e6533c92449cc251001667 |
def unique_in_order(iterable):
|
4,642 | It's a Pokemon battle! Your task is to calculate the damage that a particular move would do using the following formula (not the actual one from the game):
Where:
* attack = your attack power
* defense = the opponent's defense
* effectiveness = the effectiveness of the attack based on the matchup (see explanation bel... | ["import math\n\neffectiveness = {\n \"electric\":{\n \"electric\": 0.5,\n \"fire\": 1,\n \"grass\": 1,\n \"water\": 2\n },\n \"fire\":{\n \"electric\": 1,\n \"fire\": 0.5,\n \"grass\": 2,\n \"water\": 0.5\n },\n \"grass\":{\n \"electric\": 1,\n \"fir... | {"fn_name": "calculate_damage", "inputs": [["fire", "water", 100, 100], ["grass", "water", 100, 100], ["electric", "fire", 100, 100], ["grass", "electric", 57, 19], ["grass", "water", 40, 40], ["grass", "fire", 35, 5], ["fire", "electric", 10, 2]], "outputs": [[25], [100], [50], [150], [100], [175], [250]]} | introductory | https://www.codewars.com/kata/536e9a7973130a06eb000e9f |
def calculate_damage(your_type, opponent_type, attack, defense):
|
4,643 | You should write a simple function that takes string as input and checks if it is a valid Russian postal code, returning `true` or `false`.
A valid postcode should be 6 digits with no white spaces, letters or other symbols. Empty string should also return false.
Please also keep in mind that a valid post code **cann... | ["def zipvalidate(postcode):\n return len(postcode) == 6 and postcode.isdigit() and postcode[0] not in \"05789\"", "import re\n\ndef zipvalidate(postcode):\n return bool(re.fullmatch(r\"[12346]\\d{5}\", postcode))", "def zipvalidate(p):\n return p.isdigit() and 100000 < int(p) < 699999 and p[0] != \"5\"\n \... | {"fn_name": "zipvalidate", "inputs": [["142784"], ["642784"], ["111"], ["1111111"], ["AA5590"], [""], ["\n245980"], ["245980\n"], ["245980a"], ["24598a"], [" 310587 "], ["555555"], ["775255"], ["875555"], ["012345"], ["968345"], ["@68345"]], "outputs": [[true], [true], [false], [false], [false], [false], [false], [fals... | introductory | https://www.codewars.com/kata/552e45cc30b0dbd01100001a |
def zipvalidate(postcode):
|
4,644 | Take a string and return a hash with all the ascii values of the characters in the string.
Returns nil if the string is empty.
The key is the character, and the value is the ascii value of the character.
Repeated characters are to be ignored and non-alphebetic characters as well. | ["def char_to_ascii(string):\n return {c: ord(c) for c in set(string) if c.isalpha()} if len(string) else None", "def char_to_ascii(s):\n if s: return {c: ord(c) for c in set(s) if c.isalpha()}\n", "def char_to_ascii(s):\n if s: return {c: ord(c) for c in set(s) if c.isalpha()}", "char_to_ascii = lambda s: {e:... | {"fn_name": "char_to_ascii", "inputs": [[""], ["a"], ["aaa"], ["hello world"], ["ABaa ^"]], "outputs": [[null], [{"a": 97}], [{"a": 97}], [{"h": 104, "e": 101, "l": 108, "o": 111, "w": 119, "r": 114, "d": 100}], [{"A": 65, "B": 66, "a": 97}]]} | introductory | https://www.codewars.com/kata/55e9529cbdc3b29d8c000016 |
def char_to_ascii(string):
|
4,645 | > If you've finished this kata, you can try the [more difficult version](https://www.codewars.com/kata/5b256145a454c8a6990000b5).
## Taking a walk
A promenade is a way of uniquely representing a fraction by a succession of “left or right” choices.
For example, the promenade `"LRLL"` represents the fraction `4/7`.
... | ["def promenade(choices):\n \n def compute(): return l+r,m+s\n \n l,m, r,s = 1,0, 0,1\n for c in choices:\n if c=='L': l,m = compute()\n else: r,s = compute()\n \n return compute()", "def promenade(choices):\n l, m = (1, 0)\n r, s = (0, 1)\n for choice in choices:\n ... | {"fn_name": "promenade", "inputs": [[""], ["L"], ["R"], ["LRLL"], ["LLRLR"], ["RRRLRRR"], ["LLLLRLLLL"], ["LLLLLLLLLL"], ["RLRLRLRRLRLL"], ["LLRRLRRLRLLL"], ["LRRLLRLLRLRR"], ["LRRLRLLLLRLL"], ["LLLRRRLLLRLL"], ["RRLRRRLLRLRR"], ["RRRRLLRLLRLR"], ["LLRLRLLRLLRL"], ["LRLLRRRRLLRR"], ["RLRRLRRRRRRR"]], "outputs": [[[1, 1... | introductory | https://www.codewars.com/kata/5b254b2225c2bb99c500008d |
def promenade(choices):
|
4,646 | *This is my first Kata in the Ciphers series. This series is meant to test our coding knowledge.*
## Ciphers #1 - The 01 Cipher
This cipher doesn't exist, I just created it by myself. It can't actually be used, as there isn't a way to decode it. It's a hash. Multiple sentences may also have the same result.
## How th... | ["def encode(s):\n return ''.join( str(1 - ord(c)%2) if c.isalpha() else c for c in s )", "encode = lambda s: \"\".join((x, str(~ord(x)%2))[x.isalpha()] for x in s)", "import re\n\ndef encode(s):\n return re.sub(r\"[a-zA-Z]\", lambda m: str((ord(m.group())+1)%2), s)", "def encode(s):\n return \"\".join(['1', '... | {"fn_name": "encode", "inputs": [["Hello World!"]], "outputs": [["10110 00111!"]]} | introductory | https://www.codewars.com/kata/593f50f343030bd35e0000c6 |
def encode(s):
|
4,647 | This kata is the second part of a series: [Neighbourhood kata collection](https://www.codewars.com/collections/5b2f4db591c746349d0000ce). If this one is to easy you can try out the harder Katas.;)
___
The neighbourhood of a cell (in a matrix) are cells that are near to it. There are two popular types:
- The [Moore nei... | ["def get_neighbourhood(typ, arr, coordinates):\n \n def isInside(x,y): return 0 <= x < len(arr) and 0 <= y < len(arr[0])\n \n x,y = coordinates\n if not isInside(x,y): return []\n \n neigh = ( [(dx, dy) for dx in range(-1,2) for dy in range(-1,2) if (dx,dy) != (0,0)]\n if typ == '... | {"fn_name": "get_neighbourhood", "inputs": [["moore", [[]], [0, 0]], ["von_neumann", [[]], [0, 0]], ["moore", [[], [], []], [0, 0]], ["von_neumann", [[], [], []], [0, 0]]], "outputs": [[[]], [[]], [[]], [[]]]} | introductory | https://www.codewars.com/kata/5b2e5a02a454c82fb9000048 |
def get_neighbourhood(n_type, mat, coordinates):
|
4,648 | # Definition
A **number** is called **_Automorphic number_** if and only if *its square ends in the same digits as the number itself*.
___
# Task
**_Given_** a **number** *determine if it Automorphic or not* .
___
# Warm-up (Highly recommended)
# [Playing With Numbers Series](https://www.codewars.com/collections/p... | ["def automorphic(n):\n return \"Automorphic\" if str(n*n).endswith(str(n)) else \"Not!!\"", "def automorphic(n):\n return \"Automorphic\" if str(n**2).endswith(str(n)) else \"Not!!\"", "def automorphic(n):\n return ('Not!!', 'Automorphic')[str(n ** 2).endswith(str(n))]", "def automorphic(n):\n return \"Aut... | {"fn_name": "automorphic", "inputs": [[1], [3], [6], [9], [25], [53], [76], [95], [625], [225]], "outputs": [["Automorphic"], ["Not!!"], ["Automorphic"], ["Not!!"], ["Automorphic"], ["Not!!"], ["Automorphic"], ["Not!!"], ["Automorphic"], ["Not!!"]]} | introductory | https://www.codewars.com/kata/5a58d889880385c2f40000aa |
def automorphic(n):
|
4,649 | Your website is divided vertically in sections, and each can be of different size (height).
You need to establish the section index (starting at `0`) you are at, given the `scrollY` and `sizes` of all sections.
Sections start with `0`, so if first section is `200` high, it takes `0-199` "pixels" and second starts a... | ["def get_section_id(scroll, sizes):\n c = 0\n for idx, s in enumerate(sizes):\n c += s\n if scroll < c: return idx\n return -1", "from itertools import accumulate\n\n# Once again, thanks itertools\ndef get_section_id(scroll, sizes):\n return next((i for i,x in enumerate(accumulate(sizes)) if ... | {"fn_name": "get_section_id", "inputs": [[1, [300, 200, 400, 600, 100]], [299, [300, 200, 400, 600, 100]], [300, [300, 200, 400, 600, 100]], [1599, [300, 200, 400, 600, 100]], [1600, [300, 200, 400, 600, 100]]], "outputs": [[0], [0], [1], [4], [-1]]} | introductory | https://www.codewars.com/kata/5cb05eee03c3ff002153d4ef |
def get_section_id(scroll, sizes):
|
4,650 | Write a function that accepts a string, and returns true if it is in the form of a phone number. Assume that any integer from 0-9 in any of the spots will produce a valid phone number.
Only worry about the following format:
(123) 456-7890 (don't forget the space after the close parentheses)
Examples:
```
validPho... | ["def validPhoneNumber(phoneNumber):\n import re\n return bool(re.match(r\"^(\\([0-9]+\\))? [0-9]+-[0-9]+$\", phoneNumber))", "# This is actually quite a bit more complicated in real life\n# I'd use https://github.com/googlei18n/libphonenumber\nimport re\n\nprog = re.compile('^\\(\\d{3}\\) \\d{3}-\\d{4}$')\n\ndef... | {"fn_name": "validPhoneNumber", "inputs": [["(123) 456-7890"], ["(1111)555 2345"], ["(098) 123 4567"], ["(123)456-7890"], ["abc(123)456-7890"], ["(123)456-7890abc"], ["abc(123)456-7890abc"], ["abc(123) 456-7890"], ["(123) 456-7890abc"], ["abc(123) 456-7890abc"]], "outputs": [[true], [false], [false], [false], [false], ... | introductory | https://www.codewars.com/kata/525f47c79f2f25a4db000025 |
def validPhoneNumber(phoneNumber):
|
4,651 | Here your task is to Create a (nice) Christmas Tree.
You don't have to check errors or incorrect input values, every thing is ok without bad tricks, only one int parameter as input and a string to return;-)...
So what to do?First three easy examples:
````
Input: 3 and Output:
*
***
*****
###
Input 9 and Output:... | ["def christmas_tree(h):\n return \"\" if h<3 else \"\\r\\n\".join([\"\\r\\n\".join([\" \"*(((5-y)//2)+(h//3)-i-1)+\"*\"*(y+i*2) for y in [1,3,5]]) for i in range(h//3)])+\"\\r\\n\"+\" \"*(h//3)+\"###\"", "def christmas_tree(height):\n height, tree = height // 3, []\n for floor in range(height):\n for bra... | {"fn_name": "christmas_tree", "inputs": [[5], [10], [8], [2]], "outputs": [[" *\r\n ***\r\n*****\r\n ###"], [" *\r\n ***\r\n *****\r\n ***\r\n *****\r\n *******\r\n *****\r\n *******\r\n*********\r\n ###"], [" *\r\n ***\r\n *****\r\n ***\r\n *****\r\n*******\r\n ###"], [""]]} | introductory | https://www.codewars.com/kata/56c30eaef85696bf35000ccf |
def christmas_tree(height):
|
4,652 | Given a number `n` we will define its scORe to be `0 | 1 | 2 | 3 | ... | n`, where `|` is the [bitwise OR operator](https://en.wikipedia.org/wiki/Bitwise_operation#OR).
Write a function that takes `n` and finds its scORe.
---------------------
| n | scORe n |
|---------|-------- |
| 0 | 0 |
| 1 ... | ["score=lambda n:2**n.bit_length()-1", "score=lambda n:(1<<n.bit_length())-1", "def score(n):\n # Good Luck!\n return 2**n.bit_length()-1", "def score(n):\n res = n\n while n:\n res, n = res | n, n >> 1\n return res", "def score(n):\n return 0 if n == 0 else n | int(n.bit_length() * '1', 2)", "... | {"fn_name": "score", "inputs": [[0], [1], [49], [1000000], [10000000], [1000000000000000000]], "outputs": [[0], [1], [63], [1048575], [16777215], [1152921504606846975]]} | introductory | https://www.codewars.com/kata/56cafdabc8cfcc3ad4000a2b |
def score(n):
|
4,653 | In this kata you will have to change every letter in a given string to the next letter in the alphabet. You will write a function `nextLetter` to do this. The function will take a single parameter `s` (string).
Examples:
```
"Hello" --> "Ifmmp"
"What is your name?" --> "Xibu jt zpvs obnf?"
"zoo" --> "app"
"zzZAaa"... | ["def next_letter(string):\n return \"\".join(chr(ord(c)+(-25 if c in 'zZ' else 1)) if c.isalpha() else c for c in string)", "def next_letter(s):\n return s.translate(str.maketrans('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', \n 'bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA'))", "from string... | {"fn_name": "next_letter", "inputs": [["Hello"], ["What is your name?"], ["zOo"]], "outputs": [["Ifmmp"], ["Xibu jt zpvs obnf?"], ["aPp"]]} | introductory | https://www.codewars.com/kata/57b2020eb69bfcbf64000375 |
def next_letter(s):
|
4,654 | You have recently discovered that horses travel in a unique pattern - they're either running (at top speed) or resting (standing still).
Here's an example of how one particular horse might travel:
```
The horse Blaze can run at 14 metres/second for 60 seconds, but must then rest for 45 seconds.
After 500 seconds Bla... | ["def travel(total_time, run_time, rest_time, speed):\n q, r = divmod(total_time, run_time + rest_time)\n return (q * run_time + min(r, run_time)) * speed\n", "def travel(total_time, run_time, rest_time, speed):\n d, m = divmod(total_time, run_time + rest_time)\n return (d * run_time + min(m, run_time)) * s... | {"fn_name": "travel", "inputs": [[1000, 10, 127, 14], [1000, 10, 0, 10], [25, 50, 120, 18], [35869784, 90, 100, 5], [1234567, 4, 3, 11], [100000000, 21, 5, 14], [0, 100, 10, 14], [250, 0, 5, 14], [100, 10, 0, 14], [500, 100, 10, 0]], "outputs": [[1120], [10000], [450], [84954920], [7760148], [1130769276], [0], [0], [14... | introductory | https://www.codewars.com/kata/56d46b8fda159582e100001b |
def travel(total_time, run_time, rest_time, speed):
|
4,655 | Sort array by last character
Complete the function to sort a given array or list by last character of elements.
```if-not:haskell
Element can be an integer or a string.
```
### Example:
```
['acvd', 'bcc'] --> ['bcc', 'acvd']
```
The last characters of the strings are `d` and `c`. As `c` comes before `d`, sortin... | ["def sort_me(arr):\n return sorted(arr, key=lambda elem: str(elem)[-1])", "def sort_me(arr):\n # Good Luck!\n return sorted(arr, key=lambda x:str(x)[-1])", "def sort_me(xs):\n return sorted(xs, key=lambda x: str(x)[-1])", "def sort_me(a):\n return sorted(a, key=lambda x: str(x)[-1])", "def sort_me(arr):... | {"fn_name": "sort_me", "inputs": [[["acvd", "bcc"]], [["14", "13"]], [["asdf", "asdf", "14", "13"]], [["bsde", "asdf", 14, "13"]], [["asdf", 14, "13", "asdf"]]], "outputs": [[["bcc", "acvd"]], [["13", "14"]], [["13", "14", "asdf", "asdf"]], [["13", 14, "bsde", "asdf"]], [["13", 14, "asdf", "asdf"]]]} | introductory | https://www.codewars.com/kata/55aea0a123c33fa3400000e7 |
def sort_me(arr):
|
4,656 | # Task
Christmas is coming. In the [previous kata](https://www.codewars.com/kata/5a405ba4e1ce0e1d7800012e), we build a custom Christmas tree with the specified characters and the specified height.
Now, we are interested in the center of the Christmas tree.
Please imagine that we build a Christmas tree with `chars =... | ["def center_of(chars):\n if not chars:\n return \"\"\n total=0\n res=[]\n for i in range(1,len(chars)*2+1): \n if i%2==1:\n res.append((i+1)//2+total)\n res[-1]=chars[(res[-1]-1)%len(chars)]\n total+=i\n res=\"\".join(res)\n for i in range(len(res)//2+... | {"fn_name": "center_of", "inputs": [[""], ["a"], ["ab"], ["abc"], ["abab"], ["abcde"], ["aaaaaaaaaaaaaa"], ["abaabaaab"], ["dbdbebedbddbedededeeddbbdeddbeddeebdeddeebbbb"], ["vttussvutvuvvtustsvsvtvu"]], "outputs": [[""], ["a"], ["a"], ["aba"], ["a"], ["aecea"], ["a"], ["aba"], ["deededebddeebeddeddeddbddeddeddebeeddbe... | introductory | https://www.codewars.com/kata/5a4076f3e1ce0ee6d4000010 |
def center_of(chars):
|
4,657 | You will be given an array of positive integers. The array should be sorted by the amount of distinct perfect squares and reversed, that can be generated from each number permuting its digits.
E.g.: ```arr = [715, 112, 136, 169, 144]```
```
Number Perfect Squares w/ its Digits Amount
715 - ... | ["from collections import defaultdict\nSQUARES = [x**2 for x in range(1, 3163)]\nDIGITS = defaultdict(int)\nfor sqr in SQUARES:\n DIGITS[''.join(sorted(str(sqr)))] += 1\n\ndef sort_by_perfsq(arr):\n return sorted(arr, key=lambda n: (-DIGITS[''.join(sorted(str(n)))], n))", "from itertools import permutations\n\nd... | {"fn_name": "sort_by_perfsq", "inputs": [[[715, 112, 136, 169, 144]], [[234, 61, 16, 441, 144, 728]]], "outputs": [[[169, 144, 112, 136, 715]], [[144, 441, 16, 61, 234, 728]]]} | introductory | https://www.codewars.com/kata/582fdcc039f654905400001e |
def sort_by_perfsq(arr):
|
4,658 | ### Introduction and Warm-up (Highly recommended)
### [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
___
## Task
**_Given_** an *array/list [] of integers* , **_Find the product of the k maximal_** numbers.
___
### Notes
* **_Array/list_** size is *at leas... | ["def max_product(lst, n_largest_elements):\n lst_largest = sorted(lst)[-n_largest_elements:]\n prod = 1\n for number in lst_largest:\n prod *= number\n return prod", "def max_product(lst, n):\n from functools import reduce\n return reduce(lambda x,y: x*y, sorted(lst, reverse=True)[:n])", "def ... | {"fn_name": "max_product", "inputs": [[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 5], [[4, 3, 5], 2], [[10, 8, 7, 9], 3], [[8, 6, 4, 6], 3], [[10, 2, 3, 8, 1, 10, 4], 5], [[13, 12, -27, -302, 25, 37, 133, 155, -1], 5], [[-4, -27, -15, -6, -1], 2], [[-17, -8, -102, -309], 2], [[10, 3, -27, -1], 3], [[14, 29, -28, 39, -16, -48], 4]... | introductory | https://www.codewars.com/kata/5a63948acadebff56f000018 |
def max_product(lst, n_largest_elements):
|
4,659 | # Task
An IP address contains four numbers(0-255) and separated by dots. It can be converted to a number by this way:
Given a string `s` represents a number or an IP address. Your task is to convert it to another representation(`number to IP address` or `IP address to number`).
You can assume that all inputs are va... | ["from ipaddress import IPv4Address\n\ndef numberAndIPaddress(s):\n return str(int(IPv4Address(s))) if '.' in s else str(IPv4Address(int(s)))", "from ipaddress import IPv4Address\n\ndef numberAndIPaddress(string):\n if '.' in string:\n return str(int(IPv4Address(string)))\n return str(IPv4Address(int(st... | {"fn_name": "numberAndIPaddress", "inputs": [["10.0.3.193"], ["167969729"]], "outputs": [["167773121"], ["10.3.3.193"]]} | introductory | https://www.codewars.com/kata/5936371109ca68fe6900000c |
def numberAndIPaddress(s):
|
4,660 | As a strict big brother, I do limit my young brother Vasya on time he spends on computer games. I define a prime-time as a time period till which Vasya have a permission to play computer games. I specify start hour and end hour as pair of integers.
I need a function which will take three numbers - a present moment (cu... | ["def can_i_play(now_hour, start_hour, end_hour):\n return 0<=(now_hour-start_hour)%24<(end_hour-start_hour)%24\n", "def can_i_play(now_hour, start_hour, end_hour):\n if start_hour < end_hour:\n return start_hour <= now_hour < end_hour\n return start_hour <= now_hour or now_hour < end_hour\n", "def ca... | {"fn_name": "can_i_play", "inputs": [[9, 10, 11], [12, 12, 13], [13, 10, 15], [14, 9, 14], [15, 8, 12], [20, 21, 1], [21, 21, 6], [17, 15, 3], [0, 22, 1], [1, 22, 1], [3, 23, 2], [20, 0, 23], [14, 2, 9], [9, 20, 11], [23, 23, 0], [11, 2, 9], [0, 20, 23], [4, 0, 3], [6, 2, 10]], "outputs": [[false], [true], [true], [fal... | introductory | https://www.codewars.com/kata/59ca888aaeb284bb8f0000aa |
def can_i_play(now_hour, start_hour, end_hour):
|
4,661 | ###Task:
You have to write a function **pattern** which returns the following Pattern(See Examples) upto n rows, where n is parameter.
####Rules/Note:
* If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string.
* The length of each line = (2n-1).
* Range of n is (-∞,100]
###Examples:
pa... | ["def pattern(n):\n nums = '1234567890'\n str_nums = nums*(n//10) + nums[:n%10]\n return '\\n'.join(' '*(n - i - 1) + str_nums + ' '*i for i in range(n))\n", "def pattern(n):\n return \"\\n\".join([(n-1 - i) * \" \" + \"\".join(str(j % 10) for j in range(1, n+1)) + (i * \" \") for i in range(n)])", "def pat... | {"fn_name": "pattern", "inputs": [[3], [5], [8], [-3], [-11], [-25], [0]], "outputs": [[" 123\n 123 \n123 "], [" 12345\n 12345 \n 12345 \n 12345 \n12345 "], [" 12345678\n 12345678 \n 12345678 \n 12345678 \n 12345678 \n 12345678 \n 12345678 \n12345678 "], [""], [""... | introductory | https://www.codewars.com/kata/5581a7651185fe13190000ee |
def pattern(n):
|
4,662 | Consider an array that has no prime numbers, and none of its elements has any prime digit. It would start with: `[1,4,6,8,9,10,14,16,18,..]`.
`12` and `15` are not in the list because `2` and `5` are primes.
You will be given an integer `n` and your task will be return the number at that index in the array.
For exa... | ["n,forbid = 100000, set(\"2357\")\nsieve, notPrimes = [0]*(n+1), [1]\nfor i in range(2, n+1):\n if sieve[i]:\n if not (forbid & set(str(i))): notPrimes.append(i)\n else:\n for j in range(i**2, n+1, i): sieve[j] = 1\n\ndef solve(n): return notPrimes[n]", "solve=lambda n: [1,4,6,8,9,10,14,16,18,40,4... | {"fn_name": "solve", "inputs": [[10], [50], [100], [150], [200], [300], [400], [500], [1000], [2000], [3000]], "outputs": [[44], [169], [644], [896], [1060], [1668], [4084], [4681], [9110], [18118], [46166]]} | introductory | https://www.codewars.com/kata/59f8750ac374cba8f0000033 |
def solve(n):
|
4,663 | Your task is to sort a given string. Each word in the string will contain a single number. This number is the position the word should have in the result.
Note: Numbers can be from 1 to 9. So 1 will be the first word (not 0).
If the input string is empty, return an empty string.
The words in the input String will onl... | ["def order(sentence):\n return \" \".join(sorted(sentence.split(), key=lambda x: int(\"\".join(filter(str.isdigit, x)))))\n", "def order(words):\n return ' '.join(sorted(words.split(), key=lambda w:sorted(w)))", "def order(sentence):\n if not sentence:\n return \"\"\n result = [] #the list that wil... | {"fn_name": "order", "inputs": [["is2 Thi1s T4est 3a"], ["4of Fo1r pe6ople g3ood th5e the2"], ["d4o dru7nken sh2all w5ith s8ailor wha1t 3we a6"], [""], ["3 6 4 2 8 7 5 1 9"]], "outputs": [["Thi1s is2 3a T4est"], ["Fo1r the2 g3ood 4of th5e pe6ople"], ["wha1t sh2all 3we d4o w5ith a6 dru7nken s8ailor"], [""], ["1 2 3 4 5 ... | introductory | https://www.codewars.com/kata/55c45be3b2079eccff00010f |
def order(sentence):
|
4,664 | Lucy loves to travel. Luckily she is a renowned computer scientist and gets to travel to international conferences using her department's budget.
Each year, Society for Exciting Computer Science Research (SECSR) organizes several conferences around the world. Lucy always picks one conference from that list that is hos... | ["def conference_picker(cities_visited, cities_offered):\n for city in cities_offered:\n if city not in cities_visited:\n return city\n return 'No worthwhile conferences this year!'", "def conference_picker(visited, offered):\n visited = set(visited)\n return next((city for city in offered... | {"fn_name": "conference_picker", "inputs": [[[], ["Philadelphia", "Osaka", "Tokyo", "Melbourne"]], [[], ["Brussels", "Madrid", "London"]], [[], ["Sydney", "Tokyo"]], [["London", "Berlin", "Mexico City", "Melbourne", "Buenos Aires", "Hong Kong", "Madrid", "Paris"], ["Berlin", "Melbourne"]], [["Beijing", "Johannesburg", ... | introductory | https://www.codewars.com/kata/56f5594a575d7d3c0e000ea0 |
def conference_picker(cities_visited, cities_offered):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.