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,364
My grandfather always predicted how old people would get, and right before he passed away he revealed his secret! In honor of my grandfather's memory we will write a function using his formula! * Take a list of ages when each of your great-grandparent died. * Multiply each number by itself. * Add them all togethe...
["def predict_age(*ages):\n return sum(a*a for a in ages)**.5//2", "def predict_age(*age):\n return sum(a*a for a in age)**0.5//2", "import numpy as np\ndef predict_age(age_1, age_2, age_3, age_4, age_5, age_6, age_7, age_8):\n return np.sum(np.array([age_1, age_2, age_3, age_4, age_5, age_6, age_7, age_8]) **...
{"fn_name": "predict_age", "inputs": [[65, 60, 75, 55, 60, 63, 64, 45], [32, 54, 76, 65, 34, 63, 64, 45]], "outputs": [[86], [79]]}
introductory
https://www.codewars.com/kata/5aff237c578a14752d0035ae
def predict_age(age_1, age_2, age_3, age_4, age_5, age_6, age_7, age_8):
3,365
You have a collection of lovely poems. Unfortuantely they aren't formatted very well. They're all on one line, like this: ``` Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated. ``` What you want is to present each sentence on a new line, ...
["def format_poem(poem):\n return \".\\n\".join(poem.split(\". \"))", "def format_poem(poem):\n return poem.replace(\". \", \".\\n\")\n", "def format_poem(poem):\n lines = poem.split('. ')\n return '.\\n'.join(lines)\n \n \n \n \n \n", "from re import sub\n\n# Try to solve this challenge with...
{"fn_name": "format_poem", "inputs": [["Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated."], ["Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules."], ["Altho...
introductory
https://www.codewars.com/kata/585af8f645376cda59000200
def format_poem(poem):
3,366
Lexicographic permutations are ordered combinations of a set of items ordered in a specific way. For instance, the first 8 permutations of the digits 0123, in lexicographic order, are: ``` 1st 0123 2nd 0132 3rd 0213 4th 0231 5th 0312 6th 0321 7th 1023 8th 1032 ``` Your task is to write a function ```L( n, d )``` tha...
["import math\ndef nth_perm(n,d):\n digits = [str(i) for i in range(d)]\n out = ''\n for i in range(1, d):\n cycles = math.ceil(n/math.factorial(d-i))\n out += digits.pop((cycles % (d-i+1)) - 1)\n return out + digits.pop()", "def nth_perm(n,d):\n st, i, n, fc = list(map(str, range(d))), 1, ...
{"fn_name": "nth_perm", "inputs": [[1, 1], [12, 5], [1000, 7], [1000, 8], [1000000, 10], [874, 7], [100, 5], [400, 6], [900, 8], [3000000, 10], [1234567, 10], [654321, 10], [100000, 9], [33333, 8]], "outputs": [["0"], ["02431"], ["1325460"], ["02436571"], ["2783915460"], ["1234560"], ["40231"], ["314250"], ["02354761"]...
introductory
https://www.codewars.com/kata/55baa55cf332e67eb000000a
def nth_perm(n,d):
3,367
Given a side length `n`, traveling only right and down how many ways are there to get from the top left corner to the bottom right corner of an `n by n` grid? Your mission is to write a program to do just that! Add code to `route(n)` that returns the number of routes for a grid `n by n` (if n is less than 1 return 0)...
["from math import factorial\n\ndef routes(n):\n return n > 0 and factorial(2*n) // factorial(n)**2", "from math import factorial as f\nroutes=lambda n:f(n*2) // (f(n)*f(n)) if n>0 else 0", "def routes(n):\n if(n < 1):\n return(0);\n \n res = 1;\n for i in range(1, n + 1):\n res = res*(n + i)//i;\n \n ...
{"fn_name": "routes", "inputs": [[156], [106], [108], [126], [165], [125], [103]], "outputs": [[376594020312425061595746241557406711201605603899894320577733841460621358204120168599683135056], [360262512886894560870925723424985925545493469115736766525399280], [571070328060067027174940931265047783328344528146596234788184...
introductory
https://www.codewars.com/kata/559aa1295f5c38fd7b0000ac
def routes(n):
3,368
_Based on [Project Euler problem 35](https://projecteuler.net/problem=35)_ A circular prime is a prime in which every circular permutation of that number is also prime. Circular permutations are created by rotating the digits of the number, for example: `197, 971, 719`. One-digit primes are circular primes by definiti...
["def circular_permutations(n):\n n = str(n)\n return [int(n[i:] + n[:i]) for i in range(len(n))]\n\ndef is_prime(n):\n return n > 1 and all(n % i != 0 for i in range(2, int(n**0.5)+1))\n\ndef circular_prime(n):\n return all(is_prime(x) for x in circular_permutations(n))\n", "def circular_prime(n):\n ret...
{"fn_name": "circular_prime", "inputs": [[197], [179], [971], [222], [9377], [7], [213], [35], [1]], "outputs": [[true], [false], [true], [false], [true], [true], [false], [false], [false]]}
introductory
https://www.codewars.com/kata/56b2333e2542c2aadb000079
def circular_prime(n):
3,369
## Terminal game move function In this game, the hero moves from left to right. The player rolls the dice and moves the number of spaces indicated by the dice **two times**. ~~~if-not:sql Create a function for the terminal game that takes the current position of the hero and the roll (1-6) and return the new position...
["def move(position, roll):\n return position + 2*roll", "def move(position, roll):\n return position+roll*2", "move = lambda p,r: p+r*2", "def move(start, roll):\n return start + 2*roll", "def move(start, roll):\n return start + roll * 2", "def move(position, roll):\n return position+(roll<<1)", "move=lam...
{"fn_name": "move", "inputs": [[0, 4], [3, 6], [2, 5]], "outputs": [[8], [15], [12]]}
introductory
https://www.codewars.com/kata/563a631f7cbbc236cf0000c2
def move(position, roll):
3,370
In this kata the function returns an array/list of numbers without its last element. The function is already written for you and the basic tests pass, but random tests fail. Your task is to figure out why and fix it. Good luck! Hint: watch out for side effects. ~~~if:javascript Some good reading: [MDN Docs about arr...
["def without_last(lst):\n return lst[:-1]", "def without_last(lst):\n lst_copy = list(lst) # creates a shallow copy\n lst_copy.pop()\n return lst_copy\n\n# There are several other ways to solve this\n# like returning lst[:-1] directly or creating a new list iteratively with all the elements of lst minus th...
{"fn_name": "without_last", "inputs": [[[1, 2, 3, 4, 5]], [[9, 7, 6, 9]]], "outputs": [[[1, 2, 3, 4]], [[9, 7, 6]]]}
introductory
https://www.codewars.com/kata/5a4ff3c5fd56cbaf9800003e
def without_last(lst):
3,371
Implement `String.eight_bit_signed_number?` (Ruby), `String.eightBitSignedNumber()` (Python), `eight_bit_signed_number()` (JS) or `StringUtils.isSignedEightBitNumber(String)` (Java) which should return `true/True` if given object is a number representable by 8 bit signed integer (-128 to -1 or 0 to 127), `false/False` ...
["import re\ndef signed_eight_bit_number(number):\n return bool(re.match(\"(0|-128|-?([1-9]|[1-9]\\d|1[01]\\d|12[0-7]))\\Z\", number))", "def signed_eight_bit_number(number):\n if number in list(map(str,list(range(-128,128)))):\n return True\n return False\n \n", "import re\n\nSIGNED_BYTE_PATTERN...
{"fn_name": "signed_eight_bit_number", "inputs": [[""], ["0"], ["00"], ["-0"], ["55"], ["-23"], ["042"], ["127"], ["128"], ["999"], ["-128"], ["-129"], ["-999"], ["1\n"], ["1 "], [" 1"], ["1\n2"], ["+1"], ["--1"], ["01"], ["-01"]], "outputs": [[false], [true], [false], [false], [true], [true], [false], [true], [false],...
introductory
https://www.codewars.com/kata/567ed73340895395c100002e
def signed_eight_bit_number(number):
3,372
Given two words and a letter, return a single word that's a combination of both words, merged at the point where the given letter first appears in each word. The returned word should have the beginning of the first word and the ending of the second, with the dividing letter in the middle. You can assume both words will...
["def string_merge(string1, string2, letter):\n return string1[:string1.index(letter)] + string2[string2.index(letter):]", "def string_merge(string1, string2, letter):\n \"\"\"given two words and a letter, merge one word that combines both at the first occurence of \n the letter\n >>> \"hello\",\"world\",\"l\"\n hel...
{"fn_name": "string_merge", "inputs": [["hello", "world", "l"], ["coding", "anywhere", "n"], ["jason", "samson", "s"], ["wonderful", "people", "e"], ["person", "here", "e"], ["apowiejfoiajsf", "iwahfeijouh", "j"], ["abcdefxxxyzz", "abcxxxyyyxyzz", "x"], ["12345654321", "123456789", "6"], ["JiOdIdA4", "oopopopoodddasdfd...
introductory
https://www.codewars.com/kata/597bb84522bc93b71e00007e
def string_merge(string1, string2, letter):
3,373
Write a function that accepts two square (`NxN`) matrices (two dimensional arrays), and returns the product of the two. Only square matrices will be given. How to multiply two square matrices: We are given two matrices, A and B, of size 2x2 (note: tests are not limited to 2x2). Matrix C, the solution, will be equal ...
["from numpy import matrix\n\ndef matrix_mult(a, b):\n return ( matrix(a) * matrix(b) ).tolist()", "def matrix_mult(a, b):\n return [[sum(a[i][k]*b[k][j] for k in range(len(a))) for j in range(len(a))] for i in range(len(a))]", "import numpy as np\ndef matrix_mult(a, b):\n return np.dot(a,b).tolist()", "def matrix_m...
{"fn_name": "matrix_mult", "inputs": [[[[1, 2], [3, 2]], [[3, 2], [1, 1]]], [[[9, 7], [0, 1]], [[1, 1], [4, 12]]], [[[1, 2, 3], [3, 2, 1], [2, 1, 3]], [[4, 5, 6], [6, 5, 4], [4, 6, 5]]]], "outputs": [[[[5, 4], [11, 8]]], [[[37, 93], [4, 12]]], [[[28, 33, 29], [28, 31, 31], [26, 33, 31]]]]}
introductory
https://www.codewars.com/kata/5263a84ffcadb968b6000513
def matrix_mult(a, b):
3,374
You certainly can tell which is the larger number between 2^(10) and 2^(15). But what about, say, 2^(10) and 3^(10)? You know this one too. Things tend to get a bit more complicated with **both** different bases and exponents: which is larger between 3^(9) and 5^(6)? Well, by now you have surely guessed that you hav...
["from math import log\n\ndef compare_powers(*numbers):\n a,b = map(lambda n: n[1]*log(n[0]), numbers)\n return (a<b) - (a>b)", "from math import log\ndef compare_powers(n1, n2):\n val = n2[1] * log(n2[0]) - n1[1] * log(n1[0])\n return -1 if val < 0 else 1 if val > 0 else 0", "from math import log\n\ndef compar...
{"fn_name": "compare_powers", "inputs": [[[2, 10], [2, 15]], [[1, 10], [3, 10]], [[2, 10], [2, 10]], [[3, 9], [1, 6]], [[1, 7], [1, 8]], [[2, 100], [2, 150]], [[2, 100], [3, 100]], [[2, 100], [2, 100]], [[34, 98], [51, 67]], [[1024, 97], [1024, 81]]], "outputs": [[1], [1], [0], [-1], [0], [1], [1], [0], [-1], [-1]]}
introductory
https://www.codewars.com/kata/55b2549a781b5336c0000103
def compare_powers(n1,n2):
3,375
Consider the following numbers (where `n!` is `factorial(n)`): ``` u1 = (1 / 1!) * (1!) u2 = (1 / 2!) * (1! + 2!) u3 = (1 / 3!) * (1! + 2! + 3!) ... un = (1 / n!) * (1! + 2! + 3! + ... + n!) ``` Which will win: `1 / n!` or `(1! + 2! + 3! + ... + n!)`? Are these numbers going to `0` because of `1/n!` or to infinity du...
["def going(n): \n s = 1.0\n for i in range(2, n + 1):\n s = s/i + 1\n return int(s * 1e6) / 1e6", "def going(n):\n factor = 1.0\n acc = 1.0\n for i in range(n, 1, -1):\n factor *= 1.0 / i\n acc += factor\n return int(acc * 1e6) / 1e6", "def going(n):\n a = 1.\n for i in...
{"fn_name": "going", "inputs": [[5], [6], [7], [8], [20], [30], [50], [113], [200], [523], [1011], [10110]], "outputs": [[1.275], [1.2125], [1.173214], [1.146651], [1.052786], [1.034525], [1.020416], [1.008929], [1.005025], [1.001915], [1.00099], [1.000098]]}
introductory
https://www.codewars.com/kata/55a29405bc7d2efaff00007c
def going(n):
3,376
The squarefree part of a positive integer is the largest divisor of that integer which itself has no square factors (other than 1). For example, the squareefree part of 12 is 6, since the only larger divisor is 12, and 12 has a square factor (namely, 4). Your challenge, should you choose to accept it, is to implement ...
["def square_free_part(n):\n if type(n) != int or n < 1:return None\n for i in xrange(2, int(n ** 0.5) + 1):\n while n % (i ** 2) == 0:\n n /= i\n return n", "def square_free_part(n):\n\n fac = lambda n: [i for i in range(2, (n//2)+1) if n % i == 0] + [n]\n issquare = lambda n: True if ...
{"fn_name": "square_free_part", "inputs": [[0], [-100], [2.5]], "outputs": [[null], [null], [null]]}
introductory
https://www.codewars.com/kata/567cd7da4b9255b96b000022
def square_free_part(n):
3,377
Given time in 24-hour format, convert it to words. ``` For example: 13:00 = one o'clock 13:09 = nine minutes past one 13:15 = quarter past one 13:29 = twenty nine minutes past one 13:30 = half past one 13:31 = twenty nine minutes to two 13:45 = quarter to two 00:48 = twelve minutes to one 00:08 = eight minutes p...
["def solve(time):\n def number(n):\n if n > 20: return \"twenty {}\".format(number(n - 20))\n return [\n None, \"one\", \"two\", \"three\", \"four\",\n \"five\", \"six\", \"seven\", \"eight\", \"nine\",\n \"ten\", \"eleven\", \"twelve\", \"thirteen\",\n \"fo...
{"fn_name": "solve", "inputs": [["13:00"], ["13:09"], ["13:15"], ["13:29"], ["13:30"], ["13:31"], ["13:45"], ["13:59"], ["00:48"], ["00:08"], ["12:00"], ["00:00"], ["19:01"], ["07:01"], ["01:59"], ["12:01"], ["00:01"], ["11:31"], ["23:31"], ["11:45"], ["11:59"], ["23:45"], ["23:59"], ["01:45"]], "outputs": [["one o'clo...
introductory
https://www.codewars.com/kata/5c2b4182ac111c05cf388858
def solve(time):
3,378
For building the encrypted string:Take every 2nd char from the string, then the other chars, that are not every 2nd char, and concat them as new String. Do this n times! Examples: ``` "This is a test!", 1 -> "hsi etTi sats!" "This is a test!", 2 -> "hsi etTi sats!" -> "s eT ashi tist!" ``` Write two methods: ```pyt...
["def decrypt(text, n):\n if text in (\"\", None):\n return text\n \n ndx = len(text) // 2\n\n for i in range(n):\n a = text[:ndx]\n b = text[ndx:]\n text = \"\".join(b[i:i+1] + a[i:i+1] for i in range(ndx + 1))\n return text\n\n\n\ndef encrypt(text, n):\n for i in range(n)...
{"fn_name": "decrypt", "inputs": [["This is a test!", 0], ["hsi etTi sats!", 1], ["s eT ashi tist!", 2], [" Tah itse sits!", 3], ["This is a test!", 4], ["This is a test!", -1], ["hskt svr neetn!Ti aai eyitrsig", 1], ["", 0], [null, 0]], "outputs": [["This is a test!"], ["This is a test!"], ["This is a test!"], ["This...
introductory
https://www.codewars.com/kata/57814d79a56c88e3e0000786
def decrypt(text, n):
3,379
You have been recruited by an unknown organization for your cipher encrypting/decrypting skills. Being new to the organization they decide to test your skills. Your first test is to write an algorithm that encrypts the given string in the following steps. 1. The first step of the encryption is a standard ROT13 cip...
["def encrypter(strng):\n return ''.join( c if c==' ' else chr(122 - ((ord(c)-97)+13) % 26) for c in strng )", "from string import ascii_lowercase as abc\n\ndef encrypter(strng):\n return strng.translate(str.maketrans(abc[::-1], abc[13:] + abc[:13]))", "def encrypter(strng):\n z={0:'m',1:'l',2:'k',3:'j',4:'i',...
{"fn_name": "encrypter", "inputs": [["amz"], ["welcome to the organization"], ["hello"], ["my name is"], ["goodbye"]], "outputs": [["man"], ["qibkyai ty tfi yvgmzenmteyz"], ["fibby"], ["ao zmai eu"], ["gyyjloi"]]}
introductory
https://www.codewars.com/kata/56fb3cde26cc99c2fd000009
def encrypter(strng):
3,380
The look and say sequence is a sequence in which each number is the result of a "look and say" operation on the previous element. Considering for example the classical version startin with `"1"`: `["1", "11", "21, "1211", "111221", ...]`. You can see that the second element describes the first as `"1(times number)1"`,...
["from re import sub\n\ndef look_and_say_sequence(s, n):\n for _ in range(1, n):\n s = sub(r'(.)\\1*', lambda m: str(len(m.group(0))) + m.group(1), s)\n return s", "def look_and_say_sequence(first, n): \n result = first\n \n for _ in range(n-1):\n \n sequence = result\n result ...
{"fn_name": "look_and_say_sequence", "inputs": [["1", 1], ["1", 3], ["1", 5], ["22", 10], ["14", 2]], "outputs": [["1"], ["21"], ["111221"], ["22"], ["1114"]]}
introductory
https://www.codewars.com/kata/592421cb7312c23a990000cf
def look_and_say_sequence(first_element, n):
3,381
Americans are odd people: in their buildings, the first floor is actually the ground floor and there is no 13th floor (due to superstition). Write a function that given a floor in the american system returns the floor in the european system. With the 1st floor being replaced by the ground floor and the 13th floor bei...
["def get_real_floor(n):\n if n <= 0: return n\n if n < 13: return n-1\n if n > 13: return n-2", "def get_real_floor(n):\n return n if n < 1 else n - 1 if n < 13 else n - 2", "def get_real_floor(n):\n return n - (1 if n < 13 else 2) if n > 0 else n", "def get_real_floor(n):\n return n - (n > 0) - (n >...
{"fn_name": "get_real_floor", "inputs": [[1], [0], [5], [10], [12], [14], [15], [37], [200], [-2], [-5]], "outputs": [[0], [0], [4], [9], [11], [12], [13], [35], [198], [-2], [-5]]}
introductory
https://www.codewars.com/kata/574b3b1599d8f897470018f6
def get_real_floor(n):
3,382
Your task is simply to count the total number of lowercase letters in a string. ## Examples
["def lowercase_count(strng):\n return sum(a.islower() for a in strng)\n", "import re\ndef lowercase_count(string):\n return len(re.findall('[a-z]',string))", "def lowercase_count(str):\n return sum(1 for c in str if c.islower())", "def lowercase_count(strng):\n return len([ch for ch in strng if ch.islower(...
{"fn_name": "lowercase_count", "inputs": [["abc"], ["abcABC123"], ["abcABC123!@#$%^&*()_-+=}{[]|':;?/>.<,~"], [""], ["ABC123!@#$%^&*()_-+=}{[]|':;?/>.<,~"], ["abcdefghijklmnopqrstuvwxyz"]], "outputs": [[3], [3], [3], [0], [0], [26]]}
introductory
https://www.codewars.com/kata/56a946cd7bd95ccab2000055
def lowercase_count(strng):
3,383
Is the number even? If the numbers is even return `true`. If it's odd, return `false`. Oh yeah... the following symbols/commands have been disabled! use of ```%``` use of ```.even?``` in Ruby use of ```mod``` in Python
["def is_even(n):\n return not n & 1", "def is_even(n):\n return n // 2 * 2 == n", "def is_even(n): return n & 1 == 0 \n", "def is_even(n):\n return n/2 == int(n/2)", "def is_even(n):\n return str(n)[-1] in '02468'", "is_even=lambda n: n|1!=n", "def is_even(n):\n return str(bin(n)[2:])[-1] == '0'", "def ...
{"fn_name": "is_even", "inputs": [[2], [3], [14], [15], [26], [27]], "outputs": [[true], [false], [true], [false], [true], [false]]}
introductory
https://www.codewars.com/kata/592a33e549fe9840a8000ba1
def is_even(n):
3,384
General primality test are often computationally expensive, so in the biggest prime number race the idea is to study special sub-families of prime number and develop more effective tests for them. [Mersenne Primes](https://en.wikipedia.org/wiki/Mersenne_prime) are prime numbers of the form: Mn = 2^(n) - 1. So far, 49...
["def lucas_lehmer(n):\n return n in [2, 3, 5, 7, 13, 17, 19, 31, 61, 89, 107, 127, 521, 607, 1279,\n 2203, 2281, 3217, 4253, 4423, 9689, 9941, 11213, 19937, 21701,\n 23209, 44497, 86243, 110503, 132049, 216091, 756839, 859433,\n 1257787, 1398269, 2976221, 3021377, 697...
{"fn_name": "lucas_lehmer", "inputs": [[2], [3], [4], [5], [7], [10], [33], [101], [11213], [11215]], "outputs": [[true], [true], [false], [true], [true], [false], [false], [false], [true], [false]]}
introductory
https://www.codewars.com/kata/5416fac7932c1dcc4f0006b4
def lucas_lehmer(n):
3,385
Find the longest substring in alphabetical order. Example: the longest alphabetical substring in `"asdfaaaabbbbcttavvfffffdf"` is `"aaaabbbbctt"`. There are tests with strings up to `10 000` characters long so your code will need to be efficient. The input will only consist of lowercase characters and will be at lea...
["import re\n\nreg = re.compile('a*b*c*d*e*f*g*h*i*j*k*l*m*n*o*p*q*r*s*t*u*v*w*x*y*z*')\n\ndef longest(s):\n return max(reg.findall(s), key=len)", "def longest(string):\n start = 0\n longest = string[0:1]\n length = len(string)\n for i in range(1, length):\n if string[i] < string[i - 1] or i == le...
{"fn_name": "longest", "inputs": [["asd"], ["nab"], ["abcdeapbcdef"], ["asdfaaaabbbbcttavvfffffdf"], ["asdfbyfgiklag"], ["z"], ["zyba"]], "outputs": [["as"], ["ab"], ["abcde"], ["aaaabbbbctt"], ["fgikl"], ["z"], ["z"]]}
introductory
https://www.codewars.com/kata/5a7f58c00025e917f30000f1
def longest(s):
3,386
Hi there! You have to implement the `String get_column_title(int num) // syntax depends on programming language` function that takes an integer number (index of the Excel column) and returns the string represents the title of this column. #Intro In the MS Excel lines are numbered by decimals, columns - by sets of ...
["from string import ascii_uppercase as u\n\ndef get_column_title(n):\n assert isinstance(n, int) and n > 0\n col = []\n while n:\n n, r = divmod(n-1, 26)\n col.append(u[r])\n return ''.join(reversed(col))", "upper = __import__(\"string\").ascii_uppercase.__getitem__\n\ndef get_column_title(nu...
{"fn_name": "get_column_title", "inputs": [[1], [26], [52], [53], [702]], "outputs": [["A"], ["Z"], ["AZ"], ["BA"], ["ZZ"]]}
introductory
https://www.codewars.com/kata/56d082c24f60457198000e77
def get_column_title(num):
3,387
What's in a name? ..Or rather, what's a name in? For us, a particular string is where we are looking for a name. Task Test whether or not the string contains all of the letters which spell a given name, in order. The format A function passing two strings, searching for one (the name) within the other. ``function nam...
["def name_in_str(str, name):\n it = iter(str.lower())\n return all(c in it for c in name.lower())", "def name_in_str(text, name):\n for c in text.lower():\n if c == name[0].lower():\n name = name[1:]\n if not name:\n return True\n return False", "def name_in_str(...
{"fn_name": "name_in_str", "inputs": [["Across the rivers", "chris"], ["Next to a lake", "chris"], ["Under a sea", "chris"], ["A crew that boards the ship", "chris"], ["A live son", "Allison"], ["Just enough nice friends", "Jennifer"], ["thomas", "Thomas"], ["pippippi", "Pippi"], ["pipipp", "Pippi"], ["ppipip", "Pippi"...
introductory
https://www.codewars.com/kata/59daf400beec9780a9000045
def name_in_str(str, name):
3,388
Write a function that takes in a binary string and returns the equivalent decoded text (the text is ASCII encoded). Each 8 bits on the binary string represent 1 character on the ASCII table. The input string will always be a valid binary string. Characters can be in the range from "00000000" to "11111111" (inclusive...
["def binary_to_string(binary):\n return \"\".join( [ chr( int(binary[i: i+8], 2) ) for i in range(0, len(binary), 8) ] )", "def binary_to_string(binary):\n return \"\".join(chr(int(binary[i:i+8],2)) for i in range(0,len(binary),8))\n", "def binary_to_string(binary):\n result = \"\"\n \n while binary:\n ...
{"fn_name": "binary_to_string", "inputs": [[""], ["0100100001100101011011000110110001101111"], ["00110001001100000011000100110001"], ["01010011011100000110000101110010011010110111001100100000011001100110110001100101011101110010111000101110001000000110010101101101011011110111010001101001011011110110111001110011001000000...
introductory
https://www.codewars.com/kata/5583d268479559400d000064
def binary_to_string(binary):
3,389
Write a function that when given a URL as a string, parses out just the domain name and returns it as a string. For example: ```python domain_name("http://github.com/carbonfive/raygun") == "github" domain_name("http://www.zombie-bites.com") == "zombie-bites" domain_name("https://www.cnet.com") == "cnet" ```
["def domain_name(url):\n return url.split(\"//\")[-1].split(\"www.\")[-1].split(\".\")[0]", "import re\ndef domain_name(url):\n return re.search('(https?://)?(www\\d?\\.)?(?P<name>[\\w-]+)\\.', url).group('name')\n", "def domain_name(url):\n url = url.replace('www.','')\n url = url.replace('https://','')\n...
{"fn_name": "domain_name", "inputs": [["http://google.com"], ["http://google.co.jp"], ["https://123.net"], ["https://hyphen-site.org"], ["http://codewars.com"], ["www.xakep.ru"], ["https://youtube.com"], ["http://www.codewars.com/kata/"], ["icann.org"]], "outputs": [["google"], ["google"], ["123"], ["hyphen-site"], ["c...
introductory
https://www.codewars.com/kata/514a024011ea4fb54200004b
def domain_name(url):
3,390
A [Narcissistic Number](https://en.wikipedia.org/wiki/Narcissistic_number) is a positive number which is the sum of its own digits, each raised to the power of the number of digits in a given base. In this Kata, we will restrict ourselves to decimal (base 10). For example, take 153 (3 digits): ``` 1^3 + 5^3 + 3^3 ...
["def narcissistic(value):\n return value == sum(int(x) ** len(str(value)) for x in str(value))", "def narcissistic( value ):\n value = str(value)\n size = len(value)\n sum = 0\n for i in value:\n sum += int(i) ** size\n return sum == int(value)", "def narcissistic(value):\n return bool(valu...
{"fn_name": "narcissistic", "inputs": [[1], [5], [7], [153], [370], [371], [1634]], "outputs": [[true], [true], [true], [true], [true], [true], [true]]}
introductory
https://www.codewars.com/kata/5287e858c6b5a9678200083c
def narcissistic( value ):
3,391
For this exercise you will create a global flatten method. The method takes in any number of arguments and flattens them into a single array. If any of the arguments passed in are an array then the individual objects within the array will be flattened so that they exist at the same level as the other arguments. Any nes...
["def flatten(*a):\n r = []\n for x in a:\n if isinstance(x, list):\n r.extend(flatten(*x))\n else:\n r.append(x)\n return r", "def flatten(*args):\n return [x for a in args for x in (flatten(*a) if isinstance(a, list) else [a])]", "def flatten(*args):\n \n def _fla...
{"fn_name": "flatten", "inputs": [[1, 2, 3], [1, 2], [5, "string"], [-4.5, -3, 1, 4], [[3, 4, 5], [1, 2, 3]], [[1], [], 2, [4, 5, 6]], [[4, "string", 9, 3, 1], [], [], [], [], ["string"]], [1, 2, ["9", [], []], null], [[1, 2], [3, 4, 5], [6, [7], [[8]]]], [["hello", 2, ["text", [4, 5]]], [[]], "[list]"]], "outputs": [[...
introductory
https://www.codewars.com/kata/513fa1d75e4297ba38000003
def flatten(*args):
3,392
Create a function `sierpinski` to generate an ASCII representation of a Sierpinski triangle of order **N**. Seperate each line with `\n`. You don't have to check the input value. The output should look like this: sierpinski(4) * * * ...
["def sierpinski(n):\n t = ['*']\n for _ in range(n):\n t = [r.center(2*len(t[-1])+1) for r in t] + [r + ' ' + r for r in t]\n return '\\n'.join(t)", "def sierpinski(n):\n lines = [\"*\"]\n for i in range(2, n+2):\n lines = [l.center(2**i - 1) for l in lines] + [f\"{l} {l}\" for l in lines]...
{"fn_name": "sierpinski", "inputs": [[1], [2], [3]], "outputs": [[" * \n* *"], [" * \n * * \n * * \n* * * *"], [" * \n * * \n * * \n * * * * \n * * \n * * * * \n * * * * \n* * * * * * * *"]]}
introductory
https://www.codewars.com/kata/58add662ea140541a50000f7
def sierpinski(n):
3,393
Divisors of 42 are : 1, 2, 3, 6, 7, 14, 21, 42. These divisors squared are: 1, 4, 9, 36, 49, 196, 441, 1764. The sum of the squared divisors is 2500 which is 50 * 50, a square! Given two integers m, n (1 <= m <= n) we want to find all integers between m and n whose sum of squared divisors is itself a square. 42 is su...
["CACHE = {}\n\ndef squared_cache(number):\n if number not in CACHE:\n divisors = [x for x in range(1, number + 1) if number % x == 0]\n CACHE[number] = sum([x * x for x in divisors])\n return CACHE[number] \n \n return CACHE[number]\n\ndef list_squared(m, n):\n ret = []\n\n for numb...
{"fn_name": "list_squared", "inputs": [[1, 250], [42, 250], [250, 500], [300, 600], [600, 1500], [1500, 1800], [1800, 2000], [2000, 2200], [2200, 5000], [5000, 10000]], "outputs": [[[[1, 1], [42, 2500], [246, 84100]]], [[[42, 2500], [246, 84100]]], [[[287, 84100]]], [[]], [[[728, 722500], [1434, 2856100]]], [[[1673, 28...
introductory
https://www.codewars.com/kata/55aa075506463dac6600010d
def list_squared(m, n):
3,394
The Collatz Conjecture states that for any natural number n, if n is even, divide it by 2. If n is odd, multiply it by 3 and add 1. If you repeat the process continuously for n, n will eventually reach 1. For example, if n = 20, the resulting sequence will be: [20, 10, 5, 16, 8, 4, 2, 1] Write a program that will o...
["def collatz(n):\n step = 1\n while n!= 1:\n n = [n//2, (n*3)+1][n%2]\n step += 1\n return step\n\n\n", "from itertools import count\n\ndef collatz(n):\n for iteration in count(1):\n if n == 1:\n return iteration\n elif n % 2 == 0:\n n //= 2\n else:\n n...
{"fn_name": "collatz", "inputs": [[100], [10], [500], [73567465519280238573], [1000000000], [1000000000000000]], "outputs": [[26], [7], [111], [362], [101], [276]]}
introductory
https://www.codewars.com/kata/54fb963d3fe32351f2000102
def collatz(n):
3,395
Your task is to remove all duplicate words from a string, leaving only single (first) words entries. Example: Input: 'alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta' Output: 'alpha beta gamma delta'
["def remove_duplicate_words(s):\n return ' '.join(dict.fromkeys(s.split()))", "def remove_duplicate_words(s):\n s = s.split(\" \")\n words = []\n for item in s:\n if item not in words:\n words.append(item)\n return \" \".join(words)\n", "def remove_duplicate_words(s):\n return ' '.j...
{"fn_name": "remove_duplicate_words", "inputs": [["alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta"], ["my cat is my cat fat"]], "outputs": [["alpha beta gamma delta"], ["my cat is fat"]]}
introductory
https://www.codewars.com/kata/5b39e3772ae7545f650000fc
def remove_duplicate_words(s):
3,396
Write a function that accepts two square matrices (`N x N` two dimensional arrays), and return the sum of the two. Both matrices being passed into the function will be of size `N x N` (square), containing only integers. How to sum two matrices: Take each cell `[n][m]` from the first matrix, and add it with the same `...
["import numpy as np\ndef matrix_addition(a, b):\n return(np.mat(a)+np.mat(b)).tolist()", "def matrix_addition(a, b):\n for row in range(len(a)):\n for index in range(len(a)):\n a[row][index] += b[row][index]\n return a\n", "def matrix_addition(a, b):\n return [[sum(xs) for xs in zip(ra, r...
{"fn_name": "matrix_addition", "inputs": [[[[1, 2, 3], [3, 2, 1], [1, 1, 1]], [[2, 2, 1], [3, 2, 3], [1, 1, 3]]], [[[1, 2], [1, 2]], [[2, 3], [2, 3]]], [[[1]], [[2]]]], "outputs": [[[[3, 4, 4], [6, 4, 4], [2, 2, 4]]], [[[3, 5], [3, 5]]], [[[3]]]]}
introductory
https://www.codewars.com/kata/526233aefd4764272800036f
def matrix_addition(a, b):
3,397
# Introduction A grille cipher was a technique for encrypting a plaintext by writing it onto a sheet of paper through a pierced sheet (of paper or cardboard or similar). The earliest known description is due to the polymath Girolamo Cardano in 1550. His proposal was for a rectangular stencil allowing single letters, ...
["def grille(msg, code):\n return ''.join(msg[-1-i] for i,c in enumerate(bin(code)[::-1]) if c == '1' and i < len(msg))[::-1]", "def grille(message, code):\n binary = bin(code)[2:][-len(message):].zfill(len(message))\n return ''.join(char for char, code in zip(message, binary) if code == '1')", "def grille(m, ...
{"fn_name": "grille", "inputs": [["abcdef", 5], ["", 5], ["abcd", 1], ["0abc", 2], ["ab", 255], ["ab", 256], ["abcde", 32], ["tcddoadepwweasresd", 77098]], "outputs": [["df"], [""], ["d"], ["b"], ["ab"], [""], [""], ["codewars"]]}
introductory
https://www.codewars.com/kata/595b3f0ad26b2d817400002a
def grille(message, code):
3,398
In this Kata, we define an arithmetic progression as a series of integers in which the differences between adjacent numbers are the same. You will be given an array of ints of `length > 2` and your task will be to convert it into an arithmetic progression by the following rule: ```Haskell For each element there are exa...
["def solve(arr):\n res = []\n for first in (arr[0]-1, arr[0], arr[0]+1):\n for second in (arr[1]-1, arr[1], arr[1]+1):\n val, step, count = second, second-first, abs(arr[0]-first) + abs(arr[1]-second)\n for current in arr[2:]:\n val += step\n if abs(val-...
{"fn_name": "solve", "inputs": [[[1, 1, 3, 5, 6, 5]], [[2, 1, 2]], [[1, 2, 3]], [[1, 1, 10]], [[24, 21, 14, 10]], [[3, 2, 1, 1, 1]], [[1, 3, 6, 9, 12]], [[0, 0, 0, 0, 0]], [[5, 4, 3, 2, 1, 1]], [[1, 2, 1]], [[1, 2, 3, 1, 1]], [[1, 3, 6, 8, 10]], [[5, 6, 5, 3, 1, 1]]], "outputs": [[4], [1], [0], [-1], [3], [4], [1], [0]...
introductory
https://www.codewars.com/kata/5b77b030f0aa5c9114000024
def solve(arr):
3,399
In this kata you will be given a random string of letters and tasked with returning them as a string of comma-separated sequences sorted alphabetically, with each sequence starting with an uppercase character followed by `n-1` lowercase characters, where `n` is the letter's alphabet position `1-26`. ## Example ```pyt...
["def alpha_seq(s):\n return \",\".join( (c * (ord(c)-96)).capitalize() for c in sorted(s.lower()) )", "def alpha_seq(string):\n alpha = 'abcdefghijklmnopqrstuvwxyz'\n output = ''\n for s in ''.join(sorted((string.lower()))):\n output += s.upper()\n output += s * alpha.find(s)\n output ...
{"fn_name": "alpha_seq", "inputs": [["BfcFA"], ["ZpglnRxqenU"], ["NyffsGeyylB"], ["MjtkuBovqrU"], ["EvidjUnokmM"], ["HbideVbxncC"]], "outputs": [["A,Bb,Ccc,Ffffff,Ffffff"], ["Eeeee,Ggggggg,Llllllllllll,Nnnnnnnnnnnnnn,Nnnnnnnnnnnnnn,Pppppppppppppppp,Qqqqqqqqqqqqqqqqq,Rrrrrrrrrrrrrrrrrr,Uuuuuuuuuuuuuuuuuuuuu,Xxxxxxxxxxxx...
introductory
https://www.codewars.com/kata/5bd00c99dbc73908bb00057a
def alpha_seq(string):
3,400
Given an `array` of digital numbers, return a new array of length `number` containing the last even numbers from the original array (in the same order). The original array will be not empty and will contain at least "number" even numbers. For example: ``` ([1, 2, 3, 4, 5, 6, 7, 8, 9], 3) => [4, 6, 8] ([-22, 5, 3, 11, ...
["def even_numbers(arr,n):\n return [i for i in arr if i % 2 == 0][-n:] ", "def even_numbers(arr, n):\n result = []\n a = list(reversed(arr))\n for number in a:\n if n == 0:\n break\n if number % 2 == 0:\n result.append(number)\n n -= 1\n return list(reverse...
{"fn_name": "even_numbers", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9], 3], [[-22, 5, 3, 11, 26, -6, -7, -8, -9, -8, 26], 2], [[6, -25, 3, 7, 5, 5, 7, -3, 23], 1]], "outputs": [[[4, 6, 8]], [[-8, 26]], [[6]]]}
introductory
https://www.codewars.com/kata/5a431c0de1ce0ec33a00000c
def even_numbers(arr,n):
3,401
With one die of 6 sides we will have six different possible results:``` 1, 2, 3, 4, 5, 6``` . With 2 dice of six sides, we will have 36 different possible results: ``` (1,1),(1,2),(2,1),(1,3),(3,1),(1,4),(4,1),(1,5), (5,1), (1,6),(6,1),(2,2),(2,3),(3,2),(2,4),(4,2), (2,5),(5,2)(2,6),(6,2),(3,3),(3,4),(4,3),(3,5),(5,...
["import numpy as np\n\ndef products(n, min_divisor, max_divisor): \n if n == 1:\n yield []\n for divisor in range(min_divisor, max_divisor+1):\n if n % divisor == 0:\n for product in products(n // divisor, divisor, max_divisor):\n yield product + [divisor] \n\ndef eq_...
{"fn_name": "eq_dice", "inputs": [[[6, 6]], [[5, 6, 4]], [[3, 15, 8, 20]], [[6]], [[3, 3]], [[20]], [[3, 6]]], "outputs": [[3], [5], [44], [0], [0], [1], [0]]}
introductory
https://www.codewars.com/kata/5b26047b9e40b9f4ec00002b
def eq_dice(set_):
3,402
**Debug** a function called calculate that takes 3 values. The first and third values are numbers. The second value is a character. If the character is "+" , "-", "\*", or "/", the function will return the result of the corresponding mathematical function on the two numbers. If the string is not one of the specified ch...
["from operator import add, sub, mul, truediv\nD = {'+':add, '-':sub, '*':mul, '/':truediv}\n\ndef calculate(a, o, b):\n try: return D[o](a, b)\n except: pass", "def calculate(a, o, b):\n result = 0\n if(o == \"+\"):\n return a + b\n elif(o == \"-\"):\n return a - b\n elif(o == \"/\" and...
{"fn_name": "calculate", "inputs": [[2, "+", 4], [6, "-", 1.5], [-4, "*", 8], [49, "/", -7], [8, "m", 2], [4, "/", 0], [3.2, "+", 8], [3.2, "-", 8], [3.2, "/", 8], [3.2, "*", 8], [-3, "+", 0], [-3, "-", 0], [-3, "/", 0], [-2, "/", -2], [-2, "codewars", -2], [-3, "*", 0], [0, "*", 0], [0, "**", 0], [-3, "w", 0], [0, "/"...
introductory
https://www.codewars.com/kata/56368f37d464c0a43c00007f
def calculate(a, o, b):
3,403
This kata focuses on the Numpy python package and you can read up on the Numpy array manipulation functions here: https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.array-manipulation.html You will get two integers `N` and `M`. You must return an array with two sub-arrays with numbers in ranges `[0, N / 2)` an...
["import numpy as np\n\n\ndef reorder(a, b):\n return np.roll(np.arange(a).reshape(2, -1), b, 1).tolist()\n", "from collections import deque\n\n\ndef reorder(n, m):\n a, b = deque(range(n // 2)), deque(range(n // 2, n))\n a.rotate(m)\n b.rotate(m)\n return [list(a), list(b)]", "# Numpy?\n# https://media....
{"fn_name": "reorder", "inputs": [[10, 1], [10, 3], [10, 97]], "outputs": [[[[4, 0, 1, 2, 3], [9, 5, 6, 7, 8]]], [[[2, 3, 4, 0, 1], [7, 8, 9, 5, 6]]], [[[3, 4, 0, 1, 2], [8, 9, 5, 6, 7]]]]}
introductory
https://www.codewars.com/kata/5a48fab7bdb9b5b3690009b6
def reorder(a, b):
3,404
In this Kata, you will be given a string and two indexes (`a` and `b`). Your task is to reverse the portion of that string between those two indices inclusive. ~~~if-not:fortran ``` solve("codewars",1,5) = "cawedors" -- elements at index 1 to 5 inclusive are "odewa". So we reverse them. solve("cODEWArs", 1,5) = "cAWE...
["def solve(s,a,b):\n return s[:a]+s[a:b+1][::-1]+s[b+1:]", "def solve(st,a,b):\n return st[:a]+st[a:b+1][::-1]+ st[b+1:]", "def solve(st,a,b):\n return f'{st[:a]}{st[a : b + 1][::-1]}{st[b + 1 :]}'", "def solve(st,a,b):\n sub, rev = st[a:b+1], st[a:b+1][::-1]\n return st.replace(sub, rev)", "def solve(s...
{"fn_name": "solve", "inputs": [["codewars", 1, 5], ["codingIsFun", 2, 100], ["FunctionalProgramming", 2, 15], ["abcefghijklmnopqrstuvwxyz", 0, 20], ["abcefghijklmnopqrstuvwxyz", 5, 20]], "outputs": [["cawedors"], ["conuFsIgnid"], ["FuargorPlanoitcnmming"], ["vutsrqponmlkjihgfecbawxyz"], ["abcefvutsrqponmlkjihgwxyz"]]}
introductory
https://www.codewars.com/kata/5a8d1c82373c2e099d0000ac
def solve(st,a,b):
3,405
A **pandigital number** is one that has its digits from ```1``` to ```9``` occuring only once (they do not have the digit 0). The number ```169```, is the first pandigital square, higher than ```100```, having its square root, ```13```, pandigital too. The number ```1728``` is the first pandigital cubic, higher than ...
["def is_pandigital(n):\n s = str(n)\n return not '0' in s and len(set(s)) == len(s)\n\ndef pow_root_pandigit(val, n, k):\n res = []\n current = int(round(val ** (1.0 / n), 5)) + 1\n while len(res) < k and current <= 987654321 ** (1.0 / n):\n if is_pandigital(current):\n p = current ** ...
{"fn_name": "pow_root_pandigit", "inputs": [[388, 2, 3], [1750, 3, 5], [1728, 3, 4], [600000000, 2, 5], [900000000, 2, 5]], "outputs": [[[[23, 529], [24, 576], [25, 625]]], [[[13, 2197], [17, 4913], [18, 5832], [19, 6859], [21, 9261]]], [[[13, 2197], [17, 4913], [18, 5832], [19, 6859]]], [[25941, 672935481]], [[]]]}
introductory
https://www.codewars.com/kata/572a0fd8984419070e000491
def pow_root_pandigit(val, n, k):
3,406
Mutual Recursion allows us to take the fun of regular recursion (where a function calls itself until a terminating condition) and apply it to multiple functions calling each other! Let's use the Hofstadter Female and Male sequences to demonstrate this technique. You'll want to create two functions `F` and `M` such th...
["def f(n): return n - m(f(n-1)) if n else 1\n\ndef m(n): return n - f(m(n-1)) if n else 0", "def f(n):\n if n == 0:\n return 1\n return n - m(f(n - 1))\n\ndef m(n):\n if n == 0:\n return 0\n return n - f(m(n - 1))", "df={0:1}\ndm={0:0}\ndef f(n):\n if n in df: \n return df[n]\n e...
{"fn_name": "f", "inputs": [[0], [5], [10], [15], [25]], "outputs": [[1], [3], [6], [9], [16]]}
introductory
https://www.codewars.com/kata/53a1eac7e0afd3ad3300008b
def f(n):
3,407
Number is a palindrome if it is equal to the number with digits in reversed order. For example, 5, 44, 171, 4884 are palindromes and 43, 194, 4773 are not palindromes. Write a method `palindrome_chain_length` which takes a positive number and returns the number of special steps needed to obtain a palindrome. The speci...
["def palindrome_chain_length(n):\n steps = 0\n while str(n) != str(n)[::-1]:\n n = n + int(str(n)[::-1])\n steps += 1\n return steps", "def palindrome_chain_length(n, count=0):\n if str(n) == str(n)[::-1]: return count\n else: return palindrome_chain_length(n + int(str(n)[::-1]), count+1)"...
{"fn_name": "palindrome_chain_length", "inputs": [[87], [1], [88], [89], [10]], "outputs": [[4], [0], [0], [24], [1]]}
introductory
https://www.codewars.com/kata/525f039017c7cd0e1a000a26
def palindrome_chain_length(n):
3,408
## Check Digits Some numbers are more important to get right during data entry than others: a common example is product codes. To reduce the possibility of mistakes, product codes can be crafted in such a way that simple errors are detected. This is done by calculating a single-digit value based on the product number...
["from itertools import cycle\n\ndef add_check_digit(number):\n fact = cycle([2,3,4,5,6,7])\n r = sum( int(c) * next(fact) for c in number[::-1]) % 11\n return number + ('0' if not r else 'X' if r == 1 else str(11-r))", "from itertools import cycle\n\n\ndef add_check_digit(s):\n rem = 11 - sum(int(a) * b fo...
{"fn_name": "add_check_digit", "inputs": [["036532"], ["12388878"], ["111111111"], ["9735597355"], ["2356"], ["6789"]], "outputs": [["0365327"], ["123888782"], ["1111111118"], ["97355973550"], ["23566"], ["6789X"]]}
introductory
https://www.codewars.com/kata/568d1ee43ee6afb3ad00001d
def add_check_digit(number):
3,409
# Introduction Fish are an integral part of any ecosystem. Unfortunately, fish are often seen as high maintenance. Contrary to popular belief, fish actually reduce pond maintenance as they graze on string algae and bottom feed from the pond floor. They also make very enjoyable pets, providing hours of natural enterta...
["def fish(shoal):\n eaten, size, target = 0, 1, 4\n for f in sorted(map(int, shoal)):\n if f > size: break\n eaten += f\n if eaten >= target:\n size += 1\n target += 4 * size\n return size", "from collections import Counter\n\ndef fish(shoal):\n size, eaten = 1, 0...
{"fn_name": "fish", "inputs": [[""], ["0"], ["6"], ["1111"], ["11112222"], ["111122223333"], ["111111111111"], ["111111111111111111112222222222"], ["151128241212192113722321331"]], "outputs": [[1], [1], [1], [2], [3], [4], [3], [5], [5]]}
introductory
https://www.codewars.com/kata/5904be220881cb68be00007d
def fish(shoal):
3,410
# Task You got a `scratch lottery`, you want to know how much money you win. There are `6` sets of characters on the lottery. Each set of characters represents a chance to win. The text has a coating on it. When you buy the lottery ticket and then blow it off, you can see the text information below the coating. Each...
["def scratch(lottery):\n return sum(int(n) for lot in lottery for a,b,c,n in [lot.split()] if a==b==c)", "def scratch(lottery):\n return sum(int(i.split()[-1]) for i in lottery if len(set(i.split()))==2)", "def scratch(l):\n c = 0\n for i in l:\n i = i.split()\n if i[0] == i[1] == i[2]:\n ...
{"fn_name": "scratch", "inputs": [[["tiger tiger tiger 100", "rabbit dragon snake 100", "rat ox pig 1000", "dog cock sheep 10", "horse monkey rat 5", "dog dog dog 1000"]]], "outputs": [[1100]]}
introductory
https://www.codewars.com/kata/594a1822a2db9e93bd0001d4
def scratch(lottery):
3,411
The description is rather long but it tries to explain what a financing plan is. The fixed monthly payment for a fixed rate mortgage is the amount paid by the borrower every month that ensures that the loan is paid off in full with interest at the end of its term. The monthly payment formula is based on the annuit...
["def amort(rate, bal, term, num_payments):\n monthlyRate = rate / (12 * 100)\n c = bal * (monthlyRate * (1 + monthlyRate) ** term) / (((1 + monthlyRate) ** term) - 1)\n newBalance = bal\n for i in range(num_payments):\n interest = newBalance * monthlyRate\n princ = c - interest\n newBa...
{"fn_name": "amort", "inputs": [[7.4, 10215, 24, 20], [7.9, 107090, 48, 41], [6.8, 105097, 36, 4], [3.8, 48603, 24, 10], [1.9, 182840, 48, 18], [1.9, 19121, 48, 2], [2.2, 112630, 60, 11], [5.6, 133555, 60, 53], [9.8, 67932, 60, 34], [3.7, 64760, 36, 24], [4.6, 85591, 36, 5], [7.0, 168742, 48, 16], [9.6, 17897, 60, 23],...
introductory
https://www.codewars.com/kata/59c68ea2aeb2843e18000109
def amort(rate, bal, term, num_payments):
3,412
Every natural number, ```n```, may have a prime factorization like: We define the **geometric derivative of n**, as a number with the following value: For example: calculate the value of ```n*``` for ```n = 24500```. ``` 24500 = 2²5³7² n* = (2*2) * (3*5²) * (2*7) = 4200 ``` Make a function, ```f``` that can perfo...
["def f(n):\n res = 1\n i = 2\n while n != 1:\n k = 0\n while n % i == 0:\n k += 1\n n //= i\n if k != 0:\n res *= k * i**(k-1)\n i += 1\n return res", "def f(n):\n p, n_, m = 2, 1, int(n ** .5)\n while n > 1 and p <= m:\n k = 0\n ...
{"fn_name": "f", "inputs": [[24500], [997]], "outputs": [[4200], [1]]}
introductory
https://www.codewars.com/kata/572caa2672a38ba648001dcd
def f(n):
3,413
Finish the solution so that it sorts the passed in array of numbers. If the function passes in an empty array or null/nil value then it should return an empty array. For example: ```python solution([1,2,3,10,5]) # should return [1,2,3,5,10] solution(None) # should return [] ``` ```Hakell sortNumbers [1, 2, 10, 50, 5...
["def solution(nums):\n return sorted(nums) if nums else []", "solution = lambda l: sorted(l) if l else []\n", "def solution(nums):\n return sorted(nums or [])", "def solution(nums):\n return [] if nums is None else sorted(nums)", "def solution(nums):\n return sorted(nums) if isinstance(nums, list) else []"...
{"fn_name": "solution", "inputs": [[[1, 2, 3, 10, 5]], [null], [[]], [[20, 2, 10]], [[2, 20, 10]]], "outputs": [[[1, 2, 3, 5, 10]], [[]], [[]], [[2, 10, 20]], [[2, 10, 20]]]}
introductory
https://www.codewars.com/kata/5174a4c0f2769dd8b1000003
def solution(nums):
3,414
# Introduction: Reversi is a game usually played by 2 people on a 8x8 board. Here we're only going to consider a single 8x1 row. Players take turns placing pieces, which are black on one side and white on the other, onto the board with their colour facing up. If one or more of the opponents pieces are sandwiched by ...
["import re\ndef reversi_row(moves):\n row = '........'\n stones = '*O'\n for i, m in enumerate(moves):\n L, M, R = row[:m], stones[i%2], row[m+1:]\n if R!='' and R[0] == stones[(i+1)%2] and R.find(stones[i%2])>0 and '.' not in R[:R.find(stones[i%2])]:\n R = R.replace(stones[(i+1)%2], ...
{"fn_name": "reversi_row", "inputs": [[[]], [[0]], [[0, 1]], [[0, 7, 4]], [[3]], [[3, 4]], [[3, 4, 5]], [[2, 1, 0]], [[0, 1, 4, 3, 2]], [[0, 1, 7, 2, 3]], [[3, 2, 7, 1, 0]], [[3, 4, 5, 6, 0, 2]], [[0, 1, 2, 3, 4, 5, 6, 7]], [[7, 0, 1]], [[0, 7, 6]], [[1, 0, 2, 3, 4, 5, 6, 7]], [[5, 1, 3, 4, 6]], [[1, 7, 0, 5, 6, 4]]], ...
introductory
https://www.codewars.com/kata/55aa92a66f9adfb2da00009a
def reversi_row(moves):
3,415
# Task Given a string `str`, find the shortest possible string which can be achieved by adding characters to the end of initial string to make it a palindrome. # Example For `str = "abcdc"`, the output should be `"abcdcba"`. # Input/Output - `[input]` string `str` A string consisting of lowercase latin let...
["def build_palindrome(strng):\n n = 0\n while strng[n:] != strng[n:][::-1]: n += 1\n return strng + strng[:n][::-1]", "def build_palindrome(str):\n suf = \"\"\n for c in str:\n pal = str + suf\n if pal == pal[::-1]:\n return pal\n suf = c + suf", "def build_palindrome(s):...
{"fn_name": "build_palindrome", "inputs": [["abcdc"], ["ababab"]], "outputs": [["abcdcba"], ["abababa"]]}
introductory
https://www.codewars.com/kata/58942f9175f2c78f4b000108
def build_palindrome(s):
3,416
John is developing a system to report fuel usage but needs help with the coding. First, he needs you to write a function that, given the actual consumption (in l/100 km) and remaining amount of petrol (in l), will give you how many kilometers you'll be able to drive. Second, he needs you to write a function that, giv...
["def total_kilometers(cons, petrol):\n return round(100*petrol/cons, 2)\n\ndef check_distance(dist, cons, petrol):\n return (\"You will need to refuel\" if dist > total_kilometers(cons, petrol) else\n [ [n*100, dist-100*n, round(petrol-cons*n, 2)] for n in range(dist//100+1)])", "def total_kilometers(...
{"fn_name": "total_kilometers", "inputs": [[10, 60], [8, 0], [6.4, 54], [9.3, 87.3], [11.7, 63.4]], "outputs": [[600], [0], [843.75], [938.71], [541.88]]}
introductory
https://www.codewars.com/kata/55cb8b5ddd6a67fef7000070
def total_kilometers(cons, petrol):
3,417
# Task You are given `N` ropes, where the length of each rope is a positive integer. At each step, you have to reduce all the ropes by the length of the smallest rope. The step will be repeated until no ropes are left. Given the length of N ropes, print the number of ropes that are left before each step. # Example...
["def cut_the_ropes(arr):\n results = [len(arr)]\n while arr:\n m = min(arr)\n arr = [elem - m for elem in arr if elem != m]\n results.append(len(arr))\n return results[:-1]\n \n", "def cut_the_ropes(arr):\n qty = len(arr)\n sorted_ropes = sorted(arr)\n return [qty - sorted_rop...
{"fn_name": "cut_the_ropes", "inputs": [[[3, 3, 2, 9, 7]], [[1, 2, 3, 4, 3, 3, 2, 1]], [[13035, 6618, 13056, 20912, 1119, 13035, 6618, 6618, 8482, 13056]], [[9, 9, 9, 9, 7]]], "outputs": [[[5, 4, 2, 1]], [[8, 6, 4, 1]], [[10, 9, 6, 5, 3, 1]], [[5, 4]]]}
introductory
https://www.codewars.com/kata/58ad388555bf4c80e800001e
def cut_the_ropes(arr):
3,418
In this kata you will create a function that takes in a list and returns a list with the reverse order. ### Examples ```python reverse_list([1,2,3,4]) == [4,3,2,1] reverse_list([3,1,5,4]) == [4,5,1,3] ```
["def reverse_list(l):\n return l[::-1]", "def reverse_list(l):\n \"\"\"return a list with the reverse order of l\"\"\"\n return list(reversed(l))", "def reverse_list(l):\n l.reverse()\n return l", "def reverse_list(l):\n \"\"\" Returns reversed list. \"\"\"\n return list(reversed(l))", "def reverse_list(l):\n ...
{"fn_name": "reverse_list", "inputs": [[[1, 2, 3, 4]], [[3, 1, 5, 4]], [[3, 6, 9, 2]], [[1]]], "outputs": [[[4, 3, 2, 1]], [[4, 5, 1, 3]], [[2, 9, 6, 3]], [[1]]]}
introductory
https://www.codewars.com/kata/53da6d8d112bd1a0dc00008b
def reverse_list(l):
3,419
Write a function that will encrypt a given sentence into International Morse Code, both the input and out puts will be strings. Characters should be separated by a single space. Words should be separated by a triple space. For example, "HELLO WORLD" should return -> ".... . .-.. .-.. --- .-- --- .-. .-.. -.." To f...
["#CHAR_TO_MORSE preloaded to convert characters into Morse code\nCODE = {'A': '.-', 'B': '-...', 'C': '-.-.', \n 'D': '-..', 'E': '.', 'F': '..-.',\n 'G': '--.', 'H': '....', 'I': '..',\n 'J': '.---', 'K': '-.-', 'L': '.-..',\n 'M': '--', 'N': '-.', 'O': '---...
{"fn_name": "encryption", "inputs": [["HELLO WORLD"], ["SOS"], ["1836"], ["THE QUICK BROWN FOX"], ["JUMPED OVER THE"], ["LAZY DOG"], ["WOLFRAM ALPHA 1"], ["CodeWars Rocks"], [""], ["Final basic test"]], "outputs": [[".... . .-.. .-.. --- .-- --- .-. .-.. -.."], ["... --- ..."], [".---- ---.. ...-- -...."], ["- .... ....
introductory
https://www.codewars.com/kata/55b8c0276a7930249e00003c
def encryption(string):
3,420
# Task Given a sorted array of integers `A`, find such an integer x that the value of `abs(A[0] - x) + abs(A[1] - x) + ... + abs(A[A.length - 1] - x)` is the smallest possible (here abs denotes the `absolute value`). If there are several possible answers, output the smallest one. # Example For `A = [2, 4, 7]`, th...
["from statistics import median_low as absolute_values_sum_minimization", "def absolute_values_sum_minimization(A):\n d = {x: sum(abs(n-x) for n in A) for x in A}\n return min(d, key=lambda x: (d[x], x))", "import numpy as np\ndef absolute_values_sum_minimization(A):\n return np.median(A) if len(A) % 2 else A[le...
{"fn_name": "absolute_values_sum_minimization", "inputs": [[[2, 4, 7]], [[1, 1, 3, 4]], [[23]], [[-10, -10, -10, -10, -10, -9, -9, -9, -8, -8, -7, -6, -5, -4, -3, -2, -1, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37...
introductory
https://www.codewars.com/kata/589414918afa367b4800015c
def absolute_values_sum_minimization(A):
3,421
> 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 this Kata, we have to try to create a mysterious pattern. Given a positive integer `m`, you can generate a Fibonacci sequence with a length of `m`: ``...
["def mysterious_pattern(m, n):\n rows = [[' '] * m for _ in range(n)]\n a, b = 1, 1\n for i in range(m):\n rows[a % n][i] = 'o'\n a, b = b, a + b\n rows = [''.join(r).rstrip() for r in rows]\n return '\\n'.join(rows).strip('\\n')", "def genFib():\n a,b = 1,0\n while 1:\n yield...
{"fn_name": "mysterious_pattern", "inputs": [[5, 5], [12, 4], [4, 5], [10, 1]], "outputs": [[" o\noo\n o\n o"], [" o o\noo o oo o\n o o\n o o"], ["oo\n o\n o"], ["oooooooooo"]]}
introductory
https://www.codewars.com/kata/580ec64394291d946b0002a1
def mysterious_pattern(m, n):
3,422
Jamie is a programmer, and James' girlfriend. She likes diamonds, and wants a diamond string from James. Since James doesn't know how to make this happen, he needs your help. ## Task You need to return a string that looks like a diamond shape when printed on the screen, using asterisk (`*`) characters. Trailing space...
["def diamond(n):\n if n < 0 or n % 2 == 0:\n return None\n \n result = \"*\" * n + \"\\n\";\n spaces = 1;\n n = n - 2\n while n > 0:\n current = \" \" * spaces + \"*\" * n + \"\\n\"\n spaces = spaces + 1\n n = n - 2\n result = current + result + current\n \n r...
{"fn_name": "diamond", "inputs": [[3], [0], [2], [-1], [-2]], "outputs": [[" *\n***\n *\n"], [null], [null], [null], [null]]}
introductory
https://www.codewars.com/kata/5503013e34137eeeaa001648
def diamond(n):
3,423
In this Kata, you will be given an array of numbers and a number `n`, and your task will be to determine if `any` array elements, when summed (or taken individually), are divisible by `n`. For example: * `solve([1,3,4,7,6],9) == true`, because `3 + 6` is divisible by `9` * `solve([1,2,3,4,5],10) == true` for sim...
["from itertools import combinations\n\ndef solve(a, n):\n return any(sum(c) % n == 0 for i in range(len(a)) for c in combinations(a, i+1))", "def solve(xs, n):\n rs = set()\n for x in xs:\n for r in list(rs):\n rs.add((r + x) % n)\n rs.add(x % n)\n return 0 in rs", "from itertools ...
{"fn_name": "solve", "inputs": [[[1, 2, 3, 4, 5], 8], [[7, 2, 8, 5], 16], [[1, 2, 3, 4, 5], 10], [[3, 1, 5, 7], 14], [[1, 2, 3, 4, 5], 15], [[8, 5, 3, 9], 7], [[8, 5, 3], 7]], "outputs": [[true], [false], [true], [false], [true], [true], [false]]}
introductory
https://www.codewars.com/kata/59eb64cba954273cd4000099
def solve(arr,n):
3,424
Given a non-negative integer, return an array / a list of the individual digits in order. Examples: ``` 123 => [1,2,3] 1 => [1] 8675309 => [8,6,7,5,3,0,9] ```
["def digitize(n):\n return [int(d) for d in str(n)]", "def digitize(n):\n return [int(n) for n in str(n)]", "def digitize(n):\n return list(map(int, str(n)))", "def digitize(n):\n return [int(e) for e in str(n)]", "def digitize(n):\n n = str(n)\n return [int(x) for x in n]", "\ndef digitize(n):\n ...
{"fn_name": "digitize", "inputs": [[123], [1], [0], [1230], [8675309]], "outputs": [[[1, 2, 3]], [[1]], [[0]], [[1, 2, 3, 0]], [[8, 6, 7, 5, 3, 0, 9]]]}
introductory
https://www.codewars.com/kata/5417423f9e2e6c2f040002ae
def digitize(n):
3,425
A [Word Square](https://en.wikipedia.org/wiki/Word_square) is a set of words written out in a square grid, such that the same words can be read both horizontally and vertically. The number of words, equal to the number of letters in each word, is known as the *order* of the square. For example, this is an *order* `5` ...
["from collections import Counter\ndef word_square(ls):\n n = int(len(ls)**0.5)\n return n*n==len(ls) and sum(i%2 for i in list(Counter(ls).values())) <= n\n", "def word_square(letters):\n root = int(len(letters)**0.5)\n return len(letters)**0.5 == root and sum([ letters.count(i)%2 for i in set(letters) ]) ...
{"fn_name": "word_square", "inputs": [["SATORAREPOTENETOPERAROTAS"], ["NOTSQUARE"], ["BITICETEN"], ["CARDAREAREARDART"], ["CODEWARS"], ["AAAAACEEELLRRRTT"], ["AAACCEEEEHHHMMTT"], ["AAACCEEEEHHHMMTTXXX"], ["ABCD"], ["GHBEAEFGCIIDFHGG"], ["AAHHFDKIHHFCXZBFDERRRTXXAA"], ["AABBCCDDEEFFGGGG"], ["ABCABCABC"], ["FRACTUREOUTLI...
introductory
https://www.codewars.com/kata/578e07d590f2bb8d3300001d
def word_square(letters):
3,426
Write a function to calculate compound tax using the following table: For $10 and under, the tax rate should be 10%. For $20 and under, the tax rate on the first $10 is %10, and the tax on the rest is 7%. For $30 and under, the tax rate on the first $10 is still %10, the rate for the next $10 is still 7%, and everythi...
["def tax_calculator(total):\n if not isinstance(total, (int, float)) or total < 0: return 0\n \n tax = 0\n \n if total > 30: tax = 2.2 + (total - 30) * 0.03\n elif total > 20: tax = 1.7 + (total - 20) * 0.05\n elif total > 10: tax = 1 + (total-10) * 0.07\n elif total > 0: tax = total / 10.0\n\n...
{"fn_name": "tax_calculator", "inputs": [[1], [10], [11], [15], [18], [21], [26], [30], [30.49], [35], [100], [1000000], [0], [-3], [null], ["monkey"], [[]], [{}]], "outputs": [[0.1], [1], [1.07], [1.35], [1.56], [1.75], [2], [2.2], [2.21], [2.35], [4.3], [30001.3], [0], [0], [0], [0], [0], [0]]}
introductory
https://www.codewars.com/kata/56314d3c326bbcf386000007
def tax_calculator(total):
3,427
There is an array with some numbers. All numbers are equal except for one. Try to find it! ```python find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2 find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55 ``` It’s guaranteed that array contains at least 3 numbers. The tests contain some very huge arrays, so think about performance. This is t...
["def find_uniq(arr):\n a, b = set(arr)\n return a if arr.count(a) == 1 else b", "def find_uniq(arr):\n if (arr[0]==arr[1]):\n return([x for x in arr[2:] if x!=arr[0] ][0])\n return(arr[0] if arr[1]==arr[2] else arr[1])\n", "def find_uniq(arr):\n s = set(arr)\n for e in s:\n if arr.coun...
{"fn_name": "find_uniq", "inputs": [[[1, 1, 1, 2, 1, 1]], [[0, 0, 0.55, 0, 0]], [[4, 4, 4, 3, 4, 4, 4, 4]], [[5, 5, 5, 5, 4, 5, 5, 5]], [[6, 6, 6, 6, 6, 5, 6, 6]], [[7, 7, 7, 7, 7, 7, 6, 7]], [[8, 8, 8, 8, 8, 8, 8, 7]], [[3, 3, 3, 3, 3, 3, 3, 2]], [[2, 2, 2, 2, 2, 2, 2, 1]], [[0, 1, 1, 1, 1, 1, 1, 1]]], "outputs": [[2]...
introductory
https://www.codewars.com/kata/585d7d5adb20cf33cb000235
def find_uniq(arr):
3,428
*Translations appreciated* # Overview Your task is to decode a qr code. You get the qr code as 2 dimensional array, filled with numbers. 1 is for a black field and 0 for a white field. It is always a qr code of version 1 (21*21), it is always using mask 0 ((x+y)%2), it is always using byte mode and it always has erro...
["def scanner(qrc):\n bits = ''.join( str(qrc[x][y] ^ ((x+y)%2==0)) for x,y in ticTocGen())\n size = int(bits[4:12],2)\n return ''.join( chr(int(bits[i:i+8],2)) for i in range(12,12+8*size,8))\n\n\ndef ticTocGen():\n x,y,dx = 20,20,-1\n while y>13: \n yield from ( (x,y-dy) for dy in range(2) )\n ...
{"fn_name": "scanner", "inputs": [[[[1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1], [1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1], [1, 0, 1, 1, 1, 0, 1, 0,...
introductory
https://www.codewars.com/kata/5ef9c85dc41b4e000f9a645f
def scanner(qrcode):
3,429
Complete the function ```circleArea``` so that it will return the area of a circle with the given ```radius```. Round the returned number to two decimal places (except for Haskell). If the radius is not positive or not a number, return ```false```. Example: ```python circleArea(-1485.86) #returns false circleArea...
["from math import pi\n\ndef circleArea(r):\n return round(pi * r ** 2, 2) if type(r) in (int, float) and r > 0 else False\n", "import math\n\ndef circleArea(r):\n try:\n if (r > 0):\n return round(math.pi*r**2, 2)\n else:\n return False\n except TypeError:\n return F...
{"fn_name": "circleArea", "inputs": [[0], ["An integer"]], "outputs": [[false], [false]]}
introductory
https://www.codewars.com/kata/537baa6f8f4b300b5900106c
def circleArea(r):
3,430
You were given a string of integer temperature values. Create a function `lowest_temp(t)` and return the lowest value or `None/null/Nothing` if the string is empty.
["def lowest_temp(t):\n return min((int(x) for x in t.split()), default=None)", "def lowest_temp(t):\n return min(map(int,t.split()),default=None)", "def lowest_temp(t):\n if t:\n return min([int(x) for x in t.split()])\n else:\n return None\n", "def lowest_temp(t):\n return min([int(tm) for ...
{"fn_name": "lowest_temp", "inputs": [[""], ["-1 50 -4 20 22 -7 0 10 -8"]], "outputs": [[null], [-8]]}
introductory
https://www.codewars.com/kata/588e0f11b7b4a5b373000041
def lowest_temp(t):
3,431
# A wolf in sheep's clothing Wolves have been reintroduced to Great Britain. You are a sheep farmer, and are now plagued by wolves which pretend to be sheep. Fortunately, you are good at spotting them. Warn the sheep in front of the wolf that it is about to be eaten. Remember that you are standing **at the front of ...
["def warn_the_sheep(queue):\n n = len(queue) - queue.index('wolf') - 1\n return f'Oi! Sheep number {n}! You are about to be eaten by a wolf!' if n else 'Pls go away and stop eating my sheep'\n", "def warn_the_sheep(queue):\n i = queue[::-1].index('wolf')\n if i == 0:\n return 'Pls go away and stop e...
{"fn_name": "warn_the_sheep", "inputs": [[["sheep", "sheep", "sheep", "sheep", "sheep", "wolf", "sheep", "sheep"]], [["sheep", "wolf", "sheep", "sheep", "sheep", "sheep", "sheep"]], [["wolf", "sheep", "sheep", "sheep", "sheep", "sheep", "sheep"]], [["sheep", "wolf", "sheep"]], [["sheep", "sheep", "wolf"]]], "outputs": ...
introductory
https://www.codewars.com/kata/5c8bfa44b9d1192e1ebd3d15
def warn_the_sheep(queue):
3,432
You have been presented with a cipher, your goal is to re-create the cipher with little information. Use the examples provided to see if you can find a solution to how this cipher is made. You will be given no hints, only the handful of phrases that have already been deciphered for you. Your only hint: Spaces are lef...
["def cipher(p):\n return ''.join(chr((ord(j)+i%3+(i-1)//3-97)%26+97) if j!=' 'and i!=0 else j for i,j in enumerate(p))", "from itertools import count\n\nBASE = ord('a')\n\ndef deltas():\n for i in count(-1):\n yield max(i, 0)\n yield i + 2\n yield i + 3\n\ndef cipher(phrase):\n return ''....
{"fn_name": "cipher", "inputs": [["this will probably not be fun"], ["hopefully you will find satisfaction at least"], ["really this is very tedious"], ["if you made it this far you are a better programmer than i am"]], "outputs": [["tiks zjop twrggfrf uwz kl pcx"], ["hprehxmoc ctx cmrs mqtl zjdqcqjnfsaa nh ztnhj"], ["...
introductory
https://www.codewars.com/kata/5e539724dd38d0002992eaad
def cipher(phrase:
3,433
Given an array containing only zeros and ones, find the index of the zero that, if converted to one, will make the longest sequence of ones. For instance, given the array: ``` [1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1] ``` replacing the zero at index 10 (counting from 0) forms a sequence of 9 ones: `...
["def replace_zero(arr):\n m, im, i, lst = 0, -1, -1, ''.join(map(str,arr)).split('0')\n for a,b in zip(lst,lst[1:]):\n i += len(a) + 1 \n candidate = len(a)+len(b)+1\n if m <= candidate:\n im, m = i, candidate\n return im", "def replace_zero(arr):\n ret = [0,0]\n arr = [N...
{"fn_name": "replace_zero", "inputs": [[[1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1]], [[1, 1, 0, 1, 1, 0, 1, 1]], [[1, 1, 1, 0, 1, 1, 0, 1, 1, 1]], [[0, 1, 1, 1]], [[1, 1, 1, 0]], [[1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1]], [[0, 0, 0, 0, 0, 1]], [[0, 0, 0, 0, 1, 0]], [[1, 0, 0, 0, 0, 0]], [[0, 1, 0, 0, 0, 0]]...
introductory
https://www.codewars.com/kata/5a00a8b5ffe75f8888000080
def replace_zero(arr):
3,434
You will be given two numbers `m,n`. The numbers could span from `0` to `10000`. We can get their product by using binary reduction as show in the table below. Example (to understand the table please read the description below it) real value of m(r) m n (r*n) 0 100 15 0 0 50 30 0 1 25 60 60 0 12 120 0 0...
["def bin_mul(m,n):\n if m < n: return bin_mul(n,m)\n if n == 0: return []\n res = []\n while m > 0:\n if m % 2 == 1: res.append(n)\n m = m//2; n *=2\n return res[::-1]", "def bin_mul(m, n):\n if m < n:\n m, n = n, m\n xs = []\n while m >= 1:\n m, m_r = divmod(m, 2)\n...
{"fn_name": "bin_mul", "inputs": [[100, 15], [15, 0], [0, 0]], "outputs": [[[960, 480, 60]], [[]], [[]]]}
introductory
https://www.codewars.com/kata/596a81352240711f3b00006e
def bin_mul(m,n):
3,435
# Introduction There is a war and nobody knows - the alphabet war! There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began. The letters called airstrike to help them in war - dashes and dots are spreaded everywhere on the battlefield. # Ta...
["import re\n\npowers = {\n 'w': -4, 'p': -3, 'b': -2, 's': -1,\n 'm': +4, 'q': +3, 'd': +2, 'z': +1,\n}\n\ndef alphabet_war(fight):\n fight = re.sub('.(?=\\*)|(?<=\\*).', '', fight)\n result = sum(powers.get(c, 0) for c in fight)\n if result < 0:\n return 'Left side wins!'\n elif result > 0:\n...
{"fn_name": "alphabet_war", "inputs": [["z"], ["z*dq*mw*pb*s"], ["zdqmwpbs"], ["zz*zzs"], ["sz**z**zs"], ["z*z*z*zs"], ["*wwwwww*z*"]], "outputs": [["Right side wins!"], ["Let's fight again!"], ["Let's fight again!"], ["Right side wins!"], ["Left side wins!"], ["Left side wins!"], ["Left side wins!"]]}
introductory
https://www.codewars.com/kata/5938f5b606c3033f4700015a
def alphabet_war(fight):
3,436
Description In English we often use "neutral vowel sounds" such as "umm", "err", "ahh" as fillers in conversations to help them run smoothly. Bob always finds himself saying "err". Infact he adds an "err" to every single word he says that ends in a consonant! Because Bob is odd, he likes to stick to this habit even w...
["def err_bob(s):\n res = \"\"\n for i, c in enumerate(s):\n res += c\n if i == len(s)-1 or s[i+1] in \" .,:;!?\":\n if c.islower() and c not in \"aeiou\":\n res += \"err\"\n if c.isupper() and c not in \"AEIOU\":\n res += \"ERR\"\n return res",...
{"fn_name": "err_bob", "inputs": [["r r r r r r r r"], ["THIS, is crazy!"], ["hI, hi. hI hi skY! sky? skY sky"], ["Hello, I am Mr Bob."], ["This, is. another! test? case to check your beautiful code."], ["Hello from the other siiiiideeee"], ["Punctuation? is, important! double space also"]], "outputs": [["rerr rerr re...
introductory
https://www.codewars.com/kata/5751fef5dcc1079ac5001cff
def err_bob(s):
3,437
You are given a secret message you need to decipher. Here are the things you need to know to decipher it: For each word: - the second and the last letter is switched (e.g. `Hello` becomes `Holle`) - the first letter is replaced by its character code (e.g. `H` becomes `72`) Note: there are no special characters used, ...
["def decipher_word(word):\n i = sum(map(str.isdigit, word))\n decoded = chr(int(word[:i]))\n if len(word) > i + 1:\n decoded += word[-1]\n if len(word) > i:\n decoded += word[i+1:-1] + word[i:i+1]\n return decoded\n\ndef decipher_this(string):\n return ' '.join(map(decipher_word, string...
{"fn_name": "decipher_this", "inputs": [["65 119esi 111dl 111lw 108dvei 105n 97n 111ka"], ["84eh 109ero 104e 115wa 116eh 108sse 104e 115eokp"], ["84eh 108sse 104e 115eokp 116eh 109ero 104e 104dare"], ["87yh 99na 119e 110to 97ll 98e 108eki 116tah 119esi 111dl 98dri"], ["84kanh 121uo 80roti 102ro 97ll 121ruo 104ple"]], "...
introductory
https://www.codewars.com/kata/581e014b55f2c52bb00000f8
def decipher_this(string):
3,438
If we multiply the integer `717 (n)` by `7 (k)`, the result will be equal to `5019`. Consider all the possible ways that this last number may be split as a string and calculate their corresponding sum obtained by adding the substrings as integers. When we add all of them up,... surprise, we got the original numbe...
["def sum_part(n):\n m, p, q, r, s = 1, 1, 1, 0, n\n while n > 9:\n n, d = divmod(n, 10)\n r += d * p\n p *= 10\n if d: m = 1\n else: m*= 2\n s += q*n + m*memo[r]\n q *= 2\n return s\n\nfrom collections import defaultdict\nqualified = defaultdict(list)\nmemo = {...
{"fn_name": "next_higher", "inputs": [[100, 3], [200, 4], [300, 5], [500, 7], [717, 7], [1611, 3]], "outputs": [[162], [260], [846], [717], [861], [1989]]}
introductory
https://www.codewars.com/kata/5b713d7187c59b53e60000b0
def next_higher(start,k):
3,439
Given an integer `n`, find two integers `a` and `b` such that: ```Pearl A) a >= 0 and b >= 0 B) a + b = n C) DigitSum(a) + Digitsum(b) is maximum of all possibilities. ``` You will return the digitSum(a) + digitsum(b). ``` For example: solve(29) = 11. If we take 15 + 14 = 29 and digitSum = 1 + 5 + 1 + 4 = 11. There...
["def solve(n):\n if n < 10:\n return n\n a = int((len(str(n)) - 1) * '9')\n b = n - a\n return sum([int(i) for i in (list(str(a)) + list(str(b)))])\n", "def solve(n):\n a = (len(str(n)) - 1) * '9' or '0'\n return sum(map(int, a + str(n - int(a))))", "def solve(n):\n a = 0\n while a * 10 ...
{"fn_name": "solve", "inputs": [[18], [29], [45], [1140], [7019], [50000000], [15569047737], [2452148459], [1], [0]], "outputs": [[18], [11], [18], [33], [35], [68], [144], [116], [1], [0]]}
introductory
https://www.codewars.com/kata/5bc027fccd4ec86c840000b7
def solve(n):
3,440
# Description Given a number `n`, you should find a set of numbers for which the sum equals `n`. This set must consist exclusively of values that are a power of `2` (eg: `2^0 => 1, 2^1 => 2, 2^2 => 4, ...`). The function `powers` takes a single parameter, the number `n`, and should return an array of unique numbers. ...
["def powers(n):\n return [1<<i for i, x in enumerate(reversed(bin(n))) if x == \"1\"]", "def powers(n):\n return [2**i for i, d in enumerate(f\"{n:b}\"[::-1]) if d == \"1\"]", "def powers(n):\n tmp = []\n i = 0\n res = []\n while 2 ** i <= n:\n tmp.append(2 ** i)\n i += 1\n for j in ...
{"fn_name": "powers", "inputs": [[1], [2], [4], [32], [128], [512], [6], [14], [688], [8197], [1966], [9007199254740991]], "outputs": [[[1]], [[2]], [[4]], [[32]], [[128]], [[512]], [[2, 4]], [[2, 4, 8]], [[16, 32, 128, 512]], [[1, 4, 8192]], [[2, 4, 8, 32, 128, 256, 512, 1024]], [[1, 2, 4, 8, 16, 32, 64, 128, 256, 512...
introductory
https://www.codewars.com/kata/5d9f95424a336600278a9632
def powers(n):
3,441
It's the academic year's end, fateful moment of your school report. The averages must be calculated. All the students come to you and entreat you to calculate their average for them. Easy ! You just need to write a script. Return the average of the given array rounded **down** to its nearest integer. The array will n...
["def get_average(marks):\n return sum(marks) // len(marks)\n", "def get_average(marks):\n average = sum(marks) / len(marks) \n return int(average)\n", "import numpy\n\ndef get_average(marks):\n return int(numpy.mean(marks))", "get_average = lambda marks: sum(marks)//len(marks)\n \n", "def get_average...
{"fn_name": "get_average", "inputs": [[[2, 2, 2, 2]], [[1, 5, 87, 45, 8, 8]], [[2, 5, 13, 20, 16, 16, 10]], [[1, 2, 15, 15, 17, 11, 12, 17, 17, 14, 13, 15, 6, 11, 8, 7]]], "outputs": [[2], [25], [11], [11]]}
introductory
https://www.codewars.com/kata/563e320cee5dddcf77000158
def get_average(marks):
3,442
In genetics 2 differents DNAs sequences can code for the same protein. This is due to the redundancy of the genetic code, in fact 2 different tri-nucleotide can code for the same amino-acid. For example the tri-nucleotide 'TTT' and the tri-nucleotide 'TTC' both code for the amino-acid 'F'. For more information you ca...
["def code_for_same_protein(seq1,seq2):\n if seq1 == seq2:\n return True\n lista = [['GCT','GCC','GCA','GCG'],['CGT','CGC','CGA','CGG','AGA','AGG'],['AAT','AAC'],['GAT','GAC'],['AAT','AAC','GAT','GAC'],['TGT','TGC'],['CAA','CAG'],['GAA','GAG'],['CAA','CAG','GAA','GAG'],['GGT','GGC','GGA','GGG'],['CAT','CAC...
{"fn_name": "code_for_same_protein", "inputs": [["ATGTCGTCAATTTAA", "ATGTCGTCAATTTAA"], ["ATGTTTTAA", "ATGTTCTAA"], ["ATGTTTTAA", "ATGATATAA"], ["ATGTTTGGGAATAATTAAGGGTAA", "ATGTTCGGGAATAATGGGAGGTAA"]], "outputs": [[true], [true], [false], [false]]}
introductory
https://www.codewars.com/kata/57cbb9e240e3024aae000b26
def code_for_same_protein(seq1,seq2):
3,443
A system is transmitting messages in binary, however it is not a perfect transmission, and sometimes errors will occur which result in a single bit flipping from 0 to 1, or from 1 to 0. To resolve this, A 2-dimensional Parity Bit Code is used: https://en.wikipedia.org/wiki/Multidimensional_parity-check_code In this s...
["def correct(m, n, bits):\n l = m*n\n row = next((i for i in range(m) if f\"{bits[i*n:(i+1)*n]}{bits[l+i]}\".count(\"1\") % 2), None)\n col = next((i for i in range(n) if f\"{bits[i:l:n]}{bits[l+m+i]}\".count(\"1\") % 2), None)\n if row is col is None:\n return bits\n err = (l + row) if col is No...
{"fn_name": "correct", "inputs": [[1, 1, "111"], [1, 1, "011"], [1, 1, "101"], [1, 1, "110"], [2, 3, "11111010001"], [2, 3, "11011010001"], [2, 3, "11111011001"], [2, 3, "11111010011"]], "outputs": [["111"], ["111"], ["111"], ["111"], ["11111010001"], ["11111010001"], ["11111010001"], ["11111010001"]]}
introductory
https://www.codewars.com/kata/5d870ff1dc2362000ddff90b
def correct(m, n, bits):
3,444
# Task You're given a substring s of some cyclic string. What's the length of the smallest possible string that can be concatenated to itself many times to obtain this cyclic string? # Example For` s = "cabca"`, the output should be `3` `"cabca"` is a substring of a cycle string "abcabcabcabc..." that can be obta...
["def cyclic_string(s):\n return next((i for i, _ in enumerate(s[1:], 1) if s.startswith(s[i:])), len(s))", "import math\n\ndef cyclic_string(s):\n for l in [i for i,ch in enumerate(s) if ch==s[0]][1:]:\n if (s[:l]*math.ceil(len(s)/l))[:len(s)] == s:\n return l\n return len(s)\n \n", "from itertools...
{"fn_name": "cyclic_string", "inputs": [["cabca"], ["aba"], ["ccccccccccc"], ["abaca"]], "outputs": [[3], [2], [1], [4]]}
introductory
https://www.codewars.com/kata/58899594b832f80348000122
def cyclic_string(s):
3,445
Given the sum and gcd of two numbers, return those two numbers in ascending order. If the numbers do not exist, return `-1`, (or `NULL` in C, `tuple (-1,-1)` in C#, `pair (-1,-1)` in C++,`None` in Rust, `array {-1,-1} ` in Java and Golang). ``` For example: Given sum = 12 and gcd = 4... solve(12,4) = [4,8]. The two ...
["def solve(s,g):\n return -1 if s % g else (g, s - g)", "def solve(s,g):\n return not s%g and (g, s-g) or -1", "def solve(s,g):\n if s % g != 0:\n return -1\n else:\n b = s - g\n a = g\n return (a,b)", "import math\n\ndef solve(s,g):\n if s % g != 0:\n return -1\n e...
{"fn_name": "solve", "inputs": [[6, 3], [8, 2], [10, 3], [12, 4], [12, 5], [50, 10], [50, 4], [10, 5], [100, 5], [1000, 5]], "outputs": [[[3, 3]], [[2, 6]], [-1], [[4, 8]], [-1], [[10, 40]], [-1], [[5, 5]], [[5, 95]], [[5, 995]]]}
introductory
https://www.codewars.com/kata/5dd259444228280032b1ed2a
def solve(s,g):
3,446
#### Task: Your job here is to implement a method, `approx_root` in Ruby/Python/Crystal and `approxRoot` in JavaScript/CoffeeScript, that takes one argument, `n`, and returns the approximate square root of that number, rounded to the nearest hundredth and computed in the following manner. 1. Start with `n = 213`...
["def approx_root(n):\n base = int(n**0.5)\n return round( base + (n - base**2) / ((base + 1)**2 - base**2) , 2)", "def approx_root(n):\n m = n**0.5\n a, b = [int(x) for x in [m, m + 1]]\n c = a**2\n return round(a + ((n - c) / (b**2 - c)), 2)", "def approx_root(n):\n b = int(n ** 0.5)\n diff_gn...
{"fn_name": "approx_root", "inputs": [[400], [401], [2], [4], [5], [6], [7], [8], [9], [100], [120], [106], [111], [121], [168]], "outputs": [[20], [20.02], [1.33], [2], [2.2], [2.4], [2.6], [2.8], [3], [10], [10.95], [10.29], [10.52], [11], [12.96]]}
introductory
https://www.codewars.com/kata/58475cce273e5560f40000fa
def approx_root(n):
3,447
Write a function name `nextPerfectSquare` that returns the first perfect square that is greater than its integer argument. A `perfect square` is a integer that is equal to some integer squared. For example 16 is a perfect square because `16=4*4`. ``` example n next perfect sqare 6 9 36 49 0 1 -5 0 ``` ...
["def next_perfect_square(n):\n return n>=0 and (int(n**0.5)+1)**2", "next_perfect_square=lambda n:(n>=0and int(n**.5)+1)**2", "def next_perfect_square(n):\n return n >= 0 and (int(n**.5)+1)**2", "import math\ndef next_perfect_square(n):\n return math.ceil((n + 1) ** 0.5) ** 2 if n > -1 else 0\n", "from bisect...
{"fn_name": "next_perfect_square", "inputs": [[6], [36], [0], [-5]], "outputs": [[9], [49], [1], [0]]}
introductory
https://www.codewars.com/kata/599f403119afacf9f1000051
def next_perfect_square(n):
3,448
Due to another of his misbehaved, the primary school's teacher of the young Gauß, Herr J.G. Büttner, to keep the bored and unruly young schoolboy Karl Friedrich Gauss busy for a good long time, while he teaching arithmetic to his mates, assigned him the problem of adding up all the whole numbers from 1 through a give...
["def f(n):\n return n * (n + 1) // 2 if (isinstance(n, int) and n > 0) else None\n", "def f(n):\n return sum(range(1, n + 1)) if type(n) is int and n > 0 else None", "def f(n):\n try:\n return None if n <= 0 else sum(range(1,(n+1)))\n except:\n return None", "def f(n):\n return ((n+1)/2)*n...
{"fn_name": "f", "inputs": [[100], [300], [303], [50000], ["n"], [3.14], [0], [-10]], "outputs": [[5050], [45150], [46056], [1250025000], [null], [null], [null], [null]]}
introductory
https://www.codewars.com/kata/54df2067ecaa226eca000229
def f(n):
3,449
As a member of the editorial board of the prestigous scientific Journal _Proceedings of the National Academy of Sciences_, you've decided to go back and review how well old articles you've published stand up to modern publication best practices. Specifically, you'd like to re-evaluate old findings in light of recent li...
["def categorize_study(p_value, requirements):\n study_value = p_value * (2**(6-requirements))\n \n if study_value < 0.05 and requirements != 0:\n return \"Fine\"\n elif study_value < 0.05 and requirements == 0:\n return \"Needs review\"\n elif study_value > 0.05 and study_value < 0.15:\n ...
{"fn_name": "categorize_study", "inputs": [[0.01, 3], [0.04, 6], [0.0001, 0], [0.012, 0]], "outputs": [["Needs review"], ["Fine"], ["Needs review"], ["Pants on fire"]]}
introductory
https://www.codewars.com/kata/5864af6739c5ab26e80000bf
def categorize_study(p_value, requirements):
3,450
This is a spin off of my first [kata](http://www.codewars.com/kata/56bc28ad5bdaeb48760009b0). You are given a list of character sequences as a comma separated string. Write a function which returns another string containing all the character sequences except the first and the last ones, separated by spaces. If the inpu...
["def array(strng):\n return ' '.join(strng.split(',')[1:-1]) or None\n", "def array(s):\n r = ' '.join(s.split(',')[1:-1])\n return r if r else None", "def array(string):\n res = ' '.join(string.split(',')[1:-1])\n return res if len(res) > 0 else None", "def array(string):\n if len(string) <5:\n ret...
{"fn_name": "array", "inputs": [[""], ["1"], ["1, 3"], ["1,2,3"], ["1,2,3,4"]], "outputs": [[null], [null], [null], ["2"], ["2 3"]]}
introductory
https://www.codewars.com/kata/570597e258b58f6edc00230d
def array(string):
3,451
If you finish this kata, you can try [Insane Coloured Triangles](http://www.codewars.com/kata/insane-coloured-triangles) by Bubbler, which is a ***much*** harder version of this one. A coloured triangle is created from a row of colours, each of which is red, green or blue. Successive rows, each containing one fewer co...
["COLORS = set(\"RGB\")\n\ndef triangle(row):\n while len(row)>1:\n row = ''.join( a if a==b else (COLORS-{a,b}).pop() for a,b in zip(row, row[1:]))\n return row", "def triangle(row):\n dicts = {'GG':'G', 'BB':'B', 'RR':'R', 'BR':'G', 'BG':'R', 'GB':'R', 'GR':'B', 'RG':'B', 'RB':'G'}\n if len(row) > ...
{"fn_name": "triangle", "inputs": [["GB"], ["RRR"], ["RGBG"], ["RBRGBRB"], ["RBRGBRBGGRRRBGBBBGG"], ["B"]], "outputs": [["R"], ["R"], ["B"], ["G"], ["G"], ["B"]]}
introductory
https://www.codewars.com/kata/5a25ac6ac5e284cfbe000111
def triangle(row):
3,452
The snail crawls up the column. During the day it crawls up some distance. During the night she sleeps, so she slides down for some distance (less than crawls up during the day). Your function takes three arguments: 1. The height of the column (meters) 2. The distance that the snail crawls during the day (meters) 3. T...
["from math import ceil\n\n\ndef snail(column, day, night):\n return max(ceil((column-night)/(day-night)), 1)", "snail=lambda c,d,n:-(min(0,d-c)//(d-n))+1", "def snail(height, day, night):\n n,r = divmod(max(0,height-day), day-night)\n return n + 1 + (r!=0)", "def snail(column, day, night):\n count = 0\n ...
{"fn_name": "snail", "inputs": [[3, 2, 1], [10, 3, 1], [10, 3, 2], [100, 20, 5], [5, 10, 3]], "outputs": [[2], [5], [8], [7], [1]]}
introductory
https://www.codewars.com/kata/5b93fecd8463745630001d05
def snail(column, day, night):
3,453
You will be given an array that contains two strings. Your job is to create a function that will take those two strings and transpose them, so that the strings go from top to bottom instead of left to right. A few things to note: 1. There should be one space in between the two characters 2. You don't have to modify th...
["import itertools\ndef transpose_two_strings(arr):\n return '\\n'.join( ' '.join(elt) for elt in itertools.zip_longest(arr[0],arr[1],fillvalue=' ') )", "from itertools import*;transpose_two_strings=lambda a:'\\n'.join(map(' '.join,zip_longest(*a,fillvalue=' ')))", "def transpose_two_strings(arr):\n p = arr[:]\n ...
{"fn_name": "transpose_two_strings", "inputs": [[["Hello", "World"]], [["joey", "louise"]], [["a", "cat"]], [["cat", ""]], [["!a!a!", "?b?b"]]], "outputs": [["H W\ne o\nl r\nl l\no d"], ["j l\no o\ne u\ny i\n s\n e"], ["a c\n a\n t"], ["c \na \nt "], ["! ?\na b\n! ?\na b\n! "]]}
introductory
https://www.codewars.com/kata/581f4ac139dc423f04000b99
def transpose_two_strings(arr):
3,454
Description overhauled by V --- I've invited some kids for my son's birthday, during which I will give to each kid some amount of candies. Every kid hates receiving less amount of candies than any other kids, and I don't want to have any candies left - giving it to my kid would be bad for his teeth. However, not ev...
["from fractions import gcd\nfrom functools import reduce\n\ndef candies_to_buy(n):\n return reduce(lambda a,b:a*b//gcd(a,b), range(1,n+1))", "def candies_to_buy(n):\n xx = 1\n for i in range(n):\n x = xx\n while xx % (i+1):\n xx += x\n return xx", "from functools import reduce\nfro...
{"fn_name": "candies_to_buy", "inputs": [[1], [2], [5], [6], [9], [10], [60], [61], [100], [101]], "outputs": [[1], [2], [60], [60], [2520], [2520], [9690712164777231700912800], [591133442051411133755680800], [69720375229712477164533808935312303556800], [7041757898200960193617914702466542659236800]]}
introductory
https://www.codewars.com/kata/56cca888a9d0f25985000036
def candies_to_buy(n):
3,455
# Definition **_Disarium number_** is the number that *The sum of its digits powered with their respective positions is equal to the number itself*. ____ # Task **_Given_** a number, **_Find if it is Disarium or not_** . ____ # Warm-up (Highly recommended) # [Playing With Numbers Series](https://www.codewars.com...
["def disarium_number(n):\n return \"Disarium !!\" if n == sum(int(d)**i for i, d in enumerate(str(n), 1)) else \"Not !!\"", "def disarium_number(number):\n a=0\n for j,i in enumerate(str(number)):\n a+=int(i)**(j+1)\n return 'Disarium !!' if a==number else 'Not !!'\n", "def disarium_number(num):\n ...
{"fn_name": "disarium_number", "inputs": [[1024], [1306], [1999], [2427], [1048576], [2646798]], "outputs": [["Not !!"], ["Disarium !!"], ["Not !!"], ["Disarium !!"], ["Not !!"], ["Disarium !!"]]}
introductory
https://www.codewars.com/kata/5a53a17bfd56cb9c14000003
def disarium_number(number):
3,456
This challenge extends the previous [repeater()](https://www.codewars.com/kata/thinkful-string-drills-repeater) challenge. Just like last time, your job is to write a function that accepts a string and a number as arguments. This time, however, you should format the string you return like this: ```python >>> repeater('...
["def repeater(string, n):\n return '\"{}\" repeated {} times is: \"{}\"'.format(string, n, string * n)\n", "def repeater(string, n):\n return '\"{0}\" repeated {1} times is: \"{2}\"'.format(string, n, string * n)\n", "def repeater(s, n):\n return '\"{}\" repeated {} times is: \"{}\"'.format(s, n, s * n)", "def ...
{"fn_name": "repeater", "inputs": [["yo", 3], ["WuB", 6], ["code, eat, code, sleep... ", 2]], "outputs": [["\"yo\" repeated 3 times is: \"yoyoyo\""], ["\"WuB\" repeated 6 times is: \"WuBWuBWuBWuBWuBWuB\""], ["\"code, eat, code, sleep... \" repeated 2 times is: \"code, eat, code, sleep... code, eat, code, sleep... \""]]...
introductory
https://www.codewars.com/kata/585a1f0945376c112a00019a
def repeater(string, n):
3,457
Create a function finalGrade, which calculates the final grade of a student depending on two parameters: a grade for the exam and a number of completed projects. This function should take two arguments: exam - grade for exam (from 0 to 100); projects - number of completed projects (from 0 and above); This function sh...
["def final_grade(exam, projects):\n if exam > 90 or projects > 10: return 100\n if exam > 75 and projects >= 5: return 90\n if exam > 50 and projects >= 2: return 75\n return 0", "def final_grade(exam, projects):\n if exam > 90 or projects > 10:\n return 100\n elif exam > 75 and projects >= 5:\n ...
{"fn_name": "final_grade", "inputs": [[100, 12], [99, 0], [10, 15], [85, 5], [55, 3], [55, 0], [20, 2]], "outputs": [[100], [100], [100], [90], [75], [0], [0]]}
introductory
https://www.codewars.com/kata/5ad0d8356165e63c140014d4
def final_grade(exam, projects):
3,458
Create a function that accepts dimensions, of Rows x Columns, as parameters in order to create a multiplication table sized according to the given dimensions. **The return value of the function must be an array, and the numbers must be Fixnums, NOT strings. Example: multiplication_table(3,3) 1 2 3 ...
["def multiplication_table(row,col):\n return [[(i+1)*(j+1) for j in range(col)] for i in range(row)]", "def multiplication_table(row,col):\n return [[x*y for y in range(1,col+1)] for x in range(1,row+1)]", "def multiplication_table(row,col):\n res = []\n for i in range(1, row+1):\n item = []\n ...
{"fn_name": "multiplication_table", "inputs": [[2, 2], [3, 3], [3, 4], [4, 4], [2, 5]], "outputs": [[[[1, 2], [2, 4]]], [[[1, 2, 3], [2, 4, 6], [3, 6, 9]]], [[[1, 2, 3, 4], [2, 4, 6, 8], [3, 6, 9, 12]]], [[[1, 2, 3, 4], [2, 4, 6, 8], [3, 6, 9, 12], [4, 8, 12, 16]]], [[[1, 2, 3, 4, 5], [2, 4, 6, 8, 10]]]]}
introductory
https://www.codewars.com/kata/5432fd1c913a65b28f000342
def multiplication_table(row,col):
3,459
In this Kata, you will be given two integers `n` and `k` and your task is to remove `k-digits` from `n` and return the lowest number possible, without changing the order of the digits in `n`. Return the result as a string. Let's take an example of `solve(123056,4)`. We need to remove `4` digits from `123056` and retur...
["from itertools import combinations\n\ndef solve(n, k):\n return ''.join(min(combinations(str(n), len(str(n))-k)))", "from itertools import combinations\n\ndef solve(n,k):\n return min((''.join(c) for c in combinations(str(n), len(str(n))-k)), key=int)", "from itertools import combinations as c\ndef solve(n,k):\...
{"fn_name": "solve", "inputs": [[123056, 1], [123056, 2], [123056, 3], [123056, 4], [1284569, 1], [1284569, 2], [1284569, 3], [1284569, 4]], "outputs": [["12056"], ["1056"], ["056"], ["05"], ["124569"], ["12456"], ["1245"], ["124"]]}
introductory
https://www.codewars.com/kata/59fd6d2332b8b9955200005f
def solve(n, k):
3,460
Given a string ``string`` that contains only letters, you have to find out the number of **unique** strings (including ``string`` itself) that can be produced by re-arranging the letters of the ``string``. Strings are case **insensitive**. HINT: Generating all the unique strings and calling length on that isn't a gre...
["from operator import mul\nfrom functools import reduce\nfrom collections import Counter\nfrom math import factorial as fact\n\ndef uniq_count(s):\n return fact(len(s)) // reduce(mul, map(fact, Counter(s.lower()).values()), 1)", "from collections import Counter\nfrom functools import reduce\nfrom math import factor...
{"fn_name": "uniq_count", "inputs": [["AB"], ["ABC"], ["AbA"], ["ABBb"], ["AbcD"], ["AAA"], [""], ["ASTON"], ["BEST"], ["ABcDEFgHIJ"], ["ABcDEFgHIJbaslidbailsbdilasbdkanmsdklhkbHSJKHVDASH"], ["ABcDEFgHIJbaslidbailsbdilasbdkanmsdklhkbHSJKHVDASHVVYQVWKDVDWQUV"]], "outputs": [[2], [6], [3], [4], [24], [1], [1], [120], [24...
introductory
https://www.codewars.com/kata/586c7cd3b98de02ef60001ab
def uniq_count(s):
3,461
# Two samurai generals are discussing dinner plans after a battle, but they can't seem to agree. The discussion gets heated and you are cannot risk favoring either of them as this might damage your political standing with either of the two clans the samurai generals belong to. Thus, the only thing left to do is find w...
["def common_ground(s1,s2):\n lst = []\n for w in s2.split():\n if w in s1.split() and w not in lst:\n lst.append(w)\n return ' '.join(lst) if lst else \"death\"", "def common_ground(s1,s2):\n words = s2.split()\n return ' '.join(sorted((a for a in set(s1.split()) if a in words),\n ...
{"fn_name": "common_ground", "inputs": [["eat chicken", "eat chicken and rice"], ["eat a burger and drink a coke", "drink a coke"], ["i like turtles", "what are you talking about"], ["aa bb", "aa bb cc"], ["aa bb cc", "bb cc"], ["aa bb cc", "bb cc bb aa"], ["aa bb", "cc dd"], ["aa bb", ""], ["", "cc dd"], ["", ""]], "o...
introductory
https://www.codewars.com/kata/57212c55b6fa235edc0002a2
def common_ground(s1,s2):
3,462
Introduction to Disjunctions In logic and mathematics, a disjunction is an operation on 2 or more propositions. A disjunction is true if and only if 1 or more of its operands is true. In programming, we typically denote a disjunction using "||", but in logic we typically use "v". Example of disjunction: p = 1 > 2 = f...
["from functools import reduce\n\n\ndef disjunction(operands, is_exclusive):\n return reduce(bool.__xor__ if is_exclusive else bool.__or__, operands)", "from functools import reduce\n\ndef disjunction(operands, is_exclusive):\n op = int.__xor__ if is_exclusive else int.__or__\n return reduce(op, operands)", "f...
{"fn_name": "disjunction", "inputs": [[[false, true, true], false], [[false, true, false], false], [[false, true, true, true], true], [[true, true, true], false], [[true, true, true, true], false]], "outputs": [[true], [true], [true], [true], [true]]}
introductory
https://www.codewars.com/kata/55b019265ff4eeef8c000039
def disjunction(operands, is_exclusive):
3,463
Write a function `sumTimesTables` which sums the result of the sums of the elements specified in `tables` multiplied by all the numbers in between `min` and `max` including themselves. For example, for `sumTimesTables([2,5],1,3)` the result should be the same as ``` 2*1 + 2*2 + 2*3 + 5*1 + 5*2 + 5*3 ``` i.e. the table...
["def sum_times_tables(table,a,b):\n return sum(table) * (a + b) * (b - a + 1) // 2 \n", "def sum_times_tables(table,a,b):\n s = 0\n for i in range(a,b+1):\n s = s+i*sum(table)\n return s ", "def sum_times_tables(table,a,b):\n return sum(table) * sum(range(a, b+1))", "def T(n):\n return n * (n ...
{"fn_name": "sum_times_tables", "inputs": [[[2, 3], 1, 3], [[1, 3, 5], 1, 1], [[1, 3, 5], 1, 10], [[], 1, 10], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1, 10], [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1], 1, 10], [[5, 4, 7, 8, 9, 6, 3, 2, 10, 1], 1, 10], [[-2], -1, 3], [[-2, 2], -1, 3], [[-2, 3], -1, 3], [[2, -3], -1, 3], [[2, 4, 7], -1...
introductory
https://www.codewars.com/kata/551e51155ed5ab41450006e1
def sum_times_tables(table,a,b):