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
4,365
An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case. ```python is_isogram("Dermatoglyphics" ) == true is_isogram("aba" ) == false is_...
["def is_isogram(string):\n return len(string) == len(set(string.lower()))", "def is_isogram(string):\n string = string.lower()\n for letter in string:\n if string.count(letter) > 1: return False\n return True", "def is_isogram(string): \n return len(set(string.lower())) == len(string)", "def is_i...
{"fn_name": "is_isogram", "inputs": [["Dermatoglyphics"], ["isogram"], ["moose"], ["isIsogram"], ["aba"], ["moOse"], ["thumbscrewjapingly"], ["abcdefghijklmnopqrstuvwxyz"], ["abcdefghijklmnopqrstuwwxyz"], [""]], "outputs": [[true], [true], [false], [false], [false], [false], [true], [true], [false], [true]]}
introductory
https://www.codewars.com/kata/54ba84be607a92aa900000f1
def is_isogram(string):
4,366
#It's show time! Archers have gathered from all around the world to participate in the Arrow Function Faire. But the faire will only start if there are archers signed and if they all have enough arrows in their quivers - at least 5 is the requirement! Are all the archers ready? #Reference https://developer.mozilla.org...
["def archers_ready(archers):\n return all(i >= 5 for i in archers) if archers else False", "def archers_ready(archers):\n return len(archers) > 0 and all(a > 4 for a in archers)", "def archers_ready(archers):\n try:\n return min(archers)>=5\n except:\n return False", "def archers_ready(archer...
{"fn_name": "archers_ready", "inputs": [[[]], [[1, 2, 3, 4]], [[5, 6, 7, 8]], [[5, 6, 7, 4]], [[1, 2, 3, 4, 5, 6, 7, 8]]], "outputs": [[false], [false], [true], [false], [false]]}
introductory
https://www.codewars.com/kata/559f89598c0d6c9b31000125
def archers_ready(archers):
4,367
You are given the `length` and `width` of a 4-sided polygon. The polygon can either be a rectangle or a square. If it is a square, return its area. If it is a rectangle, return its perimeter. ``` area_or_perimeter(6, 10) --> 32 area_or_perimeter(4, 4) --> 16 ``` > Note: for the purposes of this kata you will assume ...
["def area_or_perimeter(l, w):\n return l * w if l == w else (l + w) * 2", "area_or_perimeter = lambda a, b : a * b if a == b else 2 * (a + b)", "def area_or_perimeter(l , w):\n return l * w if l == w else 2 * (l + w)", "def area_or_perimeter(l , w):\n return l*w if l==w else l+l+w+w", "def area_or_perimeter(l...
{"fn_name": "area_or_perimeter", "inputs": [[4, 4], [6, 10]], "outputs": [[16], [32]]}
introductory
https://www.codewars.com/kata/5ab6538b379d20ad880000ab
def area_or_perimeter(l , w):
4,368
Fast & Furious Driving School's (F&F) charges for lessons are as below: Time Cost Up to 1st hour $30 Every subsequent half hour** $10 ** Subsequent charges are calculated by rounding up to nearest half hour. For example, if student X has a lesson for 1hr 20 minutes, he will be charged $40 (30+10) for 1 hr 3...
["import math\n\ndef cost(mins):\n return 30 + 10 * math.ceil(max(0, mins - 60 - 5) / 30)", "from math import ceil\n\ndef cost(n):\n n -= 5\n \n if n<60 : return 30\n \n n -= 60\n \n return 30 + ceil(n/30) * 10", "def cost(mins):\n price = 0\n print (mins)\n while mins > 0:\n if ...
{"fn_name": "cost", "inputs": [[45], [63], [84], [102], [273]], "outputs": [[30], [30], [40], [50], [100]]}
introductory
https://www.codewars.com/kata/589b1c15081bcbfe6700017a
def cost(mins):
4,369
There exist two zeroes: +0 (or just 0) and -0. Write a function that returns `true` if the input number is -0 and `false` otherwise (`True` and `False` for Python). In JavaScript / TypeScript / Coffeescript the input will be a number. In Python / Java / C / NASM / Haskell / the input will be a float.
["def is_negative_zero(n):\n return str(n) == '-0.0'", "import math\ndef is_negative_zero(n):\n return n == 0 and math.copysign(1, n) == -1", "import math\n\ndef is_negative_zero(n):\n return math.atan2(-0.0, -0.0) == math.atan2(n, n)\n", "def is_negative_zero(n):\n return str(n) == str(-0.0)", "def is_nega...
{"fn_name": "is_negative_zero", "inputs": [[-0.0], [-Infinity], [-5.0], [-4.0], [-3.0], [-2.0], [-1.0], [1.0], [2.0], [3.0], [4.0], [5.0], [Infinity]], "outputs": [[true], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false]]}
introductory
https://www.codewars.com/kata/5c5086287bc6600001c7589a
def is_negative_zero(n):
4,370
A generalization of Bézier surfaces, called the S-patch, uses an interesting scheme for indexing its control points. In the case of an n-sided surface of degree d, each index has n non-negative integers that sum to d, and all possible configurations are used. For example, for a 3-sided quadratic (degree 2) surface th...
["def gen(n, d):\n if d == 0 or n == 1:\n yield [d]*n\n else:\n for x in range(d+1):\n for y in gen(n-1, d-x):\n yield [x] + y\n\ndef indices(n, d):\n return list(gen(n, d))", "import itertools\ndef indices(n, d):\n return list(recurse(n,d, []))\n\ndef recurse(n, d, p...
{"fn_name": "indices", "inputs": [[1, 0], [3, 0]], "outputs": [[[[0]]], [[[0, 0, 0]]]]}
introductory
https://www.codewars.com/kata/553291f451ab4fbcdc0001c6
def indices(n, d):
4,371
Given a long number, return all the possible sum of two digits of it. For example, `12345`: all possible sum of two digits from that number are: [ 1 + 2, 1 + 3, 1 + 4, 1 + 5, 2 + 3, 2 + 4, 2 + 5, 3 + 4, 3 + 5, 4 + 5 ] Therefore the result must be: [ 3, 4, 5, 6, 5, 6, 7, 7, 8, 9 ]
["from itertools import combinations\n\ndef digits(num):\n return list(map(sum, combinations(map(int,str(num)),2)))", "# Solution 1\ndef digits(num):\n return [int(a)+int(b) for i,a in enumerate(str(num)) for b in str(num)[(i+1):]]\n \n \n# Solution 2\ndef digits(num):\n from itertools import combination...
{"fn_name": "digits", "inputs": [[156], [81596], [3852], [3264128], [999999]], "outputs": [[[6, 7, 11]], [[9, 13, 17, 14, 6, 10, 7, 14, 11, 15]], [[11, 8, 5, 13, 10, 7]], [[5, 9, 7, 4, 5, 11, 8, 6, 3, 4, 10, 10, 7, 8, 14, 5, 6, 12, 3, 9, 10]], [[18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18]]]}
introductory
https://www.codewars.com/kata/5b4e474305f04bea11000148
def digits(num):
4,372
Every Friday and Saturday night, farmer counts amount of sheep returned back to his farm (sheep returned on Friday stay and don't leave for a weekend). Sheep return in groups each of the days -> you will be given two arrays with these numbers (one for Friday and one for Saturday night). Entries are always positive int...
["def lostSheep(friday,saturday,total):\n return total - sum(friday+saturday)", "def lostSheep(friday,saturday,total):\n return total - sum(friday) - sum(saturday)", "def lostSheep(friday,saturday,total):\n sheeps = friday + saturday\n return total - sum(sheeps)", "def lostSheep(friday, saturday, total):\n ...
{"fn_name": "lostSheep", "inputs": [[[1, 2], [3, 4], 15], [[3, 1, 2], [4, 5], 21], [[5, 1, 4], [5, 4], 29], [[11, 23, 3, 4, 15], [7, 14, 9, 21, 15], 300], [[2, 7, 13, 17], [23, 56, 44, 12, 1, 2, 1], 255], [[2, 5, 8], [11, 23, 3, 4, 15, 112, 12, 4], 355], [[1, 1, 1, 2, 1, 2], [2, 1, 2, 1, 2, 1], 30], [[5, 10, 15], [11, ...
introductory
https://www.codewars.com/kata/58e0f0bf92d04ccf0a000010
def lostSheep(friday,saturday,total):
4,373
Given an array (arr) as an argument complete the function `countSmileys` that should return the total number of smiling faces. Rules for a smiling face: - Each smiley face must contain a valid pair of eyes. Eyes can be marked as `:` or `;` - A smiley face can have a nose but it does not have to. Valid characters for...
["from re import findall\ndef count_smileys(arr):\n return len(list(findall(r\"[:;][-~]?[)D]\", \" \".join(arr))))", "def count_smileys(arr):\n eyes = [\":\", \";\"]\n noses = [\"\", \"-\", \"~\"]\n mouths = [\")\", \"D\"]\n count = 0\n for eye in eyes:\n for nose in noses:\n for mou...
{"fn_name": "count_smileys", "inputs": [[[]], [[":D", ":~)", ";~D", ":)"]], [[":)", ":(", ":D", ":O", ":;"]], [[";]", ":[", ";*", ":$", ";-D"]]], "outputs": [[0], [4], [2], [1]]}
introductory
https://www.codewars.com/kata/583203e6eb35d7980400002a
def count_smileys(arr):
4,374
It's the fourth quater of the Super Bowl and your team is down by 4 points. You're 10 yards away from the endzone, if your team doesn't score a touchdown in the next four plays you lose. On a previous play, you were injured and rushed to the hospital. Your hospital room has no internet, tv, or radio and you don't know ...
["def did_we_win(plays):\n plays = [p for p in plays if p]\n return all(p != 'turnover' for y,p in plays) and sum(-y if p == 'sack' else y for y,p in plays) > 10 ", "def did_we_win(plays):\n s = 0\n for i in range(4):\n if not plays[i]: break\n if plays[i][1] == \"turnover\": return...
{"fn_name": "did_we_win", "inputs": [[[[8, "pass"], [5, "sack"], [3, "sack"], [5, "run"]]], [[[12, "pass"], [], [], []]], [[[2, "run"], [5, "pass"], [3, "sack"], [8, "pass"]]], [[[5, "pass"], [6, "turnover"], [], []]], [[[5, "pass"], [5, "pass"], [10, "sack"], [10, "run"]]], [[[5, "pass"], [5, "run"], [1, "run"], []]],...
introductory
https://www.codewars.com/kata/59f69fefa0143109e5000019
def did_we_win(plays):
4,375
The function is not returning the correct values. Can you figure out why? ```python get_planet_name(3) # should return 'Earth' ```
["def get_planet_name(id):\n return {\n 1: \"Mercury\",\n 2: \"Venus\",\n 3: \"Earth\",\n 4: \"Mars\",\n 5: \"Jupiter\",\n 6: \"Saturn\",\n 7: \"Uranus\",\n 8: \"Neptune\",\n }.get(id, None)", "def get_planet_name(id):\n return{\n 1: \"Mercury\",\n...
{"fn_name": "get_planet_name", "inputs": [[2], [5], [3], [4], [8], [1]], "outputs": [["Venus"], ["Jupiter"], ["Earth"], ["Mars"], ["Neptune"], ["Mercury"]]}
introductory
https://www.codewars.com/kata/515e188a311df01cba000003
def get_planet_name(id):
4,376
A friend of mine told me privately: "I don't like palindromes". "why not?" - I replied. "Because when I want to do some programming challenges, I encounter 2 or 3 ones first related with palindromes. I'm fed up" - he confess me with anger. I said to myself:"Thankfully, that doesn't happen in Codewars". Talking seriousl...
["def count_pal(n):\n # No recursion; direct calculation:\n return [9 * 10**((n-1) // 2), 10**(n // 2) * (13 - 9 * (-1)**n) // 2 - 2]", "def count_pal(n):\n x = lambda y: 9 * int(10 ** ((y - 1)//2))\n return [x(n), sum(x(i) for i in range(n+1))]", "from itertools import accumulate\n\nN_PALS = [0] + [9 * 10*...
{"fn_name": "count_pal", "inputs": [[1], [2], [3], [4], [5], [10], [30], [50], [70]], "outputs": [[[9, 9]], [[9, 18]], [[90, 108]], [[90, 198]], [[900, 1098]], [[90000, 199998]], [[900000000000000, 1999999999999998]], [[9000000000000000000000000, 19999999999999999999999998]], [[90000000000000000000000000000000000, 1999...
introductory
https://www.codewars.com/kata/5b33452ab6989d2407000100
def count_pal(n):
4,377
Alice and Bob have participated to a Rock Off with their bands. A jury of true metalheads rates the two challenges, awarding points to the bands on a scale from 1 to 50 for three categories: Song Heaviness, Originality, and Members' outfits. For each one of these 3 categories they are going to be awarded one point, sh...
["def solve(a, b):\n alice = sum(i > j for i, j in zip(a, b))\n bob = sum(j > i for i, j in zip(a, b))\n \n if alice == bob:\n words = 'that looks like a \"draw\"! Rock on!'\n elif alice > bob:\n words = 'Alice made \"Kurt\" proud!'\n else:\n words = 'Bob made \"Jeff\" proud!'\n ...
{"fn_name": "solve", "inputs": [[[47, 7, 2], [47, 7, 2]], [[47, 50, 22], [26, 47, 12]], [[25, 50, 22], [34, 49, 50]], [[8, 8, 11], [3, 8, 10]], [[20, 32, 18], [48, 25, 40]], [[5, 6, 7], [3, 6, 10]], [[21, 39, 15], [50, 1, 12]], [[0, 1, 2], [1, 2, 0]]], "outputs": [["0, 0: that looks like a \"draw\"! Rock on!"], ["3, 0:...
introductory
https://www.codewars.com/kata/5b097da6c3323ac067000036
def solve(a, b):
4,378
Late last night in the Tanner household, ALF was repairing his spaceship so he might get back to Melmac. Unfortunately for him, he forgot to put on the parking brake, and the spaceship took off during repair. Now it's hovering in space. ALF has the technology to bring the spaceship home if he can lock on to its locati...
["def find_spaceship(astromap):\n lines = astromap.splitlines()\n for y, line in enumerate(lines):\n x = line.find('X')\n if x != -1:\n return [x, len(lines) - 1 - y]\n return 'Spaceship lost forever.'\n", "def find_spaceship(astromap):\n for a, row in enumerate(reversed(astromap.sp...
{"fn_name": "find_spaceship", "inputs": [["X"], ["X\n."], [".X\n.."], ["..\n.X"], ["..\nX."], [".......\nX......."], ["..........\n..........\n.......X..\n..........\n.........."], ["..........\n..........\n..........\n........X.\n.........."], ["........................"], ["\n\n\n\n"]], "outputs": [[[0, 0]], [[0, 1]]...
introductory
https://www.codewars.com/kata/5660aa3d5e011dfd6e000063
def find_spaceship(astromap):
4,379
### Combine strings function ```if:coffeescript,haskell,javascript Create a function named `combineNames` that accepts two parameters (first and last name). The function should return the full name. ``` ```if:python,ruby Create a function named (`combine_names`) that accepts two parameters (first and last name). The fu...
["def combine_names(first, last):\n return first + \" \" + last", "def combine_names(*args):\n return ' '.join(args)\n", "def combine_names(first, second):\n return '{} {}'.format(first, second)", "def combine_names(a,b):\n return '%s %s' %(a,b)", "def combine_names(*ns): return ' '.join(ns)", "# Create the...
{"fn_name": "combine_names", "inputs": [["James", "Stevens"], ["Davy", "Back"], ["Arthur", "Dent"]], "outputs": [["James Stevens"], ["Davy Back"], ["Arthur Dent"]]}
introductory
https://www.codewars.com/kata/55f73f66d160f1f1db000059
def combine_names(first, last):
4,380
Let's assume we need "clean" strings. Clean means a string should only contain letters `a-z`, `A-Z` and spaces. We assume that there are no double spaces or line breaks. Write a function that takes a string and returns a string without the unnecessary characters. ### Examples ```python remove_chars('.tree1') ==> ...
["import re\n\ndef remove_chars(s):\n return re.sub(r'[^a-zA-Z ]', '', s)", "def remove_chars(s):\n return \"\".join( c for c in s if c.isalpha() or c==\" \" )", "import re\ndef remove_chars(s):\n return re.sub(r'[^A-Za-z\\s]','',s)", "def remove_chars(s):\n return \"\".join(list(i for i in s if i.isalpha()...
{"fn_name": "remove_chars", "inputs": [["co_ol f0un%(c)t-io\"n"], ["test for error!"], [".tree1"], ["that's a pie&ce o_f p#ie!"]], "outputs": [["cool function"], ["test for error"], ["tree"], ["thats a piece of pie"]]}
introductory
https://www.codewars.com/kata/59be6bdc4f98a8a9c700007d
def remove_chars(s):
4,381
We define the "unfairness" of a list/array as the *minimal* difference between max(x1,x2,...xk) and min(x1,x2,...xk), for all possible combinations of k elements you can take from the list/array; both minimum and maximum of an empty list/array are considered to be 0. **More info and constraints:** * lists/arrays can ...
["def min_unfairness(arr,k):\n arr = sorted(arr)\n return min(b - a for a, b in zip(arr, arr[k-1:])) if arr and k else 0", "def min_unfairness(arr,k):\n if len(arr) < 2 or k < 2:\n return 0\n t = sorted(arr)\n diff = float('inf')\n for i in range(len(t)-k+1):\n x= t[i+k-1]-t[i]\n ...
{"fn_name": "min_unfairness", "inputs": [[[30, 100, 1000, 150, 60, 250, 10, 120, 20], 3], [[30, 100, 1000, 150, 60, 250, 10, 120, 20], 5], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2], 10], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2], 9], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 10], [[1, 1, -1]...
introductory
https://www.codewars.com/kata/577bcb5dd48e5180030004de
def min_unfairness(arr,k):
4,382
## Task In this kata you'll be given a string of English digits "collapsed" together, like this: `zeronineoneoneeighttwoseventhreesixfourtwofive` Your task is to split the string back to digits: `zero nine one one eight two seven three six four two five` ## Examples ``` three -> three eightsix -> eight six fivefour...
["import re\n\ndef uncollapse(digits):\n return ' '.join(re.findall('zero|one|two|three|four|five|six|seven|eight|nine', digits))", "import re\n\ndef uncollapse(digits):\n return ' '.join(m.group() for m in re.finditer(r'zero|one|two|three|four|five|six|seven|eight|nine', digits))", "uncollapse=lambda s:__import_...
{"fn_name": "uncollapse", "inputs": [["three"], ["eightsix"], ["fivefourseven"], ["ninethreesixthree"], ["foursixeighttwofive"], ["fivethreefivesixthreenineonesevenoneeight"], ["threesevensevensixninenineninefiveeighttwofiveeightsixthreeeight"], ["zeroonetwothreefourfivesixseveneightnine"]], "outputs": [["three"], ["ei...
introductory
https://www.codewars.com/kata/5a626fc7fd56cb63c300008c
def uncollapse(digits):
4,383
Little Petya often visits his grandmother in the countryside. The grandmother has a large vertical garden, which can be represented as a set of `n` rectangles of varying height. Due to the newest irrigation system we can create artificial rain above them. Creating artificial rain is an expensive operation. That's why ...
["def artificial_rain(garden):\n left,area,record = 0,0,1\n for i in range(1,len(garden)):\n if garden[i] < garden[i-1]:\n left = i\n elif garden[i] > garden[i-1]:\n area = max(area,record)\n record = i - left\n record += 1\n return max(area,record)", "def ...
{"fn_name": "artificial_rain", "inputs": [[[2]], [[1, 2, 1, 2, 1]], [[4, 2, 3, 3, 2]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]], [[1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]], [[1, 2, 3, 4, 5, 1, 5, 4, 3, 2, 1]], [[1, 1, 1, 2, 1, 2, 10, 2, 3, 3]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1...
introductory
https://www.codewars.com/kata/5c1bb3d8e514df60b1000242
def artificial_rain(garden):
4,384
# Task Given two integers `a` and `b`, return the sum of the numerator and the denominator of the reduced fraction `a/b`. # Example For `a = 2, b = 4`, the result should be `3` Since `2/4 = 1/2 => 1 + 2 = 3`. For `a = 10, b = 100`, the result should be `11` Since `10/100 = 1/10 => 1 + 10 = 11`. For `a = 5, b = 5`...
["from fractions import gcd\n\ndef fraction(a,b):\n return (a+b)//gcd(a,b)", "from math import gcd\ndef fraction(a, b):\n return a/gcd(a,b) + b/(gcd(a,b))", "\ndef fraction(a, b):\n from math import gcd\n return (a + b) / gcd(a, b)", "from fractions import gcd\n\ndef fraction(a, b):\n d = gcd(a, b)\n ...
{"fn_name": "fraction", "inputs": [[90, 120], [2, 4], [100, 1000], [3, 15], [114, 200], [3, 118]], "outputs": [[7], [3], [11], [6], [157], [121]]}
introductory
https://www.codewars.com/kata/58b8db810f40ea7788000126
def fraction(a, b):
4,385
Write a function `generatePairs` that accepts an integer argument `n` and generates an array containing the pairs of integers `[a, b]` that satisfy the following conditions: ``` 0 <= a <= b <= n ``` The pairs should be sorted by increasing values of `a` then increasing values of `b`. For example, `generatePairs(2)` s...
["def generate_pairs(n):\n return [[i,j] for i in range(n+1) for j in range(i, n+1)]", "def generate_pairs(n):\n return [[a, b] for a in range(n+1) for b in range (a, n+1)]", "def generate_pairs(n):\n return [ [i,y] for i in range(n+1) for y in range(i,n+1) ]", "from itertools import combinations_with_replacem...
{"fn_name": "generate_pairs", "inputs": [[2], [0]], "outputs": [[[[0, 0], [0, 1], [0, 2], [1, 1], [1, 2], [2, 2]]], [[[0, 0]]]]}
introductory
https://www.codewars.com/kata/588e27b7d1140d31cb000060
def generate_pairs(n):
4,386
# Right in the Center _This is inspired by one of Nick Parlante's exercises on the [CodingBat](https://codingbat.com/java) online code practice tool._ Given a sequence of characters, does `"abc"` appear in the CENTER of the sequence? The sequence of characters could contain more than one `"abc"`. To define CENTER, ...
["def is_in_middle(s):\n while len(s)>4:\n s = s[1:-1]\n return 'abc' in s", "def is_in_middle(seq):\n mid, rem = divmod(len(seq), 2)\n start = mid-1\n end = start+3\n \n if not rem: \n start -= 1\n \n return 'abc' in seq[start:end]\n", "def is_in_middle(s):\n return is_in_mi...
{"fn_name": "is_in_middle", "inputs": [["abc"], ["abcabcabc"], ["AAabcBBB"], ["AAAabcBB"], ["AAAAabcBB"], ["AAabcabcBB"], ["abcabcabcabc"], ["AabcBBB"], [""], ["ABC"], ["abcZ"], ["Yabc"]], "outputs": [[true], [true], [true], [true], [false], [false], [false], [false], [false], [false], [true], [true]]}
introductory
https://www.codewars.com/kata/5f5da7a415fbdc0001ae3c69
def is_in_middle(s):
4,387
Please write a function that sums a list, but ignores any duplicate items in the list. For instance, for the list [3, 4, 3, 6] , the function should return 10.
["from collections import Counter\n\n\ndef sum_no_duplicates(nums):\n return sum(k for k, v in list(Counter(nums).items()) if v == 1)\n", "def sum_no_duplicates(l):\n return sum(n for n in set(l) if l.count(n) == 1)", "from collections import Counter\n\ndef sum_no_duplicates(l):\n return sum(k for k,v in list(...
{"fn_name": "sum_no_duplicates", "inputs": [[[1, 1, 2, 3]], [[]], [[1, 1, 2, 2, 3]], [[5, 6, 10, 3, 10, 10, 6, 7, 0, 9, 1, 1, 6, 3, 1]], [[0, 10, 8, 9, 7, 3, 3, 9, 3, 6, 0]], [[0, 1, 4, 4, 0, 4, 2, 5, 9, 0, 10, 9, 0, 1, 2]], [[7, 2, 10, 9, 10, 2, 7, 3, 10, 8, 2, 5]], [[7, 2, 0, 3, 5, 7, 8, 3, 2, 10, 9, 5]], [[1, 9, 9, ...
introductory
https://www.codewars.com/kata/5993fb6c4f5d9f770c0000f2
def sum_no_duplicates(l):
4,388
In this kata, you will make a function that converts between `camelCase`, `snake_case`, and `kebab-case`. You must write a function that changes to a given case. It must be able to handle all three case types: ```python py> change_case("snakeCase", "snake") "snake_case" py> change_case("some-lisp-name", "camel") "som...
["import re\n\ndef change_case(label, target):\n if ('_' in label) + ('-' in label) + (label != label.lower()) > 1:\n return\n \n if target == 'snake':\n return re.sub('([A-Z])', r'_\\1', label.replace('-', '_')).lower()\n \n if target == 'kebab':\n return re.sub('([A-Z])', r'-\\1', ...
{"fn_name": "change_case", "inputs": [["snakeCase", "snake"], ["some-lisp-name", "camel"], ["map_to_all", "kebab"], ["doHTMLRequest", "kebab"], ["invalid-inPut_bad", "kebab"], ["valid-input", "huh???"], ["", "camel"], ["snake-kebab_case", "kebab"], ["snakeCamel_case", "snake"], ["kebabCamel-case", "snake"], ["case-Came...
introductory
https://www.codewars.com/kata/59be8c08bf10a49a240000b1
def change_case(identifier, targetCase):
4,389
## Story John runs a shop, bought some goods, and then sells them. He used a special accounting method, like this: ``` [[60,20],[60,-20]] ``` Each sub array records the commodity price and profit/loss to sell (percentage). Positive mean profit and negative means loss. In the example above, John's first commodity sold...
["def profitLoss(records):\n return round(sum(price - price / (1 + profit / 100) for (price, profit) in records), 2)", "def profitLoss(records):\n return round(sum(pr * pe / (100+pe) for pr, pe in records), 2)", "def profitLoss(records):\n \n return round(sum(amount * (1 - 1/(1 + perc/100)) for amount, p...
{"fn_name": "profitLoss", "inputs": [[[[60, 20], [60, -20]]], [[[60, 100], [60, -50]]], [[[60, 0], [60, 0]]]], "outputs": [[-5], [-30], [0]]}
introductory
https://www.codewars.com/kata/5768b775b8ed4a360f000b20
def profitLoss(records):
4,390
![](http://www.grindtv.com/wp-content/uploads/2015/08/drone.jpg) The other day I saw an amazing video where a guy hacked some wifi controlled lightbulbs by flying a drone past them. Brilliant. In this kata we will recreate that stunt... sort of. You will be given two strings: `lamps` and `drone`. `lamps` represents ...
["def fly_by(lamps, drone):\n return lamps.replace('x', 'o', drone.count('=') + 1)", "def fly_by(lamps, drone):\n l = len(lamps)\n d = len(drone)\n if d >= l:\n return 'o'* l\n return ('o' * d) + ('x' * (l - d))", "def fly_by(lamps, drone):\n newlamps = []\n for x in lamps:\n newlamps...
{"fn_name": "fly_by", "inputs": [["xxxxxx", "====T"], ["xxxxxxxxx", "==T"], ["xxxxxxxxxxxxxxx", "=========T"]], "outputs": [["ooooox"], ["oooxxxxxx"], ["ooooooooooxxxxx"]]}
introductory
https://www.codewars.com/kata/58356a94f8358058f30004b5
def fly_by(lamps, drone):
4,391
## The Story Green Lantern's long hours of study and practice with his ring have really paid off -- his skills, focus, and control have improved so much that now he can even use his ring to update and redesign his web site. Earlier today he was focusing his will and a beam from his ring upon the Justice League web serv...
["def yellow_be_gone(s):\n d = {'gold':'ForestGreen', 'khaki':'LimeGreen', 'lemonchiffon':'PaleGreen', 'lightgoldenrodyellow':'SpringGreen',\n 'lightyellow':'MintCream', 'palegoldenrod':'LightGreen', 'yellow':'Lime'}\n \n if s[0] == '#':\n R, G, B = s[1:3], s[3:5], s[5:]\n if B < G a...
{"fn_name": "yellow_be_gone", "inputs": [["lemonchiffon"], ["GOLD"], ["pAlEgOlDeNrOd"], ["BlueViolet"], ["#000000"], ["#b8860b"], ["#8FBC8F"], ["#C71585"]], "outputs": [["PaleGreen"], ["ForestGreen"], ["LightGreen"], ["BlueViolet"], ["#000000"], ["#0bb886"], ["#8FBC8F"], ["#C71585"]]}
introductory
https://www.codewars.com/kata/57e6bcbd684e570c6700021c
def yellow_be_gone(s):
4,392
We have two consecutive integers k1 and k2, k2 = k1 + 1 We need to calculate the lowest integer `n`, such that: the values nk1 and nk2 have the same digits but in different order. E.g.# 1: ``` k1 = 100 k2 = 101 n = 8919 #Because 8919 * 100 = 891900 and 8919 * 101 = 900819 ``` E.g.# 2: ``` k1 = 325 k2 = 326 n =...
["def find_lowest_int(k1):\n k2, n = k1 + 1, 1\n\n def digits(n):\n return sorted(str(n))\n \n while digits(n*k1) != digits(n*k2):\n n += 1\n \n return n", "from itertools import count as c\n\ndef find_lowest_int(k):\n return next((n for n in c(1) if sorted(str(n*k))== sorted(str(n*(k...
{"fn_name": "find_lowest_int", "inputs": [[325], [599], [855], [1], [100], [1000], [10000]], "outputs": [[477], [2394], [999], [125874], [8919], [89919], [899919]]}
introductory
https://www.codewars.com/kata/5ba178be875de960a6000187
def find_lowest_int(k):
4,393
Write a function that takes a list comprised of other lists of integers and returns the sum of all numbers that appear in two or more lists in the input list. Now that might have sounded confusing, it isn't: ```python repeat_sum([[1, 2, 3],[2, 8, 9],[7, 123, 8]]) >>> sum of [2, 8] return 10 repeat_sum([[1], [2], [3, ...
["from collections import defaultdict\n\ndef repeat_sum(l):\n count = defaultdict(int)\n for l1 in l:\n for val in set(l1):\n count[val] += 1\n \n return sum(k for k,v in list(count.items()) if v > 1)\n", "from collections import Counter\n\n\ndef repeat_sum(l):\n counter = sum((Counter(...
{"fn_name": "repeat_sum", "inputs": [[[[1, 2, 3], [2, 8, 9], [7, 123, 8]]], [[[1], [2], [3, 4, 4, 4], [123456789]]], [[[1, 8, 8], [8, 8, 8], [8, 8, 8, 1]]], [[[1]]]], "outputs": [[10], [0], [9], [0]]}
introductory
https://www.codewars.com/kata/56b4bae128644b5613000037
def repeat_sum(l):
4,394
Most football fans love it for the goals and excitement. Well, this Kata doesn't. You are to handle the referee's little notebook and count the players who were sent off for fouls and misbehavior. The rules: Two teams, named "A" and "B" have 11 players each; players on each team are numbered from 1 to 11. Any player m...
["def men_still_standing(cards):\n # generate teams\n A = {k: 0 for k in range(1, 12)}\n B = A.copy()\n \n for card in cards:\n # parse card\n team = A if card[0] == \"A\" else B\n player = int(card[1:-1])\n color = card[-1]\n \n if player not in team:\n ...
{"fn_name": "men_still_standing", "inputs": [[[]], [["A4Y", "A4Y"]], [["A4Y", "A4R"]], [["A4Y", "A5R", "B5R", "A4Y", "B6Y"]], [["A4R", "A4R", "A4R"]], [["A4R", "A2R", "A3R", "A6R", "A8R", "A10R", "A11R"]]], "outputs": [[[11, 11]], [[10, 11]], [[10, 11]], [[9, 10]], [[10, 11]], [[6, 11]]]}
introductory
https://www.codewars.com/kata/5cde4e3f52910d00130dc92c
def men_still_standing(cards):
4,395
Your task is to ___find the next higher number (int) with same '1'- Bits___. I.e. as much `1` bits as before and output next higher than input. Input is always an int in between 1 and 1<<30 (inclusive). No bad cases or special tricks... ### Some easy examples: ``` Input: 129 => Output: 130 (10000001 => 10000010) I...
["def next_higher(value):\n s = f'0{value:b}'\n i = s.rfind('01')\n s = s[:i] + '10' + ''.join(sorted(s[i+2:]))\n return int(s, 2)", "from itertools import count\ndef next_higher(value):\n bits = bin(value).count('1')\n return next(i for i in count(value+1) if bin(i).count('1')==bits)", "import re\n\n...
{"fn_name": "next_higher", "inputs": [[128], [1], [1022], [127], [1253343]], "outputs": [[256], [2], [1279], [191], [1253359]]}
introductory
https://www.codewars.com/kata/56bdd0aec5dc03d7780010a5
def next_higher(value):
4,396
Return an output string that translates an input string `s`/`$s` by replacing each character in `s`/`$s` with a number representing the number of times that character occurs in `s`/`$s` and separating each number with the character(s) `sep`/`$sep`.
["def freq_seq(s, sep):\n return sep.join([str(s.count(i)) for i in s])\n", "from collections import Counter\n\ndef freq_seq(s, sep):\n freq = Counter(s)\n return sep.join(str(freq[c]) for c in s)\n", "from collections import Counter\n\ndef freq_seq(string, separator):\n count = Counter(string)\n return ...
{"fn_name": "freq_seq", "inputs": [["hello world", "-"], ["19999999", ":"], ["^^^**$", "x"]], "outputs": [["1-1-3-3-2-1-1-2-1-3-1"], ["1:7:7:7:7:7:7:7"], ["3x3x3x2x2x1"]]}
introductory
https://www.codewars.com/kata/585a033e3a36cdc50a00011c
def freq_seq(s, sep):
4,397
# Task Given a sequence of 0s and 1s, determine if it is a prefix of Thue-Morse sequence. The infinite Thue-Morse sequence is obtained by first taking a sequence containing a single 0 and then repeatedly concatenating the current sequence with its binary complement. A binary complement of a sequence X is a sequenc...
["def is_thue_morse(seq):\n init_seq = [0]\n while len(init_seq) < len(seq):\n init_seq += [1 if n == 0 else 0 for n in init_seq]\n return init_seq[:len(seq)] == seq\n", "def is_thue_morse(seq):\n return all(bin(i).count('1')%2==n for i,n in enumerate(seq))", "sequence =\"0110100110010110100101100110...
{"fn_name": "is_thue_morse", "inputs": [[[0, 1, 1, 0, 1]], [[0]], [[1]], [[0, 1, 0, 0]]], "outputs": [[true], [true], [false], [false]]}
introductory
https://www.codewars.com/kata/589a9792ea93aae1bf00001c
def is_thue_morse(seq):
4,398
Imagine you start on the 5th floor of a building, then travel down to the 2nd floor, then back up to the 8th floor. You have travelled a total of 3 + 6 = 9 floors of distance. Given an array representing a series of floors you must reach by elevator, return an integer representing the total distance travelled for visi...
["def elevator_distance(array):\n return sum(abs(a - b) for a, b in zip(array, array[1:]))", "def elevator_distance(array):\n return sum(abs(array[i+1] - array[i]) for i in range(len(array)-1))", "def elevator_distance(floors):\n return sum(abs(floors[i + 1] - floors[i]) for i in range(len(floors) - 1))", "def...
{"fn_name": "elevator_distance", "inputs": [[[5, 2, 8]], [[1, 2, 3]], [[7, 1, 7, 1]]], "outputs": [[9], [2], [18]]}
introductory
https://www.codewars.com/kata/59f061773e532d0c87000d16
def elevator_distance(array):
4,399
# Task The function `fold_cube(number_list)` should return a boolean based on a net (given as a number list), if the net can fold into a cube. Your code must be effecient and complete the tests within 500ms. ## Input Imagine a net such as the one below. ``` @ @ @ @ @ @ ``` Then, put it on the table with each ...
["def fold_cube(nums):\n return expand(nums.pop(), set(nums), 1, 2, 3) == {1, 2, 3, -1, -2, -3}\n\n\ndef expand(val, nums, x, y, z):\n dirs = {z}\n for num in nums.copy():\n if abs(val - num) not in (1, 5) or {val % 5, num % 5} == {0, 1}:\n continue\n\n nums.discard(num)\n diff ...
{"fn_name": "fold_cube", "inputs": [[[24, 20, 14, 19, 18, 9]], [[1, 7, 6, 17, 12, 16]], [[12, 14, 13, 9, 10, 6]], [[18, 16, 17, 15, 13, 14]], [[1, 25, 24, 2, 3, 16]], [[1, 1, 1, 1, 1, 1]], [[2, 3, 8, 9, 10, 13]]], "outputs": [[true], [false], [false], [true], [false], [false], [true]]}
introductory
https://www.codewars.com/kata/5f2ef12bfb6eb40019cc003e
def fold_cube(nums):
4,400
# Task **_Given_** *an array of N integers, you have to find* **_how many times_** *you have to* **_add up the smallest numbers_** *in the array until* **_their Sum_** *becomes greater or equal to* **_K_**. ___ # Notes: * **_List size_** is *at least 3*. * **_All numbers_** *will be* **_positive_**. * **_Num...
["def minimum_steps(arr, n):\n arr = sorted(arr)\n s = 0\n for i,v in enumerate(arr): \n s += v\n if s >= n: return i", "from itertools import accumulate\n\ndef minimum_steps(numbers, value):\n return next(i for i, s in enumerate(accumulate(sorted(numbers))) if s >= value)", "def minimum_steps...
{"fn_name": "minimum_steps", "inputs": [[[4, 6, 3], 7], [[10, 9, 9, 8], 17], [[8, 9, 10, 4, 2], 23], [[19, 98, 69, 28, 75, 45, 17, 98, 67], 464], [[4, 6, 3], 2]], "outputs": [[1], [1], [3], [8], [0]]}
introductory
https://www.codewars.com/kata/5a91a7c5fd8c061367000002
def minimum_steps(numbers, value):
4,401
In geometry, a cube is a three-dimensional solid object bounded by six square faces, facets or sides, with three meeting at each vertex.The cube is the only regular hexahedron and is one of the five Platonic solids. It has 12 edges, 6 faces and 8 vertices.The cube is also a square parallelepiped, an equilateral cuboid ...
["def you_are_a_cube(cube):\n return round(cube ** (1/3)) ** 3 == cube", "def you_are_a_cube(cube):\n return int(cube**0.33334)**3 == cube", "def you_are_a_cube(cube):\n x = round(abs(cube)**(1/3))\n if x**3 == cube:\n return True\n else:\n return False", "def you_are_a_cube(cube):\n ret...
{"fn_name": "you_are_a_cube", "inputs": [[27], [1], [2], [99], [64]], "outputs": [[true], [true], [false], [false], [true]]}
introductory
https://www.codewars.com/kata/57da5365a82a1998440000a9
def you_are_a_cube(cube):
4,402
In this Kata, we will check if a string contains consecutive letters as they appear in the English alphabet and if each letter occurs only once. ```Haskell Rules are: (1) the letters are adjacent in the English alphabet, and (2) each letter occurs only once. For example: solve("abc") = True, because it contains a,b...
["import string\n\ndef solve(st):\n return ''.join(sorted(st)) in string.ascii_letters", "def solve(s):\n return \"\".join(sorted(s)) in \"abcdefghijklmnopqrstuvwxyz\"", "def solve(s):\n return len(s) == len(set(s)) == ord(max(s)) - ord(min(s)) + 1", "def solve(s):\n return len(s) == ord(max(s)) - ord(min(s))...
{"fn_name": "solve", "inputs": [["abc"], ["abd"], ["dabc"], ["abbc"]], "outputs": [[true], [false], [true], [false]]}
introductory
https://www.codewars.com/kata/5ce6728c939bf80029988b57
def solve(st):
4,403
In computing, there are two primary byte order formats: big-endian and little-endian. Big-endian is used primarily for networking (e.g., IP addresses are transmitted in big-endian) whereas little-endian is used mainly by computers with microprocessors. Here is an example (using 32-bit integers in hex format): Little-...
["def switch_endian(n, bits):\n out = 0\n while bits > 7:\n bits -= 8\n out <<= 8\n out |= n & 255\n n >>= 8\n return None if n or bits else out", "# Bitwise operators? What's that? Don't need it\ndef switch_endian(n, bits):\n if not (0 <= n < 2**bits and bits == 2**(bits.bit_...
{"fn_name": "switch_endian", "inputs": [[153, 8], [255, 8], [256, 8], [1534, 32], [364334, 32], [2, 64], [164345, 64], [23, 128], [256245645346, 128], [6423, 256], [988847589347589798345, 256], [98, 512], [9827498275894278943758934789347, 512], [111, 1024], [859983475894789589772983457982345896389458937589738945435, 10...
introductory
https://www.codewars.com/kata/56f2dd31e40b7042ad001026
def switch_endian(n, bits):
4,404
Section numbers are strings of dot-separated integers. The highest level sections (chapters) are numbered 1, 2, 3, etc. Second level sections are numbered 1.1, 1.2, 1.3, 2.1, 2.2, 2.3, etc. Next level sections are numbered 1.1.1, 1.1.2, 1.1.2, 1.2.1, 1.2.2, erc. There is no bound on the number of sections a document ma...
["def compare(s1, s2):\n v1,v2 = version(s1),version(s2)\n return -1 if v1 < v2 else 1 if v1 > v2 else 0\n\ndef version( s ):\n v = [int(n) for n in s.split(\".\")]\n while( v[-1]==0 ) : v = v[0:-1]\n return v", "def compare(s1, s2):\n s1 , s2 = s1.split('.') , s2.split('.')\n for i in range(abs(le...
{"fn_name": "compare", "inputs": [["1", "2"], ["1.1", "1.2"], ["1.1", "1"], ["1.2.3.4", "1.2.3.4"], ["3", "3.0"], ["3", "3.0.0.0"], ["1.2.1", "1.2.0"], ["3.0.0", "3.1.1"], ["3.0.1", "3.1"], ["1.2.3", "1.02.003"], ["1.20", "1.5"]], "outputs": [[-1], [-1], [1], [0], [0], [0], [1], [-1], [-1], [0], [1]]}
introductory
https://www.codewars.com/kata/5829c6fe7da141bbf000021b
def compare(s1, s2):
4,405
# Palindrome strings A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. This includes capital letters, punctuation, and word dividers. Implement a function that checks if something is a palindrome. ## Examples ``` isPalindrome("anna") ==> true isPalind...
["def is_palindrome(string):\n return str(string)[::-1] == str(string)", "def is_palindrome(string):\n return str(string).lower() == str(string).lower()[::-1]", "def is_palindrome(string):\n return str(string) == str(string)[::-1]", "def is_palindrome(string):\n string=str(string)\n return string==string...
{"fn_name": "is_palindrome", "inputs": [["anna"], ["walter"], [12321], [123456]], "outputs": [[true], [false], [true], [false]]}
introductory
https://www.codewars.com/kata/57a5015d72292ddeb8000b31
def is_palindrome(string):
4,406
Linear Kingdom has exactly one tram line. It has `n` stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. ## Your task Calculate the tram's minimum capacity such that the number o...
["from itertools import accumulate\n\ndef tram(stops, descending, onboarding):\n return max(accumulate(o - d for d, o in zip(descending[:stops], onboarding)))", "def tram(stops, descending, onboarding):\n return max(sum(onboarding[:i])-sum(descending[:i]) for i in range(stops+1))\n", "def tram(stops, descending, ...
{"fn_name": "tram", "inputs": [[4, [0, 2, 4, 4], [3, 5, 2, 0]], [2, [0, 2, 4, 4], [3, 5, 2, 0]], [1, [0, 2, 4, 4], [3, 5, 2, 0]], [10, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]], [5, [0, 2, 4, 14, 2], [3, 5, 14, 0, 0]]], "outputs": [[6], [6], [3], [25], [16]]}
introductory
https://www.codewars.com/kata/5b190aa7803388ec97000054
def tram(stops, descending, onboarding):
4,407
Write a function that accepts two parameters (a and b) and says whether a is smaller than, bigger than, or equal to b. Here is an example code: var noIfsNoButs = function (a,b) { if(a > b) return a + " is greater than " + b else if(a < b) return a + " is smaller than " + b else if(a == b) return a + " is equal t...
["def no_ifs_no_buts(a, b):\n return {\n a == b: str(a) + \" is equal to \" + str(b),\n a < b: str(a) + \" is smaller than \" + str(b),\n a > b: str(a) + \" is greater than \" + str(b),\n }[True]", "def no_ifs_no_buts(a, b):\n return ([\n '%d is smaller than %d',\n '%d is equ...
{"fn_name": "no_ifs_no_buts", "inputs": [[45, 51], [1, 2], [-3, 2], [1, 1], [100, 100], [100, 80], [20, 19]], "outputs": [["45 is smaller than 51"], ["1 is smaller than 2"], ["-3 is smaller than 2"], ["1 is equal to 1"], ["100 is equal to 100"], ["100 is greater than 80"], ["20 is greater than 19"]]}
introductory
https://www.codewars.com/kata/592915cc1fad49252f000006
def no_ifs_no_buts(a, b):
4,408
Description Lets imagine a yoga classroom as a Square 2D Array of Integers ```classroom```, with each integer representing a person, and the value representing their skill level. ``` classroom = [ [3,2,1,3], [1,3,2,1], [1,1,1,2], ] poses = [1,7,5,9,10,21,4,...
["def yoga(classroom, poses):\n total_poses = 0\n for pose in poses:\n for row in classroom:\n for person in row:\n if person + sum(row) >= pose:\n total_poses += 1\n return total_poses", "def yoga(classroom, poses):\n return sum(1 for r in classroom for v...
{"fn_name": "yoga", "inputs": [[[[0, 0], [0, 0]], [1, 1, 0, 1, 2, 3, 0, 1, 5]], [[], [1, 3, 4]], [[[0, 0], [0, 0]], []], [[], []]], "outputs": [[8], [0], [0], [0]]}
introductory
https://www.codewars.com/kata/5c79c07b4ba1e100097f4e1a
def yoga(classroom, poses):
4,409
Spoonerize... with numbers... numberize?... numboonerize?... noonerize? ...anyway! If you don't yet know what a spoonerism is and haven't yet tried my spoonerism kata, please do [check it out](http://www.codewars.com/kata/spoonerize-me) first. You will create a function which takes an array of two positive integers, ...
["def noonerize(numbers):\n \n try:\n num1 = int(str(numbers[1])[0] + str(numbers[0])[1:])\n num2 = int(str(numbers[0])[0] + str(numbers[1])[1:])\n except ValueError:\n return \"invalid array\"\n \n return abs(num1 - num2)", "def noonerize(numbers):\n if not all(isinstance(n, ...
{"fn_name": "noonerize", "inputs": [[[12, 34]], [[55, 63]], [[357, 579]], [[1000000, 9999999]], [[1000000, "hello"]], [["pippi", 9999999]], [["pippi", "hello"]], [[1, 1]], [[1, 0]], [[0, 1]]], "outputs": [[18], [12], [178], [7000001], ["invalid array"], ["invalid array"], ["invalid array"], [0], [1], [1]]}
introductory
https://www.codewars.com/kata/56dbed3a13c2f61ae3000bcd
def noonerize(numbers):
4,410
.task { background: #fff; color: #333; padding: 25px; box-sizing: border-box; font-family: Comfortaa, sans-serif !important; position: relative; } .task code, .task_code { display: inline-block; padding: 0; border-radius: 2px; margin: 0; position: relative; top: 6px; background: bisque; bord...
["from math import floor, log\ndef count_sixes(n):\n return floor((n - n % 2) * log(2, 10))", "count_sixes=lambda n:len(str(1<<n-n%2))-1", "from math import log10, floor, log\n\ndef count_sixes(n):\n k = floor(log10(3) + (n - 1)*log10(2))\n return k - (k*log(10) > (n - (n & 1))*log(2))\n\n# x[n] = 2/3 + d if n is ...
{"fn_name": "count_sixes", "inputs": [[10]], "outputs": [[3]]}
introductory
https://www.codewars.com/kata/582110dc2fd420bf7f00117b
def count_sixes(n):
4,411
# Background: You're working in a number zoo, and it seems that one of the numbers has gone missing! Zoo workers have no idea what number is missing, and are too incompetent to figure it out, so they're hiring you to do it for them. In case the zoo loses another number, they want your program to work regardless of h...
["def find_missing_number(a):\n n = len(a) + 1\n return n * (n + 1) // 2 - sum(a)", "def find_missing_number(numbers):\n if numbers == []:return 1\n diff = list(set(range(1, len(numbers)+1))- set(numbers))\n if diff == []:return max(numbers)+1\n return diff[0]", "def find_missing_number(nums):\n re...
{"fn_name": "find_missing_number", "inputs": [[[2, 3, 4]], [[1, 3, 4]], [[1, 2, 4]], [[1, 2, 3]], [[]], [[1]], [[2]]], "outputs": [[1], [2], [3], [4], [1], [2], [1]]}
introductory
https://www.codewars.com/kata/5276c18121e20900c0000235
def find_missing_number(numbers):
4,412
We have the integer `9457`. We distribute its digits in two buckets having the following possible distributions (we put the generated numbers as strings and we add the corresponding formed integers for each partition): ``` - one bucket with one digit and the other with three digits [['9'], ['4','5','7']] --> ['9','4...
["def subsets(collection):\n if len(collection) == 1:\n yield [collection]\n return\n\n first = collection[0]\n for smaller in subsets(collection[1:]):\n yield [first] + smaller\n for n, subset in enumerate(smaller):\n yield smaller[:n] + [first + subset] + smaller[n+1:]...
{"fn_name": "find", "inputs": [[500, 200], [1000, 2000], [3000, 1000], [5200, 500], [10001, 100], [30000, 1000]], "outputs": [[888], [1987], [3388], [5288], [10003], [30046]]}
introductory
https://www.codewars.com/kata/5b74e28e69826c336e00002a
def find(n,z):
4,413
## Task Complete function `splitOddAndEven`, accept a number `n`(n>0), return an array that contains the continuous parts of odd or even digits. Please don't worry about digit `0`, it won't appear ;-) ## Examples
["def split_odd_and_even(n):\n \n import re\n \n return [int(i) for i in re.findall(r\"[2468]+|[13579]+\", str(n))]", "from itertools import groupby\n\ndef split_odd_and_even(n):\n return [int(\"\".join(g))\n for i, g in groupby(str(n), key=lambda x: int(x) % 2)]", "import re\ndef split_odd_and_even...
{"fn_name": "split_odd_and_even", "inputs": [[123], [223], [111], [13579], [2468642], [135246], [123456], [8123456], [82123456], [88123456]], "outputs": [[[1, 2, 3]], [[22, 3]], [[111]], [[13579]], [[2468642]], [[135, 246]], [[1, 2, 3, 4, 5, 6]], [[8, 1, 2, 3, 4, 5, 6]], [[82, 1, 2, 3, 4, 5, 6]], [[88, 1, 2, 3, 4, 5, 6...
introductory
https://www.codewars.com/kata/57a2ab1abb994466910003af
def split_odd_and_even(n):
4,414
Karan's company makes software that provides different features based on the version of operating system of the user. For finding which version is more recent, Karan uses the following method: While this function worked for OS versions 10.6, 10.7, 10.8 and 10.9, the Operating system company just released OS version 1...
["def compare_versions(ver1,ver2):\n return [int(i) for i in ver1.split(\".\")] >= [int(i) for i in ver2.split(\".\")]\n", "def compare_versions(version1,version2):\n from distutils.version import LooseVersion, StrictVersion\n return LooseVersion(version1) >= LooseVersion(version2)\n", "from distutils.version ...
{"fn_name": "compare_versions", "inputs": [["11", "10"], ["11", "11"], ["10.4.6", "10.4"], ["10.4", "10.4.8"], ["10.4", "11"], ["10.4.9", "10.5"], ["4.3.3", "4.3.3.1"], ["10.4.9", "104.9"], ["10.15", "10.12"]], "outputs": [[true], [true], [true], [false], [false], [false], [false], [false], [true]]}
introductory
https://www.codewars.com/kata/53b138b3b987275b46000115
def compare_versions(version1, version2):
4,415
We have an array with string digits that occurrs more than once, for example, ```arr = ['1', '2', '2', '2', '3', '3']```. How many different string numbers can be generated taking the 6 elements at a time? We present the list of them below in an unsorted way: ``` ['223213', '312322', '223312', '222133', '312223', '22...
["from operator import mul\nfrom math import factorial\nfrom functools import reduce\nfrom collections import Counter\n\ndef proc_arr(arr):\n s = ''.join(sorted(arr))\n return [factorial(len(arr)) // reduce(mul, list(map(factorial, list(Counter(arr).values())))), int(s), int(s[::-1])]\n", "from math import factor...
{"fn_name": "proc_arr", "inputs": [[["1", "2", "2", "3", "2", "3"]]], "outputs": [[[60, 122233, 332221]]]}
introductory
https://www.codewars.com/kata/584d05422609c8890f0000be
def proc_arr(arr):
4,416
Welcome young Jedi! In this Kata you must create a function that takes an amount of US currency in `cents`, and returns a dictionary/hash which shows the least amount of coins used to make up that amount. The only coin denominations considered in this exercise are: `Pennies (1¢), Nickels (5¢), Dimes (10¢) and Quarters ...
["import math\n\ndef loose_change(cents):\n if cents < 0:\n cents = 0\n cents = int(cents)\n \n change = {}\n\n change['Quarters'] = cents // 25\n cents = cents % 25\n\n change['Dimes'] = cents // 10\n cents = cents % 10\n\n change['Nickels'] = cents // 5\n cents = cents % 5\n \n...
{"fn_name": "loose_change", "inputs": [[56], [0], [100], [-3], [7.9]], "outputs": [[{"Nickels": 1, "Pennies": 1, "Dimes": 0, "Quarters": 2}], [{"Nickels": 0, "Pennies": 0, "Dimes": 0, "Quarters": 0}], [{"Nickels": 0, "Pennies": 0, "Dimes": 0, "Quarters": 4}], [{"Nickels": 0, "Pennies": 0, "Dimes": 0, "Quarters": 0}], [...
introductory
https://www.codewars.com/kata/5571f712ddf00b54420000ee
def loose_change(cents):
4,417
Consider the prime number `23`. If we sum the square of its digits we get: `2^2 + 3^2 = 13`, then for `13: 1^2 + 3^2 = 10`, and finally for `10: 1^2 + 0^2 = 1`. Similarly, if we start with prime number `7`, the sequence is: `7->49->97->130->10->1`. Given a range, how many primes within that range will eventually end...
["def is_prime(n):\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % 2 == 0 or n % 3 == 0:\n return False\n sqrtn = int(n**0.5) + 1\n for i in range(5, sqrtn, 6):\n if n % i == 0 or n % (i + 2) == 0:\n return False\n return True\n\ndef end_one(n):\n...
{"fn_name": "solve", "inputs": [[1, 25], [100, 1000], [100, 2000], [100, 3000], [100, 4000]], "outputs": [[4], [28], [47], [65], [95]]}
introductory
https://www.codewars.com/kata/59aa6567485a4d03ff0000ca
def solve(a,b):
4,418
This is a follow-up from my previous Kata which can be found here: http://www.codewars.com/kata/5476f4ca03810c0fc0000098 This time, for any given linear sequence, calculate the function [f(x)] and return it as a function in Javascript or Lambda/Block in Ruby. For example: ```python get_function([0, 1, 2, 3, 4])(5) =...
["def get_function(sequence):\n slope = sequence[1] - sequence[0]\n for x in range(1,5):\n if sequence[x] - sequence[x-1] != slope:\n return \"Non-linear sequence\"\n \n return lambda a : slope * a + sequence[0]", "def get_function(sequence):\n first, dist = sequence[0], sequence[1] - seq...
{"fn_name": "get_function", "inputs": [[[1, 2, 4, 7, 11]], [[0, 1, 2, 3, 100000]], [[0, 1, 2, 100000, 4]], [[0, 1, 100000, 3, 4]], [[0, 100000, 2, 3, 4]]], "outputs": [["Non-linear sequence"], ["Non-linear sequence"], ["Non-linear sequence"], ["Non-linear sequence"], ["Non-linear sequence"]]}
introductory
https://www.codewars.com/kata/54784a99b5339e1eaf000807
def get_function(sequence):
4,419
Perhaps it would be convenient to solve first ```Probabilities for Sums in Rolling Cubic Dice``` see at: http://www.codewars.com/kata/probabilities-for-sums-in-rolling-cubic-dice Suppose that we roll dice that we never used, a tetrahedral die that has only 4 sides(values 1 to 4), or perhaps better the dodecahedral one...
["def reg_sum_hits(dices,sides=6):\n d,s = sides*[1],sides-1\n for i in range(dices-1):\n t = s*[0] + d + s*[0]\n d = [sum(t[i:i+sides]) for i in range(len(t)-s)]\n return [[i+dices, prob] for (i,prob) in enumerate(d)]", "reg_sum_hits=lambda n,s:sorted(map(list,__import__('collections').Counter(m...
{"fn_name": "reg_sum_hits", "inputs": [[3, 4], [4, 4], [3, 6], [4, 6]], "outputs": [[[[3, 1], [4, 3], [5, 6], [6, 10], [7, 12], [8, 12], [9, 10], [10, 6], [11, 3], [12, 1]]], [[[4, 1], [5, 4], [6, 10], [7, 20], [8, 31], [9, 40], [10, 44], [11, 40], [12, 31], [13, 20], [14, 10], [15, 4], [16, 1]]], [[[3, 1], [4, 3], [5,...
introductory
https://www.codewars.com/kata/56f852635d7c12fb610013d7
def reg_sum_hits(n, s):
4,420
Every number may be factored in prime factors. For example, the number 18 may be factored by its prime factors ``` 2 ``` and ```3``` ``` 18 = 2 . 3 . 3 = 2 . 3² ``` The sum of the prime factors of 18 is ```2 + 3 + 3 = 8``` But some numbers like 70 are divisible by the sum of its prime factors: ``` 70 = 2 . 5 . 7 # s...
["def mult_primefactor_sum(a, b): \n s=[]\n for i in range(a,b+1):\n r=factorize_add(i)\n if r!=i and i%r==0: s.append(i)\n return s\n \ndef factorize_add(num):\n if num<4: return num\n d=2; p=0\n while d<num**.5+1:\n while not num%d: p+=d; num/=d\n d+=1 if d==2 else 2\n ...
{"fn_name": "mult_primefactor_sum", "inputs": [[10, 100], [80, 150], [90, 200]], "outputs": [[[16, 27, 30, 60, 70, 72, 84]], [[84, 105, 150]], [[105, 150, 180]]]}
introductory
https://www.codewars.com/kata/5626ec066d35051d4500009e
def mult_primefactor_sum(a, b):
4,421
Implement a class/function, which should parse time expressed as `HH:MM:SS`, or `null/nil/None` otherwise. Any extra characters, or minutes/seconds higher than 59 make the input invalid, and so should return `null/nil/None`.
["def to_seconds(time):\n try:\n s, m, h = int(time[-2:]), int(time[3:5]), int(time[:2])\n return s + m*60 + h*3600 if m < 60 and s < 60 and len(time) == 8 else None\n except:\n return None", "import re\n\n\ndef to_seconds(time):\n if bool(re.match('[0-9][0-9]:[0-5][0-9]:[0-5][0-9]\\Z', ti...
{"fn_name": "to_seconds", "inputs": [["00:00:00"], ["01:02:03"], ["01:02:60"], ["01:60:03"], ["99:59:59"], ["0:00:00"], ["00:0:00"], ["00:00:0"], ["00:00:00\n"], ["\n00:00:00"], ["100:59:59"], ["09:059:59"], ["09:159:59"], ["09:59:059"], ["09:59:159"]], "outputs": [[0], [3723], [null], [null], [359999], [null], [null],...
introductory
https://www.codewars.com/kata/568338ea371e86728c000002
def to_seconds(time):
4,422
Welcome This kata is inspired by This Kata We have a string s We have a number n Here is a function that takes your string, concatenates the even-indexed chars to the front, odd-indexed chars to the back. Examples s = "Wow Example!" result = "WwEapeo xml!" s = "I'm JomoPipi" result = "ImJm ii' oo...
["def jumbled_string(s, n):\n iterations = [s]\n \n while True:\n s = s[::2] + s[1::2]\n if s == iterations[0]: break\n iterations.append(s)\n \n return iterations[n % len(iterations)]", "#Kata: String -> N iterations -> String Rating 5kyu\n\n\n#To optimize this problem, we must loo...
{"fn_name": "jumbled_string", "inputs": [["Such Wow!", 1], ["better example", 2], ["qwertyuio", 2], ["Greetings", 8], ["I like it!", 1234], ["codingisfornerdsyounerd", 10101010], ["this_test_will_hurt_you", 12345678987654321]], "outputs": [["Sc o!uhWw"], ["bexltept merae"], ["qtorieuwy"], ["Gtsegenri"], ["Iiei t kl!"],...
introductory
https://www.codewars.com/kata/5ae43ed6252e666a6b0000a4
def jumbled_string(s, n):
4,423
In the previous Kata we discussed the OR case. We will now discuss the AND case, where rather than calculating the probablility for either of two (or more) possible results, we will calculate the probability of receiving all of the viewed outcomes. For example, if we want to know the probability of receiving head OR ...
["from collections import Counter as C\ndef ball_probability(b):\n d, n, p = C(b[0]), len(b[0]), 1\n for i in b[1]:\n p *= d.get(i,0)/n\n n -= b[2]^1\n d[i] -= b[2]^1\n return round(p,3)", "def ball_probability(balls):\n colors, (first, second), replaced = balls\n first_c...
{"fn_name": "ball_probability", "inputs": [[[["red", "blue", "yellow", "green", "red", "blue", "yellow", "green", "red", "blue"], ["red", "blue"], true]], [[["red", "blue", "yellow", "green", "red", "blue", "yellow", "green", "red", "blue"], ["red", "red"], true]], [[["red", "red", "yellow", "green", "red", "red", "yel...
introductory
https://www.codewars.com/kata/576a527ea25aae70b7000c77
def ball_probability(balls):
4,424
# Task * **_Given_** *three integers* `a` ,`b` ,`c`, **_return_** *the **_largest number_** obtained after inserting the following operators and brackets*: `+`, `*`, `()` * In other words , **_try every combination of a,b,c with [*+()] , and return the Maximum Obtained_** ___ # Consider an Example : **_With the numbe...
["def expression_matter(a, b, c):\n return max(a*b*c, a+b+c, (a+b)*c, a*(b+c))", "def expression_matter(a, b, c):\n return max(a + b + c, (a + b) * c, a * (b + c), a * b * c)", "def expression_matter(a, b, c):\n cases = [a + b + c]\n cases.append(a * b * c)\n cases.append((a * b) + c)\n cases.append(...
{"fn_name": "expression_matter", "inputs": [[2, 1, 2], [2, 1, 1], [1, 1, 1], [1, 2, 3], [1, 3, 1], [2, 2, 2], [5, 1, 3], [3, 5, 7], [5, 6, 1], [1, 6, 1], [2, 6, 1], [6, 7, 1], [2, 10, 3], [1, 8, 3], [9, 7, 2], [1, 1, 10], [9, 1, 1], [10, 5, 6], [1, 10, 1]], "outputs": [[6], [4], [3], [9], [5], [8], [20], [105], [35], [...
introductory
https://www.codewars.com/kata/5ae62fcf252e66d44d00008e
def expression_matter(a, b, c):
4,425
There's a **"3 for 2"** (or **"2+1"** if you like) offer on mangoes. For a given quantity and price (per mango), calculate the total cost of the mangoes. ### Examples ```python mango(3, 3) ==> 6 # 2 mangoes for 3 = 6; +1 mango for free mango(9, 5) ==> 30 # 6 mangoes for 5 = 30; +3 mangoes for free ```
["def mango(quantity, price):\n return (quantity - quantity // 3) * price", "def mango(quantity, price):\n return ((quantity - int(quantity/3)) * price)", "def mango(quantity, price):\n batch = quantity//3 \n total = (batch * 2 + quantity%3 ) * price \n return total", "def mango(quantity, price):\n return ...
{"fn_name": "mango", "inputs": [[3, 3], [9, 5]], "outputs": [[6], [30]]}
introductory
https://www.codewars.com/kata/57a77726bb9944d000000b06
def mango(quantity, price):
4,426
Your task it to return ```true``` if the fractional part (rounded to 1 digit) of the result (```a``` / ```b```) exists, more than ```0``` and is multiple of ```n```. Otherwise return ```false```. (For Python return True or False) All arguments are positive digital numbers. Rounding works like toFixed() method. (if mo...
["def isMultiple(a, b, n):\n remainder = int((a / b + 0.05) * 10) % 10\n return remainder > 0 and remainder % n == 0", "def isMultiple(a, b, n):\n frac_part = int(10.0 * (a / b - a // b) + 0.5) % 10\n return frac_part != 0 and frac_part % n == 0", "isMultiple=lambda a,b,n:(lambda d:d>0==d%n)((20*a/b+1)//2%1...
{"fn_name": "isMultiple", "inputs": [[5, 2, 3], [5, 3, 4], [5, 4, 3], [666, 665, 2], [3691401, 1892272, 5]], "outputs": [[false], [false], [true], [false], [false]]}
introductory
https://www.codewars.com/kata/5a2f83daee1aae4f1c00007e
def isMultiple(a, b, n):
4,427
# Task Given an array of integers, sum consecutive even numbers and consecutive odd numbers. Repeat the process while it can be done and return the length of the final array. # Example For `arr = [2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]` The result should be `6`. ``` [2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7...
["from itertools import groupby\n\ndef sum_groups(arr):\n newarr = [sum(j) for i,j in groupby(arr, key = lambda x: x % 2 == 0)]\n return len(newarr) if newarr == arr else sum_groups(newarr)", "def sum_groups(arr):\n lenArr, arr = -1, arr[:]\n while lenArr != len(arr):\n parity, lenArr, next = -1, len...
{"fn_name": "sum_groups", "inputs": [[[2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]], [[2, 1, 2, 2, 6, 5, 0, 2, 0, 3, 3, 3, 9, 2]], [[2]], [[1, 2]], [[1, 1, 2, 2]]], "outputs": [[6], [5], [1], [2], [1]]}
introductory
https://www.codewars.com/kata/58b3c2bd917a5caec0000017
def sum_groups(arr):
4,428
In this kata you're expected to sort an array of 32-bit integers in ascending order of the number of **on** bits they have. E.g Given the array **[7, 6, 15, 8]** - 7 has **3 on** bits (000...0**111**) - 6 has **2 on** bits (000...00**11**) - 15 has **4 on** bits (000...**1111**) - 8 has **1 on** bit (000...**1**0...
["def sort_by_bit(arr): \n return sorted(arr, key=lambda x: (bin(x).count(\"1\"), x))", "def sort_by_bit(a):\n return sorted(a, key=lambda x: (bin(x).count(\"1\"), x))", "def sort_by_bit(arr): \n return sorted(arr, key=lambda n: (bin(n).count(\"1\"), n))", "def sort_by_bit(lst): \n return sorted(lst, key=la...
{"fn_name": "sort_by_bit", "inputs": [[[3, 8, 3, 6, 5, 7, 9, 1]], [[9, 4, 5, 3, 5, 7, 2, 56, 8, 2, 6, 8, 0]]], "outputs": [[[1, 8, 3, 3, 5, 6, 9, 7]], [[0, 2, 2, 4, 8, 8, 3, 5, 5, 6, 9, 7, 56]]]}
introductory
https://www.codewars.com/kata/59fa8e2646d8433ee200003f
def sort_by_bit(arr):
4,429
A palindrome is a series of characters that read the same forwards as backwards such as "hannah", "racecar" and "lol". For this Kata you need to write a function that takes a string of characters and returns the length, as an integer value, of longest alphanumeric palindrome that could be made by combining the charact...
["from collections import Counter\n\ndef longest_palindrome(s):\n c = Counter(filter(str.isalnum, s.lower()))\n return sum(v//2*2 for v in c.values()) + any(v%2 for v in c.values())", "from collections import Counter\nimport re\n\ndef longest_palindrome(s):\n n, odds, c = 0, 0, Counter(re.sub(r'\\W+|_', '', s....
{"fn_name": "longest_palindrome", "inputs": [["A"], ["Hannah"], ["xyz__a_/b0110//a_zyx"], ["$aaabbbccddd_!jJpqlQx_.///yYabababhii_"], [""]], "outputs": [[1], [6], [13], [25], [0]]}
introductory
https://www.codewars.com/kata/5a0178f66f793bc5b0001728
def longest_palindrome(s):
4,430
Write a function ```python vowel_2_index``` that takes in a string and replaces all the vowels [a,e,i,o,u] with their respective positions within that string. E.g: ```python vowel_2_index('this is my string') == 'th3s 6s my str15ng' vowel_2_index('Codewars is the best site in the world') == 'C2d4w6rs 10s th15 b18...
["def vowel_2_index(string):\n vowels = 'aeiouAEIOU'\n return ''.join(x if x not in vowels else str(n + 1) for n,x in enumerate(string))", "import re\n\ndef vowel_2_index(string):\n return re.sub(\"[aeiou]\",lambda m:str(m.end()),string,0,re.I)", "def vowel_2_index(string):\n vowels = frozenset('aeiouAEIOU')\...
{"fn_name": "vowel_2_index", "inputs": [["this is my string"], ["Codewars is the best site in the world"], ["Tomorrow is going to be raining"], [""], ["90's cornhole Austin, pickled butcher yr messenger bag gastropub next level leggings listicle meditation try-hard Vice. Taxidermy gastropub gentrify, meh fap organic en...
introductory
https://www.codewars.com/kata/55d410c492e6ed767000004f
def vowel_2_index(string):
4,431
You have managed to intercept an important message and you are trying to read it. You realise that the message has been encoded and can be decoded by switching each letter with a corresponding letter. You also notice that each letter is paired with the letter that it coincides with when the alphabet is reversed. For...
["from string import ascii_lowercase as alphabet\n\n\ndef decode(message):\n return message.translate(str.maketrans(alphabet, alphabet[::-1]))", "def decode(message):\n return message.translate(str.maketrans('abcdefghijklmnopqrstuvwxyz','zyxwvutsrqponmlkjihgfedcba'))", "def decode(message):\n return ''.join([c...
{"fn_name": "decode", "inputs": [["sr"], ["svool"], ["r slkv mlylwb wvxlwvh gsrh nvhhztv"], ["qzezxirkg rh z srts ovevo wbmznrx fmgbkvw zmw rmgvikivgvw kiltiznnrmt ozmtfztv rg szh yvvm hgzmwziwravw rm gsv vxnzxirkg ozmtfztv hkvxrurxzgrlm zolmthrwv sgno zmw xhh rg rh lmv lu gsv gsivv vhhvmgrzo gvxsmloltrvh lu dliow drwv...
introductory
https://www.codewars.com/kata/565b9d6f8139573819000056
def decode(message):
4,432
Jump is a simple one-player game: You are initially at the first cell of an array of cells containing non-negative integers; At each step you can jump ahead in the array as far as the integer at the current cell, or any smaller number of cells. You win if there is a path that allows you to jump from one cell to anoth...
["def can_jump(arr):\n if arr[0] == 0 or len(arr) == 1:\n return False\n \n if arr[0] >= len(arr):\n return True\n \n for jump in range(1, arr[0] +1):\n if can_jump(arr[jump:]):\n return True\n \n return False\n", "def can_jump(arr):\n last = len(arr)\n for i i...
{"fn_name": "can_jump", "inputs": [[[11, 6, 11, 0, 2, 1, 14, 3, 7, 6, 2, 1, 10, 6, 0, 0, 8, 10, 2, 12, 13, 11, 14, 6, 1, 4, 14, 3, 10, 4, 14, 2, 3, 10, 8, 13, 14, 8, 2, 13, 11, 14, 0, 1, 6, 2, 1, 6, 8, 2, 0, 12, 4, 9, 2, 6, 8, 14, 4, 14, 4, 10, 8, 7, 12, 11, 0, 3, 8, 0, 13, 9, 9, 11, 10, 13, 12, 1, 0, 10, 14, 6, 1, 11,...
introductory
https://www.codewars.com/kata/594fae1a0462da7beb000046
def can_jump(arr):
4,433
Your task is to calculate logical value of boolean array. Test arrays are one-dimensional and their size is in the range 1-50. Links referring to logical operations: [AND](https://en.wikipedia.org/wiki/Logical_conjunction), [OR](https://en.wikipedia.org/wiki/Logical_disjunction) and [XOR](https://en.wikipedia.org/wiki...
["import operator\nfrom functools import reduce\n\nOPS = {\n \"AND\": operator.and_,\n \"OR\" : operator.or_,\n \"XOR\": operator.xor\n}\n\ndef logical_calc(array, op):\n return reduce(OPS[op], array)\n", "from operator import and_, or_, xor\nfrom functools import reduce\n\nOPERATOR = {'AND': and_, 'OR': or...
{"fn_name": "logical_calc", "inputs": [[[true, true, true, false], "AND"], [[true, true, true, false], "OR"], [[true, true, true, false], "XOR"], [[true, true, false, false], "AND"], [[true, true, false, false], "OR"], [[true, true, false, false], "XOR"], [[true, false, false, false], "AND"], [[true, false, false, fals...
introductory
https://www.codewars.com/kata/57096af70dad013aa200007b
def logical_calc(array, op):
4,434
You need to write a function, that returns the first non-repeated character in the given string. For example for string `"test"` function should return `'e'`. For string `"teeter"` function should return `'r'`. If a string contains all unique characters, then return just the first character of the string. Exa...
["def first_non_repeated(s):\n return next((c for c in s if s.count(c) == 1), None)", "def first_non_repeated(s):\n for c in s:\n if s.count(c) == 1: return c", "from collections import Counter\n\ndef first_non_repeated(s):\n return next((k for k,v in Counter(s).items() if v==1), None)", "def first_non_...
{"fn_name": "first_non_repeated", "inputs": [["test"], ["teeter"], ["1122321235121222"], ["rend"]], "outputs": [["e"], ["r"], ["5"], ["r"]]}
introductory
https://www.codewars.com/kata/570f6436b29c708a32000826
def first_non_repeated(s):
4,435
Similarly to the [previous kata](https://www.codewars.com/kata/string-subpattern-recognition-i/), you will need to return a boolean value if the base string can be expressed as the repetition of one subpattern. This time there are two small changes: * if a subpattern has been used, it will be repeated at least twice,...
["from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\ndef has_subpattern(string):\n return reduce(gcd, Counter(string).values()) != 1", "from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\ndef has_subpattern(s):\n return reduce(gcd, Counter(s)....
{"fn_name": "has_subpattern", "inputs": [["a"], ["aaaa"], ["abcd"], ["babababababababa"], ["ababababa"], ["123a123a123a"], ["123A123a123a"], ["12aa13a21233"], ["12aa13a21233A"], ["abcdabcaccd"]], "outputs": [[false], [true], [false], [true], [false], [true], [false], [true], [false], [false]]}
introductory
https://www.codewars.com/kata/5a4a391ad8e145cdee0000c4
def has_subpattern(string):
4,436
# Task Your task is to find the sum for the range `0 ... m` for all powers from `0 ... n. # Example For `m = 2, n = 3`, the result should be `20` `0^0+1^0+2^0 + 0^1+1^1+2^1 + 0^2+1^2+2^2 + 0^3+1^3+2^3 = 20` Note, that no output ever exceeds 2e9. # Input/Output - `[input]` integer m `0 <= m <= 50000` ...
["def S2N(m, n):\n return sum(i**j for i in range(m+1) for j in range(n+1))", "def S2N(m,n):\n return sum((a**(n+1)-1)//(a-1) if a!=1 else n+1 for a in range(m+1))", "def S2N(m, n):\n result = 0\n for x in range(n+1):\n for y in range(m+1):\n result += y**x\n return result", "def S2N(m,n):\n ret...
{"fn_name": "S2N", "inputs": [[2, 3], [3, 5], [10, 9], [1, 1], [0, 0], [300, 2], [567, 2], [37, 4], [36, 4]], "outputs": [[20], [434], [1762344782], [3], [1], [9090501], [61083856], [15335280], [13409059]]}
introductory
https://www.codewars.com/kata/58a6742c14b042a042000038
def S2N(m, n):
4,437
For this problem you must create a program that says who ate the last cookie. If the input is a string then "Zach" ate the cookie. If the input is a float or an int then "Monica" ate the cookie. If the input is anything else "the dog" ate the cookie. The way to return the statement is: "Who ate the last cookie? It was ...
["def cookie(x):\n return \"Who ate the last cookie? It was %s!\" % {str:\"Zach\", float:\"Monica\", int:\"Monica\"}.get(type(x), \"the dog\")", "def cookie(x):\n try:\n who = {int: 'Monica', float: 'Monica', str: 'Zach'}[type(x)]\n except KeyError:\n who = 'the dog'\n return 'Who ate the last...
{"fn_name": "cookie", "inputs": [["Ryan"], [2.3], [26], [true], ["True"], [false], [1.98528462]], "outputs": [["Who ate the last cookie? It was Zach!"], ["Who ate the last cookie? It was Monica!"], ["Who ate the last cookie? It was Monica!"], ["Who ate the last cookie? It was the dog!"], ["Who ate the last cookie? It w...
introductory
https://www.codewars.com/kata/55a996e0e8520afab9000055
def cookie(x):
4,438
For this kata, you are given three points ```(x1,y1,z1)```, ```(x2,y2,z2)```, and ```(x3,y3,z3)``` that lie on a straight line in 3-dimensional space. You have to figure out which point lies in between the other two. Your function should return 1, 2, or 3 to indicate which point is the in-between one.
["def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):\n return sorted(((x1, y1, z1, 1), (x2, y2, z2, 2), (x3, y3, z3, 3)))[1][3]\n", "def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):\n return max(\n ((x2-x3)**2 + (y2-y3)**2 + (z2-z3)**2, 1),\n ((x1-x3)**2 + (y1-y3)**2 + (z1-z3)**2, 2),\n ...
{"fn_name": "middle_point", "inputs": [[1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 0, 6, -2, 8, 3, 0, 4], [0.25, 0.5, 0.75, 3.25, -0.5, -0.25, 1.0, 0.25, 0.5], [1, 0, 4, 5, 0, 6, -7, 0, 0], [-1, 0, 2, -2, 4, -1, -3, 8, -4]], "outputs": [[2], [3], [3], [1], [2]]}
introductory
https://www.codewars.com/kata/58a672d6426bf38be4000057
def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):
4,439
# Task Find the integer from `a` to `b` (included) with the greatest number of divisors. For example: ``` divNum(15, 30) ==> 24 divNum(1, 2) ==> 2 divNum(0, 0) ==> 0 divNum(52, 156) ==> 120 ``` If there are several numbers that have the same (maximum) number of divisors, the smallest among them should be ...
["import numpy as np\ns = np.ones(100000)\nfor i in range(2, 100000):\n s[i::i] += 1\n\ndef div_num(a, b):\n return max(range(a, b+1), key=lambda i: (s[i], -i), default='Error')", "def div_num(a, b):\n return 'Error' if a > b else sorted([i for i in range(a, b + 1)], key=lambda k:(-divisors(k), k))[0]\n \nd...
{"fn_name": "div_num", "inputs": [[15, 30], [1, 2], [52, 156], [159, 4], [15, 48]], "outputs": [[24], [2], [120], ["Error"], [48]]}
introductory
https://www.codewars.com/kata/588c0a38b7cd14085300003f
def div_num(a, b):
4,440
ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but **exactly** 4 digits or exactly 6 digits. If the function is passed a valid PIN string, return `true`, else return `false`. ## Examples ``` "1234" --> true "12345" --> false "a234" --> false ```
["def validate_pin(pin):\n return len(pin) in (4, 6) and pin.isdigit()", "def validate_pin(pin):\n return len(pin) in [4, 6] and pin.isdigit()\n", "validate_pin = lambda pin: len(pin) in (4, 6) and pin.isdigit()", "def merge(array1,array2):\n array3 = []\n i = 0\n j = 0\n while (i < len(array1) and j ...
{"fn_name": "validate_pin", "inputs": [["1"], ["12"], ["123"], ["12345"], ["1234567"], ["-1234"], ["-12345"], ["1.234"], ["00000000"], ["a234"], [".234"], ["1234"], ["0000"], ["1111"], ["123456"], ["098765"], ["000000"], ["090909"]], "outputs": [[false], [false], [false], [false], [false], [false], [false], [false], [f...
introductory
https://www.codewars.com/kata/55f8a9c06c018a0d6e000132
def validate_pin(pin):
4,441
Lot of junior developer can be stuck when they need to change the access permission to a file or a directory in an Unix-like operating systems. To do that they can use the `chmod` command and with some magic trick they can change the permissionof a file or a directory. For more information about the `chmod` command yo...
["def chmod_calculator(perm):\n perms = { \"r\": 4, \"w\": 2, \"x\": 1 }\n value = \"\"\n for permission in [\"user\", \"group\", \"other\"]:\n value += str(sum(perms.get(x, 0) for x in perm.get(permission, \"\")))\n \n return value", "def chmod_calculator(perm): \n return str(sum([wbin(...
{"fn_name": "chmod_calculator", "inputs": [[{"user": "rwx", "group": "r-x", "other": "r-x"}], [{"user": "rwx", "group": "r--", "other": "r--"}], [{"user": "r-x", "group": "r-x", "other": "---"}], [{"group": "rwx"}], [{}]], "outputs": [["755"], ["744"], ["550"], ["070"], ["000"]]}
introductory
https://www.codewars.com/kata/57f4ccf0ab9a91c3d5000054
def chmod_calculator(perm):
4,442
Your task is very simple. Given an input string s, case\_sensitive(s), check whether all letters are lowercase or not. Return True/False and a list of all the entries that are not lowercase in order of their appearance in s. For example, case\_sensitive('codewars') returns [True, []], but case\_sensitive('codeWaRs') r...
["def case_sensitive(s):\n return [s.islower() or not s, [c for c in s if c.isupper()]]", "l,case_sensitive=lambda s:[not any(s),s],lambda s:l([x for x in s if x.isupper()])", "def case_sensitive(s):l=list(filter(str.isupper,s));return[not l,l]", "def case_sensitive(s):\n return [not s or s.islower(), [c for c in...
{"fn_name": "case_sensitive", "inputs": [["asd"], ["cellS"], ["z"], [""]], "outputs": [[[true, []]], [[false, ["S"]]], [[true, []]], [[true, []]]]}
introductory
https://www.codewars.com/kata/5a805631ba1bb55b0c0000b8
def case_sensitive(s):
4,443
You throw a ball vertically upwards with an initial speed `v (in km per hour)`. The height `h` of the ball at each time `t` is given by `h = v*t - 0.5*g*t*t` where `g` is Earth's gravity `(g ~ 9.81 m/s**2)`. A device is recording at every **tenth of second** the height of the ball. For example with `v = 15 km/h` the de...
["\"\"\"\nh = vt-0.5gt^2\nlet h = 0 [that is, when the ball has returned to the ground]\n=> 0 = vt-0.5gt^2\n=> 0.5gt^2 = vt\n=> 0.5gt = v\n=> t = 2v/g - the total time the ball is in the air.\n=> t at max height = v/g\n\"\"\"\n\ndef max_ball(v0):\n return round(10*v0/9.81/3.6)", "def max_ball(v0):\n return round...
{"fn_name": "max_ball", "inputs": [[37], [45], [99], [85], [136], [52], [16], [127], [137], [14]], "outputs": [[10], [13], [28], [24], [39], [15], [5], [36], [39], [4]]}
introductory
https://www.codewars.com/kata/566be96bb3174e155300001b
def max_ball(v0):
4,444
An abundant number or excessive number is a number for which the sum of its proper divisors is greater than the number itself. The integer 12 is the first abundant number. Its proper divisors are 1, 2, 3, 4 and 6 for a total of 16 (> 12). Derive function `abundantNumber(num)/abundant_number(num)` which returns `true...
["def abundant_number(num):\n return (sum([e for e in range(1,num) if num%e==0]) > num)", "def abundant_number(n):\n return sum(m for m in range(1, n) if n % m == 0) > n", "def abundant_number(num):\n return sum(i for i in range(1, num//2 + 1) if not num % i) > num", "def abundant_number(num):\n # O(sqrt(nu...
{"fn_name": "abundant_number", "inputs": [[12], [18], [37], [120], [77], [118], [5830], [11410], [14771], [11690]], "outputs": [[true], [true], [false], [true], [false], [false], [true], [true], [false], [true]]}
introductory
https://www.codewars.com/kata/56a75b91688b49ad94000015
def abundant_number(num):
4,445
[Haikus](https://en.wikipedia.org/wiki/Haiku_in_English) are short poems in a three-line format, with 17 syllables arranged in a 5–7–5 pattern. Your task is to check if the supplied text is a haiku or not. ### About syllables [Syllables](https://en.wikipedia.org/wiki/Syllable) are the phonological building blocks of...
["import re\n\nPATTERN = re.compile(r'[aeyuio]+[^aeyuio ]*((?=e\\b)e)?', flags=re.I)\n\n\ndef is_haiku(text):\n return [5,7,5] == [check(s) for s in text.split(\"\\n\")]\n \ndef check(s):\n return sum(1 for _ in PATTERN.finditer(s))\n", "import re\n\ndef is_haiku(text):\n def count_syllables(line):\n ...
{"fn_name": "is_haiku", "inputs": [["An old silent pond...\nA frog jumps into the pond,\nsplash! Silence again."], ["An old silent pond...\nA frog jumps into the pond, splash!\nSilence again."], ["An old silent pond...\nA frog jumps into the pond,\nsplash!\nSilence again."], ["An old silent pond... A frog jumps into th...
introductory
https://www.codewars.com/kata/5c765a4f29e50e391e1414d4
def is_haiku(text):
4,446
Write function ```wordsToSentence``` which will create a string from a list of strings, separated by space. Example: ```["hello", "world"] -> "hello world"```
["words_to_sentence=' '.join", "def words_to_sentence(words):\n return ' '.join(words)", "def words_to_sentence(a):\n return \" \".join(a)", "def words_to_sentence(words):\n st = \"\"\n for x in range(len(words)):\n st = st + words[x] + ' '\n return st.strip()\n\n", "def words_to_sentence(words):\...
{"fn_name": "words_to_sentence", "inputs": [[["bacon", "is", "delicious"]]], "outputs": [["bacon is delicious"]]}
introductory
https://www.codewars.com/kata/57a06005cf1fa5fbd5000216
def words_to_sentence(words):
4,447
# Task Consider a string of lowercase Latin letters and space characters (" "). First, rearrange the letters in each word `alphabetically`. And then rearrange the words in ascending order of the sum of their characters' `ASCII` values. If two or more words have the same `ASCII` value, rearrange them by the...
["def revamp(s):\n words = [''.join(sorted(word)) for word in s.split()]\n words.sort(key=lambda word: (sum(map(ord, word)), len(word), word))\n return ' '.join(words)", "def revamp(s):\n words = [\"\".join(sorted(word)) for word in s.split()]\n return \" \".join(sorted(words, key = lambda word: (sum(ord...
{"fn_name": "revamp", "inputs": [["batman is bruce wayne"], ["peter parker is spiderman"], ["codewars is great"], ["airplanes in the night sky"]], "outputs": [["is bceru aenwy aabmnt"], ["is eeprt aekprr adeimnprs"], ["is aegrt acdeorsw"], ["in eht ksy ghint aaeilnprs"]]}
introductory
https://www.codewars.com/kata/58bcfe1e23fee9fd95000007
def revamp(s):
4,448
I need some help with my math homework. I have a number of problems I need to return the derivative for. They will all be of the form: ax^b, A and B are both integers, but can be positive or negative. Note: - if b is 1, then the equation will be ax. - if b is 0, then the equation will be 0. Examples: ...
["def get_derivative(s):\n if '^' in s:\n f,t = map(int, s.split('x^'))\n return '{}x'.format(f*t) if t==2 else '{}x^{}'.format(f*t, t-1)\n elif 'x' in s: return s[:-1]\n else: return '0'", "def get_derivative(s):\n if 'x' not in s: return '0'\n if '^' not in s: return s.replace('x', '')\n ...
{"fn_name": "get_derivative", "inputs": [["3x^3"], ["3x^2"], ["3x"], ["3"], ["3x^-1"], ["-3x^-1"], ["-3x^10"], ["-954x^2"]], "outputs": [["9x^2"], ["6x"], ["3"], ["0"], ["-3x^-2"], ["3x^-2"], ["-30x^9"], ["-1908x"]]}
introductory
https://www.codewars.com/kata/5a0350c380171ffd7b00012a
def get_derivative(s):
4,449
There are some stones on Bob's table in a row, and each of them can be red, green or blue, indicated by the characters `R`, `G`, and `B`. Help Bob find the minimum number of stones he needs to remove from the table so that the stones in each pair of adjacent stones have different colours. Examples: ``` "RGBRGBRGGB" ...
["def solution(s):\n st=[1 for i in range(1,len(s)) if s[i-1]==s[i]]\n return sum(st)", "def solution(s):\n return sum(1 for i in range(len(s)) if i and s[i-1]==s[i])", "def solution(s):\n r = s\n for i in range(9):\n r = r.replace('RR', 'R').replace('GG', 'G').replace('BB', 'B')\n\n return len...
{"fn_name": "solution", "inputs": [["RRGGBB"], ["RGBRGB"], ["BGRBBGGBRRR"], ["GBBBGGRRGRB"], ["GBRGGRBBBBRRGGGB"]], "outputs": [[3], [0], [4], [4], [7]]}
introductory
https://www.codewars.com/kata/5f70e4cce10f9e0001c8995a
def solution(stones):
4,450
Create the function ```consecutive(arr)``` that takes an array of integers and return the minimum number of integers needed to make the contents of ```arr``` consecutive from the lowest number to the highest number. For example: If ```arr``` contains [4, 8, 6] then the output should be 2 because two numbers need to be...
["def consecutive(arr):\n return max(arr) - min(arr) + 1 - len(arr) if arr else 0", "def consecutive(arr):\n #your code here\n if len(arr) == 1 or len(arr) == 0:\n return 0\n mn, mx = min(arr), max(arr)\n s = set(arr)\n return mx - mn - len(s) + 1", "consecutive=lambda a:len(a)and-~max(a)-min(a...
{"fn_name": "consecutive", "inputs": [[[4, 8, 6]], [[1, 2, 3, 4]], [[]], [[1]], [[-10]], [[1, -1]], [[-10, -9]], [[0]], [[10, -10]], [[-10, 10]]], "outputs": [[2], [0], [0], [0], [0], [1], [0], [0], [19], [19]]}
introductory
https://www.codewars.com/kata/559cc2d2b802a5c94700000c
def consecutive(arr):
4,451
I have the `par` value for each hole on a golf course and my stroke `score` on each hole. I have them stored as strings, because I wrote them down on a sheet of paper. Right now, I'm using those strings to calculate my golf score by hand: take the difference between my actual `score` and the `par` of the hole, and add...
["def golf_score_calculator(par, score):\n return sum(int(b) - int(a) for a, b in zip(par, score))", "def golf_score_calculator(p, s):\n return sum([int(s[i])-int(p[i]) for i in range(len(p))])", "def golf_score_calculator(par, score):\n return sum(map(int, score)) - sum(map(int, par))", "def golf_score_calcul...
{"fn_name": "golf_score_calculator", "inputs": [["443454444344544443", "353445334534445344"], ["123456123456123456", "123456123456123456"]], "outputs": [[-1], [0]]}
introductory
https://www.codewars.com/kata/59f7a0a77eb74bf96b00006a
def golf_score_calculator(par_string, score_string):
4,452
The written representation of a number (with 4 or more digits) can be split into three parts in various different ways. For example, the written number 1234 can be split as [1 | 2 | 34] or [1 | 23 | 4] or [12 | 3 | 4]. Given a written number, find the highest possible product from splitting it into three parts and mul...
["from functools import reduce\nfrom operator import mul\n\ndef maximum_product_of_parts(n):\n s = str(n)\n return max(reduce(mul, map(int, (s[:i], s[i:j], s[j:])))\n for i in range(1,len(s)-1) for j in range(i+1,len(s)))", "from functools import reduce, partial\nfrom operator import mul\nproduct = ...
{"fn_name": "maximum_product_of_parts", "inputs": [[1234], [4321], [4224]], "outputs": [[144], [252], [352]]}
introductory
https://www.codewars.com/kata/5a3a95c2e1ce0efe2c0001b0
def maximum_product_of_parts(n):
4,453
# Summary: Given a number, `num`, return the shortest amount of `steps` it would take from 1, to land exactly on that number. # Description: A `step` is defined as either: - Adding 1 to the number: `num += 1` - Doubling the number: `num *= 2` You will always start from the number `1` and you will have to return the s...
["def shortest_steps_to_num(num):\n steps = 0\n \n while num != 1:\n if num % 2:\n num -= 1\n else:\n num //= 2\n \n steps += 1\n \n return steps", "def shortest_steps_to_num(num):\n return num.bit_length() + bin(num).count('1') - 2", "def shortest_ste...
{"fn_name": "shortest_steps_to_num", "inputs": [[2], [3], [4], [5], [6], [7], [8], [9], [10], [20], [30], [40], [50], [11], [24], [37], [19], [48], [59], [65], [73], [83], [64], [99], [100], [10000], [1500], [1534], [1978], [2763], [9999], [2673], [4578], [9876], [2659], [7777], [9364], [7280], [4998], [9283], [8234], ...
introductory
https://www.codewars.com/kata/5cd4aec6abc7260028dcd942
def shortest_steps_to_num(num):
4,454
Prior to having fancy iPhones, teenagers would wear out their thumbs sending SMS messages on candybar-shaped feature phones with 3x4 numeric keypads. ------- ------- ------- | | | ABC | | DEF | | 1 | | 2 | | 3 | ------- ------- ------- ------- ------- ------- | GHI | | JKL | | MNO | ...
["BUTTONS = [ '1', 'abc2', 'def3',\n 'ghi4', 'jkl5', 'mno6',\n 'pqrs7', 'tuv8', 'wxyz9',\n '*', ' 0', '#' ]\ndef presses(phrase):\n return sum(1 + button.find(c) for c in phrase.lower() for button in BUTTONS if c in button)", "def presses(phrase):\n x = 0\n for letter i...
{"fn_name": "presses", "inputs": [["LOL"], ["HOW R U"], ["WHERE DO U WANT 2 MEET L8R"], ["lol"], ["0"], ["ZER0"], ["1"], ["IS NE1 OUT THERE"], ["#"], ["#codewars #rocks"]], "outputs": [[9], [13], [47], [9], [2], [11], [1], [31], [1], [36]]}
introductory
https://www.codewars.com/kata/54a2e93b22d236498400134b
def presses(phrase):
4,455
Consider integer coordinates x, y in the Cartesian plan and three functions f, g, h defined by: ``` f: 1 <= x <= n, 1 <= y <= n --> f(x, y) = min(x, y) g: 1 <= x <= n, 1 <= y <= n --> g(x, y) = max(x, y) h: 1 <= x <= n, 1 <= y <= n --> h(x, y) = x + y ``` where n is a given integer (n >= 1, guaranteed) and x, y are in...
["def sumin(n):\n return n * (n + 1) * (2 * n + 1) // 6\n \ndef sumax(n):\n return n * (n + 1) * (4 * n - 1) // 6\n \ndef sumsum(n):\n return n * n * (n + 1)\n\n", "def sumin(n):\n# return sum(min(x+1,y+1) for y in range(n) for x in range(n))\n return sum((i+1)*(2*(n-i)-1) for i in range(n))\n ...
{"fn_name": "sumin", "inputs": [[5], [6], [8], [15], [100], [365], [730], [4000]], "outputs": [[55], [91], [204], [1240], [338350], [16275715], [129938905], [21341334000]]}
introductory
https://www.codewars.com/kata/559e3224324a2b6e66000046
def sumin(n):
4,456
In this kata, your task is to create a function that takes a single list as an argument and returns a flattened list. The input list will have a maximum of one level of nesting (list(s) inside of a list). ```python # no nesting [1, 2, 3] # one level of nesting [1, [2, 3]] ``` --- # Examples ```python >>> flatten_me...
["def flatten_me(lst):\n res = []\n for l in lst:\n if isinstance(l, list):\n res.extend(l)\n else:\n res.append(l)\n return res\n", "def flatten_me(nput):\n output = []\n for itm in nput:\n if isinstance(itm, list):\n output += flatten_me(itm)\n ...
{"fn_name": "flatten_me", "inputs": [[[1, [2, 3], 4]], [[["a", "b"], "c", ["d"]]], [["!", "?"]]], "outputs": [[[1, 2, 3, 4]], [["a", "b", "c", "d"]], [["!", "?"]]]}
introductory
https://www.codewars.com/kata/55a5bef147d6be698b0000cd
def flatten_me(lst):
4,457
Have you heard about Megamind? Megamind and Metro Man are two aliens who came to earth. Megamind wanted to destroy the earth, while Metro Man wanted to stop him and protect mankind. After a lot of fighting, Megamind finally threw Metro Man up into the sky. Metro Man was defeated and was never seen again. Megamind wante...
["from math import ceil\n\ndef mega_mind(hp, dps, shots, regen):\n if dps*shots >= hp: return ceil(hp / dps)\n if dps*shots <= regen: return -1\n\n number_of_regenerations = ceil((hp - dps*shots) / (dps*shots - regen))\n return ceil((hp + regen*number_of_regenerations) / dps)", "from math import ceil\n\ndef...
{"fn_name": "mega_mind", "inputs": [[12, 4, 3, 2], [9, 4, 2, 7], [13, 4, 3, 1], [13, 4, 3, 50], [36, 4, 3, 2], [15, 4, 3, 12], [100000, 99999, 100000, 100000], [100000, 100000, 100000, 100000], [100000, 1, 50000, 49999], [100000, 1, 1000, 999], [17, 4, 4, 16], [23, 4, 4, 13], [1, 4, 4, 15], [22, 4, 4, 13], [16, 4, 4, 1...
introductory
https://www.codewars.com/kata/5baf21542d15ec9453000147
def mega_mind(hp, dps, shots, regen):
4,458
A new task for you! You have to create a method, that corrects a given time string. There was a problem in addition, so many of the time strings are broken. Time-Format is european. So from "00:00:00" to "23:59:59". Some examples: "09:10:01" -> "09:10:01" "11:70:10" -> "12:10:10" "19:99:99" -> "20:40:39" "24:01:01"...
["def time_correct(t):\n if not t: return t\n try:\n h, m, s = map(int, t.split(':'))\n if s >= 60: s -= 60; m += 1\n if m >= 60: m -= 60; h += 1\n return '%02d:%02d:%02d' % (h % 24, m, s)\n except: pass", "import re\n\n\ndef time_correct(t):\n if not t:\n return t\n \n...
{"fn_name": "time_correct", "inputs": [[null], [""], ["001122"], ["00;11;22"], ["0a:1c:22"], ["09:10:01"], ["11:70:10"], ["19:99:99"], ["24:01:01"], ["52:01:01"], ["14:59:94"]], "outputs": [[null], [""], [null], [null], [null], ["09:10:01"], ["12:10:10"], ["20:40:39"], ["00:01:01"], ["04:01:01"], ["15:00:34"]]}
introductory
https://www.codewars.com/kata/57873ab5e55533a2890000c7
def time_correct(t):
4,459
Return the Nth Even Number The input will not be 0.
["def nth_even(n):\n return 2 * (n - 1);", "def nth_even(n):\n return n * 2 - 2", "def nth_even(n):\n return (n-1)*2;", "nth_even = lambda x: 2 * (x - 1)", "nth_even = lambda n: (n - 1) * 2\n", "def nth_even(n):\n '''import numpy as np\n np.even1=0\n #even1 = long(even1)\n for i in range(n):\n ...
{"fn_name": "nth_even", "inputs": [[1], [2], [3], [100], [1298734]], "outputs": [[0], [2], [4], [198], [2597466]]}
introductory
https://www.codewars.com/kata/5933a1f8552bc2750a0000ed
def nth_even(n):
4,460
Complete the function which returns the weekday according to the input number: * `1` returns `"Sunday"` * `2` returns `"Monday"` * `3` returns `"Tuesday"` * `4` returns `"Wednesday"` * `5` returns `"Thursday"` * `6` returns `"Friday"` * `7` returns `"Saturday"` * Otherwise returns `"Wrong, please enter a number betwee...
["WEEKDAY = {\n 1: 'Sunday',\n 2: 'Monday',\n 3: 'Tuesday',\n 4: 'Wednesday',\n 5: 'Thursday',\n 6: 'Friday',\n 7: 'Saturday' }\nERROR = 'Wrong, please enter a number between 1 and 7'\n\n\ndef whatday(n):\n return WEEKDAY.get(n, ERROR)\n", "def whatday(num):\n switcher = {\n 1:'Sunday',\n ...
{"fn_name": "whatday", "inputs": [[1], [2], [3], [4], [5], [6], [7], [0], [8], [20]], "outputs": [["Sunday"], ["Monday"], ["Tuesday"], ["Wednesday"], ["Thursday"], ["Friday"], ["Saturday"], ["Wrong, please enter a number between 1 and 7"], ["Wrong, please enter a number between 1 and 7"], ["Wrong, please enter a number...
introductory
https://www.codewars.com/kata/59dd3ccdded72fc78b000b25
def whatday(num):
4,461
# Task You are given n rectangular boxes, the ith box has the length lengthi, the width widthi and the height heighti. Your task is to check if it is possible to pack all boxes into one so that inside each box there is no more than one another box (which, in turn, can contain at most one another box, and so on). ...
["def boxes_packing(l, w, h):\n boxes = sorted(sorted(t) for t in zip(l, w, h))\n return all( s < l for b1,b2 in zip(boxes[:-1], boxes[1:]) for s,l in zip(b1,b2))", "def boxes_packing(length, width, height):\n boxes = sorted([sorted(b) for b in zip(length, width, height)])\n return all(all(x < y for x, y in...
{"fn_name": "boxes_packing", "inputs": [[[1, 3, 2], [1, 3, 2], [1, 3, 2]], [[1, 1], [1, 1], [1, 1]], [[3, 1, 2], [3, 1, 2], [3, 2, 1]], [[2], [3], [4]], [[5, 7, 4, 1, 2], [4, 10, 3, 1, 4], [6, 5, 5, 1, 2]], [[6, 4], [5, 3], [4, 5]], [[6, 3], [5, 4], [4, 5]], [[6, 3], [5, 5], [4, 4]], [[883, 807], [772, 887], [950, 957]...
introductory
https://www.codewars.com/kata/58957c5041c979cf9e00002f
def boxes_packing(length, width, height):
4,462
## Task **_Given_** *an array of integers* , **_Find_** **_the maximum product_** *obtained from multiplying 2 adjacent numbers in the array*. ____ # Notes * **_Array/list_** size is *at least 2*. * **_Array/list_** numbers could be a *mixture of positives, negatives also zeroes* . ___ # Input >> Output Examples `...
["def adjacent_element_product(array):\n return max( a*b for a, b in zip(array, array[1:]) )", "def adjacent_element_product(array):\n return max(array[i]*array[i+1] for i in range(len(array)-1))", "def adjacent_element_product(array):\n return max(x * y for x, y in zip(array, array[1:]))\n", "from operator im...
{"fn_name": "adjacent_element_product", "inputs": [[[5, 8]], [[5, 1, 1, 8]], [[1, 2, 3]], [[1, 5, 10, 9]], [[4, 12, 3, 1, 5]], [[5, 1, 2, 3, 1, 4]], [[3, 6, -2, -5, 7, 3]], [[9, 5, 10, 2, 24, -1, -48]], [[5, 6, -4, 2, 3, 2, -23]], [[-23, 4, -5, 99, -27, 329, -2, 7, -921]], [[1, 0, 1, 0, 1000]], [[1, 2, 3, 0]]], "output...
introductory
https://www.codewars.com/kata/5a4138acf28b82aa43000117
def adjacent_element_product(array):
4,463
Welcome. In this kata you are required to, given a string, replace every letter with its position in the alphabet. If anything in the text isn't a letter, ignore it and don't return it. `"a" = 1`, `"b" = 2`, etc. ## Example ```python alphabet_position("The sunset sets at twelve o' clock.") ``` Should return `"20 8...
["def alphabet_position(text):\n return ' '.join(str(ord(c) - 96) for c in text.lower() if c.isalpha())", "def alphabet_position(s):\n return \" \".join(str(ord(c)-ord(\"a\")+1) for c in s.lower() if c.isalpha())\n", "alphabet = 'abcdefghijklmnopqrstuvwxyz'\n\ndef alphabet_position(text):\n if type(text) == str:...
{"fn_name": "alphabet_position", "inputs": [["-.-'"]], "outputs": [[""]]}
introductory
https://www.codewars.com/kata/546f922b54af40e1e90001da
def alphabet_position(text):
4,464
All of the animals are having a feast! Each animal is bringing one dish. There is just one rule: the dish must start and end with the same letters as the animal's name. For example, the great blue heron is bringing garlic naan and the chickadee is bringing chocolate cake. Write a function `feast` that takes the animal...
["def feast(beast, dish):\n return beast[0]==dish[0] and dish[-1]==beast[-1]", "def feast(beast, dish):\n return beast[0] == dish[0] and beast[-1] == dish[-1] ", "def feast(beast, dish):\n return beast.startswith(dish[0]) and beast.endswith(dish[-1])", "def feast(beast, dish):\n \"\"\" (str, str) -> bool...
{"fn_name": "feast", "inputs": [["great blue heron", "garlic naan"], ["chickadee", "chocolate cake"], ["brown bear", "bear claw"], ["marmot", "mulberry tart"], ["porcupine", "pie"], ["cat", "yogurt"], ["electric eel", "lasagna"], ["slow loris", "salsas"], ["ox", "orange lox"], ["blue-footed booby", "blueberry"], ["frui...
introductory
https://www.codewars.com/kata/5aa736a455f906981800360d
def feast(beast, dish):