problem_id int64 80 5k | question stringlengths 170 10.1k | solutions stringlengths 0 675k | input_output stringlengths 0 33.5k | difficulty stringclasses 3
values | url stringlengths 38 68 | starter_code stringlengths 0 315 |
|---|---|---|---|---|---|---|
2,673 | Passer ratings are the generally accepted standard for evaluating NFL quarterbacks.
I knew a rating of 100 is pretty good, but never knew what makes up the rating.
So out of curiosity I took a look at the wikipedia page and had an idea or my first kata: https://en.wikipedia.org/wiki/Passer_rating
## Formula
There are... | ["def passer_rating(att, yds, comp, td, ints):\n limit = lambda x: min(max(x, 0), 2.375)\n \n att = float(att) # for python 2 compatibility\n \n A = ((comp / att) - .3) * 5\n B = ((yds / att) - 3) * .25\n C = (td / att) * 20\n D = 2.375 - ((ints / att) * 25)\n \n A, B, C, D = map(limit,... | {"fn_name": "passer_rating", "inputs": [[432, 3554, 291, 28, 2], [5, 76, 4, 1, 0], [48, 192, 19, 2, 3], [1, 2, 1, 1, 0], [34, 172, 20, 1, 1], [10, 17, 2, 0, 1]], "outputs": [[112.2], [158.3], [39.6], [118.8], [69.7], [0.0]]} | introductory | https://www.codewars.com/kata/59952e17f902df0e5f000078 |
def passer_rating(att, yds, comp, td, ints):
|
2,678 | Imagine if there were no order of operations. Instead, you would do the problem from left to right. For example, the equation `$a +b *c /d$` would become `$(((a+b)*c)//d)$` (`Math.floor(((a+b)*c)/d)` in JS). Return `None`/`null` (depending on your language) if the equation is `""`.
### Task:
Given an equation with a... | ["def no_order(equation):\n equation = equation.replace(' ', '')\n equation = equation.replace('+', ')+')\n equation = equation.replace('-', ')-')\n equation = equation.replace('*', ')*')\n equation = equation.replace('/', ')//')\n equation = equation.replace('%', ')%')\n equation = equation.replac... | {"fn_name": "no_order", "inputs": [["2 + 3- 4*1 ^ 3"], ["7 * 3 - 3/ 10 0"], ["1 20% 0 + 9"], ["6 9* 2+6 / 0"]], "outputs": [[1], [0], [null], [null]]} | introductory | https://www.codewars.com/kata/5e9df3a0a758c80033cefca1 |
def no_order(equation):
|
2,684 | ## Witamy!
You are in Poland and want to order a drink. You need to ask "One beer please": "Jedno piwo poprosze"
``` java
Translator.orderingBeers(1) = "Jedno piwo poprosze"
```
But let's say you are really thirsty and want several beers. Then you need to count in Polish. And more difficult, you need to understand t... | ["def ordering_beers(beers):\n assert 0 <= beers < 100\n \n units = [\"\", \"jeden\", \"dwa\", \"trzy\", \"cztery\", \"piec\", \"szesc\" , \"siedem\", \"osiem\", \"dziewiec\",\n \"dziesiec\", \"jedenascie\", \"dwanascie\", \"trzynascie\", \"czternascie\", \"pietnascie\", \"szesnascie\", \"siedemnasc... | {"fn_name": "ordering_beers", "inputs": [[0], [1], [2], [3], [4], [5], [8], [10], [11], [12], [13], [14], [15], [16], [20], [21], [22], [28], [33], [44], [55], [98], [99]], "outputs": [["Woda mineralna poprosze"], ["Jedno piwo poprosze"], ["Dwa piwa poprosze"], ["Trzy piwa poprosze"], ["Cztery piwa poprosze"], ["Piec p... | introductory | https://www.codewars.com/kata/54f4e56e00ecc43c6d000220 |
def ordering_beers(beers):
|
2,691 | In this Kata, you will be given a string that has lowercase letters and numbers. Your task is to compare the number groupings and return the largest number. Numbers will not have leading zeros.
For example, `solve("gh12cdy695m1") = 695`, because this is the largest of all number groupings.
Good luck!
Please also t... | ["import re\n\n\ndef solve(s):\n return max(map(int,re.findall(r\"(\\d+)\", s)))", "def solve(s):\n largest = 0\n number = 0\n \n for char in s:\n if char.isdigit():\n number = number * 10 + int(char)\n if largest < number:\n largest = number\n else:\n ... | {"fn_name": "solve", "inputs": [["gh12cdy695m1"], ["2ti9iei7qhr5"], ["vih61w8oohj5"], ["f7g42g16hcu5"], ["lu1j8qbbb85"]], "outputs": [[695], [9], [61], [42], [85]]} | introductory | https://www.codewars.com/kata/59dd2c38f703c4ae5e000014 |
def solve(s):
|
2,692 | #Bubbleing around
Since everybody hates chaos and loves sorted lists we should implement some more sorting algorithms. Your task is to implement a Bubble sort (for some help look at https://en.wikipedia.org/wiki/Bubble_sort) and return a list of snapshots after **each change** of the initial list.
e.g.
If the initi... | ["def bubble(l):\n ret = []\n for i in range(len(l) - 1, 0, -1):\n for j in range(i):\n if l[j] > l[j + 1]:\n l[j], l[j + 1] = l[j + 1], l[j]\n ret.append(l[:])\n return ret", "def bubble(l):\n bubbling,bubbles = True, []\n while bubbling :\n bubblin... | {"fn_name": "bubble", "inputs": [[[]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[1, 3, 3, 7, 4, 2]]], "outputs": [[[]], [[]], [[[1, 3, 3, 4, 7, 2], [1, 3, 3, 4, 2, 7], [1, 3, 3, 2, 4, 7], [1, 3, 2, 3, 4, 7], [1, 2, 3, 3, 4, 7]]]]} | introductory | https://www.codewars.com/kata/57403b5ad67e87b5e7000d1d |
def bubble(l):
|
2,693 | In this kata the function returns an array/list like the one passed to it but with its nth element removed (with `0 <= n <= array/list.length - 1`). The function is already written for you and the basic tests pass, but random tests fail. Your task is to figure out why and fix it.
Good luck!
~~~if:javascript
Some good... | ["def remove_nth_element(a, n):\n return a[:n] + a[n+1:]", "def remove_nth_element(lst, n):\n lst_copy = lst.copy()\n del lst_copy[n]\n return lst_copy", "def remove_nth_element(lst, n):\n # Fix it\n import copy\n lst_copy = copy.deepcopy(lst)\n del lst_copy[n]\n return lst_copy\n", "def remo... | {"fn_name": "remove_nth_element", "inputs": [[[9, 7, 6, 9], 0]], "outputs": [[[7, 6, 9]]]} | introductory | https://www.codewars.com/kata/5a7b3d08fd5777bf6a000121 |
def remove_nth_element(lst, n):
|
2,707 | *This kata is based on [Project Euler Problem 539](https://projecteuler.net/problem=539)*
##Object
Find the last number between 1 and `n` (inclusive) that survives the elimination process
####How It Works
Start with the first number on the left then remove every other number moving right until you reach the the end... | ["def last_man_standing(n):\n dir, lst = -1, range(2,n+1,2)\n while len(lst) != 1:\n lst = lst[len(lst)%2 or dir == 1 ::2]\n dir = -dir\n return lst[0]", "from math import log\n\ndef last_man_standing(n):\n return 1 + sum((((n >> i) | (i + 1)) % 2) << i for i in range(int(log(n, 2))))", "def l... | {"fn_name": "last_man_standing", "inputs": [[9], [10], [100], [1000], [50000]], "outputs": [[6], [8], [54], [510], [22358]]} | introductory | https://www.codewars.com/kata/567c26df18e9b1083a000049 |
def last_man_standing(n):
|
2,728 | A common problem in number theory is to find x given a such that:
a * x = 1 mod [n]
Then x is called the inverse of a modulo n.
Your goal is to code a function inverseMod wich take a and n as parameters and return x.
You may be interested by these pages:
http://en.wikipedia.org/wiki/Modular_multiplicative_invers... | ["def egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n\n\ndef inverseMod(a, m):\n g, x, y = egcd(a, m)\n if g != 1:\n return None\n else:\n return x % m\n \n\n", "def gcd_ext(a, b):\n if b == 0:\n ... | {"fn_name": "inverseMod", "inputs": [[2, 5], [48, 101], [7, 733], [48, 733], [2, 733], [229, 101], [229, 103], [229, 105], [5, 5], [61965, 17408], [101014, 125445], [156435434, 3543432125]], "outputs": [[3], [40], [419], [168], [367], [15], [9], [94], [null], [null], [7969], [1056765589]]} | introductory | https://www.codewars.com/kata/53c945d750fe7094ee00016b |
def inverseMod(a, m):
|
2,735 | # Definition
**_Jumping number_** is the number that *All adjacent digits in it differ by 1*.
____
# Task
**_Given_** a number, **_Find if it is Jumping or not_** .
____
# Warm-up (Highly recommended)
# [Playing With Numbers Series](https://www.codewars.com/collections/playing-with-numbers)
___
# Notes
* **_N... | ["def jumping_number(number):\n arr = list(map(int, str(number)))\n return ('Not!!', 'Jumping!!')[all(map(lambda a, b: abs(a - b) == 1, arr, arr[1:]))]", "def jumping_number(number):\n digits = [int(char) for char in str(number)]\n if len(digits) == 1:\n return 'Jumping!!'\n else:\n deltas ... | {"fn_name": "jumping_number", "inputs": [[1], [7], [9], [23], [32], [79], [98], [987654322]], "outputs": [["Jumping!!"], ["Jumping!!"], ["Jumping!!"], ["Jumping!!"], ["Jumping!!"], ["Not!!"], ["Jumping!!"], ["Not!!"]]} | introductory | https://www.codewars.com/kata/5a54e796b3bfa8932c0000ed |
def jumping_number(number):
|
2,763 | In mathematics, a [Diophantine equation](https://en.wikipedia.org/wiki/Diophantine_equation) is a polynomial equation, usually with two or more unknowns, such that only the integer solutions are sought or studied.
In this kata we want to find all integers `x, y` (`x >= 0, y >= 0`) solutions of a diophantine equation o... | ["import math\ndef sol_equa(n):\n res = []\n for i in range(1, int(math.sqrt(n)) + 1):\n if n % i == 0:\n j = n // i\n if (i + j) % 2 == 0 and (j - i) % 4 == 0:\n x = (i + j) // 2\n y = (j - i) // 4\n res.append([x, y])\n \n r... | {"fn_name": "sol_equa", "inputs": [[5], [12], [13], [16], [17], [20], [9001], [9004], [9005], [9008], [90001], [90002], [90004], [90005], [90009], [900001], [900004], [900005], [9000001], [9000004], [90000001], [90000004], [900000012], [9000000041]], "outputs": [[[[3, 1]]], [[[4, 1]]], [[[7, 3]]], [[[4, 0]]], [[[9, 4]]... | introductory | https://www.codewars.com/kata/554f76dca89983cc400000bb |
def sol_equa(n):
|
2,777 | Consider the following expansion:
```Haskell
solve("3(ab)") = "ababab" -- "ab" repeats 3 times
solve("2(a3(b))" = "abbbabbb" -- "a3(b)" == "abbb" repeats twice.
```
Given a string, return the expansion of that string.
Input will consist of only lowercase letters and numbers (1 to 9) in valid parenthesis. There will ... | ["def solve(s):\n s1 = s[::-1]\n s2 = ''\n for i in s1:\n if i.isalpha():\n s2 += i\n elif i.isdigit():\n s2 = s2*int(i)\n return s2[::-1]", "import re\n\ndef solve(s):\n ops, parts = [], ['']\n for c in re.findall(r'\\d*\\(|\\)|[a-z]+', s):\n if c == ')':\n ... | {"fn_name": "solve", "inputs": [["3(ab)"], ["2(a3(b))"], ["3(b(2(c)))"], ["k(a3(b(a2(c))))"]], "outputs": [["ababab"], ["abbbabbb"], ["bccbccbcc"], ["kabaccbaccbacc"]]} | introductory | https://www.codewars.com/kata/5a793fdbfd8c06d07f0000d5 |
def solve(st):
|
2,781 | ##Background - the Collatz Conjecture:
Imagine you are given a positive integer, `n`, then:
* if `n` is even, calculate: `n / 2`
* if `n` is odd, calculate: `3 * n + 1`
Repeat until your answer is `1`. The Collatz conjecture states that performing this operation repeatedly, you will always eventually reach `1`.
You... | ["AVAILABLE_METHODS = {\n 'even' : lambda x: x / 2,\n 'odd': lambda x: 3 * x + 1\n}\n\ndef generator(x):\n temp = x\n temp_num = 0\n while temp > 1:\n if temp % 2 == 0:\n temp = AVAILABLE_METHODS['even'](temp)\n else:\n temp = AVAILABLE_METHODS['odd'](temp)\n te... | {"fn_name": "longest_collatz", "inputs": [[[1, 5, 27, 4]], [[64, 64, 27, 64]], [[75, 226, 113, 340]], [[340, 113, 226, 75]], [[75, 113, 226, 75]]], "outputs": [[27], [27], [75], [75], [75]]} | introductory | https://www.codewars.com/kata/57acc8c3e298a7ae4e0007e3 |
def longest_collatz(input_array):
|
2,782 | Your job is to create a calculator which evaluates expressions in [Reverse Polish notation](http://en.wikipedia.org/wiki/Reverse_Polish_notation).
For example expression `5 1 2 + 4 * + 3 -` (which is equivalent to `5 + ((1 + 2) * 4) - 3` in normal notation) should evaluate to `14`.
For your convenience, the input is ... | ["import operator\n\ndef calc(expr):\n OPERATORS = {'+': operator.add, '-': operator.sub, '*': operator.mul, '/': operator.truediv}\n stack = [0]\n for token in expr.split(\" \"):\n if token in OPERATORS:\n op2, op1 = stack.pop(), stack.pop()\n stack.append(OPERATORS[token](op1,op2... | {"fn_name": "calc", "inputs": [[""], ["3"], ["3.5"], ["1 3 +"], ["1 3 *"], ["1 3 -"], ["4 2 /"], ["10000 123 +"], ["5 1 2 + 4 * + 3 -"]], "outputs": [[0], [3], [3.5], [4], [3], [-2], [2], [10123], [14]]} | introductory | https://www.codewars.com/kata/52f78966747862fc9a0009ae |
def calc(expr):
|
2,787 | You're familiar with [list slicing](https://docs.python.org/3/library/functions.html#slice) in Python and know, for example, that:
```python
>>> ages = [12, 14, 63, 72, 55, 24]
>>> ages[2:4]
[63, 72]
>>> ages[2:]
[63, 72, 55, 24]
>>> ages[:3]
[12, 14, 63]
```
write a function `inverse_slice()` that takes three argume... | ["def inverse_slice(items, a, b):\n return items[:a] + items[b:]", "def inverse_slice(items, a, b):\n del items[a:b]\n return items", "def inverse_slice(items, a, b):\n part1 = items[:a]\n part2 = items[b:]\n return (part1+part2)", "def inverse_slice(items, a, b):\n return [v for i,v in enumerate(ite... | {"fn_name": "inverse_slice", "inputs": [[[12, 14, 63, 72, 55, 24], 2, 4], [[12, 14, 63, 72, 55, 24], 0, 3], [["Intuition", "is", "a", "poor", "guide", "when", "facing", "probabilistic", "evidence"], 5, 13]], "outputs": [[[12, 14, 55, 24]], [[72, 55, 24]], [["Intuition", "is", "a", "poor", "guide"]]]} | introductory | https://www.codewars.com/kata/586ec0b8d098206cce001141 |
def inverse_slice(items, a, b):
|
2,790 | In this Kata, you will be given an array of strings and your task is to remove all consecutive duplicate letters from each string in the array.
For example:
* `dup(["abracadabra","allottee","assessee"]) = ["abracadabra","alote","asese"]`.
* `dup(["kelless","keenness"]) = ["keles","kenes"]`.
Strings will be ... | ["from itertools import groupby\n\ndef dup(arry):\n return [\"\".join(c for c, grouper in groupby(i)) for i in arry]", "import re\n\ndef dup(arry):\n return list(map(lambda s: re.sub(r'(\\w)\\1+', r'\\1', s), arry))", "def dup(arry):\n array_new = []\n for string in arry:\n string_new = \"\"\n ... | {"fn_name": "dup", "inputs": [[["ccooddddddewwwaaaaarrrrsssss", "piccaninny", "hubbubbubboo"]], [["abracadabra", "allottee", "assessee"]], [["kelless", "keenness"]], [["Woolloomooloo", "flooddoorroommoonlighters", "chuchchi"]], [["adanac", "soonness", "toolless", "ppellee"]], [["callalloo", "feelless", "heelless"]], [[... | introductory | https://www.codewars.com/kata/59f08f89a5e129c543000069 |
def dup(arry):
|
2,791 | Trigrams are a special case of the n-gram, where n is 3. One trigram is a continious sequence of 3 chars in phrase. [Wikipedia](https://en.wikipedia.org/wiki/Trigram)
- return all trigrams for the given phrase
- replace spaces with \_
- return an empty string for phrases shorter than 3
Example:
trigrams('the qu... | ["def trigrams(phrase):\n phrase = phrase.replace(\" \", \"_\")\n return \" \".join([phrase[i:i+3]for i in range(len(phrase)-2)])\n", "def trigrams(phrase):\n solution = ''\n if len(phrase) < 3:\n return solution\n phrase = phrase.replace(' ','_')\n for i in range(len(phrase)-2):\n solut... | {"fn_name": "trigrams", "inputs": [["the quick red"], ["Hi"]], "outputs": [["the he_ e_q _qu qui uic ick ck_ k_r _re red"], [""]]} | introductory | https://www.codewars.com/kata/55d8dc4c8e629e55dc000068 |
def trigrams(phrase):
|
2,802 | *Based on this Numberphile video: https://www.youtube.com/watch?v=Wim9WJeDTHQ*
---
Multiply all the digits of a nonnegative integer `n` by each other, repeating with the product until a single digit is obtained. The number of steps required is known as the **multiplicative persistence**.
Create a function that calcu... | ["def per(n):\n r = []\n while n>=10:\n p=1\n for i in str(n):\n p=p*int(i)\n r.append(p)\n n = p\n return r", "from functools import reduce\n\ndef per(n):\n r = []\n p = reduce(lambda a, b: a*b, map(int, str(n)))\n return r if p == n else [p] + per(p)", "from fu... | {"fn_name": "per", "inputs": [[1234567890], [123456789], [12345678], [1234567], [123456], [12345], [2379], [777], [25], [277777788888899], [3778888999]], "outputs": [[[0]], [[362880, 0]], [[40320, 0]], [[5040, 0]], [[720, 0]], [[120, 0]], [[378, 168, 48, 32, 6]], [[343, 36, 18, 8]], [[10, 0]], [[4996238671872, 43893964... | introductory | https://www.codewars.com/kata/5c942f40bc4575001a3ea7ec |
def per(n):
|
2,807 | Positive integers have so many gorgeous features.
Some of them could be expressed as a sum of two or more consecutive positive numbers.
___
# Consider an Example :
* `10` , could be expressed as a sum of `1 + 2 + 3 + 4 `.
___
# Task
**_Given_** *Positive integer*, N , **_Return_** true if it could be expressed as a... | ["from math import log2\n\ndef consecutive_ducks(n):\n return not log2(n).is_integer()", "def consecutive_ducks(n):\n while n % 2 == 0:\n n //= 2\n return n > 1", "def consecutive_ducks(n):\n '''\n find x + (x + 1) = n thus x exists if (n-1) % 2 == 0\n if not, find x + (x + 1) + (x + 2) = n\n ... | {"fn_name": "consecutive_ducks", "inputs": [[69], [8], [57], [6], [13], [16], [91], [75], [38], [25], [32], [65], [99], [522], [974], [755], [512], [739], [1006], [838], [1092], [727], [648], [1024], [851], [541], [1011], [822], [382131], [118070], [17209], [32768], [161997], [400779], [198331], [325482], [88441], [655... | introductory | https://www.codewars.com/kata/5dae2599a8f7d90025d2f15f |
def consecutive_ducks(n):
|
2,808 | Implement the [Polybius square cipher](http://en.wikipedia.org/wiki/Polybius_square).
Replace every letter with a two digit number. The first digit is the row number, and the second digit is the column number of following square. Letters `'I'` and `'J'` are both 24 in this cipher:
table#polybius-square {width: 100px... | ["def polybius(text):\n letmap = { \"A\" : \"11\",\"B\" : \"12\",\"C\" : \"13\",\"D\" : \"14\",\"E\" : \"15\",\n \"F\" : \"21\",\"G\" : \"22\",\"H\" : \"23\",\"I\" : \"24\",\"J\" : \"24\", \"K\" : \"25\",\n \"L\" : \"31\",\"M\" : \"32\",\"N\" : \"33\",\"O\" : \"34\",\"P\" : \"35\",\n ... | {"fn_name": "polybius", "inputs": [["POLYBIUS"], ["CODEWARS"], ["POLYBIUS SQUARE CIPHER"]], "outputs": [["3534315412244543"], ["1334141552114243"], ["3534315412244543 434145114215 132435231542"]]} | introductory | https://www.codewars.com/kata/542a823c909c97da4500055e |
def polybius(text):
|
2,810 | Consider the word `"abode"`. We can see that the letter `a` is in position `1` and `b` is in position `2`. In the alphabet, `a` and `b` are also in positions `1` and `2`. Notice also that `d` and `e` in `abode` occupy the positions they would occupy in the alphabet, which are positions `4` and `5`.
Given an array of ... | ["def solve(arr):\n return [ sum(c == chr(97+i) for i,c in enumerate(w[:26].lower())) for w in arr ]", "from string import ascii_lowercase as alphabet\n\ndef solve(arr):\n return [sum(c == alphabet[i] for i,c in enumerate(word[:26].lower())) for word in arr]", "from operator import eq\nfrom string import ascii_lo... | {"fn_name": "solve", "inputs": [[["abode", "ABc", "xyzD"]], [["abide", "ABc", "xyz"]], [["IAMDEFANDJKL", "thedefgh", "xyzDEFghijabc"]], [["encode", "abc", "xyzD", "ABmD"]]], "outputs": [[[4, 3, 1]], [[4, 3, 0]], [[6, 5, 7]], [[1, 3, 1, 3]]]} | introductory | https://www.codewars.com/kata/59d9ff9f7905dfeed50000b0 |
def solve(arr):
|
2,817 | Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms.
If you want to know more http://en.wikipedia.org/wiki/DNA
In DNA strings, symbols "A" and "T" are complements of each other, as "C" and "G".
You have functio... | ["def DNA_strand(dna):\n pairs = [(\"A\", \"T\"), (\"C\", \"G\")]\n replacing_rules = pairs_to_dict(pairs)\n return \"\".join(list([replacing_rules[a] for a in dna]))\n\n\ndef pairs_to_dict(pairs):\n d = {}\n for pair in pairs: # Add two replacing rules for each pair\n d[pair[0]] = pair[1]\n ... | {"fn_name": "DNA_strand", "inputs": [["AAAA"], ["ATTGC"], ["GTAT"], ["AAGG"], ["CGCG"], ["GTATCGATCGATCGATCGATTATATTTTCGACGAGATTTAAATATATATATATACGAGAGAATACAGATAGACAGATTA"]], "outputs": [["TTTT"], ["TAACG"], ["CATA"], ["TTCC"], ["GCGC"], ["CATAGCTAGCTAGCTAGCTAATATAAAAGCTGCTCTAAATTTATATATATATATGCTCTCTTATGTCTATCTGTCTAAT"]... | introductory | https://www.codewars.com/kata/554e4a2f232cdd87d9000038 |
def DNA_strand(dna):
|
2,819 | ### Problem Context
The [Fibonacci](http://en.wikipedia.org/wiki/Fibonacci_number) sequence is traditionally used to explain tree recursion.
```python
def fibonacci(n):
if n in [0, 1]:
return n
return fibonacci(n - 1) + fibonacci(n - 2)
```
This algorithm serves welll its educative purpose but it's... | ["def memoized(f):\n cache = {}\n def wrapped(k):\n v = cache.get(k)\n if v is None:\n v = cache[k] = f(k)\n return v\n return wrapped\n\n@memoized\ndef fibonacci(n):\n if n in [0, 1]:\n return n\n return fibonacci(n - 1) + fibonacci(n - 2)", "from functools import ... | {"fn_name": "fibonacci", "inputs": [[70], [60], [50]], "outputs": [[190392490709135], [1548008755920], [12586269025]]} | introductory | https://www.codewars.com/kata/529adbf7533b761c560004e5 |
def fibonacci(n):
|
2,820 | This kata is part of the collection [Mary's Puzzle Books](https://www.codewars.com/collections/marys-puzzle-books).
Mary brought home a "spot the differences" book. The book is full of a bunch of problems, and each problem consists of two strings that are similar. However, in each string there are a few characters tha... | ["def spot_diff(s1, s2):\n return [i for i in range(len(s1)) if s1[i] != s2[i]]", "def spot_diff(s1, s2):\n return [k for k in range(len(s1)) if s1[k] != s2[k]]", "def spot_diff(s1, s2):\n r=[]\n for i in range (len(s1)):\n if s1[i]!=s2[i]: r.append(i)\n return r", "def spot_diff(s1, s2):\n return [i for i... | {"fn_name": "spot_diff", "inputs": [["abcdefg", "abcqetg"], ["Hello World!", "hello world."], ["FixedGrey", "FixedGrey"], ["HACKER", "H4CK3R"], ["This is a really long sentence.", "That is a_really long sentence,"], ["", ""], ["abcdefghijklmnopqrstuvwxyz", "zyxwvutsrqponmlkjihgfedcba"], ["YOLO lol", "ROLO mom"], ["www.... | introductory | https://www.codewars.com/kata/5881460c780e0dd207000084 |
def spot_diff(s1, s2):
|
2,828 | A [Power Law](https://en.wikipedia.org/wiki/Power_law) distribution occurs whenever "a relative change in one quantity results in a proportional relative change in the other quantity." For example, if *y* = 120 when *x* = 1 and *y* = 60 when *x* = 2 (i.e. *y* halves whenever *x* doubles) then when *x* = 4, *y* = 30 and... | ["from math import log\n\ndef power_law(p1, p2, x3):\n (x1, y1), (x2, y2) = p1, p2\n x1 += 1e-9; y1 += 1e-9\n return round(y1 * (y2 / y1) ** log(x3 / x1, x2 / x1))", "from math import log\n\ndef power_law(x1y1, x2y2, x3):\n a, b, c = x2y2[0]/x1y1[0], x2y2[1]/x1y1[1], x3/x1y1[0]\n try:\n return ro... | {"fn_name": "power_law", "inputs": [[[1, 120], [2, 60], 4], [[1, 120], [2, 60], 8], [[1, 120], [4, 30], 8], [[1, 120], [3, 60], 9], [[1, 120], [3, 60], 27], [[1, 120], [9, 30], 27], [[1, 81], [2, 27], 4], [[1, 81], [2, 27], 8], [[1, 81], [4, 9], 8], [[1, 81], [5, 27], 25], [[1, 81], [5, 27], 125], [[1, 81], [25, 9], 12... | introductory | https://www.codewars.com/kata/59b6ae2e5227dd0fbc000005 |
def power_law(x1y1, x2y2, x3):
|
2,834 | "Point reflection" or "point symmetry" is a basic concept in geometry where a given point, P, at a given position relative to a mid-point, Q has a corresponding point, P1, which is the same distance from Q but in the opposite direction.
## Task
Given two points P and Q, output the symmetric point of point P about Q.
... | ["def symmetric_point(p, q):\n return [2*q[0] - p[0], 2*q[1] - p[1]]", "symmetric_point = lambda p, q: [2 * b - a for a, b in zip(p, q)]", "def symmetric_point(p, q):\n # your code here\n p1x = (q[0] - p[0]) + q[0]\n p1y = (q[1] - p[1]) + q[1]\n return [p1x, p1y]", "symmetric_point = lambda p,q: [2*q[0] ... | {"fn_name": "symmetric_point", "inputs": [[[0, 0], [1, 1]], [[2, 6], [-2, -6]], [[10, -10], [-10, 10]], [[1, -35], [-12, 1]], [[1000, 15], [-7, -214]], [[0, 0], [0, 0]]], "outputs": [[[2, 2]], [[-6, -18]], [[-30, 30]], [[-25, 37]], [[-1014, -443]], [[0, 0]]]} | introductory | https://www.codewars.com/kata/57bfea4cb19505912900012c |
def symmetric_point(p, q):
|
2,835 | Consider a sequence made up of the consecutive prime numbers. This infinite sequence would start with:
```python
"2357111317192329313741434753596167717379..."
```
You will be given two numbers: `a` and `b`, and your task will be to return `b` elements starting from index `a` in this sequence.
```
For example:
solve(1... | ["def solve(a, b):\n primes = \"235711131719232931374143475359616771737983899710110310710911312713113713914915115716316717317918119119319719921122322722923323924125125726326927127728128329330731131331733133734734935335936737337938338939740140941942143143343944344945746146346747948749149950350952152354154755756356957... | {"fn_name": "solve", "inputs": [[2, 2], [10, 5], [10, 3], [20, 9], [30, 12], [40, 8], [50, 6], [10000, 5], [20000, 5]], "outputs": [["57"], ["19232"], ["192"], ["414347535"], ["616771737983"], ["83899710"], ["031071"], ["02192"], ["09334"]]} | introductory | https://www.codewars.com/kata/5a908da30025e995880000e3 |
def solve(a, b):
|
2,841 | Taking into consideration the [3.5 edition rules](http://www.dandwiki.com/wiki/SRD:Ability_Scores#Table:_Ability_Modifiers_and_Bonus_Spells), your goal is to build a function that takes an ability score (worry not about validation: it is always going to be a non negative integer), will return:
* attribute modifier, as... | ["def char_attribute(score):\n return ({\"modifier\": 0, \"maximum_spell_level\": -1, \"extra_spells\": []} if not score\n else {\"modifier\": score//2-5,\n \"maximum_spell_level\": -1 if score//2-5 < 0 else min(9, score -10) ,\n \"extra_spells\": [1+n//4 for n in r... | {"fn_name": "char_attribute", "inputs": [[0], [1], [5], [10], [20]], "outputs": [[{"modifier": 0, "maximum_spell_level": -1, "extra_spells": []}], [{"modifier": -5, "maximum_spell_level": -1, "extra_spells": []}], [{"modifier": -3, "maximum_spell_level": -1, "extra_spells": []}], [{"modifier": 0, "maximum_spell_level":... | introductory | https://www.codewars.com/kata/596a690510ffee5c0b00006a |
def char_attribute(score):
|
2,844 | Write a program that prints a chessboard with N rows and M columns with the following rules:
The top left cell must be an asterisk (*)
Any cell touching (left, right, up or down) a cell with an asterisk must be a dot (.)
Any cell touching (left, right, up or down) a cell with a dot must be an asterisk.
A chessboard of... | ["def chessboard(s):\n N, M = map(int, s.split())\n row = \".*\" * M\n return \"\\n\".join( [row[:M] if i&1 else row[1:M+1] for i in range(N)] )", "chessboard = lambda s: '\\n'.join(([''.join(['.' if (x + y) % 2 else '*' for x in range(int(s.split()[1]))]) for y in range(int(s.split()[0]))]))", "from itertools... | {"fn_name": "chessboard", "inputs": [["0 0"], ["1 0"], ["0 1"], ["2 2"], ["3 3"], ["5 2"], ["8 8"]], "outputs": [[""], [""], [""], ["*.\n.*"], ["*.*\n.*.\n*.*"], ["*.\n.*\n*.\n.*\n*."], ["*.*.*.*.\n.*.*.*.*\n*.*.*.*.\n.*.*.*.*\n*.*.*.*.\n.*.*.*.*\n*.*.*.*.\n.*.*.*.*"]]} | introductory | https://www.codewars.com/kata/5749b82229d16cbc320015fe |
def chessboard(s):
|
2,845 | DNA is a biomolecule that carries genetic information. It is composed of four different building blocks, called nucleotides: adenine (A), thymine (T), cytosine (C) and guanine (G). Two DNA strands join to form a double helix, whereby the nucleotides of one strand bond to the nucleotides of the other strand at the corre... | ["def check_DNA(seq1, seq2):\n if len(seq1) < len(seq2): seq1, seq2 = seq2, seq1\n seq2 = seq2[::-1].replace('C','g').replace('G','c').replace('T','a').replace('A','t').upper()\n return seq1.find(seq2) >= 0", "table = str.maketrans(\"ACGT\", \"TGCA\")\n\ndef check_DNA(seq1, seq2):\n seq1, seq2 = sorted((seq1, seq2),... | {"fn_name": "check_DNA", "inputs": [["GTCTTAGTGTAGCTATGCATGC", "GCATGCATAGCTACACTACGAC"], ["ATGCTACG", "CGTAGCAT"], ["AGTCTGTATGCATCGTACCC", "GGGTACGATGCATACAGACT"], ["TGCTACGTACGATCGACGATCCACGAC", "GTCGTGGATCGTCGATCGTACGTAGCA"], ["ATGCCTACGGCCATATATATTTAG", "CTAAATATGTATGGCCGTAGGCAT"], ["GTCACCGA", "TCGGCTGAC"], ["TAA... | introductory | https://www.codewars.com/kata/56fbb2b8fca8b97e4d000a31 |
def check_DNA(seq1, seq2):
|
2,847 | You just took a contract with the Jedi council. They need you to write a function, `greet_jedi()`, which takes two arguments (a first name and a last name), works out the corresponding *Jedi name*, and returns a string greeting the Jedi.
A person's *Jedi name* is the first three letters of their last name followed by ... | ["def greet_jedi(first, last):\n return \"Greetings, master {}{}\".format(last[:3].capitalize(), first[:2].capitalize())", "def greet_jedi(f, l):\n return 'Greetings, master ' + l[0:3].capitalize() + f[0:2].capitalize()", "def greet_jedi(first, last):\n return 'Greetings, master %s%s' % (last[:3].capitalize(), f... | {"fn_name": "greet_jedi", "inputs": [["Beyonce", "Knowles"], ["Chris", "Angelico"], ["grae", "drake"]], "outputs": [["Greetings, master KnoBe"], ["Greetings, master AngCh"], ["Greetings, master DraGr"]]} | introductory | https://www.codewars.com/kata/585a29183d357b31f700023f |
def greet_jedi(first, last):
|
2,848 | Consider the array `[3,6,9,12]`. If we generate all the combinations with repetition that sum to `12`, we get `5` combinations: `[12], [6,6], [3,9], [3,3,6], [3,3,3,3]`. The length of the sub-arrays (such as `[3,3,3,3]` should be less than or equal to the length of the initial array (`[3,6,9,12]`).
Given an array of... | ["from itertools import combinations_with_replacement\n\ndef find(arr,n):\n return sum( sum(c) == n for x in range(1,len(arr)+1) for c in combinations_with_replacement(arr, x) )", "def find(arr,n):\n return(findl(arr,n,len(arr)))\ndef findl(arr,n,l):\n return(sum(findl(arr[1:],n-arr[0]*i,l-i) for i in range(l+... | {"fn_name": "find", "inputs": [[[1, 2, 3], 10], [[1, 2, 3], 7], [[1, 2, 3], 5], [[3, 6, 9, 12], 12], [[1, 4, 5, 8], 8], [[3, 6, 9, 12], 15], [[3, 6, 9, 12, 14, 18], 30]], "outputs": [[0], [2], [3], [5], [3], [5], [21]]} | introductory | https://www.codewars.com/kata/59f3178e3640cef6d90000d5 |
def find(arr,n):
|
2,849 | Given an array of ints, return the index such that the sum of the elements to the right of that index equals the sum of the elements to the left of that index. If there is no such index, return `-1`. If there is more than one such index, return the left-most index.
For example:
```
peak([1,2,3,5,3,2,1]) = 3, because ... | ["def peak(arr):\n for i, val in enumerate(arr):\n if sum(arr[:i]) == sum(arr[i+1:]):\n return i\n return -1", "def peak(arr):\n for i in range(len(arr)):\n if sum(arr[:i]) == sum(arr[i+1:]): return i\n return -1", "def peak(arr):\n sl, sr = 0, sum(arr)\n for i,v in enumerate(... | {"fn_name": "peak", "inputs": [[[1, 2, 3, 5, 3, 2, 1]], [[1, 12, 3, 3, 6, 3, 1]], [[10, 20, 30, 40]]], "outputs": [[3], [2], [-1]]} | introductory | https://www.codewars.com/kata/5a61a846cadebf9738000076 |
def peak(arr):
|
2,858 | # Task
Miss X has only two combs in her possession, both of which are old and miss a tooth or two. She also has many purses of different length, in which she carries the combs. The only way they fit is horizontally and without overlapping. Given teeth' positions on both combs, find the minimum length of the purse she ... | ["def combs(a, b):\n return min(mesh(a, b), mesh(b, a))\n\ndef mesh(a, b):\n for i in range(len(a)):\n for j, k in zip(a[i:], b):\n if j + k == '**': break\n else:\n return max(i + len(b), len(a))\n return len(a) + len(b) ", "def combs(comb1, comb2):\n options ... | {"fn_name": "combs", "inputs": [["*..*", "*.*"], ["*...*", "*.*"], ["*..*.*", "*.***"], ["*.*", "*.*"], ["*.**", "*.*"]], "outputs": [[5], [5], [9], [4], [5]]} | introductory | https://www.codewars.com/kata/58898b50b832f8046a0000ec |
def combs(comb1, comb2):
|
2,876 | *** No Loops Allowed ***
You will be given an array (a) and a value (x). All you need to do is check whether the provided array contains the value, without using a loop.
Array can contain numbers or strings. X can be either. Return true if the array contains the value, false if not. With strings you will need to acco... | ["def check(a, x): \n return x in a", "check=lambda a,x:x in a", "check = list.__contains__", "from operator import contains as check", "def check(a, x): \n return a.count(x) > 0", "check = lambda x,a: a in x", "def check(a, x): \n#My first solution\n\n# if x in a:\n# return True\n# else:\n# ... | {"fn_name": "check", "inputs": [[[66, 101], 66], [[80, 117, 115, 104, 45, 85, 112, 115], 45], [["t", "e", "s", "t"], "e"], [["what", "a", "great", "kata"], "kat"], [[66, "codewars", 11, "alex loves pushups"], "alex loves pushups"], [["come", "on", 110, "2500", 10, "!", 7, 15], "Come"], [["when's", "the", "next", "Katat... | introductory | https://www.codewars.com/kata/57cc40b2f8392dbf2a0003ce |
def check(a, x):
|
2,879 | The objective is to disambiguate two given names: the original with another
This kata is slightly more evolved than the previous one: [Author Disambiguation: to the point!](https://www.codewars.com/kata/580a429e1cb4028481000019).
The function ```could_be``` is still given the original name and another one to test
aga... | ["import re\nimport unicodedata\n\nNAME = re.compile(\"[\\w-]+\")\n\ndef decompose(name):\n standarized = unicodedata.normalize('NFKD', name.lower()) \\\n .encode('ascii', 'ignore') if type(name) != str \\\n else name.lower()\n return re.findall(NAME, standarized)\n\ndef could_be(original, another):... | {"fn_name": "could_be", "inputs": [["Carlos Ray Norris", "Carlos Ray Norris"], ["Carlos Ray Norris", "Carlos Ray"], ["Carlos Ray Norris", "Ray Norris"], ["Carlos Ray Norris", "Carlos Norris"], ["Carlos Ray Norris", "Norris"], ["Carlos Ray Norris", "Carlos"], ["Carlos Ray Norris", "Norris Carlos"], ["Carlos Ray Norris",... | introductory | https://www.codewars.com/kata/580a8f039a90a3654b000032 |
def could_be(original, another):
|
2,881 | In this Kata, you will implement the [Luhn Algorithm](http://en.wikipedia.org/wiki/Luhn_algorithm), which is used to help validate credit card numbers.
Given a positive integer of up to 16 digits, return ```true``` if it is a valid credit card number, and ```false``` if it is not.
Here is the algorithm:
* Double e... | ["def validate(n):\n digits = [int(x) for x in str(n)]\n even = [x*2 if x*2 <= 9 else x*2 - 9 for x in digits[-2::-2]]\n odd = [x for x in digits[-1::-2]]\n return (sum(even + odd)%10) == 0\n", "import numpy as np\ndef validate(cc_number):\n # split integer into array of digits\n arr = np.array([int(... | {"fn_name": "validate", "inputs": [[123], [1], [2121], [1230], [8675309], [4111111111111111], [26], [2626262626262626], [91], [92], [912030], [922030]], "outputs": [[false], [false], [true], [true], [false], [true], [true], [true], [true], [false], [true], [false]]} | introductory | https://www.codewars.com/kata/5418a1dd6d8216e18a0012b2 |
def validate(n):
|
2,884 | # Convert a linked list to a string
## Related Kata
Although this Kata is not part of an official Series, you may also want to try out [Parse a linked list from a string](https://www.codewars.com/kata/582c5382f000e535100001a7) if you enjoyed this Kata.
## Preloaded
Preloaded for you is a class, struct or derived da... | ["def stringify(list):\n return 'None' if list == None else str(list.data) + ' -> ' + stringify(list.next)", "def stringify(ll):\n r = []\n while ll:\n r, ll = r + [str(ll.data)], ll.next\n return ' -> '.join(r + ['None'])", "def stringify(head):\n if head is None:\n return \"None\"\n re... | {"fn_name": "stringify", "inputs": [[null]], "outputs": [["None"]]} | introductory | https://www.codewars.com/kata/582c297e56373f0426000098 |
def stringify(node):
|
2,885 | Ho ho! So you think you know integers, do you? Well then, young wizard, tell us what the Nth digit of the [Champernowne constant](https://en.wikipedia.org/wiki/Champernowne_constant) is!
The constant proceeds like this: `0.12345678910111213141516...`
I hope you see the pattern!
Conjure a function that will accept an... | ["def champernowne_digit(n):\n if not type(n) is int or n < 1:\n return float(\"NaN\")\n i, l = 1, 11\n while l <= n:\n i, l = i + 1, l + 9 * (i + 1) * 10**i\n return ((n - l) // (i * 10**(i - 1 - (n - l) % i))) % 10\n\nchampernowneDigit = champernowne_digit\n", "DIGIT_CNTS = [1] + [(10**i - 1... | {"fn_name": "champernowneDigit", "inputs": [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [20], [35], [36], [37], [100], [101], [102], [103], [104], [105], [190], [2890], [38890], [488890], [5888890], [3678608], [3678609], [3678610], [3678611], [3678612], [3678613], [3678614], [3897249], [3897189], [38... | introductory | https://www.codewars.com/kata/5ac53c71376b11df7e0001a9 |
def champernowneDigit(n):
|
2,886 | # Description:
Find the longest successive exclamation marks and question marks combination in the string. A successive exclamation marks and question marks combination must contains two part: a substring of "!" and a substring "?", they are adjacent.
If more than one result are found, return the one which at lef... | ["import re\n\ndef find(stg):\n matches = re.findall(r\"(!+|\\?+)\", stg)\n return max((f\"{a}{b}\" for a, b in zip(matches, matches[1:])), key=len, default=\"\")", "from itertools import groupby\n\ndef find(s):\n L = [k*len(list(v)) for k,v in groupby(s)]\n return max((x + y for x,y in zip(L, L[1:])), key=... | {"fn_name": "find", "inputs": [["!!"], ["!??"], ["!?!!"], ["!!???!????"], ["!!???!?????"], ["!????!!!?"], ["!?!!??!!!?"]], "outputs": [[""], ["!??"], ["?!!"], ["!!???"], ["!?????"], ["????!!!"], ["??!!!"]]} | introductory | https://www.codewars.com/kata/57fb3c839610ce39f7000023 |
def find(s):
|
2,887 | Everyone Knows AdFly and their Sister Sites.
If we see the Page Source of an ad.fly site we can see this perticular line:
Believe it or not This is actually the Encoded url which you would skip to.
The Algorithm is as Follows:
```
1) The ysmm value is broken like this
ysmm = 0 1 2 3 4 5 6 7 8 9 = "0123456789"
cod... | ["import base64\nimport binascii\nimport math\nfrom itertools import zip_longest\n\n\ndef adFly_decoder(sc):\n code1 = \"\"\n code2 = \"\"\n flip = False\n for c in sc:\n if flip:\n code2 += c\n else:\n code1 += c\n flip = not flip\n\n try:\n url = base64... | {"fn_name": "adFly_decoder", "inputs": [["O=T0ZToPdRHJRmwdcOz1oGvTL22lFzkRZhih5GsbezSw9kndbvyR50wYawHIAF/SdhT1"], ["N=z0dDoMdyHIRmwac1zMolvWLz2RFmkMZiiZ5HsZeySw9kndbvyR50wYawHIAF/SdhT1"], ["lololol"]], "outputs": [["http://yahoo.com"], ["http://google.com"], ["Invalid"]]} | introductory | https://www.codewars.com/kata/56896d1d6ba4e91b8c00000d |
def adFly_decoder(sc):
|
2,891 | # Introduction
Digital Cypher assigns a unique number to each letter of the alphabet:
```
a b c d e f g h i j k l m n o p q r s t u v w x y z
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
```
In the encrypted word we write the corresponding numbers instead o... | ["def find_the_key(message, code):\n diffs = \"\".join( str(c - ord(m) + 96) for c, m in zip(code, message) )\n for size in range(1, len(code) +1):\n key = diffs[:size]\n if (key * len(code))[:len(code)] == diffs:\n return int(key)", "def find_the_key(message, code):\n key = \"\".join(... | {"fn_name": "find_the_key", "inputs": [["scout", [20, 12, 18, 30, 21]], ["masterpiece", [14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8]], ["nomoretears", [15, 17, 14, 17, 19, 7, 21, 7, 2, 20, 20]], ["notencrypted", [14, 15, 20, 5, 14, 3, 18, 25, 16, 20, 5, 4]], ["tenthousand", [21, 5, 14, 20, 8, 16, 21, 19, 1, 14, 5]], ["one... | introductory | https://www.codewars.com/kata/5930d8a4b8c2d9e11500002a |
def find_the_key(message, code):
|
2,892 | We’ve all seen katas that ask for conversion from snake-case to camel-case, from camel-case to snake-case, or from camel-case to kebab-case — the possibilities are endless.
But if we don’t know the case our inputs are in, these are not very helpful.
### Task:
So the task here is to implement a function (called `id` ... | ["import re\n\nCASES = [\n ('snake', re.compile(r'\\A[a-z]+(_[a-z]+)+\\Z')),\n ('kebab', re.compile(r'\\A[a-z]+(-[a-z]+)+\\Z')),\n ('camel', re.compile(r'\\A[a-z]+([A-Z][a-z]*)+\\Z')),\n ('none', re.compile(r'')),\n]\n\ndef case_id(c_str):\n for case, pattern in CASES:\n if pattern.match(c_str): r... | {"fn_name": "case_id", "inputs": [["hello-world"], ["hello-to-the-world"], ["hello_world"], ["hello_to_the_world"], ["helloWorld"], ["helloToTheWorld"], ["hello-World"], ["hello-To-The-World"], ["good-Night"], ["he--llo"], ["good-night"], ["good_night"], ["goodNight"], ["hello_World"], ["hello_To_The_World"], ["he_lloW... | introductory | https://www.codewars.com/kata/5819a6fdc929bae4f5000a33 |
def case_id(c_str):
|
2,901 | Following from the previous kata and taking into account how cool psionic powers are compare to the Vance spell system (really, the idea of slots to dumb down the game sucks, not to mention that D&D became a smash hit among geeks, so...), your task in this kata is to create a function that returns how many power points... | ["psion_power_points=lambda l,s: [0,2,6,11,17,25,35,46,58,72,88,106,126,147,170,195,221,250,280,311,343][min(l,20)]+(s-10)//2*l//2 if l and s>10 else 0", "powers = [0,2,6,11,17,25,35,46,58,72,88,106,126,147,170,195,221,250,280,311,343]\ndef psion_power_points(level, score):\n score = max(score - 10, 0)\n return l... | {"fn_name": "psion_power_points", "inputs": [[1, 0], [1, 10], [1, 11], [0, 11], [1, 20], [21, 30]], "outputs": [[0], [0], [2], [0], [4], [448]]} | introductory | https://www.codewars.com/kata/596b1d44224071b9f5000010 |
def psion_power_points(level,score):
|
2,907 | This kata is an extension of "Combinations in a Set Using Boxes":https://www.codewars.com/kata/5b5f7f7607a266914200007c
The goal for this kata is to get all the possible combinations (or distributions) (with no empty boxes) of a certain number of balls, but now, **with different amount of boxes.** In the previous kata... | ["MAX_BALL = 2+1800\nDP,lst = [None], [0,1]\nfor _ in range(MAX_BALL):\n DP.append([sum(lst), *max( (v,i) for i,v in enumerate(lst) )])\n lst.append(0)\n lst = [ v*i + lst[i-1] for i,v in enumerate(lst) ]\n \ncombs_non_empty_boxesII = DP.__getitem__\n", "# this is [A000110, A002870, A024417]\n\n# Stirling n... | {"fn_name": "combs_non_empty_boxesII", "inputs": [[4], [3], [2], [20]], "outputs": [[[15, 7, 2]], [[5, 3, 2]], [[2, 1, 2]], [[51724158235372, 15170932662679, 8]]]} | introductory | https://www.codewars.com/kata/5b61e9306d0db7d097000632 |
def combs_non_empty_boxesII(n):
|
2,910 | *** No Loops Allowed ***
You will be given an array (a) and a limit value (limit). You must check that all values in the array are below or equal to the limit value. If they are, return true. Else, return false.
You can assume all values in the array are numbers.
Do not use loops. Do not modify input array.
Looking... | ["def small_enough(a, limit): \n return max(a) <= limit", "def small_enough(a, limit): \n if max(a) <= limit:\n return True\n else:\n return False", "def small_enough(a, limit): \n if a[0] > limit:\n return False\n \n if len(a) > 1:\n return small_enough(a[1:], limit)\n... | {"fn_name": "small_enough", "inputs": [[[66, 101], 200], [[78, 117, 110, 99, 104, 117, 107, 115], 100], [[101, 45, 75, 105, 99, 107], 107], [[80, 117, 115, 104, 45, 85, 112, 115], 120]], "outputs": [[true], [false], [true], [true]]} | introductory | https://www.codewars.com/kata/57cc4853fa9fc57a6a0002c2 |
def small_enough(a, limit):
|
2,919 | # Introduction
Digital Cypher assigns to each letter of the alphabet unique number. For example:
```
a b c d e f g h i j k l m
1 2 3 4 5 6 7 8 9 10 11 12 13
n o p q r s t u v w x y z
14 15 16 17 18 19 20 21 22 23 24 25 26
```
Instead of letters in encrypted word we write the corre... | ["from itertools import cycle\n\ndef encode(message, key):\n return [ord(a) - 96 + int(b) for a,b in zip(message,cycle(str(key)))]", "def encode(message, key):\n # initialize variables\n output = []\n i = 0\n \n # convert key to a list of integers\n key = [int(d) for d in str(key)]\n \n # enc... | {"fn_name": "encode", "inputs": [["scout", 1939], ["masterpiece", 1939]], "outputs": [[[20, 12, 18, 30, 21]], [[14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8]]]} | introductory | https://www.codewars.com/kata/592e830e043b99888600002d |
def encode(message, key):
|
2,921 | Just another day in the world of Minecraft, Steve is working on his new project -- building a beacon pyramid in front of his house.

Steve has already obtained the beacon (the glass wrapped blue thingy on the top), he just needs to ... | ["def blocks_to_collect(level):\n answer = {\n 'total': sum([(i+3+i)**2 for i in range(level)]),\n 'gold': sum([(i+3+i)**2 for i in range(0,level,4)]),\n 'diamond': sum([(i+3+i)**2 for i in range(1,level,4)]),\n 'emerald': sum([(i+3+i)**2 for i in range(2,level,4)]),\n 'iron': sum([(i+3+i)**2 for i in... | {"fn_name": "blocks_to_collect", "inputs": [[1], [2], [3]], "outputs": [[{"total": 9, "gold": 9, "diamond": 0, "emerald": 0, "iron": 0}], [{"total": 34, "gold": 9, "diamond": 25, "emerald": 0, "iron": 0}], [{"total": 83, "gold": 9, "diamond": 25, "emerald": 49, "iron": 0}]]} | introductory | https://www.codewars.com/kata/5839cd780426f5d0ec00009a |
def blocks_to_collect(level):
|
2,929 | #### Task:
Your job here is to implement a function `factors`, which takes a number `n`, and outputs an array of arrays comprised of two
parts, `sq` and `cb`. The part `sq` will contain all the numbers that, when squared, yield a number which is a factor of `n`,
while the `cb` part will contain all the numbers that, w... | ["def factors(n):\n sq = [a for a in range(2, n+1) if not n % (a**2)]\n cb = [b for b in range(2, n+1) if not n % (b**3)]\n return [sq, cb]", "def factors(n):\n sq = [i for i in range(2, int(n**0.5) + 2) if n%(i*i)==0]\n cb = [i for i in range(2, int(n**(1/3) + 2)) if n%(i*i*i)==0]\n return [sq, cb]",... | {"fn_name": "factors", "inputs": [[1], [4], [16], [81], [80], [100], [5], [120], [18], [8]], "outputs": [[[[], []]], [[[2], []]], [[[2, 4], [2]]], [[[3, 9], [3]]], [[[2, 4], [2]]], [[[2, 5, 10], []]], [[[], []]], [[[2], [2]]], [[[3], []]], [[[2], [2]]]]} | introductory | https://www.codewars.com/kata/582b0d73c190130d550000c6 |
def factors(n):
|
2,934 | Given a lowercase string that has alphabetic characters only and no spaces, return the highest value of consonant substrings. Consonants are any letters of the alphabet except `"aeiou"`.
We shall assign the following values: `a = 1, b = 2, c = 3, .... z = 26`.
For example, for the word "zodiacs", let's cross out the... | ["import re\n\ndef solve(s):\n return max(sum(ord(c)-96 for c in subs) for subs in re.split('[aeiou]+', s))", "def solve(s):\n max_ord = 0\n curr_ord = 0\n for char in s:\n if char not in 'aeiou':\n curr_ord += ord(char)-ord('a')+1\n else:\n if curr_ord > max_ord:\n ... | {"fn_name": "solve", "inputs": [["zodiac"], ["chruschtschov"], ["khrushchev"], ["strength"], ["catchphrase"], ["twelfthstreet"], ["mischtschenkoana"]], "outputs": [[26], [80], [38], [57], [73], [103], [80]]} | introductory | https://www.codewars.com/kata/59c633e7dcc4053512000073 |
def solve(s):
|
2,940 | In this Kata, you will be given an array of numbers in which two numbers occur once and the rest occur only twice. Your task will be to return the sum of the numbers that occur only once.
For example, `repeats([4,5,7,5,4,8]) = 15` because only the numbers `7` and `8` occur once, and their sum is `15`.
More examples ... | ["def repeats(arr):\n return sum([x for x in arr if arr.count(x) == 1])", "from collections import Counter\n\ndef repeats(arr):\n return sum(k for k, v in Counter(arr).items() if v == 1)", "def repeats(arr):\n return sum(n for n in arr if arr.count(n) == 1)", "def repeats(arr):\n single = [] #create a list to... | {"fn_name": "repeats", "inputs": [[[4, 5, 7, 5, 4, 8]], [[9, 10, 19, 13, 19, 13]], [[16, 0, 11, 4, 8, 16, 0, 11]], [[5, 17, 18, 11, 13, 18, 11, 13]], [[5, 10, 19, 13, 10, 13]]], "outputs": [[15], [19], [12], [22], [24]]} | introductory | https://www.codewars.com/kata/59f11118a5e129e591000134 |
def repeats(arr):
|
2,941 | This kata is all about adding numbers.
You will create a function named add. It will return the sum of all the arguments. Sounds easy, doesn't it?
Well Here's the Twist. The inputs will gradually decrease with their index as parameter to the function.
```python
add(3,4,6) #returns (3/1)+(4/2)+(6/3)=7
```
Remember... | ["def add(*args):\n return int(round(sum(float(a) / i for (i, a) in enumerate(args, 1))))", "def add(*args):\n return round(sum(x / i for i, x in enumerate(args, 1)))\n", "add = lambda *a: round(sum(e/i for i,e in enumerate(a,1)))", "def add(*args): \n return round(sum([args[i]/(i + 1) for i in range(len(args... | {"fn_name": "add", "inputs": [[100, 200, 300], [2], [4, -3, -2], [-1, -2, -3, -4]], "outputs": [[300], [2], [2], [-4]]} | introductory | https://www.codewars.com/kata/555de49a04b7d1c13c00000e |
def add(*args):
|
2,942 | Have you heard about the myth that [if you fold a paper enough times, you can reach the moon with it](http://scienceblogs.com/startswithabang/2009/08/31/paper-folding-to-the-moon/)? Sure you have, but exactly how many? Maybe it's time to write a program to figure it out.
You know that a piece of paper has a thickness ... | ["def fold_to(distance, thickness=0.0001, folds=0):\n if distance < 0:\n return\n \n while thickness < distance:\n thickness *= 2\n folds += 1\n \n return folds", "import math\ndef fold_to(d):\n if d<0:\n return None\n if d<0.0001:\n return 0\n return math.ceil... | {"fn_name": "fold_to", "inputs": [[384000000], [5e-05], [1e-07], [0], [-1]], "outputs": [[42], [0], [0], [0], [null]]} | introductory | https://www.codewars.com/kata/58f0ba42e89aa6158400000e |
def fold_to(distance):
|
2,943 | __Definition:__ According to Wikipedia, a [complete binary tree](https://en.wikipedia.org/wiki/Binary_tree#Types_of_binary_trees) is a binary tree _"where every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible."_
The Wikipedia page referenced above also... | ["def complete_binary_tree(a):\n def in_order(n=0):\n if n < len(a):\n yield from in_order(2 * n + 1)\n yield n\n yield from in_order(2 * n + 2)\n\n result = [None] * len(a)\n for i, x in zip(in_order(), a):\n result[i] = x\n return result", "def mid(n):\n x... | {"fn_name": "complete_binary_tree", "inputs": [[[1]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]], "outputs": [[[1]], [[4, 2, 6, 1, 3, 5]], [[7, 4, 9, 2, 6, 8, 10, 1, 3, 5]]]} | introductory | https://www.codewars.com/kata/5c80b55e95eba7650dc671ea |
def complete_binary_tree(a):
|
2,949 | *Inspired by the [Fold an Array](https://www.codewars.com/kata/fold-an-array) kata. This one is sort of similar but a little different.*
---
## Task
You will receive an array as parameter that contains 1 or more integers and a number `n`.
Here is a little visualization of the process:
* Step 1: Split the array in t... | ["def split_and_add(numbers, n):\n for _ in range(n):\n middle = len(numbers) // 2\n left = numbers[:middle]\n right = numbers[middle:]\n numbers = [a + b for a, b in zip((len(right) - len(left)) * [0] + left, right)]\n if len(numbers) == 1:\n return numbers\n return ... | {"fn_name": "split_and_add", "inputs": [[[1, 2, 3, 4, 5], 2], [[1, 2, 3, 4, 5], 3], [[15], 3], [[1, 2, 3, 4], 1], [[1, 2, 3, 4, 5, 6], 20], [[32, 45, 43, 23, 54, 23, 54, 34], 2], [[32, 45, 43, 23, 54, 23, 54, 34], 0], [[3, 234, 25, 345, 45, 34, 234, 235, 345], 3], [[3, 234, 25, 345, 45, 34, 234, 235, 345, 34, 534, 45, ... | introductory | https://www.codewars.com/kata/5946a0a64a2c5b596500019a |
def split_and_add(numbers, n):
|
2,954 | # A History Lesson
The Pony Express was a mail service operating in the US in 1859-60.
It reduced the time for messages to travel between the Atlantic and Pacific coasts to about 10 days, before it was made obsolete by the [transcontinental telegraph](https://en.wikipedia.org/wiki/First_transcontinental_telegraph)... | ["def riders(stations):\n riders, travelled = 1, 0\n \n for dist in stations:\n if travelled + dist > 100:\n riders += 1\n travelled = dist\n else:\n travelled += dist\n \n return riders", "def riders(stations):\n n = 1\n acc = 0\n for x in stations... | {"fn_name": "riders", "inputs": [[[18, 15]], [[43, 23, 40, 13]], [[33, 8, 16, 47, 30, 30, 46]], [[6, 24, 6, 8, 28, 8, 23, 47, 17, 29, 37, 18, 40, 49]], [[50, 50]], [[50, 50, 25, 50, 24]], [[50, 50, 25, 50, 25]], [[50, 50, 25, 50, 26]], [[90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90... | introductory | https://www.codewars.com/kata/5b18e9e06aefb52e1d0001e9 |
def riders(stations):
|
2,958 | # Your Task
You have a cuboid with dimensions x,y,z ∈ ℕ. A subcuboid of this cuboid has dimensions length, width, height ∈ ℕ where 1≤length≤x, 1≤width≤y, 1≤height≤z. If two subcuboids have the same length, width, and height, but they are at different positions within the cuboid, they are distinct. Find the total number... | ["def subcuboids(x,y,z):\n return x*y*z*(x+1)*(y+1)*(z+1)//8", "def n(x):\n return x * (x+1) // 2\n\ndef subcuboids(x, y, z):\n return n(x) * n(y) * n(z)", "def subcuboids(x,y,z):\n return (x*(x+1)//2)*(y*(y+1)//2)*(z*(z+1)//2)", "def subcuboids(x,y,z):\n return (x + 1) * (y + 1) * (z + 1) * x * y * z //... | {"fn_name": "subcuboids", "inputs": [[1, 1, 1], [2, 2, 2], [2, 3, 3], [4, 5, 6], [3, 7, 11]], "outputs": [[1], [27], [108], [3150], [11088]]} | introductory | https://www.codewars.com/kata/5b9e29dc1d5ed219910000a7 |
def subcuboids(x,y,z):
|
2,960 | In this kata you need to create a function that takes a 2D array/list of non-negative integer pairs and returns the sum of all the "saving" that you can have getting the [LCM](https://en.wikipedia.org/wiki/Least_common_multiple) of each couple of number compared to their simple product.
For example, if you are given:
... | ["from fractions import gcd\n\ndef sum_differences_between_products_and_LCMs(pairs):\n return sum(a*b - a*b//gcd(a,b) for a, b in pairs if a and b)", "from fractions import gcd\n\ndef lcm(x, y):\n return x * y / gcd(x, y) if gcd(x, y) else 0\n \ndef sum_differences_between_products_and_LCMs(pairs):\n return... | {"fn_name": "sum_differences_between_products_and_LCMs", "inputs": [[[[15, 18], [4, 5], [12, 60]]], [[[1, 1], [0, 0], [13, 91]]], [[[15, 7], [4, 5], [19, 60]]], [[[20, 50], [10, 10], [50, 20]]], [[]]], "outputs": [[840], [1092], [0], [1890], [0]]} | introductory | https://www.codewars.com/kata/56e56756404bb1c950000992 |
def sum_differences_between_products_and_LCMs(pairs):
|
2,982 | Here you will create the classic [Pascal's triangle](https://en.wikipedia.org/wiki/Pascal%27s_triangle).
Your function will be passed the depth of the triangle and you code has to return the corresponding pascal triangle up to that depth.
The triangle should be returned as a nested array.
for example:
```python
pasca... | ["def pascal(p):\n triangle = [[1]]\n for _ in range(p - 1):\n to_sum = list(zip([0] + triangle[-1], triangle[-1] + [0]))\n triangle.append(list(map(sum, to_sum)))\n return triangle\n", "def pascal(p):\n def create_row(n):\n row = [1]\n for k in range(n):\n row.append(... | {"fn_name": "pascal", "inputs": [[1], [5], [10]], "outputs": [[[[1]]], [[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]], [[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1], [1, 6, 15, 20, 15, 6, 1], [1, 7, 21, 35, 35, 21, 7, 1], [1, 8, 28, 56, 70, 56, 28, 8, 1], [1, 9, 36, 84, 126, 1... | introductory | https://www.codewars.com/kata/52945ce49bb38560fe0001d9 |
def pascal(p):
|
2,985 | ## **Task**
Four mirrors are placed in a way that they form a rectangle with corners at coordinates `(0, 0)`, `(max_x, 0)`, `(0, max_y)`, and `(max_x, max_y)`. A light ray enters this rectangle through a hole at the position `(0, 0)` and moves at an angle of 45 degrees relative to the axes. Each time it hits one of th... | ["def reflections(n, m):\n x = y = 0\n dx = dy = 1\n while 1:\n x += dx\n y += dy\n if x == y == 0 or x == n and y == m: return 1\n if 0 in (x, y) and (x == n or y == m): return 0\n if x in (0, n): dx *= -1\n if y in (0, m): dy *= -1", "from math import gcd\n\ndef refl... | {"fn_name": "reflections", "inputs": [[10, 10], [10, 20], [12, 23], [5, 25]], "outputs": [[true], [false], [false], [true]]} | introductory | https://www.codewars.com/kata/5eaf88f92b679f001423cc66 |
def reflections(max_x, max_y):
|
2,989 | The odd and even numbers are fighting against each other!
You are given a list of positive integers. The odd numbers from the list will fight using their `1` bits from their binary representation, while the even numbers will fight using their `0` bits. If present in the list, number `0` will be neutral, hence not figh... | ["def bits_battle(nums):\n binary = '{:b}'.format\n evens = odds = 0\n for num in nums:\n if num % 2:\n odds += binary(num).count('1')\n else:\n evens += binary(num).count('0')\n if odds == evens:\n return 'tie'\n return '{} win'.format('odds' if odds > evens el... | {"fn_name": "bits_battle", "inputs": [[[5, 3, 14]], [[3, 8, 22, 15, 78]], [[]], [[1, 13, 16]]], "outputs": [["odds win"], ["evens win"], ["tie"], ["tie"]]} | introductory | https://www.codewars.com/kata/58856a06760b85c4e6000055 |
def bits_battle(numbers):
|
2,990 | The Monty Hall problem is a probability puzzle base on the American TV show "Let's Make A Deal".
In this show, you would be presented with 3 doors: One with a prize behind it, and two without (represented with goats).
After choosing a door, the host would open one of the other two doors which didn't include a prize, ... | ["def monty_hall(door, guesses):\n return round(100.0 * (len(guesses)-guesses.count(door))/len(guesses))", "def monty_hall(c, p):\n print((c, p))\n return round((1 - (p.count(c) / len(p))) * 100)\n # Your code here!\n", "def monty_hall(correct, guesses):\n return round(sum([correct != x for x in guesses]... | {"fn_name": "monty_hall", "inputs": [[1, [1, 2, 2, 2, 3, 2, 1, 3, 1, 3]], [2, [2, 1, 2, 1, 2, 3, 1, 1, 2, 2, 3]], [3, [1, 1, 1, 2, 2, 3, 2, 2, 1, 3, 3, 2, 3, 1, 1, 2]]], "outputs": [[70], [55], [75]]} | introductory | https://www.codewars.com/kata/54f9cba3c417224c63000872 |
def monty_hall(correct_door_number, participant_guesses):
|
2,993 | ## Nova polynomial add
This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8807940ff3001140 ) [#4](http://www.codewars.com/kata/571a2e2df24bdfd4e20001f5) )
... | ["# return the sum of the two polynomials p1 and p2. \ndef poly_add(p1,p2):\n if p1 == []:\n return p2\n if p2 == []:\n return p1\n return [p1[0] + p2[0]] + poly_add(p1[1:], p2[1:])\n", "from itertools import zip_longest\ndef poly_add(p1, p2):\n return [x+y for x, y in zip_longest(p1, p2, fil... | {"fn_name": "poly_add", "inputs": [[[1], [1]], [[1, 2], [1]], [[1, 2, 3, 4], [4, 3, 2, 1]], [[], []], [[1, 2, 3, 4, 5, 6], []], [[], [1, 2, 3, 4, 5, 6]]], "outputs": [[[2]], [[2, 2]], [[5, 5, 5, 5]], [[]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4, 5, 6]]]} | introductory | https://www.codewars.com/kata/570ac43a1618ef634000087f |
def poly_add(p1, p2):
|
3,000 | ## Task
Let's say we have a positive integer, `$n$`. You have to find the smallest possible positive integer that when multiplied by `$n$`, becomes a perfect power of integer `$k$`. A perfect power of `$k$` is any positive integer that can be represented as `$a^k$`. For example if `$k = 2$`, then `$36$` is a perfect p... | ["from collections import Counter\nfrom math import ceil\n\nPRIMES = [2] + [n for n in range(3, 1000, 2) if all(n%d for d in range(3, int(n**0.5) +1, 2))]\n\ndef get_factors(n):\n factors = []\n for p in PRIMES:\n if p > n: break\n while n % p == 0:\n factors.append(p)\n n //= ... | {"fn_name": "mul_power", "inputs": [[100, 3], [36, 2], [72, 4], [5, 2], [1152, 3]], "outputs": [[10], [1], [18], [5], [12]]} | introductory | https://www.codewars.com/kata/5ee98cf315741d00104499e5 |
def mul_power(n, k):
|
3,009 | In this Kata your task will be to return the count of pairs that have consecutive numbers as follows:
```Haskell
pairs([1,2,5,8,-4,-3,7,6,5]) = 3
The pairs are selected as follows [(1,2),(5,8),(-4,-3),(7,6),5]
--the first pair is (1,2) and the numbers in the pair are consecutive; Count = 1
--the second pair is (5,8) an... | ["def pairs(ar):\n count = 0\n for i in range(0, len(ar), 2):\n try:\n a, b = ar[i], ar[i+1]\n except IndexError:\n return count\n \n if abs(a-b) == 1: \n count +=1\n \n return count", "def pairs(arr):\n return sum( abs(a-b)==1 for a,b in z... | {"fn_name": "pairs", "inputs": [[[1, 2, 5, 8, -4, -3, 7, 6, 5]], [[21, 20, 22, 40, 39, -56, 30, -55, 95, 94]], [[81, 44, 80, 26, 12, 27, -34, 37, -35]], [[-55, -56, -7, -6, 56, 55, 63, 62]], [[73, 72, 8, 9, 73, 72]]], "outputs": [[3], [2], [0], [4], [3]]} | introductory | https://www.codewars.com/kata/5a3e1319b6486ac96f000049 |
def pairs(ar):
|
3,021 | The queen can be moved any number of unoccupied squares in a straight line vertically, horizontally, or diagonally, thus combining the moves of the rook and bishop. The queen captures by occupying the square on which an enemy piece sits. (wikipedia: https://en.wikipedia.org/wiki/Queen_(chess)).
## Task:
Write a functi... | ["from itertools import product\n\nBOARD = set(map(\"\".join,product(\"ABCDEFGH\", \"12345678\")))\n\ndef available_moves(position):\n if isinstance(position, str) and position in BOARD :\n\n return sorted(p for p in BOARD-{position} \n if abs(ord(p[0])-ord(position[0])) == abs(int(p[1])... | {"fn_name": "available_moves", "inputs": [[7]], "outputs": [[[]]]}
| introductory | https://www.codewars.com/kata/5aa1031a7c7a532be30000e5 |
def available_moves(position):
|
3,026 | # Task
**_Given_** a **_list of digits_**, *return the **_smallest number_** that could be formed from these digits, using the digits only once (ignore duplicates).*
___
# Notes:
* Only **_positive integers_** *will be passed to the function (> 0 ), no negatives or zeros.*
___
# Input >> Output Examples
```
minVa... | ["def min_value(digits):\n return int(\"\".join(map(str,sorted(set(digits)))))\n", "def min_value(digits):\n return int(\"\".join(str(x) for x in sorted(set(digits))))", "def min_value(digits):\n l = list(set(digits))\n l.sort(reverse=True)\n return sum(x * 10**i for i, x in enumerate(l))", "def min_val... | {"fn_name": "min_value", "inputs": [[[1, 3, 1]], [[4, 7, 5, 7]], [[4, 8, 1, 4]], [[5, 7, 9, 5, 7]], [[6, 7, 8, 7, 6, 6]], [[5, 6, 9, 9, 7, 6, 4]], [[1, 9, 1, 3, 7, 4, 6, 6, 7]], [[3, 6, 5, 5, 9, 8, 7, 6, 3, 5, 9]]], "outputs": [[13], [457], [148], [579], [678], [45679], [134679], [356789]]} | introductory | https://www.codewars.com/kata/5ac6932b2f317b96980000ca |
def min_value(digits):
|
3,029 | > In information theory and computer science, the Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (i.e. insertions, deletions or substitutions) required to change one word i... | ["def levenshtein(a,b):\n d = [[0] * (len(b) + 1) for _ in range(len(a) + 1)]\n\n d[0][:] = list(range(len(b)+1))\n for i in range(1, len(a) + 1):\n d[i][0] = i\n\n for i, x in enumerate(a):\n for j, y in enumerate(b):\n d[i+1][j+1] = min(1 + d[i][j+1], 1 + d[i+1][j], d[i][j] + (1 i... | {"fn_name": "levenshtein", "inputs": [["kitten", "sitting"], ["book", "back"], ["book", "book"], ["qlzcfayxiz", "vezkvgejzb"], ["nayvyedosf", "sjxen"], ["sjxen", "sjxen"], ["peter", "peter"]], "outputs": [[3], [2], [0], [9], [9], [0], [0]]} | introductory | https://www.codewars.com/kata/545cdb4f61778e52810003a2 |
def levenshtein(a,b):
|
3,033 | Task
=======
Make a custom esolang interpreter for the language Tick. Tick is a descendant of [Ticker](https://www.codewars.com/kata/esolang-ticker) but also very different data and command-wise.
Syntax/Info
========
Commands are given in character format. Non-command characters should be ignored. Tick has an potent... | ["def interpreter(tape):\n memory, ptr, output = {}, 0, \"\"\n \n for command in tape:\n if command == \">\": ptr += 1\n elif command == \"<\": ptr -= 1\n elif command == \"+\": memory[ptr] = (memory.get(ptr, 0) + 1) % 256\n elif command == \"*\": output += chr(memory[ptr])\n ... | {"fn_name": "interpreter", "inputs": [["++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++... | introductory | https://www.codewars.com/kata/587edac2bdf76ea23500011a |
def interpreter(tape):
|
3,034 | # Task
Your task is to write a function for calculating the score of a 10 pin bowling game. The input for the function is a list of pins knocked down per roll for one player. Output is the player's total score.
# Rules
## General rules
Rules of bowling in a nutshell:
* A game consists of 10 frames. In each frame th... | ["def bowling_score(rolls):\n \"Compute the total score for a player's game of bowling.\"\n \n def is_spare(rolls):\n return 10 == sum(rolls[:2])\n\n def is_strike(rolls):\n return 10 == rolls[0]\n\n def calc_score(rolls, frame):\n return (sum(rolls) if frame == 10 else\n sum(rolls[:3]) + calc_... | {"fn_name": "bowling_score", "inputs": [[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]], [[9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9]], [[10, 10, 10, 10, 10,... | introductory | https://www.codewars.com/kata/5427db696f30afd74b0006a3 |
def bowling_score(rolls):
|
3,039 | *This kata is inspired by [Project Euler Problem #387](https://projecteuler.net/problem=387)*
---
A [Harshad number](https://en.wikipedia.org/wiki/Harshad_number) (or Niven number) is a number that is divisible by the sum of its digits. A *right truncatable Harshad number* is any Harshad number that, when recursively... | ["def gen(n):\n if n >= 10**16: return\n for i in range(10):\n x = 10*n + i\n if x % sum(map(int, str(x))): continue\n yield x\n for y in gen(x): yield y\nL = sorted(x for n in range(1, 10) for x in gen(n))\n\nfrom bisect import bisect_left as bl, bisect_right as br\ndef rthn_between(a... | {"fn_name": "rthn_between", "inputs": [[0, 20], [30, 100], [90, 200], [200, 210], [1000, 2000], [2200, 2300], [9000002182976, 9000195371842]], "outputs": [[[10, 12, 18, 20]], [[30, 36, 40, 42, 45, 48, 50, 54, 60, 63, 70, 72, 80, 81, 84, 90, 100]], [[90, 100, 102, 108, 120, 126, 180, 200]], [[200, 201, 204, 207, 209, 21... | introductory | https://www.codewars.com/kata/5c824b7b9775761ada934500 |
def rthn_between(a, b):
|
3,042 | Calculate the trace of a square matrix. A square matrix has `n` rows and `n` columns, where `n` is any integer > 0. The entries of the matrix can contain any number of integers. The function should return the calculated trace of the matrix, or `nil/None` if the array is empty or not square; you can otherwise assume the... | ["def trace(matrix):\n if not matrix or len(matrix) != len(matrix[0]):\n return None\n return sum(matrix[i][i] for i in range(len(matrix)))", "def trace(matrix):\n if matrix and set(map(len,matrix))=={len(matrix)}:\n return sum(matrix[x][x] for x in range(len(matrix)))", "trace=lambda m: sum(m[i]... | {"fn_name": "trace", "inputs": [[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[0, 0], [0, 0]]], [[[0, 0, 0], [0, 0, 0], [0, 0, 0]]], [[[1, 0, 0], [0, 1, 0], [0, 0, -2]]], [[[0]]], [[[1]]], [[[-300]]], [[]], [[[]]], [[[1, 2], [1, 2], [1, 2]]], [[[1, 2, 3], [1, 2, 3]]]], "outputs": [[15], [0], [0], [0], [0], [1], [-300], [null]... | introductory | https://www.codewars.com/kata/55208f16ecb433c5c90001d2 |
def trace(matrix):
|
3,046 | Given a positive integer `n`, return first n dgits of Thue-Morse sequence, as a string (see examples).
Thue-Morse sequence is a binary sequence with 0 as the first element. The rest of the sequece is obtained by adding the Boolean (binary) complement of a group obtained so far.
```
For example:
0
01
0110
01101001
an... | ["thue_morse=lambda n: \"0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100110010110100101100110100110010110011010010110100110010110011010011001011010010110011010010110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110100... | {"fn_name": "thue_morse", "inputs": [[1], [2], [5], [10], [100]], "outputs": [["0"], ["01"], ["01101"], ["0110100110"], ["0110100110010110100101100110100110010110011010010110100110010110100101100110100101101001100101100110"]]} | introductory | https://www.codewars.com/kata/591aa1752afcb02fa300002a |
def thue_morse(n):
|
3,050 | Write a function called `LCS` that accepts two sequences and returns the longest subsequence common to the passed in sequences.
### Subsequence
A subsequence is different from a substring. The terms of a subsequence need not be consecutive terms of the original sequence.
### Example subsequence
Subsequences of `"abc"... | ["def lcs(x, y):\n if len(x) == 0 or len(y) == 0:\n return ''\n if x[-1] == y[-1]:\n return lcs(x[:-1], y[:-1]) + x[-1]\n else:\n lcs1 = lcs(x,y[:-1])\n lcs2 = lcs(x[:-1],y)\n if len(lcs1) > len(lcs2):\n return lcs1\n else:\n return lcs2\n", "from... | {"fn_name": "lcs", "inputs": [["a", "b"], ["a", "a"], ["abc", "ac"], ["abcdef", "abc"], ["abcdef", "acf"], ["anothertest", "notatest"], ["132535365", "123456789"], ["finaltest", "zzzfinallyzzz"]], "outputs": [[""], ["a"], ["ac"], ["abc"], ["acf"], ["nottest"], ["12356"], ["final"]]} | introductory | https://www.codewars.com/kata/52756e5ad454534f220001ef |
def lcs(x, y):
|
3,051 | The idea for this Kata came from 9gag today.[here](http://9gag.com/gag/amrb4r9)
[screen]:("http://img-9gag-fun.9cache.com/photo/amrb4r9_700b.jpg")
You'll have to translate a string to Pilot's alphabet (NATO phonetic alphabet) [wiki](https://en.wikipedia.org/wiki/NATO_phonetic_alphabet).
Like this:
**Input:**
`If, ... | ["import string\n\ndb = { 'A':'Alfa','B':'Bravo','C':'Charlie','D':'Delta','E':'Echo',\n 'F':'Foxtrot','G':'Golf','H':'Hotel','I':'India','J':'Juliett',\n 'K':'Kilo','L':'Lima','M':'Mike','N':'November','O':'Oscar',\n 'P':'Papa','Q':'Quebec','R':'Romeo','S':'Sierra','T':'Tango',\n 'U':'Uniform',... | {"fn_name": "to_nato", "inputs": [["If you can read"], ["Did not see that coming"]], "outputs": [["India Foxtrot Yankee Oscar Uniform Charlie Alfa November Romeo Echo Alfa Delta"], ["Delta India Delta November Oscar Tango Sierra Echo Echo Tango Hotel Alfa Tango Charlie Oscar Mike India November Golf"]]} | introductory | https://www.codewars.com/kata/586538146b56991861000293 |
def to_nato(words):
|
3,054 | A [sequence or a series](http://world.mathigon.org/Sequences), in mathematics, is a string of objects, like numbers, that follow a particular pattern. The individual elements in a sequence are called terms. A simple example is `3, 6, 9, 12, 15, 18, 21, ...`, where the pattern is: _"add 3 to the previous term"_.
In thi... | ["def sum_of_n(n):\n return [(-1 if n < 0 else 1) * sum(range(i+1)) for i in range(abs(n)+1)]\n", "def sum_of_n(n):\n output = [0]\n sign = 1\n if n < 0: sign = -1\n for numb in range(1, abs(n) + 1):\n output.append(sign * (numb + abs(output[numb - 1])))\n return output", "def sum_of_n(n):\n ... | {"fn_name": "sum_of_n", "inputs": [[3], [-4], [1], [0], [10]], "outputs": [[[0, 1, 3, 6]], [[0, -1, -3, -6, -10]], [[0, 1]], [[0]], [[0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55]]]} | introductory | https://www.codewars.com/kata/5436f26c4e3d6c40e5000282 |
def sum_of_n(n):
|
3,058 | In recreational mathematics, a magic square is an arrangement of distinct numbers (i.e., each number is used once), usually integers, in a square grid, where the numbers in each row, and in each column, and the numbers in the main and secondary diagonals, all add up to the same number, called the "magic constant."
For... | ["def is_magical(sq):\n return sum(sq[2:7:2])==sum(sq[::4])==sum(sq[::3])==sum(sq[1::3])==sum(sq[2::3])==sum(sq[:3])==sum(sq[3:6])==sum(sq[6:])", "def is_magical(sq):\n return len(set( [sum(sq[i*3:(i+1)*3]) for i in range(3)] # lines\n + [sum(sq[i::3]) for i in range(3)] ... | {"fn_name": "is_magical", "inputs": [[[4, 9, 2, 3, 5, 7, 8, 1, 6]], [[4, 9, 2, 3, 5, 7, 8, 6, 1]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[9, 4, 7, 3, 5, 2, 8, 6, 1]], [[8, 1, 6, 3, 5, 7, 4, 9, 2]]], "outputs": [[true], [false], [false], [false], [true]]} | introductory | https://www.codewars.com/kata/57be6a612eaf7cc3af000178 |
def is_magical(sq):
|
3,072 | Well, those numbers were right and we're going to feed their ego.
Write a function, isNarcissistic, that takes in any amount of numbers and returns true if all the numbers are narcissistic. Return false for invalid arguments (numbers passed in as strings are ok).
For more information about narcissistic numbers (and b... | ["def get_digits(n):\n return [int(x) for x in list(str(n))]\n\n\ndef is_narc(n):\n return n == sum([x**len(get_digits(n)) for x in get_digits(n)])\n\n\ndef is_narcissistic(*values):\n try:\n return all(type(n) in [int,str] and is_narc(int(n)) for n in values)\n except ValueError:\n return Fal... | {"fn_name": "is_narcissistic", "inputs": [[11], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 22, 9], ["4"], ["4", 7, "9"], ["words"], [[1, 2]], [407, 8208], [-1], [""], ["", 407], [407, ""], [5, "", 407], [9474], [{}]], "outputs": [[false], [true], [false], [true], [true], [false], [false], [true], [false],... | introductory | https://www.codewars.com/kata/565225029bcf176687000022 |
def is_narcissistic(*args):
|
3,076 | In this Kata, you will be given directions and your task will be to find your way back.
```Perl
solve(["Begin on Road A","Right on Road B","Right on Road C","Left on Road D"]) = ['Begin on Road D', 'Right on Road C', 'Left on Road B', 'Left on Road A']
solve(['Begin on Lua Pkwy', 'Right on Sixth Alley', 'Right on 1st ... | ["DIRS = {'Left': 'Right', 'Right': 'Left'}\n\ndef solve(arr):\n lst,prevDir = [], 'Begin'\n for cmd in arr[::-1]:\n d, r = cmd.split(' on ')\n follow = DIRS.get(prevDir, prevDir)\n prevDir = d\n lst.append(f'{follow} on {r}')\n return lst", "def solve(arr):\n go_moves, go_pl... | {"fn_name": "solve", "inputs": [[["Begin on 3rd Blvd", "Right on First Road", "Left on 9th Dr"]], [["Begin on Road A", "Right on Road B", "Right on Road C", "Left on Road D"]], [["Begin on Road A"]]], "outputs": [[["Begin on 9th Dr", "Right on First Road", "Left on 3rd Blvd"]], [["Begin on Road D", "Right on Road C", "... | introductory | https://www.codewars.com/kata/5b94d7eb1d5ed297680000ca |
def solve(arr):
|
3,081 | Following on from [Part 1](http://www.codewars.com/kata/filling-an-array-part-1/), part 2 looks at some more complicated array contents.
So let's try filling an array with...
## ...square numbers
The numbers from `1` to `n*n`
## ...a range of numbers
A range of numbers starting from `start` and increasing by `step`
... | ["import random\ndef squares(n):\n return [i**2 for i in range(1, n+1)]\n\ndef num_range(n, start, step):\n return [i for i in range(start, start+step*n, step)]\n\ndef rand_range(n, mn, mx):\n return [random.randint(mn, mx) for i in range(n)]\ndef primes(n):\n return [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31,... | {"fn_name": "squares", "inputs": [[5]], "outputs": [[[1, 4, 9, 16, 25]]]} | introductory | https://www.codewars.com/kata/571e9af407363dbf5700067c |
def squares(n):
|
3,083 | Most of this problem is by the original author of [the harder kata](https://www.codewars.com/kata/556206664efbe6376700005c), I just made it simpler.
I read a book recently, titled "Things to Make and Do in the Fourth Dimension" by comedian and mathematician Matt Parker ( [Youtube](https://www.youtube.com/user/standupm... | ["def polydivisible(x):\n for i in range(1, len(str(x)) + 1):\n if int(str(x)[:i]) % i != 0:\n return False\n return True", "def polydivisible(x):\n s = str(x)\n return all(int(s[:i]) % i == 0 for i in range(1, len(s) + 1))", "def polydivisible(x):\n return all(int(str(x)[:i+1])%(i+1)==... | {"fn_name": "polydivisible", "inputs": [[1232], [123220], [0], [1], [141], [1234], [21234], [81352], [987654], [1020005], [9876545], [381654729], [1073741823]], "outputs": [[true], [false], [true], [true], [true], [false], [false], [false], [true], [true], [true], [true], [false]]} | introductory | https://www.codewars.com/kata/5e4217e476126b000170489b |
def polydivisible(x):
|
3,085 | The AKS algorithm for testing whether a number is prime is a polynomial-time test based on the following theorem:
A number p is prime if and only if all the coefficients of the polynomial expansion of `(x − 1)^p − (x^p − 1)` are divisible by `p`.
For example, trying `p = 3`:
(x − 1)^3 − (x^3 − 1) = (x^3 − 3x^2... | ["def aks_test(p):\n lst = []\n for i in range(2, p+1):\n for j in lst:\n if i % j == 0:\n break\n else:\n lst.append(i)\n if p in lst:\n return True\n else:\n return False", "import math\ndef aks_test(p):\n center = (math.factorial(p//2)*m... | {"fn_name": "aks_test", "inputs": [[3], [4], [5], [7], [10], [33], [101], [1], [2], [11213], [8191], [8192]], "outputs": [[true], [false], [true], [true], [false], [false], [true], [false], [true], [true], [true], [false]]} | introductory | https://www.codewars.com/kata/5416d02d932c1df3a3000492 |
def aks_test(p):
|
3,087 | You will be given a string and you task is to check if it is possible to convert that string into a palindrome by removing a single character. If the string is already a palindrome, return `"OK"`. If it is not, and we can convert it to a palindrome by removing one character, then return `"remove one"`, otherwise return... | ["def solve(s):\n isOK = lambda x: x == x[::-1]\n \n return (\"OK\" if isOK(s) else\n \"remove one\" if any( isOK(s[:i]+s[i+1:]) for i in range(len(s)) ) else\n \"not possible\")", "def solve(s):\n if s == s[::-1]:\n return 'OK'\n for i in range(len(s)):\n if s[:i] + ... | {"fn_name": "solve", "inputs": [["abba"], ["abbaa"], ["abbaab"], ["madmam"], ["raydarm"], ["hannah"], ["baba"], ["babab"], ["bababa"], ["abcbad"], ["abcdba"], ["dabcba"], ["abededba"], ["abdcdeba"], ["abcdedba"], ["abbcdedba"]], "outputs": [["OK"], ["remove one"], ["not possible"], ["remove one"], ["not possible"], ["O... | introductory | https://www.codewars.com/kata/5a2c22271f7f709eaa0005d3 |
def solve(s):
|
3,096 | This problem takes its name by arguably the most important event in the life of the ancient historian Josephus: according to his tale, he and his 40 soldiers were trapped in a cave by the Romans during a siege.
Refusing to surrender to the enemy, they instead opted for mass suicide, with a twist: **they formed a circl... | ["def josephus(xs, k):\n i, ys = 0, []\n while len(xs) > 0:\n i = (i + k - 1) % len(xs)\n ys.append(xs.pop(i))\n return ys", "def josephus(n,k):\n i, ans = 0, []\n while n: i = (i + k - 1) % len(n); ans.append(n.pop(i))\n return ans", "from collections import deque\n\ndef josephus(items,... | {"fn_name": "josephus", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2], [["C", "o", "d", "e", "W", "a", "r", "s"], 4], [["C", 0, "d", 3, "W", 4, "r", 5], 4], [[1, 2, 3, 4, 5, 6, 7], 3], [[], 3], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 2... | introductory | https://www.codewars.com/kata/5550d638a99ddb113e0000a2 |
def josephus(items,k):
|
3,099 | Based on [this kata, Connect Four.](https://www.codewars.com/kata/connect-four-1)
In this kata we play a modified game of connect four. It's connect X, and there can be multiple players.
Write the function ```whoIsWinner(moves,connect,size)```.
```2 <= connect <= 10```
```2 <= size <= 52```
Each column is identifi... | ["from itertools import compress\nfrom string import ascii_uppercase, ascii_lowercase\nD = {c:i for i,c in enumerate(ascii_uppercase + ascii_lowercase)}\n\ndef whoIsWinner(moves, con, sz):\n def gen(i, j):\n for x in range(1, con):\n yield ((i, j-x), (i-x, j), (i+x, j), (i-x, j-x), (i+x, j+x), (i+x... | {"fn_name": "whoIsWinner", "inputs": [[["A_R", "B_Y", "A_R"], 2, 2], [["B_R", "A_Y", "A_R", "D_Y", "B_R", "D_Y", "B_R", "D_Y", "C_R", "D_Y"], 4, 4], [["A_R", "C_Y", "C_R", "B_Y", "A_R", "C_Y", "B_R", "B_Y", "D_R", "A_Y", "D_R", "A_Y"], 2, 4], [["H_R", "A_Y", "A_R", "C_Y", "H_R", "E_Y", "G_R", "C_Y", "D_R", "F_Y", "E_R"... | introductory | https://www.codewars.com/kata/5b442a063da310049b000047 |
def whoIsWinner(moves, con, sz):
|
3,100 | >When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
# Description:
Given two array of integers(`arr1`,`arr2`). Your task is going to find a pair of numbers(an element in arr1, and another element in arr2), their difference... | ["def max_and_min(arr1,arr2):\n diffs = [abs(x-y) for x in arr1 for y in arr2]\n return [max(diffs), min(diffs)]\n", "def max_and_min(arr1,arr2):\n max_min = [abs(y-x) for x in arr1 for y in arr2]\n \n return [max(max_min), min(max_min)]", "def max_and_min(arr1, arr2):\n return [op(a... | {"fn_name": "max_and_min", "inputs": [[[3, 10, 5], [20, 7, 15, 8]], [[3], [20]], [[3, 10, 5], [3, 10, 5]], [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]], "outputs": [[[17, 2]], [[17, 17]], [[7, 0]], [[9, 1]]]} | introductory | https://www.codewars.com/kata/583c5469977933319f000403 |
def max_and_min(arr1,arr2):
|
3,107 | Program the function distance(p1, p2) which returns the distance between the points p1 and p2 in n-dimensional space. p1 and p2 will be given as arrays.
Your program should work for all lengths of arrays, and should return -1 if the arrays aren't of the same length or if both arrays are empty sets.
If you don't know ... | ["def distance(p1, p2):\n return sum((a - b) ** 2 for a, b in zip(p1, p2)) ** 0.5 if len(p1) == len(p2) > 0 else -1", "def distance(p1, p2):\n from functools import reduce\n from math import hypot\n if not p1 or len(p1) != len(p2): return -1\n return reduce(hypot, (x-y for x,y in zip(p1, p2)))", "def dis... | {"fn_name": "distance", "inputs": [[[], []], [[1], [1, 1, 1, 1, 1, 1, 1, 1, 1]]], "outputs": [[-1], [-1]]} | introductory | https://www.codewars.com/kata/5a0b72484bebaefe60001867 |
def distance(p1, p2):
|
3,109 | Background
There is a message that is circulating via public media that claims a reader can easily read a message where the inner letters of each words is scrambled, as long as the first and last letters remain the same and the word contains all the letters.
Another example shows that it is quite difficult to read the... | ["import re\n\ndef scramble_words(words):\n def sort_letters(match):\n s = match.group()\n letters = iter(sorted(filter(str.isalpha, s[1:-1])))\n return s[0] + \"\".join(next(letters) if c.isalpha() else c for c in s[1:-1]) + s[-1]\n return re.sub(r'[a-z][^\\s]*[a-z]', sort_letters, words)", ... | {"fn_name": "scramble_words", "inputs": [["professionals"], ["i"], [""], ["me"], ["you"], ["card-carrying"], ["shan't"], ["-dcba"], ["dcba."], ["you've gotta dance like there's nobody watching, love like you'll never be hurt, sing like there's nobody listening, and live like it's heaven on earth."]], "outputs": [["paef... | introductory | https://www.codewars.com/kata/55953e906851cf2441000032 |
def scramble_words(words):
|
3,117 | The vowel substrings in the word `codewarriors` are `o,e,a,io`. The longest of these has a length of 2. Given a lowercase string that has alphabetic characters only (both vowels and consonants) and no spaces, return the length of the longest vowel substring.
Vowels are any of `aeiou`.
```if:csharp
Documentation:
Kat... | ["def solve(s):\n return max(map(len, ''.join(c if c in 'aeiou' else ' ' for c in s).split()))", "import re\n\ndef solve(s):\n return max(len(x.group(0)) for x in re.finditer(r'[aeiou]+', s))", "from re import findall\n\ndef solve(s):\n return max(map(len, findall(\"[aeiou]+\", s)))", "def solve(s):\n vowel... | {"fn_name": "solve", "inputs": [["codewarriors"], ["suoidea"], ["ultrarevolutionariees"], ["strengthlessnesses"], ["cuboideonavicuare"], ["chrononhotonthuooaos"], ["iiihoovaeaaaoougjyaw"]], "outputs": [[2], [3], [3], [1], [2], [5], [8]]} | introductory | https://www.codewars.com/kata/59c5f4e9d751df43cf000035 |
def solve(s):
|
3,122 | # Task
Consider a `bishop`, a `knight` and a `rook` on an `n × m` chessboard. They are said to form a `triangle` if each piece attacks exactly one other piece and is attacked by exactly one piece.
Calculate the number of ways to choose positions of the pieces to form a triangle.
Note that the bishop attacks piec... | ["def chess_triangle(n, m):\n return sum( 8 * (n-x+1)*(m-y+1) for dims in {(3,4), (3,3), (2,4), (2,3)} for x,y in [dims, dims[::-1]] if x <= n and y <= m )\n", "def chess_triangle(n, m):\n if n>m:\n n,m=m,n\n if m<=2 or n<2:\n return 0\n elif n==2:\n return (m*2-5)*8\n else:\n ... | {"fn_name": "chess_triangle", "inputs": [[2, 3], [1, 30], [3, 3], [2, 2], [5, 2], [40, 40]], "outputs": [[8], [0], [48], [0], [40], [92400]]} | introductory | https://www.codewars.com/kata/5897eebff3d21495a70000df |
def chess_triangle(n, m):
|
3,130 | In this kata you need to build a function to return either `true/True` or `false/False` if a string can be seen as the repetition of a simpler/shorter subpattern or not.
For example:
```cpp,java
hasSubpattern("a") == false; //no repeated pattern
hasSubpattern("aaaa") == true; //created repeating "a"
hasSubpattern("ab... | ["def has_subpattern(string):\n return (string * 2).find(string, 1) != len(string)", "import re\n\ndef has_subpattern(string):\n return bool(re.match(r'(.+)\\1+$', string))", "def has_subpattern(string):\n s = len(string)\n for i in range(1,s//2+1):\n if s % i == 0:\n q = s//i\n ... | {"fn_name": "has_subpattern", "inputs": [["a"], ["aaaa"], ["abcd"], ["abababab"], ["ababababa"], ["123a123a123a"], ["123A123a123a"], ["abbaabbaabba"], ["abbabbabba"], ["abcdabcabcd"]], "outputs": [[false], [true], [false], [true], [false], [true], [false], [true], [false], [false]]} | introductory | https://www.codewars.com/kata/5a49f074b3bfa89b4c00002b |
def has_subpattern(string):
|
3,137 | From this lesson, we learn about JS static object: ```Math```. It mainly helps us to carry out mathematical calculations. It has a lot of properties and methods. Some of the properties and methods we rarely used. So we only learn some common methods.
The properties of the Math object are some constants, such as PI, on... | ["from math import ceil\n\ndef round_it(n):\n left, right = (len(part) for part in str(n).split(\".\"))\n return ceil(n) if left < right else int(n) if left > right else round(n)", "from math import floor, ceil\n\ndef round_it(n):\n l, r = [len(x) for x in str(n).split('.')]\n if r > l:\n return ceil... | {"fn_name": "round_it", "inputs": [[3.45], [34.5], [34.56]], "outputs": [[4], [34], [35]]} | introductory | https://www.codewars.com/kata/5732d3c9791aafb0e4001236 |
def round_it(n):
|
3,140 | Math geeks and computer nerds love to anthropomorphize numbers and assign emotions and personalities to them. Thus there is defined the concept of a "happy" number. A happy number is defined as an integer in which the following sequence ends with the number 1.
* Start with the number itself.
* Calculate the sum of the... | ["def is_happy(n):\n seen = set()\n while n not in seen:\n seen.add(n)\n n = sum( int(d)**2 for d in str(n) )\n return n == 1\n\n\ndef happy_numbers(n): \n return [x for x in range(1, n+1) if is_happy(x)]", "# Code reuse: https://www.codewars.com/kata/reviews/5ac53889cd661be6ee0013ff/groups... | {"fn_name": "happy_numbers", "inputs": [[10], [50], [100]], "outputs": [[[1, 7, 10]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100]]]} | introductory | https://www.codewars.com/kata/59d53c3039c23b404200007e |
def happy_numbers(n):
|
3,146 | Unicode Transformation Format – 8-bit
As the name suggests UTF-8 was designed to encode data in a stream of bytes.
It works by splitting the bits up in multiples of eight. This is achieved by inserting headers to mark in how many bytes the bits were split. If the bits need to be split in two, the header `110` is added... | ["from textwrap import wrap\n\ndef to_utf8_binary(string):\n return ''.join(format(x, 'b').rjust(8, '0') for x in bytearray(string, 'utf-8'))\n \ndef from_utf8_binary(bitstring):\n return bytearray([int(t, 2) for t in wrap(bitstring, 8)]).decode()\n", "def to_utf8_binary(string):\n return ''.join('{:08b}'.form... | {"fn_name": "to_utf8_binary", "inputs": [["\u0080"], ["\u07ff"], ["\u0800"], ["\uffff"]], "outputs": [["1100001010000000"], ["1101111110111111"], ["111000001010000010000000"], ["111011111011111110111111"]]} | introductory | https://www.codewars.com/kata/5f5fffc4f6b3390029a6b277 |
def to_utf8_binary(string):
|
3,147 | *This is the advanced version of the [Total Primes](https://www.codewars.com/kata/total-primes/) kata.*
---
The number `23` is the smallest prime that can be "cut" into **multiple** primes: `2, 3`. Another such prime is `6173`, which can be cut into `61, 73` or `617, 3` or `61, 7, 3` (all primes). A third one is `557... | ["import numpy as np\nfrom itertools import accumulate\ndef sieve_primes(n):\n sieve = np.ones(n // 2, dtype = np.bool)\n limit = 1 + int(n ** 0.5)\n\n for a in range(3, limit, 2):\n if sieve[a // 2]:\n sieve[a * a // 2::a] = False\n\n prime_indexes = 2 * np.nonzero(sieve)[0].astype(int) +... | {"fn_name": "total_primes", "inputs": [[10, 100], [500, 600], [23, 37], [0, 20], [113, 197], [199, 299], [1, 2273], [11703, 13330], [312232, 312311], [967335, 967871]], "outputs": [[[23, 37, 53, 73]], [[523, 541, 547, 557, 571, 577, 593]], [[23, 37]], [[]], [[113, 137, 173, 193, 197]], [[211, 223, 227, 229, 233, 241, 2... | introductory | https://www.codewars.com/kata/5d2351b313dba8000eecd5ee |
def total_primes(a, b):
|
3,152 | # Task:
This kata asks you to make a custom esolang interpreter for the language [MiniBitMove](https://esolangs.org/wiki/MiniBitMove). MiniBitMove has only two commands and operates on a array of bits. It works like this:
- `1`: Flip the bit at the current cell
- `0`: Move selector by 1
It takes two inputs, the progr... | ["from itertools import cycle\ndef interpreter(tape, array):\n idx, result = 0, list(map(int, array))\n for cmd in cycle(map(int, tape)):\n if idx == len(array): break\n if cmd: result[idx] = 1-result[idx]\n else: idx += 1\n return ''.join(map(str, result))", "def interpreter(tape, code): ... | {"fn_name": "interpreter", "inputs": [["10", "1100101"], ["100", "1111111111"], ["110", "1010"], ["0", "100010001"], ["101010", "111"]], "outputs": [["0011010"], ["0101010101"], ["1010"], ["100010001"], ["000"]]} | introductory | https://www.codewars.com/kata/587c0138110b20624e000253 |
def interpreter(tape, array):
|
3,163 | # Task
`Triangular numbers` are defined by the formula `n * (n + 1) / 2` with `n` starting from 1. They count the number of objects that can form an equilateral triangle as shown in the picture below:

So the sequence of triangular numbers begins as follows... | ["triangular_sum=lambda n: (-0.5+(1+8*n)**0.5/2.0)**0.5%1==0", "from math import sqrt\n\ndef triangular_sum(n):\n return sqrt(2 * (sqrt(8*n + 1) - 1)) % 2 == 0", "def triangular_sum(n):\n r = int((n*2)**0.5)\n return r * (r+1) / 2 == n and round(r**0.5)**2 == r", "triangular_sum = lambda n: ((((1+8*n)**0.5 - 1... | {"fn_name": "triangular_sum", "inputs": [[6], [28], [45], [105], [136], [190], [210], [5050], [300], [2080]], "outputs": [[false], [false], [true], [false], [true], [false], [false], [true], [false], [true]]} | introductory | https://www.codewars.com/kata/591404294ef3051cbe000035 |
def triangular_sum(n):
|
3,178 | Our friendly friend Pete is really a nice person, but he tends to be rather... Inappropriate.
And possibly loud, if given enough ethanol and free rein, so we ask you to write a function that should take its not always "clean" speech and cover as much as possible of it, in order not to offend some more sensible spirits... | ["import re\n\nPATTERN = re.compile(r'(?P<first>(?:(?<=[.!?] )|^)\\w+)|(?P<other>\\w+)')\n\ndef pete_talk(speech,ok=[]):\n\n def watchYourMouth(m):\n w = (m.group(\"first\") or m.group(\"other\")).lower()\n if w not in ok and len(w) > 1: w = w[0] + '*'*(len(w)-2) + w[-1]\n if m.group(\"first\"):... | {"fn_name": "pete_talk", "inputs": [["I want to punch someone in the face"], ["uh!"], ["What the hell am I doing here? And where is my wallet? PETE SMASH!"], ["I want to punch someone in the face", ["someone", "face"]], ["I want to punch someone in the face", ["drink", "job", "girls"]]], "outputs": [["I w**t to p***h s... | introductory | https://www.codewars.com/kata/571d0c80eed4a1c850000ef2 |
def pete_talk(speech, ok = []):
|
3,183 | Task
======
Make a custom esolang interpreter for the language [InfiniTick](https://esolangs.org/wiki/InfiniTick). InfiniTick is a descendant of [Tick](https://esolangs.org/wiki/tick) but also very different. Unlike Tick, InfiniTick has 8 commands instead of 4. It also runs infinitely, stopping the program only when a... | ["def interpreter(tape):\n memory, ptr, output, iCmd = {}, 0, \"\", 0\n \n while True:\n cmd = tape[iCmd]\n if cmd == \">\": ptr += 1\n elif cmd == \"<\": ptr -= 1\n elif cmd == \"+\": memory[ptr] = (memory.get(ptr, 0) + 1) % 256\n elif cmd == \"-\": memory[ptr] = (memo... | {"fn_name": "interpreter", "inputs": [["\\h*&"], ["+-*&"]], "outputs": [["\u0000"], ["\u0000"]]} | introductory | https://www.codewars.com/kata/58817056e7a31c2ceb000052 |
def interpreter(tape):
|
3,190 | Consider the number `1176` and its square (`1176 * 1176) = 1382976`. Notice that:
* the first two digits of `1176` form a prime.
* the first two digits of the square `1382976` also form a prime.
* the last two digits of `1176` and `1382976` are the same.
Given two numbers representing a range (`a, b`), how many numb... | ["ls = ['11', '13', '17', '19', '23', '29', '31', '37', '41', '43', '47', '53', '59', '61', '67', '71', '73', '79', '83', '89', '97']\ndef solve(a,b):\n i = a\n s = 0\n while i < b:\n if (i*i-i)%100==0 and str(i)[:2] in ls and str(i*i)[:2] in ls:\n s += 1\n i += 1\n return s", "from... | {"fn_name": "solve", "inputs": [[2, 1200], [1176, 1200], [2, 100000], [2, 1000000], [100000, 1000000]], "outputs": [[1], [1], [247], [2549], [2302]]} | introductory | https://www.codewars.com/kata/59a9466f589d2af4c50001d8 |
def solve(a,b):
|
3,191 | # Introduction
Digital Cypher assigns to each letter of the alphabet unique number. For example:
```
a b c d e f g h i j k l m
1 2 3 4 5 6 7 8 9 10 11 12 13
n o p q r s t u v w x y z
14 15 16 17 18 19 20 21 22 23 24 25 26
```
Instead of letters in encrypted word we write the corre... | ["from itertools import cycle\nfrom string import ascii_lowercase\n\ndef decode(code, key):\n keys = cycle(map(int, str(key)))\n return ''.join(ascii_lowercase[n - next(keys) - 1] for n in code)", "def decode(code, key):\n key=str(key)\n return \"\".join([chr(code[i] +96 - int(key[i%len(key)])) for i in r... | {"fn_name": "decode", "inputs": [[[20, 12, 18, 30, 21], 1939], [[14, 10, 22, 29, 6, 27, 19, 18, 6, 12, 8], 1939]], "outputs": [["scout"], ["masterpiece"]]} | introductory | https://www.codewars.com/kata/592edfda5be407b9640000b2 |
def decode(code, key):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.