problem_id int64 0 5k | question stringlengths 50 14k | solutions stringlengths 12 1.21M | input_output stringlengths 0 23.6M | difficulty stringclasses 3
values | url stringlengths 36 108 | starter_code stringlengths 0 1.4k |
|---|---|---|---|---|---|---|
4,000 | # Definition
**_Strong number_** is the number that *the sum of the factorial of its digits is equal to number itself*.
## **_For example_**: **_145_**, since
```
1! + 4! + 5! = 1 + 24 + 120 = 145
```
So, **_145_** is a **_Strong number_**.
____
# Task
**_Given_** a number, **_Find if it is Strong or not_**.
___... | ["import math\n\ndef strong_num(number):\n return \"STRONG!!!!\" if sum(math.factorial(int(i)) for i in str(number)) == number else \"Not Strong !!\"", "STRONGS = {1, 2, 145, 40585}\n\ndef strong_num(number):\n return \"STRONG!!!!\" if number in STRONGS else \"Not Strong !!\"", "from math import factorial\ndef st... | {"fn_name": "strong_num", "inputs": [[40585], [2999999]], "outputs": [["STRONG!!!!"], ["Not Strong !!"]]} | introductory | https://www.codewars.com/kata/5a4d303f880385399b000001 |
def strong_num(number):
|
4,001 | This is now a little serie :)
Funny Dots
You will get two Integer n (width) and m (height) and your task is to draw following pattern. Each line is seperated with '\n'.
Both integers are equal or greater than 1. No need to check for invalid parameters.
e.g.:
+---+---+---... | ["def dot(n, m):\n sep = '+---' * n + '+'\n dot = '| o ' * n + '|'\n return '\\n'.join([sep, dot] * m + [sep])", "def dot(n,m):\n result = [(\"+---\" * n) + \"+\" + \"\\n\" + (\"| o \" * n) + \"|\" for i in range(m)]\n result.append((\"+---\" * n) + \"+\")\n return \"\\n\".join(result)", "def dot(n,m)... | {"fn_name": "dot", "inputs": [[1, 1], [3, 2]], "outputs": [["+---+\n| o |\n+---+"], ["+---+---+---+\n| o | o | o |\n+---+---+---+\n| o | o | o |\n+---+---+---+"]]} | introductory | https://www.codewars.com/kata/59098c39d8d24d12b6000020 |
def dot(n,m):
|
4,002 | Roma is programmer and he likes memes about IT,
Maxim is chemist and he likes memes about chemistry,
Danik is designer and he likes memes about design,
and Vlad likes all other memes.
___
You will be given a meme (string), and your task is to identify its category, and send it to the right receiver: `IT - 'Roma... | ["import re\nfrom itertools import accumulate\n\n\npatterns = [\n (re.compile('.*'.join('bug'), flags=re.I), 'Roma'),\n (re.compile('.*'.join('boom'), flags=re.I), 'Maxim'),\n (re.compile('.*'.join('edits'), flags=re.I), 'Danik'),\n]\n\ndef memesorting(meme):\n return next((who for m in accumulate(meme) for... | {"fn_name": "memesorting", "inputs": [["This is programmer meme ecause it has bug"], ["This is also programbur meme gecause it has needed key word"], ["This is edsigner meme cause it has key word"], ["This could be chemistry meme but our gey word boom is too late"], ["This is meme"]], "outputs": [["Roma"], ["Roma"], ["... | introductory | https://www.codewars.com/kata/5b6183066d0db7bfac0000bb |
def memesorting(meme):
|
4,003 | # Description
Write a function that accepts the current position of a knight in a chess board, it returns the possible positions that it will end up after 1 move. The resulted should be sorted.
## Example
"a1" -> ["b3", "c2"] | ["def possible_positions(p):\n r, c = ord(p[0])-96, int(p[1])\n moves = [(-2,-1), (-2,1), (-1,-2), (-1,2), (1,-2), (1,2), (2,-1), (2,1)]\n return [''.join((chr(r+i+96), str(c+j))) for i, j in moves if 1 <= r+i <= 8 and 1 <= c+j <= 8]", "def possible_positions(pos):\n col = \"abcdefgh\"\n row = \"12345678... | {"fn_name": "possible_positions", "inputs": [["a1"], ["f7"], ["c3"]], "outputs": [[["b3", "c2"]], [["d6", "d8", "e5", "g5", "h6", "h8"]], [["a2", "a4", "b1", "b5", "d1", "d5", "e2", "e4"]]]} | introductory | https://www.codewars.com/kata/5b5736abf1d553f844000050 |
def possible_positions(pos):
|
4,004 | Find the first character that repeats in a String and return that character.
```python
first_dup('tweet') => 't'
first_dup('like') => None
```
*This is not the same as finding the character that repeats first.*
*In that case, an input of 'tweet' would yield 'e'.* | ["def first_dup(s):\n for x in s:\n if s.count(x) > 1:\n return x\n return None", "def first_dup(s):\n return next((x for x in s if s.count(x) > 1),None)", "from collections import Counter, OrderedDict\n\nclass OC(Counter,OrderedDict): pass\n\ndef first_dup(s):\n return next((c for c,n in ... | {"fn_name": "first_dup", "inputs": [["tweet"], ["Ode to Joy"], ["ode to joy"], ["bar"]], "outputs": [["t"], [" "], ["o"], [null]]} | introductory | https://www.codewars.com/kata/54f9f4d7c41722304e000bbb |
def first_dup(s):
|
4,005 | Write a function that reverses the bits in an integer.
For example, the number `417` is `110100001` in binary. Reversing the binary is `100001011` which is `267`.
You can assume that the number is not negative. | ["def reverse_bits(n):\n return int(bin(n)[:1:-1],2)", "def reverse_bits(n):\n return int(f'{n:b}'[::-1],2)", "def reverse_bits(n):\n return int(bin(n)[-1:1:-1], 2)", "def reverse_bits(n):\n listbin = [bin(n)]\n listbin.sort(reverse = True)\n pleasework = list(''.join(listbin))\n comeonguy = ''.jo... | {"fn_name": "reverse_bits", "inputs": [[417], [267], [0], [2017], [1023], [1024]], "outputs": [[267], [417], [0], [1087], [1023], [1]]} | introductory | https://www.codewars.com/kata/5959ec605595565f5c00002b |
def reverse_bits(n):
|
4,006 | Your task is to create a function that does four basic mathematical operations.
The function should take three arguments - operation(string/char), value1(number), value2(number).
The function should return result of numbers after applying the chosen operation.
### Examples
```python
basic_op('+', 4, 7) # O... | ["def basic_op(operator, value1, value2):\n if operator=='+':\n return value1+value2\n if operator=='-':\n return value1-value2\n if operator=='/':\n return value1/value2\n if operator=='*':\n return value1*value2", "def basic_op(operator, value1, value2):\n return eval(\"{}{}... | {"fn_name": "basic_op", "inputs": [["+", 4, 7], ["-", 15, 18], ["*", 5, 5], ["/", 49, 7]], "outputs": [[11], [-3], [25], [7]]} | introductory | https://www.codewars.com/kata/57356c55867b9b7a60000bd7 |
def basic_op(operator, value1, value2):
|
4,007 | # Task
Given an array `arr`, find the maximal value of `k` such `a[i] mod k` = `a[j] mod k` for all valid values of i and j.
If it's impossible to find such number (there's an infinite number of `k`s), return `-1` instead.
# Input/Output
`[input]` integer array `arr`
A non-empty array of positive integer.
`2 <= a... | ["def finding_k(arr):\n for n in range(max(arr)-1, 0, -1):\n if len({ x%n for x in arr }) == 1: return n\n return -1", "from itertools import repeat\nfrom functools import reduce\nfrom operator import sub\nfrom math import gcd\n\ndef finding_k(arr):\n return reduce(gcd, filter(None, map(sub, set(arr), r... | {"fn_name": "finding_k", "inputs": [[[1, 2, 3]], [[1, 1, 1]], [[5, 2, 8]], [[4, 1, 7]], [[1, 7, 13]], [[4, 5, 4]], [[5, 6, 7, 8]], [[10, 100]], [[64, 8, 1]], [[2, 9, 30]]], "outputs": [[1], [-1], [3], [3], [6], [1], [1], [90], [7], [7]]} | introductory | https://www.codewars.com/kata/5919427e5ffc30804900005f |
def finding_k(arr):
|
4,008 | Given a string containing a list of integers separated by commas, write the function string_to_int_list(s) that takes said string and returns a new list containing all integers present in the string, preserving the order.
For example, give the string "-1,2,3,4,5", the function string_to_int_list() should return [-1,2,... | ["def string_to_int_list(s):\n return [int(n) for n in s.split(\",\") if n]", "def string_to_int_list(s):\n return [int(x) for x in s.split(',') if x != '']", "def string_to_int_list(s):\n return [int(x) for x in s.split(',') if x]", "import re\nnumber_pattern = re.compile(\"-?[0-9]+\")\n\ndef string_to_int_li... | {"fn_name": "string_to_int_list", "inputs": [["1,2,3,4,5"], ["21,12,23,34,45"], ["-1,-2,3,-4,-5"], ["1,2,3,,,4,,5,,,"], [",,,,,1,2,3,,,4,,5,,,"], [""], [",,,,,,,,"]], "outputs": [[[1, 2, 3, 4, 5]], [[21, 12, 23, 34, 45]], [[-1, -2, 3, -4, -5]], [[1, 2, 3, 4, 5]], [[1, 2, 3, 4, 5]], [[]], [[]]]} | introductory | https://www.codewars.com/kata/5727868888095bdf5c001d3d |
def string_to_int_list(s):
|
4,009 | Given an integer, take the (mean) average of each pair of consecutive digits. Repeat this process until you have a single integer, then return that integer. e.g.
Note: if the average of two digits is not an integer, round the result **up** (e.g. the average of 8 and 9 will be 9)
## Examples
```
digitsAverage(246) =... | ["def digits_average(input):\n digits = [int(c) for c in str(input)]\n while len(digits) > 1:\n digits = [(a + b + 1) // 2 for a, b in zip(digits, digits[1:])]\n return digits[0]", "digits_average=a=lambda n:n>9and a(int(''.join(str(-~int(a)+int(b)>>1)for a,b in zip(str(n),str(n)[1:]))))or n", "import m... | {"fn_name": "digits_average", "inputs": [[246], [89], [2], [245], [345], [346], [3700]], "outputs": [[4], [9], [2], [4], [5], [5], [4]]} | introductory | https://www.codewars.com/kata/5a32526ae1ce0ec0f10000b2 |
def digits_average(input):
|
4,010 | # Task
Given some sticks by an array `V` of positive integers, where V[i] represents the length of the sticks, find the number of ways we can choose three of them to form a triangle.
# Example
For `V = [2, 3, 7, 4]`, the result should be `1`.
There is only `(2, 3, 4)` can form a triangle.
For `V = [5, 6, 7, 8]`... | ["from itertools import combinations\n\ndef counting_triangles(v):\n v.sort()\n return sum(a+b>c for a,b,c in combinations(v,3))", "counting_triangles=lambda V:sum(a+b>c for a,b,c in __import__('itertools').combinations(sorted(V),3))", "import itertools\ndef counting_triangles(V):\n count = 0\n for x in ite... | {"fn_name": "counting_triangles", "inputs": [[[2, 3, 7, 4]], [[5, 6, 7, 8]], [[2, 2, 2, 2]], [[1, 2, 5]], [[1, 2, 3, 10, 20, 30, 4]], [[1, 2, 3]]], "outputs": [[1], [4], [4], [0], [1], [0]]} | introductory | https://www.codewars.com/kata/58ad29bc4b852b14a4000050 |
def counting_triangles(V):
|
4,011 | # How many urinals are free?
In men's public toilets with urinals, there is this unwritten rule that you leave at least one urinal free
between you and the next person peeing.
For example if there are 3 urinals and one person is already peeing in the left one, you will choose the
urinal on the right and not the one in... | ["def get_free_urinals(urinals):\n return -1 if '11' in urinals else sum(((len(l)-1)//2 for l in f'0{urinals}0'.split('1')))", "def get_free_urinals(urinals):\n if '11' in urinals: return -1\n if urinals == '0': return 1\n free = 0\n i = 0\n while (i < len(urinals)):\n if i == 0 and urinals[i:i... | {"fn_name": "get_free_urinals", "inputs": [["10001"], ["1001"], ["00000"], ["0000"], ["01000"], ["00010"], ["10000"], ["1"], ["0"], ["10"], ["110"], ["1011000001"]], "outputs": [[1], [0], [3], [2], [1], [1], [2], [0], [1], [0], [-1], [-1]]} | introductory | https://www.codewars.com/kata/5e2733f0e7432a000fb5ecc4 |
def get_free_urinals(urinals):
|
4,012 | ### Background
In classical cryptography, the Hill cipher is a polygraphic substitution cipher based on linear algebra. It was invented by Lester S. Hill in 1929.
### Task
This cipher involves a text key which has to be turned into a matrix and text which needs to be encoded. The text key can be of any perfect squ... | ["import numpy as np\nfrom itertools import zip_longest\nfrom string import ascii_lowercase as lower, ascii_uppercase as upper\n\nD = {c:i%26 for i,c in enumerate(lower+upper)}\n\ndef encrypt(text, key):\n result = []\n text = ''.join(filter(str.isalpha, text))\n key = np.array(([D[key[0]], D[key[1]]], [D[key[... | {"fn_name": "encrypt", "inputs": [["", "azyb"], ["hello", "hill"], ["This is a good day", "bbaa"], ["CODEWARS IS GREAT", "wxyz"], ["Five + Seven = Twelve", "math"], ["+-*/ &*%^$", "azyb"]], "outputs": [[""], ["DRJIMN"], ["AAAAAAGACAGAYA"], ["CICQQIIASSDXKSFP"], ["IVSLIGSLAQEECSWR"], [""]]} | introductory | https://www.codewars.com/kata/5e958a9bbb01ec000f3c75d8 |
def encrypt(text,key):
|
4,013 | A spoonerism is a spoken phrase in which the first letters of two of the words are swapped around, often with amusing results.
In its most basic form a spoonerism is a two word phrase in which only the first letters of each word are swapped:
```"not picking" --> "pot nicking"```
Your task is to create a function tha... | ["def spoonerize(words):\n a, b = words.split()\n return '{}{} {}{}'.format(b[0], a[1:], a[0], b[1:])\n", "def spoonerize(words):\n a, b = words.split()\n return f\"{b[0]}{a[1:]} {a[0]}{b[1:]}\"", "def spoonerize(words):\n a, b = words.split()\n return ' '.join((b[0]+a[1:], a[0]+b[1:])) ", "def spoone... | {"fn_name": "spoonerize", "inputs": [["not picking"], ["wedding bells"], ["jelly beans"], ["pop corn"]], "outputs": [["pot nicking"], ["bedding wells"], ["belly jeans"], ["cop porn"]]} | introductory | https://www.codewars.com/kata/56b8903933dbe5831e000c76 |
def spoonerize(words):
|
4,014 | Write a function that takes an arbitrary number of strings and interlaces them (combines them by alternating characters from each string).
For example `combineStrings('abc', '123')` should return `'a1b2c3'`.
If the strings are different lengths the function should interlace them until each string runs out, continuing... | ["from itertools import zip_longest\n\ndef combine_strings(*args):\n return ''.join(''.join(x) for x in zip_longest(*args, fillvalue=''))", "from itertools import zip_longest, chain\ndef combine_strings(*args):\n return ''.join(chain(*zip_longest(*args, fillvalue = '')))", "from itertools import zip_longest\ncomb... | {"fn_name": "combine_strings", "inputs": [["abc"], ["abc", "123"], ["abcd", "123"], ["abc", "1234"], ["abc", "123", "$%"], ["abcd", "123", "$%"], ["abcd", "123", "$%^&"], ["abcd", "123", "$%^&", "qwertyuiop"], ["abcd", "123", "$%^&", "qwertyuiop", "X"]], "outputs": [["abc"], ["a1b2c3"], ["a1b2c3d"], ["a1b2c34"], ["a1$b... | introductory | https://www.codewars.com/kata/5836ebe4f7e1c56e1a000033 |
def combine_strings(*args):
|
4,015 | # Story
You and a group of friends are earning some extra money in the school holidays by re-painting the numbers on people's letterboxes for a small fee.
Since there are 10 of you in the group each person just concentrates on painting one digit! For example, somebody will paint only the ```1```'s, somebody else will... | ["def paint_letterboxes(start, finish):\n xs = [0] * 10\n for n in range(start, finish+1):\n for i in str(n):\n xs[int(i)] += 1\n return xs", "from collections import Counter\n\ndef paint_letterboxes(s, f):\n a = Counter(\"\".join(map(str, range(s, f+1))))\n return [a[x] for x in \"0123... | {"fn_name": "paint_letterboxes", "inputs": [[125, 132], [1001, 1001]], "outputs": [[[1, 9, 6, 3, 0, 1, 1, 1, 1, 1]], [[2, 2, 0, 0, 0, 0, 0, 0, 0, 0]]]} | introductory | https://www.codewars.com/kata/597d75744f4190857a00008d |
def paint_letterboxes(start, finish):
|
4,016 | Mike and Joe are fratboys that love beer and games that involve drinking. They play the following game: Mike chugs one beer, then Joe chugs 2 beers, then Mike chugs 3 beers, then Joe chugs 4 beers, and so on. Once someone can't drink what he is supposed to drink, he loses.
Mike can chug at most A beers in total (other... | ["def game(maxMike, maxJoe):\n roundsMike = int(maxMike**.5)\n roundsJoe = (-1 + (1 + 4*maxJoe)**.5) // 2\n return (\"Non-drinkers can't play\" if not maxMike or not maxJoe else\n \"Joe\" if roundsMike <= roundsJoe else \n \"Mike\")", "def game(a, b):\n if a * b:\n c = int(a **... | {"fn_name": "game", "inputs": [[3, 2], [4, 2], [9, 1000], [0, 1]], "outputs": [["Joe"], ["Mike"], ["Joe"], ["Non-drinkers can't play"]]} | introductory | https://www.codewars.com/kata/5a491f0be6be389dbb000117 |
def game(a, b):
|
4,017 | Make multiple functions that will return the sum, difference, modulus, product, quotient, and the exponent respectively.
Please use the following function names:
addition = **add**
multiply = **multiply**
division = **divide** (both integer and float divisions are accepted)
modulus = **mod**
exponential = **expo... | ["add = lambda a, b: a + b\nmultiply = lambda a, b: a * b\ndivide = lambda a, b: a / b\nmod = lambda a, b: a % b\nexponent = lambda a, b: a ** b\nsubt = lambda a, b:a - b\n", "def add(a,b):\n return a + b \ndef multiply(a,b):\n return a * b\ndef divide(a,b):\n return a / b\ndef mod(a,b):\n return a % b\ndef exponen... | {"fn_name": "add", "inputs": [[1, 2], [5, 7]], "outputs": [[3], [12]]} | introductory | https://www.codewars.com/kata/55a5befdf16499bffb00007b |
def add(a,b):
|
4,018 | Given a string s, write a method (function) that will return true if its a valid single integer or floating number or false if its not.
Valid examples, should return true:
should return false: | ["def isDigit(string):\n try:\n float(string)\n return True\n except:\n return False", "def isDigit(strng):\n try:\n float(strng)\n return True\n except ValueError:\n return False", "def isDigit(string):\n return string.lstrip('-').replace('.','').isdigit()\n", "... | {"fn_name": "isDigit", "inputs": [["s2324"], ["-234.4"], ["3 4"], ["3-4"], ["3 4 "], ["34.65"], ["-0"], ["0.0"], [""], [" "]], "outputs": [[false], [true], [false], [false], [false], [true], [true], [true], [false], [false]]} | introductory | https://www.codewars.com/kata/57126304cdbf63c6770012bd |
def isDigit(string):
|
4,019 | # Task
**_Given_** a **_Divisor and a Bound_** , *Find the largest integer N* , Such That ,
# Conditions :
* **_N_** is *divisible by divisor*
* **_N_** is *less than or equal to bound*
* **_N_** is *greater than 0*.
___
# Notes
* The **_parameters (divisor, bound)_** passed to the function are *only posit... | ["def max_multiple(divisor, bound):\n return bound - (bound % divisor)", "def max_multiple(divisor, bound):\n return bound // divisor * divisor", "max_multiple = lambda divisor, bound: bound - (bound % divisor)", "def max_multiple(divisor, bound):\n l = []\n for int in range(bound + 1):\n if int % di... | {"fn_name": "max_multiple", "inputs": [[2, 7], [3, 10], [7, 17], [10, 50], [37, 200], [7, 100]], "outputs": [[6], [9], [14], [50], [185], [98]]} | introductory | https://www.codewars.com/kata/5aba780a6a176b029800041c |
def max_multiple(divisor, bound):
|
4,020 | You received a whatsup message from an unknown number. Could it be from that girl/boy with a foreign accent you met yesterday evening?
Write a simple regex to check if the string contains the word hallo in different languages.
These are the languages of the possible people you met the night before:
* hello - english... | ["def validate_hello(greetings):\n return any(x in greetings.lower() for x in ['hello','ciao','salut','hallo','hola','ahoj','czesc'])", "from re import compile, search, I\n\nREGEX = compile(r'hello|ciao|salut|hallo|hola|ahoj|czesc', I)\n\n\ndef validate_hello(greeting):\n return bool(search(REGEX, greeting))\n", ... | {"fn_name": "validate_hello", "inputs": [["hello"], ["ciao bella!"], ["salut"], ["hallo, salut"], ["hombre! Hola!"], ["Hallo, wie geht's dir?"], ["AHOJ!"], ["czesc"], ["meh"], ["Ahoj"]], "outputs": [[true], [true], [true], [true], [true], [true], [true], [true], [false], [true]]} | introductory | https://www.codewars.com/kata/56a4addbfd4a55694100001f |
def validate_hello(greetings):
|
4,021 | # Task
Elections are in progress!
Given an array of numbers representing votes given to each of the candidates, and an integer which is equal to the number of voters who haven't cast their vote yet, find the number of candidates who still have a chance to win the election.
The winner of the election must secure stri... | ["def elections_winners(votes, k):\n m = max(votes)\n return sum(x + k > m for x in votes) or votes.count(m) == 1", "def elections_winners(votes, k):\n best = max(votes)\n if k == 0 and votes.count(best) == 1:\n return 1\n return len([x for x in votes if x + k > best])", "def elections_winners(votes, k):\... | {"fn_name": "elections_winners", "inputs": [[[2, 3, 5, 2], 3], [[1, 3, 3, 1, 1], 0], [[5, 1, 3, 4, 1], 0], [[1, 1, 1, 1], 1], [[1, 1, 1, 1], 0], [[3, 1, 1, 3, 1], 2]], "outputs": [[2], [0], [1], [4], [0], [2]]} | introductory | https://www.codewars.com/kata/58881b859ab1e053240000cc |
def elections_winners(votes, k):
|
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,023 | Given a string of words, you need to find the highest scoring word.
Each letter of a word scores points according to its position in the alphabet: `a = 1, b = 2, c = 3` etc.
You need to return the highest scoring word as a string.
If two words score the same, return the word that appears earliest in the original str... | ["def high(x):\n return max(x.split(), key=lambda k: sum(ord(c) - 96 for c in k))", "def high(x):\n words=x.split(' ')\n list = []\n for i in words:\n scores = [sum([ord(char) - 96 for char in i])]\n list.append(scores)\n return words[list.index(max(list))]", "def high(x):\n scoreboard=[... | {"fn_name": "high", "inputs": [["man i need a taxi up to ubud"], ["what time are we climbing up the volcano"], ["take me to semynak"], ["massage yes massage yes massage"], ["take two bintang and a dance please"]], "outputs": [["taxi"], ["volcano"], ["semynak"], ["massage"], ["bintang"]]} | introductory | https://www.codewars.com/kata/57eb8fcdf670e99d9b000272 |
def high(x):
|
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,025 | In this kata, you have to define a function named **func** that will take a list as input.
You must try and guess the pattern how we get the output number and return list - **[output number,binary representation,octal representation,hexadecimal representation]**, but **you must convert that specific number without bui... | ["def func(l):\n n = sum(l) // len(l)\n return [n] + [format(n, f) for f in \"box\"]", "from statistics import mean\n\nDIGITS = '0123456789abcdef'\n\ndef to(n, base):\n result = []\n while n:\n n, r = divmod(n, base)\n result.append(DIGITS[r])\n return ''.join(reversed(result))\n\ndef func(... | {"fn_name": "func", "inputs": [[[1, 4, 9, 16, 25, 36, 49]], [[2, 31, 3, 56, 46, 3, 467, 33]], [[9, 99, 999, 9999]], [[1, 12, 123, 1234, 12345]], [[1, 2, 6, 3, 1, 577, 12]]], "outputs": [[[20, "10100", "24", "14"]], [[80, "1010000", "120", "50"]], [[2776, "101011011000", "5330", "ad8"]], [[2743, "101010110111", "5267", ... | introductory | https://www.codewars.com/kata/59affdeb7d3c9de7ca0000ec |
def func(l):
|
4,026 | ### Preface
You are currently working together with a local community to build a school teaching children how to code. First plans have been made and the community wants to decide on the best location for the coding school.
In order to make this decision data about the location of students and potential locations is co... | ["def optimum_location(students, locations):\n m = min(locations, key = lambda loc: sum(abs(loc['x'] - s[0]) + abs(loc['y'] - s[1]) for s in students))\n return \"The best location is number %d with the coordinates x = %d and y = %d\" % (m['id'], m['x'], m['y'])\n", "def manhattan(p1,p2): return sum(abs(b-a) for ... | {"fn_name": "optimum_location", "inputs": [[[[3, 7], [2, 2], [14, 1]], [{"id": 1, "x": 3, "y": 4}, {"id": 2, "x": 8, "y": 2}]], [[[54, 7], [1, 211], [14, 44], [12, 5], [14, 7]], [{"id": 1, "x": 44, "y": 55}, {"id": 2, "x": 12, "y": 57}, {"id": 3, "x": 23, "y": 66}]], [[[152, 7], [1, 211], [14, 56], [12, 4], [142, 7]], ... | introductory | https://www.codewars.com/kata/55738b0cffd95756c3000056 |
def optimum_location(students, locations):
|
4,027 | Build a function `sumNestedNumbers`/`sum_nested_numbers` that finds the sum of all numbers in a series of nested arrays raised to the power of their respective nesting levels. Numbers in the outer most array should be raised to the power of 1.
For example,
should return `1 + 2*2 + 3 + 4*4 + 5*5*5 === 149` | ["def sum_nested_numbers(a, depth=1):\n return sum(sum_nested_numbers(e, depth+1) if type(e) == list else e**depth for e in a)", "def sum_nested_numbers(arr,m=1):\n total = 0\n for element in arr:\n if isinstance(element, int): \n total += element**m\n else:\n total += sum_n... | {"fn_name": "sum_nested_numbers", "inputs": [[[0]], [[1, 2, 3, 4, 5]], [[1, [2], 3, [4, [5]]]], [[6, [5], [[4]], [[[3]]], [[[[2]]]], [[[[[1]]]]]]], [[1, [-1], [[1]], [[[-1]]], [[[[1]]]]]]], "outputs": [[0], [15], [149], [209], [5]]} | introductory | https://www.codewars.com/kata/5845e6a7ae92e294f4000315 |
def sum_nested_numbers(a, depth=1):
|
4,028 | # A History Lesson
The Pony Express was a mail service operating in the US in 1859-60.
It reduced the time for messages to travel between the Atlantic and Pacific coasts to about 10 days, before it was made obsolete by the transcontinental telegraph.
# How it worked
There were a number of *stations*, where:
*... | ["def riders(stations, lost):\n stations = stations[:lost-1] + stations[lost-2:]\n rider, dist = 1, 0\n for i,d in enumerate(stations):\n rider += (dist+d > 100) + (i == lost-2)\n dist = dist * (dist+d <= 100 and i != lost-2) + d\n return rider", "LIMIT = 100\n\ndef riders(stations, station_... | {"fn_name": "riders", "inputs": [[[43, 23, 40, 13], 4], [[18, 15], 2], [[43, 23, 40, 13], 3], [[33, 8, 16, 47, 30, 30, 46], 5], [[6, 24, 6, 8, 28, 8, 23, 47, 17, 29, 37, 18, 40, 49], 2], [[50, 50], 2], [[50, 50, 25, 50, 24], 3], [[50, 51, 25, 50, 25], 3], [[50, 100, 25, 50, 26], 3], [[100], 2], [[50, 50], 3], [[50, 51]... | introductory | https://www.codewars.com/kata/5b204d1d9212cb6ef3000111 |
def riders(stations, station_x):
|
4,029 | Complete the solution so that it returns the number of times the search_text is found within the full_text.
```python
search_substr( fullText, searchText, allowOverlap = true )
```
so that overlapping solutions are (not) counted. If the searchText is empty, it should return `0`. Usage examples:
```python
search_subs... | ["import re\n\ndef search_substr(full_text, search_text, allow_overlap=True):\n if not full_text or not search_text: return 0\n return len(re.findall(f'(?=({search_text}))' if allow_overlap else search_text, full_text))", "import re\n\ndef search_substr(origin, target, overlap=True):\n if not target: return 0\... | {"fn_name": "search_substr", "inputs": [["aa_bb_cc_dd_bb_e", "bb"], ["aaabbbcccc", "bbb"], ["aaacccbbbcccc", "cc"], ["aaa", "aa"], ["aaa", "aa", false], ["aaabbbaaa", "bb", false], ["a", ""], ["", "a"], ["", ""], ["", "", false]], "outputs": [[2], [1], [5], [2], [1], [1], [0], [0], [0], [0]]} | introductory | https://www.codewars.com/kata/52190daefe9c702a460003dd |
def search_substr(full_text, search_text, allow_overlap=True):
|
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,032 | Consider the number triangle below, in which each number is equal to the number above plus the number to the left. If there is no number above, assume it's a `0`.
The triangle has `5` rows and the sum of the last row is `sum([1,4,9,14,14]) = 42`.
You will be given an integer `n` and your task will be to return the su... | ["# https://oeis.org/A000108\nfrom math import factorial as fac\ndef solve(n): return fac(2*n)//fac(n)//fac(n+1)", "def binomial_coefficient (n, k):\n if not n >= k >= 0:\n return None\n lower_k = min(k, n-k)\n coeff = 1\n for i in range(lower_k):\n coeff *= n - i\n coeff //= i + 1\n ... | {"fn_name": "solve", "inputs": [[4], [5], [6], [7], [8], [20]], "outputs": [[14], [42], [132], [429], [1430], [6564120420]]} | introductory | https://www.codewars.com/kata/5a906c895084d7ed740000c2 |
def solve(n):
|
4,033 | An AI has infected a text with a character!!
This text is now **fully mutated** to this character.
If the text or the character are empty, return an empty string.
There will never be a case when both are empty as nothing is going on!!
**Note:** The character is a string of length 1 or an empty string.
# Example
... | ["def contamination(text, char):\n return char*len(text)", "def contamination(text, char):\n return len(text) * char", "import re\ndef contamination(text, char):\n return re.sub(\".\", char, text)", "import re\n\ndef contamination(text, char):\n if text == '' or char == '':\n return \"\"\n else:\n ... | {"fn_name": "contamination", "inputs": [["abc", "z"], ["", "z"], ["abc", ""], ["_3ebzgh4", "&"], ["//case", " "]], "outputs": [["zzz"], [""], [""], ["&&&&&&&&"], [" "]]} | introductory | https://www.codewars.com/kata/596fba44963025c878000039 |
def contamination(text, char):
|
4,034 | Create a function that takes a string and returns that
string with the first half lowercased and the last half uppercased.
eg: foobar == fooBAR
If it is an odd number then 'round' it up to find which letters to uppercase. See example below.
sillycase("brian")
// --^-- midpoint
// bri ... | ["def sillycase(silly):\n half = (len(silly) + 1) // 2\n return silly[:half].lower() + silly[half:].upper()", "def sillycase(s):\n l = len(s)\n return s[:l//2+l%2].lower() + s[l//2+l%2:].upper()", "from math import ceil\ndef sillycase(silly):\n return silly[:ceil(len(silly)/2)].lower() + silly[ceil(len(s... | {"fn_name": "sillycase", "inputs": [["foobar"], ["codewars"], ["jAvASCript"], ["brian"], ["jabberwock"], ["SCOTland"], ["WeLlDoNe"]], "outputs": [["fooBAR"], ["codeWARS"], ["javasCRIPT"], ["briAN"], ["jabbeRWOCK"], ["scotLAND"], ["wellDONE"]]} | introductory | https://www.codewars.com/kata/552ab0a4db0236ff1a00017a |
def sillycase(silly):
|
4,035 | Given 2 strings, your job is to find out if there is a substring that appears in both strings. You will return true if you find a substring that appears in both strings, or false if you do not. We only care about substrings that are longer than one letter long.
#Examples:
````
*Example 1*
SubstringTest("Something","F... | ["def substring_test(first, second):\n first = first.lower()\n second = second.lower()\n\n for i in range(len(first) - 2):\n if first[i:i+2] in second:\n return True\n return False", "def substring_test(str1, str2):\n str1 = str1.lower()\n str2 = str2.lower()\n return any(\n ... | {"fn_name": "substring_test", "inputs": [["Something", "Home"], ["Something", "Fun"], ["Something", ""], ["", "Something"], ["BANANA", "banana"], ["test", "lllt"], ["", ""], ["1234567", "541265"], ["supercalifragilisticexpialidocious", "SoundOfItIsAtrocious"], ["LoremipsumdolorsitametconsecteturadipiscingelitAeneannona... | introductory | https://www.codewars.com/kata/5669a5113c8ebf16ed00004c |
def substring_test(str1, str2):
|
4,036 | How many days are we represented in a foreign country?
My colleagues make business trips to a foreign country. We must find the number of days our company is represented in a country. Every day that one or more colleagues are present in the country is a day that the company is represented. A single day cannot count fo... | ["def days_represented(a):\n return len({i for x, y in a for i in range(x, y + 1)})", "def days_represented(trips):\n L=[]\n for i in trips:\n for j in range(i[0],i[1]+1):\n L.append(j)\n a=set(L)\n return len(a)", "def days_represented(trips):\n return len({i for (start, stop) in tr... | {"fn_name": "days_represented", "inputs": [[[[10, 15], [25, 35]]], [[[2, 8], [220, 229], [10, 16]]]], "outputs": [[17], [24]]} | introductory | https://www.codewars.com/kata/58e93b4706db4d24ee000096 |
def days_represented(trips):
|
4,037 | When a warrior wants to talk with another one about peace or war he uses a smartphone. In one distinct country warriors who spent all time in training kata not always have enough money. So if they call some number they want to know which operator serves this number.
Write a function which **accepts number and retu... | ["OPERATORS = {\n '039': 'Golden Telecom', '050': 'MTS', '063': 'Life:)', '066': 'MTS',\n '067': 'Kyivstar', '068': 'Beeline', '093': 'Life:)', '095': 'MTS',\n '096': 'Kyivstar', '097': 'Kyivstar', '098': 'Kyivstar', '099': 'MTS'}\n\n\ndef detect_operator(num):\n return OPERATORS.get(str(num)[1:4], 'no info... | {"fn_name": "detect_operator", "inputs": [["80661111841"], ["80671991111"], ["80631551111"], ["80931551111"], ["80111551111"]], "outputs": [["MTS"], ["Kyivstar"], ["Life:)"], ["Life:)"], ["no info"]]} | introductory | https://www.codewars.com/kata/55f8ba3be8d585b81e000080 |
def detect_operator(num):
|
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,040 | Complete the function that takes an array of words.
You must concatenate the `n`th letter from each word to construct a new word which should be returned as a string, where `n` is the position of the word in the list.
For example:
```
["yoda", "best", "has"] --> "yes"
^ ^ ^
n=0 n=1 n=2
``... | ["def nth_char(words):\n return ''.join(w[i] for i,w in enumerate(words))\n", "def nth_char(words):\n return \"\".join( word[i] for i,word in enumerate(words))\n", "def nth_char(words):\n result = \"\"\n\n for index, word in enumerate(words):\n result += word[index]\n\n return result\n", "def nth_... | {"fn_name": "nth_char", "inputs": [[["yoda", "best", "has"]], [[]], [["X-ray"]], [["No", "No"]], [["Chad", "Morocco", "India", "Algeria", "Botswana", "Bahamas", "Ecuador", "Micronesia"]]], "outputs": [["yes"], [""], ["X"], ["No"], ["Codewars"]]} | introductory | https://www.codewars.com/kata/565b112d09c1adfdd500019c |
def nth_char(words):
|
4,041 | Given a string S.
You have to return another string such that even-indexed and odd-indexed characters of S are grouped and groups are space-separated (see sample below)
Note:
0 is considered to be an even index.
All input strings are valid with no spaces
input:
'CodeWars'
output
'CdWr oeas'
S[0] = 'C'
S[1] = 'o'... | ["def sort_my_string(s):\n return '{} {}'.format(s[::2], s[1::2])", "def sort_my_string(s):\n return s[::2] + ' ' + s[1::2]", "def sort_my_string(S):\n return (S[0::2] + \" \" + S[1::2])", "def sort_my_string(S):\n return str(S[0::2] + ' ' + S[1::2])", "def sort_my_string(s):\n return f'{s[::2]} {s[1::2]... | {"fn_name": "sort_my_string", "inputs": [["Wolfeschlegelsteinhausenbergerdorff"], ["METHIONYLTHREONYLTHREONYGLUTAMINYLARGINYL"], ["PNEUMONOULTRAMICROSCOPICSILICOVOLCANOCONIOSIS"], ["PSEUDOPSEUDOHYPOPARATHYROIDISM"], ["FLOCCINAUCINIHILIPILIFICATION"], ["SUBDERMATOGLYPHIC"]], "outputs": [["Wleclgltihuebredrf ofsheesenasn... | introductory | https://www.codewars.com/kata/580755730b5a77650500010c |
def sort_my_string(s):
|
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,043 | # Task
John won the championship of a TV show. He can get some bonuses.
He needs to play a game to determine the amount of his bonus.
Here are `n` rows and `m` columns of cards were placed on the ground. A non-negative number is written on each card.
The rules of the game are:
- Player starts from the top-left con... | ["def calc(gamemap):\n nr, nc = len(gamemap), len(gamemap[0])\n def _i(ra, rb):\n return ra*nr + rb\n vs, ws = [0] * nr**2, [0] * nr**2\n for s in range(nr + nc - 1):\n for ra in range(max(0, s - nc + 1), min(s + 1, nr)):\n for rb in range(ra, min(s + 1, nr)):\n ws[_i... | {"fn_name": "calc", "inputs": [[[[1, 3, 9], [2, 8, 5], [5, 7, 4]]], [[[11, 72, 38], [80, 69, 65], [68, 96, 99]]], [[[1, 5, 1, 1], [1, 5, 5, 1], [5, 5, 5, 1], [1, 1, 5, 1]]], [[[0, 0, 2, 3, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0], [0, 0, 3, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 4, 0, 0], [0, 0, 0, 0, 4, 0, 0], [0, 0,... | introductory | https://www.codewars.com/kata/5c2ef8c3a305ad00139112b7 |
def calc(gamemap):
|
4,044 | Let's say take 2 strings, A and B, and define the similarity of the strings to be the length of the longest prefix common to both strings. For example, the similarity of strings `abc` and `abd` is 2, while the similarity of strings `aaa` and `aaab` is 3.
write a function that calculates the sum of similarities of a st... | ["from os.path import commonprefix\n\ndef string_suffix(s):\n return sum(len(commonprefix([s, s[i:]])) for i in range(len(s)))", "def similarity(strng1, strng2):\n result = 0\n for c1, c2 in zip(strng1, strng2):\n if c1 != c2:\n break\n result += 1\n return result\n\ndef string_suff... | {"fn_name": "string_suffix", "inputs": [["aa"], ["abc"], ["ababaa"], ["aaaa"], ["aaaaa"], ["aaaaaa"], ["mnsomn"], ["apple"], ["a"], ["pippi"]], "outputs": [[3], [3], [11], [10], [15], [21], [8], [5], [1], [8]]} | introductory | https://www.codewars.com/kata/559d34cb2e65e765b90000f0 |
def string_suffix(s):
|
4,045 | Your team is writing a fancy new text editor and you've been tasked with implementing the line numbering.
Write a function which takes a list of strings and returns each line prepended by the correct number.
The numbering starts at 1. The format is `n: string`. Notice the colon and space in between.
**Examples:**
`... | ["def number(lines):\n return ['%d: %s' % v for v in enumerate(lines, 1)]", "def number(lines):\n return [f\"{n}: {ligne}\" for n, ligne in enumerate(lines, 1)]\n", "def number(lines):\n return ['{}: {}'.format(n, s) for (n, s) in enumerate(lines, 1)]", "def number(lines):\n return [f\"{counter}: {line}\" for c... | {"fn_name": "number", "inputs": [[[]], [["a", "b", "c"]], [["", "", "", "", ""]], [["", "b", "", "", ""]]], "outputs": [[[]], [["1: a", "2: b", "3: c"]], [["1: ", "2: ", "3: ", "4: ", "5: "]], [["1: ", "2: b", "3: ", "4: ", "5: "]]]} | introductory | https://www.codewars.com/kata/54bf85e3d5b56c7a05000cf9 |
def number(lines):
|
4,046 | # Explanation
It's your first day in the robot factory and your supervisor thinks that you should start with an easy task. So you are responsible for purchasing raw materials needed to produce the robots.
A complete robot weights `50` kilogram. Iron is the only material needed to create a robot. All iron is inserted ... | ["from math import ceil\n\ndef calculate_scrap(arr,n):\n x = 50\n for i in arr:\n x /= (1-i/100)\n return ceil(n*x)", "from functools import reduce\nfrom operator import mul\nfrom math import ceil\n\ndef calculate_scrap(scraps, number_of_robots):\n return ceil(50 * number_of_robots * 100**len(scraps)... | {"fn_name": "calculate_scrap", "inputs": [[[10], 90], [[20, 10], 55], [[0], 90], [[0, 0, 0], 90], [[10, 0], 90], [[0, 10], 90], [[10, 0, 0, 10], 81], [[0, 10, 0, 10], 81], [[0, 10, 10, 0], 81], [[10, 20, 30, 40, 50, 60, 70, 80, 90], 25], [[90, 80, 70, 60, 50, 40, 30, 20, 10], 20], [[10, 0, 30, 0, 50, 0, 70, 0, 90], 25]... | introductory | https://www.codewars.com/kata/5898a7208b431434e500013b |
def calculate_scrap(scraps, number_of_robots):
|
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,048 | Task:
Make a function that converts a word to pig latin. The rules of pig latin are:
```
If the word has more than 3 letters:
1. Take the first letter of a word and move it to the end
2. Add -ay to the word
Otherwise leave the word alone.
```
Example: `hello` = `ellohay` | ["def pig_latin(word):\n return word[1:]+word[0]+'ay' if len(word)>3 else word", "def pig_latin(word):\n return word if len(word) < 4 else word[1:]+word[0]+\"ay\"", "def pig_latin(word):\n return f\"{word[1:]}{word[0]}ay\" if len(word) > 3 else word", "def pig_latin(word):\n if len(word) > 3:\n ay = wo... | {"fn_name": "pig_latin", "inputs": [["hello"], ["hi"]], "outputs": [["ellohay"], ["hi"]]} | introductory | https://www.codewars.com/kata/58702c0ca44cfc50dc000245 |
def pig_latin(word):
|
4,049 | You take your son to the forest to see the monkeys. You know that there are a certain number there (n), but your son is too young to just appreciate the full number, he has to start counting them from 1.
As a good parent, you will sit and count with him. Given the number (n), populate an array with all numbers up to a... | ["def monkey_count(n):\n return list(range(1,n+1))", "def monkey_count(n):\n return [i+1 for i in range(n)]", "def monkey_count(n):\n return [i for i in range(1, n+1)]", "def monkey_count(n):\n #your code here\n list = []\n for i in range(1,n+1):\n list.append(i)\n return list", "def monkey_... | {"fn_name": "monkey_count", "inputs": [[5], [3], [9], [10], [20]], "outputs": [[[1, 2, 3, 4, 5]], [[1, 2, 3]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]]]} | introductory | https://www.codewars.com/kata/56f69d9f9400f508fb000ba7 |
def monkey_count(n):
|
4,050 | Laura really hates people using acronyms in her office and wants to force her colleagues to remove all acronyms before emailing her. She wants you to build a system that will edit out all known acronyms or else will notify the sender if unknown acronyms are present.
Any combination of three or more letters in upper ca... | ["import re\nfrom functools import reduce\n\n_ACRONYMS = {\n 'KPI': 'key performance indicators',\n 'EOD': 'the end of the day',\n 'EOP': 'the end of the day', # snafu in the tests?\n 'TBD': 'to be decided',\n 'WAH': 'work at home',\n 'IAM': 'in a meeting',\n 'OOO': 'out of office',\n ... | {"fn_name": "acronym_buster", "inputs": [["BRB I need to go into a KPI meeting before EOD"], ["I am IAM so will be OOO until EOD"], ["Going to WAH today. NRN. OOO"], ["We're looking at SMB on SM DMs today"], ["OOO"], ["KPI"], ["EOD"], ["TBD"], ["TBD by EOD"], ["BRB I am OOO"], ["WAH"], ["IAM"], ["NRN"], ["CTA"], ["Hi P... | introductory | https://www.codewars.com/kata/58397ee871df657929000209 |
def acronym_buster(message):
|
4,051 | You wrote all your unit test names in camelCase.
But some of your colleagues have troubles reading these long test names.
So you make a compromise to switch to underscore separation.
To make these changes fast you wrote a class to translate a camelCase name
into an underscore separated name.
Implement the ToUnderscor... | ["import re\n\ndef toUnderScore(name):\n return re.sub(\"(?<=[^_-])_?(?=[A-Z])|(?<=[^\\\\d_])_?(?=\\\\d)\", \"_\" , name)", "from re import sub\n\ndef toUnderScore(name):\n return sub('([a-zA-Z](?=[A-Z0-9])|\\d(?=[A-Z]))', r'\\1_', name)", "def toUnderScore(name):\n if len(name) ==0:\n return \"\"\n ... | {"fn_name": "toUnderScore", "inputs": [["ThisIsAUnitTest"], ["ThisShouldBeSplittedCorrectIntoUnderscore"], ["Calculate1Plus1Equals2"], ["Calculate15Plus5Equals20"], ["Calculate500DividedBy5Equals100"], ["Adding_3To_3ShouldBe_6"], ["This_Is_Already_Splitted_Correct"], ["ThisIs_Not_SplittedCorrect"], ["_IfATestStartAndEn... | introductory | https://www.codewars.com/kata/5b1956a7803388baae00003a |
def toUnderScore(name):
|
4,052 | You will be given the prime factors of a number as an array.
E.g: ```[2,2,2,3,3,5,5,13]```
You need to find the number, n, to which that prime factorization belongs.
It will be:
```
n = 2³.3².5².13 = 23400
```
Then, generate the divisors of this number.
Your function ```get_num() or getNum()``` will receive an array ... | ["def get_num(arr):\n c,n,r=1,1,{}\n arr.sort()\n for a in arr: n*=a; r[a]= r[a]+1 if a in r else 1\n for a in r: c*=r[a]+1 \n return [n,c-1,arr[0],n//arr[0]]", "from collections import Counter\nfrom functools import reduce\nfrom operator import mul\n\ndef get_num(arr):\n n, small = reduce(mul, arr), ... | {"fn_name": "get_num", "inputs": [[[2, 3, 5, 5]], [[2, 3, 3, 3, 7]], [[3, 3, 3, 11]], [[2, 13, 2, 5, 2, 5, 3, 3]]], "outputs": [[[150, 11, 2, 75]], [[378, 15, 2, 189]], [[297, 7, 3, 99]], [[23400, 71, 2, 11700]]]} | introductory | https://www.codewars.com/kata/58f301633f5066830c000092 |
def get_num(arr):
|
4,053 | I'm sure you're familiar with factorials – that is, the product of an integer and all the integers below it.
For example, `5! = 120`, as `5 * 4 * 3 * 2 * 1 = 120`
Your challenge is to create a function that takes any number and returns the number that it is a factorial of. So, if your function receives `120`, it sho... | ["def reverse_factorial(num):\n c = f = 1\n while f < num:\n c += 1\n f *= c\n return 'None' if f > num else \"%d!\" %c", "def reverse_factorial(num):\n n = 1\n f = 1\n while f < num:\n n += 1\n f = f * n\n return f\"{n}!\" if f == num else \"None\"\n \n \n", "... | {"fn_name": "reverse_factorial", "inputs": [[120], [3628800], [150]], "outputs": [["5!"], ["10!"], ["None"]]} | introductory | https://www.codewars.com/kata/58067088c27998b119000451 |
def reverse_factorial(num):
|
4,054 | **This Kata is intended as a small challenge for my students**
All Star Code Challenge #23
There is a certain multiplayer game where players are assessed at the end of the game for merit. Players are ranked according to an internal scoring system that players don't see.
You've discovered the formula for the scoring ... | ["def scoring(array):\n res = {}\n \n for e in array:\n score = e[\"norm_kill\"] * 100 + e[\"assist\"] * 50 + e[\"damage\"] // 2 +\\\n e[\"healing\"] + 2 ** e[\"streak\"] + e[\"env_kill\"] * 500\n \n res[e[\"name\"]] = score\n \n return sorted(res, key=res.get, reverse=True)",... | {"fn_name": "scoring", "inputs": [[[]]], "outputs": [[[]]]} | introductory | https://www.codewars.com/kata/5865dd726b56998ec4000185 |
def scoring(array):
|
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,056 | # Leaderboard climbers
In this kata you will be given a leaderboard of unique names for example:
```python
['John',
'Brian',
'Jim',
'Dave',
'Fred']
```
Then you will be given a list of strings for example:
```python
['Dave +1', 'Fred +4', 'Brian -1']
```
Then you sort the leaderboard.
The steps for our exampl... | ["def leaderboard_sort(leaderboard, changes):\n for change in changes:\n name, delta = change.split()\n idx = leaderboard.index(name)\n leaderboard.insert(idx - int(delta), leaderboard.pop(idx))\n return leaderboard", "def leaderboard_sort(lbd, changes):\n lbd = lbd[:]\n for name,n in m... | {"fn_name": "leaderboard_sort", "inputs": [[["John", "Brian", "Jim", "Dave", "Fred"], ["Dave +1", "Fred +4", "Brian -1"]], [["Bob", "Larry", "Kevin", "Jack", "Max"], ["Max +3", "Kevin -1", "Kevin +3"]]], "outputs": [[["Fred", "John", "Dave", "Brian", "Jim"]], [["Bob", "Kevin", "Max", "Larry", "Jack"]]]} | introductory | https://www.codewars.com/kata/5f6d120d40b1c900327b7e22 |
def leaderboard_sort(leaderboard, changes):
|
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,060 | # Background
My pet bridge-maker ants are marching across a terrain from left to right.
If they encounter a gap, the first one stops and then next one climbs over him, then the next, and the next, until a bridge is formed across the gap.
What clever little things they are!
Now all the other ants can walk over the ... | ["import re\n\ndef ant_bridge(ants, terrain):\n nGap = sum( 2 + len(gap) - (free == '-') for free,gap in re.findall(r'(-+)(\\.+)', '-'+terrain) ) % len(ants)\n return ants[-nGap:] + ants[:-nGap]", "def ant_bridge(ants, terrain):\n n_ants = len(ants)\n \n terrain = terrain.replace('-.', '..')\n terrain... | {"fn_name": "ant_bridge", "inputs": [["GFEDCBA", "-----------------------"], ["GFEDCBA", "------------...-----------"], ["GFEDCBA", "------------.....---------"], ["GFEDCBA", "------.....------.....---------"], ["GFEDCBA", "------------...-----..----"], ["CBA", "--.--.---"], ["GFEDCBA", "------....-.---"], ["EDCBA", "-... | introductory | https://www.codewars.com/kata/599385ae6ca73b71b8000038 |
def ant_bridge(ants, terrain):
|
4,061 | Consider the sequence `a(1) = 7, a(n) = a(n-1) + gcd(n, a(n-1)) for n >= 2`:
`7, 8, 9, 10, 15, 18, 19, 20, 21, 22, 33, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 69, 72, 73...`.
Let us take the differences between successive elements of the sequence and
get a second sequence `g: 1, 1, 1, 5, 3, 1, 1, 1, 1, 11, 3, 1,... | ["from fractions import gcd\n\ndef seq():\n i, a, g = 1, 7, 1\n while 1:\n yield i, a, g\n i += 1\n g = gcd(i, a)\n a += g\n\ndef count_ones(n):\n return sum(g == 1 for _, (i, a, g) in zip(range(n), seq()))\n\ndef p(n):\n seen = set()\n for i, a, g in seq():\n if not n:... | {"fn_name": "count_ones", "inputs": [[1], [10], [100], [200], [1000], [10000], [100000]], "outputs": [[1], [8], [90], [184], [975], [9968], [99955]]} | introductory | https://www.codewars.com/kata/562b384167350ac93b00010c |
def count_ones(n):
|
4,062 | An element in an array is dominant if it is greater than all elements to its right. You will be given an array and your task will be to return a list of all dominant elements. For example:
```Haskell
solve([1,21,4,7,5]) = [21,7,5] because 21, 7 and 5 are greater than elments to their right.
solve([5,4,3,2,1]) = [5,4,3... | ["def solve(arr):\n r = []\n for v in arr[::-1]:\n if not r or r[-1] < v: r.append(v)\n return r[::-1]", "def solve(arr):\n return [a for i,a in enumerate(arr) if all(x < a for x in arr[i+1:])]", "def solve(arr):\n return [a for i,a in enumerate(arr) if a > max(arr[i+1:]+[0])]", "def solve(arr):\n... | {"fn_name": "solve", "inputs": [[[16, 17, 14, 3, 14, 5, 2]], [[92, 52, 93, 31, 89, 87, 77, 105]], [[75, 47, 42, 56, 13, 55]], [[67, 54, 27, 85, 66, 88, 31, 24, 49]], [[76, 17, 25, 36, 29]], [[104, 18, 37, 9, 36, 47, 28]]], "outputs": [[[17, 14, 5, 2]], [[105]], [[75, 56, 55]], [[88, 49]], [[76, 36, 29]], [[104, 47, 28]... | introductory | https://www.codewars.com/kata/5a04133e32b8b998dc000089 |
def solve(arr):
|
4,063 | Mr. E Ven only likes even length words.
Please create a translator so that he doesn't have to hear those pesky odd length words.
For some reason he also hates punctuation, he likes his sentences to flow.
Your translator should take in a string and output it with all odd length words having an extra letter (the last le... | ["def evenize_word(w):\n return w + w[-1] if len(w) % 2 else w\n\ndef evenator(s):\n s = \"\".join(c for c in s if c.isspace() or c.isalnum())\n return \" \".join(evenize_word(w) for w in s.split())", "def evenator(s):\n return \" \".join([w+w[-1] if len(w)&1 else w for w in \"\".join([c for c in s if c.isa... | {"fn_name": "evenator", "inputs": [["I got a hole in 1!"], ["tHiS sEnTeNcE iS eVeN."], ["underscore is not considered a word..in this case,"], ["hi. how are you? Bye!!"], ["lorem is so ipsum. why bother?"], ["_under the seA!"]], "outputs": [["II gott aa hole in 11"], ["tHiS sEnTeNcE iS eVeN"], ["underscore is nott cons... | introductory | https://www.codewars.com/kata/56ce2f90aa4ac7a4770019fa |
def evenator(s):
|
4,064 | Create a function with two arguments that will return an array of the first (n) multiples of (x).
Assume both the given number and the number of times to count will be positive numbers greater than 0.
Return the results as an array (or list in Python, Haskell or Elixir).
Examples:
```python
count_by(1,10) #should... | ["def count_by(x, n):\n return [i * x for i in range(1, n + 1)]", "def count_by(x, n):\n \"\"\"\n Return a sequence of numbers counting by `x` `n` times.\n \"\"\"\n return [i * x for i in range(1, n+1)]\n", "def count_by(x, n):\n return [x * i for i in range(1, n+1)]", "def count_by(x, n):\n \"\"\"... | {"fn_name": "count_by", "inputs": [[1, 5], [2, 5], [3, 5], [50, 5], [100, 5]], "outputs": [[[1, 2, 3, 4, 5]], [[2, 4, 6, 8, 10]], [[3, 6, 9, 12, 15]], [[50, 100, 150, 200, 250]], [[100, 200, 300, 400, 500]]]} | introductory | https://www.codewars.com/kata/5513795bd3fafb56c200049e |
def count_by(x, n):
|
4,065 | In mathematics, a **pandigital number** is a number that in a given base has among its significant digits each digit used in the base at least once. For example, 1234567890 is a pandigital number in base 10.
For simplification, in this kata, we will consider pandigital numbers in *base 10* and with all digits used *ex... | ["def get_sequence(o,s,st=1023456789):\n li = []\n for i in range([st,o][o>0 and o>st],9876543211):\n i = str(i)\n if i[0]!='0' and len(set(i))==10 : li.append(int(i))\n if len(li)==s : break\n return li ", "from itertools import permutations\nfrom bisect import bisect_left\n\nmemo = [int(... | {"fn_name": "get_sequence", "inputs": [[0, 5], [5432160879, 3], [9876543000, 5], [9999999999, 1], [-123456789, 1], [-9999999999, 25]], "outputs": [[[1023456789, 1023456798, 1023456879, 1023456897, 1023456978]], [[5432160879, 5432160897, 5432160978]], [[9876543012, 9876543021, 9876543102, 9876543120, 9876543201]], [[]],... | introductory | https://www.codewars.com/kata/5ac69d572f317bdfc3000124 |
def get_sequence(offset, size):
|
4,066 | Write a function to split a string and convert it into an array of words. For example:
```python
"Robin Singh" ==> ["Robin", "Singh"]
"I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"]
``` | ["def string_to_array(string):\n return string.split(\" \")", "def string_to_array(string=''):\n return string.split() if string else ['']", "def string_to_array(s):\n return s.split(' ')", "def string_to_array(string):\n array = string.split(' ')\n return array", "def string_to_array(string):\n retur... | {"fn_name": "string_to_array", "inputs": [["Robin Singh"], ["CodeWars"], ["I love arrays they are my favorite"], ["1 2 3"], [""]], "outputs": [[["Robin", "Singh"]], [["CodeWars"]], [["I", "love", "arrays", "they", "are", "my", "favorite"]], [["1", "2", "3"]], [[""]]]} | introductory | https://www.codewars.com/kata/57e76bc428d6fbc2d500036d |
def string_to_array(s):
|
4,067 | Bob is preparing to pass IQ test. The most frequent task in this test is `to find out which one of the given numbers differs from the others`. Bob observed that one number usually differs from the others in **evenness**. Help Bob — to check his answers, he needs a program that among the given numbers finds one that is ... | ["def iq_test(numbers):\n e = [int(i) % 2 == 0 for i in numbers.split()]\n\n return e.index(True) + 1 if e.count(True) == 1 else e.index(False) + 1\n", "def iq_test(n):\n n = [int(i)%2 for i in n.split()]\n if n.count(0)>1:\n return n.index(1)+1\n else:\n return n.index(0)+1\n", "def iq_tes... | {"fn_name": "iq_test", "inputs": [["2 4 7 8 10"], ["1 2 2"], ["88 96 66 51 14 88 2 92 18 72 18 88 20 30 4 82 90 100 24 46"], ["100 99 100"], ["5 3 2"], ["43 28 1 91"], ["20 94 56 50 10 98 52 32 14 22 24 60 4 8 98 46 34 68 82 82 98 90 50 20 78 49 52 94 64 36"], ["79 27 77 57 37 45 27 49 65 33 57 21 71 19 75 85 65 61 23 ... | introductory | https://www.codewars.com/kata/552c028c030765286c00007d |
def iq_test(numbers):
|
4,068 | # Task
Mr.Nam has `n` candies, he wants to put one candy in each cell of a table-box. The table-box has `r` rows and `c` columns.
Each candy was labeled by its cell number. The cell numbers are in range from 1 to N and the direction begins from right to left and from bottom to top.
Nam wants to know the position o... | ["def get_candy_position(n, r, c, candy):\n if candy > n: return [-1,-1,-1]\n \n linIdx = r*c - ( (candy-1) % (r*c) + 1 )\n return [(candy-1)//(r*c) + 1, linIdx//c, linIdx%c]", "def get_candy_position(n, r, c, candy):\n if candy > n:\n return [-1, -1, -1]\n label = (candy + r * c - 1) // (r * c... | {"fn_name": "get_candy_position", "inputs": [[6, 2, 2, 3], [6, 2, 2, 5], [6, 2, 2, 7], [8, 4, 2, 3], [15, 3, 3, 1], [15, 3, 3, 5], [15, 3, 3, 7], [15, 3, 3, 14], [15, 3, 3, 18]], "outputs": [[[1, 0, 1]], [[2, 1, 1]], [[-1, -1, -1]], [[1, 2, 1]], [[1, 2, 2]], [[1, 1, 1]], [[1, 0, 2]], [[2, 1, 1]], [[-1, -1, -1]]]} | introductory | https://www.codewars.com/kata/58b626ee2da07adf3e00009c |
def get_candy_position(n, r, c, candy):
|
4,069 | I love Fibonacci numbers in general, but I must admit I love some more than others.
I would like for you to write me a function that when given a number (n) returns the n-th number in the Fibonacci Sequence.
For example:
```python
nth_fib(4) == 2
```
Because 2 is the 4th number in the Fibonacci Sequence.
For ... | ["def nth_fib(n):\n a, b = 0, 1\n for i in range(n-1):\n a, b = b, a + b\n return a", "def nth_fib(n):\n a, b = (0, 1)\n for _ in range(n-1):\n a, b = b, a + b\n return a", "def nth_fib(n):\n if n==1:\n return 0\n elif n==2:\n return 1\n else:\n return nth_fib(n-1)+nth_fib(n-2)\n", "from m... | {"fn_name": "nth_fib", "inputs": [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24], [25]], "outputs": [[0], [1], [1], [2], [3], [5], [8], [13], [21], [34], [55], [89], [144], [233], [377], [610], [987], [1597], [2584], [4181], [6765], ... | introductory | https://www.codewars.com/kata/522551eee9abb932420004a0 |
def nth_fib(n):
|
4,070 | The magic sum of 3s is calculated on an array by summing up odd numbers which include the digit `3`. Write a function `magic_sum` which accepts an array of integers and returns the sum.
*Example:* `[3, 12, 5, 8, 30, 13]` results in `16` (`3` + `13`)
If the sum cannot be calculated, `0` should be returned. | ["def magic_sum(arr):\n return arr and sum(x for x in arr if x%2 and '3' in str(x)) or 0", "def magic_sum(arr):\n if arr == None: return 0 \n return sum(list(filter(lambda x: x % 2 == 1 and '3' in str(x),arr)))", "def magic_sum(arr):\n def check(x):\n return x % 2 and '3' in str(x)\n return sum(x ... | {"fn_name": "magic_sum", "inputs": [[[3]], [[3, 13]], [[30, 34, 330]], [[3, 12, 5, 8, 30, 13]], [[]], [null]], "outputs": [[3], [16], [0], [16], [0], [0]]} | introductory | https://www.codewars.com/kata/57193a349906afdf67000f50 |
def magic_sum(arr):
|
4,071 | # Scenario
*You're saying good-bye your best friend* , **_See you next happy year_** .
**_Happy Year_** *is the year with only distinct digits* , (e.g) **_2018_**
___
# Task
**_Given_** a year, **_Find_** **_The next happy year_** or **_The closest year You'll see your best friend_** :\n year += 1\n \n while len(set(str(year))) != 4:\n year += 1\n \n return year", "def next_happy_year(year):\n for n in range(year+1, 9999):\n if len(set(str(n))) == 4:\n return n", "def next_happy_year(year):\n while True:\n year+=1\n ... | {"fn_name": "next_happy_year", "inputs": [[1001], [1123], [2001], [2334], [3331], [1987], [5555], [7712], [8088], [8999]], "outputs": [[1023], [1203], [2013], [2340], [3401], [2013], [5601], [7801], [8091], [9012]]} | introductory | https://www.codewars.com/kata/5ae7e3f068e6445bc8000046 |
def next_happy_year(year):
|
4,072 | #Permutation position
In this kata you will have to permutate through a string of lowercase letters, each permutation will start at ```a``` and you must calculate how many iterations it takes to reach the current permutation.
##examples
```
input: 'a'
result: 1
input: 'c'
result: 3
input: 'z'
result: 26
input: 'fo... | ["from functools import reduce\ndef permutation_position(perm):\n return reduce(lambda t,c:t*26+ord(c)-97,perm,0)+1\n", "trans_table = str.maketrans('abcdefghijklmnopqrstuvwxyz',\n '0123456789abcdefghijklmnop')\n\ndef permutation_position(perm):\n return int(perm.translate(trans_table),... | {"fn_name": "permutation_position", "inputs": [["a"], ["z"], ["aaa"], ["aaab"], ["foo"]], "outputs": [[1], [26], [1], [2], [3759]]} | introductory | https://www.codewars.com/kata/57630df805fea67b290009a3 |
def permutation_position(perm):
|
4,073 | # Task
Given a rectangular `matrix` and integers `a` and `b`, consider the union of the ath row and the bth (both 0-based) column of the `matrix`. Return sum of all elements of that union.
# Example
For
```
matrix = [[1, 1, 1, 1],
[2, 2, 2, 2],
[3, 3, 3, 3]]
a = 1 and b = 3 ```
the output shou... | ["def crossing_sum(matrix, row, col):\n return sum(matrix[row]) + sum(line[col] for line in matrix) - matrix[row][col]", "def crossing_sum(a, b, c):\n return sum(a[b]) + sum(x[c] for x in a) - a[b][c]", "def crossing_sum(matrix, row, col):\n return sum(matrix[row]) + sum(i[col] for i in matrix[:row] + matrix[r... | {"fn_name": "crossing_sum", "inputs": [[[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]], 1, 3], [[[1, 1], [3, 3], [1, 1], [2, 2]], 3, 0], [[[100]], 0, 0], [[[1, 2, 3, 4, 5]], 0, 0], [[[1], [2], [3], [4], [5]], 0, 0]], "outputs": [[12], [9], [100], [15], [15]]} | introductory | https://www.codewars.com/kata/5889ab4928c08c08da00009b |
def crossing_sum(matrix, row, col):
|
4,074 | Given an array of numbers, return the difference between the largest and smallest values.
For example:
`[23, 3, 19, 21, 16]` should return `20` (i.e., `23 - 3`).
`[1, 434, 555, 34, 112]` should return `554` (i.e., `555 - 1`).
The array will contain a minimum of two elements. Input data range guarantees that `max-m... | ["def between_extremes(numbers):\n return max(numbers) - min(numbers)", "def between_extremes(ns):\n return max(ns) - min(ns)", "def between_extremes(a):\n return max(a) - min(a)", "# Naive method: 2 iterations\ndef between_extremes(numbers):\n return max(numbers) - min(numbers)\n\n# Faster method: 1 iterat... | {"fn_name": "between_extremes", "inputs": [[[1, 1]], [[-1, -1]], [[1, -1]], [[21, 34, 54, 43, 26, 12]], [[-1, -41, -77, -100]]], "outputs": [[0], [0], [2], [42], [99]]} | introductory | https://www.codewars.com/kata/56d19b2ac05aed1a20000430 |
def between_extremes(numbers):
|
4,075 | We have the following recursive function:
The 15-th term; ```f(14)``` is the first term in having more that 100 digits.
In fact,
```
f(14) = 2596253046576879973769082409566059879570061514363339324718953988724415850732046186170181072783243503881471037546575506836249417271830960970629933033088
It has 151 digits.
``... | ["from functools import reduce\ndef product(ar):\n return reduce(lambda x,y:x*y, ar)\n\ndef something_acci(num_digits):\n seq = [1, 1, 2, 2, 3, 3]\n \n while(len(str(seq[-1])) < num_digits):\n seq.append(product(seq[-3:]) - product(seq[-6:-3]))\n \n return (len(seq), len(str(seq[-1])))\n", "def... | {"fn_name": "something_acci", "inputs": [[5], [10], [20], [100]], "outputs": [[[10, 8]], [[11, 14]], [[12, 25]], [[15, 151]]]} | introductory | https://www.codewars.com/kata/5683838837b2d1db32000021 |
def something_acci(num_digits):
|
4,076 | Error Handling is very important in coding and seems to be overlooked or not implemented properly.
#Task
Your task is to implement a function which takes a string as input and return an object containing the properties
vowels and consonants. The vowels property must contain the total count of vowels {a,e,i,o,u}, and ... | ["def get_count(words=\"\"):\n if not isinstance(words, str):\n return {'vowels':0,'consonants':0}\n letter = \"\".join([c.lower() for c in words if c.isalpha()])\n vowel = \"\".join([c for c in letter if c in 'aeiou'])\n consonant = \"\".join([c for c in letter if c not in 'aeiou']) \n return {'v... | {"fn_name": "get_count", "inputs": [["Test"], ["Here is some text"], ["To be a Codewarrior or not to be"], ["To Kata or not to Kata"], ["aeiou"], ["TEst"], ["HEre Is sOme text"], [["To Kata or not to Kata"]], [null], ["Test "], ["Here is some text "], [" "], [{"jjjjj": "jjjjj"}]],... | introductory | https://www.codewars.com/kata/55e6125ad777b540d9000042 |
def get_count(words=''):
|
4,077 | The new football league season is coming and the Football Association need some help resetting the league standings. Normally the initial league standing is done in alphabetical order (from A to Z) but this year the FA have decided to freshen it up.
It has been decided that team who finished first last season will be... | ["def premier_league_standings(teams):\n dct = {1: teams[1]}\n dct.update({i:t for i,t in enumerate(sorted(set(teams.values())-{teams[1]}), 2)})\n return dct", "def premier_league_standings(teams):\n order = [teams[1]] + sorted(team for place,team in teams.items() if place!=1)\n return {place:team for pl... | {"fn_name": "premier_league_standings", "inputs": [[{"1": "Arsenal"}], [{"2": "Arsenal", "3": "Accrington Stanley", "1": "Leeds United"}], [{"1": "Leeds United", "2": "Liverpool", "3": "Manchester City", "4": "Coventry", "5": "Arsenal"}]], "outputs": [{"1": "Arsenal"}, {"3": "Arsenal", "2": "Accrington Stanley", "1": "... | introductory | https://www.codewars.com/kata/58de08d376f875dbb40000f1 |
def premier_league_standings(teams):
|
4,078 | Your task is to write a function that does just what the title suggests (so, fair warning, be aware that you are not getting out of it just throwing a lame bas sorting method there) with an array/list/vector of integers and the expected number `n` of smallest elements to return.
Also:
* the number of elements to be r... | ["def first_n_smallest(arr, n):\n lst = sorted(enumerate(arr), key=lambda it: it[1])[:n]\n lst.sort(key=lambda it:it[0])\n return [v for _,v in lst]", "def first_n_smallest(arr, n):\n m = sorted(arr)[:n]\n return [m.pop(m.index(i)) for i in arr if i in m]", "from operator import itemgetter\ndef first_n_s... | {"fn_name": "first_n_smallest", "inputs": [[[1, 2, 3, 4, 5], 3], [[5, 4, 3, 2, 1], 3], [[1, 2, 3, 1, 2], 3], [[1, 2, 3, -4, 0], 3], [[1, 2, 3, 4, 5], 0], [[1, 2, 3, 4, 5], 5], [[1, 2, 3, 4, 2], 4], [[2, 1, 2, 3, 4, 2], 2], [[2, 1, 2, 3, 4, 2], 3], [[2, 1, 2, 3, 4, 2], 4]], "outputs": [[[1, 2, 3]], [[3, 2, 1]], [[1, 2, ... | introductory | https://www.codewars.com/kata/5aec1ed7de4c7f3517000079 |
def first_n_smallest(arr, n):
|
4,079 | This is a follow up from my kata The old switcheroo
Write
```python
def encode(str)
```
that takes in a string ```str``` and replaces all the letters with their respective positions in the English alphabet.
```python
encode('abc') == '123' # a is 1st in English alpabet, b is 2nd and c is 3rd
encode('codewars') == '... | ["def encode(string):\n return ''.join(str(ord(c.upper())-64) if c.isalpha() else c for c in string)", "def encode(string):\n return ''.join(str(ord(c)-96) if c.isalpha() else c for c in string.lower())", "def encode(s):\n return ''.join(str(ord(x) - ord('a') + 1) if x.isalpha() else x for x in s.lower())", "fro... | {"fn_name": "encode", "inputs": [["abc"], ["ABCD"], ["ZzzzZ"], ["abc-#@5"], ["this is a long string!! Please [encode] @C0RrEctly"]], "outputs": [["123"], ["1234"], ["2626262626"], ["123-#@5"], ["208919 919 1 1215147 1920189147!! 161251195 [51431545] @30181853201225"]]} | introductory | https://www.codewars.com/kata/55d6a0e4ededb894be000005 |
def encode(string):
|
4,080 | Is every value in the array an array?
This should only test the second array dimension of the array. The values of the nested arrays don't have to be arrays.
Examples:
```python
[[1],[2]] => true
['1','2'] => false
[{1:1},{2:2}] => false
``` | ["def arr_check(arr):\n return all(isinstance(el, list) for el in arr)", "def arr_check(arr):\n return all(isinstance(a, list) for a in arr)", "def arr_check(arr):\n return all(type(ele) is list for ele in arr)", "def arr_check(arr):\n return all(type(i) == list for i in arr)", "def arr_check(arr):\n ret... | {"fn_name": "arr_check", "inputs": [[[]], [[["string"]]], [[[], {}]], [[[1], [2], [3]]], [["A", "R", "R", "A", "Y"]]], "outputs": [[true], [true], [false], [true], [false]]} | introductory | https://www.codewars.com/kata/582c81d982a0a65424000201 |
def arr_check(arr):
|
4,081 | Baby is getting his frst tooth. This means more sleepless nights, but with the fun of feeling round his gums and trying to guess which will be first out!
Probably best have a sweepstake with your friends - because you have the best chance of knowing. You can feel the gums and see where the raised bits are - most rais... | ["def first_tooth(lst):\n gums = lst[:1] + lst + lst[-1:]\n diff = [gums[i+1]*2 - gums[i] - gums[i+2] for i in range(len(lst))]\n m = max(diff)\n return diff.index(m) if diff.count(m) == 1 else -1\n", "def first_tooth(array):\n array = [array[0]]+array+[array[-1]]\n diffs = [2*array[i]-array[i-1]-arra... | {"fn_name": "first_tooth", "inputs": [[[1, 2, 3, 4]], [[1, 2, 6, 4]], [[1, 2, 5, 7, 1, 0, 9]], [[9, 2, 8, 1]], [[1, 1, 1, 1]], [[20, 9, 16, 19]], [[15]]], "outputs": [[3], [2], [6], [2], [-1], [0], [0]]} | introductory | https://www.codewars.com/kata/5bcac5a01cbff756e900003e |
def first_tooth(array):
|
4,082 | A series or sequence of numbers is usually the product of a function and can either be infinite or finite.
In this kata we will only consider finite series and you are required to return a code according to the type of sequence:
|Code|Type|Example|
|-|-|-|
|`0`|`unordered`|`[3,5,8,1,14,3]`|
|`1`|`strictly increasing`... | ["def sequence_classifier(arr):\n if all(arr[i] == arr[i+1] for i in range(len(arr)-1)): return 5\n if all(arr[i] < arr[i+1] for i in range(len(arr)-1)): return 1\n if all(arr[i] <= arr[i+1] for i in range(len(arr)-1)): return 2\n if all(arr[i] > arr[i+1] for i in range(len(arr)-1)): return 3\n if all(... | {"fn_name": "sequence_classifier", "inputs": [[[3, 5, 8, 1, 14, 3]], [[3, 5, 8, 9, 14, 23]], [[3, 5, 8, 8, 14, 14]], [[14, 9, 8, 5, 3, 1]], [[14, 14, 8, 8, 5, 3]], [[8, 8, 8, 8, 8, 8]], [[8, 9]], [[8, 8, 8, 8, 8, 9]], [[9, 8]], [[9, 9, 9, 8, 8, 8]], [[3, 5, 8, 1, 14, 2]]], "outputs": [[0], [1], [2], [3], [4], [5], [1],... | introductory | https://www.codewars.com/kata/5921c0bc6b8f072e840000c0 |
def sequence_classifier(arr):
|
4,083 | This challenge is based on [the kata](https://www.codewars.com/kata/n-smallest-elements-in-original-order) by GiacomoSorbi. Before doing this one it is advisable to complete the non-performance version first.
___
# Task
You will be given an array of random integers and a number `n`. You have to extract `n` smallest ... | ["from collections import Counter\nfrom itertools import count, islice\n\ndef performant_smallest(arr, n):\n cnts = Counter(arr)\n total = 0\n for i, c in sorted(cnts.items()):\n total += c\n if total >= n:\n break\n available = count(c + n - total, -1)\n it = (x for x in arr if ... | {"fn_name": "performant_smallest", "inputs": [[[1, 2, 3, 4, 5], 3], [[5, 4, 3, 2, 1], 3], [[1, 2, 3, 4, 1], 3], [[2, 1, 3, 2, 3], 3]], "outputs": [[[1, 2, 3]], [[3, 2, 1]], [[1, 2, 1]], [[2, 1, 2]]]} | introductory | https://www.codewars.com/kata/5aeed69804a92621a7000077 |
def performant_smallest(arr, n):
|
4,084 | Alex is transitioning from website design to coding and wants to sharpen his skills with CodeWars.
He can do ten kata in an hour, but when he makes a mistake, he must do pushups. These pushups really tire poor Alex out, so every time he does them they take twice as long. His first set of redemption pushups takes 5 mi... | ["from math import log\n\ndef alex_mistakes(n, time):\n return int(log((time - n * 6) / 5 +1, 2))\n", "def alex_mistakes(katas, time):\n mistakes = 0\n pushup_time = 5\n time_left = time - katas * 6\n \n while time_left >= pushup_time:\n time_left -= pushup_time\n pushup_time *= 2\n ... | {"fn_name": "alex_mistakes", "inputs": [[10, 120], [11, 120], [3, 45], [8, 120], [6, 60], [9, 180], [20, 120], [20, 125], [20, 130], [20, 135]], "outputs": [[3], [3], [2], [3], [2], [4], [0], [1], [1], [2]]} | introductory | https://www.codewars.com/kata/571640812ad763313600132b |
def alex_mistakes(number_of_katas, time_limit):
|
4,085 | One of the first chain emails I ever received was about a supposed Cambridge University study that suggests your brain can read words no matter what order the letters are in, as long as the first and last letters of each word are correct.
Your task is to **create a function that can take any string and randomly jumbl... | ["import re\nfrom random import sample\n\ndef mix_words(string):\n return re.sub(\n r'(?<=[a-zA-Z])([a-zA-Z]{2,})(?=[a-zA-Z])',\n lambda match: ''.join(sample(match.group(1), len(match.group(1)))),\n string)\n", "from re import sub\nfrom random import shuffle\n\ndef scramble(m):\n s = list(m.... | {"fn_name": "mix_words", "inputs": [["Hi"], ["Hi!"], ["Hey"], ["Hey?"]], "outputs": [["Hi"], ["Hi!"], ["Hey"], ["Hey?"]]} | introductory | https://www.codewars.com/kata/564e48ebaaad20181e000024 |
def mix_words(s):
|
4,086 | Your task is to find the first element of an array that is not consecutive.
By not consecutive we mean not exactly 1 larger than the previous element of the array.
E.g. If we have an array `[1,2,3,4,6,7,8]` then `1` then `2` then `3` then `4` are all consecutive but `6` is not, so that's the first non-consecutive num... | ["def first_non_consecutive(arr):\n if not arr: return 0\n for i, x in enumerate(arr[:-1]):\n if x + 1 != arr[i + 1]:\n return arr[i + 1]", "def first_non_consecutive(a):\n i = a[0]\n for e in a:\n if e != i:\n return e\n i += 1\n return None", "def first_non_co... | {"fn_name": "first_non_consecutive", "inputs": [[[1, 2, 3, 4, 6, 7, 8]], [[1, 2, 3, 4, 5, 6, 7, 8]], [[4, 6, 7, 8, 9, 11]], [[4, 5, 6, 7, 8, 9, 11]], [[31, 32]], [[-3, -2, 0, 1]], [[-5, -4, -3, -1]]], "outputs": [[6], [null], [6], [11], [null], [0], [-1]]} | introductory | https://www.codewars.com/kata/58f8a3a27a5c28d92e000144 |
def first_non_consecutive(arr):
|
4,087 | Write a function which takes a number and returns the corresponding ASCII char for that value.
Example:
~~~if-not:java,racket
```
get_char(65) # => 'A'
```
~~~
~~~if:java
~~~
~~~if:racket
~~~
For ASCII table, you can refer to http://www.asciitable.com/ | ["def get_char(c):\n return chr(c)", "get_char=chr", "def get_char(value):\n '''Return the ASCII char for a given value'''\n return chr(value)", "get_char = lambda c: chr(c)", "def get_char(num_of_char):\n return chr(num_of_char)", "def get_char(c):\n c = chr(c)\n return c", "def get_char(c: int) -> str:\n ... | {"fn_name": "get_char", "inputs": [[65], [33], [34], [35], [36], [37], [38]], "outputs": [["A"], ["!"], ["\""], ["#"], ["$"], ["%"], ["&"]]} | introductory | https://www.codewars.com/kata/55ad04714f0b468e8200001c |
def get_char(c):
|
4,088 | # Fun fact
Tetris was the first video game played in outer space
In 1993, Russian cosmonaut Aleksandr A. Serebrov spent 196 days on the Mir space station with a very special distraction: a gray Game Boy loaded with Tetris. During that time the game orbited the Earth 3,000 times and became the first video game played i... | ["pos = {\"L4\":0, \"L3\":1, \"L2\":2, \"L1\":3, \"L0\":4, \"R0\":4, \"R1\":5, \"R2\":6, \"R3\":7, \"R4\":8}\n\ndef tetris(arr):\n current, res = [0]*9, 0\n for x in arr:\n p = pos[x[1:]]\n current[p] += int(x[0])\n if current[p] >= 30: break\n y = min(current)\n if y: current, ... | {"fn_name": "tetris", "inputs": [[["1R4", "2L3", "3L2", "4L1", "1L0", "2R1", "3R2", "4R3", "1L4"]], [["1L2", "4R2", "3L3", "3L1", "1L4", "1R4"]], [["4R4", "4L3", "4L2", "4L1", "4L0", "4R1", "4R2", "4R3", "3L4"]]], "outputs": [[1], [0], [3]]} | introductory | https://www.codewars.com/kata/5db8a241b8d7260011746407 |
def tetris(arr):
|
4,089 | The number 45 is the first integer in having this interesting property:
the sum of the number with its reversed is divisible by the difference between them(absolute Value).
```
45 + 54 = 99
abs(45 - 54) = 9
99 is divisible by 9.
```
The first terms of this special sequence are :
```
n a(n)
1 ... | ["MEMO = []\n\ndef sum_dif_rev(n):\n i = MEMO[-1] if MEMO else 0\n \n while len(MEMO) < n:\n i += 1\n r = int(str(i)[::-1])\n if i % 10 and r != i and (i + r) % abs(r - i) == 0:\n MEMO.append(i)\n\n return MEMO[n-1]", "from itertools import count\n\n# It's not worth it to mem... | {"fn_name": "sum_dif_rev", "inputs": [[1], [3], [4], [5], [6]], "outputs": [[45], [495], [594], [4356], [4545]]} | introductory | https://www.codewars.com/kata/5603a9585480c94bd5000073 |
def sum_dif_rev(n):
|
4,090 | Farmer Bob have a big farm, where he growths chickens, rabbits and cows. It is very difficult to count the number of animals for each type manually, so he diceded to buy a system to do it. But he bought a cheap system that can count only total number of heads, total number of legs and total number of horns of animals o... | ["def get_animals_count(legs, heads, horns):\n cows = horns // 2\n rabbits = legs // 2 - cows - heads\n chickens = heads - cows - rabbits\n return dict(cows=cows, rabbits=rabbits, chickens=chickens)", "def get_animals_count(ln, hn, horn):\n c,ln,hn = horn//2, ln - 2*horn, hn - horn//2\n return {\"rabb... | {"fn_name": "get_animals_count", "inputs": [[34, 11, 6], [154, 42, 10], [74, 20, 34], [152, 38, 34], [56, 17, 0]], "outputs": [[{"rabbits": 3, "chickens": 5, "cows": 3}], [{"rabbits": 30, "chickens": 7, "cows": 5}], [{"rabbits": 0, "chickens": 3, "cows": 17}], [{"rabbits": 21, "chickens": 0, "cows": 17}], [{"rabbits": ... | introductory | https://www.codewars.com/kata/5a02037ac374cbab41000089 |
def get_animals_count(legs, heads, horns):
|
4,091 | You're continuing to enjoy your new piano, as described in Piano Kata, Part 1. You're also continuing the exercise where you start on the very first (leftmost, lowest in pitch) key on the 88-key keyboard, which (as shown below) is the note A, with the little finger on your left hand, then the second key, which is the b... | ["def which_note(count):\n return \"A A# B C C# D D# E F F# G G#\".split()[(count - 1) % 88 % 12]", "keyboard = \"A A# B C C# D D# E F F# G G#\".split()\n\ndef which_note(count):\n return keyboard[(count - 1) % 88 % 12]", "NOTES = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#']\nNUMBER_OF_KEYS =... | {"fn_name": "which_note", "inputs": [[1], [5], [12], [42], [88], [89], [92], [100], [111], [200], [2017]], "outputs": [["A"], ["C#"], ["G#"], ["D"], ["C"], ["A"], ["C"], ["G#"], ["G"], ["G#"], ["F"]]} | introductory | https://www.codewars.com/kata/589631d24a7323d18d00016f |
def which_note(key_press_count):
|
4,092 | # Grasshopper - Function syntax debugging
A student was working on a function and made some syntax mistakes while coding. Help them find their mistakes and fix them. | ["def main(verb, noun): \n return verb + noun", "def main (verb, noun):\n # This function has three problems: square brackets instead of parenthesis,\n # a colon after the parenthesis and the return command inside the\n # function is not indented.\n return verb + noun", "def main(*a):\n return ''.join... | {"fn_name": "main", "inputs": [["take ", "item"], ["use ", "sword"]], "outputs": [["take item"], ["use sword"]]} | introductory | https://www.codewars.com/kata/56dae9dc54c0acd29d00109a |
def main(verb, noun):
|
4,093 | In an infinite array with two rows, the numbers in the top row are denoted
`. . . , A[−2], A[−1], A[0], A[1], A[2], . . .`
and the numbers in the bottom row are denoted
`. . . , B[−2], B[−1], B[0], B[1], B[2], . . .`
For each integer `k`, the entry `A[k]` is directly above
the entry `B[k]` in the array, as shown:
... | ["def find_a(lst,n):\n if n<0: return find_a(lst[::-1], 3-n)\n if n<4: return lst[n]\n a,b,c,d = lst\n for _ in range(n-3):\n a,b,c,d = b, c, d, 6*d-10*c+6*b-a\n return d", "def find_a(A, n):\n if 0 <= n < 4: return A[n]\n if n < 0:\n A, n = A[::-1], abs(n) + 3\n B = [0] * 4\n B... | {"fn_name": "find_a", "inputs": [[[1, 2, 3, 4], 2], [[38, 200, -18, 45], 1], [[1, 0, 0, 1], 5], [[0, 2, 0, 3], -2], [[-20, 1, -3, 14], -5], [[1, 2, 3, 5], 100], [[0, 4, 6, 13], 100]], "outputs": [[3], [200], [20], [-126], [-44402], [60560100487003612846322657690093088848428068520476594299], [335254562473098582210532865... | introductory | https://www.codewars.com/kata/5d1eb2db874bdf9bf6a4b2aa |
def find_a(array, n):
|
4,094 | Given an array of integers.
Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers.
If the input array is empty or null, return an empty array.
# Example
For input `[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]`, you should return `[10... | ["def count_positives_sum_negatives(arr):\n if not arr: return []\n pos = 0\n neg = 0\n for x in arr:\n if x > 0:\n pos += 1\n if x < 0:\n neg += x\n return [pos, neg]", "def count_positives_sum_negatives(arr):\n pos = sum(1 for x in arr if x > 0)\n neg = sum(x for x in ... | {"fn_name": "count_positives_sum_negatives", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]], [[0, 2, 3, 0, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14]], [[1]], [[-1]], [[0, 0, 0, 0, 0, 0, 0, 0, 0]], [[]]], "outputs": [[[10, -65]], [[8, -50]], [[1, 0]], [[0, -1]], [[0, 0]], [[]]]} | introductory | https://www.codewars.com/kata/576bb71bbbcf0951d5000044 |
def count_positives_sum_negatives(arr):
|
4,095 | Given two strings, the first being a random string and the second being the same as the first, but with three added characters somewhere in the string (three same characters),
Write a function that returns the added character
### E.g
```
string1 = "hello"
string2 = "aaahello"
// => 'a'
```
The above is just an exa... | ["from collections import Counter\n\ndef added_char(s1, s2): \n return next((Counter(s2) - Counter(s1)).elements())", "def added_char(s1, s2): \n for i in s2:\n if s1.count(i) != s2.count(i):\n return i", "from functools import reduce\nfrom operator import xor\n\ndef added_char(s1, s2): \n retur... | {"fn_name": "added_char", "inputs": [["hello", "checlclo"], ["aabbcc", "aacccbbcc"], ["abcde", "2db2a2ec"]], "outputs": [["c"], ["c"], ["2"]]} | introductory | https://www.codewars.com/kata/5971b219d5db74843a000052 |
def added_char(s1, s2):
|
4,096 | Write a function called that takes a string of parentheses, and determines if the order of the parentheses is valid. The function should return `true` if the string is valid, and `false` if it's invalid.
## Examples
```
"()" => true
")(()))" => false
"(" => false
"(())((()())())... | ["def valid_parentheses(string):\n cnt = 0\n for char in string:\n if char == '(': cnt += 1\n if char == ')': cnt -= 1\n if cnt < 0: return False\n return True if cnt == 0 else False", "def valid_parentheses(string):\n count = 0\n for i in string:\n if i == \"(\":\n ... | {"fn_name": "valid_parentheses", "inputs": [[")"], ["("], [""], ["hi)("], ["hi(hi)"], ["hi(hi)("], ["((())()())"], ["(c(b(a)))(d)"], ["hi(hi))("], ["())(()"]], "outputs": [[false], [false], [true], [false], [true], [false], [true], [true], [false], [false]]} | introductory | https://www.codewars.com/kata/52774a314c2333f0a7000688 |
def valid_parentheses(string):
|
4,097 | Hi guys, welcome to introduction to DocTesting.
The kata is composed of two parts; in part (1) we write three small functions, and in part (2) we write a few doc tests for those functions.
Lets talk about the functions first...
The reverse_list function takes a list and returns the reverse of it.
If given an... | ["def reverse_list(x):\n \"\"\"Takes an list and returns the reverse of it. \n If x is empty, return [].\n \n >>> reverse_list([1, 2, 3, 4])\n [4, 3, 2, 1]\n >>> reverse_list([])\n []\n \"\"\" \n \n return x[::-1]\n\ndef sum_list(x):\n \"\"\"Takes a list, and returns the sum of that lis... | {"fn_name": "reverse_list", "inputs": [[[1, 2, 3]], [[]]], "outputs": [[[3, 2, 1]], [[]]]} | introductory | https://www.codewars.com/kata/58e4033b5600a17be1000103 |
def reverse_list(x):
|
4,098 | # Task
Your Informatics teacher at school likes coming up with new ways to help you understand the material. When you started studying numeral systems, he introduced his own numeral system, which he's convinced will help clarify things. His numeral system has base 26, and its digits are represented by English capital ... | ["def new_numeral_system(n):\n a = [c for c in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' if c <= n]\n return ['{} + {}'.format(a[i], a[-1-i]) for i in range((len(a) + 1) // 2)]", "new_numeral_system=lambda n:['%c + %c'%(65+i,ord(n)-i)for i in range(ord(n)-63>>1)]", "def new_numeral_system(number):\n return [(chr(65+i) + ' ... | {"fn_name": "new_numeral_system", "inputs": [["G"], ["A"], ["D"], ["E"], ["O"]], "outputs": [[["A + G", "B + F", "C + E", "D + D"]], [["A + A"]], [["A + D", "B + C"]], [["A + E", "B + D", "C + C"]], [["A + O", "B + N", "C + M", "D + L", "E + K", "F + J", "G + I", "H + H"]]]} | introductory | https://www.codewars.com/kata/5888445107a0d57711000032 |
def new_numeral_system(number):
|
4,099 | Your work is to write a method that takes a value and an index, and returns the value with the bit at given index flipped.
The bits are numbered from the least significant bit (index 1).
Example:
```python
flip_bit(15, 4) == 7 # 15 in binary is 1111, after flipping 4th bit, it becomes 0111, i.e. 7
flip_bit(15, 5) == ... | ["def flip_bit(value, bit_index):\n return value ^ (1 << (bit_index-1))", "flip_bit=lambda n,k:n^1<<k-1", "def flip_bit(value, bit_index):\n return value ^ 2 ** (bit_index-1)", "def flip_bit(v, b):\n return 1<<b-1 ^ v", "flip_bit=lambda v, i: int(\"\".join([l if 64-i!=k else \"0\" if l==\"1\" else \"1\" for k,... | {"fn_name": "flip_bit", "inputs": [[0, 16], [2147483647, 31], [127, 8]], "outputs": [[32768], [1073741823], [255]]} | introductory | https://www.codewars.com/kata/560e80734267381a270000a2 |
def flip_bit(value, bit_index):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.