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 |
|---|---|---|---|---|---|---|
4,022 | # A History Lesson
Soundex is an interesting phonetic algorithm developed nearly 100 years ago for indexing names as they are pronounced in English. The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling.
Reference: https://en.wikipedia.or... | ["import re\n\nREPLACMENTS = [\"BFPV\", \"CGJKQSXZ\", \"DT\",\"L\",\"MN\",\"R\"]\nER1, ER2 = \"HW\", \"AEIOUY\"\n\nTABLE_ERASE1 = str.maketrans(\"\", \"\", ER1)\nTABLE_NUMS = str.maketrans( ''.join(REPLACMENTS), ''.join( str(n)*len(elt) for n,elt in enumerate(REPLACMENTS, 1)) )\nTABLE_ERASE2 = str.maketrans(\"\"... | {"fn_name": "soundex", "inputs": [["Sarah Connor"], ["Sara Conar"], ["Serah Coner"], ["Sarh Connor"], ["Sayra Cunnarr"], ["Tim"], ["Joe"], ["Bob"], ["Robert"], ["Rupert"], ["Rubin"], ["Ashcraft"], ["Ashcroft"], ["Tymczak"], ["Pfister"], ["zxqurlwbx"], ["uryrtkzp"]], "outputs": [["S600 C560"], ["S600 C560"], ["S600 C560... | introductory | https://www.codewars.com/kata/587319230e9cf305bb000098 |
def soundex(name):
|
4,024 | # Definition
A number is a **_Special Number_** *if it’s digits only consist 0, 1, 2, 3, 4 or 5*
**_Given_** a number *determine if it special number or not* .
# Warm-up (Highly recommended)
# [Playing With Numbers Series](https://www.codewars.com/collections/playing-with-numbers)
___
# Notes
* **_The numbe... | ["def special_number(n):\n return \"Special!!\" if max(str(n)) <= \"5\" else \"NOT!!\"", "SPECIAL = set('012345')\n\ndef special_number(number):\n return \"Special!!\" if set(str(number)) <= SPECIAL else \"NOT!!\"", "def special_number(n):\n return [\"NOT!!\", \"Special!!\"][max(str(n)) < \"6\"]\n \n ret... | {"fn_name": "special_number", "inputs": [[2], [3], [5], [9], [7], [23], [79], [32], [39], [55], [11350224]], "outputs": [["Special!!"], ["Special!!"], ["Special!!"], ["NOT!!"], ["NOT!!"], ["Special!!"], ["NOT!!"], ["Special!!"], ["NOT!!"], ["Special!!"], ["Special!!"]]} | introductory | https://www.codewars.com/kata/5a55f04be6be383a50000187 |
def special_number(number):
|
4,030 | Implement a function which
creates a **[radix tree](https://en.wikipedia.org/wiki/Radix_tree)** (a space-optimized trie [prefix tree])
in which each node that is the only child is merged with its parent [unless a word from the input ends there])
from a given list of words
using dictionaries (aka hash maps or hash t... | ["from itertools import groupby\nfrom operator import itemgetter\nfrom os.path import commonprefix\n\nfirst = itemgetter(0)\n\ndef radix_tree(*words):\n words = [w for w in words if w]\n result = {}\n for key, grp in groupby(sorted(words), key=first):\n lst = list(grp)\n prefix = commonprefix(lst... | {"fn_name": "radix_tree", "inputs": [[""], ["abc", "def", "ghi", "jklm", "nop"], ["ape", "apple"], ["ape", "appendix", "apel"], ["ape", "apple", "applet", "appendix"], ["romane", "romanus", "romulus"], ["test", "tester", "testers"], ["test", "tester", "testers", "tester"], ["testers", "tester", "test"]], "outputs": [[{... | introductory | https://www.codewars.com/kata/5c9d62cbf1613a001af5b067 |
def radix_tree(*words):
|
4,031 | # Esolang Interpreters #2 - Custom Smallfuck Interpreter
## About this Kata Series
"Esolang Interpreters" is a Kata Series that originally began as three separate, independent esolang interpreter Kata authored by [@donaldsebleung](http://codewars.com/users/donaldsebleung) which all shared a similar format and were al... | ["def interpreter(code, tape):\n tape = list(map(int, tape))\n ptr = step = loop = 0\n \n while 0 <= ptr < len(tape) and step < len(code):\n command = code[step]\n \n if loop:\n if command == \"[\": loop += 1\n elif command == \"]\": loop -= 1\n \n ... | {"fn_name": "interpreter", "inputs": [["*", "00101100"], [">*>*", "00101100"], ["*>*>*>*>*>*>*>*", "00101100"], ["*>*>>*>>>*>*", "00101100"], [">>>>>*<*<<*", "00101100"], ["iwmlis *!BOSS 333 ^v$#@", "00101100"], [">*>*;;;.!.,+-++--!!-!!!-", "00101100"], [" * >* >*>*lskdfjsdklfj>*;;+--+--+++--+-+- lskjfio... | introductory | https://www.codewars.com/kata/58678d29dbca9a68d80000d7 |
def interpreter(code, tape):
|
4,038 | # Task
Given a position of a knight on the standard chessboard, find the number of different moves the knight can perform.
The knight can move to a square that is two squares horizontally and one square vertically, or two squares vertically and one square horizontally away from it. The complete move therefore looks ... | ["def chess_knight(cell):\n x, y = (ord(c) - ord(origin) for c, origin in zip(cell, 'a1'))\n return sum(0 <= x + dx < 8 and 0 <= y + dy < 8 for dx, dy in (\n (-2, -1), (-2, 1), (-1, -2), (-1, 2), (1, -2), (1, 2), (2, -1), (2, 1)))", "moves = {(-2, -1), (-2, 1), (-1, 2), (1, 2), (2, 1), (2, -1), (1, -2), (-... | {"fn_name": "chess_knight", "inputs": [["a1"], ["c2"], ["d4"], ["g6"]], "outputs": [[2], [6], [8], [6]]} | introductory | https://www.codewars.com/kata/589433358420bf25950000b6 |
def chess_knight(cell):
|
4,039 | # Fourier transformations are hard. Fouriest transformations are harder.
This Kata is based on the SMBC Comic on fourier transformations.
A fourier transformation on a number is one that converts the number to a base in which it has more `4`s ( `10` in base `6` is `14`, which has `1` four as opposed to none, hence, f... | ["def transform(num, base):\n digits = []\n \n while num > 0:\n num, remainder = divmod(num, base)\n digits.append( remainder if remainder < 10 else \"x\" )\n \n return digits\n\n\ndef fouriest(i):\n max_fours, base, best = 0, 5, [None, None]\n \n while i >= base**(max_fours):\n ... | {"fn_name": "fouriest", "inputs": [[30], [15], [9999], [35353], [100], [1000000243], [142042158218941532125212890], [2679388715912901287113185885289513476], [640614569414659959863091616350016384446719891887887380], [25791111079649870250475363614833123853740082482826554016752110339267820069204152249134948096885813148788... | introductory | https://www.codewars.com/kata/59e1254d0863c7808d0000ef |
def fouriest(i):
|
4,042 | You have the `radius` of a circle with the center in point `(0,0)`.
Write a function that calculates the number of points in the circle where `(x,y)` - the cartesian coordinates of the points - are `integers`.
Example: for `radius = 2` the result should be `13`.
`0 <= radius <= 1000`
:\n from math import sqrt\n point = sum(int(sqrt(R * R - x * x)) for x in range(0,R+1)) * 4 + 1\n return point", "from math import floor, sqrt\n\ndef points(n):\n # solution is \n # A000328 Number of points of norm <= n^2 in square lattice.\n # which can be calculated as \n # a... | {"fn_name": "points", "inputs": [[1], [2], [3], [5], [1000], [55], [33], [15], [42], [0], [99], [17]], "outputs": [[5], [13], [29], [81], [3141549], [9477], [3409], [709], [5525], [1], [30757], [901]]} | introductory | https://www.codewars.com/kata/5b55c49d4a317adff500015f |
def points(n):
|
4,047 | ```if-not:rust
Your task is to write a function `toLeetSpeak` that converts a regular english sentence to Leetspeak.
```
```if:rust
Your task is to write a function `to_leet_speak` that converts a regular english sentence to Leetspeak.
```
More about LeetSpeak You can read at wiki -> https://en.wikipedia.org/wiki/Leet... | ["def to_leet_speak(str):\n return str.translate(str.maketrans(\"ABCEGHILOSTZ\", \"@8(36#!10$72\"))", "def to_leet_speak(str):\n leet = {\n 'A' : '@',\n 'B' : '8',\n 'C' : '(',\n 'D' : 'D',\n 'E' : '3',\n 'F' : 'F',\n 'G' : '6',\n 'H': '#',\n 'I' : '!',\n 'J' : 'J',\n 'K' : 'K',\n 'L' : '1',\n 'M' : ... | {"fn_name": "to_leet_speak", "inputs": [["LEET"], ["CODEWARS"], ["HELLO WORLD"], ["LOREM IPSUM DOLOR SIT AMET"], ["THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG"]], "outputs": [["1337"], ["(0D3W@R$"], ["#3110 W0R1D"], ["10R3M !P$UM D010R $!7 @M37"], ["7#3 QU!(K 8R0WN F0X JUMP$ 0V3R 7#3 1@2Y D06"]]} | introductory | https://www.codewars.com/kata/57c1ab3949324c321600013f |
def to_leet_speak(str):
|
4,055 | Given that
```
f0 = '0'
f1 = '01'
f2 = '010' = f1 + f0
f3 = '01001' = f2 + f1
```
You will be given a number and your task is to return the `nth` fibonacci string. For example:
```
solve(2) = '010'
solve(3) = '01001'
```
More examples in test cases. Good luck!
If you like sequence Katas, you will enjoy this Kata: ... | ["def solve(n):\n a,b = '01'\n for _ in range(n): a,b = a+b,a\n return a", "def solve(n):\n return \"0\" if n == 0 else \"01\" if n == 1 else solve(n-1) + solve(n-2)", "def solve(n):\n a, b = \"0\", \"01\"\n for i in range(0, n):\n a = b + a\n a, b = b, a\n return a\n pass", "def s... | {"fn_name": "solve", "inputs": [[0], [1], [2], [3], [5]], "outputs": [["0"], ["01"], ["010"], ["01001"], ["0100101001001"]]} | introductory | https://www.codewars.com/kata/5aa39ba75084d7cf45000008 |
def solve(n):
|
4,057 | Complete the function that determines the score of a hand in the card game [Blackjack](https://en.wikipedia.org/wiki/Blackjack) (aka 21).
The function receives an array of strings that represent each card in the hand (`"2"`, `"3",` ..., `"10"`, `"J"`, `"Q"`, `"K"` or `"A"`) and should return the score of the hand (int... | ["def score_hand(a):\n n = sum(11 if x == \"A\" else 10 if x in \"JQK\" else int(x) for x in a)\n for _ in range(a.count(\"A\")):\n if n > 21:\n n -= 10\n return n", "def score_hand(cards):\n total = 0\n number_of_aces = 0\n for i in cards:\n if i == \"A\":\n total ... | {"fn_name": "score_hand", "inputs": [[["2", "3"]], [["4", "5", "6"]], [["7", "7", "8"]], [["9", "2", "10"]], [["4", "7", "8"]], [["J", "3"]], [["J", "Q"]], [["K", "J", "Q"]], [["A", "3"]], [["A", "J"]], [["A", "A", "A", "J"]], [["A", "2", "A", "9", "9"]], [["A", "A"]], [["8", "A", "A"]], [["5", "4", "A", "A"]], [["A", ... | introductory | https://www.codewars.com/kata/534ffb35edb1241eda0015fe |
def score_hand(cards):
|
4,058 | ### Task:
You have to write a function `pattern` which returns the following Pattern(See Examples) upto (2n-1) rows, where n is parameter.
* Note:`Returning` the pattern is not the same as `Printing` the pattern.
#### Parameters:
pattern( n );
^
... | ["def pattern(n):\n res = []\n for i in range(1, n + 1):\n line = ' ' * (i - 1) + str(i % 10) + ' ' * (n - i)\n res.append(line + line[::-1][1:])\n return '\\n'.join(res + res[::-1][1:])\n", "def pattern(n):\n quarters = (\"\".join(str(j %10) if j == i else \" \" for j in range(1, n)) for i in... | {"fn_name": "pattern", "inputs": [[3], [15], [-3], [-25], [0]], "outputs": [["1 1\n 2 2 \n 3 \n 2 2 \n1 1"], ["1 1\n 2 2 \n 3 3 \n 4 4 \n 5 5 \n 6 6 \n 7 ... | introductory | https://www.codewars.com/kata/558ac25e552b51dbc60000c3 |
def pattern(n):
|
4,059 | # Task
`N` candles are placed in a row, some of them are initially lit. For each candle from the 1st to the Nth the following algorithm is applied: if the observed candle is lit then states of this candle and all candles before it are changed to the opposite. Which candles will remain lit after applying the algorithm ... | ["def switch_lights(initial_states):\n states = list(initial_states)\n parity = 0\n for i in reversed(range(len(states))):\n parity ^= initial_states[i]\n states[i] ^= parity\n return states", "def switch_lights(a):\n n = sum(a)\n for i, x in enumerate(a):\n if n % 2:\n ... | {"fn_name": "switch_lights", "inputs": [[[1, 1, 1, 1, 1]], [[0, 0]], [[1, 0, 0, 1, 0, 1, 0, 1]], [[1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1]]], "outputs": [[[0, 1, 0, 1, 0]], [[0, 0]], [[1, 1, 1, 0, 0, 1, 1, 0]], [[1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0]]]} | introductory | https://www.codewars.com/kata/5888145122fe8620950000f0 |
def switch_lights(a):
|
4,071 | # Scenario
*You're saying good-bye your best friend* , **_See you next happy year_** .
**_Happy Year_** *is the year with only distinct digits* , (e.g) **_2018_**
___
# Task
**_Given_** a year, **_Find_** **_The next happy year_** or **_The closest year You'll see your best friend_** :\n year += 1\n \n while len(set(str(year))) != 4:\n year += 1\n \n return year", "def next_happy_year(year):\n for n in range(year+1, 9999):\n if len(set(str(n))) == 4:\n return n", "def next_happy_year(year):\n while True:\n year+=1\n ... | {"fn_name": "next_happy_year", "inputs": [[1001], [1123], [2001], [2334], [3331], [1987], [5555], [7712], [8088], [8999]], "outputs": [[1023], [1203], [2013], [2340], [3401], [2013], [5601], [7801], [8091], [9012]]} | introductory | https://www.codewars.com/kata/5ae7e3f068e6445bc8000046 |
def next_happy_year(year):
|
4,078 | Your task is to write a function that does just what the title suggests (so, fair warning, be aware that you are not getting out of it just throwing a lame bas sorting method there) with an array/list/vector of integers and the expected number `n` of smallest elements to return.
Also:
* the number of elements to be r... | ["def first_n_smallest(arr, n):\n lst = sorted(enumerate(arr), key=lambda it: it[1])[:n]\n lst.sort(key=lambda it:it[0])\n return [v for _,v in lst]", "def first_n_smallest(arr, n):\n m = sorted(arr)[:n]\n return [m.pop(m.index(i)) for i in arr if i in m]", "from operator import itemgetter\ndef first_n_s... | {"fn_name": "first_n_smallest", "inputs": [[[1, 2, 3, 4, 5], 3], [[5, 4, 3, 2, 1], 3], [[1, 2, 3, 1, 2], 3], [[1, 2, 3, -4, 0], 3], [[1, 2, 3, 4, 5], 0], [[1, 2, 3, 4, 5], 5], [[1, 2, 3, 4, 2], 4], [[2, 1, 2, 3, 4, 2], 2], [[2, 1, 2, 3, 4, 2], 3], [[2, 1, 2, 3, 4, 2], 4]], "outputs": [[[1, 2, 3]], [[3, 2, 1]], [[1, 2, ... | introductory | https://www.codewars.com/kata/5aec1ed7de4c7f3517000079 |
def first_n_smallest(arr, n):
|
4,083 | This challenge is based on [the kata](https://www.codewars.com/kata/n-smallest-elements-in-original-order) by GiacomoSorbi. Before doing this one it is advisable to complete the non-performance version first.
___
# Task
You will be given an array of random integers and a number `n`. You have to extract `n` smallest ... | ["from collections import Counter\nfrom itertools import count, islice\n\ndef performant_smallest(arr, n):\n cnts = Counter(arr)\n total = 0\n for i, c in sorted(cnts.items()):\n total += c\n if total >= n:\n break\n available = count(c + n - total, -1)\n it = (x for x in arr if ... | {"fn_name": "performant_smallest", "inputs": [[[1, 2, 3, 4, 5], 3], [[5, 4, 3, 2, 1], 3], [[1, 2, 3, 4, 1], 3], [[2, 1, 3, 2, 3], 3]], "outputs": [[[1, 2, 3]], [[3, 2, 1]], [[1, 2, 1]], [[2, 1, 2]]]} | introductory | https://www.codewars.com/kata/5aeed69804a92621a7000077 |
def performant_smallest(arr, n):
|
4,086 | Your task is to find the first element of an array that is not consecutive.
By not consecutive we mean not exactly 1 larger than the previous element of the array.
E.g. If we have an array `[1,2,3,4,6,7,8]` then `1` then `2` then `3` then `4` are all consecutive but `6` is not, so that's the first non-consecutive num... | ["def first_non_consecutive(arr):\n if not arr: return 0\n for i, x in enumerate(arr[:-1]):\n if x + 1 != arr[i + 1]:\n return arr[i + 1]", "def first_non_consecutive(a):\n i = a[0]\n for e in a:\n if e != i:\n return e\n i += 1\n return None", "def first_non_co... | {"fn_name": "first_non_consecutive", "inputs": [[[1, 2, 3, 4, 6, 7, 8]], [[1, 2, 3, 4, 5, 6, 7, 8]], [[4, 6, 7, 8, 9, 11]], [[4, 5, 6, 7, 8, 9, 11]], [[31, 32]], [[-3, -2, 0, 1]], [[-5, -4, -3, -1]]], "outputs": [[6], [null], [6], [11], [null], [0], [-1]]} | introductory | https://www.codewars.com/kata/58f8a3a27a5c28d92e000144 |
def first_non_consecutive(arr):
|
4,087 | Write a function which takes a number and returns the corresponding ASCII char for that value.
Example:
~~~if-not:java,racket
```
get_char(65) # => 'A'
```
~~~
~~~if:java
~~~
~~~if:racket
~~~
For ASCII table, you can refer to http://www.asciitable.com/ | ["def get_char(c):\n return chr(c)", "get_char=chr", "def get_char(value):\n '''Return the ASCII char for a given value'''\n return chr(value)", "get_char = lambda c: chr(c)", "def get_char(num_of_char):\n return chr(num_of_char)", "def get_char(c):\n c = chr(c)\n return c", "def get_char(c: int) -> str:\n ... | {"fn_name": "get_char", "inputs": [[65], [33], [34], [35], [36], [37], [38]], "outputs": [["A"], ["!"], ["\""], ["#"], ["$"], ["%"], ["&"]]} | introductory | https://www.codewars.com/kata/55ad04714f0b468e8200001c |
def get_char(c):
|
4,093 | In an infinite array with two rows, the numbers in the top row are denoted
`. . . , A[−2], A[−1], A[0], A[1], A[2], . . .`
and the numbers in the bottom row are denoted
`. . . , B[−2], B[−1], B[0], B[1], B[2], . . .`
For each integer `k`, the entry `A[k]` is directly above
the entry `B[k]` in the array, as shown:
... | ["def find_a(lst,n):\n if n<0: return find_a(lst[::-1], 3-n)\n if n<4: return lst[n]\n a,b,c,d = lst\n for _ in range(n-3):\n a,b,c,d = b, c, d, 6*d-10*c+6*b-a\n return d", "def find_a(A, n):\n if 0 <= n < 4: return A[n]\n if n < 0:\n A, n = A[::-1], abs(n) + 3\n B = [0] * 4\n B... | {"fn_name": "find_a", "inputs": [[[1, 2, 3, 4], 2], [[38, 200, -18, 45], 1], [[1, 0, 0, 1], 5], [[0, 2, 0, 3], -2], [[-20, 1, -3, 14], -5], [[1, 2, 3, 5], 100], [[0, 4, 6, 13], 100]], "outputs": [[3], [200], [20], [-126], [-44402], [60560100487003612846322657690093088848428068520476594299], [335254562473098582210532865... | introductory | https://www.codewars.com/kata/5d1eb2db874bdf9bf6a4b2aa |
def find_a(array, n):
|
4,097 | Hi guys, welcome to introduction to DocTesting.
The kata is composed of two parts; in part (1) we write three small functions, and in part (2) we write a few doc tests for those functions.
Lets talk about the functions first...
The reverse_list function takes a list and returns the reverse of it.
If given an... | ["def reverse_list(x):\n \"\"\"Takes an list and returns the reverse of it. \n If x is empty, return [].\n \n >>> reverse_list([1, 2, 3, 4])\n [4, 3, 2, 1]\n >>> reverse_list([])\n []\n \"\"\" \n \n return x[::-1]\n\ndef sum_list(x):\n \"\"\"Takes a list, and returns the sum of that lis... | {"fn_name": "reverse_list", "inputs": [[[1, 2, 3]], [[]]], "outputs": [[[3, 2, 1]], [[]]]} | introductory | https://www.codewars.com/kata/58e4033b5600a17be1000103 |
def reverse_list(x):
|
4,104 | # Task
**_Given_** an *array/list [] of n integers* , *find maximum triplet sum in the array* **_Without duplications_** .
___
# Notes :
* **_Array/list_** size is *at least 3* .
* **_Array/list_** numbers could be a *mixture of positives , negatives and zeros* .
* **_Repetition_** of numbers in *the array/list ... | ["def max_tri_sum(numbers):\n return sum(sorted(set(numbers))[-3:])", "from heapq import nlargest\n\ndef max_tri_sum(numbers):\n return sum(nlargest(3, set(numbers)))", "def max_tri_sum(n):\n return sum(sorted(set(n))[-3:])", "def max_tri_sum(nums): return sum(sorted(set(nums))[-3:])\n", "max_tri_sum=lambda l:... | {"fn_name": "max_tri_sum", "inputs": [[[3, 2, 6, 8, 2, 3]], [[2, 9, 13, 10, 5, 2, 9, 5]], [[2, 1, 8, 0, 6, 4, 8, 6, 2, 4]], [[-3, -27, -4, -2, -27, -2]], [[-14, -12, -7, -42, -809, -14, -12]], [[-13, -50, 57, 13, 67, -13, 57, 108, 67]], [[-7, 12, -7, 29, -5, 0, -7, 0, 0, 29]], [[-2, 0, 2]], [[-2, -4, 0, -9, 2]], [[-5, ... | introductory | https://www.codewars.com/kata/5aa1bcda373c2eb596000112 |
def max_tri_sum(numbers):
|
4,106 | ### self_converge
`Goal`: Given a number (with a minimum of 3 digits), return the number of iterations it takes to arrive at a derived number that converges on to itself, as per the following [Kaprekar][Kaprekar] routine. As a learning exercise, come up with a solution that uses recursion. The
following steps would be ... | ["def self_converge(number):\n n, cycle = str(number), set()\n while n not in cycle:\n cycle.add(n)\n s = ''.join(sorted(n))\n n = '%0*d' % (len(n), int(s[::-1]) - int(s))\n return -1 if not int(n) else len(cycle)", "def self_converge(n, seen=None):\n s, seen = \"\".join(sorted(str(n)))... | {"fn_name": "self_converge", "inputs": [[4321], [2111], [211], [90900], [992299229]], "outputs": [[4], [6], [7], [9], [22]]} | introductory | https://www.codewars.com/kata/54ab259e15613ce0c8001bab |
def self_converge(number):
|
4,112 | Find the second-to-last element of a list.
Example:
```python
penultimate([1,2,3,4]) # => 3
penultimate(["Python is dynamic"]) # => 'i'
(courtesy of [haskell.org](http://www.haskell.org/haskellwiki/99_questions/1_to_10))
``` | ["def penultimate(a):\n return a[-2]\n", "def penultimate(a):\n # implement here\n try:\n return a[-2]\n except:\n return None", "def penultimate(a):\n try:\n return a[-2]\n except IndexError:\n pass", "def penultimate(a):\n return a[len(a)-2]", "from operator import itemgetter\npenul... | {"fn_name": "penultimate", "inputs": [[[1, 2, 3, 4]], ["hello"]], "outputs": [[3], ["l"]]} | introductory | https://www.codewars.com/kata/54162d1333c02486a700011d |
def penultimate(a):
|
4,122 | This is the simple version of Shortest Code series. If you need some challenges, please try the [challenge version](http://www.codewars.com/kata/56f928b19982cc7a14000c9d)
## Task:
Every uppercase letter is Father, The corresponding lowercase letters is the Son.
Give you a string ```s```, If the father and s... | ["def sc(strng):\n seen = set(strng)\n return ''.join(a for a in strng if a.swapcase() in seen)\n", "def sc(s):\n return \"\".join(ch for ch in s if ch.upper() in s and ch.lower() in s);", "def sc(s):\n xs = set(s)\n return ''.join(c for c in s if c.swapcase() in xs)", "def sc(s):\n return ''.join([e ... | {"fn_name": "sc", "inputs": [["Aab"], ["AabBc"], ["SONson"], ["FfAaTtHhEeRr"], ["SONsonfather"], ["sonfather"], ["DONKEYmonkey"], ["monkeyDONKEY"], ["BANAna"]], "outputs": [["Aa"], ["AabB"], ["SONson"], ["FfAaTtHhEeRr"], ["SONson"], [""], ["ONKEYonkey"], ["onkeyONKEY"], ["ANAna"]]} | introductory | https://www.codewars.com/kata/56fe9a0c11086cd842000008 |
def sc(s):
|
4,129 | You managed to send your friend to queue for tickets in your stead, but there is a catch: he will get there only if you tell him how much that is going to take. And everybody can only take one ticket at a time, then they go back in the last position of the queue if they need more (or go home if they are fine).
Each ti... | ["def queue(queuers,pos):\n return sum(min(queuer, queuers[pos] - (place > pos)) for place, queuer in enumerate(queuers))", "def queue(queuers,pos):\n friendWait = queuers[pos]\n # Divide the line into the front of the line (up to the friend)\n # and back of the line (behind the friend):\n frontOfLine = ... | {"fn_name": "queue", "inputs": [[[2, 5, 3, 6, 4], 0], [[2, 5, 3, 6, 4], 1], [[2, 5, 3, 6, 4], 2], [[2, 5, 3, 6, 4], 3], [[2, 5, 3, 6, 4], 4]], "outputs": [[6], [18], [12], [20], [17]]} | introductory | https://www.codewars.com/kata/5b538734beb8654d6b00016d |
def queue(queuers,pos):
|
4,136 | # Task
A cake is sliced with `n` straight lines. Your task is to calculate the maximum number of pieces the cake can have.
# Example
For `n = 0`, the output should be `1`.
For `n = 1`, the output should be `2`.
For `n = 2`, the output should be `4`.
For `n = 3`, the output should be `7`.
See the followin... | ["def cake_slice(n):\n return (n ** 2 + n + 2) // 2", "def cake_slice(n):\n return 0.5*n**2+0.5*n+1", "def cake_slice(n):\n return (n**2 + n) // 2 + 1", "cake_slice = lambda n: sum(range(n + 1)) + 1", "def cake_slice(n):\n #coding and coding...\n sum = 1\n for i in range(n):\n sum += i+1\n ret... | {"fn_name": "cake_slice", "inputs": [[0], [1], [2], [3], [10]], "outputs": [[1], [2], [4], [7], [56]]} | introductory | https://www.codewars.com/kata/58c8a41bedb423240a000007 |
def cake_slice(n):
|
4,137 | ## A square of squares
You like building blocks. You especially like building blocks that are squares. And what you even like more, is to arrange them into a square of square building blocks!
However, sometimes, you can't arrange them into a square. Instead, you end up with an ordinary rectangle! Those blasted things!... | ["import math\ndef is_square(n):\n return n > -1 and math.sqrt(n) % 1 == 0;", "import math\n\ndef is_square(n): \n\n if n < 0:\n return False\n\n sqrt = math.sqrt(n)\n \n return sqrt.is_integer()", "def is_square(n): \n return n >= 0 and (n**0.5) % 1 == 0", "import math\ndef is_square(n):... | {"fn_name": "is_square", "inputs": [[-1], [25], [26]], "outputs": [[false], [true], [false]]} | introductory | https://www.codewars.com/kata/54c27a33fb7da0db0100040e |
def is_square(n):
|
4,141 | A special type of prime is generated by the formula `p = 2^m * 3^n + 1` where `m` and `n` can be any non-negative integer.
The first `5` of these primes are `2, 3, 5, 7, 13`, and are generated as follows:
```Haskell
2 = 2^0 * 3^0 + 1
3 = 2^1 * 3^0 + 1
5 = 2^2 * 3^0 + 1
7 = 2^1 * 3^1 + 1
13 = 2^2 * 3^1 + 1
..and so on... | ["sb_primes = [2, 3, 5, 7, 13, 17, 19, 37, 73, 97, 109, 163, 193, 257, 433, 487, 577, 769, 1153, 1297, 1459, 2593, 2917, 3457, 3889, 10369, 12289, 17497, 18433, 39367, 52489, 65537, 139969, 147457, 209953, 331777, 472393, 629857, 746497, 786433, 839809, 995329, 1179649, 1492993]\n\ndef solve(x, y):\n return sum(x <=... | {"fn_name": "solve", "inputs": [[0, 10], [0, 15], [0, 100], [100, 1000], [340, 500], [3400, 5000], [20000, 60000], [750000, 1000000], [300000, 900000], [100, 1000000], [500000, 1000000], [1000000, 1500000], [0, 1500000]], "outputs": [[4], [5], [10], [8], [2], [2], [2], [3], [6], [32], [5], [2], [44]]} | introductory | https://www.codewars.com/kata/5a1502db46d84395ab00008a |
def solve(x, y):
|
4,143 | [Generala](https://en.wikipedia.org/wiki/Generala) is a dice game popular in South America. It's very similar to [Yahtzee](https://en.wikipedia.org/wiki/Yahtzee) but with a different scoring approach. It is played with 5 dice, and the possible results are:
| Result | Points | Rules ... | ["def points(dice):\n dice = sorted([int(d) for d in dice])\n counts = [dice.count(i) for i in range(1, 7)]\n if 5 in counts:\n # GENERALA\n return 50\n if 4 in counts:\n # POKER\n return 40\n if 3 in counts and 2 in counts:\n # FULLHOUSE\n return 30\n if coun... | {"fn_name": "points", "inputs": [["55555"], ["44444"], ["44441"], ["33233"], ["22262"], ["12121"], ["44455"], ["66116"], ["12345"], ["23456"], ["34561"], ["13564"], ["62534"], ["44421"], ["61623"], ["12346"]], "outputs": [[50], [50], [40], [40], [40], [30], [30], [30], [20], [20], [20], [20], [20], [0], [0], [0]]} | introductory | https://www.codewars.com/kata/5f70c55c40b1c90032847588 |
def points(dice):
|
4,144 | In number theory, an **[abundant](https://en.wikipedia.org/wiki/Abundant_number)** number or an **[excessive](https://en.wikipedia.org/wiki/Abundant_number)** number is one for which the sum of it's **[proper divisors](http://mathworld.wolfram.com/ProperDivisor.html)** is greater than the number itself. The integer *... | ["def abundant(h):\n for n in range(h,0,-1):\n s = sum(i for i in range(1,n) if n % i == 0)\n if s > h:\n return [[n],[s-n]]", "from operator import itemgetter\nfrom bisect import bisect\n\nLIMIT = 2000\n\nmemo, result = [0]*LIMIT, {}\nfor x in range(1, LIMIT):\n if memo[x] > x:\n ... | {"fn_name": "abundant", "inputs": [[15], [19], [100], [999], [200], [250], [300], [350], [400], [450], [500], [555], [600], [666], [707], [777], [800], [900], [1111]], "outputs": [[[[12], [4]]], [[[18], [3]]], [[[100], [17]]], [[[996], [360]]], [[[200], [65]]], [[[246], [12]]], [[[300], [268]]], [[[350], [44]]], [[[400... | introductory | https://www.codewars.com/kata/57f3996fa05a235d49000574 |
def abundant(h):
|
4,145 | # Problem Statement
Write a function that takes two string parameters, an IP (v4) address and a subnet mask, and returns two strings: the network block, and the host identifier.
The function does not need to support CIDR notation.
# Description
A single IP address with subnet mask actually specifies several addresses... | ["def ipv4__parser(addr, mask):\n return tuple(\".\".join(str(n) for n in a) for a in zip(*(((a & m), (a & ~m)) for a, m in zip((int(n) for n in addr.split(\".\")), (int(n) for n in mask.split(\".\"))))))", "from socket import inet_aton, inet_ntoa\nfrom struct import Struct\n\nAddr = Struct('>I')\n\ndef ipv4__parser... | {"fn_name": "ipv4__parser", "inputs": [["192.168.50.1", "255.255.255.0"], ["192.168.50.129", "255.255.255.192"], ["192.168.50.153", "255.255.255.225"], ["65.196.188.53", "255.255.240.0"], ["65.196.188.53", "0.0.0.0"]], "outputs": [[["192.168.50.0", "0.0.0.1"]], [["192.168.50.128", "0.0.0.1"]], [["192.168.50.129", "0.0.... | introductory | https://www.codewars.com/kata/556d120c7c58dacb9100008b |
def ipv4__parser(ip_addr, mask):
|
4,147 | Everyone knows passphrases. One can choose passphrases from poems, songs, movies names and so on but frequently
they can be guessed due to common cultural references.
You can get your passphrases stronger by different means. One is the following:
choose a text in capital letters including or not digits and non alphab... | ["def play_pass(s, n):\n\n # Step 1, 2, 3\n shiftText = \"\"\n for char in s:\n if char.isdigit():\n shiftText += str(9 - int(char))\n elif char.isalpha():\n shifted = ord(char.lower()) + n\n shiftText += chr(shifted) if shifted <= ord('z') else chr(shifted - 26)\... | {"fn_name": "play_pass", "inputs": [["I LOVE YOU!!!", 1], ["I LOVE YOU!!!", 0], ["AAABBCCY", 1], ["MY GRANMA CAME FROM NY ON THE 23RD OF APRIL 2015", 2], ["TO BE HONEST WITH YOU I DON'T USE THIS TEXT TOOL TOO OFTEN BUT HEY... MAYBE YOUR NEEDS ARE DIFFERENT.", 5], ["IN 2012 TWO CAMBRIDGE UNIVERSITY RESEARCHERS ANALYSED ... | introductory | https://www.codewars.com/kata/559536379512a64472000053 |
def play_pass(s, n):
|
4,150 | How can you tell an extrovert from an
introvert at NSA? Va gur ryringbef,
gur rkgebireg ybbxf ng gur BGURE thl'f fubrf.
I found this joke on USENET, but the punchline is scrambled. Maybe you can decipher it?
According to Wikipedia, ROT13 (http://en.wikipedia.org/wiki/ROT13) is frequently used to obfuscate jokes on USE... | ["def rot13(message):\n def decode(c):\n if 'a' <= c <= 'z':\n base = 'a'\n elif 'A' <= c <= 'Z':\n base = 'A'\n else:\n return c\n return chr((ord(c) - ord(base) + 13) % 26 + ord(base))\n return \"\".join(decode(c) for c in message)", "def rot13(messag... | {"fn_name": "rot13", "inputs": [["EBG13 rknzcyr."], ["How can you tell an extrovert from an\nintrovert at NSA? Va gur ryringbef,\ngur rkgebireg ybbxf ng gur BGURE thl'f fubrf."], ["123"], ["Guvf vf npghnyyl gur svefg xngn V rire znqr. Gunaxf sbe svavfuvat vg! :)"], ["@[`{"]], "outputs": [["ROT13 example."], ["Ubj pna l... | introductory | https://www.codewars.com/kata/52223df9e8f98c7aa7000062 |
def rot13(message):
|
4,155 | Consider the numbers `6969` and `9116`. When you rotate them `180 degrees` (upside down), these numbers remain the same. To clarify, if we write them down on a paper and turn the paper upside down, the numbers will be the same. Try it and see! Some numbers such as `2` or `5` don't yield numbers when rotated.
Given a r... | ["REV = {'6':'9', '9':'6'}\nBASE = set(\"01869\")\n\ndef isReversible(n):\n s = str(n)\n return ( not (set(s) - BASE) # contains only reversible characters\n and (not len(s)%2 or s[len(s)//2] not in \"69\") # does n... | {"fn_name": "solve", "inputs": [[0, 10], [10, 100], [100, 1000], [1000, 10000], [10000, 15000], [15000, 20000], [60000, 70000], [60000, 130000]], "outputs": [[3], [4], [12], [20], [6], [9], [15], [55]]} | introductory | https://www.codewars.com/kata/59f7597716049833200001eb |
def solve(a, b):
|
4,159 | *** Nova polynomial multiply***
This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8807940ff3001140 ) [#4](http://www.codewars.com/kata/571a2e2df24bdf... | ["def poly_multiply(p1, p2):\n if not p1 or not p2: return []\n n = len(p1) + len(p2) - 1\n p = [0]*n\n for i,a in enumerate(p1):\n for j,b in enumerate(p2):\n p[i + j] += a*b\n return p", "from numpy import polymul\n\ndef poly_multiply(p1, p2):\n res = list(polymul(p1, p2))\n return res if any(res) ... | {"fn_name": "poly_multiply", "inputs": [[[], []], [[1, 2, 3, 4, 5, 6], []], [[], [1, 2, 3, 4, 5, 6]]], "outputs": [[[]], [[]], [[]]]} | introductory | https://www.codewars.com/kata/570eb07e127ad107270005fe |
def poly_multiply(p1, p2):
|
4,166 | Consider the following well known rules:
- A number is divisible by 3 if the sum of its digits is divisible by 3. Let's call '3' a "1-sum" prime
- For 37, we take numbers in groups of threes from the right and check if the sum of these groups is divisible by 37.
Example: 37 * 123456787 = 4567901119 => 4 + 567 + 901... | ["import math\n\ndef divisors(n):\n divs = [1]\n for i in range(2,int(math.sqrt(n))+1):\n if n%i == 0:\n divs.extend([i,n//i])\n divs.extend([n])\n return list(set(divs))\n\ndef solve(p):\n for d in sorted(divisors(p-1)):\n if pow(10, d, p) == 1:\n return \"{}-sum\".fo... | {"fn_name": "solve", "inputs": [[3], [7], [11], [13], [37], [47], [73], [239], [376049], [999883], [24701723], [45939401]], "outputs": [["1-sum"], ["3-altsum"], ["1-altsum"], ["3-altsum"], ["3-sum"], ["23-altsum"], ["4-altsum"], ["7-sum"], ["47006-altsum"], ["499941-sum"], ["12350861-sum"], ["11484850-altsum"]]} | introductory | https://www.codewars.com/kata/5cfe4465ac68b86026b09c77 |
def solve(p):
|
4,173 | [Langton's ant](https://en.wikipedia.org/wiki/Langton%27s_ant) is a two-dimensional Turing machine invented in the late 1980s. The ant starts out on a grid of black and white cells and follows a simple set of rules that has complex emergent behavior.
## Task
Complete the function and return the `n`th iteration of Lan... | ["BLACK = 0\nWHITE = 1\n# N, E, S, W\nCARDINALS = [(-1, 0), (0, 1), (1, 0), (0, -1)]\n\ndef ant(grid, column, row, n, direction=0):\n r, c, d = row, column, direction\n for _ in range(n):\n # Handle direction change and current cell colour flip\n if grid[r][c] == BLACK:\n grid[r][c] = WHI... | {"fn_name": "ant", "inputs": [[[[1]], 0, 0, 1, 0], [[[0]], 0, 0, 1, 0], [[[1]], 0, 0, 3, 0], [[[1]], 0, 0, 1]], "outputs": [[[[0, 0]]], [[[0, 1]]], [[[0, 1], [0, 1]]], [[[0, 0]]]]} | introductory | https://www.codewars.com/kata/58e6996019af2cff71000081 |
def ant(grid, column, row, n, direction = 0):
|
4,177 | # Scenario
*Now that the competition gets tough it will* **_Sort out the men from the boys_** .
**_Men_** are the **_Even numbers_** and **_Boys_** are the **_odd_**  
___
# Task
**_Given_** an *array/list [] of n integers* , **_Se... | ["def men_from_boys(arr):\n men = []\n boys = []\n for i in sorted(set(arr)):\n if i % 2 == 0:\n men.append(i)\n else:\n boys.append(i)\n return men + boys[::-1]", "def men_from_boys(arr):\n return sorted(set(arr), key=lambda n: (n%2, n * (-1)**(n%2)))", "def men_from_... | {"fn_name": "men_from_boys", "inputs": [[[7, 3, 14, 17]], [[2, 43, 95, 90, 37]], [[20, 33, 50, 34, 43, 46]], [[82, 91, 72, 76, 76, 100, 85]], [[2, 15, 17, 15, 2, 10, 10, 17, 1, 1]], [[-32, -39, -35, -41]], [[-64, -71, -63, -66, -65]], [[-94, -99, -100, -99, -96, -99]], [[-53, -26, -53, -27, -49, -51, -14]], [[-17, -45,... | introductory | https://www.codewars.com/kata/5af15a37de4c7f223e00012d |
def men_from_boys(arr):
|
4,178 | # Introduction and Warm-up (Highly recommended)
# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
___
# Task
**_Given_** an **_array of integers_** , **_Find the minimum sum_** which is obtained *from summing each Two integers product* .
___
# Notes
* **_Ar... | ["def min_sum(arr):\n arr = sorted(arr)\n return sum(arr[i]*arr[-i-1] for i in range(len(arr)//2))", "def min_sum(arr):\n arr.sort()\n left, right, res = 0, len(arr) - 1, 0\n while left < right:\n res += arr[left] * arr[right]\n left += 1\n right -= 1\n return res", "def min_sum(a... | {"fn_name": "min_sum", "inputs": [[[5, 4, 2, 3]], [[12, 6, 10, 26, 3, 24]], [[9, 2, 8, 7, 5, 4, 0, 6]]], "outputs": [[22], [342], [74]]} | introductory | https://www.codewars.com/kata/5a523566b3bfa84c2e00010b |
def min_sum(arr):
|
4,184 | As most of you might know already, a prime number is an integer `n` with the following properties:
* it must be greater than 1
* it must be divisible only by itself and 1
And that's it: -15 or 8 are not primes, 5 or 97 are; pretty easy, isn't it?
Well, turns out that primes are not just a mere mathematical curiosity... | ["primes = [2, 3, 5, 7]\n\ndef is_prime(n):\n if n < 2:\n return False\n m = int(n ** .5) + 1\n for p in primes:\n if p >= m: break\n if not n % p:\n return False\n q, d = primes[-1], 4 if (n + 1) % 6 else 2\n while q < m:\n q, d = q + d, 4 - d\n if is_prime(... | {"fn_name": "is_prime", "inputs": [[1], [2], [5], [143], [-1], [29], [53], [529]], "outputs": [[false], [true], [true], [false], [false], [true], [true], [false]]} | introductory | https://www.codewars.com/kata/58603c898989d15e9e000475 |
def is_prime(n):
|
4,185 | This is the simple version of Shortest Code series. If you need some challenges, please try the [challenge version](http://www.codewars.com/kata/570f45fab29c705d330004e3)
## Task:
There is a rectangular land and we need to plant trees on the edges of that land.
I will give you three parameters:
```width``` and ```l... | ["def sc(width,length,gaps):\n #your code here\n a, b = divmod(2*width + 2*length - 4, gaps+1)\n return 0 if b else a", "def sc(width,length,gaps):\n places = width*2 + (length-2)*2\n if gaps == 0:\n return places\n div, mod = divmod(places, gaps+1)\n if mod:\n return 0\n return di... | {"fn_name": "sc", "inputs": [[3, 3, 1], [3, 3, 3], [3, 3, 2], [7, 7, 3], [3, 3, 0], [3, 3, 10], [2, 2, 1], [2, 2, 0], [200, 2, 1], [2, 200, 1]], "outputs": [[4], [2], [0], [6], [8], [0], [2], [4], [200], [200]]} | introductory | https://www.codewars.com/kata/5710443187a36a9cee0005a1 |
def sc(width,length,gaps):
|
4,187 | Background
----------
In another dimension, there exist two immortal brothers: Solomon and Goromon. As sworn loyal subjects to the time elemental, Chronixus, both Solomon and Goromon were granted the power to create temporal folds. By sliding through these temporal folds, one can gain entry to parallel dimensions where... | ["def solomons_quest(arr):\n pos, lvl = [0,0], 0\n for dilat,dir,dist in arr:\n lvl += dilat\n pos[dir in [0,2]] += dist * 2**lvl * (-1)**( dir in [2,3] )\n return pos", "def solomons_quest(arr):\n level = 0\n ds = [1j, 1, -1j, -1]\n pos = 0\n for level_shift, direction, distance in a... | {"fn_name": "solomons_quest", "inputs": [[[[1, 3, 5], [2, 0, 10], [-3, 1, 4], [4, 2, 4], [1, 1, 5], [-3, 0, 12], [2, 1, 12], [-2, 2, 6]]], [[[4, 0, 8], [2, 1, 2], [1, 0, 5], [-3, 3, 16], [2, 2, 2], [-1, 1, 7], [0, 0, 5], [-4, 3, 14]]], [[[1, 1, 20], [1, 2, 30], [1, 3, 8], [1, 0, 2], [1, 1, 6], [1, 2, 4], [1, 3, 6], [-7... | introductory | https://www.codewars.com/kata/59d7c910f703c460a2000034 |
def solomons_quest(arr):
|
4,196 | # Summation Of Primes
The sum of the primes below or equal to 10 is **2 + 3 + 5 + 7 = 17**. Find the sum of all the primes **_below or equal to the number passed in_**.
From Project Euler's [Problem #10](https://projecteuler.net/problem=10 "Project Euler - Problem 10"). | ["from bisect import bisect\n\ndef sieve(n):\n sieve, primes = [0]*(n+1), []\n for i in range(2, n+1):\n if not sieve[i]:\n primes.append(i) \n for j in range(i**2, n+1, i): sieve[j] = 1\n return primes\n\nPRIMES = sieve(1000000)\n\ndef summationOfPrimes(n):\n return sum(PRIMES[... | {"fn_name": "summationOfPrimes", "inputs": [[5], [6], [7], [8], [9], [10], [20], [30], [40], [50], [100], [200], [300], [400], [500], [1000], [2000], [3000], [4000], [5000], [25000]], "outputs": [[10], [10], [17], [17], [17], [17], [77], [129], [197], [328], [1060], [4227], [8275], [13887], [21536], [76127], [277050], ... | introductory | https://www.codewars.com/kata/59ab0ca4243eae9fec000088 |
def summationOfPrimes(primes):
|
4,198 | ### What is simplifying a square root?
If you have a number, like 80, for example, you would start by finding the greatest perfect square divisible by 80. In this case, that's 16. Find the square root of 16, and multiply it by 80 / 16. Answer = 4 √5.
##### The above example:
:\n for d in range(int(n ** .5), 0, -1):\n if not n % d ** 2: break\n if d*d == n: return '%d' % d\n elif d == 1: return 'sqrt %d' % n\n else: return '%d sqrt %d' % (d, n // d ** 2)\n\ndef desimplify(s):\n x, _, y = s.partition('sqrt')\n return int(x or '1') ** 2 * int(y or '1'... | {"fn_name": "simplify", "inputs": [[1], [2], [3], [8], [15], [16], [18], [20], [24], [32], [4], [7], [9], [10], [12], [13], [14], [50], [80], [200]], "outputs": [["1"], ["sqrt 2"], ["sqrt 3"], ["2 sqrt 2"], ["sqrt 15"], ["4"], ["3 sqrt 2"], ["2 sqrt 5"], ["2 sqrt 6"], ["4 sqrt 2"], ["2"], ["sqrt 7"], ["3"], ["sqrt 10"]... | introductory | https://www.codewars.com/kata/5850e85c6e997bddd300005d |
def simplify(n):
|
4,202 | The Ulam sequence `U` is defined by `u0 = u`, `u1 = v`, with the general term `uN` for `N > 2` given by the least integer expressible uniquely as the sum of two distinct earlier terms. In other words, the next number is always the smallest, unique sum of any two previous terms.
Complete the function that creates an Ul... | ["from itertools import combinations\nfrom collections import defaultdict\n\ndef ulam_sequence(u0, u1, n):\n seq = [u0, u1, u0 + u1]\n \n while len(seq) < n:\n candidates = defaultdict(int)\n \n for a, b in combinations(seq, 2):\n candidates[a + b] += 1\n \n for nu... | {"fn_name": "ulam_sequence", "inputs": [[1, 2, 5], [3, 4, 5], [5, 6, 8]], "outputs": [[[1, 2, 3, 4, 6]], [[3, 4, 7, 10, 11]], [[5, 6, 11, 16, 17, 21, 23, 26]]]} | introductory | https://www.codewars.com/kata/5995ff073acba5fa3a00011d |
def ulam_sequence(u0, u1, n):
|
4,205 | Ahoy Matey!
Welcome to the seven seas.
You are the captain of a pirate ship.
You are in battle against the royal navy.
You have cannons at the ready.... or are they?
Your task is to check if the gunners are loaded and ready, if they are: ```Fire!```
If they aren't ready: ```Shiver me timbers!```
Your gunners for... | ["def cannons_ready(gunners):\n return 'Shiver me timbers!' if 'nay' in gunners.values() else 'Fire!'", "def cannons_ready(gunners):\n for i in gunners:\n if gunners[i] == 'nay':\n return 'Shiver me timbers!'\n return 'Fire!'", "def cannons_ready(g):\n return ['Fire!','Shiver me timbers!']['na... | {"fn_name": "cannons_ready", "inputs": [[{"Joe": "nay", "Johnson": "nay", "Peter": "aye"}]], "outputs": [["Shiver me timbers!"]]} | introductory | https://www.codewars.com/kata/5748a883eb737cab000022a6 |
def cannons_ready(gunners):
|
4,212 | Write a function that takes one or more arrays and returns a new array of unique values in the order of the original provided arrays.
In other words, all values present from all arrays should be included in their original order, but with no duplicates in the final array.
The unique numbers should be sorted by their o... | ["def unite_unique(*arg):\n res = []\n for arr in arg:\n for val in arr:\n if not val in res: res.append(val)\n return res", "from itertools import chain\n\ndef unite_unique(*args):\n return list(dict.fromkeys(chain.from_iterable(args)))", "from itertools import chain\n\ndef unite_unique(*... | {"fn_name": "unite_unique", "inputs": [[[1, 2], [3, 4]], [[1, 3, 2], [5, 2, 1, 4], [2, 1]], [[4, 3, 2, 2]], [[4, "a", 2], []], [[], [4, "a", 2]], [[], [4, "a", 2], []], [[]], [[], []], [[], [1, 2]], [[], [1, 2, 1, 2], [2, 1, 1, 2, 1]]], "outputs": [[[1, 2, 3, 4]], [[1, 3, 2, 5, 4]], [[4, 3, 2]], [[4, "a", 2]], [[4, "a"... | introductory | https://www.codewars.com/kata/5729c30961cecadc4f001878 |
def unite_unique(*args):
|
4,216 | Create a method (**JS**: function) `every` which returns every nth element of an array.
### Usage
With no arguments, `array.every` it returns every element of the array.
With one argument, `array.every(interval)` it returns every `interval`th element.
With two arguments, `array.every(interval, start_index)` it re... | ["def every(lst, n=1, start=0):\n return lst[start::n]", "#code here\ndef every(array, interval=None, start=None):\n return array[start::interval]", "def every(arr, n = 1, m = 0):\n return arr[m::n]\n", "#code here\ndef every(arr,n=1,s=0):\n return arr[s::n]", "def every(arr, n = 1, i = 0):\n return arr[... | {"fn_name": "every", "inputs": [[[null, null, null, null, null], 2]], "outputs": [[[null, null, null]]]} | introductory | https://www.codewars.com/kata/5753b987aeb792508d0010e2 |
def every(array, interval = 1, start_index = 0):
|
4,217 | If the first day of the month is a Friday, it is likely that the month will have an `Extended Weekend`. That is, it could have five Fridays, five Saturdays and five Sundays.
In this Kata, you will be given a start year and an end year. Your task will be to find months that have extended weekends and return:
```
- The... | ["from calendar import month_abbr\nfrom datetime import datetime \ndef solve(a,b):\n res = [month_abbr[month]\n for year in range(a, b+1) \n for month in [1,3,5,7,8,10,12] \n if datetime(year, month, 1).weekday() == 4]\n return (res[0],res[-1], len(res))", "from datetime import date\n\ndef solve(a, b):... | {"fn_name": "solve", "inputs": [[2016, 2020], [1900, 1950], [1800, 2500]], "outputs": [[["Jan", "May", 5]], [["Mar", "Dec", 51]], [["Aug", "Oct", 702]]]} | introductory | https://www.codewars.com/kata/5be7f613f59e0355ee00000f |
def solve(a,b):
|
4,237 | Converting a 24-hour time like "0830" or "2030" to a 12-hour time (like "8:30 am" or "8:30 pm") sounds easy enough, right? Well, let's see if you can do it!
You will have to define a function named "to12hourtime", and you will be given a four digit time string (in "hhmm" format) as input.
Your task is to return a 12... | ["from datetime import datetime\n\ndef to12hourtime(t):\n return datetime.strptime(t, '%H%M').strftime('%I:%M %p').lstrip('0').lower()", "def to12hourtime(t):\n hour = int(t[:2])\n \n if hour >= 12:\n hour -= 12\n suf = 'pm'\n else:\n suf = 'am'\n \n if hour == 0:\n hour... | {"fn_name": "to12hourtime", "inputs": [["0000"], ["0001"], ["0002"], ["0003"], ["0004"], ["0005"], ["0006"], ["0007"], ["0008"], ["0009"], ["0010"], ["0011"], ["0012"], ["0013"], ["0014"], ["0015"], ["0016"], ["0017"], ["0018"], ["0019"], ["0020"], ["0021"], ["0022"], ["0023"], ["0024"], ["0025"], ["0026"], ["0027"], [... | introductory | https://www.codewars.com/kata/59b0ab12cf3395ef68000081 |
def to12hourtime(t):
|
4,238 | I assume most of you are familiar with the ancient legend of the rice (but I see wikipedia suggests [wheat](https://en.wikipedia.org/wiki/Wheat_and_chessboard_problem), for some reason) problem, but a quick recap for you: a young man asks as a compensation only `1` grain of rice for the first square, `2` grains for the... | ["squares_needed = int.bit_length", "def squares_needed(grains):\n return grains.bit_length()", "def squares_needed(grains):\n if grains < 1:\n return 0\n else:\n return 1 + squares_needed(grains // 2)", "from math import log2, ceil\n\ndef squares_needed(grains):\n return grains and ceil(log2(... | {"fn_name": "squares_needed", "inputs": [[0], [1], [2], [3], [4]], "outputs": [[0], [1], [2], [2], [3]]} | introductory | https://www.codewars.com/kata/5b0d67c1cb35dfa10b0022c7 |
def squares_needed(grains):
|
4,241 | Your task is to make function, which returns the sum of a sequence of integers.
The sequence is defined by 3 non-negative values: **begin**, **end**, **step**.
If **begin** value is greater than the **end**, function should returns **0**
*Examples*
~~~if-not:nasm
~~~
This is the first kata in the series:
1) Sum ... | ["def sequence_sum(start, end, step):\n return sum(range(start, end+1, step))", "def sequence_sum(begin_number, end_number, step):\n return sum(range(begin_number, end_number+1, step))", "def sequence_sum(b, e, s):\n k = (e - b) // s\n return (1 + k) * (b + s * k / 2) if b <= e else 0", "def sequence_sum(begin,... | {"fn_name": "sequence_sum", "inputs": [[2, 6, 2], [1, 5, 1], [1, 5, 3], [0, 15, 3], [16, 15, 3], [2, 24, 22], [2, 2, 2], [2, 2, 1], [1, 15, 3], [15, 1, 3]], "outputs": [[12], [15], [5], [45], [0], [26], [2], [2], [35], [0]]} | introductory | https://www.codewars.com/kata/586f6741c66d18c22800010a |
def sequence_sum(begin_number, end_number, step):
|
4,242 | # Task
You're standing at the top left corner of an `n × m` grid and facing towards the `right`.
Then you start walking one square at a time in the direction you are facing.
If you reach the border of the grid or if the next square you are about to visit has already been visited, you turn right.
You stop w... | ["def direction_in_grid(n, m):\n return \"LR\"[n%2] if m >= n else \"UD\"[m%2]\n", "def direction_in_grid(n,m):\n return \"LRUD\"[n%2 if m>=n else 2+m%2]\n", "NEXT = {'R': 'D', 'D': 'L', 'L': 'U', 'U': 'R'}\n\ndef direction_in_grid(n, m, d='R'):\n while n > 1:\n n, m, d = m, n-1, NEXT[d]\n return d", "... | {"fn_name": "direction_in_grid", "inputs": [[1, 1], [2, 2], [2, 3], [2, 4], [3, 1], [3, 2], [3, 3], [3, 4], [3, 5], [4, 2], [4, 3], [4, 4], [4, 5], [4, 6], [5, 4], [5, 5], [5, 6], [100, 100]], "outputs": [["R"], ["L"], ["L"], ["L"], ["D"], ["U"], ["R"], ["R"], ["R"], ["U"], ["D"], ["L"], ["L"], ["L"], ["U"], ["R"], ["R... | introductory | https://www.codewars.com/kata/58bcd7f2f6d3b11fce000025 |
def direction_in_grid(n,m):
|
4,251 | *Recreation of [Project Euler problem #6](https://projecteuler.net/problem=6)*
Find the difference between the sum of the squares of the first `n` natural numbers `(1 <= n <= 100)` and the square of their sum.
## Example
For example, when `n = 10`:
* The square of the sum of the numbers is:
(1 + 2 + 3 + 4 + 5 + 6... | ["def difference_of_squares(x):\n r = range(1,x+1,1)\n return (sum(r) ** 2) - (sum( z**2 for z in r))", "difference_of_squares = lambda n: n ** 2 * (n + 1) ** 2 / 4 - n * (n + 1) * (2 * n + 1) / 6", "def difference_of_squares(x):\n \n # Initialize\n square_sum = 0\n sum_squares = 0\n \n # Loop o... | {"fn_name": "difference_of_squares", "inputs": [[5], [10], [100]], "outputs": [[170], [2640], [25164150]]} | introductory | https://www.codewars.com/kata/558f9f51e85b46e9fa000025 |
def difference_of_squares(n):
|
4,254 | Given a mathematical equation that has `*,+,-,/`, reverse it as follows:
```Haskell
solve("100*b/y") = "y/b*100"
solve("a+b-c/d*30") = "30*d/c-b+a"
```
More examples in test cases.
Good luck!
Please also try:
[Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9db0000f2)
[Simple remove duplicat... | ["import re\n\ndef solve(eq):\n return ''.join(reversed(re.split(r'(\\W+)', eq)))", "def solve(eq):\n #\n # implemantation takes advantage of abscence of spaces\n #\n leq = (eq.replace('*', ' * ')\n .replace('/', ' / ')\n .replace('+', ' + ')\n .replace('-', ' - ')\n ... | {"fn_name": "solve", "inputs": [["100*b/y"], ["a+b-c/d*30"], ["a*b/c+50"]], "outputs": [["y/b*100"], ["30*d/c-b+a"], ["50+c/b*a"]]} | introductory | https://www.codewars.com/kata/5aa3af22ba1bb5209f000037 |
def solve(eq):
|
4,259 | ## Task:
You have to write a function `pattern` which returns the following Pattern(See Examples) upto desired number of rows.
* Note:`Returning` the pattern is not the same as `Printing` the pattern.
### Parameters:
pattern( n , x );
^ ^ ... | ["def pattern(n, *x):\n if n < 1:\n return \"\"\n x = x[0] if x and x[0] > 0 else 1\n result = []\n for i in range(1, n + 1):\n line = \" \" * (i - 1) + str(i % 10) + \" \" * (n - i)\n result.append((line + line[::-1][1:]) + (line[1:] + line[::-1][1:]) * (x - 1))\n return \"\\n\".joi... | {"fn_name": "pattern", "inputs": [[3, 7], [15, 3], [10, -29], [5], [4, 2, 3, 5, 7, -8], [-3, 5], [-11, -1], [-9999999], [-25, -11, 9], [-25, 5, -9, 55, -8, -7, 8]], "outputs": [["1 1 1 1 1 1 1 1\n 2 2 2 2 2 2 2 2 2 2 2 2 2 2 \n 3 3 3 3 3 3 3 \n 2 2 2 2 2 2 2 2 2 2 2 2 2 2 \n1 1 1 1 1... | introductory | https://www.codewars.com/kata/5592e5d3ede9542ff0000057 |
def pattern(n, x=1, *args):
|
4,261 | # Task
A robot is standing at the `(0, 0)` point of the Cartesian plane and is oriented towards the vertical (y) axis in the direction of increasing y values (in other words, he's facing up, or north). The robot executes several commands each of which is a single positive integer. When the robot is given a positive in... | ["def robot_walk(a):\n i=3\n while(i<len(a) and a[i] < a[i-2]): i+=1\n return i<len(a)\n", "def robot_walk(a):\n return any(x <= y for x,y in zip(a[1:], a[3:]))", "def robot_walk(a):\n if len(set(a)) == 1:\n return True\n movings = []\n p = (0, 0) # x, y\n dir = (0, 1)\n for k in a: \n ... | {"fn_name": "robot_walk", "inputs": [[[4, 4, 3, 2, 2, 3]], [[7, 5, 4, 5, 2, 3]], [[10, 3, 10, 2, 5, 1, 2]], [[11, 8, 6, 6, 4, 3, 7, 2, 1]], [[5, 5, 5, 5]], [[34241, 23434, 2341]], [[9348, 2188, 9348]]], "outputs": [[true], [true], [false], [true], [true], [false], [false]]} | introductory | https://www.codewars.com/kata/58a64b48586e9828df000109 |
def robot_walk(a):
|
4,263 | For every string, after every occurrence of `'and'` and `'but'`, insert the substring `'apparently'` directly after the occurrence.
If input does not contain 'and' or 'but', return the original string. If a blank string, return `''`.
If substring `'apparently'` is already directly after an `'and'` and/or `'but'`, do ... | ["import re\n\ndef apparently(string):\n return re.sub(r'(?<=\\b(and|but)\\b(?! apparently\\b))', ' apparently', string)", "import re\napparently=lambda Q:re.sub(r'(?<=\\band|\\bbut)\\b(?! apparently\\b)',' apparently',Q)", "import re\nfrom functools import partial\n\napparently = partial(re.sub, r'(?<=\\b(and|but)\... | {"fn_name": "apparently", "inputs": [["A fast-food resteraunt down the street was grumbling my tummy but I could not go."], ["apparently"], ["and"], ["but"], ["but apparently"], ["and apparently"], ["but but but and and and"], [""], ["but and apparently apparently apparently apparently"], ["and apparentlybutactuallynot... | introductory | https://www.codewars.com/kata/5b049d57de4c7f6a6c0001d7 |
def apparently(string):
|
4,266 | ### Task
The __dot product__ is usually encountered in linear algebra or scientific computing. It's also called __scalar product__ or __inner product__ sometimes:
> In mathematics, the __dot product__, or __scalar product__ (or sometimes __inner product__ in the context of Euclidean space), is an algebraic operation t... | ["def min_dot(a, b):\n return sum(x * y for (x, y) in zip(sorted(a), sorted(b, reverse = True)))", "from numpy import dot\n\ndef min_dot(a, b):\n return dot(sorted(a), sorted(b, reverse=True))", "def min_dot(a, b):\n return sum(map(int.__mul__, sorted(a), sorted(b)[::-1]))", "def min_dot(a, b):\n a, b = sor... | {"fn_name": "min_dot", "inputs": [[[], []], [[1, 2, 3, 4, 5], [0, 1, 1, 1, 0]], [[1, 2, 3, 4, 5], [0, 0, 1, 1, -4]], [[1, 3, 5], [4, -2, 1]]], "outputs": [[0], [6], [-17], [-3]]} | introductory | https://www.codewars.com/kata/5457ea88aed18536fc000a2c |
def min_dot(a, b):
|
4,271 | We all know about Roman Numerals, and if not, here's a nice [introduction kata](http://www.codewars.com/kata/5580d8dc8e4ee9ffcb000050). And if you were anything like me, you 'knew' that the numerals were not used for zeroes or fractions; but not so!
I learned something new today: the [Romans did use fractions](https:/... | ["FRACTIONS = \" . : :. :: :.: S S. S: S:. S:: S:.:\".split(\" \")\nUNITS = \" I II III IV V VI VII VIII IX\" .split(\" \")\nTENS = \" X XX XXX XL L LX LXX LXXX XC\" .split(\" \")\nHUNDREDS = \" C CC CCC CD D DC DCC DCCC CM\" .split(\" \")\nTHOUSANDS = \" M MM MMM MMMM MMMMM\" .sp... | {"fn_name": "roman_fractions", "inputs": [[-12], [0, -1], [0, 12], [0], [1], [1, 5], [1, 9], [1632, 2], [5000], [5001], [0, 0], [0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11]], "outputs": [["NaR"], ["NaR"], ["NaR"], ["N"], ["I"], ["I:.:"], ["IS:."], ["MDCXXXII:"], ["MMMMM"], ["... | introductory | https://www.codewars.com/kata/55832eda1430b01275000059 |
def roman_fractions(integer, fraction=None):
|
4,281 | To introduce the problem think to my neighbor who drives a tanker truck.
The level indicator is down and he is worried
because he does not know if he will be able to make deliveries.
We put the truck on a horizontal ground and measured the height of the liquid in the tank.
Fortunately the tank is a perfect cylinder ... | ["import math\ndef tankvol(h, d, vt):\n r = d/2.0\n if h == r: return vt/2 # is the tank half full?\n half = h>r # is it more than half full\n h = d-h if half else h # adjust h accordingly\n a = r-h # perpendicular intercept of the chord\n b = math.sqrt(r**2-... | {"fn_name": "tankvol", "inputs": [[5, 7, 3848], [2, 7, 3848], [2, 8, 5026], [4, 9, 6361], [3, 10, 7853], [3, 5, 1963], [4, 7, 3848], [0, 7, 3848], [7, 7, 3848], [2, 5, 1963], [2, 4, 1256], [4, 10, 7853], [3, 9, 6361], [2, 10, 7853], [5, 9, 6361], [5, 6, 2827], [1, 4, 1256]], "outputs": [[2940], [907], [982], [2731], [1... | introductory | https://www.codewars.com/kata/55f3da49e83ca1ddae0000ad |
def tankvol(h, d, vt):
|
4,286 | In this Kata, you will be given a number and your task will be to return the nearest prime number.
```Haskell
solve(4) = 3. The nearest primes are 3 and 5. If difference is equal, pick the lower one.
solve(125) = 127
```
We'll be testing for numbers up to `1E10`. `500` tests.
More examples in test cases.
Good lu... | ["def solve(n):\n print('starting with {0}'.format(n), flush=True)\n\n def is_prime(p):\n if p % 2 == 0 :\n return False\n for x in range(3,int(p**.5)):\n if p % x == 0:\n return False\n return True\n #return not any([p%x==0 for x in range(3,int(p**... | {"fn_name": "solve", "inputs": [[3], [11], [4], [110], [1110], [3000], [35000], [350000], [3500000], [10000000000]], "outputs": [[3], [11], [3], [109], [1109], [2999], [34981], [350003], [3499999], [10000000019]]} | introductory | https://www.codewars.com/kata/5a9078e24a6b340b340000b8 |
def solve(n):
|
4,293 | You just got done with your set at the gym, and you are wondering how much weight you could lift if you did a single repetition. Thankfully, a few scholars have devised formulas for this purpose (from [Wikipedia](https://en.wikipedia.org/wiki/One-repetition_maximum)) :
### Epley
### McGlothin
### Lombardi
Your ... | ["def calculate_1RM(w, r):\n if r == 0: return 0\n if r == 1: return w\n \n return round(max([\n w * (1 + r / 30), # Epley\n 100 * w / (101.3 - 2.67123 * r), # McGlothin\n w * r**0.10 # Lombardi\n ]))", "def calculate_1RM(w, r):\n return (\n ... | {"fn_name": "calculate_1RM", "inputs": [[135, 20], [200, 8], [270, 2], [360, 1], [400, 0]], "outputs": [[282], [253], [289], [360], [0]]} | introductory | https://www.codewars.com/kata/595bbea8a930ac0b91000130 |
def calculate_1RM(w, r):
|
4,295 | # Definition
**_Balanced number_** is the number that * **_The sum of_** all digits to the **_left of the middle_** digit(s) and the sum of all digits to the **_right of the middle_** digit(s) are **_equal_***.
____
# Task
**_Given_** a number, **_Find if it is Balanced or not_** .
____
# Warm-up (Highly recommen... | ["def balancedNum(n):\n s = str(n)\n l = (len(s)-1)//2\n same = len(s) < 3 or sum(map(int, s[:l])) == sum(map(int, s[-l:]))\n return \"Balanced\" if same else \"Not Balanced\"\n\nbalanced_num = balancedNum", "def balanced_num(number):\n number = [int(n) for n in str(number)]\n left, right = 0, 0\n \n... | {"fn_name": "balanced_num", "inputs": [[56239814]], "outputs": [["Balanced"]]} | introductory | https://www.codewars.com/kata/5a4e3782880385ba68000018 |
def balanced_num(number):
|
4,300 | In this Kata, you will count the number of times the first string occurs in the second.
```Haskell
solve("zaz","zazapulz") = 4 because they are ZAZapulz, ZAzapulZ, ZazApulZ, zaZApulZ
```
More examples in test cases.
Good luck!
Please also try [Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9... | ["def solve(a, b):\n if len(a) is 1:\n return b.count(a)\n index = [x for x in range(len(b)-1) if b[x] is a[0]]\n return sum(solve(a[1:], b[x+1:]) for x in index)", "def solve(a, b, i=0, j=0):\n return i == len(a) or sum(solve(a,b,i+1,x+1) for x in range(j, len(b)-(len(a)-i-1)) if a[i] == b[x])", "fr... | {"fn_name": "solve", "inputs": [["zaz", "zazapulz"], ["rat", "ratatoulie"], ["kata", "katakatak"], ["code", "codeodecode"], ["kata", "kataxxxxkatak"], ["code", "cozzdezodeczzode"], ["zaaz", "zazaapulz"], ["defg", "dsedsfsgsg"], ["defg", "dvsxvevdvsvfvsvgvsvgg"]], "outputs": [[4], [3], [7], [11], [7], [11], [4], [2], [3... | introductory | https://www.codewars.com/kata/5a942c461a60f677730032df |
def solve(a, b):
|
4,301 | The Menger Sponge is a three-dimensional fractal, first described by Karl Menger in 1926.

###### _An illustration of the iterative construction of a Menger sponge_
A method of constructing a Menger Sponge can be visualized as follows:
1. Start from a cube ... | ["def calc_ms(n):\n return 20 ** n", "def calc_ms(n):\n return pow(20,n)", "calc_ms = (20).__pow__", "from functools import partial\n\ncalc_ms = partial(pow, 20)", "from functools import partial\nfrom operator import pow\n\ncalc_ms = partial(pow, 20)", "def calc_ms(n):\n a = n * '0'\n return int(str(pow(2, n)) + ... | {"fn_name": "calc_ms", "inputs": [[0], [1], [2], [3], [4], [5], [6]], "outputs": [[1], [20], [400], [8000], [160000], [3200000], [64000000]]} | introductory | https://www.codewars.com/kata/59d28768a25c8c51a6000057 |
def calc_ms(n):
|
4,311 | Consider the range `0` to `10`. The primes in this range are: `2, 3, 5, 7`, and thus the prime pairs are: `(2,2), (2,3), (2,5), (2,7), (3,3), (3,5), (3,7),(5,5), (5,7), (7,7)`.
Let's take one pair `(2,7)` as an example and get the product, then sum the digits of the result as follows: `2 * 7 = 14`, and `1 + 4 = 5`. W... | ["import itertools\n\ndef solve(a, b):\n primes = set([2] + [n for n in range(3, b, 2) if all(n % r for r in range(3, int(n**0.5)+1, 2))])\n return sum( sum(map(int, str(x*y))) in primes for x, y in itertools.combinations_with_replacement([p for p in primes if a <= p < b], 2) )", "from bisect import bisect_left\n... | {"fn_name": "solve", "inputs": [[0, 20], [2, 200], [2, 2000], [1000, 3000], [2000, 5000]], "outputs": [[14], [457], [17705], [12801], [25005]]} | introductory | https://www.codewars.com/kata/59b46276afcda204ed000094 |
def solve(a, b):
|
4,313 | Your company, [Congo Pizza](http://interesting-africa-facts.com/Africa-Landforms/Congo-Rainforest-Facts.html), is the second-largest online frozen pizza retailer. You own a number of international warehouses that you use to store your frozen pizzas, and you need to figure out how many crates of pizzas you can store at ... | ["def box_capacity(length, width, height):\n return (length * 12 // 16) * (width * 12 // 16) * (height * 12 // 16)\n", "def box_capacity(l, w, h):\n return ((l * 3) // 4) * ((w * 3) // 4) * ((h * 3) // 4)\n", "def box_capacity(length, width, height):\n # Your code here.\n length_capacity = (length * 12) // ... | {"fn_name": "box_capacity", "inputs": [[32, 64, 16], [20, 20, 20], [80, 40, 20], [70, 60, 15], [90, 7, 5], [53, 21, 13]], "outputs": [[13824], [3375], [27000], [25740], [1005], [5265]]} | introductory | https://www.codewars.com/kata/5862e7c63f8628a126000e18 |
def box_capacity(length, width, height):
|
4,314 | # Task
In ChessLand there is a small but proud chess bishop with a recurring dream.
In the dream the bishop finds itself on an `n × m` chessboard with mirrors along each edge, and it is not a bishop but a ray of light. This ray of light moves only along diagonals (the bishop can't imagine any other types of moves ... | ["def chess_bishop_dream(b,p,d,k):\n yq,yr=divmod(p[0]+k*d[0],2*b[0])\n xq,xr=divmod(p[1]+k*d[1],2*b[1])\n return [min(yr, 2*b[0]-yr-1), min(xr, 2*b[1]-xr-1)]", "chess_bishop_dream=lambda b,p,d,k:[c-abs((q+k*e)%(2*c)-c+.5)-.5for c,q,e in zip(b,p,d)]", "def chess_bishop_dream(board_size, init_position, init_dir... | {"fn_name": "chess_bishop_dream", "inputs": [[[3, 7], [1, 2], [-1, 1], 13], [[1, 2], [0, 0], [1, 1], 6], [[2, 2], [1, 0], [1, 1], 12], [[1, 1], [0, 0], [1, -1], 1000000000], [[2, 3], [1, 2], [-1, -1], 41], [[17, 19], [14, 8], [1, -1], 239239], [[17, 19], [16, 18], [1, 1], 239239239]], "outputs": [[[0, 1]], [[0, 1]], [[... | introductory | https://www.codewars.com/kata/5897ea323387497f460001a0 |
def chess_bishop_dream(board_size, init_position, init_direction, k):
|
4,316 | # Do you speak retsec?
You and your friends want to play undercover agents. In order to exchange your *secret* messages, you've come up with the following system: you take the word, cut it in half, and place the first half behind the latter. If the word has an uneven number of characters, you leave the middle at its pr... | ["def reverse_by_center(s):n=len(s)//2;return s[-n:]+s[n:-n]+s[:n]", "import re\n\ndef reverse_by_center(s):\n half = len(s) // 2\n return re.sub(\"(.{%s})(.?)(.{%s})\" % (half, half), r\"\\3\\2\\1\", s)", "def reverse_by_center(s):\n q, r = divmod(len(s), 2)\n return s[-q:] + s[q:q+r] + s[:q]", "def revers... | {"fn_name": "reverse_by_center", "inputs": [["secret"], ["agent"], ["raw"], ["onion"]], "outputs": [["retsec"], ["nteag"], ["war"], ["onion"]]} | introductory | https://www.codewars.com/kata/5516ab668915478845000780 |
def reverse_by_center(s):
|
4,320 | Write a comparator for a list of phonetic words for the letters of the [greek alphabet](https://en.wikipedia.org/wiki/Greek_alphabet).
A comparator is:
> *a custom comparison function of two arguments (iterable elements) which should return a negative, zero or positive number depending on whether the first argument is... | ["def greek_comparator(lhs, rhs):\n greek_alphabet = [\n 'alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta',\n 'eta', 'theta', 'iota', 'kappa', 'lambda', 'mu',\n 'nu', 'xi', 'omicron', 'pi', 'rho', 'sigma',\n 'tau', 'upsilon', 'phi', 'chi', 'psi', 'omega']\n l = len(greek_alphabet)\n... | {"fn_name": "greek_comparator", "inputs": [["chi", "chi"]], "outputs": [[0]]} | introductory | https://www.codewars.com/kata/56bc1acf66a2abc891000561 |
def greek_comparator(lhs, rhs):
|
4,327 | **Story**
On some island lives a chameleon population. Chameleons here can be of only one of three colors - red, green and blue. Whenever two chameleons of different colors meet, they can change their colors to a third one (i.e. when red and blue chameleons meet, they can both become green). There is no other way for... | ["def chameleon(chameleons, color):\n (_,a), (_,b), (_,c) = sorted((i==color, v) for i,v in enumerate(chameleons))\n return -1 if not a and not c or (b-a) % 3 else b", "def chameleon(chameleons, desiredColor):\n \n color_count = dict(list(zip(['r', 'g', 'b'], chameleons)))\n target = ['r', 'g', 'b'][desi... | {"fn_name": "chameleon", "inputs": [[[0, 0, 17], 1], [[1, 1, 15], 2], [[34, 32, 35], 0], [[34, 32, 35], 1], [[33, 0, 35], 2], [[673905669, 673905681, 174867657], 2], [[74356, 0, 0], 0], [[1, 2147483646, 1], 1], [[0, 1, 0], 2], [[0, 1, 0], 1], [[0, 333, 0], 0]], "outputs": [[-1], [1], [35], [-1], [33], [673905681], [0],... | introductory | https://www.codewars.com/kata/553ba31138239b9bc6000037 |
def chameleon(chameleons, desiredColor):
|
4,332 | *This kata is based on [Project Euler Problem #349](https://projecteuler.net/problem=349). You may want to start with solving [this kata](https://www.codewars.com/kata/langtons-ant) first.*
---
[Langton's ant](https://en.wikipedia.org/wiki/Langton%27s_ant) moves on a regular grid of squares that are coloured either b... | ["move = [lambda p: (p[0]+1, p[1]), lambda p: (p[0], p[1]+1), lambda p: (p[0]-1, p[1]), lambda p: (p[0], p[1]-1)]\nstart, loop, size = 9977, 104, 12\n\ndef langtons_ant(n):\n pos, d, black, res = (0, 0), 0, set(), 0\n if n > start:\n x = (n - start)%loop\n res = size * (n-start-x)//loop\n n =... | {"fn_name": "langtons_ant", "inputs": [[0], [1], [2], [10], [100], [1000], [10000], [100000], [1000000], [10000000]], "outputs": [[0], [1], [2], [6], [20], [118], [720], [11108], [114952], [1153412]]} | introductory | https://www.codewars.com/kata/5c99553d5c67244b60cb5722 |
def langtons_ant(n):
|
4,336 | *Shamelessly stolen from Here :)*
Your server has sixteen memory banks; each memory bank can hold any number of blocks. You must write a routine to balance the blocks between the memory banks.
The reallocation routine operates in cycles. In each cycle, it finds the memory bank with the most blocks (ties won by the lo... | ["def mem_alloc(banks):\n seen = set()\n while tuple(banks) not in seen:\n seen.add(tuple(banks))\n number = max(banks)\n index = banks.index(number)\n banks[index] = 0\n while number:\n index = (index + 1) % 16\n banks[index] += 1\n number -= 1\... | {"fn_name": "mem_alloc", "inputs": [[[5, 1, 10, 0, 1, 7, 13, 14, 3, 12, 8, 10, 7, 12, 0, 600]], [[53, 21, 10, 0, 1, 7, 13, 14, 3, 12, 8, 10, 7, 12, 0, 60]], [[14, 21, 10, 0, 1, 7, 0, 14, 3, 12, 8, 10, 17, 12, 0, 19]], [[5, 1, 10, 0, 1, 7, 13, 14, 3, 12, 8, 10, 7, 12, 0, 6]], [[17, 17, 3, 5, 1, 10, 6, 2, 0, 12, 8, 11, 1... | introductory | https://www.codewars.com/kata/5ad927c932d79e34fb000091 |
def mem_alloc(banks):
|
4,339 | Implement function which will return sum of roots of a quadratic equation rounded to 2 decimal places, if there are any possible roots, else return **None/null/nil/nothing**. If you use discriminant,when discriminant = 0, x1 = x2 = root => return sum of both roots. There will always be valid arguments.
Quadratic equa... | ["def roots(a,b,c):\n if b**2>=4*a*c:\n return round(-b/a,2)", "def roots(a,b,c):\n import math\n d = b ** 2 - 4 * a * c\n if d > 0:\n return round(-2 * b / (2 * a), 2)\n elif d == 0:\n x = -b / (2 * a)\n return x * 2\n else:\n return None", "def roots(a,b,c):\n r... | {"fn_name": "roots", "inputs": [[1, -35, -23], [6, 0, -24], [-5, 21, 0], [6, 4, 8], [1, 5, -24], [3, 11, 6], [2, 2, 9], [1, -1.6666666666666667, -26], [1, 6, 10], [7, -2, -5], [1, 8, 20], [2, 3, -2], [1, 4, 12], [3, -2, -5], [3, 4, 9], [5, 4, 0], [4, -5, 0], [1, 4, 9], [1, 0, -49], [2, 8, 8], [1, 0, -0.16], [1, 6, 12],... | introductory | https://www.codewars.com/kata/57d448c6ba30875437000138 |
def roots(a,b,c):
|
4,341 | In this Kata, you will be given two positive integers `a` and `b` and your task will be to apply the following operations:
```
i) If a = 0 or b = 0, return [a,b]. Otherwise, go to step (ii);
ii) If a ≥ 2*b, set a = a - 2*b, and repeat step (i). Otherwise, go to step (iii);
iii) If b ≥ 2*a, set b = b - 2*a, and repeat ... | ["def solve(a,b):\n if not (a and b): return [a, b]\n if a >= 2*b: return solve(a%(2*b), b)\n if b >= 2*a: return solve(a, b%(2*a))\n return [a, b]", "def solve(a,b):\n '''\n Used the % operator instead of repeated subtraction of a - 2*b or b - 2*a\n Because as long as a > 2*b, the repeated subtrac... | {"fn_name": "solve", "inputs": [[6, 19], [2, 1], [22, 5], [2, 10], [8796203, 7556], [7, 11], [19394, 19394]], "outputs": [[[6, 7]], [[0, 1]], [[0, 1]], [[2, 2]], [[1019, 1442]], [[7, 11]], [[19394, 19394]]]} | introductory | https://www.codewars.com/kata/5b752a42b11814b09c00005d |
def solve(a,b):
|
4,348 | Just another day in the world of Minecraft, Steve is getting ready to start his next exciting project -- building a railway system!

But first, Steve needs to melt some iron ores in the furnace to get the m... | ["t = ((800, \"lava\"), (120, \"blaze rod\"), (80, \"coal\"), (15, \"wood\"), (1, \"stick\"))\n\n\ndef calc_fuel(n):\n s, r = n * 11, {}\n for d, e in t:\n r[e], s = divmod(s, d)\n return r", "def calc_fuel(n):\n time = n * 11\n lava, blaze = divmod(time, 800)\n blaze, coal = divmod(blaze, 120)... | {"fn_name": "calc_fuel", "inputs": [[37], [21], [123]], "outputs": [[{"lava": 0, "blaze rod": 3, "coal": 0, "wood": 3, "stick": 2}], [{"lava": 0, "blaze rod": 1, "coal": 1, "wood": 2, "stick": 1}], [{"lava": 1, "blaze rod": 4, "coal": 0, "wood": 4, "stick": 13}]]} | introductory | https://www.codewars.com/kata/583a02740b0a9fdf5900007c |
def calc_fuel(n):
|
4,353 | The objective is to disambiguate two given names: the original with another
Let's start simple, and just work with plain ascii strings.
The function ```could_be``` is given the original name and another one to test
against.
```python
# should return True if the other name could be the same person
> could_be("Chuc... | ["def could_be(original, another):\n if not another.strip(): return False\n return all(name in original.split() for name in another.split())", "def could_be(original, another):\n original, another = (set(s.split()) for s in (original, another))\n return bool(another) and another <= original", "def could_be(... | {"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/580a429e1cb4028481000019 |
def could_be(original, another):
|
4,355 | ## Euler's Method
We want to calculate the shape of an unknown curve which starts at a given point
with a given slope. This curve satisfies an ordinary differential equation (ODE):
```math
\frac{dy}{dx} = f(x, y);\\
y(x_0) = y_0
```
The starting point `$ A_0 (x_0, y_0) $` is known as well as the slope to the curve ... | ["from math import floor, exp\n \ndef ex_euler(n):\n # fct to study\n F = lambda t,y : 2 - exp(-4 * t) - 2 * y\n # initial conditions\n t0 = 0; y0 = 1; # pt A0\n T = 1; \n # variables\n h = T / float(n); X = [t0]; Y = [y0]; Z = []; R = []\n # points A1 ... An\n for k in range(0, n):\n ... | {"fn_name": "ex_euler", "inputs": [[1], [10], [17], [50], [100], [200], [400], [800], [1000], [1200], [1500], [2000]], "outputs": [[0.5], [0.026314], [0.015193], [0.005073], [0.002524], [0.001259], [0.000628], [0.000314], [0.000251], [0.000209], [0.000167], [0.000125]]} | introductory | https://www.codewars.com/kata/56347fcfd086de8f11000014 |
def ex_euler(n):
|
4,357 | # Introduction and Warm-up (Highly recommended)
# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
___
# Task
**_Given_** an *array/list [] of integers* , **_Find_** *the Nth smallest element in this array of integers*
___
# Notes
* **_Array/list_** size is... | ["def nth_smallest(arr, pos):\n return sorted(arr)[pos-1] # Gotta love Python", "def nth_smallest(arr, pos):\n return sorted(arr)[pos-1]", "from heapq import nsmallest\ndef nth_smallest(arr, pos):\n return nsmallest(pos, arr)[-1]", "def nth_smallest(arr, pos):\n arr.sort()\n return arr[pos-1]", "\"\"\"\n... | {"fn_name": "nth_smallest", "inputs": [[[3, 1, 2], 2], [[15, 20, 7, 10, 4, 3], 3], [[-5, -1, -6, -18], 4], [[-102, -16, -1, -2, -367, -9], 5], [[2, 169, 13, -5, 0, -1], 4]], "outputs": [[2], [7], [-1], [-2], [2]]} | introductory | https://www.codewars.com/kata/5a512f6a80eba857280000fc |
def nth_smallest(arr, pos):
|
4,366 | #It's show time!
Archers have gathered from all around the world to participate in the Arrow Function Faire. But the faire will only start if there are archers signed and if they all have enough arrows in their quivers - at least 5 is the requirement! Are all the archers ready?
#Reference
https://developer.mozilla.org... | ["def archers_ready(archers):\n return all(i >= 5 for i in archers) if archers else False", "def archers_ready(archers):\n return len(archers) > 0 and all(a > 4 for a in archers)", "def archers_ready(archers):\n try:\n return min(archers)>=5\n except:\n return False", "def archers_ready(archer... | {"fn_name": "archers_ready", "inputs": [[[]], [[1, 2, 3, 4]], [[5, 6, 7, 8]], [[5, 6, 7, 4]], [[1, 2, 3, 4, 5, 6, 7, 8]]], "outputs": [[false], [false], [true], [false], [false]]} | introductory | https://www.codewars.com/kata/559f89598c0d6c9b31000125 |
def archers_ready(archers):
|
4,381 | We define the "unfairness" of a list/array as the *minimal* difference between max(x1,x2,...xk) and min(x1,x2,...xk), for all possible combinations of k elements you can take from the list/array; both minimum and maximum of an empty list/array are considered to be 0.
**More info and constraints:**
* lists/arrays can ... | ["def min_unfairness(arr,k):\n arr = sorted(arr)\n return min(b - a for a, b in zip(arr, arr[k-1:])) if arr and k else 0", "def min_unfairness(arr,k):\n if len(arr) < 2 or k < 2:\n return 0\n t = sorted(arr)\n diff = float('inf')\n for i in range(len(t)-k+1):\n x= t[i+k-1]-t[i]\n ... | {"fn_name": "min_unfairness", "inputs": [[[30, 100, 1000, 150, 60, 250, 10, 120, 20], 3], [[30, 100, 1000, 150, 60, 250, 10, 120, 20], 5], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2], 10], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2], 9], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 10], [[1, 1, -1]... | introductory | https://www.codewars.com/kata/577bcb5dd48e5180030004de |
def min_unfairness(arr,k):
|
4,386 | # Right in the Center
_This is inspired by one of Nick Parlante's exercises on the [CodingBat](https://codingbat.com/java) online code practice tool._
Given a sequence of characters, does `"abc"` appear in the CENTER of the sequence?
The sequence of characters could contain more than one `"abc"`.
To define CENTER, ... | ["def is_in_middle(s):\n while len(s)>4:\n s = s[1:-1]\n return 'abc' in s", "def is_in_middle(seq):\n mid, rem = divmod(len(seq), 2)\n start = mid-1\n end = start+3\n \n if not rem: \n start -= 1\n \n return 'abc' in seq[start:end]\n", "def is_in_middle(s):\n return is_in_mi... | {"fn_name": "is_in_middle", "inputs": [["abc"], ["abcabcabc"], ["AAabcBBB"], ["AAAabcBB"], ["AAAAabcBB"], ["AAabcabcBB"], ["abcabcabcabc"], ["AabcBBB"], [""], ["ABC"], ["abcZ"], ["Yabc"]], "outputs": [[true], [true], [true], [true], [false], [false], [false], [false], [false], [false], [true], [true]]} | introductory | https://www.codewars.com/kata/5f5da7a415fbdc0001ae3c69 |
def is_in_middle(s):
|
4,390 | 
The other day I saw an amazing video where a guy hacked some wifi controlled lightbulbs by flying a drone past them. Brilliant.
In this kata we will recreate that stunt... sort of.
You will be given two strings: `lamps` and `drone`. `lamps` represents ... | ["def fly_by(lamps, drone):\n return lamps.replace('x', 'o', drone.count('=') + 1)", "def fly_by(lamps, drone):\n l = len(lamps)\n d = len(drone)\n if d >= l:\n return 'o'* l\n return ('o' * d) + ('x' * (l - d))", "def fly_by(lamps, drone):\n newlamps = []\n for x in lamps:\n newlamps... | {"fn_name": "fly_by", "inputs": [["xxxxxx", "====T"], ["xxxxxxxxx", "==T"], ["xxxxxxxxxxxxxxx", "=========T"]], "outputs": [["ooooox"], ["oooxxxxxx"], ["ooooooooooxxxxx"]]} | introductory | https://www.codewars.com/kata/58356a94f8358058f30004b5 |
def fly_by(lamps, drone):
|
4,399 | # Task
The function `fold_cube(number_list)` should return a boolean based on a net (given as a number list), if the net can fold into a cube.
Your code must be effecient and complete the tests within 500ms.
## Input
Imagine a net such as the one below.
```
@
@ @ @ @
@
```
Then, put it on the table with each ... | ["def fold_cube(nums):\n return expand(nums.pop(), set(nums), 1, 2, 3) == {1, 2, 3, -1, -2, -3}\n\n\ndef expand(val, nums, x, y, z):\n dirs = {z}\n for num in nums.copy():\n if abs(val - num) not in (1, 5) or {val % 5, num % 5} == {0, 1}:\n continue\n\n nums.discard(num)\n diff ... | {"fn_name": "fold_cube", "inputs": [[[24, 20, 14, 19, 18, 9]], [[1, 7, 6, 17, 12, 16]], [[12, 14, 13, 9, 10, 6]], [[18, 16, 17, 15, 13, 14]], [[1, 25, 24, 2, 3, 16]], [[1, 1, 1, 1, 1, 1]], [[2, 3, 8, 9, 10, 13]]], "outputs": [[true], [false], [false], [true], [false], [false], [true]]} | introductory | https://www.codewars.com/kata/5f2ef12bfb6eb40019cc003e |
def fold_cube(nums):
|
4,400 | # Task
**_Given_** *an array of N integers, you have to find* **_how many times_** *you have to* **_add up the smallest numbers_** *in the array until* **_their Sum_** *becomes greater or equal to* **_K_**.
___
# Notes:
* **_List size_** is *at least 3*.
* **_All numbers_** *will be* **_positive_**.
* **_Num... | ["def minimum_steps(arr, n):\n arr = sorted(arr)\n s = 0\n for i,v in enumerate(arr): \n s += v\n if s >= n: return i", "from itertools import accumulate\n\ndef minimum_steps(numbers, value):\n return next(i for i, s in enumerate(accumulate(sorted(numbers))) if s >= value)", "def minimum_steps... | {"fn_name": "minimum_steps", "inputs": [[[4, 6, 3], 7], [[10, 9, 9, 8], 17], [[8, 9, 10, 4, 2], 23], [[19, 98, 69, 28, 75, 45, 17, 98, 67], 464], [[4, 6, 3], 2]], "outputs": [[1], [1], [3], [8], [0]]} | introductory | https://www.codewars.com/kata/5a91a7c5fd8c061367000002 |
def minimum_steps(numbers, value):
|
4,409 | Spoonerize... with numbers... numberize?... numboonerize?... noonerize? ...anyway! If you don't yet know what a spoonerism is and haven't yet tried my spoonerism kata, please do [check it out](http://www.codewars.com/kata/spoonerize-me) first.
You will create a function which takes an array of two positive integers, ... | ["def noonerize(numbers):\n \n try:\n num1 = int(str(numbers[1])[0] + str(numbers[0])[1:])\n num2 = int(str(numbers[0])[0] + str(numbers[1])[1:])\n except ValueError:\n return \"invalid array\"\n \n return abs(num1 - num2)", "def noonerize(numbers):\n if not all(isinstance(n, ... | {"fn_name": "noonerize", "inputs": [[[12, 34]], [[55, 63]], [[357, 579]], [[1000000, 9999999]], [[1000000, "hello"]], [["pippi", 9999999]], [["pippi", "hello"]], [[1, 1]], [[1, 0]], [[0, 1]]], "outputs": [[18], [12], [178], [7000001], ["invalid array"], ["invalid array"], ["invalid array"], [0], [1], [1]]} | introductory | https://www.codewars.com/kata/56dbed3a13c2f61ae3000bcd |
def noonerize(numbers):
|
4,417 | Consider the prime number `23`. If we sum the square of its digits we get:
`2^2 + 3^2 = 13`, then for `13: 1^2 + 3^2 = 10`, and finally for `10: 1^2 + 0^2 = 1`.
Similarly, if we start with prime number `7`, the sequence is: `7->49->97->130->10->1`.
Given a range, how many primes within that range will eventually end... | ["def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n sqrtn = int(n**0.5) + 1\n for i in range(5, sqrtn, 6):\n if n % i == 0 or n % (i + 2) == 0:\n return False\n return True\n\ndef end_one(n):\n... | {"fn_name": "solve", "inputs": [[1, 25], [100, 1000], [100, 2000], [100, 3000], [100, 4000]], "outputs": [[4], [28], [47], [65], [95]]} | introductory | https://www.codewars.com/kata/59aa6567485a4d03ff0000ca |
def solve(a,b):
|
4,418 | This is a follow-up from my previous Kata which can be found here: http://www.codewars.com/kata/5476f4ca03810c0fc0000098
This time, for any given linear sequence, calculate the function [f(x)] and return it as a function in Javascript or Lambda/Block in Ruby.
For example:
```python
get_function([0, 1, 2, 3, 4])(5) =... | ["def get_function(sequence):\n slope = sequence[1] - sequence[0]\n for x in range(1,5):\n if sequence[x] - sequence[x-1] != slope:\n return \"Non-linear sequence\"\n \n return lambda a : slope * a + sequence[0]", "def get_function(sequence):\n first, dist = sequence[0], sequence[1] - seq... | {"fn_name": "get_function", "inputs": [[[1, 2, 4, 7, 11]], [[0, 1, 2, 3, 100000]], [[0, 1, 2, 100000, 4]], [[0, 1, 100000, 3, 4]], [[0, 100000, 2, 3, 4]]], "outputs": [["Non-linear sequence"], ["Non-linear sequence"], ["Non-linear sequence"], ["Non-linear sequence"], ["Non-linear sequence"]]} | introductory | https://www.codewars.com/kata/54784a99b5339e1eaf000807 |
def get_function(sequence):
|
4,419 | Perhaps it would be convenient to solve first ```Probabilities for Sums in Rolling Cubic Dice``` see at: http://www.codewars.com/kata/probabilities-for-sums-in-rolling-cubic-dice
Suppose that we roll dice that we never used, a tetrahedral die that has only 4 sides(values 1 to 4), or perhaps better the dodecahedral one... | ["def reg_sum_hits(dices,sides=6):\n d,s = sides*[1],sides-1\n for i in range(dices-1):\n t = s*[0] + d + s*[0]\n d = [sum(t[i:i+sides]) for i in range(len(t)-s)]\n return [[i+dices, prob] for (i,prob) in enumerate(d)]", "reg_sum_hits=lambda n,s:sorted(map(list,__import__('collections').Counter(m... | {"fn_name": "reg_sum_hits", "inputs": [[3, 4], [4, 4], [3, 6], [4, 6]], "outputs": [[[[3, 1], [4, 3], [5, 6], [6, 10], [7, 12], [8, 12], [9, 10], [10, 6], [11, 3], [12, 1]]], [[[4, 1], [5, 4], [6, 10], [7, 20], [8, 31], [9, 40], [10, 44], [11, 40], [12, 31], [13, 20], [14, 10], [15, 4], [16, 1]]], [[[3, 1], [4, 3], [5,... | introductory | https://www.codewars.com/kata/56f852635d7c12fb610013d7 |
def reg_sum_hits(n, s):
|
4,424 | # Task
* **_Given_** *three integers* `a` ,`b` ,`c`, **_return_** *the **_largest number_** obtained after inserting the following operators and brackets*: `+`, `*`, `()`
* In other words , **_try every combination of a,b,c with [*+()] , and return the Maximum Obtained_**
___
# Consider an Example :
**_With the numbe... | ["def expression_matter(a, b, c):\n return max(a*b*c, a+b+c, (a+b)*c, a*(b+c))", "def expression_matter(a, b, c):\n return max(a + b + c, (a + b) * c, a * (b + c), a * b * c)", "def expression_matter(a, b, c):\n cases = [a + b + c]\n cases.append(a * b * c)\n cases.append((a * b) + c)\n cases.append(... | {"fn_name": "expression_matter", "inputs": [[2, 1, 2], [2, 1, 1], [1, 1, 1], [1, 2, 3], [1, 3, 1], [2, 2, 2], [5, 1, 3], [3, 5, 7], [5, 6, 1], [1, 6, 1], [2, 6, 1], [6, 7, 1], [2, 10, 3], [1, 8, 3], [9, 7, 2], [1, 1, 10], [9, 1, 1], [10, 5, 6], [1, 10, 1]], "outputs": [[6], [4], [3], [9], [5], [8], [20], [105], [35], [... | introductory | https://www.codewars.com/kata/5ae62fcf252e66d44d00008e |
def expression_matter(a, b, c):
|
4,433 | Your task is to calculate logical value of boolean array. Test arrays are one-dimensional and their size is in the range 1-50.
Links referring to logical operations: [AND](https://en.wikipedia.org/wiki/Logical_conjunction), [OR](https://en.wikipedia.org/wiki/Logical_disjunction) and [XOR](https://en.wikipedia.org/wiki... | ["import operator\nfrom functools import reduce\n\nOPS = {\n \"AND\": operator.and_,\n \"OR\" : operator.or_,\n \"XOR\": operator.xor\n}\n\ndef logical_calc(array, op):\n return reduce(OPS[op], array)\n", "from operator import and_, or_, xor\nfrom functools import reduce\n\nOPERATOR = {'AND': and_, 'OR': or... | {"fn_name": "logical_calc", "inputs": [[[true, true, true, false], "AND"], [[true, true, true, false], "OR"], [[true, true, true, false], "XOR"], [[true, true, false, false], "AND"], [[true, true, false, false], "OR"], [[true, true, false, false], "XOR"], [[true, false, false, false], "AND"], [[true, false, false, fals... | introductory | https://www.codewars.com/kata/57096af70dad013aa200007b |
def logical_calc(array, op):
|
4,435 | Similarly to the [previous kata](https://www.codewars.com/kata/string-subpattern-recognition-i/), you will need to return a boolean value if the base string can be expressed as the repetition of one subpattern.
This time there are two small changes:
* if a subpattern has been used, it will be repeated at least twice,... | ["from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\ndef has_subpattern(string):\n return reduce(gcd, Counter(string).values()) != 1", "from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\ndef has_subpattern(s):\n return reduce(gcd, Counter(s).... | {"fn_name": "has_subpattern", "inputs": [["a"], ["aaaa"], ["abcd"], ["babababababababa"], ["ababababa"], ["123a123a123a"], ["123A123a123a"], ["12aa13a21233"], ["12aa13a21233A"], ["abcdabcaccd"]], "outputs": [[false], [true], [false], [true], [false], [true], [false], [true], [false], [false]]} | introductory | https://www.codewars.com/kata/5a4a391ad8e145cdee0000c4 |
def has_subpattern(string):
|
4,441 | Lot of junior developer can be stuck when they need to change the access permission to a file or a directory in an Unix-like operating systems.
To do that they can use the `chmod` command and with some magic trick they can change the permissionof a file or a directory. For more information about the `chmod` command yo... | ["def chmod_calculator(perm):\n perms = { \"r\": 4, \"w\": 2, \"x\": 1 }\n value = \"\"\n for permission in [\"user\", \"group\", \"other\"]:\n value += str(sum(perms.get(x, 0) for x in perm.get(permission, \"\")))\n \n return value", "def chmod_calculator(perm): \n return str(sum([wbin(... | {"fn_name": "chmod_calculator", "inputs": [[{"user": "rwx", "group": "r-x", "other": "r-x"}], [{"user": "rwx", "group": "r--", "other": "r--"}], [{"user": "r-x", "group": "r-x", "other": "---"}], [{"group": "rwx"}], [{}]], "outputs": [["755"], ["744"], ["550"], ["070"], ["000"]]} | introductory | https://www.codewars.com/kata/57f4ccf0ab9a91c3d5000054 |
def chmod_calculator(perm):
|
4,445 | [Haikus](https://en.wikipedia.org/wiki/Haiku_in_English) are short poems in a three-line format, with 17 syllables arranged in a 5–7–5 pattern. Your task is to check if the supplied text is a haiku or not.
### About syllables
[Syllables](https://en.wikipedia.org/wiki/Syllable) are the phonological building blocks of... | ["import re\n\nPATTERN = re.compile(r'[aeyuio]+[^aeyuio ]*((?=e\\b)e)?', flags=re.I)\n\n\ndef is_haiku(text):\n return [5,7,5] == [check(s) for s in text.split(\"\\n\")]\n \ndef check(s):\n return sum(1 for _ in PATTERN.finditer(s))\n", "import re\n\ndef is_haiku(text):\n def count_syllables(line):\n ... | {"fn_name": "is_haiku", "inputs": [["An old silent pond...\nA frog jumps into the pond,\nsplash! Silence again."], ["An old silent pond...\nA frog jumps into the pond, splash!\nSilence again."], ["An old silent pond...\nA frog jumps into the pond,\nsplash!\nSilence again."], ["An old silent pond... A frog jumps into th... | introductory | https://www.codewars.com/kata/5c765a4f29e50e391e1414d4 |
def is_haiku(text):
|
4,448 | I need some help with my math homework. I have a number of problems I need to return the derivative for.
They will all be of the form:
ax^b,
A and B are both integers, but can be positive or negative.
Note:
- if b is 1, then the equation will be ax.
- if b is 0, then the equation will be 0.
Examples:
... | ["def get_derivative(s):\n if '^' in s:\n f,t = map(int, s.split('x^'))\n return '{}x'.format(f*t) if t==2 else '{}x^{}'.format(f*t, t-1)\n elif 'x' in s: return s[:-1]\n else: return '0'", "def get_derivative(s):\n if 'x' not in s: return '0'\n if '^' not in s: return s.replace('x', '')\n ... | {"fn_name": "get_derivative", "inputs": [["3x^3"], ["3x^2"], ["3x"], ["3"], ["3x^-1"], ["-3x^-1"], ["-3x^10"], ["-954x^2"]], "outputs": [["9x^2"], ["6x"], ["3"], ["0"], ["-3x^-2"], ["3x^-2"], ["-30x^9"], ["-1908x"]]} | introductory | https://www.codewars.com/kata/5a0350c380171ffd7b00012a |
def get_derivative(s):
|
4,462 | ## Task
**_Given_** *an array of integers* , **_Find_** **_the maximum product_** *obtained from multiplying 2 adjacent numbers in the array*.
____
# Notes
* **_Array/list_** size is *at least 2*.
* **_Array/list_** numbers could be a *mixture of positives, negatives also zeroes* .
___
# Input >> Output Examples
`... | ["def adjacent_element_product(array):\n return max( a*b for a, b in zip(array, array[1:]) )", "def adjacent_element_product(array):\n return max(array[i]*array[i+1] for i in range(len(array)-1))", "def adjacent_element_product(array):\n return max(x * y for x, y in zip(array, array[1:]))\n", "from operator im... | {"fn_name": "adjacent_element_product", "inputs": [[[5, 8]], [[5, 1, 1, 8]], [[1, 2, 3]], [[1, 5, 10, 9]], [[4, 12, 3, 1, 5]], [[5, 1, 2, 3, 1, 4]], [[3, 6, -2, -5, 7, 3]], [[9, 5, 10, 2, 24, -1, -48]], [[5, 6, -4, 2, 3, 2, -23]], [[-23, 4, -5, 99, -27, 329, -2, 7, -921]], [[1, 0, 1, 0, 1000]], [[1, 2, 3, 0]]], "output... | introductory | https://www.codewars.com/kata/5a4138acf28b82aa43000117 |
def adjacent_element_product(array):
|
4,475 | If you have not ever heard the term **Arithmetic Progrossion**, refer to:
http://www.codewars.com/kata/find-the-missing-term-in-an-arithmetic-progression/python
And here is an unordered version. Try if you can survive lists of **MASSIVE** numbers (which means time limit should be considered). :D
Note: Don't be afrai... | ["def find(seq):\n return (min(seq)+max(seq))*(len(seq)+1)/2-sum(seq)", "def find(a):\n return (max(a) + min(a)) * (len(a) + 1) / 2 - sum(a)", "def find(seq):\n a,b,c = max(seq), min(seq), len(seq)\n z = list(range(b, a, (a-b)//c))\n return list(set(z)-set(seq))[0]\n", "def find(nums):\n # hmm, quite fa... | {"fn_name": "find", "inputs": [[[3, 9, 1, 11, 13, 5]], [[5, -1, 0, 3, 4, -3, 2, -2]], [[2, -2, 8, -8, 4, -4, 6, -6]]], "outputs": [[7], [1], [0]]} | introductory | https://www.codewars.com/kata/568fca718404ad457c000033 |
def find(seq):
|
4,483 | ## Description
You are a *Fruit Ninja*, your skill is cutting fruit. All the fruit will be cut in half by your knife. For example:
```
[ "apple", "pear", "banana" ] --> ["app", "le", "pe", "ar", "ban", "ana"]
```
As you see, all fruits are cut in half. You should pay attention to `"apple"`: if you cannot cu... | ["FRUIT_NAMES = {'blueberry', 'pear', 'durian', 'ginkgo', 'peach', 'apple', 'cantaloupe', 'fig', 'mangosteen', 'watermelon', 'pineapple', 'cherry', 'pomegranate', 'carambola', 'hawthorn', 'persimmon', 'apricot', 'plum', 'litchi', 'mango', 'jujube', 'lemon', 'orange', 'tomato', 'banana', 'coconut', 'grape', 'pitaya'}\nd... | {"fn_name": "cut_fruits", "inputs": [[["apple", "pear", "banana"]], [["apple", "pear", "banana", "bomb"]], [[]]], "outputs": [[["app", "le", "pe", "ar", "ban", "ana"]], [["app", "le", "pe", "ar", "ban", "ana", "bomb"]], [[]]]} | introductory | https://www.codewars.com/kata/57d60363a65454701d000e11 |
def cut_fruits(fruits):
|
4,485 | You task is to implement an simple interpreter for the notorious esoteric language [HQ9+](https://esolangs.org/wiki/HQ9+) that will work for a single character input:
- If the input is `'H'`, return `'Hello World!'`
- If the input is `'Q'`, return the input
- If the input is `'9'`, return the full lyrics of [99 Bottle... | ["LINES = \"{0} of beer on the wall, {0} of beer.\\nTake one down and pass it around, {1} of beer on the wall.\"\nSONG = '\\n'.join( LINES.format(\"{} bottles\".format(n), \"{} bottle\".format(n-1)+\"s\"*(n!=2)) for n in range(99,1,-1) )\nSONG += \"\"\"\n1 bottle of beer on the wall, 1 bottle of beer.\nTake one down an... | {"fn_name": "HQ9", "inputs": [["X"], ["H"], ["Q"]], "outputs": [[null], ["Hello World!"], ["Q"]]} | introductory | https://www.codewars.com/kata/591588d49f4056e13f000001 |
def HQ9(code):
|
4,490 | The Collatz conjecture is one of the most famous one. Take any positive integer n, if it is even divide it by 2, if it is odd multiply it by 3 and add 1 and continue indefinitely.The conjecture is that whatever is n the sequence will reach 1. There is many ways to approach this problem, each one of them had given beaut... | ["from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef rec(n): return 1 + (0 if n==1 else rec(3*n+1) if n&1 else rec(n//2))\n\nmemo = [[0, None], [1, 1]]\ndef max_collatz_length(n):\n if not (type(n) == int and n > 0): return []\n while n >= len(memo):\n x = rec(len(memo))\n if x > memo[... | {"fn_name": "max_collatz_length", "inputs": [[0], [1], [4], [30], [1000], [1000000], ["a"], [-1], [["a"]]], "outputs": [[[]], [[1, 1]], [[3, 8]], [[27, 112]], [[871, 179]], [[837799, 525]], [[]], [[]], [[]]]} | introductory | https://www.codewars.com/kata/53a9ee602f150d5d6b000307 |
def max_collatz_length(n):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.