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,564
write me a function `stringy` that takes a `size` and returns a `string` of alternating `'1s'` and `'0s'`. the string should start with a `1`. a string with `size` 6 should return :`'101010'`. with `size` 4 should return : `'1010'`. with `size` 12 should return : `'101010101010'`. The size will always be positive ...
["def stringy(size):\n return \"\".join([str(i % 2) for i in range(1, size + 1)])", "def stringy(size):\n return ('10' * size)[:size]", "from itertools import cycle, islice\n\ndef stringy(size):\n return ''.join(islice(cycle('10'), size))", "def stringy(size):\n s = \"\"\n for x in range (0, size):\n ...
{"fn_name": "stringy", "inputs": [[3], [5], [12], [26], [28]], "outputs": [["101"], ["10101"], ["101010101010"], ["10101010101010101010101010"], ["1010101010101010101010101010"]]}
introductory
https://www.codewars.com/kata/563b74ddd19a3ad462000054
def stringy(size):
3,565
In this Kata, you will be given a lower case string and your task will be to remove `k` characters from that string using the following rule: ```Python - first remove all letter 'a', followed by letter 'b', then 'c', etc... - remove the leftmost character first. ``` ```Python For example: solve('abracadabra', 1) = 'b...
["def solve(st,k): \n for l in sorted(st)[:k]:\n st=st.replace(l,'',1)\n return st", "solve = lambda s, k: ''.join(t[1] for t in sorted(sorted(enumerate(s), key=lambda x:x[1])[k:]))", "from collections import Counter\nfrom itertools import accumulate\nfrom operator import add\nfrom string import ascii_lowe...
{"fn_name": "solve", "inputs": [["abracadabra", 0], ["abracadabra", 1], ["abracadabra", 2], ["abracadabra", 6], ["abracadabra", 8], ["abracadabra", 50], ["hxehmvkybeklnj", 5], ["cccaabababaccbc", 3], ["cccaabababaccbc", 9], ["u", 1], ["back", 3]], "outputs": [["abracadabra"], ["bracadabra"], ["brcadabra"], ["rcdbr"], [...
introductory
https://www.codewars.com/kata/5b728f801db5cec7320000c7
def solve(st,k):
3,566
Given two integer arrays where the second array is a shuffled duplicate of the first array with one element missing, find the missing element. Please note, there may be duplicates in the arrays, so checking if a numerical value exists in one and not the other is not a valid solution. ``` find_missing([1, 2, 2, 3], [1...
["def find_missing(arr1, arr2):\n return sum(arr1) - sum(arr2)\n", "from functools import reduce\ndef find_missing(arr1, arr2):\n from itertools import chain\n from functools import reduce\n from operator import xor\n return reduce(xor, chain(arr1, arr2))\n", "def find_missing(A1, A2):\n return sum(A1...
{"fn_name": "find_missing", "inputs": [[[1, 2, 3], [1, 3]], [[6, 1, 3, 6, 8, 2], [3, 6, 6, 1, 2]], [[7], []], [[4, 3, 3, 61, 8, 8], [8, 61, 8, 3, 4]], [[0, 0, 0, 0, 0], [0, 0, 0, 0]]], "outputs": [[2], [8], [7], [3], [0]]}
introductory
https://www.codewars.com/kata/5a5915b8d39ec5aa18000030
def find_missing(arr1, arr2):
3,567
You have to write a function that describe Leo: ```python def leo(oscar): pass ``` if oscar was (integer) 88, you have to return "Leo finally won the oscar! Leo is happy". if oscar was 86, you have to return "Not even for Wolf of wallstreet?!" if it was not 88 or 86 (and below 88) you should return "When will you gi...
["def leo(oscar):\n if oscar == 88:\n return \"Leo finally won the oscar! Leo is happy\"\n elif oscar == 86:\n return \"Not even for Wolf of wallstreet?!\"\n elif oscar < 88:\n return \"When will you give Leo an Oscar?\"\n elif oscar > 88:\n return \"Leo got one a...
{"fn_name": "leo", "inputs": [[88], [87], [86]], "outputs": [["Leo finally won the oscar! Leo is happy"], ["When will you give Leo an Oscar?"], ["Not even for Wolf of wallstreet?!"]]}
introductory
https://www.codewars.com/kata/56d49587df52101de70011e4
def leo(oscar):
3,568
Your car is old, it breaks easily. The shock absorbers are gone and you think it can handle about 15 more bumps before it dies totally. Unfortunately for you, your drive is very bumpy! Given a string showing either flat road ("\_") or bumps ("n"), work out if you make it home safely. 15 bumps or under, return "Woohoo!...
["def bumps(road):\n return \"Woohoo!\" if road.count(\"n\") <= 15 else \"Car Dead\"", "def bumps(road):\n return 'Car Dead' if road.count('n')>15 else 'Woohoo!'", "def bumps(road):\n return \"Woohoo!\" if road.count('n')<16 else \"Car Dead\"", "from collections import Counter\n\n\ndef bumps(road):\n return...
{"fn_name": "bumps", "inputs": [["n"], ["_nnnnnnn_n__n______nn__nn_nnn"], ["______n___n_"], ["nnnnnnnnnnnnnnnnnnnnn"]], "outputs": [["Woohoo!"], ["Car Dead"], ["Woohoo!"], ["Car Dead"]]}
introductory
https://www.codewars.com/kata/57ed30dde7728215300005fa
def bumps(road):
3,569
In Russia regular bus tickets usually consist of 6 digits. The ticket is called lucky when the sum of the first three digits equals to the sum of the last three digits. Write a function to find out whether the ticket is lucky or not. Return true if so, otherwise return false. Consider that input is always a string. Wat...
["def is_lucky(ticket):\n if len(ticket) == 6 and ticket.isdigit():\n t = list(map(int, ticket))\n return sum(t[:3]) == sum(t[3:])\n return False", "def is_lucky(t):\n return len(t) == 6 and t.isdigit() and sum(map(int, t[:3])) == sum(map(int, t[3:]))", "def is_lucky(ticket):\n if len(ticket) ...
{"fn_name": "is_lucky", "inputs": [["123321"], ["12341234"], ["100001"], ["100200"], ["912435"], ["12a12a"], ["999999"], ["1111"], ["000000"], [""]], "outputs": [[true], [false], [true], [false], [true], [false], [true], [false], [true], [false]]}
introductory
https://www.codewars.com/kata/58902f676f4873338700011f
def is_lucky(ticket):
3,570
In this Kata, we will calculate the **minumum positive number that is not a possible sum** from a list of positive integers. ``` solve([1,2,8,7]) = 4 => we can get 1, 2, 3 (from 1+2), but we cannot get 4. 4 is the minimum number not possible from the list. solve([4,1,2,3,12]) = 11. We can get 1, 2, 3, 4, 4+1=5, 4+2=...
["def solve(xs):\n m = 0\n for x in sorted(xs):\n if x > m + 1:\n break\n m += x\n return m + 1", "from itertools import accumulate\n\ndef solve(arr):\n arr = sorted(arr)\n return next((x+1 for x, i in zip(accumulate([0]+arr), arr+[0]) if i > x + 1), sum(arr)+1)", "def solve(r):\...
{"fn_name": "solve", "inputs": [[[1, 2, 8, 7]], [[2, 12, 3, 1]], [[4, 2, 8, 3, 1]], [[4, 2, 7, 3, 1]], [[4, 2, 12, 3]]], "outputs": [[4], [7], [19], [18], [1]]}
introductory
https://www.codewars.com/kata/5a941f3a4a6b34edf900006f
def solve(arr):
3,571
You're laying out a rad pixel art mural to paint on your living room wall in homage to [Paul Robertson](http://68.media.tumblr.com/0f55f7f3789a354cfcda7c2a64f501d1/tumblr_o7eq3biK9s1qhccbco1_500.png), your favorite pixel artist. You want your work to be perfect down to the millimeter. You haven't decided on the dimens...
["def is_divisible(wall_length, pixel_size):\n return wall_length % pixel_size == 0", "def is_divisible(wall_length, pixel_size):\n return not wall_length % pixel_size", "def is_divisible(a, b):\n return a % b == 0", "def is_divisible(wall_length, pixel_size):\n return divmod(wall_length,pixel_size)[1] == 0...
{"fn_name": "is_divisible", "inputs": [[4050, 27], [4066, 27], [10000, 20], [10005, 20]], "outputs": [[true], [false], [true], [false]]}
introductory
https://www.codewars.com/kata/58630e2ae88af44d2b0000ea
def is_divisible(wall_length, pixel_size):
3,572
### Task King Arthur and his knights are having a New Years party. Last year Lancelot was jealous of Arthur, because Arthur had a date and Lancelot did not, and they started a duel. To prevent this from happening again, Arthur wants to make sure that there are at least as many women as men at this year's party. He g...
["def invite_more_women(arr):\n return sum(arr) > 0", "def invite_more_women(arr):\n return arr.count(1) > arr.count(-1)", "def invite_more_women(arr):\n x = arr.count(-1)\n y = arr.count(1)\n if x >= y:\n return 0\n else:\n return 1", "\ndef invite_more_women(arr):\n a = sum(arr)\n ...
{"fn_name": "invite_more_women", "inputs": [[[1, -1, 1]], [[-1, -1, -1]], [[1, -1]], [[1, 1, 1]], [[]]], "outputs": [[true], [false], [false], [true], [false]]}
introductory
https://www.codewars.com/kata/58acfe4ae0201e1708000075
def invite_more_women(arr):
3,573
You are given three piles of casino chips: white, green and black chips: * the first pile contains only white chips * the second pile contains only green chips * the third pile contains only black chips Each day you take exactly two chips of different colors and head to the casino. You can choose any color, but you a...
["def solve(xs):\n x, y, z = sorted(xs)\n return min(x + y, (x + y + z) // 2)", "def solve(arr):\n cnt = 0\n arr.sort()\n while(arr[2]<(arr[0]+arr[1])):\n arr[0]-=1\n arr[1]-=1\n cnt+=1\n return cnt+arr[0]+arr[1]", "def solve(arr):\n a,b,c = sorted(arr)\n ...
{"fn_name": "solve", "inputs": [[[1, 1, 1]], [[1, 2, 1]], [[4, 1, 1]], [[8, 2, 8]], [[8, 1, 4]], [[7, 4, 10]], [[12, 12, 12]], [[1, 23, 2]]], "outputs": [[1], [2], [2], [9], [5], [10], [18], [3]]}
introductory
https://www.codewars.com/kata/5e0b72d2d772160011133654
def solve(arr):
3,574
The dragon's curve is a self-similar fractal which can be obtained by a recursive method. Starting with the string `D0 = 'Fa'`, at each step simultaneously perform the following operations: ``` replace 'a' with: 'aRbFR' replace 'b' with: 'LFaLb' ``` For example (spaces added for more visibility) : ``` 1st iterati...
["def Dragon(n):\n if not isinstance(n, int) or n < 0:\n return ''\n \n value = 'Fa'\n \n for i in range(n):\n value = value.replace('a', 'aRcFR')\n value = value.replace('b', 'LFaLb')\n value = value.replace('c', 'b')\n \n return value.replace('a', '').replace('...
{"fn_name": "Dragon", "inputs": [["a"], [1.1], [-1]], "outputs": [[""], [""], [""]]}
introductory
https://www.codewars.com/kata/53ad7224454985e4e8000eaa
def Dragon(n):
3,575
# Task For the given set `S` its powerset is the set of all possible subsets of `S`. Given an array of integers nums, your task is to return the powerset of its elements. Implement an algorithm that does it in a depth-first search fashion. That is, for every integer in the set, we can either choose to take or not tak...
["from itertools import compress,product\n\ndef powerset(a):\n return [list(compress(a,p)) for p in product((0,1),repeat=len(a))]\n", "def powerset(nums):\n if not nums:\n return [[]]\n l = powerset(nums[1:])\n a = nums[0]\n return l + [[a] + q for q in l]", "def powerset(nums):\n t = []\n f...
{"fn_name": "powerset", "inputs": [[[1, 2]], [[1, 2, 3]], [[1]], [[125, 15, 155, 15, 158]], [[1, 2, 3, 4]]], "outputs": [[[[], [2], [1], [1, 2]]], [[[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]]], [[[], [1]]], [[[], [158], [15], [15, 158], [155], [155, 158], [155, 15], [155, 15, 158], [15], [15, 158], [15, 15],...
introductory
https://www.codewars.com/kata/59157809f05d9a8ad7000096
def powerset(nums):
3,576
Complete the function that takes one argument, a list of words, and returns the length of the longest word in the list. For example: ```python ['simple', 'is', 'better', 'than', 'complex'] ==> 7 ``` Do not modify the input list.
["def longest(words):\n return max(map(len, words))", "def longest(words):\n return max(len(i) for i in words)", "def longest(words):\n return len(max(words, key=len))", "def longest(words):\n number_of_chars = [len(word) for word in words]\n return max(number_of_chars)", "longest = lambda w: len(max(w, ...
{"fn_name": "longest", "inputs": [[["simple", "is", "better", "than", "complex"]], [["explicit", "is", "better", "than", "implicit"]], [["beautiful", "is", "better", "than", "ugly"]]], "outputs": [[7], [8], [9]]}
introductory
https://www.codewars.com/kata/58670300f04e7449290000e5
def longest(words):
3,577
Fibonacci numbers are generated by setting F0 = 0, F1 = 1, and then using the formula: # Fn = Fn-1 + Fn-2 Your task is to efficiently calculate the **n**th element in the Fibonacci sequence and then count the occurrence of each digit in the number. Return a list of integer pairs sorted in **descending** order. 10 ≤ ...
["from collections import Counter\n\ndef fib_digits(n):\n a, b = 0, 1\n for i in range(n): a, b = b, a+b\n return sorted(((b, int(a)) for a, b in Counter(str(a)).items()), reverse=True)", "from operator import itemgetter\ndef fib_digits(n):\n a,b = 1,1\n num=n\n num_int=int(num-2)\n for i in range ...
{"fn_name": "fib_digits", "inputs": [[10]], "outputs": [[[[2, 5]]]]}
introductory
https://www.codewars.com/kata/5779f894ec8832493f00002d
def fib_digits(n):
3,578
Your classmates asked you to copy some paperwork for them. You know that there are 'n' classmates and the paperwork has 'm' pages. Your task is to calculate how many blank pages do you need. ### Example: ```python paperwork(5, 5) == 25 ``` **Note:** if `n < 0` or `m < 0` return `0`! Waiting for translations and Fee...
["def paperwork(n, m):\n return n * m if n > 0 and m > 0 else 0", "def paperwork(n, m):\n if m<0 or n<0:\n return 0\n else:\n return n*m", "def paperwork(n, m):\n return max(n, 0)*max(m, 0)", "def paperwork(n, m):\n return n*m if n>=0 and m>=0 else 0", "def paperwork(n, m):\n return 0 if...
{"fn_name": "paperwork", "inputs": [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 0]], "outputs": [[25], [0], [0], [0], [0]]}
introductory
https://www.codewars.com/kata/55f9b48403f6b87a7c0000bd
def paperwork(n, m):
3,579
You may be familiar with the concept of combinations: for example, if you take 5 cards from a 52 cards deck as you would playing poker, you can have a certain number (2,598,960, would you say?) of different combinations. In mathematics the number of *k* combinations you can have taking from a set of *n* elements is ca...
["from math import factorial\n\ndef choose(n, k):\n return factorial(n) / ( factorial(k) * factorial(n-k) ) if k <=n else 0", "import sys\nimport functools\nsys.setrecursionlimit(1_000_000)\n\n# lru_cache is a python shortcut for memoization\n# memoization is a technique to avoid repeatedly calculating\n# something ...
{"fn_name": "choose", "inputs": [[1, 1], [5, 4], [10, 5], [10, 20], [52, 5], [100, 10], [500, 4], [1000, 3], [200, 8], [300, 6]], "outputs": [[1], [5], [252], [0], [2598960], [17310309456440], [2573031125], [166167000], [55098996177225], [962822846700]]}
introductory
https://www.codewars.com/kata/55b22ef242ad87345c0000b2
def choose(n,k):
3,580
Imagine that you have an array of 3 integers each representing a different person. Each number can be 0, 1, or 2 which represents the number of hands that person holds up. Now imagine there is a sequence which follows these rules: * None of the people have their arms raised at first * Firstly, a person raises 1 hand; ...
["def get_positions(n):\n return tuple(n // d % 3 for d in (1, 3, 9))", "def get_positions(n):\n return n%3, n//3%3, n//9%3", "def get_positions(n): #Jai Shree Ram!!!\n num2=n\n num3=n\n p2=[0,0,0,1,1,1,2,2,2]\n p3=[0,0,0,0,0,0,0,0,0,\n 1,1,1,1,1,1,1,1,1,\n 2,2,2,2,2,2,2,2,2]\n \n ...
{"fn_name": "get_positions", "inputs": [[54], [98], [3]], "outputs": [[[0, 0, 0]], [[2, 2, 1]], [[0, 1, 0]]]}
introductory
https://www.codewars.com/kata/56d8f14cba01a83cdb0002a2
def get_positions(n):
3,581
Thanks to the effects of El Nino this year my holiday snorkelling trip was akin to being in a washing machine... Not fun at all. Given a string made up of '~' and '\_' representing waves and calm respectively, your job is to check whether a person would become seasick. Remember, only the process of change from wave t...
["def sea_sick(sea):\n return \"Throw Up\" if (sea.count(\"~_\") + sea.count(\"_~\"))/len(sea) > 0.2 else \"No Problem\"", "def sea_sick(sea):\n changes = sum(1 for a,b in zip(sea,sea[1:]) if a!=b)\n return \"No Problem\" if changes*5 <= len(sea) else \"Throw Up\"", "def sea_sick(sea):\n waves = sum(sea[i: ...
{"fn_name": "sea_sick", "inputs": [["~"], ["_~~~~~~~_~__~______~~__~~_~~"], ["______~___~_"], ["____"], ["_~~_~____~~~~~~~__~_~"]], "outputs": [["No Problem"], ["Throw Up"], ["Throw Up"], ["No Problem"], ["Throw Up"]]}
introductory
https://www.codewars.com/kata/57e90bcc97a0592126000064
def sea_sick(sea):
3,582
Implement `String#digit?` (in Java `StringUtils.isDigit(String)`), which should return `true` if given object is a digit (0-9), `false` otherwise.
["def is_digit(n):\n return n.isdigit() and len(n)==1", "import re\n\ndef is_digit(n):\n return bool(re.match(\"\\d\\Z\", n))", "import re\ndef is_digit(n):\n return bool(re.fullmatch(r'\\d', n))", "is_digit=lambda n: len(n)==1 and n in \"0123456789\"", "is_digit = set(\"1234567890\").__contains__", "def is_di...
{"fn_name": "is_digit", "inputs": [[""], ["7"], [" "], ["a"], ["a5"], ["14"], ["!"], ["\""], ["#"], ["$"], ["%"], ["&"], ["'"], ["("], [")"], ["*"], ["+"], [","], ["-"], ["."], ["/"], ["0"], ["1"], ["2"], ["3"], ["4"], ["5"], ["6"], ["8"], ["9"], [":"], [";"], ["<"], ["="], [">"], ["?"], ["@"], ["A"], ["B"], ["C"], ["D...
introductory
https://www.codewars.com/kata/567bf4f7ee34510f69000032
def is_digit(n):
3,583
Given an array of ones and zeroes, convert the equivalent binary value to an integer. Eg: `[0, 0, 0, 1]` is treated as `0001` which is the binary representation of `1`. Examples: ``` Testing: [0, 0, 0, 1] ==> 1 Testing: [0, 0, 1, 0] ==> 2 Testing: [0, 1, 0, 1] ==> 5 Testing: [1, 0, 0, 1] ==> 9 Testing: [0, 0, 1, 0] =...
["def binary_array_to_number(arr):\n return int(\"\".join(map(str, arr)), 2)", "def binary_array_to_number(arr):\n return int(''.join(str(a) for a in arr), 2)", "def binary_array_to_number(arr):\n s = 0\n for digit in arr:\n s = s * 2 + digit\n\n return s", "def binary_array_to_number(arr):\n ret...
{"fn_name": "binary_array_to_number", "inputs": [[[0, 0, 0, 1]], [[0, 0, 1, 0]], [[1, 1, 1, 1]], [[0, 1, 1, 0]]], "outputs": [[1], [2], [15], [6]]}
introductory
https://www.codewars.com/kata/578553c3a1b8d5c40300037c
def binary_array_to_number(arr):
3,584
You have to write two methods to *encrypt* and *decrypt* strings. Both methods have two parameters: ``` 1. The string to encrypt/decrypt 2. The Qwerty-Encryption-Key (000-999) ``` The rules are very easy: ``` The crypting-regions are these 3 lines from your keyboard: 1. "qwertyuiop" 2. "asdfghjkl" 3. "zxcvbnm,." If ...
["from collections import deque\nKEYBOARD = ['zxcvbnm,.', 'ZXCVBNM<>', 'asdfghjkl', 'ASDFGHJKL', 'qwertyuiop', 'QWERTYUIOP']\n\ndef encrypt(text, encryptKey): return converter(text, encryptKey, 1)\ndef decrypt(text, encryptKey): return converter(text, encryptKey, -1)\n \ndef converter(text, encryptKey, sens):\n d...
{"fn_name": "encrypt", "inputs": [["A", 111], ["Abc", 212], ["Ball", 134], ["Ball", 444], ["This is a test.", 348], ["Do the kata Kobayashi Maru Test. Endless fun and excitement when finding a solution.", 583]], "outputs": [["S"], ["Smb"], [">fdd"], [">gff"], ["Iaqh qh g iyhi,"], ["Sr pgi jlpl Jr,lqlage Zlow Piapc I.sk...
introductory
https://www.codewars.com/kata/57f14afa5f2f226d7d0000f4
def encrypt(text, encryptKey):
3,585
You will receive an uncertain amount of integers in a certain order ```k1, k2, ..., kn```. You form a new number of n digits in the following way: you take one of the possible digits of the first given number, ```k1```, then the same with the given number ```k2```, repeating the same process up to ```kn``` and you con...
["from itertools import product\ndef proc_seq(*args):\n nums = set(int(''.join(l)) for l in product(*(str(a) for a in args)) if l[0] != '0')\n if len(nums) == 1: return [1, nums.pop()]\n return [len(nums), min(nums), max(nums), sum(nums)]", "from itertools import product\n\ndef proc_seq(*args):\n p = set([i...
{"fn_name": "proc_seq", "inputs": [[23, 17, 89], [22, 22, 22, 22], [230, 15, 8]], "outputs": [[[8, 218, 379, 2388]], [[1, 2222]], [[4, 218, 358, 1152]]]}
introductory
https://www.codewars.com/kata/5717924a1c2734e78f000430
def proc_seq(*args):
3,586
HTML Element Generator In this kata, you will be creating a python function that will take arguments and turn them into an HTML element. An HTML tag has three parts: The opening tag, which consists of a tag name and potentially attributes, all in between angle brackets. The element content, which is the data that is s...
["def html(tag, *contents, **attr):\n openTag = tag + ''.join(f' {\"class\" if k==\"cls\" else k}=\"{v}\"' for k,v in attr.items())\n \n return '\\n'.join( f'<{openTag}>{c}</{tag}>' for c in contents) or f'<{openTag} />'", "def html(tag, *args, **kwargs):\n open = tag + ''.join(f' {\"class\" if k == \"cls\"...
{"fn_name": "html", "inputs": [["br"], ["title", "Webpage Title"]], "outputs": [["<br />"], ["<title>Webpage Title</title>"]]}
introductory
https://www.codewars.com/kata/5e7837d0262211001ecf04d7
def html(tag_name, *args, **kwargs):
3,587
# Task John has an important number, and he doesn't want others to see it. He decided to encrypt the number, using the following steps: ``` His number is always a non strict increasing sequence ie. "123" He converted each digit into English words. ie. "123"--> "ONETWOTHREE" And then, rearrange the letters randomly....
["from collections import Counter \n\nEXECUTIONS_ORDER = [('Z', Counter(\"ZERO\"), '0'),\n ('W', Counter(\"TWO\"), '2'),\n ('U', Counter(\"FOUR\"), '4'),\n ('X', Counter(\"SIX\"), '6'),\n ('G', Counter(\"EIGHT\"), '8'),\n ...
{"fn_name": "original_number", "inputs": [["ONE"], ["OEN"], ["ONETWO"], ["OONETW"], ["TTONWOHREEE"]], "outputs": [["1"], ["1"], ["12"], ["12"], ["123"]]}
introductory
https://www.codewars.com/kata/5959b637030042889500001d
def original_number(s):
3,588
In this Kata you are expected to find the coefficients of quadratic equation of the given two roots (`x1` and `x2`). Equation will be the form of ```ax^2 + bx + c = 0``` Return type is a Vector (tuple in Rust, Array in Ruby) containing coefficients of the equations in the order `(a, b, c)`. Since there are infinitel...
["def quadratic(x1, x2):\n return (1,-x1-x2,x1*x2)\n", "def quadratic(x1, x2):\n return (1, -(x1 + x2), x1 * x2)\n", "import numpy as np\n\ndef quadratic(*args):\n return tuple(np.poly(args))", "def quadratic(x1, x2):\n equ = 1 , - x1-x2 , x1*x2\n return equ\n", "def quadratic(x1, x2):\n a = (1, -(x1+...
{"fn_name": "quadratic", "inputs": [[0, 1], [4, 9], [2, 6], [-5, -4]], "outputs": [[[1, -1, 0]], [[1, -13, 36]], [[1, -8, 12]], [[1, 9, 20]]]}
introductory
https://www.codewars.com/kata/5d59576768ba810001f1f8d6
def quadratic(x1, x2):
3,589
Make a function that receives a value, ```val``` and outputs the smallest higher number than the given value, and this number belong to a set of positive integers that have the following properties: - their digits occur only once - they are odd - they are multiple of three ```python next_numb(12) == 15 next_numb(1...
["def unique_digits(n):\n return len(set(str(n))) == len(str(n))\n\ndef next_numb(val):\n val += 1\n while val % 3: val += 1\n if val % 2 == 0: val += 3\n \n while not unique_digits(val):\n val += 6\n if val > 9876543210: break\n else:\n return val\n \n return \"There is ...
{"fn_name": "next_numb", "inputs": [[12], [13], [99], [999999], [9999999999]], "outputs": [[15], [15], [105], [1023459], ["There is no possible number that fulfills those requirements"]]}
introductory
https://www.codewars.com/kata/56abc5e63c91630882000057
def next_numb(val):
3,590
Given two arrays of strings, return the number of times each string of the second array appears in the first array. #### Example ```python array1 = ['abc', 'abc', 'xyz', 'cde', 'uvw'] array2 = ['abc', 'cde', 'uap'] ``` How many times do the elements in `array2` appear in `array1`? * `'abc'` appears twice in the fi...
["def solve(a,b):\n return [a.count(e) for e in b]", "from collections import Counter\n\ndef solve(a,b):\n c = Counter(a)\n return [c[s] for s in b]", "def solve(a,b):\n return [a.count(x) for x in b]", "def solve(a,b):\n return list(map(a.count, b))", "def solve(haystack, needles):\n return [haystack...
{"fn_name": "solve", "inputs": [[["abc", "abc", "xyz", "abcd", "cde"], ["abc", "cde", "uap"]], [["abc", "xyz", "abc", "xyz", "cde"], ["abc", "cde", "xyz"]], [["quick", "brown", "fox", "is", "quick"], ["quick", "abc", "fox"]]], "outputs": [[[2, 1, 0]], [[2, 1, 2]], [[2, 0, 1]]]}
introductory
https://www.codewars.com/kata/59ca8e8e1a68b7de740001f4
def solve(a,b):
3,591
In the morning all the doors in the school are closed. The school is quite big: there are **N** doors. Then pupils start coming. It might be hard to believe, but all of them want to study! Also, there are exactly **N** children studying in this school, and they come one by one. When these strange children pass by some...
["def doors(n):\n return int(n ** .5)", "def doors(n):\n doors = [False] * n\n for i in range(0, n):\n for j in range(i, n, i + 1):\n doors[j] = not doors[j]\n return doors.count(True)", "def doors(n):\n return int(n**0.5)", "def doors(n):\n from math import sqrt\n return int(sqrt...
{"fn_name": "doors", "inputs": [[5], [10], [100]], "outputs": [[2], [3], [10]]}
introductory
https://www.codewars.com/kata/57c15d314677bb2bd4000017
def doors(n):
3,592
Given an `x` and `y` find the smallest and greatest numbers **above** and **below** a given `n` that are divisible by both `x` and `y`. ### Examples ```python greatest(2, 3, 20) => 18 # 18 is the greatest number under 20 that is divisible by both 2 and 3 smallest(2, 3, 20) => 24 # 24 is the smallest number above 2...
["from math import gcd\n\n\ndef greatest(x, y, n):\n z = x * y // gcd(x, y)\n return (n - 1) // z * z\n \ndef smallest(x, y, n):\n z = x * y // gcd(x, y)\n return (n + z) // z * z\n", "from fractions import gcd\n\ndef near(x, y, n):\n lcm = x * y // gcd(x, y)\n return n // lcm * lcm, lcm\n\ndef gre...
{"fn_name": "greatest", "inputs": [[2, 3, 20], [13, 17, 100], [10, 100, 100], [1000000007, 1000000009, 10000000000000000000]], "outputs": [[18], [0], [0], [9000000144000000567]]}
introductory
https://www.codewars.com/kata/55f2a1c2cb3c95af75000045
def greatest(x, y, n):
3,593
Given a string and an array of integers representing indices, capitalize all letters at the given indices. For example: * `capitalize("abcdef",[1,2,5]) = "aBCdeF"` * `capitalize("abcdef",[1,2,5,100]) = "aBCdeF"`. There is no index 100. The input will be a lowercase string with no spaces and an array of digits. Goo...
["def capitalize(s,ind):\n ind = set(ind)\n return ''.join(c.upper() if i in ind else c for i,c in enumerate(s))", "def capitalize(s, ind):\n result = list(s)\n for index in ind:\n try:\n result[index] = result[index].upper()\n except IndexError:\n break # assumes the in...
{"fn_name": "capitalize", "inputs": [["abcdef", [1, 2, 5]], ["abcdef", [1, 2, 5, 100]], ["codewars", [1, 3, 5, 50]], ["abracadabra", [2, 6, 9, 10]], ["codewarriors", [5]], ["indexinglessons", [0]]], "outputs": [["aBCdeF"], ["aBCdeF"], ["cOdEwArs"], ["abRacaDabRA"], ["codewArriors"], ["Indexinglessons"]]}
introductory
https://www.codewars.com/kata/59cfc09a86a6fdf6df0000f1
def capitalize(s,ind):
3,594
**An [isogram](https://en.wikipedia.org/wiki/Isogram)** (also known as a "nonpattern word") is a logological term for a word or phrase without a repeating letter. It is also used by some to mean a word or phrase in which each letter appears the same number of times, not necessarily just once. You task is to write a me...
["from collections import Counter\nimport re\n\ndef is_isogram(word):\n if type(word) is not str or not word: return False\n return len(set( Counter(re.sub(r'[^a-z]', \"\", word.lower())).values() )) == 1", "from collections import Counter\n\ndef is_isogram(word):\n try:\n return len(set(Counter(filter(...
{"fn_name": "is_isogram", "inputs": [[null], [3], ["Dermatoglyphics"], ["isogram"], ["eleven"], ["moOse"], ["isIsogram"], [""], ["-.-"], ["subdermatoglyphic"], ["Alphabet"], ["thumbscrew-japingly"], ["Hjelmqvist-Gryb-Zock-Pfund-Wax"], ["Emily Jung Schwartzkopf"], ["aabbccddeeffgg"]], "outputs": [[false], [false], [true...
introductory
https://www.codewars.com/kata/586d79182e8d9cfaba0000f1
def is_isogram(word):
3,595
Your task is to Combine two Strings. But consider the rule... By the way you don't have to check errors or incorrect input values, everything is ok without bad tricks, only two input strings and as result one output string;-)... And here's the rule: Input Strings `a` and `b`: For every character in string `a` swap ...
["def work_on_strings(a, b):\n new_a = [letter if b.lower().count(letter.lower()) % 2 == 0 else letter.swapcase() for letter in a]\n new_b = [letter if a.lower().count(letter.lower()) % 2 == 0 else letter.swapcase() for letter in b]\n return ''.join(new_a) + ''.join(new_b)", "from collections import Counter\n\...
{"fn_name": "work_on_strings", "inputs": [["abc", "cde"], ["abcdeFgtrzw", "defgGgfhjkwqe"], ["abcdeFg", "defgG"], ["abab", "bababa"]], "outputs": [["abCCde"], ["abcDeFGtrzWDEFGgGFhjkWqE"], ["abcDEfgDEFGg"], ["ABABbababa"]]}
introductory
https://www.codewars.com/kata/56c30ad8585d9ab99b000c54
def work_on_strings(a,b):
3,596
# Task Determine the client's membership level based on the invested `amount` of money and the given thresholds for membership levels. There are four membership levels (from highest to lowest): `Platinum, Gold, Silver, Bronze` The minimum investment is the threshold limit for `Bronze` membership. If the given amount...
["def membership(amount, platinum, gold, silver, bronze):\n ordered = reversed(sorted((v, k) for k, v in locals().items() if k != 'amount'))\n return next((level.capitalize() for threshold, level in ordered if amount >= threshold), 'Not a member')", "def membership(amount, platinum, gold, silver, bronze):\n ...
{"fn_name": "membership", "inputs": [[100000, 1000000, 100000, 10000, 1000], [1001, 1000000, 100000, 10000, 1000], [998, 1000000, 100000, 10000, 1000], [0, 1000000, 100000, 10000, 1000]], "outputs": [["Gold"], ["Bronze"], ["Not a member"], ["Not a member"]]}
introductory
https://www.codewars.com/kata/5a21dcc48f27f2afa1000065
def membership(amount, platinum, gold, silver, bronze):
3,597
Create a method `sayHello`/`say_hello`/`SayHello` that takes as input a name, city, and state to welcome a person. Note that `name` will be an array consisting of one or more values that should be joined together with one space between each, and the length of the `name` array in test cases will vary. Example: ```pyth...
["def say_hello(name, city, state):\n return \"Hello, {}! Welcome to {}, {}!\".format(\" \".join(name), city, state)\n", "def say_hello(name, city, state):\n return f\"Hello, {' '.join(name)}! Welcome to {city}, {state}!\"", "def say_hello(name, city, state):\n return 'Hello, %s! Welcome to %s, %s!' % (' '.join(...
{"fn_name": "say_hello", "inputs": [[["John", "Smith"], "Phoenix", "Arizona"], [["Franklin", "Delano", "Roosevelt"], "Chicago", "Illinois"], [["Wallace", "Russel", "Osbourne"], "Albany", "New York"], [["Lupin", "the", "Third"], "Los Angeles", "California"], [["Marlo", "Stanfield"], "Baltimore", "Maryland"]], "outputs":...
introductory
https://www.codewars.com/kata/5302d846be2a9189af0001e4
def say_hello(name, city, state):
3,598
Finding your seat on a plane is never fun, particularly for a long haul flight... You arrive, realise again just how little leg room you get, and sort of climb into the seat covered in a pile of your own stuff. To help confuse matters (although they claim in an effort to do the opposite) many airlines omit the letters...
["def plane_seat(a):\n front, middle, back = (list(range(1,21)), list(range(21,41)), list(range(41,61)))\n left, center, right = ('ABC', 'DEF', \"GHK\")\n x, y = ('', '')\n \n if int(a[:-1]) in front: x = 'Front-'\n if int(a[:-1]) in middle: x = 'Middle-'\n if int(a[:-1]) in back: x = ...
{"fn_name": "plane_seat", "inputs": [["2B"], ["20B"], ["58I"], ["60D"], ["17K"]], "outputs": [["Front-Left"], ["Front-Left"], ["No Seat!!"], ["Back-Middle"], ["Front-Right"]]}
introductory
https://www.codewars.com/kata/57e8f757085f7c7d6300009a
def plane_seat(a):
3,599
We define the function `f1(n,k)`, as the least multiple of `n` that has all its digits less than `k`. We define the function `f2(n,k)`, as the least multiple of `n` that has all the digits that are less than `k`. Each digit may occur more than once in both values of `f1(n,k)` and `f2(n,k)`. The possible values for ...
["def find_f1_eq_f2(n,k):\n s = set(range(k))\n while True:\n n += 1\n testn = n\n while True:\n f = set(map(int,str(testn)))\n if f<=s:\n if f==s: return n\n break\n testn += n", "def find_f1_eq_f2(n,k):\n s = set(range(k))\n ...
{"fn_name": "find_f1_eq_f2", "inputs": [[542, 5], [1750, 6], [14990, 7], [3456, 4], [30500, 3], [62550, 5], [568525, 7], [9567100, 8]], "outputs": [[547], [1799], [14996], [3462], [30501], [62557], [568531], [9567115]]}
introductory
https://www.codewars.com/kata/5cb99d1a1e00460024827738
def find_f1_eq_f2(n,k):
3,600
Given a string as input, move all of its vowels to the end of the string, in the same order as they were before. Vowels are (in this kata): `a, e, i, o, u` Note: all provided input strings are lowercase. ## Examples ```python "day" ==> "dya" "apple" ==> "pplae" ```
["def move_vowels(s): \n return ''.join(sorted(s, key=lambda k: k in 'aeiou'))", "import re\n\ndef move_vowels(input):\n return ''.join(''.join(l) for l in zip(*re.findall(r'([^aeiou])?([aeiou])?', input)))", "def move_vowels(i): \n s, v = '', ''\n for letter in i:\n if letter in 'aeiou': v+=letter\n...
{"fn_name": "move_vowels", "inputs": [["day"], ["apple"], ["peace"], ["maker"], ["programming"], ["javascript"], ["python"], ["ruby"], ["haskell"], ["clojure"], ["csharp"]], "outputs": [["dya"], ["pplae"], ["pceae"], ["mkrae"], ["prgrmmngoai"], ["jvscrptaai"], ["pythno"], ["rbyu"], ["hskllae"], ["cljroue"], ["cshrpa"]]...
introductory
https://www.codewars.com/kata/56bf3287b5106eb10f000899
def move_vowels(input):
3,601
Your task is to construct a building which will be a pile of n cubes. The cube at the bottom will have a volume of n^3, the cube above will have volume of (n-1)^3 and so on until the top which will have a volume of 1^3. You are given the total volume m of the building. Being given m can you find the number n of cube...
["def find_nb(m):\n n = 1\n volume = 0\n while volume < m:\n volume += n**3\n if volume == m:\n return n\n n += 1\n return -1", "def find_nb(m):\n n=s=0\n while True:\n n+=1\n s+=n\n k=s*s\n if k== m:\n return n\n elif k>m:\n r...
{"fn_name": "find_nb", "inputs": [[4183059834009], [24723578342962], [135440716410000], [40539911473216], [26825883955641], [41364076483082], [9541025211025], [112668204662785], [79172108332642], [1788719004901], [131443152397956], [1801879360282], [18262169777476], [11988186060816], [826691919076], [36099801072722], [...
introductory
https://www.codewars.com/kata/5592e3bd57b64d00f3000047
def find_nb(m):
3,602
> [Run-length encoding](https://en.wikipedia.org/w/index.php?title=Run-length_encoding) (RLE) is a very simple form of data compression in which runs of data (that is, sequences in which the same data value occurs in many consecutive data elements) are stored as a single data value and count, rather than as the origina...
["from itertools import groupby\n\ndef run_length_encoding(s):\n return [[sum(1 for _ in g), c] for c, g in groupby(s)]", "from itertools import groupby\ndef run_length_encoding(s):\n return [[len(list(b)), a] for a,b in groupby(s)]", "def run_length_encoding(s):\n count, prev, lst = 1, '', []\n for c in s:\n ...
{"fn_name": "run_length_encoding", "inputs": [[""], ["abc"], ["aab"], ["hello world!"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbb"]], "outputs": [[[]], [[[1, "a"], [1, "b"], [1, "c"]]], [[[2, "a"], [1, "b"]]], [[[1, "h"], [1, "e"], [2, "l"], [1, "o"], [1, " "], [1, "w"], [1, "o"], [1, "r"], [1, "l"], [1, "d"], [1, "!"]]]...
introductory
https://www.codewars.com/kata/546dba39fa8da224e8000467
def run_length_encoding(s):
3,603
Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love. Write a function that will take the number of petals of each flower and return tru...
["def lovefunc( flower1, flower2 ):\n return (flower1+flower2)%2", "def lovefunc(flower1, flower2):\n return flower1 % 2 != flower2 % 2", "def lovefunc( flower1, flower2 ):\n return (flower1 + flower2) % 2 == 1", "def lovefunc(a, b):\n if a % 2 == 0 and b % 2 == 0:\n return False\n elif a % 2 != 0...
{"fn_name": "lovefunc", "inputs": [[1, 4], [2, 2], [0, 1], [0, 0]], "outputs": [[true], [false], [true], [false]]}
introductory
https://www.codewars.com/kata/555086d53eac039a2a000083
def lovefunc( flower1, flower2 ):
3,604
This kata is based on a [variation](https://www.codewars.com/kata/happy-numbers-5) of *Happy Numbers* by TySlothrop. It is advisable to complete it first to grasp the idea and then move on to this one. ___ Hello, my dear friend, and welcome to another *Happy Numbers* kata! What? You're not interested in them anymore?...
["sum_dig = lambda n, D={str(d): d*d for d in range(10)}: sum(map(D.get, str(n)))\nis_happy = lambda n: n > 4 and is_happy(sum_dig(n)) or n == 1\n\nhappy_set = set(filter(is_happy, range(100)))\nfor n in range(100, 3 * 10 ** 5):\n if sum_dig(n) in happy_set: happy_set.add(n)\n\nfrom bisect import bisect\ndef perform...
{"fn_name": "performant_numbers", "inputs": [[10], [50], [100]], "outputs": [[[1, 7, 10]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49]], [[1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49, 68, 70, 79, 82, 86, 91, 94, 97, 100]]]}
introductory
https://www.codewars.com/kata/5adf5b6a2f10c6c4bc000200
def performant_numbers(n, happy_list=sorted(happy_set)):
3,605
In the drawing below we have a part of the Pascal's triangle, lines are numbered from **zero** (top). The left diagonal in pale blue with only numbers equal to 1 is diagonal **zero**, then in dark green (1, 2, 3, 4, 5, 6, 7) is diagonal 1, then in pale green (1, 3, 6, 10, 15, 21) is diagonal 2 and so on. We want to c...
["def diagonal(n, p):\n # your code\n res = 0\n for base in range(p, max(n,p) + 1):\n value = 1\n for i in range(base-p+1,base+1):\n value *= i\n for i in range(1,p+1):\n value //= i\n res += int(value)\n return res\n", "import math\n\ndef diagonal(n, p):\n ...
{"fn_name": "diagonal", "inputs": [[20, 3], [20, 4], [20, 5], [20, 15], [100, 0], [1291, 5], [1291, 56], [1291, 1234], [12910, 15], [129100, 5]], "outputs": [[5985], [20349], [54264], [20349], [101], [6385476296235036], [154789835867995789816056814507354264440830262370837552235265352527754232996260833330144856388410192...
introductory
https://www.codewars.com/kata/559b8e46fa060b2c6a0000bf
def diagonal(n, p):
3,606
In this kata, your task is to identify the pattern underlying a sequence of numbers. For example, if the sequence is [1, 2, 3, 4, 5], then the pattern is [1], since each number in the sequence is equal to the number preceding it, plus 1. See the test cases for more examples. A few more rules : pattern may contain neg...
["from itertools import cycle\n\ndef find_pattern(s):\n diffs = [y - x for x, y in zip(s, s[1:])] \n for i in range(1, len(diffs) + 1):\n if len(diffs) % i == 0 and all(a == b for a, b in zip(diffs, cycle(diffs[:i]))): return diffs[:i]", "def find_pattern(seq):\n start, end = [], []\n for i in ran...
{"fn_name": "find_pattern", "inputs": [[[1, 2, 3, 4, 5]], [[1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]], [[1, 5, 2, 3, 1, 5, 2, 3, 1]], [[1, 5, 4, 8, 7, 11, 10, 14, 13]], [[0, 1]], [[4, 5, 6, 8, 3, 4, 5, 6, 8, 3, 4, 5, 6, 8, 3, 4]], [[4, 5, 3, -2, -1, 0, -2, -7, -6]], [[4, 5, 6, 5, 3, 2, 3, 4, 5, 6, 5, 3, 2, 3,...
introductory
https://www.codewars.com/kata/596185fe9c3097a345000a18
def find_pattern(seq):
3,607
Not considering number 1, the integer 153 is the first integer having this property: the sum of the third-power of each of its digits is equal to 153. Take a look: 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 The next number that experiments this particular behaviour is 370 with the same power. Write the function `eq_...
["def eq_sum_powdig(hMax, exp):\n return [i for i in range(2, hMax + 1) if i == sum(int(c) ** exp for c in str(i))]\n", "def eq_sum_powdig(hMax, exp):\n ret = []\n for i in range(10, hMax + 1):\n if i == sum(int(j) ** exp for j in str(i)):\n ret.append(i)\n return ret", "def eq_sum_powdig(...
{"fn_name": "eq_sum_powdig", "inputs": [[100, 2], [1000, 2], [2000, 2], [200, 3], [370, 3], [400, 3], [500, 3], [1000, 3], [1500, 3]], "outputs": [[[]], [[]], [[]], [[153]], [[153, 370]], [[153, 370, 371]], [[153, 370, 371, 407]], [[153, 370, 371, 407]], [[153, 370, 371, 407]]]}
introductory
https://www.codewars.com/kata/560a4962c0cc5c2a16000068
def eq_sum_powdig(hMax, exp):
3,608
*`This kata is a tribute/fanwork to the TV-show: Supernatural`* Balls! Those wayward Winchester boys are in trouble again, hunting something down in New Orleans. You are Bobby Singer, you know how "idjits" they can be, so you have to prepare. They will call you any minute with the race of the thing, and you want to ...
["database = '''werewolf : Silver knife or bullet to the heart\nvampire : Behead it with a machete\nwendigo : Burn it to death\nshapeshifter : Silver knife or bullet to the heart\nangel : Use the angelic blade\ndemon : Use Ruby's knife, or some Jesus-juice\nghost : Salt and iron, and don't forget to burn the corpse\ndr...
{"fn_name": "bob", "inputs": [["vampire"], ["pagan god"], ["werepuppy"]], "outputs": [["Behead it with a machete, idjits!"], ["It depends on which one it is, idjits!"], ["I have friggin no idea yet, idjits!"]]}
introductory
https://www.codewars.com/kata/55c9a8cda33889d69e00008b
def bob(what):
3,609
An onion array is an array that satisfies the following condition for all values of `j` and `k`: If all of the following are `true`: * `j >= 0` * `k >= 0` * `j + k = array.length - 1` * `j != k` then: * `a[j] + a[k] <= 10` ### Examples: ``` [1, 2, 19, 4, 5] => true (as 1+5 <= 10 and 2+4 <= 10) [1, 2, 19, 4,...
["def is_onion_array(a):\n return all(a[i] + a[-i-1] <= 10 for i in range(len(a) // 2))", "from typing import List\n\n\ndef is_onion_array(a: List[int]) -> bool:\n return all(aj + ak <= 10 for aj, ak in zip(a, a[:(len(a) - 1) // 2:-1]))\n", "def is_onion_array(a):\n for i in range(0,len(a)//2):\n if a[i...
{"fn_name": "is_onion_array", "inputs": [[[6, 0, 4]], [[1, 1, 15, 10, -1]]], "outputs": [[true], [false]]}
introductory
https://www.codewars.com/kata/59b2883c5e2308b54d000013
def is_onion_array(a):
3,610
## Fixed xor Write a function that takes two hex strings as input and XORs them against each other. If the strings are different lengths the output should be the length of the shortest string. Hint: The strings would first need to be converted to binary to be XOR'd. ## Note: If the two strings are of different leng...
["def fixed_xor(a, b):\n return \"\".join(f\"{int(x, 16)^int(y, 16):x}\" for x, y in zip(a, b))", "def fixed_xor(a, b):\n\n m = min(len(a), len(b)) \n \n return f\"{int(a[:m], 16) ^ int(b[:m], 16):0{m}x}\" if m else \"\"\n", "def fixed_xor(a, b):\n return \"\".join(format(int(x, 16) ^ int(y, 16), \"x...
{"fn_name": "fixed_xor", "inputs": [["1c0111001f010100061a024b53535009181c", "686974207468652062756c6c277320657965"], ["aadf", "bce2"], ["ab3f", "ac"], ["", ""], ["c611d9bdd9de38b9eb", "23a0745505d4d25494"], ["7d1e875da9d5e89b54c7eaf", "3541599be591709795cebd5"], ["785a6677b3e52f0e7", "a8d97da7441"], ["6cbd75511e7f750c...
introductory
https://www.codewars.com/kata/580f1220df91273ee90001e7
def fixed_xor(a, b):
3,611
In some ranking people collects points. The challenge is sort by points and calulate position for every person. But remember if two or more persons have same number of points, they should have same position number and sorted by name (name is unique). For example: Input structure: Output should be:
["def ranking(a):\n a.sort(key=lambda x: (-x[\"points\"], x[\"name\"]))\n for i, x in enumerate(a):\n x[\"position\"] = i + 1 if not i or x[\"points\"] < a[i-1][\"points\"] else a[i-1][\"position\"]\n return a", "def ranking(people):\n people = people[:]\n people.sort(key=lambda person: (-person['...
{"fn_name": "ranking", "inputs": [[[]]], "outputs": [[[]]]}
introductory
https://www.codewars.com/kata/5c784110bfe2ef660cb90369
def ranking(people):
3,612
A country has coins with denominations ```python coins_list = d1 < d2 < · · · < dn. ``` You want to make change for n cents, using the smallest number of coins. ```python # Example 1: U.S. coins d1 = 1 d2 = 5 d3 = 10 d4 = 25 ## Optimal change for 37 cents – 1 quarter, 1 dime, 2 pennies. # Example 2: Alien Planet Z c...
["from collections import deque\n\ndef loose_change(coins_list, amount_of_change):\n q = deque([(0, amount_of_change)])\n\n while q:\n l, a = q.popleft()\n if a == 0:\n return l\n q.extend((l + 1, a - i) for i in coins_list if a >= i)", "def loose_change(coins_list, amount):\n s...
{"fn_name": "loose_change", "inputs": [[[1, 5, 10, 25], 37], [[1, 3, 4], 6], [[25, 5, 10, 1, 21], 63], [[1, 4, 5, 10], 8], [[1, 2, 5, 10, 20, 50, 100, 200], 93]], "outputs": [[4], [2], [3], [2], [5]]}
introductory
https://www.codewars.com/kata/55722d67355421ab510001ac
def loose_change(coins_list, amount_of_change):
3,613
# Task A ciphertext alphabet is obtained from the plaintext alphabet by means of rearranging some characters. For example "bacdef...xyz" will be a simple ciphertext alphabet where a and b are rearranged. A substitution cipher is a method of encoding where each letter of the plaintext alphabet is replaced with the co...
["def is_substitution_cipher(s1, s2):\n return len(set(s1)) == len(set(s2)) == len(set(zip(s1, s2)))", "def f(s1, s2):\n d = {}\n for a, b in zip(s1, s2):\n if (a in d and d[a] != b):\n return False\n d[a] = b\n return True\n\ndef is_substitution_cipher(s1, s2):\n return f(s1, s2...
{"fn_name": "is_substitution_cipher", "inputs": [["aacb", "aabc"], ["aa", "bc"], ["aaxxaaz", "aazzaay"], ["aaxyaa", "aazzaa"], ["aazzaa", "aaxyaa"], ["jpeuizmi", "mxxcwriq"]], "outputs": [[true], [false], [true], [false], [false], [false]]}
introductory
https://www.codewars.com/kata/58870742c815166a960000af
def is_substitution_cipher(s1, s2):
3,614
NOTE: It is recommended you complete [Introduction to Esolangs](https://www.codewars.com/kata/esolang-interpreters-number-1-introduction-to-esolangs-and-my-first-interpreter-ministringfuck/) or [MiniBitFlip](https://www.codewars.com/kata/esolang-minibitflip/) before solving this one. Task: Make an interpreter for an es...
["def interpreter(tape):\n memory, ptr, output = {0: 0}, 0, \"\"\n \n for command in tape:\n if command == \">\": ptr += 1\n elif command == \"<\": ptr -= 1\n elif command == \"!\": memory[len(memory)] = 0\n elif command == \"*\": output += chr(memory.get(ptr, 0) % 256) \n ...
{"fn_name": "interpreter", "inputs": [["++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++...
introductory
https://www.codewars.com/kata/5876e24130b45aaa0c00001d
def interpreter(tape):
3,615
A group of friends (n >= 2) have reunited for a get-together after a very long time. They agree that they will make presentations on holiday destinations or expeditions they have been to only if it satisfies **one simple rule**: > the holiday/journey being presented must have been visited _only_ by the presenter a...
["from collections import Counter\n\ndef presentation_agenda(friend_list):\n uniqueDest = {d for d,c in Counter(d for p in friend_list for d in p['dest']).items() if c == 1}\n pFilteredDest = tuple((p['person'], [d for d in p['dest'] if d in uniqueDest]) for p in friend_list)\n return [{'person': name, 'des...
{"fn_name": "presentation_agenda", "inputs": [[[{"person": "Abe", "dest": ["London", "Dubai"]}, {"person": "Bond", "dest": ["Melbourne", "Dubai"]}]], [[{"person": "Abe", "dest": ["Dubai"]}, {"person": "Brad", "dest": ["Dubai"]}]], [[{"person": "Abe", "dest": ["London", "Dubai"]}, {"person": "Bond", "dest": ["Melbourne"...
introductory
https://www.codewars.com/kata/57dd8c78eb0537722f0006bd
def presentation_agenda(friend_list):
3,616
Define a "prime prime" number to be a rational number written as one prime number over another prime number: `primeA / primeB` (e.g. `7/31`) Given a whole number `N`, generate the number of "prime prime" rational numbers less than 1, using only prime numbers between `0` and `N` (non inclusive). Return the count of th...
["from bisect import bisect_left\n\ndef sieve(n):\n sieve, primes = [0]*(n+1), []\n for i in range(2, n+1):\n if not sieve[i]:\n primes.append(i)\n for j in range(i**2, n+1, i): sieve[j] = 1\n return primes\n\nPRIMES = sieve(100000)\n\ndef prime_primes(n):\n lst = PRIMES[:bisect...
{"fn_name": "prime_primes", "inputs": [[6], [4], [10], [65], [0], [1000], [666]], "outputs": [[[3, 1]], [[1, 0]], [[6, 3]], [[153, 63]], [[0, 0]], [[14028, 6266]], [[7260, 3213]]]}
introductory
https://www.codewars.com/kata/57ba58d68dcd97e98c00012b
def prime_primes(N):
3,617
An array is called `zero-balanced` if its elements sum to `0` and for each positive element `n`, there exists another element that is the negative of `n`. Write a function named `ìsZeroBalanced` that returns `true` if its argument is `zero-balanced` array, else return `false`. Note that an `empty array` will not sum to...
["from collections import Counter\n\ndef is_zero_balanced(arr):\n c = Counter(arr)\n return bool(arr) and all(c[k] == c[-k] for k in c)", "def is_zero_balanced(arr):\n return all(arr) == sum(arr) == 0", "def is_zero_balanced(arr):\n return arr != [] and sum(arr) == 0 and all(-x in arr for x in arr)", "def i...
{"fn_name": "is_zero_balanced", "inputs": [[[3]], [[-3]], [[0, 0, 0, 0, 0, 0]], [[0, 1, -1]], [[]], [[3, -2, -1]], [[0]], [[1, 1, -2]], [[-1, 1, -2, 2, -2, -2, -4, 4]], [[0, 0, 0, 0, 0]]], "outputs": [[false], [false], [true], [true], [false], [false], [true], [false], [false], [true]]}
introductory
https://www.codewars.com/kata/59c6fa6972851e8959000067
def is_zero_balanced(arr):
3,618
A core idea of several left-wing ideologies is that the wealthiest should *support* the poorest, no matter what and that is exactly what you are called to do using this kata (which, on a side note, was born out of the necessity to redistribute the width of `div`s into a given container). You will be given two paramete...
["def socialist_distribution(population, minimum):\n if minimum > sum(population)//len(population):\n return []\n while min(population) < minimum:\n population[population.index(min(population))] += 1\n population[population.index(max(population))] -= 1\n return population\n", "def socialis...
{"fn_name": "socialist_distribution", "inputs": [[[2, 3, 5, 15, 75], 5], [[2, 3, 5, 15, 75], 20], [[2, 3, 5, 45, 45], 5], [[2, 3, 5, 45, 45], 30], [[24, 48, 22, 19, 37], 30]], "outputs": [[[5, 5, 5, 15, 70]], [[20, 20, 20, 20, 20]], [[5, 5, 5, 42, 43]], [[]], [[30, 30, 30, 30, 30]]]}
introductory
https://www.codewars.com/kata/58cfa5bd1c694fe474000146
def socialist_distribution(population, minimum):
3,619
In this kata, we want to discover a small property of numbers. We say that a number is a **dd** number if it contains d occurences of a digit d, (d is in [1,9]). ## Examples * 664444309 is a **dd** number, as it contains 4 occurences of the number 4 * 30313, 122 are **dd** numbers as they respectively contain 3 occu...
["from collections import Counter\n\n\ndef is_dd(n):\n return any(value==count for value, count in Counter(int(x) for x in str(n)).items())", "from collections import Counter\n\ndef is_dd(n):\n return any(int(k) == v for k, v in Counter(str(n)).items())", "def is_dd(n):\n for i in range(1, 10):\n if str...
{"fn_name": "is_dd", "inputs": [[664444309], [122], [30313], [5023011], [9081231]], "outputs": [[true], [true], [true], [false], [false]]}
introductory
https://www.codewars.com/kata/5a40fc7ce1ce0e34440000a3
def is_dd(n):
3,620
Your task is to get Zodiac Sign using input ```day``` and ```month```. For exapmle: ```python get_zodiac_sign(1,5) => 'Taurus' get_zodiac_sign(10,10) => 'Libra' ``` Correct answers are (preloaded): ```python SIGNS = ['Capricorn', 'Aquarius', 'Pisces', 'Aries', 'Taurus', 'Gemini', 'Cancer', 'Leo', 'Virgo', 'Libra',...
["def get_zodiac_sign(day, month):\n\n signs = [\"Aquarius\", \"Pisces\", \"Aries\", \"Taurus\", \"Gemini\", \"Cancer\",\n \"Leo\", \"Virgo\", \"Libra\", \"Scorpio\", \"Sagittarius\", \"Capricorn\"]\n\n limits = [20, 19, 21, 20, 21, 21, 23, 23, 23, 23, 22, 22]\n\n return signs[month - 1] if limits[...
{"fn_name": "get_zodiac_sign", "inputs": [[10, 10], [1, 5], [6, 9], [25, 11]], "outputs": [["Libra"], ["Taurus"], ["Virgo"], ["Sagittarius"]]}
introductory
https://www.codewars.com/kata/5a376259b6cfd77ca000006b
def get_zodiac_sign(day, month):
3,621
This kata is inspired on the problem #50 of the Project Euler. The prime ``` 41``` is the result of the sum of many consecutive primes. In fact, ``` 2 + 3 + 5 + 7 + 11 + 13 = 41 , (6 addens) ``` Furthermore, the prime ``` 41``` is the prime below ``` 100 (val_max)``` that has the longest chain of consecutive ...
["# RWH primes\nLIMIT = 500000\nsieve = [True] * (LIMIT//2)\nfor n in range(3, int(LIMIT**0.5) +1, 2):\n if sieve[n//2]: sieve[n*n//2::n] = [False] * ((LIMIT-n*n-1)//2//n +1)\nPRIMES = [2] + [2*i+1 for i in range(1, LIMIT//2) if sieve[i]]\n\n\ndef prime_maxlength_chain(val_max):\n if val_max < 5:\n return ...
{"fn_name": "prime_maxlength_chain", "inputs": [[100], [200], [500], [1000]], "outputs": [[[41]], [[197]], [[499]], [[953]]]}
introductory
https://www.codewars.com/kata/56e93159f6c72164b700062b
def prime_maxlength_chain(n):
3,622
Write a simple regex to validate a username. Allowed characters are: - lowercase letters, - numbers, - underscore Length should be between 4 and 16 characters (both included).
["import re\ndef validate_usr(un):\n return re.match('^[a-z0-9_]{4,16}$', un) != None", "import re\n\ndef validate_usr(username):\n return bool(re.match(r'^[a-z0-9_]{4,16}$', username))", "import re\nvalidate_usr = lambda str: bool(re.match('^[a-z\\d_]{4,16}$', str))", "import re\ndef validate_usr(username):\n ...
{"fn_name": "validate_usr", "inputs": [["asddsa"], ["a"], ["Hass"], ["Hasd_12assssssasasasasasaasasasasas"], [""], ["____"], ["012"], ["p1pp1"], ["asd43 34"], ["asd43_34"]], "outputs": [[true], [false], [false], [false], [false], [true], [false], [true], [false], [true]]}
introductory
https://www.codewars.com/kata/56a3f08aa9a6cc9b75000023
def validate_usr(username):
3,623
# Description: Count the number of exclamation marks and question marks, return the product. # Examples ``` Product("") == 0 product("!") == 0 Product("!ab? ?") == 2 Product("!!") == 0 Product("!??") == 2 Product("!???") == 3 Product("!!!??") == 6 Product("!!!???") == 9 Product("!???!!") == 9 Product("!????!!!?") =...
["def product(s):\n return s.count(\"?\")*s.count(\"!\")", "def product(s):\n return s.count(\"!\")*s.count(\"?\")", "def product(s):\n ce = cq = 0\n for i in s:\n if i == '!':\n ce += 1\n elif i == '?':\n cq += 1\n return ce * cq", "def product(s):\n exclamation = ...
{"fn_name": "product", "inputs": [[""], ["!"], ["!!??!!"]], "outputs": [[0], [0], [8]]}
introductory
https://www.codewars.com/kata/57fb142297e0860073000064
def product(s):
3,624
>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: In kindergarten, the teacher gave the children some candies. The number of candies each child gets is not always the same. Here is an array `candies`(all e...
["def distribution_of_candy(candies):\n steps = 0\n while len(set(candies)) > 1:\n candies = [(a + 1) // 2 + (b + 1) // 2\n for a, b in zip(candies, candies[-1:] + candies)]\n steps += 1\n return [steps, candies.pop()]", "def distribution_of_candy(candies):\n n = 0\n while...
{"fn_name": "distribution_of_candy", "inputs": [[[1, 2, 3, 4, 5]], [[10, 2, 8, 22, 16, 4, 10, 6, 14, 20]]], "outputs": [[[6, 6]], [[17, 18]]]}
introductory
https://www.codewars.com/kata/582933a3c983ca0cef0003de
def distribution_of_candy(candies):
3,625
# Task You are given a regular array `arr`. Let's call a `step` the difference between two adjacent elements. Your task is to sum the elements which belong to the sequence of consecutive elements of length `at least 3 (but as long as possible)`, such that the steps between the elements in this sequence are the sam...
["def sum_of_regular_numbers(arr):\n res, value, save = 0, arr[1] - arr[0], arr[:2]\n for x,y in zip(arr[1:], arr[2:]):\n if y-x == value:\n save.append(y)\n else:\n if len(save) >= 3: res += sum(save)\n value, save = y-x, [x, y]\n if len(save) >= 3: res+= sum(sav...
{"fn_name": "sum_of_regular_numbers", "inputs": [[[54, 70, 86, 1, -2, -5, 0, 5, 78, 145, 212, 15]], [[59, 58, 57, 55, 53, 51]], [[7, 2, -3, 3, 9, 15]], [[-17, -9, 1, 9, 17, 4, -9]], [[7, 2, 3, 2, -2, 400, 802]], [[-1, 7000, 1, -6998, -13997]]], "outputs": [[639], [390], [30], [39], [1200], [-13994]]}
introductory
https://www.codewars.com/kata/58c20c8d61aefc518f0000fd
def sum_of_regular_numbers(arr):
3,626
Introduction The GADERYPOLUKI is a simple substitution cypher used in scouting to encrypt messages. The encryption is based on short, easy to remember key. The key is written as paired letters, which are in the cipher simple replacement. The most frequently used key is "GA-DE-RY-PO-LU-KI". ``` G => A g => a a =>...
["def encode(str, key):\n key = key.lower() + key.upper()\n dict = { char: key[i-1] if i % 2 else key[i+1] for i, char in enumerate(key) }\n return ''.join( dict.get(char, char) for char in str )\n\ndecode = encode", "def encode(message, key):\n a, b = (f\"{key[i::2]}{key[i::2].upper()}\" for i in (0, 1))\n...
{"fn_name": "encode", "inputs": [["Gug hgs g cgt", "gaderypoluki"], ["Dkucr pu yhr ykbir", "politykarenu"], ["ABCD", "gaderypoluki"], ["Ala has a cat", "gaderypoluki"]], "outputs": [["Ala has a cat"], ["Dance on the table"], ["GBCE"], ["Gug hgs g cgt"]]}
introductory
https://www.codewars.com/kata/592b7b16281da94068000107
def encode(message, key):
3,627
>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 arrays `arr1` and `arr2`. They have the same length(length>=2). The elements of two arrays always be integer. Sort `arr1` according to th...
["import numpy as np\n\ndef sort_two_arrays(arr1, arr2):\n idx2 = np.argsort(arr2, kind='mergesort')\n idx1 = np.argsort(arr1, kind='mergesort')\n return [[arr1[i] for i in idx2], [arr2[i] for i in idx1]]", "def sort_two_arrays(*args):\n sortedIdxRev = [ sorted((v,i) for i,v in enumerate(a)) for a in args[:...
{"fn_name": "sort_two_arrays", "inputs": [[[5, 4, 3, 2, 1], [6, 5, 7, 8, 9]], [[2, 1, 3, 4, 5], [5, 6, 7, 8, 9]], [[5, 6, 9, 2, 6, 5], [3, 6, 7, 4, 8, 1]]], "outputs": [[[[4, 5, 3, 2, 1], [9, 8, 7, 5, 6]]], [[[2, 1, 3, 4, 5], [6, 5, 7, 8, 9]]], [[[5, 5, 2, 6, 9, 6], [4, 3, 1, 6, 8, 7]]]]}
introductory
https://www.codewars.com/kata/5818c52e21a33314e00000cb
def sort_two_arrays(arr1, arr2):
3,628
> **Note**: This kata is a translation of this (Java) one: http://www.codewars.com/kata/rotate-array. I have not translated this first one as usual because I did not solved it, and I fear not being able to solve it (Java is **not** my cup of... tea). @cjmcgraw, if you want to use my translation on your kata feel free ...
["def rotate(arr, n):\n # ...\n n = n % len(arr)\n return arr[-n:] + arr[:-n]", "from collections import deque\n\n\ndef rotate(arr, n):\n \"\"\"Return a given array, rotated by n spaces.\"\"\"\n rotator = deque(arr)\n rotator.rotate(n)\n return list(rotator)\n", "def rotate(arr, n):\n dex = -(n ...
{"fn_name": "rotate", "inputs": [[["a", "b", "c"], 1], [[1.0, 2.0, 3.0], 1], [[true, true, false], 1]], "outputs": [[["c", "a", "b"]], [[3.0, 1.0, 2.0]], [[false, true, true]]]}
introductory
https://www.codewars.com/kata/54f8b0c7a58bce9db6000dc4
def rotate(arr, n):
3,629
Mash 2 arrays together so that the returning array has alternating elements of the 2 arrays . Both arrays will always be the same length. eg. [1,2,3] + ['a','b','c'] = [1, 'a', 2, 'b', 3, 'c']
["def array_mash(xs, ys):\n return [z for p in zip(xs, ys) for z in p]", "def array_mash(a, b):\n lista=[]\n c=len(a)\n for i in range(len(a)):\n lista.append(a[i])\n lista.append(b[i])\n return lista", "from itertools import chain\n\ndef array_mash(a, b):\n return list(chain(*zip(a,b)))...
{"fn_name": "array_mash", "inputs": [[[1, 2, 3], ["a", "b", "c"]], [[1, 2, 3, 4, 5], ["a", "b", "c", "d", "e"]], [[1, 1, 1, 1], [2, 2, 2, 2]], [[1, 8, "hello", "dog"], ["fish", "2", 9, 10]], [[null, 4], [null, "hello"]], [[1], [2]], [["h", "l", "o", "o", "l"], ["e", "l", "w", "r", "d"]]], "outputs": [[[1, "a", 2, "b", ...
introductory
https://www.codewars.com/kata/582642b1083e12521f0000da
def array_mash(a, b):
3,630
Given two numbers and an arithmetic operator (the name of it, as a string), return the result of the two numbers having that operator used on them. ```a``` and ```b``` will both be positive integers, and ```a``` will always be the first number in the operation, and ```b``` always the second. The four operators are "...
["def arithmetic(a, b, operator):\n return {\n 'add': a + b,\n 'subtract': a - b,\n 'multiply': a * b,\n 'divide': a / b,\n }[operator]", "def arithmetic(a, b, operator):\n if operator == \"add\":\n return a + b\n elif operator == \"subtract\":\n return a - b\n e...
{"fn_name": "arithmetic", "inputs": [[1, 2, "add"], [8, 2, "subtract"], [5, 2, "multiply"], [8, 2, "divide"]], "outputs": [[3], [6], [10], [4]]}
introductory
https://www.codewars.com/kata/583f158ea20cfcbeb400000a
def arithmetic(a, b, operator):
3,631
Time to win the lottery! Given a lottery ticket (ticket), represented by an array of 2-value arrays, you must find out if you've won the jackpot. Example ticket: To do this, you must first count the 'mini-wins' on your ticket. Each sub array has both a string and a number within it. If the character code of any of ...
["def bingo(ticket, win):\n return 'Winner!' if sum(chr(n) in s for s, n in ticket) >= win else 'Loser!'", "def bingo(ticket, win):\n return \"Winner!\" if sum( w in map(ord, s) for s, w in ticket ) >= win else \"Loser!\"", "def bingo(ticket,win):\n counter = 0\n for x,y in ticket:\n for i in x:\n ...
{"fn_name": "bingo", "inputs": [[[["ABC", 65], ["HGR", 74], ["BYHT", 74]], 2], [[["ABC", 65], ["HGR", 74], ["BYHT", 74]], 1], [[["HGTYRE", 74], ["BE", 66], ["JKTY", 74]], 3]], "outputs": [["Loser!"], ["Winner!"], ["Loser!"]]}
introductory
https://www.codewars.com/kata/57f625992f4d53c24200070e
def bingo(ticket, win):
3,632
The __Hamming weight__ of a string is the number of symbols that are different from the zero-symbol of the alphabet used. There are several algorithms for efficient computing of the Hamming weight for numbers. In this Kata, speaking technically, you have to find out the number of '1' bits in a binary representation of ...
["def hamming_weight(x):return bin(x).count('1')", "hamming_weight = lambda x: list(bin(x)).count('1') # :) \n", "def hamming_weight(x):\n count = 0\n while x:\n x &= x-1\n count += 1\n return count\n", "def hamming_weight(x):\n w = 0\n while x:\n w += x & 1\n x >>= 1\n return w", "def ...
{"fn_name": "hamming_weight", "inputs": [[0], [1], [2], [10], [21], [2048]], "outputs": [[0], [1], [1], [2], [3], [1]]}
introductory
https://www.codewars.com/kata/5519e930cd82ff8a9a000216
def hamming_weight(x):
3,633
OK, my warriors! Now that you beat the big BOSS, you can unlock three new skills. (Does it sound like we're playing an RPG? ;-) ## The Arrow Function (JS only) The first skill is the arrow function. Let's look at some examples to see how it works: ```python #ignore this part, it is just for JS ``` As you can see, it...
["def shuffle_it(A,*T):\n for x,y in T:\n A[x],A[y]=A[y],A[x]\n return A\n", "def shuffle_it(arr, *ind):\n for a, b in ind:\n [arr[b],arr[a]] = [arr[a],arr[b]]\n return arr", "def shuffle_it(a, *args):\n for x, y in args:\n a[x], a[y] = a[y], a[x]\n return a", "def shuffle_it(a,*b...
{"fn_name": "shuffle_it", "inputs": [[[1, 2, 3, 4, 5], [1, 2]], [[1, 2, 3, 4, 5], [1, 2], [3, 4]], [[1, 2, 3, 4, 5], [1, 2], [3, 4], [2, 3]], [[1, 2, 3, 4, 5], [4, 4]], [[1, 2, 3, 4, 5]]], "outputs": [[[1, 3, 2, 4, 5]], [[1, 3, 2, 5, 4]], [[1, 3, 5, 2, 4]], [[1, 2, 3, 4, 5]], [[1, 2, 3, 4, 5]]]}
introductory
https://www.codewars.com/kata/572ab0cfa3af384df7000ff8
def shuffle_it(A,*T):
3,634
You have to create a function named reverseIt. Write your function so that in the case a string or a number is passed in as the data , you will return the data in reverse order. If the data is any other type, return it as it is. Examples of inputs and subsequent outputs: ``` "Hello" -> "olleH" "314159" -> "951413" ...
["def reverse_it(data):\n if type(data) in [int, str, float]:\n return type(data)(str(data)[::-1])\n return data", "def reverse_it(data):\n t = type(data)\n return t(''.join(reversed(str(data)))) if t in [str, int, float] else data", "def reverse_it(data):\n return data if any(t is type(data) for ...
{"fn_name": "reverse_it", "inputs": [["Hello"], [314159], ["314159"], [[]], [{}], [true], [[1, 2, 3]]], "outputs": [["olleH"], [951413], ["951413"], [[]], [{}], [true], [[1, 2, 3]]]}
introductory
https://www.codewars.com/kata/557a2c136b19113912000010
def reverse_it(data):
3,635
Every positive integer number, that is not prime, may be decomposed in prime factors. For example the prime factors of 20, are: ``` 2, 2, and 5, because: 20 = 2 . 2 . 5 ``` The first prime factor (the smallest one) of ```20``` is ```2``` and the last one (the largest one) is ```5```. The sum of the first and the last ...
["def sflpf_data(val, nMax):\n r=[]\n for i in range(2,nMax):\n fac=primef(i)\n if len(fac)>1 and fac[0]+fac.pop()==val: r.append(i) \n return r\n \ndef primef(n):\n i= 2; f= []\n while i*i<=n:\n if n%i: i+=1\n else: n//=i; f.append(i)\n if n>1: f.append(n)\n return f",...
{"fn_name": "sflpf_data", "inputs": [[10, 100], [10, 200], [15, 150], [501, 1000], [501, 5000]], "outputs": [[[21, 25, 63]], [[21, 25, 63, 105, 125, 147, 189]], [[26, 52, 78, 104, 130]], [[998]], [[998, 1996, 2994, 3992, 4990]]]}
introductory
https://www.codewars.com/kata/5629b94e34e04f8fb200008e
def sflpf_data(val, nMax):
3,636
Working from left-to-right if no digit is exceeded by the digit to its left it is called an increasing number; for example, 134468. Similarly if no digit is exceeded by the digit to its right it is called a decreasing number; for example, 66420. We shall call a positive integer that is neither increasing nor decreasi...
["from operator import lt, gt\n\nmemo = {}\nis_bouncy = lambda s: memo[s] if s in memo else memo.setdefault(s, any(map(lt, s[:-1], s[1:])) and any(map(gt, s[:-1], s[1:])))\n\ndef bouncy_ratio(percent):\n if not 0 < percent < 1: raise Exception(\"Wrong percentage: {}\".format(percent))\n x, y = 100, 0\n while y...
{"fn_name": "bouncy_ratio", "inputs": [[0.1], [0.15], [0.5], [0.75], [0.9]], "outputs": [[132], [160], [538], [3088], [21780]]}
introductory
https://www.codewars.com/kata/562b099becfe844f3800000a
def bouncy_ratio(percent):
3,637
# Definition (Primorial Of a Number) *Is similar to factorial of a number*, **_In primorial_**, not all the natural numbers get multiplied, **_only prime numbers are multiplied to calculate the primorial of a number_**. It's denoted with **_P_****_#_** and it is the product of the first n prime numbers. ___ # Task ...
["def num_primorial(n):\n primorial, x, n = 2, 3, n-1\n while n:\n if all(x % d for d in range(3, int(x ** .5) + 1, 2)):\n primorial *= x\n n -= 1\n x += 2\n return primorial", "def num_primorial(n):\n primNums = [\n 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, ...
{"fn_name": "num_primorial", "inputs": [[3], [4], [5], [8], [9]], "outputs": [[30], [210], [2310], [9699690], [223092870]]}
introductory
https://www.codewars.com/kata/5a99a03e4a6b34bb3c000124
def num_primorial(n):
3,638
Gematria is an Assyro-Babylonian-Greek system of code and numerology later adopted into Jewish culture. The system assigns numerical value to a word or a phrase in the belief that words or phrases with identical numerical values bear some relation to each other or bear some relation to the number itself. While more com...
["\n\nTOME = {'a':1, 'b':2, 'c':3, 'd':4, 'e':5, 'f':6, 'g':7, 'h':8, 'i':9, 'k':10, 'l':20, 'm':30, 'n':40, 'o':50, 'p':60, 'q':70, 'r':80, 's':90, 't':100, 'u':200, 'x':300, 'y':400, 'z':500, 'j':600, 'v':700, 'w':900}\n\ndef gematria(s): return sum(TOME.get(c,0) for c in s.lower())", "def gematria(string):\n d = ...
{"fn_name": "gematria", "inputs": [["love"], ["jaels"], ["JAELS"], ["Devil"], ["Coding is fun"]], "outputs": [[775], [716], [716], [738], [458]]}
introductory
https://www.codewars.com/kata/573c91c5eaffa3bd350000b0
def gematria(string):
3,639
Ever the learned traveller, Alan Partridge has pretty strong views on London: ``` "Go to London. I guarantee you'll either be mugged or not appreciated. Catch the train to London, stopping at Rejection, Disappointment, Backstabbing Central and Shattered Dreams Parkway." ``` Your job is to check that the provided list ...
["def alan(arr):\n s = {'Rejection', 'Disappointment', 'Backstabbing Central', 'Shattered Dreams Parkway'}\n return \"Smell my cheese you mother!\" if s.issubset(arr) else \"No, seriously, run. You will miss it.\"", "def alan(arr):\n a = ['Rejection', 'Disappointment', 'Backstabbing Central', 'Shattered Dreams...
{"fn_name": "alan", "inputs": [[["Norwich", "Rejection", "Disappointment", "Backstabbing Central", "Shattered Dreams Parkway", "London"]], [["London", "Norwich"]], [["Norwich", "Tooting", "Bank", "Rejection", "Disappointment", "Backstabbing Central", "Exeter", "Shattered Dreams Parkway", "Belgium", "London"]], [["Londo...
introductory
https://www.codewars.com/kata/580a41b6d6df740d6100030c
def alan(arr):
3,640
Imagine a funnel filled with letters. The bottom letter drops out of the funnel and onto a conveyor belt: ``` \b,c/ --> \b,c/ \a/ --> \ / a ------- ------- ``` If there are two letters above a gap, the smaller letter falls into the gap. ``` \b,c/ --> \ c/ \ / --> \b/ ...
["def funnel_out(funnel):\n r=\"\"\n h=len(funnel)\n while funnel[h-1][0]!=\"~\":\n r+=funnel[h-1][0]\n funnel[h-1][0]=\"~\"\n i=h-1\n j=0\n while i>0:\n if funnel[i-1][j] < funnel[i-1][j+1]:\n funnel[i][j]=funnel[i-1][j]\n funnel[i-1][j]=\"~\"\n else:\n...
{"fn_name": "funnel_out", "inputs": [[[["q"]]], [[["b", "c"], ["a"]]], [[["d", "a", "c"], ["b", "e"], ["f"]]], [[["a", "e", "c", "f"], ["d", "i", "h"], ["j", "g"], ["b"]]]], "outputs": [["q"], ["abc"], ["fbadec"], ["bghcfiejda"]]}
introductory
https://www.codewars.com/kata/5a4b612ee626c5d116000084
def funnel_out(funnel):
3,641
In genetic the reverse complement of a sequence is formed by **reversing** the sequence and then taking the complement of each symbol. The four nucleotides in DNA is Adenine (A), Cytosine (C), Guanine (G) and Thymine (Thymine). - A is the complement of T - C is the complement of G. This is a bi-directional relatio...
["get = dict(zip(\"ATCG\", \"TAGC\")).__getitem__\n\ndef reverse_complement(dna):\n try:\n return ''.join(map(get, reversed(dna)))\n except KeyError:\n return \"Invalid sequence\"", "def reverse_complement(dna):\n table = str.maketrans(\"ACGT\", \"TGCA\")\n return \"Invalid sequence\" if set(d...
{"fn_name": "reverse_complement", "inputs": [["TTCCGGAA"], ["GACTGACTGTA"], [""], ["XYZ"]], "outputs": [["TTCCGGAA"], ["TACAGTCAGTC"], [""], ["Invalid sequence"]]}
introductory
https://www.codewars.com/kata/574a7d0dca4a8a0fbe000100
def reverse_complement(dna):
3,642
Every now and then people in the office moves teams or departments. Depending what people are doing with their time they can become more or less boring. Time to assess the current team. ```if-not:java You will be provided with an object(staff) containing the staff names as keys, and the department they work in as valu...
["def boredom(staff):\n lookup = {\n \"accounts\": 1,\n \"finance\": 2,\n \"canteen\": 10,\n \"regulation\": 3, \n \"trading\": 6,\n \"change\": 6,\n \"IS\": 8,\n \"retail\": 5,\n \"cleaning\": 4,\n \"pissing about\": 25\n }\n n = sum(lookup...
{"fn_name": "boredom", "inputs": [[{"tim": "change", "jim": "accounts", "randy": "canteen", "sandy": "change", "andy": "change", "katie": "IS", "laura": "change", "saajid": "IS", "alex": "trading", "john": "accounts", "mr": "finance"}], [{"tim": "IS", "jim": "finance", "randy": "pissing about", "sandy": "cleaning", "an...
introductory
https://www.codewars.com/kata/57ed4cef7b45ef8774000014
def boredom(staff):
3,643
Bob has a server farm crunching numbers. He has `nodes` servers in his farm. His company has a lot of work to do. The work comes as a number `workload` which indicates how many jobs there are. Bob wants his servers to get an equal number of jobs each. If that is impossible, he wants the first servers to receive more ...
["def distribute(nodes, workload):\n w = list(range(workload))[::-1]\n return [[w.pop() for _ in range(workload // nodes + (workload % nodes > n))] for n in range(nodes)]", "def distribute(n, w):\n g, (d,r) = iter(range(w)), divmod(w,n)\n return [ [next(g) for _ in range(d+(i<r))] for i in range(n)]", "def ...
{"fn_name": "distribute", "inputs": [[2, 4], [3, 3], [3, 9], [2, 5], [4, 10], [4, 5], [1, 1], [2, 1], [5, 4], [5, 1]], "outputs": [[[[0, 1], [2, 3]]], [[[0], [1], [2]]], [[[0, 1, 2], [3, 4, 5], [6, 7, 8]]], [[[0, 1, 2], [3, 4]]], [[[0, 1, 2], [3, 4, 5], [6, 7], [8, 9]]], [[[0, 1], [2], [3], [4]]], [[[0]]], [[[0], []]],...
introductory
https://www.codewars.com/kata/59f22b3cf0a83ff3e3003d8c
def distribute(nodes, workload):
3,644
Yup!! The problem name reflects your task; just add a set of numbers. But you may feel yourselves condescended, to write a C/C++ program just to add a set of numbers. Such a problem will simply question your erudition. So, lets add some flavor of ingenuity to it. Addition operation requires cost now, and the cost is th...
["from heapq import *\n\ndef add_all(lst):\n\n heapify(lst)\n total = 0\n while len(lst) > 1:\n s = heappop(lst) + heappop(lst)\n total += s\n heappush(lst, s)\n\n return total", "import heapq\n\ndef add_all(xs): \n heapq.heapify(xs)\n cost = 0\n while len(xs) > 1:\n c =...
{"fn_name": "add_all", "inputs": [[[1, 2, 3]], [[1, 2, 3, 4]], [[1, 2, 3, 4, 5]]], "outputs": [[9], [19], [33]]}
introductory
https://www.codewars.com/kata/5b7d7ce57a0c9d86c700014b
def add_all(lst):
3,645
Find the difference between two collections. The difference means that either the character is present in one collection or it is present in other, but not in both. Return a sorted set with difference. The collections can contain any character and can contain duplicates. For instance: A = [a,a,t,e,f,i,j] B = [t,g,g...
["def diff(a, b):\n return sorted(set(a) ^ set(b))", "def diff(a, b):\n return sorted(set(a).symmetric_difference(b))", "# return a sorted set with the difference\ndef diff(a, b):\n a = set(a)\n b = set(b)\n c = a.symmetric_difference(b)\n return sorted(list(c))", "# return a sorted set with the difference\nd...
{"fn_name": "diff", "inputs": [[["a", "b"], ["a", "b"]], [[], []]], "outputs": [[[]], [[]]]}
introductory
https://www.codewars.com/kata/594093784aafb857f0000122
def diff(a, b):
3,646
We have an integer array with unique elements and we want to do the permutations that have an element fixed, in other words, these permutations should have a certain element at the same position than the original. These permutations will be called: **permutations with one fixed point**. Let's see an example with an a...
["def fixed_points_perms(n, k):\n if k > n:\n return 0\n if k == n:\n return 1\n if k == 0:\n subf = lambda n: 1 if n == 0 else n * subf(n - 1) + (-1)**n\n return subf(n)\n return fixed_points_perms(n-1, k-1) * n // k\n", "from functools import lru_cache\nfrom math import factori...
{"fn_name": "fixed_points_perms", "inputs": [[4, 1], [4, 2], [4, 3], [10, 3], [10, 4], [20, 2], [4, 0], [4, 4], [4, 5]], "outputs": [[8], [6], [0], [222480], [55650], [447507315596451070], [9], [1], [0]]}
introductory
https://www.codewars.com/kata/5bbecf840441ca6d6a000126
def fixed_points_perms(n,k):
3,647
In this Kata, you will be given an array of unique elements, and your task is to rerrange the values so that the first max value is followed by the first minimum, followed by second max value then second min value, etc. For example: The first max is `15` and the first min is `7`. The second max is `12` and the second...
["def solve(arr):\n arr = sorted(arr, reverse=True)\n res = []\n while len(arr):\n res.append(arr.pop(0))\n if len(arr):\n res.append(arr.pop())\n return res", "def solve(arr):\n lmax, lmin = iter(sorted(arr)) , iter(sorted(arr)[::-1])\n return [next(lmax) if i%2==1 else next(...
{"fn_name": "solve", "inputs": [[[15, 11, 10, 7, 12]], [[91, 75, 86, 14, 82]], [[84, 79, 76, 61, 78]], [[52, 77, 72, 44, 74, 76, 40]], [[1, 6, 9, 4, 3, 7, 8, 2]], [[78, 79, 52, 87, 16, 74, 31, 63, 80]]], "outputs": [[[15, 7, 12, 10, 11]], [[91, 14, 86, 75, 82]], [[84, 61, 79, 76, 78]], [[77, 40, 76, 44, 74, 52, 72]], [...
introductory
https://www.codewars.com/kata/5a090c4e697598d0b9000004
def solve(arr):
3,648
Write a function that takes a string which has integers inside it separated by spaces, and your task is to convert each integer in the string into an integer and return their sum. ### Example ```python summy("1 2 3") ==> 6 ``` Good luck!
["def summy(string_of_ints):\n return sum(map(int,string_of_ints.split()))", "def summy(s):\n return sum(map(int, s.split(' ')))", "def summy(string_of_ints): \n return sum([int(element) for element in string_of_ints.split(\" \")])", "def summy(s):\n return eval(s.replace(' ', '+'))", "import re\n\ndef s...
{"fn_name": "summy", "inputs": [["1 2 3"], ["1 2 3 4"], ["1 2 3 4 5"], ["10 10"], ["0 0"]], "outputs": [[6], [10], [15], [20], [0]]}
introductory
https://www.codewars.com/kata/599c20626bd8795ce900001d
def summy(s):
3,649
You are a biologist working on the amino acid composition of proteins. Every protein consists of a long chain of 20 different amino acids with different properties. Currently, you are collecting data on the percentage, various amino acids make up a protein you are working on. As manually counting the occurences of am...
["def aa_percentage(seq, residues=[\"A\", \"I\", \"L\", \"M\", \"F\", \"W\", \"Y\", \"V\"]):\n return round(sum(seq.count(r) for r in residues)/len(seq)*100)", "def aa_percentage(seq, acid='AILMFWYV'):\n return round(sum(x in acid for x in seq) * 100 / len(seq) )", "def aa_percentage(protein, residue=\"AILMFWYV\"):...
{"fn_name": "aa_percentage", "inputs": [["MSRSLLLRFLLFLLLLPPLP", ["M"]], ["MSRSLLLRFLLFLLLLPPLP", ["M", "L"]], ["MSRSLLLRFLLFLLLLPPLP", ["F", "S", "L"]], ["MSRSLLLRFLLFLLLLPPLP"], ["RLMADDFFGQTLMAAAAAAQERRR", ["A"]], ["RLMADDFFGQTLMAAAAAAQERRR", ["A", "R", "D"]], ["RLMADDFFGQTLMAAAAAAQERRR"], ["PLPPLPLLEELELRPFFMAAGGTP...
introductory
https://www.codewars.com/kata/59759761e30a19cfe1000024
def aa_percentage(seq, residues=["A", "I", "L", "M", "F", "W", "Y", "V"]):
3,650
Assume we take a number `x` and perform any one of the following operations: ```Pearl a) Divide x by 3 (if it is divisible by 3), or b) Multiply x by 2 ``` After each operation, we write down the result. If we start with `9`, we can get a sequence such as: ``` [9,3,6,12,4,8] -- 9/3=3 -> 3*2=6 -> 6*2=12 -> 12/3=4 -> 4*2...
["def solve(a):\n for i in a:\n li = [i]\n while 1:\n if li[-1] % 3 == 0 and li[-1] // 3 in a : li.append(li[-1] // 3)\n elif li[-1] * 2 in a : li.append(li[-1] * 2)\n else : break\n if len(li) == len(a) : return li", "def solve(arr): \n ar, v = arr[:], lamb...
{"fn_name": "solve", "inputs": [[[1, 3]], [[4, 2]], [[12, 3, 9, 4, 6, 8]], [[4, 8, 6, 3, 12, 9]], [[558, 744, 1488, 279, 2232, 1116]], [[9, 1, 3]], [[3000, 9000]], [[4, 1, 2]], [[10, 5]]], "outputs": [[[3, 1]], [[2, 4]], [[9, 3, 6, 12, 4, 8]], [[9, 3, 6, 12, 4, 8]], [[279, 558, 1116, 2232, 744, 1488]], [[9, 3, 1]], [[9...
introductory
https://www.codewars.com/kata/5b7bae02402fb702ce000159
def solve(arr):
3,651
# Grains Write a program that calculates the number of grains of wheat on a chessboard given that the number on each square is double the previous one. There are 64 squares on a chessboard. #Example: square(1) = 1 square(2) = 2 square(3) = 4 square(4) = 8 etc... Write a program that shows how many grains were on ea...
["def square(number):\n return 2**(number-1)", "def square(n):\n return 1<<n-1", "square=lambda n: 2**(n-1)", "def square(number):\n return 1 << (number-1)", "square=lambda n:1<<n-1", "def square(number = 1):\n return 2 ** (number - 1)", "square=lambda a:1<<(a-1)", "def square(number):\n grains = 1\n...
{"fn_name": "square", "inputs": [[1], [3], [4], [16], [32]], "outputs": [[1], [4], [8], [32768], [2147483648]]}
introductory
https://www.codewars.com/kata/55f7eb009e6614447b000099
def square(number):
3,652
I have started studying electronics recently, and I came up with a circuit made up of 2 LEDs and 3 buttons. Here 's how it works: 2 buttons (`red` and `blue`) are connected to the LEDs (`red` and `blue` respectively). Buttons pressing pattern will be remembered and represented through the LEDs when the third button is...
["def button_sequences(seqR, seqB):\n pattern, state = '', ''\n toBool = lambda seq : [i == '1' for i in seq]\n for red, blue in zip(toBool(seqR), toBool(seqB)):\n if red and state == 'R' or blue and state == 'B':\n continue\n state = 'R' if red else 'B' if blue else ''\n patter...
{"fn_name": "button_sequences", "inputs": [["10011010", "10110111"], ["01001000", "01011100"], ["00010100", "01011100"], ["10101010", "01010101"], ["11011011", "11111011"]], "outputs": [["RBRB"], ["RB"], ["BRB"], ["RBRBRBRB"], ["RBR"]]}
introductory
https://www.codewars.com/kata/5bec507e1ab6db71110001fc
def button_sequences(seqR, seqB):
3,653
# Task Write a function that accepts `msg` string and returns local tops of string from the highest to the lowest. The string's tops are from displaying the string in the below way: ``` 7891012 TUWvXY 6 3 ABCDE S ...
["def tops(msg):\n n = len(msg)\n res,i,j,k = \"\",2,2,7\n while i < n:\n res = msg[i:i+j] + res\n i,j,k=i+k,j+1,k+4\n return res", "def transform(i): return (3*i-4+2*(i-1)*(i-2), i)\n\ndef tops(msg):\n iMax = int((3+(9+8*len(msg))**.5) / 4)\n return ''.join( msg[i:i+c] for i,c in map(tr...
{"fn_name": "tops", "inputs": [[""], ["abcde"], ["123456789abcdefghijklmnopqrstuwyxvzABCDEFGHIJKLMNOPQRSTU"], ["123456789abcdefghijklmnopqrstuwyxvzABCDEFGHIJKLMNOPQRSTUWvXYZ123456789012345678910123"]], "outputs": [[""], ["cd"], ["TUABCDElmnoabc34"], ["7891012TUWvXYABCDElmnoabc34"]]}
introductory
https://www.codewars.com/kata/5aa3e2b0373c2e4b420009af
def tops(msg):
3,654
Complete the function that takes 3 numbers `x, y and k` (where `x ≤ y`), and returns the number of integers within the range `[x..y]` (both ends included) that are divisible by `k`. More scientifically: `{ i : x ≤ i ≤ y, i mod k = 0 }` ## Example Given ```x = 6, y = 11, k = 2``` the function should return `3`, bec...
["def divisible_count(x,y,k):\n return y//k - (x-1)//k", "def divisible_count(x,y,k):\n upper = y//k\n lower = (x-1)//k\n return upper - lower", "divisible_count=lambda x,y,k:y//k-~-x//k", "def divisible_count(x,y,k):\n ans = 0\n \n while True:\n if x % k == 0:\n break\n el...
{"fn_name": "divisible_count", "inputs": [[6, 11, 2], [11, 345, 17], [0, 1, 7], [20, 20, 2], [20, 20, 8], [19, 20, 2], [0, 10, 1], [11, 14, 2], [101, 9999999999999999999999999999999999999999999, 11], [1005, 9999999999999999999999999999999999999999999, 109]], "outputs": [[3], [20], [1], [1], [0], [1], [11], [2], [909090...
introductory
https://www.codewars.com/kata/55a5c82cd8e9baa49000004c
def divisible_count(x,y,k):
3,655
## Task Given `n` representing the number of floors build a beautiful multi-million dollar mansions like the ones in the example below: ``` /\ / \ / \ /______\ number of floors 3 | | | | |______| /\ / \ /____\ | | 2 floors |____| /\ /__\ 1 floor...
["def my_crib(n):\n roof = \"\\n\".join(\"%s/%s\\\\%s\"%(\" \"*(n-i),\" \"*i*2,\" \"*(n-i)) for i in range(n))\n ceiling = \"\\n/%s\\\\\\n\"%(\"_\"*(n*2))\n walls = (\"|%s|\\n\"%(\" \"*(n*2)))*(n-1)\n floor = \"|%s|\"%(\"_\"*(n*2))\n \n return roof + ceiling + walls + floor", "def my_crib(n):\n roo...
{"fn_name": "my_crib", "inputs": [[1], [2], [3]], "outputs": [[" /\\ \n/__\\\n|__|"], [" /\\ \n / \\ \n/____\\\n| |\n|____|"], [" /\\ \n / \\ \n / \\ \n/______\\\n| |\n| |\n|______|"]]}
introductory
https://www.codewars.com/kata/5834a44e44ff289b5a000075
def my_crib(n):
3,656
Given a rational number n ``` n >= 0, with denominator strictly positive``` - as a string (example: "2/3" in Ruby, Python, Clojure, JS, CS, Go) - or as two strings (example: "2" "3" in Haskell, Java, CSharp, C++, Swift) - or as a rational or decimal number (example: 3/4, 0.67 in R) - or two integers (Fortran) d...
["from math import ceil\nfrom fractions import Fraction as F\ndef decompose(n):\n f = F(n)\n ff = int(f)\n result = [str(ff)] if ff else []\n f -= ff\n while f>0:\n x = F(1,int(ceil(f**-1)))\n f -= x\n result.append(str(x))\n return result", "from fractions import Fraction\nfrom m...
{"fn_name": "decompose", "inputs": [["0"], ["3/4"], ["12/4"], ["4/5"], ["0.66"], ["22/23"], ["1001/3456"], ["16/17"], ["30/45"], ["1.25"], ["75/3"], ["2/8"], ["0.9"]], "outputs": [[[]], [["1/2", "1/4"]], [["3"]], [["1/2", "1/4", "1/20"]], [["1/2", "1/7", "1/59", "1/5163", "1/53307975"]], [["1/2", "1/3", "1/9", "1/83", ...
introductory
https://www.codewars.com/kata/54f8693ea58bce689100065f
def decompose(n):
3,657
Write a program that will take a string of digits and give you all the possible consecutive slices of length `n` in that string. Raise an error if `n` is larger than the length of the string. ## Examples For example, the string `"01234"` has the following 2-digit slices: ``` [0, 1], [1, 2], [2, 3], [3, 4] ``` The...
["def series_slices(digits, n):\n if n > len(digits):\n raise ValueError\n else:\n return [[int(digit) for digit in digits[i:i+n]] for i in range(0, len(digits)-n+1)]", "def series_slices(s, n):\n if n > len(s):\n raise\n \n arr = [int(d) for d in s]\n return [ arr[i:i+n] for i in...
{"fn_name": "series_slices", "inputs": [["01234", 1], ["01234", 2], ["01234", 3], ["01234", 4], ["01234", 5]], "outputs": [[[[0], [1], [2], [3], [4]]], [[[0, 1], [1, 2], [2, 3], [3, 4]]], [[[0, 1, 2], [1, 2, 3], [2, 3, 4]]], [[[0, 1, 2, 3], [1, 2, 3, 4]]], [[[0, 1, 2, 3, 4]]]]}
introductory
https://www.codewars.com/kata/53f9a36864b19d8be7000609
def series_slices(digits, n):
3,658
Your job is to change the given string `s` using a non-negative integer `n`. Each bit in `n` will specify whether or not to swap the case for each alphabetic character in `s`: if the bit is `1`, swap the case; if its `0`, leave it as is. When you finished with the last bit of `n`, start again with the first bit. You ...
["from itertools import cycle\n\ndef swap(s,n):\n b = cycle(bin(n)[2:])\n return \"\".join(c.swapcase() if c.isalpha() and next(b) == '1' else c for c in s)", "from itertools import cycle\n\ndef swap(s,n):\n doSwap = cycle(map(int,f\"{n:b}\"))\n return ''.join(c.swapcase() if c.isalpha() and next(doSwap) el...
{"fn_name": "swap", "inputs": [["Hello world!", 11], ["the quick broWn fox leapt over the fence", 9], ["eVerybody likes ice cReam", 85], ["gOOd MOrniNg", 7864], ["how are you today?", 12345], ["the lord of the rings", 0], ["", 11345]], "outputs": [["heLLO wORLd!"], ["The QUicK BrowN foX LeaPT ovER thE FenCE"], ["EVErYb...
introductory
https://www.codewars.com/kata/5f3afc40b24f090028233490
def swap(s,n):
3,659
Consider X as the aleatory variable that count the number of letters in a word. Write a function that, give in input an array of words (strings), calculate the variance of X. Max decimal of the variance : 4. Some wiki: Variance , Aleatory variable Example: Consider "Hello" and "World": X is { 5 } with P(X = 5...
["variance=lambda w:round(__import__('statistics').pvariance(map(len,w)),4)", "from statistics import pvariance\n\ndef variance(words):\n return round(pvariance(map(len, words)), 4)", "from statistics import pvariance as var\n\nvariance = lambda words: round(var(len(word) for word in words), 4)", "def variance(words...
{"fn_name": "variance", "inputs": [[["Hello", "world"]], [["Hi", "world"]], [["Variance", "is", "not", "a", "good", "stimator"]]], "outputs": [[0], [2.25], [7.5556]]}
introductory
https://www.codewars.com/kata/55f2afa960aeea545a000049
def variance(words):
3,660
Happy traveller [Part 1] There is a play grid NxN; Always square! 0 1 2 3 0 [o, o, o, X] 1 [o, o, o, o] 2 [o, o, o, o] 3 [o, o, o, o] You start from a random point. I mean, you are given the coordinates of your start position in format (row, col). And your TASK is to define the number of unique paths to re...
["from math import factorial as f\ncount_paths=lambda n,c:f(c[0]+abs(n-c[1]-1))//(f(abs(n-c[1]-1))*f(c[0])) if n!=1 else 0", "from math import factorial\ndef count_paths(N, coords):\n if N==1:\n return 0\n x=coords[0]\n y=N-1-coords[1]\n return factorial(x+y)//(factorial(x)*factorial(y))", "count_pat...
{"fn_name": "count_paths", "inputs": [[1, [0, 0]], [2, [1, 0]], [2, [1, 1]], [3, [1, 0]], [5, [4, 0]], [6, [5, 0]], [7, [6, 0]]], "outputs": [[0], [2], [1], [3], [70], [252], [924]]}
introductory
https://www.codewars.com/kata/586d9a71aa0428466d00001c
def count_paths(N, coords):
3,661
You are given a certain integer, ```n, n > 0```. You have to search the partition or partitions, of n, with maximum product value. Let'see the case for ```n = 8```. ``` Partition Product [8] 8 [7, 1] 7 [6, 2] 12 [6, 1, 1] ...
["def find_part_max_prod(n):\n if n == 1: return [[1], 1]\n q, r = divmod(n, 3)\n if r == 0: return [[3]*q, 3**q]\n if r == 1: return [[4] + [3]*(q - 1), [3]*(q - 1) + [2, 2], 3**(q - 1) * 2**2]\n return [[3]*q + [2], 3**q * 2]", "from collections import defaultdict\nfrom functools import reduce\n\ndef find_part_m...
{"fn_name": "find_part_max_prod", "inputs": [[8], [10]], "outputs": [[[[3, 3, 2], 18]], [[[4, 3, 3], [3, 3, 2, 2], 36]]]}
introductory
https://www.codewars.com/kata/5716a4c2794d305f4900156b
def find_part_max_prod(n):
3,662
# Exclusive "or" (xor) Logical Operator ## Overview In some scripting languages like PHP, there exists a logical operator (e.g. ```&&```, ```||```, ```and```, ```or```, etc.) called the "Exclusive Or" (hence the name of this Kata). The exclusive or evaluates two booleans. It then returns true if **exactly one of th...
["def xor(a,b):\n return a != b", "def xor(a,b):\n return a ^ b", "from operator import xor", "def xor(a,b):\n return a is not b", "def xor(a,b):\n print(a,b)\n if a == True and b == True: \n return False\n elif a == True or b == True:\n return True\n return False", "xor = int.__xo...
{"fn_name": "xor", "inputs": [[false, false], [true, false], [false, true], [true, true]], "outputs": [[false], [true], [true], [false]]}
introductory
https://www.codewars.com/kata/56fa3c5ce4d45d2a52001b3c
def xor(a,b):
3,663
## Problem There are `n` apples that need to be divided into four piles. We need two mysterious number `x` and `y`. Let The number of first pile equals to `x+y`, the number of second pile equals to `x-y`, the number of third pile equals to `x*y`, the number of fourth pile equals to `x/y`. We need to calculate how many...
["def four_piles(n,y):\n x,r=divmod(n*y,(y+1)**2)\n return [] if r or x==y else [x+y,x-y,x*y,x//y]\n", "def four_piles(n,y): \n x = y * n / (y**2 + 2*y + 1)\n return [x + y, x - y, x * y, x / y] if int(x) == x and x - y > 0 else []", "def four_piles(n,y):\n x = y*n / (1+2*y+y**2)\n ans = [x+y, x...
{"fn_name": "four_piles", "inputs": [[48, 3], [100, 4], [25, 4], [24, 4]], "outputs": [[[12, 6, 27, 3]], [[20, 12, 64, 4]], [[]], [[]]]}
introductory
https://www.codewars.com/kata/57aae4facf1fa57b3300005d
def four_piles(n,y):