problem_id int64 2.36k 5k | question stringlengths 52 14k | solutions stringlengths 79 675k | input_output stringlengths 37 505k | difficulty stringclasses 1
value | url stringlengths 36 94 | starter_code stringlengths 0 952 |
|---|---|---|---|---|---|---|
3,264 | In this Kata, you will implement a function `count` that takes an integer and returns the number of digits in `factorial(n)`.
For example, `count(5) = 3`, because `5! = 120`, and `120` has `3` digits.
More examples in the test cases.
Brute force is not possible. A little research will go a long way, as this is a... | ["from math import *\n\ndef count(n):\n return ceil(lgamma(n+1)/log(10))", "from math import log10, floor, pi, e\n\ndef count(n):\n if n<0: return 0\n if n<=1: return 1\n x = n*log10(n/e)+log10(2*pi*n)/2\n return floor(x)+1\n", "from math import ceil, log10, pi, e\n\ndef count(n):\n return ceil(log10(... | {"fn_name": "count", "inputs": [[5], [50], [500], [5000], [50000], [500000], [5000000], [50000000]], "outputs": [[3], [65], [1135], [16326], [213237], [2632342], [31323382], [363233781]]} | introductory | https://www.codewars.com/kata/59f34ec5a01431ab7600005a |
def count(n):
|
3,265 | See the following triangle:
```
____________________________________
1
2 4 2
3 6 9 6 3
4 8 12 16 12 8 4
5 10 15 20 25 20 15 10 5
___________________________________
```
The tot... | ["def mult_triangle(n):\n total = (n * (n + 1) / 2)**2\n odds = ((n + 1) // 2)**4\n return [total, total - odds, odds]\n", "def mult_triangle(n):\n k = n * (n + 1) // 2\n p = ((n + 1) // 2)**4\n return [k*k, k*k - p, p]", "def get_totals_for_row(n):\n total = n**3\n if n % 2 == 0:\n retur... | {"fn_name": "mult_triangle", "inputs": [[1], [2], [3], [4], [5], [10], [50]], "outputs": [[[1, 0, 1]], [[9, 8, 1]], [[36, 20, 16]], [[100, 84, 16]], [[225, 144, 81]], [[3025, 2400, 625]], [[1625625, 1235000, 390625]]]} | introductory | https://www.codewars.com/kata/58ecc0a8342ee5e920000115 |
def mult_triangle(n):
|
3,266 | # Fix the Bugs (Syntax) - My First Kata
## Overview
Hello, this is my first Kata so forgive me if it is of poor quality.
In this Kata you should fix/create a program that ```return```s the following values:
- ```false/False``` if either a or b (or both) are not numbers
- ```a % b``` plus ```b % a``` if both argum... | ["def my_first_kata(a,b):\n #your code here\n if type(a) == int and type(b) == int:\n return a % b + b % a\n else:\n return False", "def my_first_kata(a, b):\n try:\n return a % b + b % a\n except (TypeError, ZeroDivisionError):\n return False", "def my_first_kata(a,b):\n i... | {"fn_name": "my_first_kata", "inputs": [[3, 5], ["hello", 3], [67, "bye"], [true, true], [314, 107], [1, 32], [-1, -1], [19483, 9], ["hello", {}], [[], "pippi"]], "outputs": [[5], [false], [false], [false], [207], [1], [0], [16], [false], [false]]} | introductory | https://www.codewars.com/kata/56aed32a154d33a1f3000018 |
def my_first_kata(a,b):
|
3,267 | For every good kata idea there seem to be quite a few bad ones!
In this kata you need to check the provided array (x) for good ideas 'good' and bad ideas 'bad'. If there are one or two good ideas, return 'Publish!', if there are more than 2 return 'I smell a series!'. If there are no good ideas, as is often the case, ... | ["def well(x):\n c = x.count('good')\n return 'I smell a series!' if c > 2 else 'Publish!' if c else 'Fail!'", "def well(x):\n if x.count(\"good\") == 0:\n return \"Fail!\"\n elif x.count(\"good\") <= 2:\n return \"Publish!\"\n else:\n return \"I smell a series!\"", "def well(x):\n ... | {"fn_name": "well", "inputs": [[["bad", "bad", "bad"]], [["good", "bad", "bad", "bad", "bad"]], [["good", "bad", "bad", "bad", "bad", "good", "bad", "bad", "good"]]], "outputs": [["Fail!"], ["Publish!"], ["I smell a series!"]]} | introductory | https://www.codewars.com/kata/57f222ce69e09c3630000212 |
def well(x):
|
3,268 | You're given a string containing a sequence of words separated with whitespaces. Let's say it is a sequence of patterns: a name and a corresponding number - like this:
```"red 1 yellow 2 black 3 white 4"```
You want to turn it into a different **string** of objects you plan to work with later on - like this:
```"[{n... | ["import re\n\ndef words_to_object(s):\n return \"[\" + re.sub(\"([^ ]+) ([^ ]+)\", r\"{name : '\\1', id : '\\2'},\", s).strip(',') + \"]\"", "def words_to_object(s):\n return '[' + ', '.join(\"{name : '%s', id : '%s'}\" % (n, i) for n, i in zip(s.split()[::2], s.split()[1::2])) + ']'", "def words_to_object(s):\n... | {"fn_name": "words_to_object", "inputs": [["red 1 yellow 2 black 3 white 4"], ["1 red 2 white 3 violet 4 green"], ["1 1 2 2 3 3 4 4"], ["#@&fhds 123F3f 2vn2# 2%y6D @%fd3 @!#4fs W@R^g WE56h%"], [""]], "outputs": [["[{name : 'red', id : '1'}, {name : 'yellow', id : '2'}, {name : 'black', id : '3'}, {name : 'white', id : ... | introductory | https://www.codewars.com/kata/5877786688976801ad000100 |
def words_to_object(s):
|
3,269 | You are the best freelancer in the city. Everybody knows you, but what they don't know, is that you are actually offloading your work to other freelancers and and you rarely need to do any work. You're living the life!
To make this process easier you need to write a method called workNeeded to figure out how much time... | ["def work_needed(project_minutes, freelancers):\n available_minutes = sum(hours * 60 + minutes for hours, minutes in freelancers)\n workload_minutes = project_minutes - available_minutes\n if workload_minutes <= 0:\n return 'Easy Money!'\n else:\n hours, minutes = divmod(workload_minutes, 60)... | {"fn_name": "work_needed", "inputs": [[60, [[1, 0]]], [60, [[0, 0]]]], "outputs": [["Easy Money!"], ["I need to work 1 hour(s) and 0 minute(s)"]]} | introductory | https://www.codewars.com/kata/5b3e1dca3da310a4390000f3 |
def work_needed(projectMinutes, freeLancers):
|
3,270 | The pair of integer numbers `(m, n)`, such that `10 > m > n > 0`, (below 10), that its sum, `(m + n)`, and rest, `(m - n)`, are perfect squares, is (5, 4).
Let's see what we have explained with numbers.
```
5 + 4 = 9 = 3²
5 - 4 = 1 = 1²
(10 > 5 > 4 > 0)
```
The pair of numbers `(m, n)`, closest to and below 50, havi... | ["def closest_pair_tonum(uLim):\n return next( (a,b) for a in reversed(range(1,uLim)) for b in reversed(range(1,a))\n if not (a+b)**.5%1 and not (a-b)**.5%1 )", "from itertools import combinations\ndef closest_pair_tonum(upper_lim):\n return next((x, y) for x, y in combinations(range(upper_l... | {"fn_name": "closest_pair_tonum", "inputs": [[10], [30], [50], [100], [150], [200]], "outputs": [[[5, 4]], [[29, 20]], [[45, 36]], [[97, 72]], [[149, 140]], [[197, 28]]]} | introductory | https://www.codewars.com/kata/561e1e2e6b2e78407d000011 |
def closest_pair_tonum(upper_lim):
|
3,271 | We want an array, but not just any old array, an array with contents!
Write a function that produces an array with the numbers `0` to `N-1` in it.
For example, the following code will result in an array containing the numbers `0` to `4`:
```
arr(5) // => [0,1,2,3,4]
``` | ["def arr(n=0): \n return list(range(n))", "def arr(n=0): \n return [i for i in range(n)]", "def arr(n=0): \n return [*range(n)]", "def arr(n=0): \n # [ the numbers 0 to N-1 ]\n aux = []\n for x in range(n):\n aux.append(x)\n return aux\n", "def arr(n=int()): return list(range(int(),n))", "a... | {"fn_name": "arr", "inputs": [[4], [0]], "outputs": [[[0, 1, 2, 3]], [[]]]} | introductory | https://www.codewars.com/kata/571d42206414b103dc0006a1 |
def arr(n=0):
|
3,272 | ## Find Mean
Find the mean (average) of a list of numbers in an array.
## Information
To find the mean (average) of a set of numbers add all of the numbers together and divide by the number of values in the list.
For an example list of `1, 3, 5, 7`
1. Add all of the numbers
```
1+3+5+7 = 16
```
2. Divide by the ... | ["def find_average(nums):\n return float(sum(nums)) / len(nums) if len(nums) !=0 else 0", "def find_average(nums):\n return sum(nums) / float(len(nums)) if nums else 0", "def find_average(nums):\n return sum(nums) / len(nums) if nums else 0", "import numpy\n\ndef find_average(nums):\n return numpy.mean(nums... | {"fn_name": "find_average", "inputs": [[[1]], [[1, 3, 5, 7]], [[-1, 3, 5, -7]], [[5, 7, 3, 7]], [[]]], "outputs": [[1], [4], [0], [5.5], [0]]} | introductory | https://www.codewars.com/kata/55d277882e139d0b6000005d |
def find_average(nums):
|
3,273 | In this Kata, two players, Alice and Bob, are playing a palindrome game. Alice starts with `string1`, Bob starts with `string2`, and the board starts out as an empty string. Alice and Bob take turns; during a turn, a player selects a letter from his or her string, removes it from the string, and appends it to the board... | ["from collections import Counter\n\ndef solve(*args):\n c1, c2 = map(Counter, args)\n return 2 - any(c1[k]-c2[k] >= 2 and k not in c2 for k in c1)", "def solve(str1, str2):\n return 2 - any(str1.count(c) > 1 and c not in str2 for c in str1)", "def solve(a, b):\n return [2, 1][any(a.count(e) > 1 for e in a ... | {"fn_name": "solve", "inputs": [["abc", "xyz"], ["abc", "axy"], ["abc", "bax"], ["btzgd", "svjyb"], ["eyfjy", "ooigv"], ["mctimp", "eyqbnh"], ["qtkxttl", "utvohqk"]], "outputs": [[2], [2], [2], [2], [1], [1], [2]]} | introductory | https://www.codewars.com/kata/5a26af968882f3523100003d |
def solve(str1, str2):
|
3,274 | In this Kata, you will be given a string and your task will be to return the length of the longest prefix that is also a suffix. A prefix is the start of a string while the suffix is the end of a string. For instance, the prefixes of the string `"abcd"` are `["a","ab","abc"]`. The suffixes are `["bcd", "cd", "d"]`. Yo... | ["def solve(st):\n return next((n for n in range(len(st)//2, 0, -1) if st[:n] == st[-n:]), 0)\n", "def solve(s):\n for i in range(len(s) // 2, 0, -1):\n if s[:i] == s[-i:]:\n return i\n return 0", "solve=lambda s:len(__import__('re').match(r'^(.*).*\\1$',s).group(1))", "def solve(st):\n i ... | {"fn_name": "solve", "inputs": [["abcd"], ["abcda"], ["abcdabc"], ["abcabc"], ["abcabca"], ["abcdabcc"], ["aaaaa"], ["aaaa"], ["aaa"], ["aa"], ["a"], ["acbacc"]], "outputs": [[0], [1], [3], [3], [1], [0], [2], [2], [1], [1], [0], [0]]} | introductory | https://www.codewars.com/kata/5ce969ab07d4b7002dcaa7a1 |
def solve(st):
|
3,275 | *It seemed a good idea at the time...*
# Why I did it?
After a year on **Codewars** I really needed a holiday...
But not wanting to drift backwards in the honour rankings while I was away, I hatched a cunning plan!
# The Cunning Plan
So I borrowed my friend's "Clone Machine" and cloned myself :-)
Now my clone can... | ["def clonewars(k):\n return [2**max(k-1,0),2**(k+1)-k-2]", "clonewars=lambda n:[-~2**n//2,2**-~n-n-2]", "def clonewars(n):\n return [2**max(n-1,0), 2**(n+1)-(n+2)]", "def clonewars(n):\n return [max(1,2**(n-1)), 2**(n+1)-n-2]", "def clonewars(n):\n if n == 0: return [1,0]\n return [2**(n-1), 2**(n+1) - ... | {"fn_name": "clonewars", "inputs": [[0], [1], [5], [10]], "outputs": [[[1, 0]], [[1, 1]], [[16, 57]], [[512, 2036]]]} | introductory | https://www.codewars.com/kata/58ddffda929dfc2cae0000a5 |
def clonewars(n):
|
3,276 | Jenny is 9 years old. She is the youngest detective in North America. Jenny is a 3rd grader student, so when a new mission comes up, she gets a code to decipher in a form of a sticker (with numbers) in her math notebook and a comment (a sentence) in her writing notebook. All she needs to do is to figure out one word, f... | ["def missing(nums, s):\n ans = []\n s = s.replace(' ','')\n try:\n for i in sorted(nums):\n ans.append(s[i])\n return ''.join(ans).lower()\n except IndexError:\n return (\"No mission today\")", "def missing(nums, str):\n str=str.replace(' ','').lower()\n try:\n ... | {"fn_name": "missing", "inputs": [[[0, 3, 5], "I love you"], [[7, 10, 1], "see you later"], [[29, 31, 8], "The quick brown fox jumps over the lazy dog"], [[12, 4, 6], "Good Morning"], [[1, 16, 21], "A purple pig and a green donkey flew a kite in the middle of the night"], [[35, 8, 20], "A song can make or ruin your day... | introductory | https://www.codewars.com/kata/58b972cae826b960a300003e |
def missing(nums, str):
|
3,277 | You have to create a function which receives 3 arguments: 2 numbers, and the result of an unknown operation performed on them (also a number).
Based on those 3 values you have to return a string, that describes which operation was used to get the given result.
The possible return strings are:
`"addition"`,
`"subt... | ["def calc_type(a, b, res):\n return {a + b: \"addition\", a - b: \"subtraction\", a * b: \"multiplication\", a / b: \"division\"}[res]\n", "from operator import add, sub, mul, truediv\n\nOPS = ((\"addition\", add),\n (\"subtraction\", sub),\n (\"multiplication\", mul),\n (\"division\", truediv))\n... | {"fn_name": "calc_type", "inputs": [[1, 2, 3], [10, 5, 5], [10, 4, 40], [9, 5, 1.8]], "outputs": [["addition"], ["subtraction"], ["multiplication"], ["division"]]} | introductory | https://www.codewars.com/kata/5aca48db188ab3558e0030fa |
def calc_type(a, b, res):
|
3,278 | Given a string that includes alphanumeric characters ('3a4B2d') return the expansion of that string: The numeric values represent the occurrence of each letter preceding that numeric value. There should be no numeric characters in the final string. Empty strings should return an empty string.
The first occurrence of... | ["def string_expansion(s):\n m,n = '',1\n for j in s:\n if j.isdigit():\n n = int(j)\n else:\n m += j*n\n return m", "import re\n\ndef string_expansion(s):\n return ''.join(''.join(int(n or '1')*c for c in cc) for n,cc in re.findall(r'(\\d?)(\\D+)', s))\n", "def string_ex... | {"fn_name": "string_expansion", "inputs": [["3D2a5d2f"], ["4D1a8d4j3k"], ["4D2a8d4j2f"], ["3n6s7f3n"], ["0d4n8d2b"], ["0c3b1n7m"], ["7m3j4ik2a"], ["3A5m3B3Y"], ["5M0L8P1"], ["2B"], ["7M1n3K"], ["A4g1b4d"], ["111111"], ["4d324n2"], ["5919nf3u"], ["2n1k523n4i"], ["6o23M32d"], ["1B44n3r"], ["M21d1r32"], ["23M31r2r2"], ["8... | introductory | https://www.codewars.com/kata/5ae326342f8cbc72220000d2 |
def string_expansion(s):
|
3,279 | Once upon a time, a CodeWarrior, after reading a [discussion on what can be the plural](http://www.codewars.com/kata/plural/discuss/javascript), took a look at [this page](http://en.wikipedia.org/wiki/Grammatical_number#Types_of_number
) and discovered that **more than 1** "kind of plural" may exist.
For example [Sur... | ["import re\n\ndef sursurungal(txt):\n txt=re.sub(r'\\b2\\s(\\S+)s', r'2 bu\\1', txt) \n txt=re.sub(r'\\b([3-9])\\s(\\S+)s', r'\\1 \\2zo', txt)\n return re.sub(r'(\\d+\\d)\\s(\\S+)s', r'\\1 ga\\2ga', txt)\n \n", "import re\n\ndef sursurungal(txt):\n txt = re.sub(r'\\b2\\s(\\S+)s', r'2 bu\\1', txt)\n t... | {"fn_name": "sursurungal", "inputs": [["1 tomato"], ["0 tomato"], ["1 ananas"], ["2 bananas"], ["3 bananas"], ["10 bananas"], ["111 bananas"], ["6 birds with 2 wings each = 12 legs"], ["\n3 pigs\nmet 1 wolf\n2 days ago"]], "outputs": [["1 tomato"], ["0 tomato"], ["1 ananas"], ["2 bubanana"], ["3 bananazo"], ["10 gabana... | introductory | https://www.codewars.com/kata/5536aba6e4609cc6a600003d |
def sursurungal(txt):
|
3,280 | Write a function, which takes a non-negative integer (seconds) as input and returns the time in a human-readable format (`HH:MM:SS`)
* `HH` = hours, padded to 2 digits, range: 00 - 99
* `MM` = minutes, padded to 2 digits, range: 00 - 59
* `SS` = seconds, padded to 2 digits, range: 00 - 59
The maximum time never excee... | ["def make_readable(s):\n return '{:02}:{:02}:{:02}'.format(s // 3600, s // 60 % 60, s % 60)\n", "def make_readable(seconds):\n hours, seconds = divmod(seconds, 60 ** 2)\n minutes, seconds = divmod(seconds, 60)\n return '{:02}:{:02}:{:02}'.format(hours, minutes, seconds)", "def make_readable(seconds):\n ... | {"fn_name": "make_readable", "inputs": [[0], [59], [60], [3599], [3600], [86399], [86400], [359999]], "outputs": [["00:00:00"], ["00:00:59"], ["00:01:00"], ["00:59:59"], ["01:00:00"], ["23:59:59"], ["24:00:00"], ["99:59:59"]]} | introductory | https://www.codewars.com/kata/52685f7382004e774f0001f7 |
def make_readable(seconds):
|
3,281 | _Friday 13th or Black Friday is considered as unlucky day. Calculate how many unlucky days are in the given year._
Find the number of Friday 13th in the given year.
__Input:__ Year as an integer.
__Output:__ Number of Black Fridays in the year as an integer.
__Examples:__
unluckyDays(2015) == 3
unl... | ["from datetime import date\n\ndef unlucky_days(year):\n return sum(date(year, m, 13).weekday() == 4 for m in range(1, 13))", "from calendar import weekday\n\ndef unlucky_days(year):\n return sum(1 for i in range(1, 13) if weekday(year, i, 13) == 4)\n", "from datetime import datetime\n\ndef unlucky_days(year):\n ... | {"fn_name": "unlucky_days", "inputs": [[1634], [2873], [1586]], "outputs": [[2], [2], [1]]} | introductory | https://www.codewars.com/kata/56eb0be52caf798c630013c0 |
def unlucky_days(year):
|
3,282 | Lot of museum allow you to be a member, for a certain amount `amount_by_year` you can have unlimitted acces to the museum.
In this kata you should complete a function in order to know after how many visit it will be better to take an annual pass. The function take 2 arguments `annual_price` and `individual_price`. | ["from math import ceil\nfrom operator import truediv\n\n\ndef how_many_times(annual_price, individual_price):\n return int(ceil(truediv(annual_price, individual_price)))", "from math import ceil\ndef how_many_times(ap, ip):\n return ceil(ap/ip)\n", "def how_many_times(annual_price, individual_price):\n count ... | {"fn_name": "how_many_times", "inputs": [[40, 15], [30, 10], [80, 15]], "outputs": [[3], [3], [6]]} | introductory | https://www.codewars.com/kata/57efcb78e77282f4790003d8 |
def how_many_times(annual_price, individual_price):
|
3,283 | Your aged grandfather is tragically optimistic about Team GB's chances in the upcoming World Cup, and has enlisted you to help him make [Union Jack](https://en.wikipedia.org/wiki/Union_Jack) flags to decorate his house with.
## Instructions
* Write a function which takes as a parameter a number which represents the d... | ["from math import ceil\n\ndef union_jack(n):\n if not isinstance(n, (int, float)):\n return False\n n = max(7, ceil(n))\n h, m = divmod(n-1, 2)\n flag = [[\"X\" if len({i, n-j-1, j, h, h+m}) < 4+m else \"-\" for i in range(n)] for j in range(n)] \n return \"\\n\".join(\"\".join(row) for row in fl... | {"fn_name": "union_jack", "inputs": [[4.5], [7.1], [19.00384], [109.1], [66.4], ["pippi"], [{}]], "outputs": [["X--X--X\n-X-X-X-\n--XXX--\nXXXXXXX\n--XXX--\n-X-X-X-\nX--X--X"], ["X--XX--X\n-X-XX-X-\n--XXXX--\nXXXXXXXX\nXXXXXXXX\n--XXXX--\n-X-XX-X-\nX--XX--X"], ["X--------XX--------X\n-X-------XX-------X-\n--X------XX--... | introductory | https://www.codewars.com/kata/5620281f0eeee479cd000020 |
def union_jack(n):
|
3,284 | Each floating-point number should be formatted that only the first two decimal places are returned. You don't need to check whether the input is a valid number because only valid numbers are used in the tests.
Don't round the numbers! Just cut them after two decimal places!
```
Right examples:
32.8493 is 32.84
1... | ["def two_decimal_places(number):\n \n return int (number * 100) / 100.0", "from math import trunc\n\n\ndef two_decimal_places(number):\n factor = float(10 ** 2)\n return trunc(number * factor) / factor\n", "def two_decimal_places(number):\n number = str(number)\n return float(number[:number.index('.'... | {"fn_name": "two_decimal_places", "inputs": [[10.1289767789], [-7488.83485834983], [4.653725356]], "outputs": [[10.12], [-7488.83], [4.65]]} | introductory | https://www.codewars.com/kata/5641c3f809bf31f008000042 |
def two_decimal_places(number):
|
3,285 | We all love the future president (or Führer or duce or sōtō as he could find them more fitting) donald trump, but we might fear that some of his many fans like John Miller or John Barron are not making him justice, sounding too much like their (and our as well, of course!) hero and thus risking to compromise him.
For ... | ["import re\ndef trump_detector(ts):\n x=re.findall(r'([aeiou])(\\1*)',ts,re.I)\n y=[len(i[1]) for i in x]\n return round(sum(y)/len(y),2)", "import re\n\ndef trump_detector(trump_speech):\n lst = [ len(tup[1]) for tup in re.findall(r'([aeiou])(\\1*)', trump_speech, re.I) ]\n return round(sum(lst)/len(ls... | {"fn_name": "trump_detector", "inputs": [["I will build a huge wall"], ["HUUUUUGEEEE WAAAAAALL"], ["MEXICAAAAAAAANS GOOOO HOOOMEEEE"], ["America NUUUUUKEEEE Oooobaaaamaaaaa"], ["listen migrants: IIII KIIIDD YOOOUUU NOOOOOOTTT"]], "outputs": [[0], [4], [2.5], [1.89], [1.56]]} | introductory | https://www.codewars.com/kata/57829376a1b8d576640000d6 |
def trump_detector(trump_speech):
|
3,286 | ### The Story:
Bob is working as a bus driver. However, he has become extremely popular amongst the city's residents. With so many passengers wanting to get aboard his bus, he sometimes has to face the problem of not enough space left on the bus! He wants you to write a simple program telling him if he will be able to ... | ["def enough(cap, on, wait):\n return max(0, wait - (cap - on))", "def enough(cap, on, wait):\n return max(0, on + wait - cap)", "def enough(cap, on, wait):\n return wait + on - cap if wait + on > cap else 0", "def enough(cap, on, wait):\n return max(on + wait - cap, 0)", "def enough(cap, on, wait):\n if... | {"fn_name": "enough", "inputs": [[10, 5, 5], [100, 60, 50], [20, 5, 5]], "outputs": [[0], [10], [0]]} | introductory | https://www.codewars.com/kata/5875b200d520904a04000003 |
def enough(cap, on, wait):
|
3,287 | The wide mouth frog is particularly interested in the eating habits of other creatures.
He just can't stop asking the creatures he encounters what they like to eat. But then he meet the alligator who just LOVES to eat wide-mouthed frogs!
When he meets the alligator, it then makes a tiny mouth.
Your goal in this kata... | ["def mouth_size(animal): \n return 'small' if animal.lower() == 'alligator' else 'wide'", "def mouth_size(animal): \n return 'wide' if animal.lower() != 'alligator' else 'small'", "def mouth_size(animal): \n mouth = {'alligator':'small'}\n return mouth.get(animal.lower(), 'wide')", "import re\n\ndef mouth_si... | {"fn_name": "mouth_size", "inputs": [["toucan"], ["ant bear"], ["alligator"]], "outputs": [["wide"], ["wide"], ["small"]]} | introductory | https://www.codewars.com/kata/57ec8bd8f670e9a47a000f89 |
def mouth_size(animal):
|
3,288 | In this Kata, you will be given a number in form of a string and an integer `k` and your task is to insert `k` commas into the string and determine which of the partitions is the largest.
```
For example:
solve('1234',1) = 234 because ('1','234') or ('12','34') or ('123','4').
solve('1234',2) = 34 because ('1','2','3... | ["def solve(st, k):\n length = len(st) - k\n return max(int(st[i:i + length]) for i in range(k + 1))", "def solve(st,k):\n c=len(st)-k\n return int(max(st[i:i+c] for i in range(k+1)))", "def solve(st,k):\n return max([int(st[i:i+len(st)-k]) for i in range(len(st))])", "def solve(st, k):\n n = len(st) ... | {"fn_name": "solve", "inputs": [["1234", 1], ["1234", 2], ["1234", 3], ["2020", 1]], "outputs": [[234], [34], [4], [202]]} | introductory | https://www.codewars.com/kata/5b83c1c44a6acac33400009a |
def solve(st,k):
|
3,289 | In genetics, a sequence’s motif is a nucleotides (or amino-acid) sequence pattern. Sequence motifs have a biological significance. For more information you can take a look [here](https://en.wikipedia.org/wiki/Sequence_motif).
For this kata you need to complete the function `motif_locator`. This function receives 2 ar... | ["def motif_locator(sequence, motif):\n res, i = [], 0\n while True:\n i = sequence.find(motif, i) + 1\n if not i: return res\n res.append(i)", "def motif_locator(sequence, motif):\n return [i+1 for i,c in enumerate(sequence) if sequence[i:i+len(motif)] == motif]", "def motif_locator(seq, ... | {"fn_name": "motif_locator", "inputs": [["TTCCGGAACC", "CC"], ["ACGTTACAACGTTAG", "ACGT"], ["ACGTACGTACGT", "AAA"], ["ACGT", "ACGTGAC"]], "outputs": [[[3, 9]], [[1, 9]], [[]], [[]]]} | introductory | https://www.codewars.com/kata/5760c1c7f2717b91e20001a4 |
def motif_locator(sequence, motif):
|
3,290 | Create a function that takes in the sum and age difference of two people, calculates their individual ages, and returns a pair of values (oldest age first) if those exist or `null/None` if:
* `sum < 0`
* `difference < 0`
* Either of the calculated ages come out to be negative | ["def get_ages(a,b):\n x = (a+b)/2\n y = (a-b)/2\n return None if a<0 or b<0 or x<0 or y<0 else (x,y)", "def get_ages(s, diff):\n older, younger = (s / 2) + (diff / 2), (s / 2) - (diff / 2) \n if older >= younger >= 0:\n return (older, younger)", "def get_ages(s, diff):\n older = (s / 2) + (di... | {"fn_name": "get_ages", "inputs": [[24, 4], [30, 6], [70, 10], [18, 4], [63, 14], [80, 80], [63, -14], [-22, 15]], "outputs": [[[14, 10]], [[18, 12]], [[40, 30]], [[11, 7]], [[38.5, 24.5]], [[80, 0]], [null], [null]]} | introductory | https://www.codewars.com/kata/58e0bd6a79716b7fcf0013b1 |
def get_ages(sum_, difference):
|
3,291 | Generate and return **all** possible increasing arithmetic progressions of six primes `[a, b, c, d, e, f]` between the given limits. Note: the upper and lower limits are inclusive.
An arithmetic progression is a sequence where the difference between consecutive numbers is the same, such as: 2, 4, 6, 8.
A prime number... | ["is_prime = lambda n: all(n % d for d in range(3, int(n ** .5) + 1, 2))\n\ndef primes_a_p(lower_limit, upper_limit):\n a_p = []\n for n in range(lower_limit | 1, upper_limit, 2):\n for gap in range(30, (upper_limit - n) // 5 + 1, 30):\n sequence = [n + i * gap for i in range(6)]\n if... | {"fn_name": "primes_a_p", "inputs": [[0, 200], [90, 600], [770, 1000], [30, 305], [1000, 4000]], "outputs": [[[[7, 37, 67, 97, 127, 157]]], [[[107, 137, 167, 197, 227, 257], [359, 389, 419, 449, 479, 509]]], [[]], [[[107, 137, 167, 197, 227, 257]]], [[[1013, 1193, 1373, 1553, 1733, 1913], [1039, 1249, 1459, 1669, 1879,... | introductory | https://www.codewars.com/kata/5aa7ce59373c2e3ed30000cb |
def primes_a_p(lower_limit, upper_limit):
|
3,292 | Given a string, turn each letter into its ASCII character code and join them together to create a number - let's call this number `total1`:
```
'ABC' --> 'A' = 65, 'B' = 66, 'C' = 67 --> 656667
```
Then replace any incidence of the number `7` with the number `1`, and call this number 'total2':
```
total1 = 656667
... | ["def calc(s):\n total1 = ''.join(map(lambda c: str(ord(c)), s))\n total2 = total1.replace('7', '1')\n return sum(map(int, total1)) - sum(map(int, total2))", "def calc(x):\n return ''.join(str(ord(ch)) for ch in x).count('7') * 6", "def calc(x):\n return ''.join([str(ord(x[i])) for i in range(len(x)) ]).... | {"fn_name": "calc", "inputs": [["abcdef"], ["ifkhchlhfd"], ["aaaaaddddr"], ["jfmgklf8hglbe"], ["jaam"], ["abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"]], "outputs": [[6], [6], [30], [6], [12], [96]]} | introductory | https://www.codewars.com/kata/57f75cc397d62fc93d000059 |
def calc(x):
|
3,293 | Rule 30 is a one-dimensional binary cellular automaton. You can have some information here:
* [https://en.wikipedia.org/wiki/Rule_30](https://en.wikipedia.org/wiki/Rule_30)
You have to write a function that takes as input an array of 0 and 1 and a positive integer that represents the number of iterations. This func... | ["def rule30(a, n):\n for _ in range(n):\n a = [int(0 < 4*x + 2*y + z < 5) for x, y, z in\n zip([0, 0] + a, [0] + a + [0], a + [0, 0])]\n return a", "def rule30(li, n):\n for i in range(n):\n li = [0] + li + [0]\n li = [(li[k-1] if k else 0)^(l or (li[k+1] if k<len(li)-1 els... | {"fn_name": "rule30", "inputs": [[[1], 1], [[1], 2], [[1], 21], [[0], 5], [[0], 0], [[1, 1, 1], 0], [[0], 3], [[1], -3], [[1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1], 1], [[1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1], 75]], "outputs": [[[1, 1, 1]], [[1, 1, 0, 0, 1]], [[1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0,... | introductory | https://www.codewars.com/kata/5581e52ac76ffdea700000c1 |
def rule30(list_, n):
|
3,294 | Sometimes, I want to quickly be able to convert miles per imperial gallon into kilometers per liter.
Create an application that will display the number of kilometers per liter (output) based on the number of miles per imperial gallon (input).
Make sure to round off the result to two decimal points. If the answer ends... | ["def converter(mpg):\n '''Converts mpg to kpl. Rounds to two decimal places.'''\n kpl = round(mpg * 1.609344/4.54609188, 2)\n return kpl", "\ndef converter(mpg):\n #your code here\n return round(mpg / 4.54609188 * 1.609344 , 2)\n", "def converter(mpg):\n return round((mpg * 1.609344 / 4.54609188)... | {"fn_name": "converter", "inputs": [[10], [20], [30], [24], [36]], "outputs": [[3.54], [7.08], [10.62], [8.5], [12.74]]} | introductory | https://www.codewars.com/kata/557b5e0bddf29d861400005d |
def converter(mpg):
|
3,295 | The aim of this kata is to split a given string into different strings of equal size (note size of strings is passed to the method)
Example:
Split the below string into other strings of size #3
'supercalifragilisticexpialidocious'
Will return a new string
'sup erc ali fra gil ist ice xpi ali doc iou... | ["from textwrap import wrap\n\n\ndef split_in_parts(s, part_length): \n return \" \".join(wrap(s,part_length))", "def split_in_parts(s, n): \n return ' '.join([s[i:i+n] for i in range(0, len(s), n)])", "def split_in_parts(s, part_length): \n new = \"\"\n i = 0\n for x in s: # Recorremos... | {"fn_name": "split_in_parts", "inputs": [["supercalifragilisticexpialidocious", 3], ["HelloKata", 1], ["HelloKata", 9]], "outputs": [["sup erc ali fra gil ist ice xpi ali doc iou s"], ["H e l l o K a t a"], ["HelloKata"]]} | introductory | https://www.codewars.com/kata/5650ab06d11d675371000003 |
def split_in_parts(s, part_length):
|
3,296 | Return the century of the input year. The input will always be a 4 digit string, so there is no need for validation.
### Examples
```
"1999" --> "20th"
"2011" --> "21st"
"2154" --> "22nd"
"2259" --> "23rd"
"1124" --> "12th"
"2000" --> "20th"
``` | ["def what_century(year):\n n = (int(year) - 1) // 100 + 1\n return str(n) + (\"th\" if n < 20 else {1: \"st\", 2: \"nd\", 3: \"rd\"}.get(n % 10, \"th\"))", "def what_century(year):\n year = str(year)\n st = year[:2]\n st = int(st)\n gt = st + 1\n gt = str(gt)\n if year != \"0000\" and year[1:] ... | {"fn_name": "what_century", "inputs": [["1999"]], "outputs": [["20th"]]} | introductory | https://www.codewars.com/kata/52fb87703c1351ebd200081f |
def what_century(year):
|
3,297 | A stick is balanced horizontally on a support. Will it topple over or stay balanced? (This is a physics problem: imagine a real wooden stick balanced horizontally on someone's finger or on a narrow table, for example).
The stick is represented as a list, where each entry shows the mass in that part of the stick.
The... | ["from math import ceil\n\ndef will_it_balance(stick, gnd):\n gravPt = sum(v*i for i,v in enumerate(stick)) / sum(stick)\n return gnd[int(gravPt)] == gnd[ceil(gravPt)] == 1", "def will_it_balance(stick, terrain):\n com = sum(i*w for i,w in enumerate(stick))/sum(stick)\n return terrain.index(1)<=com<=max(i f... | {"fn_name": "will_it_balance", "inputs": [[[2, 3, 2], [0, 1, 0]], [[5, 1, 1], [0, 1, 0]], [[3, 3, 4], [0, 1, 0]], [[9, 7, 1, 1], [1, 1, 0, 0]], [[9, 1, 1, 7], [1, 1, 0, 0]]], "outputs": [[true], [false], [false], [true], [false]]} | introductory | https://www.codewars.com/kata/5a8328fefd57777fa3000072 |
def will_it_balance(stick, terrain):
|
3,298 | # ASC Week 1 Challenge 5 (Medium #2)
Create a function that takes a 2D array as an input, and outputs another array that contains the average values for the numbers in the nested arrays at the corresponding indexes.
Note: the function should also work with negative numbers and floats.
## Examples
```
[ [1, 2, 3, 4]... | ["def avg_array(arrs):\n return [sum(a)/len(a) for a in zip(*arrs)]", "def avg_array(arrs):\n length = len(arrs)\n return [sum(arr)/length for arr in zip(*arrs)]", "from statistics import mean\n\ndef avg_array(arrs):\n return list(map(mean,zip(*arrs)))", "def avg_array(arrs):\n return [(sum(ar[i] for ar ... | {"fn_name": "avg_array", "inputs": [[[[1, 2, 3, 4], [5, 6, 7, 8]]], [[[2, 3, 9, 10, 7], [12, 6, 89, 45, 3], [9, 12, 56, 10, 34], [67, 23, 1, 88, 34]]], [[[2, 5, 4, 3, 19], [2, 5, 6, 7, 10]]], [[[1.2, 8.521, 0.4, 3.14, 1.9], [2, 4.5, 3.75, 0.987, 1.0]]], [[[2, 5, -4, 3, -19], [-2, -5, 6, 7, 10]]], [[[-2, -18, -45, -10],... | introductory | https://www.codewars.com/kata/596f6385e7cd727fff0000d6 |
def avg_array(arrs):
|
3,299 | # 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 some cards in a row. A number is written on each card.
In each turn, John can take a card, but only from the beginning or the end of the row. Then multiply the number on the... | ["def calc(a):\n res = [0] * (len(a) + 1)\n for k in range(len(a)):\n res = [2 * max(a[i] + res[i+1], a[i+k] + res[i]) for i in range(len(a) - k)]\n return res[0]", "from functools import lru_cache\n\ncalc = lambda cards : get(tuple(cards))\nget = lru_cache(None) ( lambda seq, turn=1:max([2**turn*seq[0]... | {"fn_name": "calc", "inputs": [[[1, 2, 5]], [[1]], [[1, 1]], [[1, 2, 1]], [[4, 10, 2, 3, 1, 3, 1, 6, 9]]], "outputs": [[50], [2], [6], [22], [6722]]} | introductory | https://www.codewars.com/kata/5c2d5de69611562191289041 |
def calc(cards):
|
3,300 | In input string ```word```(1 word):
* replace the vowel with the nearest left consonant.
* replace the consonant with the nearest right vowel.
P.S. To complete this task imagine the alphabet is a circle (connect the first and last element of the array in the mind). For example, 'a' replace with 'z', 'y' with 'a', etc.... | ["def replace_letters(word):\n return word.translate(str.maketrans('abcdefghijklmnopqrstuvwxyz','zeeediiihooooonuuuuutaaaaa')) \n", "table = str.maketrans('abcdefghijklmnopqrstuvwxyz', 'zeeediiihooooonuuuuutaaaaa')\ndef replace_letters(word): return word.translate(table)", "from string import ascii_lowercase as al\n\n... | {"fn_name": "replace_letters", "inputs": [["cat"], ["codewars"], ["abcdtuvwxyz"]], "outputs": [["ezu"], ["enedazuu"], ["zeeeutaaaaa"]]} | introductory | https://www.codewars.com/kata/5a4331b18f27f2b31f000085 |
def replace_letters(word):
|
3,301 | Give the summation of all even numbers in a Fibonacci sequence up to, but not including, the maximum value.
The Fibonacci sequence is a series of numbers where the next value is the addition of the previous two values. The series starts with 0 and 1:
0 1 1 2 3 5 8 13 21...
For example:
```python
eve_fib(0)==0
eve_fi... | ["def even_fib(m):\n x,y = 0, 1\n counter = 0\n while y < m:\n if y % 2 == 0:\n counter += y\n x,y = y, x+ y\n return counter", "def even_fib(m):\n a, b, total = 1, 1, 0\n \n while a < m:\n if a % 2 == 0:\n total += a\n a, b = b, a + b\n \n re... | {"fn_name": "even_fib", "inputs": [[0], [10], [5], [100], [1000], [1000000], [100000000], [1000000000], [2147483647], [-1]], "outputs": [[0], [10], [2], [44], [798], [1089154], [82790070], [350704366], [1485607536], [0]]} | introductory | https://www.codewars.com/kata/55688b4e725f41d1e9000065 |
def even_fib(m):
|
3,302 | # Task
Define crossover operation over two equal-length strings A and B as follows:
the result of that operation is a string of the same length as the input strings result[i] is chosen at random between A[i] and B[i].
Given array of strings `arr` and a string result, find for how many pairs of strings from `arr`... | ["from itertools import combinations\ndef strings_crossover(arr, result):\n return sum(1 for s1,s2 in combinations(arr,2) if all(r in (x,y) for x,y,r in zip(s1,s2,result)))", "from collections import Counter\n\ndef strings_crossover(arr, result):\n lstBit = [ int(''.join(['01'[x==y] for x,y in zip(result, w)]), 2... | {"fn_name": "strings_crossover", "inputs": [[["abc", "aaa", "aba", "bab"], "bbb"], [["aacccc", "bbcccc"], "abdddd"], [["a", "b", "c", "d", "e"], "c"], [["aa", "ab", "ba"], "bb"], [["a", "b", "c", "d", "e"], "f"], [["aaa", "aaa"], "aaa"]], "outputs": [[2], [0], [4], [1], [0], [1]]} | introductory | https://www.codewars.com/kata/5889902f53ad4a227100003f |
def strings_crossover(arr, result):
|
3,303 | Given a mixed array of number and string representations of integers, add up the string integers and subtract this from the total of the non-string integers.
Return as a number. | ["def div_con(lst):\n return sum(n if isinstance(n, int) else -int(n) for n in lst)", "def div_con(x):\n return sum([a for a in x if isinstance(a, int)]) - sum([int(a) for a in x if not isinstance(a, int)])", "def div_con(x):\n integer = []\n string = []\n for element in x:\n if type(element) == i... | {"fn_name": "div_con", "inputs": [[[9, 3, "7", "3"]], [["5", "0", 9, 3, 2, 1, "9", 6, 7]], [["3", 6, 6, 0, "5", 8, 5, "6", 2, "0"]], [["1", "5", "8", 8, 9, 9, 2, "3"]], [[8, 0, 0, 8, 5, 7, 2, 3, 7, 8, 6, 7]]], "outputs": [[2], [14], [13], [11], [61]]} | introductory | https://www.codewars.com/kata/57eaec5608fed543d6000021 |
def div_con(x):
|
3,304 | An array is defined to be `inertial`if the following conditions hold:
```
a. it contains at least one odd value
b. the maximum value in the array is even
c. every odd value is greater than every even value that is not the maximum value.
```
eg:-
```
So [11, 4, 20, 9, 2, 8] is inertial because
a. it contains at leas... | ["def is_inertial(arr):\n mx = max(arr, default=1)\n miO = min((x for x in arr if x%2==1), default=float(\"-inf\"))\n miE2 = max((x for x in arr if x%2==0 and x!=mx), default=float(\"-inf\"))\n return mx%2 == 0 and miE2 < miO", "def is_inertial(lst):\n odds = [n for n in lst if n % 2 == 1]\n evens ... | {"fn_name": "is_inertial", "inputs": [[[]], [[581, -384, 140, -287]], [[11, 4, 20, 9, 2, 8]]], "outputs": [[false], [false], [true]]} | introductory | https://www.codewars.com/kata/59a151c53f64cdd94c00008f |
def is_inertial(arr):
|
3,305 | ## TL;DR
Given a number of vertices `N` and a list of weighted directed edges in a directed acyclic graph (each edge is written as `[start, end, weight]` where `from < to`), compute the weight of the shortest path from vertex `0` to vertex `N - 1`. If there is no such path, return `-1`.
## Background
A weighted DAG... | ["import heapq\nfrom collections import defaultdict\n\ndef shortest(N, edge):\n ver, inf = defaultdict(list), 10**10\n for e in edge: ver[e[0]].append(e[1:])\n\n dist = {i:inf for i in range(N)}\n dist[0], pq = 0, []\n heapq.heappush(pq, [dist[0], 0])\n while pq: \n u_dis, u_node = heapq.heappo... | {"fn_name": "shortest", "inputs": [[4, [[0, 1, 1], [0, 2, 5], [0, 3, 5], [1, 3, 3], [2, 3, 1]]], [3, [[0, 1, 7], [1, 2, 5], [0, 2, 12]]], [5, [[0, 2, 1], [1, 2, 1], [0, 3, 1], [1, 4, 1]]]], "outputs": [[4], [12], [-1]]} | introductory | https://www.codewars.com/kata/5a2c343e8f27f2636c0000c9 |
def shortest(N, edgeList):
|
3,306 | You will be given two strings `a` and `b` consisting of lower case letters, but `a` will have at most one asterix character. The asterix (if any) can be replaced with an arbitrary sequence (possibly empty) of lowercase letters. No other character of string `a` can be replaced. If it is possible to replace the asterix i... | ["from fnmatch import fnmatch\n\ndef solve(a, b):\n return fnmatch(b, a)", "import re\ndef solve(a,b):\n return bool(re.fullmatch(a.replace('*', '.*'), b))", "def solve(a,b):\n if a == b: return True\n if \"*\" not in a: return False\n \n sides = a.split(\"*\")\n missing = b[len(sides[0]):len(b)-len(sides[1]... | {"fn_name": "solve", "inputs": [["code*s", "codewars"], ["codewar*s", "codewars"], ["code*warrior", "codewars"], ["c", "c"], ["*s", "codewars"], ["*s", "s"], ["s*", "s"], ["aa", "aaa"], ["aa*", "aaa"], ["aaa", "aa"], ["aaa*", "aa"], ["*", "codewars"], ["aaa*aaa", "aaa"]], "outputs": [[true], [true], [false], [true], [t... | introductory | https://www.codewars.com/kata/5bc052f93f43de7054000188 |
def solve(a,b):
|
3,307 | Freddy has a really fat left pinky finger, and every time Freddy tries to type an ```A```, he accidentally hits the CapsLock key!
Given a string that Freddy wants to type, emulate the keyboard misses where each ```A``` supposedly pressed is replaced with CapsLock, and return the string that Freddy actually types. It d... | ["def fat_fingers(s):\n if not s: return s\n swap = [False]\n return ''.join( c.swapcase() if swap[0] else c for c in s \n if c not in \"aA\" or swap.__setitem__(0, not swap[0]) )", "import re\n\ndef fat_fingers(string):\n return ''.join(w.swapcase() if i%2 else w for i, w in enumerate(re.s... | {"fn_name": "fat_fingers", "inputs": [["aAaaaaAaaaAAaAa"], ["The end of the institution, maintenance, and administration of government, is to secure the existence of the body politic, to protect it, and to furnish the individuals who compose it with the power of enjoying in safety and tranquillity their natural rights,... | introductory | https://www.codewars.com/kata/5aa99584fd5777ee9a0001f1 |
def fat_fingers(string):
|
3,308 | In telecomunications we use information coding to detect and prevent errors while sending data.
A parity bit is a bit added to a string of binary code that indicates whether the number of 1-bits in the string is even or odd. Parity bits are used as the simplest form of error detecting code, and can detect a 1 bit err... | ["def parity_bit(binary):\n return ' '.join(byte[:-1] if byte.count('1') % 2 == 0 else 'error' for byte in binary.split())", "def parity_bit(binary):\n return \" \".join(\"error\" if byte.count(\"1\") & 1 else byte[:-1] for byte in binary.split())", "def decode(binary):\n *b, p = binary\n if '01'[b.count('1... | {"fn_name": "parity_bit", "inputs": [["01011001"], ["00110001"], ["11111111"], ["00000000"], ["11100111"], ["00111100 00111101"], ["00001111 11100001"], ["01011110 00011000"], ["11111111 11011100 11100011"], ["00111110 00110100 00111011"], ["01101110 01100000 01010110 10001111 01100011"], ["10100011 00111001 11001100 0... | introductory | https://www.codewars.com/kata/58409435258e102ae900030f |
def parity_bit(binary):
|
3,309 | ## Overview
Resistors are electrical components marked with colorful stripes/bands to indicate both their resistance value in ohms and how tight a tolerance that value has. If you did my Resistor Color Codes kata, you wrote a function which took a string containing a resistor's band colors, and returned a string identi... | ["c='black brown red orange yellow green blue violet gray white'.split()\ndef encode_resistor_colors(ohms_string):\n ohms = str(int(eval(ohms_string.replace('k', '*1000').replace('M', '*1000000').split()[0])))\n return '%s %s %s gold' % (c[int(ohms[0])], c[int(ohms[1])], c[len(ohms[2:])])", "COLORS = {'0': 'bla... | {"fn_name": "encode_resistor_colors", "inputs": [["10 ohms"], ["47 ohms"], ["100 ohms"], ["220 ohms"], ["330 ohms"], ["470 ohms"], ["680 ohms"], ["1k ohms"], ["4.7k ohms"], ["10k ohms"], ["22k ohms"], ["47k ohms"], ["100k ohms"], ["330k ohms"], ["1M ohms"], ["2M ohms"]], "outputs": [["brown black black gold"], ["yellow... | introductory | https://www.codewars.com/kata/5855777bb45c01bada0002ac |
def encode_resistor_colors(ohms_string):
|
3,310 | Your task is to determine the top 3 place finishes in a pole vault competition involving several different competitors. This is isn't always so simple, and it is often a source of confusion for people who don't know the actual rules.
Here's what you need to know:
As input, you will receive an array of objects. Each o... | ["def score_pole_vault(vaulter_list):\n popytki = len(vaulter_list[0][\"results\"])\n temp = {}\n res = {}\n for mas in vaulter_list:\n i = popytki - 1\n while i >= 0 and mas[\"results\"][i].find('O') == -1:\n i -= 1\n if i < 0:\n n = 0\n m = ''.join(mas... | {"fn_name": "score_pole_vault", "inputs": [[[{"name": "Linda", "results": ["XXO", "O", "XXO", "O"]}, {"name": "Vickie", "results": ["O", "X", "", ""]}, {"name": "Debbie", "results": ["XXO", "O", "XO", "XXX"]}, {"name": "Michelle", "results": ["XO", "XO", "XXX", ""]}, {"name": "Carol", "results": ["XXX", "", "", ""]}]],... | introductory | https://www.codewars.com/kata/579294724be9121e4d00018f |
def score_pole_vault(vaulter_list):
|
3,311 | Reverse and invert all integer values in a given list.
Python:
reverse_invert([1,12,'a',3.4,87,99.9,-42,50,5.6]) = [-1,-21,-78,24,-5]
Ignore all other types than integer. | ["from math import copysign as sign\n\ndef reverse_invert(lst):\n return [-int(sign(int(str(abs(x))[::-1]),x)) for x in lst if isinstance(x,int)] ", "def reverse_invert(lst):\n return [(-1,1)[x<0]*int(str(abs(x))[::-1]) for x in lst if isinstance(x,int)]", "reverse_invert=lambda l: [(-1 if n>0 else 1)*int(str(ab... | {"fn_name": "reverse_invert", "inputs": [[[1, 2, 3, 4, 5]], [[-10]], [[-9, -18, 99]], [[1, 12, "a", 3.4, 87, 99.9, -42, 50, 5.6]], [[]]], "outputs": [[[-1, -2, -3, -4, -5]], [[1]], [[9, 81, -99]], [[-1, -21, -78, 24, -5]], [[]]]} | introductory | https://www.codewars.com/kata/5899e054aa1498da6b0000cc |
def reverse_invert(lst):
|
3,312 | An anagram is a word, a phrase, or a sentence formed from another by rearranging its letters. An example of this is "angel", which is an anagram of "glean".
Write a function that receives an array of words, and returns the total number of distinct pairs of anagramic words inside it.
Some examples:
- There are 2 anag... | ["from collections import Counter\n\ndef anagram_counter(words):\n return sum(n*(n-1)// 2 for n in Counter(''.join(sorted(x)) for x in words).values())", "def anagram_counter(words):\n def is_anagrams(s1, s2): return sorted(s1) == sorted(s2)\n return 0 if not words else sum([1 for x in range(len(words)-1) for ... | {"fn_name": "anagram_counter", "inputs": [[[]], [["dell", "ledl", "abc", "cba"]], [["dell", "ledl", "lled", "cba"]], [["dell", "ledl", "abc", "cba", "bca", "bac", "cab"]]], "outputs": [[0], [2], [3], [11]]} | introductory | https://www.codewars.com/kata/587e18b97a25e865530000d8 |
def anagram_counter(words):
|
3,313 | # RoboScript #1 - Implement Syntax Highlighting
## Disclaimer
The story presented in this Kata Series is purely fictional; any resemblance to actual programming languages, products, organisations or people should be treated as purely coincidental.
## About this Kata Series
This Kata Series is based on a fictional s... | ["import re\ndef highlight(code):\n code = re.sub(r\"(F+)\", '<span style=\"color: pink\">\\g<1></span>', code)\n code = re.sub(r\"(L+)\", '<span style=\"color: red\">\\g<1></span>', code)\n code = re.sub(r\"(R+)\", '<span style=\"color: green\">\\g<1></span>', code)\n code = re.sub(r\"(\\d+)\", '<span styl... | {"fn_name": "highlight", "inputs": [["F3RF5LF7"], ["FFFR345F2LL"], ["RRRRRF45L3F2"], ["RRRRR(F45L3)F2"], ["FF(LF6(RF3)2)3"]], "outputs": [["<span style=\"color: pink\">F</span><span style=\"color: orange\">3</span><span style=\"color: green\">R</span><span style=\"color: pink\">F</span><span style=\"color: orange\">5</... | introductory | https://www.codewars.com/kata/58708934a44cfccca60000c4 |
def highlight(code):
|
3,314 | In this Kata, you will be given two numbers, `a` and `b`, and your task is to determine if the first number `a` is divisible by `all` the prime factors of the second number `b`. For example: `solve(15,12) = False` because `15` is not divisible by all the prime factors of `12` (which include`2`).
See test cases for mor... | ["import fractions\n\ndef solve(a, b):\n c = fractions.gcd(a, b)\n while c > 1:\n b //= c\n c = fractions.gcd(a, b)\n return b == 1", "from math import gcd\n\n\ndef solve(a, b):\n while 1 < gcd(a, b):\n b = b // gcd(a, b)\n return b == 1\n", "from math import gcd\n\ndef solve(a, b):\... | {"fn_name": "solve", "inputs": [[2, 256], [2, 253], [9, 243], [15, 12], [21, 2893401], [21, 2893406], [54, 2834352], [54, 2834359], [1000013, 7187761], [1000013, 7187762]], "outputs": [[true], [false], [true], [false], [true], [false], [true], [false], [true], [false]]} | introductory | https://www.codewars.com/kata/59ec2d112332430ce9000005 |
def solve(a,b):
|
3,315 | A strongness of an even number is the number of times we can successively divide by 2 until we reach an odd number starting with an even number n.
For example, if n = 12, then
* 12 / 2 = 6
* 6 / 2 = 3
So we divided successively 2 times and we reached 3, so the strongness of 12 is `2`.
If n = 16 then
* 16 / 2 = 8
* 8... | ["\"\"\"Strongest even number in an interval kata\n\nDefines strongest_even(n, m) which returns the strongest even number in the set\nof integers on the interval [n, m].\n\nConstraints:\n 1. 1 <= n < m < MAX_INT\n\nNote:\n 1. The evenness of zero is need not be defined given the constraints.\n 2. In Python 3, ... | {"fn_name": "strongest_even", "inputs": [[1, 2], [5, 10], [48, 56], [129, 193], [2, 3], [4, 6], [3, 310], [33, 40], [456445, 678860], [324243, 897653214], [1151592177, 2129680158], [2085422641, 2128923730], [1082012216, 1876572332], [1806570867, 2067832928], [206346325, 1289058842]], "outputs": [[2], [8], [48], [192], ... | introductory | https://www.codewars.com/kata/5d16af632cf48200254a6244 |
def strongest_even(n, m):
|
3,316 | Inspired by the development team at Vooza, write the function `howManyLightsabersDoYouOwn`/`how_many_light_sabers_do_you_own` that
* accepts the name of a programmer, and
* returns the number of lightsabers owned by that person.
The only person who owns lightsabers is Zach, by the way. He owns 18, which is an awesom... | ["def how_many_light_sabers_do_you_own(name=\"\"):\n return (18 if name==\"Zach\" else 0)", "how_many_light_sabers_do_you_own=lambda n='': 18 if n=='Zach' else 0", "def how_many_light_sabers_do_you_own(name='haha'):\n return 18 if name=='Zach' else 0", "def how_many_light_sabers_do_you_own(name=''):\n switch =... | {"fn_name": "how_many_light_sabers_do_you_own", "inputs": [["Zach"], ["zach"]], "outputs": [[18], [0]]} | introductory | https://www.codewars.com/kata/51f9d93b4095e0a7200001b8 |
def how_many_light_sabers_do_you_own(*name):
|
3,317 | **Getting Familiar:**
LEET: (sometimes written as "1337" or "l33t"), also known as eleet or leetspeak, is another alphabet for the English language that is used mostly on the internet. It uses various combinations of ASCII characters to replace Latinate letters. For example, leet spellings of the word leet include 1337... | ["def gr33k_l33t(string):\n gl = { \"a\":\"\u03b1\", \"b\":\"\u03b2\", \"d\":\"\u03b4\", \"e\":\"\u03b5\", \"i\":\"\u03b9\", \"k\":\"\u03ba\", \"n\":\"\u03b7\", \"o\":\"\u03b8\", \n \"p\":\"\u03c1\", \"r\":\"\u03c0\", \"t\":\"\u03c4\", \"u\":\"\u03bc\", \"v\":\"\u03c5\", \"w\":\"\u03c9\", \"x\":\"\u03c7\... | {"fn_name": "gr33k_l33t", "inputs": [["codewars"], ["kata"], ["kumite"], ["greekleet"], ["This Kata's Sensei is Divyansh"], ["Any reviews about CS50"], ["Man is still the most extraordinary computer of all."], ["I do not fear computers. I fear the lack of them."], ["Do you also think these quotes are conflicting each o... | introductory | https://www.codewars.com/kata/556025c8710009fc2d000011 |
def gr33k_l33t(string):
|
3,318 | # Task
Two integer numbers are added using the column addition method. When using this method, some additions of digits produce non-zero carries to the next positions. Your task is to calculate the number of non-zero carries that will occur while adding the given numbers.
The numbers are added in base 10.
# Example... | ["def number_of_carries(a, b):\n ans, carrie = 0, 0\n while a > 0 or b > 0:\n carrie = (a%10 + b%10 + carrie) // 10 \n ans += [0,1][carrie > 0]\n a //= 10\n b //= 10\n return ans", "def number_of_carries(a, b):\n i=1\n carry_over=0\n counter=0\n length1=len(str(a))\n ... | {"fn_name": "number_of_carries", "inputs": [[543, 3456], [1927, 6426], [9999, 1], [1234, 5678]], "outputs": [[0], [2], [4], [2]]} | introductory | https://www.codewars.com/kata/58a6568827f9546931000027 |
def number_of_carries(a, b):
|
3,319 | Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized **only** if the original word was capitalized (known as Upper Camel Case, also often referred to as Pascal case).
## Examples
```python
to_camel_case("the-stealth... | ["def to_camel_case(text):\n removed = text.replace('-', ' ').replace('_', ' ').split()\n if len(removed) == 0:\n return ''\n return removed[0]+ ''.join([x.capitalize() for x in removed[1:]])", "import re\ndef to_camel_case(text):\n return re.sub('[_-](.)', lambda x: x.group(1).upper(), text)", "def ... | {"fn_name": "to_camel_case", "inputs": [[""], ["the_stealth_warrior"], ["The-Stealth-Warrior"], ["A-B-C"]], "outputs": [[""], ["theStealthWarrior"], ["TheStealthWarrior"], ["ABC"]]} | introductory | https://www.codewars.com/kata/517abf86da9663f1d2000003 |
def to_camel_case(text):
|
3,320 | ###Introduction
The [I Ching](https://en.wikipedia.org/wiki/I_Ching) (Yijing, or Book of Changes) is an ancient Chinese book of sixty-four hexagrams.
A hexagram is a figure composed of six stacked horizontal lines, where each line is either Yang (an unbroken line) or Yin (a broken line):
```
--------- ---- ---- ... | ["l = {'one': 5, 'two': 4, 'three': 3, 'four': 2, 'five': 1, 'six': 0}\ny = {'hhh': '----o----', 'hht': '---- ----', 'htt': '---------', 'ttt': '----x----'}\n\ndef oracle(arr):\n s = [''] * 6\n for x in arr: s[l[x[0]]] = y[''.join(sorted(x[1:]))]\n return '\\n'.join(s)", "ORDER = \"one two three four five six\... | {"fn_name": "oracle", "inputs": [[[["two", "h", "h", "t"], ["six", "t", "h", "t"], ["four", "t", "t", "t"], ["one", "h", "t", "h"], ["three", "h", "h", "h"], ["five", "t", "t", "h"]]], [[["six", "t", "t", "h"], ["one", "h", "h", "t"], ["three", "t", "h", "h"], ["two", "t", "t", "t"], ["five", "h", "h", "t"], ["four", "... | introductory | https://www.codewars.com/kata/56e60e54517a8c167e00154d |
def oracle(arr):
|
3,321 | The number n is Evil if it has an even number of 1's in its binary representation.
The first few Evil numbers: 3, 5, 6, 9, 10, 12, 15, 17, 18, 20
The number n is Odious if it has an odd number of 1's in its binary representation.
The first few Odious numbers: 1, 2, 4, 7, 8, 11, 13, 14, 16, 19
You have to write a functi... | ["def evil(n):\n return \"It's %s!\" % [\"Evil\",\"Odious\"][bin(n).count(\"1\")%2]", "def evil(n):\n return \"It's Evil!\" if bin(n).count('1')%2 == 0 else \"It's Odious!\"", "def evil(n):\n return 'It\\'s {}!'.format(('Evil', 'Odious')[bin(n).count('1') % 2])\n", "def evil(n):\n count = 0\n while n:\n... | {"fn_name": "evil", "inputs": [[1], [2], [3]], "outputs": [["It's Odious!"], ["It's Odious!"], ["It's Evil!"]]} | introductory | https://www.codewars.com/kata/56fcfad9c7e1fa2472000034 |
def evil(n):
|
3,322 | # Number encrypting: cypher
## Part I of Number encrypting Katas
***
## Introduction
Back then when the internet was coming up, most search functionalities simply looked for keywords in text to show relevant documents. Hackers weren't very keen on having their information displayed on websites, bulletin boards, newsgr... | ["def cypher(s):\n return s.translate(str.maketrans('IREASGTBlzeasbtgoO','123456781234567900'))", "translation = str.maketrans(\"IREASGTBOlzeasbtgo\",\"123456780123456790\")\n\ndef cypher(s):\n return s.translate(translation)", "def cypher(string):\n D = {'I' :'1', 'l':'1', 'R':'2', 'z':'2', 'E':'3', 'e':'3',\... | {"fn_name": "cypher", "inputs": [["Hello World"], ["I am your father"], ["I do not know what else I can test. Be cool. Good luck"], ["IlRzEeAaSsGbTtBgOo"], [""]], "outputs": [["H3110 W0r1d"], ["1 4m y0ur f47h3r"], ["1 d0 n07 kn0w wh47 3153 1 c4n 7357. 83 c001. 600d 1uck"], ["112233445566778900"], [""]]} | introductory | https://www.codewars.com/kata/57aa3927e298a757820000a8 |
def cypher(string):
|
3,323 | # Task
You are given a car odometer which displays the miles traveled as an integer.
The odometer has a defect, however: it proceeds from digit `3` to digit `5` always skipping the digit `4`. This defect shows up in all positions (ones, tens, hundreds, etc).
For example, if the odometer displays `15339` and th... | ["tr=str.maketrans('56789','45678')\n\ndef faulty_odometer(n):\n return int(str(n).translate(tr),9)", "def faulty_odometer(n):\n result = 0\n digits = len(str(n))\n nonaryTranslation = \"\".join([str(int(x)-1) if int(x) >= 5 else x for x in list(str(n))])\n for i in nonaryTranslation:\n digits -= ... | {"fn_name": "faulty_odometer", "inputs": [[13], [15], [55], [2005], [1500], [999999], [165826622]], "outputs": [[12], [13], [40], [1462], [1053], [531440], [69517865]]} | introductory | https://www.codewars.com/kata/58b8d22560873d9068000085 |
def faulty_odometer(n):
|
3,324 | In JavaScript, ```if..else``` is the most basic condition statement,
it consists of three parts:```condition, statement1, statement2```, like this:
```python
if condition: statementa
else: statementb
```
It means that if the condition is true, then execute the statementa, otherwise execute the statementb.If the... | ["def sale_hotdogs(n):\n return n * (100 if n < 5 else 95 if n < 10 else 90)\n", "def sale_hotdogs(n):\n rate = 100 if n<5 else 95 if n<10 else 90\n return n * rate", "def sale_hotdogs(n):\n return n * [90, 95, 100][(n<10) + (n<5)]", "class Color(object):\n BLACK = 0\n RED = 1\n\n\nclass Node(object):... | {"fn_name": "sale_hotdogs", "inputs": [[0], [1], [2], [3], [4], [5], [9], [10], [11], [100]], "outputs": [[0], [100], [200], [300], [400], [475], [855], [900], [990], [9000]]} | introductory | https://www.codewars.com/kata/57202aefe8d6c514300001fd |
def sale_hotdogs(n):
|
3,325 | Given a string, s, return a new string that orders the characters in order of frequency.
The returned string should have the same number of characters as the original string.
Make your transformation stable, meaning characters that compare equal should stay in their original order in the string s.
```python
most_... | ["from collections import Counter\n\ndef most_common(s):\n count = Counter(s)\n return ''.join(sorted(s, key=lambda c: -count[c]))", "def most_common(s):\n return ''.join(sorted(s, key = s.count, reverse = True))", "def most_common(stg):\n return \"\".join(sorted(stg, key=stg.count, reverse=True))", "def mo... | {"fn_name": "most_common", "inputs": [["Hello world"], [""], ["wubz dermatoglyphics"], ["Four score and seven years ago"], ["Hello He worldwrd"]], "outputs": [["lllooHe wrd"], [""], ["wubz dermatoglyphics"], [" eeeeorsorasarsaonnFucdvyg"], ["lllHeo He wordwrd"]]} | introductory | https://www.codewars.com/kata/59824f384df1741e05000913 |
def most_common(s):
|
3,326 | In this kata, you will be given a string of text and valid parentheses, such as `"h(el)lo"`. You must return the string, with only the text inside parentheses reversed, so `"h(el)lo"` becomes `"h(le)lo"`. However, if said parenthesized text contains parenthesized text itself, then that too must reversed back, so it fac... | ["def reverse_in_parentheses(s):\n stack = []\n for i in s:\n stack.append(i)\n \n if i == ')':\n opening = len(stack) - stack[::-1].index('(') - 1\n stack.append(''.join([i[::-1].translate(str.maketrans('()',')(')) for i in stack[opening:][::-1]])) \n del st... | {"fn_name": "reverse_in_parentheses", "inputs": [["h(el)lo"], ["a ((d e) c b)"], ["one (two (three) four)"], ["one (ruof ((rht)ee) owt)"], [""], ["many (parens) on (top)"], ["( ( ) (()) )"]], "outputs": [["h(le)lo"], ["a (b c (d e))"], ["one (ruof (three) owt)"], ["one (two ((thr)ee) four)"], [""], ["many (snerap) on (... | introductory | https://www.codewars.com/kata/5e07b5c55654a900230f0229 |
def reverse_in_parentheses(string):
|
3,327 | You're writing an excruciatingly detailed alternate history novel set in a world where [Daniel Gabriel Fahrenheit](https://en.wikipedia.org/wiki/Daniel_Gabriel_Fahrenheit) was never born.
Since Fahrenheit never lived the world kept on using the [Rømer scale](https://en.wikipedia.org/wiki/R%C3%B8mer_scale), invented by... | ["def celsius_to_romer(temp):\n # Converts temperature in degrees Celsius to degrees Romer\n return (temp * 21 / 40) + 7.5\n", "def celsius_to_romer(temp):\n return temp * 21 / 40 + 7.5\n", "def celsius_to_romer(c):\n return c * 21 / 40 + 7.5 ", "def celsius_to_romer(x):\n return x * 21 / 40 + 7.5", "def... | {"fn_name": "celsius_to_romer", "inputs": [[24], [8], [29]], "outputs": [[20.1], [11.7], [22.725]]} | introductory | https://www.codewars.com/kata/5862eeeae20244d5eb000005 |
def celsius_to_romer(temp):
|
3,328 | You have invented a time-machine which has taken you back to ancient Rome. Caeser is impressed with your programming skills and has appointed you to be the new information security officer.
Caeser has ordered you to write a Caeser cipher to prevent Asterix and Obelix from reading his emails.
A Caeser cipher shifts th... | ["def caeser(message, key):\n return ''.join(chr(65 + (ord(c.upper()) + key - 65) % 26) if c.isalpha() else c for c in message)", "def caeser(message, key):\n return ''.join(chr(ord(x)+key if ord(x)+key <= 122 else ord(x)+key-122 + 96).upper() if x.isalpha() else x for x in message)", "import string\n\ndef caeser... | {"fn_name": "caeser", "inputs": [["This is a message", 0], ["who are you?", 18], ["..5tyu..", 25], ["..#$%^..", 0], ["..#$%^..", 26], ["final one", 9]], "outputs": [["THIS IS A MESSAGE"], ["OZG SJW QGM?"], ["..5SXT.."], ["..#$%^.."], ["..#$%^.."], ["ORWJU XWN"]]} | introductory | https://www.codewars.com/kata/56dc695b2a4504b95000004e |
def caeser(message, key):
|
3,329 | ### Longest Palindrome
Find the length of the longest substring in the given string `s` that is the same in reverse.
As an example, if the input was “I like racecars that go fast”, the substring (`racecar`) length would be `7`.
If the length of the input string is `0`, the return value must be `0`.
### Ex... | ["\"\"\"\n***************************************\n* O(n) time complexity solution ! *\n***************************************\n\"\"\"\n\ndef longest_palindrome (s):\n\n maxPal, tmpPal = 0, 1\n count_dct = {}\n inPal = False\n \n for i,l in enumerate(s):\n \n count_dct[l] = count_dct.get(l... | {"fn_name": "longest_palindrome", "inputs": [["a"], ["aa"], ["baa"], ["aab"], ["baabcd"], ["baablkj12345432133d"], ["I like racecars that go fast"], ["abcdefghba"], [""], ["FourscoreandsevenyearsagoourfaathersbroughtforthonthiscontainentanewnationconceivedinzLibertyanddedicatedtothepropositionthatallmenarecreatedequalN... | introductory | https://www.codewars.com/kata/54bb6f887e5a80180900046b |
def longest_palindrome (s):
|
3,330 | >When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
# Description:
Give you two number `m` and `n`(two positive integer, m < n), make a triangle pattern with number sequence `m to n`. The order is clockwise, starting from ... | ["def make_triangle(m,n):\n lns, sm = 0, 0\n while sm < n - m + 1:\n lns += 1\n sm += lns\n if sm > n - m + 1: return \"\"\n matrix = [[0] * (i + 1) for i in range(lns)]\n y, x, s = 0, 0, 0\n ds = ((1, 1), (0, -1), (-1, 0))\n dy, dx = ds[s]\n for i in range(m, n + 1):\n matr... | {"fn_name": "make_triangle", "inputs": [[1, 12], [1, 100]], "outputs": [[""], [""]]} | introductory | https://www.codewars.com/kata/58281843cea5349c9f000110 |
def make_triangle(m,n):
|
3,331 | Consider an array containing cats and dogs. Each dog can catch only one cat, but cannot catch a cat that is more than `n` elements away. Your task will be to return the maximum number of cats that can be caught.
For example:
```Haskell
solve(['D','C','C','D','C'], 2) = 2, because the dog at index 0 (D0) catches C1 and... | ["def solve(arr, reach):\n dogs, nCats = {i for i,x in enumerate(arr) if x=='D'}, 0\n for i,c in enumerate(arr):\n if c == 'C':\n catchingDog = next((i+id for id in range(-reach,reach+1) if i+id in dogs), None)\n if catchingDog is not None:\n nCats += 1\n ... | {"fn_name": "solve", "inputs": [[["D", "C", "C", "D", "C"], 1], [["C", "C", "D", "D", "C", "D"], 2], [["C", "C", "D", "D", "C", "D"], 1], [["D", "C", "D", "C", "C", "D"], 3], [["C", "C", "C", "D", "D"], 3], [["C", "C", "C", "D", "D"], 2], [["C", "C", "C", "D", "D"], 1], [["C", "C", "C", "D", "D", "D", "C", "D", "D", "D... | introductory | https://www.codewars.com/kata/5a5f48f2880385daac00006c |
def solve(arr,n):
|
3,332 | Your friend won't stop texting his girlfriend. It's all he does. All day. Seriously. The texts are so mushy too! The whole situation just makes you feel ill.
Being the wonderful friend that you are, you hatch an evil plot. While he's sleeping, you take his phone and change the autocorrect options so that every time ... | ["import re\n\ndef autocorrect(input):\n return re.sub(r'(?i)\\b(u|you+)\\b', \"your sister\", input)", "from re import sub, I\n\ndef autocorrect(input):\n return sub(r'\\b(you+|u)\\b', 'your sister', input, flags=I)", "import re\ndef autocorrect(input):\n return re.sub(r'(?i)\\b(you+|u)\\b', 'your sister', in... | {"fn_name": "autocorrect", "inputs": [["I miss you!"], ["u want to go to the movies?"], ["Can't wait to see youuuuu"], ["I want to film the bayou with you and put it on youtube"], ["You should come over Friday night"], ["You u youville utube you youyouyou uuu raiyou united youuuu u you"]], "outputs": [["I miss your sis... | introductory | https://www.codewars.com/kata/538ae2eb7a4ba8c99b000439 |
def autocorrect(input):
|
3,333 | ## Task
You need to implement two functions, `xor` and `or`, that replicate the behaviour of their respective operators:
- `xor` = Takes 2 values and returns `true` if, and only if, one of them is truthy.
- `or` = Takes 2 values and returns `true` if either one of them is truthy.
When doing so, **you cannot use the o... | ["def func_or(a, b):\n return not (bool(a) == bool(b) == False)\n\ndef func_xor(a, b):\n return not (bool(a) == bool(b))", "def func_or(a,b):\n return bool(a) | bool(b)\n\ndef func_xor(a,b):\n return bool(a) ^ bool(b)", "def func_or(a, b):\n return bool(a) + bool(b) > 0\n\ndef func_xor(a, b):\n return... | {"fn_name": "func_or", "inputs": [[true, true], [true, false], [false, false], [0, 11], [null, []]], "outputs": [[true], [true], [false], [true], [false]]} | introductory | https://www.codewars.com/kata/584d2c19766c2b2f6a00004f |
def func_or(a,b):
|
3,334 | Write a function which reduces fractions to their simplest form! Fractions will be presented as an array/tuple (depending on the language), and the reduced fraction must be returned as an array/tuple:
```
input: [numerator, denominator]
output: [newNumerator, newDenominator]
example: [45, 120] --> [3, 8]
```
All n... | ["from fractions import Fraction\ndef reduce_fraction(fraction):\n t = Fraction(*fraction)\n return (t.numerator, t.denominator)", "def gcd(a, b):\n return a if b == 0 else gcd(b, a % b)\n \ndef reduce_fraction(fraction):\n num, denom = fraction\n gcd_num_denom = gcd(num, denom)\n return (num // gc... | {"fn_name": "reduce_fraction", "inputs": [[[60, 20]], [[80, 120]], [[4, 2]], [[45, 120]], [[1000, 1]], [[1, 1]], [[10956590, 13611876]], [[35884747, 5576447]], [[24622321, 24473455]], [[4255316, 11425973]]], "outputs": [[[3, 1]], [[2, 3]], [[2, 1]], [[3, 8]], [[1000, 1]], [[1, 1]], [[30605, 38022]], [[76841, 11941]], [... | introductory | https://www.codewars.com/kata/576400f2f716ca816d001614 |
def reduce_fraction(fraction):
|
3,335 | ASC Week 1 Challenge 4 (Medium #1)
Write a function that converts any sentence into a V A P O R W A V E sentence. a V A P O R W A V E sentence converts all the letters into uppercase, and adds 2 spaces between each letter (or special character) to create this V A P O R W A V E effect.
Example... | ["def vaporcode(s):\n return \" \".join(s.replace(\" \", \"\").upper())", "def vaporcode(s):\n string = ''\n s = ''.join(s.split()).upper()\n for c in s:\n string += c + ' '\n return string[:-2]", "vaporcode = lambda s: \" \".join(list(s.replace(\" \", \"\").upper()))", "def vaporcode(s):\n ... | {"fn_name": "vaporcode", "inputs": [["Lets go to the movies"], ["Why isn't my code working?"]], "outputs": [["L E T S G O T O T H E M O V I E S"], ["W H Y I S N ' T M Y C O D E W O R K I N G ?"]]} | introductory | https://www.codewars.com/kata/5966eeb31b229e44eb00007a |
def vaporcode(s):
|
3,336 | *Debug* function `getSumOfDigits` that takes positive integer to calculate sum of it's digits. Assume that argument is an integer.
### Example
```
123 => 6
223 => 7
1337 => 15
``` | ["def get_sum_of_digits(num):\n return sum(map(int, str(num)))", "def get_sum_of_digits(num):\n sum = 0\n str_num = str(num)\n for x in str_num:\n sum += int(x)\n return sum", "def get_sum_of_digits(n):\n return sum(int(d) for d in str(n))", "def get_sum_of_digits(n):\n return sum(map(int, s... | {"fn_name": "get_sum_of_digits", "inputs": [[123], [223], [0]], "outputs": [[6], [7], [0]]} | introductory | https://www.codewars.com/kata/563d59dd8e47a5ed220000ba |
def get_sum_of_digits(num):
|
3,337 | It's March and you just can't seem to get your mind off brackets. However, it is not due to basketball. You need to extract statements within strings that are contained within brackets.
You have to write a function that returns a list of statements that are contained within brackets given a string. If the value entere... | ["import re\n\nREGEX = re.compile(r'\\[(.*?)\\]')\n\n\ndef bracket_buster(strng):\n try:\n return REGEX.findall(strng)\n except TypeError:\n return 'Take a seat on the bench.'\n", "from re import findall\n\ndef bracket_buster(s):\n return \"Take a seat on the bench.\" if type(s) is not str else f... | {"fn_name": "bracket_buster", "inputs": [[[1, 2, 3]], [{"3": 4}], [false], [23.45], ["arc.tic.[circle]?[?]"], ["Big [L][e][B][r][o][n]!][["], ["[][]]]][[[[[[][]"], ["logger?]?system...12.12.133333 at [12-32-1432-16]"]], "outputs": [["Take a seat on the bench."], ["Take a seat on the bench."], ["Take a seat on the bench... | introductory | https://www.codewars.com/kata/56ff322e79989cff16000e39 |
def bracket_buster(string):
|
3,338 | Tranform of input array of zeros and ones to array in which counts number of continuous ones:
[1, 1, 1, 0, 1] -> [3,1] | ["from itertools import groupby\n\n\ndef ones_counter(nums):\n return [sum(g) for k, g in groupby(nums) if k]\n", "import itertools as it\n\ndef ones_counter(ar):\n return [len(list(group)) for bit, group in it.groupby(ar) if bit == 1]\n", "def ones_counter(input):\n return [i.count('1') for i in ''.join(map(s... | {"fn_name": "ones_counter", "inputs": [[[0, 0, 0, 0, 0, 0, 0, 0]], [[1, 1, 1, 1, 1]], [[1, 1, 1, 0, 0, 1, 0, 1, 1, 0]], [[0, 0, 0, 1, 0, 0, 1, 1]], [[1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1]]], "outputs": [[[]], [[5]], [[3, 1, 2]], [[1, 2]], [[1, 2, 4, 1]]]} | introductory | https://www.codewars.com/kata/56ec1e8492446a415e000b63 |
def ones_counter(input):
|
3,339 | No Story
No Description
Only by Thinking and Testing
Look at the results of the testcases, and guess the code!
---
## Series:
01. [A and B?](http://www.codewars.com/kata/56d904db9963e9cf5000037d)
02. [Incomplete string](http://www.codewars.com/kata/56d9292cc11bcc3629000533)
03. [True or False](http://www.codewars... | ["def mystery(n):\n return [i for i in range(1, n + 1, 2) if n % i == 0]", "def mystery(n):\n return [i for i in range(1, n + 1) if n%i == 0 and i%2]", "def mystery(n):\n if n < 1:\n return []\n d = {1, n}\n for k in range(2, int(n ** 0.5) + 1):\n if not n % k:\n d.add(k)\n ... | {"fn_name": "mystery", "inputs": [[-1], [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10]], "outputs": [[[]], [[]], [[1]], [[1]], [[1, 3]], [[1]], [[1, 5]], [[1, 3]], [[1, 7]], [[1]], [[1, 3, 9]], [[1, 5]]]} | introductory | https://www.codewars.com/kata/56ee0448588cbb60740013b9 |
def mystery(n):
|
3,340 | The [Sharkovsky's Theorem](https://en.wikipedia.org/wiki/Sharkovskii%27s_theorem) involves the following ordering of the natural numbers:
```math
3≺5≺7≺9≺ ...\\
≺2·3≺2·5≺2·7≺2·9≺...\\
≺2^n·3≺2^n·5≺2^n·7≺2^n·9≺...\\
≺2^{(n+1)}·3≺2^{(n+1)}·5≺2^{(n+1)}·7≺2^{(n+1)}·9≺...\\
≺2^n≺2^{(n-1)}≺...\\
≺4≺2≺1\\
```
Your task is t... | ["def sharkovsky(a, b): return f(a)<f(b)\n\ndef f(n,p=0):\n while n%2==0:\n n>>=1\n p+=1\n return n==1, p*(-1)**(n==1), n", "def analyse(x):\n n = (b := bin(x)).rstrip(\"0\")\n p = len(b) - len(n)\n return (n := int(n, 2)) == 1, p * (-1)**(n == 1), n\n\n\ndef sharkovsky(a, b):\n return ... | {"fn_name": "sharkovsky", "inputs": [[18, 12], [3, 9], [10, 16], [1, 22], [32, 1024], [17, 17]], "outputs": [[true], [true], [true], [false], [false], [false]]} | introductory | https://www.codewars.com/kata/5f579a3b34d5ad002819eb9e |
def sharkovsky(a, b):
|
3,341 | You will be given a string.
You need to return an array of three strings by gradually pulling apart the string.
You should repeat the following steps until the string length is 1:
a) remove the final character from the original string, add to solution string 1.
b) remove the first character from the original string... | ["def pop_shift(s):\n l1 = list(s); l2 = []; l3 = []\n while len(l1) > 1:\n l2.append(l1.pop())\n l3.append(l1.pop(0))\n return [\"\".join(l2),\"\".join(l3),\"\".join(l1)]", "def pop_shift(s):\n il, ir = len(s) // 2, (len(s) + 1) // 2\n return [s[:ir-1:-1], s[:il], s[il:ir]]", "def pop_shif... | {"fn_name": "pop_shift", "inputs": [["reusetestcasesbitcointakeovertheworldmaybewhoknowsperhaps"], ["turnsoutrandomtestcasesareeasierthanwritingoutbasicones"], ["exampletesthere"], ["letstalkaboutjavascriptthebestlanguage"], ["iwanttotraveltheworldwritingcodeoneday"], ["letsallgoonholidaysomewhereverycold"]], "outputs"... | introductory | https://www.codewars.com/kata/57cec34272f983e17800001e |
def pop_shift(s):
|
3,342 | ## Task:
You have to write a function `pattern` which returns the following Pattern(See Pattern & Examples) upto `n` number of rows.
* Note:`Returning` the pattern is not the same as `Printing` the pattern.
#### Rules/Note:
* If `n < 1` then it should return "" i.e. empty string.
* There are `no whitespaces` in the ... | ["def pattern(n):\n return \"\\n\".join([x * str(x) for x in range(1, n + 1)])", "def pattern(n):\n result = ''\n for i in range(1, n + 1):\n result += str(i) * i + '\\n'\n return result[:-1]", "def pattern(n):\n return '\\n'.join(str(i)*i for i in range(1, n + 1))", "pattern=lambda n: \"\\n\".joi... | {"fn_name": "pattern", "inputs": [[1], [2], [5], [0], [-25]], "outputs": [["1"], ["1\n22"], ["1\n22\n333\n4444\n55555"], [""], [""]]} | introductory | https://www.codewars.com/kata/5572f7c346eb58ae9c000047 |
def pattern(n):
|
3,343 | **Background**
You most probably know, that the *kilo* used by IT-People differs from the
*kilo* used by the rest of the world. Whereas *kilo* in kB is (mostly) intrepreted as 1024 Bytes (especially by operating systems) the non-IT *kilo* denotes the factor 1000 (as in "1 kg is 1000g"). The same goes for the prefixe... | ["def memorysize_conversion(memorysize):\n [value, unit] = memorysize.split(\" \")\n kibis = [\"KiB\", \"MiB\", \"GiB\", \"TiB\"]\n kilos = [\"kB\", \"MB\", \"GB\", \"TB\"]\n if unit in kibis:\n return (str(round(float(value)*pow(1.024, kibis.index(unit)+1), 3))+\" \"+kilos[kibis.index(unit)])\n e... | {"fn_name": "memorysize_conversion", "inputs": [["1 KiB"]], "outputs": [["1.024 kB"]]} | introductory | https://www.codewars.com/kata/5a115ff080171f9651000046 |
def memorysize_conversion(memorysize):
|
3,344 | Create a function which checks a number for three different properties.
- is the number prime?
- is the number even?
- is the number a multiple of 10?
Each should return either true or false, which should be given as an array. Remark: The Haskell variant uses `data Property`.
### Examples
```python
number_property(7... | ["import math\n\ndef number_property(n):\n return [isPrime(n), isEven(n), isMultipleOf10(n)]\n # Return isPrime? isEven? isMultipleOf10?\n #your code here\n\ndef isPrime(n):\n if n <= 3:\n return n >= 2\n if n % 2 == 0 or n % 3 == 0:\n return False\n for i in range(5, int(n ** 0.5) + 1, ... | {"fn_name": "number_property", "inputs": [[0], [2], [5], [25], [131], [1], [100], [179424691], [179424693]], "outputs": [[[false, true, true]], [[true, true, false]], [[true, false, false]], [[false, false, false]], [[true, false, false]], [[false, false, false]], [[false, true, true]], [[true, false, false]], [[false,... | introductory | https://www.codewars.com/kata/5507309481b8bd3b7e001638 |
def number_property(n):
|
3,345 | There is an array of strings. All strings contains similar _letters_ except one. Try to find it!
```python
find_uniq([ 'Aa', 'aaa', 'aaaaa', 'BbBb', 'Aaaa', 'AaAaAa', 'a' ]) # => 'BbBb'
find_uniq([ 'abc', 'acb', 'bac', 'foo', 'bca', 'cab', 'cba' ]) # => 'foo'
```
Strings may contain spaces. Spaces is not significant,... | ["from collections import defaultdict\n\ndef find_uniq(a):\n d = {}\n c = defaultdict(int)\n for e in a:\n t = frozenset(e.strip().lower())\n d[t] = e\n c[t] += 1\n \n return d[next(filter(lambda k: c[k] == 1, c))]", "def find_uniq(arr):\n if set(arr[0].lower()) == set(arr[1].lowe... | {"fn_name": "find_uniq", "inputs": [[["Aa", "aaa", "aaaaa", "BbBb", "Aaaa", "AaAaAa", "a"]], [["abc", "acb", "bac", "foo", "bca", "cab", "cba"]], [["silvia", "vasili", "victor"]], [["Tom Marvolo Riddle", "I am Lord Voldemort", "Harry Potter"]], [["", "", "", "a", "", ""]], [[" ", " ", " ", "a", " ", ""]], [["foobar... | introductory | https://www.codewars.com/kata/585d8c8a28bc7403ea0000c3 |
def find_uniq(arr):
|
3,346 | The prime numbers are not regularly spaced. For example from `2` to `3` the gap is `1`.
From `3` to `5` the gap is `2`. From `7` to `11` it is `4`.
Between 2 and 50 we have the following pairs of 2-gaps primes:
`3-5, 5-7, 11-13, 17-19, 29-31, 41-43`
A prime gap of length n is a run of n-1 consecutive composite numbers... | ["def gap(g, m, n):\n previous_prime = n\n for i in range(m, n + 1):\n if is_prime(i):\n if i - previous_prime == g: \n return [previous_prime, i]\n previous_prime = i\n return None\n \n \ndef is_prime(n):\n for i in range(2, int(n**.5 + 1)):\n ... | {"fn_name": "gap", "inputs": [[2, 3, 10], [3, 3, 10], [2, 100, 110], [4, 100, 110], [6, 100, 110], [8, 300, 400], [10, 300, 400], [4, 30000, 100000], [6, 30000, 100000], [8, 30000, 100000], [11, 30000, 100000], [2, 10000000, 11000000]], "outputs": [[[3, 5]], [null], [[101, 103]], [[103, 107]], [null], [[359, 367]], [[3... | introductory | https://www.codewars.com/kata/561e9c843a2ef5a40c0000a4 |
def gap(g, m, n):
|
3,347 | Given two integers `a` and `x`, return the minimum non-negative number to **add to** / **subtract from** `a` to make it a multiple of `x`.
```python
minimum(10, 6) #= 2
10+2 = 12 which is a multiple of 6
```
## Note
- 0 is always a multiple of `x`
## Constraints
**1 <= a <= 10^(6)**
**1 <= x <= 10^(5)** | ["def minimum(a, x):\n return min(a % x, -a % x)", "def minimum(a, x):\n return min(x-a%x, a%x)\n", "def minimum(a, x):\n return abs(a - x*round(a/x))\n", "def minimum(a, x):\n return min(a%x, abs(x - a%x))\n", "def minimum(a, x):\n r = a % x\n return r and min(r, x - r)", "def minimum(a, x):\n ret... | {"fn_name": "minimum", "inputs": [[9, 4], [10, 6]], "outputs": [[1], [2]]} | introductory | https://www.codewars.com/kata/5e030f77cec18900322c535d |
def minimum(a, x):
|
3,348 | Your colleagues have been looking over you shoulder. When you should have been doing your boring real job, you've been using the work computers to smash in endless hours of codewars.
In a team meeting, a terrible, awful person declares to the group that you aren't working. You're in trouble. You quickly have to gauge ... | ["def outed(meet, boss):\n return 'Get Out Now!' if (sum(meet.values()) + meet[boss] ) / len(meet) <= 5 else 'Nice Work Champ!'", "def outed(meet, boss):\n # sum of all people plus boss value, boss counts twice\n total_score = sum(meet.values()) + meet[boss]\n happiness_rating = total_score / len(meet)\n ... | {"fn_name": "outed", "inputs": [[{"tim": 0, "jim": 2, "randy": 0, "sandy": 7, "andy": 0, "katie": 5, "laura": 1, "saajid": 2, "alex": 3, "john": 2, "mr": 0}, "laura"], [{"tim": 1, "jim": 3, "randy": 9, "sandy": 6, "andy": 7, "katie": 6, "laura": 9, "saajid": 9, "alex": 9, "john": 9, "mr": 8}, "katie"], [{"tim": 2, "jim... | introductory | https://www.codewars.com/kata/57ecf6efc7fe13eb070000e1 |
def outed(meet, boss):
|
3,349 | You receive some random elements as a space-delimited string. Check if the elements are part of an ascending sequence of integers starting with 1, with an increment of 1 (e.g. 1, 2, 3, 4).
Return:
* `0` if the elements can form such a sequence, and no number is missing ("not broken", e.g. `"1 2 4 3"`)
* `1` if there ... | ["def find_missing_number(sequence):\n if not sequence:\n return 0\n try:\n sequence = set(int(a) for a in sequence.split())\n except ValueError:\n return 1\n for b in range(1, max(sequence) + 1):\n if b not in sequence:\n return b\n return 0\n", "def find_missing_n... | {"fn_name": "find_missing_number", "inputs": [["1 2 3 5"], ["1 5"], [""], ["1 2 3 4 5"], ["2 3 4 5"], ["2 6 4 5 3"], ["_______"], ["2 1 4 3 a"], ["1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61... | introductory | https://www.codewars.com/kata/5512e5662b34d88e44000060 |
def find_missing_number(sequence):
|
3,350 | When working with color values it can sometimes be useful to extract the individual red, green, and blue (RGB) component values for a color. Implement a function that meets these requirements:
+ Accepts a case-insensitive hexadecimal color string as its parameter (ex. `"#FF9933"` or `"#ff9933"`)
+ Returns an object wi... | ["def hex_string_to_RGB(s): \n return {i:int(s[j:j+2],16) for i,j in zip('rgb',[1,3,5])}", "def hex_string_to_RGB(hex): \n return {'r': int(hex[1:3],16),'g': int(hex[3:5],16), 'b': int(hex[5:7],16)}", "def hex_string_to_RGB(s): \n return {c: int(s[1+2*i:3+2*i], 16) for i,c in enumerate('rgb')}", "def hex_strin... | {"fn_name": "hex_string_to_RGB", "inputs": [["#FF9933"], ["#beaded"], ["#000000"], ["#111111"], ["#Fa3456"]], "outputs": [[{"r": 255, "g": 153, "b": 51}], [{"r": 190, "g": 173, "b": 237}], [{"r": 0, "g": 0, "b": 0}], [{"r": 17, "g": 17, "b": 17}], [{"r": 250, "g": 52, "b": 86}]]} | introductory | https://www.codewars.com/kata/5282b48bb70058e4c4000fa7 |
def hex_string_to_RGB(hex_string):
|
3,351 | # Task
`EvilCode` is a game similar to `Codewars`. You have to solve programming tasks as quickly as possible. However, unlike `Codewars`, `EvilCode` awards you with a medal, depending on the time you took to solve the task.
To get a medal, your time must be (strictly) inferior to the time corresponding to the medal. ... | ["def evil_code_medal(user_time, gold, silver, bronze):\n for medal, time in [[\"Gold\", gold], [\"Silver\", silver], [\"Bronze\", bronze]]:\n if user_time < time:\n return medal\n \n return \"None\"\n", "from bisect import bisect_right as bisect\n\nMEDALS = [\"Gold\", \"Silver\", \"B... | {"fn_name": "evil_code_medal", "inputs": [["00:30:00", "00:15:00", "00:45:00", "01:15:00"], ["01:15:00", "00:15:00", "00:45:00", "01:15:00"], ["00:00:01", "00:00:10", "00:01:40", "01:00:00"], ["00:10:01", "00:00:10", "00:01:40", "01:00:00"], ["00:00:01", "00:00:02", "00:00:03", "00:00:04"], ["90:00:01", "60:00:02", "70... | introductory | https://www.codewars.com/kata/5915686ed2563aa6650000ab |
def evil_code_medal(user_time, gold, silver, bronze):
|
3,352 | Find the number with the most digits.
If two numbers in the argument array have the same number of digits, return the first one in the array. | ["def find_longest(xs):\n return max(xs, key=lambda x: len(str(x)))", "def find_longest(arr):\n return max(arr, key=lambda x: len(str(x)))", "def find_longest(arr):\n #your code here\n max_lenght = 0\n max_index = 0\n for cur_num in arr:\n lenght = len(str(cur_num))\n if lenght > max_len... | {"fn_name": "find_longest", "inputs": [[[1, 10, 100]], [[9000, 8, 800]], [[8, 900, 500]], [[3, 40000, 100]], [[1, 200, 100000]]], "outputs": [[100], [9000], [900], [40000], [100000]]} | introductory | https://www.codewars.com/kata/58daa7617332e59593000006 |
def find_longest(arr):
|
3,353 | *** Nova polynomial subtract***
This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8807940ff3001140 ) [#4](http://www.codewars.com/kata/571a2e2df24bdf... | ["from itertools import zip_longest\n\ndef poly_subtract(p1, p2):\n return [x - y for x, y in zip_longest(p1, p2, fillvalue=0)]\n", "from itertools import zip_longest\n\ndef poly_subtract(a, b):\n return [x - y for x, y in zip_longest(a, b, fillvalue=0)]", "def poly_subtract(p1, p2):\n p1length = len(p1)\n ... | {"fn_name": "poly_subtract", "inputs": [[[], []], [[1, 2, 3, 4, 5, 6], []], [[], [1, 2, 3, 4, 5, 6]]], "outputs": [[[]], [[1, 2, 3, 4, 5, 6]], [[-1, -2, -3, -4, -5, -6]]]} | introductory | https://www.codewars.com/kata/5714041e8807940ff3001140 |
def poly_subtract(p1, p2):
|
3,354 | Implement a function which convert the given boolean value into its string representation. | ["def boolean_to_string(b):\n return str(b)", "def boolean_to_string(b):\n return 'True' if b else 'False'", "boolean_to_string = str ", "def boolean_to_string(b):\n if b:\n return \"True\"\n return \"False\"", "def boolean_to_string(b):\n return ('False', 'True')[b]\n", "boolean_to_string = la... | {"fn_name": "boolean_to_string", "inputs": [[true], [false]], "outputs": [["True"], ["False"]]} | introductory | https://www.codewars.com/kata/551b4501ac0447318f0009cd |
def boolean_to_string(b):
|
3,355 | In this Kata, you will be given a number and your task will be to rearrange the number so that it is divisible by `25`, but without leading zeros. Return the minimum number of digit moves that are needed to make this possible. If impossible, return `-1` ( `Nothing` in Haskell ).
For example:
More examples in test cas... | ["def solve(n):\n moves = []\n for a, b in [\"25\", \"75\", \"50\", \"00\"]:\n s = str(n)[::-1]\n x = s.find(a)\n y = s.find(b, x+1 if a == \"0\" else 0)\n if x == -1 or y == -1:\n continue\n moves.append(x + y - (x > y) - (a == b))\n s = s.replace(a, \"\", 1).... | {"fn_name": "solve", "inputs": [[50], [25], [52], [57], [75], [100], [521], [1], [5071], [705], [1241367], [50011117], [1002], [50011111112], [2057], [50001111312], [500111117], [64954713879], [71255535569], [72046951686], [68151901446], [3848363615], [75733989998], [87364011400], [2992127830], [98262144757], [81737102... | introductory | https://www.codewars.com/kata/5b165654c8be0d17f40000a3 |
def solve(n):
|
3,356 | # Kata Task
Given a list of random integers, return the Three Amigos.
These are 3 numbers that live next to each other in the list, and who have the **most** in common with each other by these rules:
* lowest statistical range
* same parity
# Notes
* The list will contain at least 3 numbers
* If there is more than ... | ["def three_amigos(numbers):\n return min(\n ([a, b, c] for a, b, c in zip(numbers, numbers[1:], numbers[2:]) if a & 1 == b & 1 == c & 1), \n key=lambda triple: max(triple) - min(triple),\n default=[])", "three_amigos = lambda a: (sorted(((max(a[i:i+3])-min(a[i:i+3]), a[i:i+3]) for i in range(le... | {"fn_name": "three_amigos", "inputs": [[[1, 2, 34, 2, 1, 5, 3, 5, 7, 234, 2, 1]], [[2, 4, 6, 8, 10, 2, 2, 2, 1, 1, 1, 5, 3]], [[2, 4, 5, 3, 6, 3, 1, 56, 7, 6, 3, 12]], [[1, 3, 5]], [[1, 3, 2]], [[1, 3, 5, 7, 9, 11, 13, 15]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 3, 5]], [[-5, -4, -2, 0, 1, 2, 3, 4, 5]], [[-8, -25, 21, -7, -5... | introductory | https://www.codewars.com/kata/59922d2ab14298db2b00003a |
def three_amigos(numbers):
|
3,357 | You are given an array of `n+1` integers `1` through `n`. In addition there is a single duplicate integer.
The array is unsorted.
An example valid array would be `[3, 2, 5, 1, 3, 4]`. It has the integers `1` through `5` and `3` is duplicated. `[1, 2, 4, 5, 5]` would not be valid as it is missing `3`.
You should retu... | ["def find_dup(arr):\n return sum(arr) - len(arr)*(len(arr)-1)/2\n #your code here\n", "def find_dup(arr):\n return max([i for i in arr if arr.count(i) > 1])", "from collections import Counter\nfind_dup = lambda xs: Counter(xs).most_common(1)[0][0]", "def find_dup(arr):\n return sum(arr) - len(arr) * (len(a... | {"fn_name": "find_dup", "inputs": [[[1, 1, 2, 3]], [[1, 2, 2, 3]], [[5, 4, 3, 2, 1, 1]], [[1, 3, 2, 5, 4, 5, 7, 6]], [[8, 2, 6, 3, 7, 2, 5, 1, 4]]], "outputs": [[1], [2], [1], [5], [2]]} | introductory | https://www.codewars.com/kata/558dd9a1b3f79dc88e000001 |
def find_dup(arr):
|
3,358 | Character recognition software is widely used to digitise printed texts. Thus the texts can be edited, searched and stored on a computer.
When documents (especially pretty old ones written with a typewriter), are digitised character recognition softwares often make mistakes.
Your task is correct the errors in the dig... | ["def correct(string):\n return string.translate(str.maketrans(\"501\", \"SOI\"))", "def correct(string):\n return string.replace('1','I').replace('0','O').replace('5','S')", "tr=str.maketrans('015','OIS')\n\ndef correct(string):\n return string.translate(tr)", "def correct(string):\n return string.replace(... | {"fn_name": "correct", "inputs": [["1F-RUDYARD K1PL1NG"], ["R0BERT MERLE - THE DAY 0F THE D0LPH1N"], ["R1CHARD P. FEYNMAN - THE FEYNMAN LECTURE5 0N PHY51C5"], ["R1CHARD P. FEYNMAN - 5TAT15T1CAL MECHAN1C5"], ["5TEPHEN HAWK1NG - A BR1EF H15T0RY 0F T1ME"], ["5TEPHEN HAWK1NG - THE UN1VER5E 1N A NUT5HELL"], ["ERNE5T HEM1NGW... | introductory | https://www.codewars.com/kata/577bd026df78c19bca0002c0 |
def correct(string):
|
3,359 | Write a function
`titleToNumber(title) or title_to_number(title) or titleToNb title ...`
(depending on the language)
that given a column title as it appears in an Excel sheet, returns its corresponding column number. All column titles will be uppercase.
Examples:
```
titleTonumber('A') === 1
titleTonumber('Z') ===... | ["def title_to_number(title):\n ret = 0\n for i in title:\n ret = ret*26 + ord(i) - 64\n return ret", "def title_to_number(title):\n return sum((ord(c) - 64) * 26**i for i, c in enumerate(title[::-1]))", "def title_to_number(title):\n return sum((ord(char) - 64) * 26 ** i for i, char in enumerate(... | {"fn_name": "title_to_number", "inputs": [["A"], ["Z"], ["AA"], ["AZ"], ["BA"], ["CODEWARS"], ["ZZZTOP"], ["OYAJI"], ["LONELINESS"], ["UNFORGIVABLE"]], "outputs": [[1], [26], [27], [52], [53], [28779382963], [321268054], [7294985], [68400586976949], [79089429845931757]]} | introductory | https://www.codewars.com/kata/55ee3ebff71e82a30000006a |
def title_to_number(title):
|
3,360 | ## Description
Peter enjoys taking risks, and this time he has decided to take it up a notch!
Peter asks his local barman to pour him **n** shots, after which Peter then puts laxatives in **x** of them. He then turns around and lets the barman shuffle the shots. Peter approaches the shots and drinks **a** of them one... | ["from functools import reduce\ndef get_chance(n, x, a):\n return round(reduce(lambda m, b: m * (1 - x / (n - b)), range(a), 1), 2)", "def get_chance(n, x, a):\n r = 1\n z = n-x\n while a>0:\n r *= z/n\n n-=1\n z-=1\n a-=1\n return round(r,2)", "def get_chance(shots, laxatives... | {"fn_name": "get_chance", "inputs": [[2, 1, 1], [4, 1, 3], [100, 10, 10], [1000, 150, 20], [25, 5, 5], [9, 3, 2], [4000, 200, 30], [10000, 100, 100], [1000000, 5000, 200], [1000000, 5000, 20000]], "outputs": [[0.5], [0.25], [0.33], [0.04], [0.29], [0.42], [0.21], [0.36], [0.37], [0.0]]} | introductory | https://www.codewars.com/kata/5b02ae6aa2afd8f1b4001ba4 |
def get_chance(n, x, a):
|
3,361 | ~~~if:csharp,javascript,cfml,php
Given a 2D array of size `m * n`. Your task is to find the sum of minimum value in each row.
~~~
~~~if:cpp
Given a 2D vector of size `m * n`. Your task is to find the sum of minimum value in each row.
~~~
~~~if:python,ruby
Given a 2D list of size `m * n`. Your task is to find the sum of... | ["def sum_of_minimums(numbers):\n return sum(map(min, numbers))", "def sum_of_minimums(numbers):\n return sum([min(rows) for rows in numbers])", "def sum_of_minimums(numbers):\n return sum(min(xs) for xs in numbers)", "def sum_of_minimums(numbers):\n total = 0\n for nums in numbers:\n total += min... | {"fn_name": "sum_of_minimums", "inputs": [[[[7, 9, 8, 6, 2], [6, 3, 5, 4, 3], [5, 8, 7, 4, 5]]], [[[11, 12, 14, 54], [67, 89, 90, 56], [7, 9, 4, 3], [9, 8, 6, 7]]]], "outputs": [[9], [76]]} | introductory | https://www.codewars.com/kata/5d5ee4c35162d9001af7d699 |
def sum_of_minimums(numbers):
|
3,362 | Given an array of integers as strings and numbers, return the sum of the array values as if all were numbers.
Return your answer as a number. | ["def sum_mix(arr):\n return sum(map(int, arr))", "def sum_mix(arr):\n return sum(int(n) for n in arr)", "def sum_mix(arr):\n result = 0\n for a in arr:\n try:\n result += a\n except TypeError:\n result += int(a)\n return result", "def sum_mix(arr):\n return sum(int... | {"fn_name": "sum_mix", "inputs": [[[9, 3, "7", "3"]], [["5", "0", 9, 3, 2, 1, "9", 6, 7]], [["3", 6, 6, 0, "5", 8, 5, "6", 2, "0"]], [["1", "5", "8", 8, 9, 9, 2, "3"]], [[8, 0, 0, 8, 5, 7, 2, 3, 7, 8, 6, 7]]], "outputs": [[22], [42], [41], [45], [61]]} | introductory | https://www.codewars.com/kata/57eaeb9578748ff92a000009 |
def sum_mix(arr):
|
3,363 | This program tests the life of an
evaporator containing a gas.
We know the content of the evaporator (content in ml),
the percentage of foam or gas lost every day (evap_per_day)
and the threshold (threshold) in percentage beyond which
the evaporator is no longer useful.
All numbers are strictly positive.
The program... | ["def evaporator(content, evap_per_day, threshold):\n n = 0\n current = 100\n percent = 1 - evap_per_day / 100.0\n while current > threshold:\n current *= percent\n n += 1\n return n", "import math\n\ndef evaporator(content, evap_per_day, threshold):\n return math.ceil(math.log(threshold... | {"fn_name": "evaporator", "inputs": [[10, 10, 10], [10, 10, 5], [100, 5, 5], [50, 12, 1], [47.5, 8, 8], [100, 1, 1], [10, 1, 1], [100, 1, 5]], "outputs": [[22], [29], [59], [37], [31], [459], [459], [299]]} | introductory | https://www.codewars.com/kata/5506b230a11c0aeab3000c1f |
def evaporator(content, evap_per_day, threshold):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.