problem_id
stringlengths
32
32
name
stringclasses
1 value
problem
stringlengths
200
14k
solutions
stringlengths
12
1.12M
test_cases
stringlengths
37
74M
difficulty
stringclasses
3 values
language
stringclasses
1 value
source
stringclasses
7 values
num_solutions
int64
12
1.12M
starter_code
stringlengths
0
956
2c7c63f2f10f748d5610fefef52f87a6
UNKNOWN
Consider the range `0` to `10`. The primes in this range are: `2, 3, 5, 7`, and thus the prime pairs are: `(2,2), (2,3), (2,5), (2,7), (3,3), (3,5), (3,7),(5,5), (5,7), (7,7)`. Let's take one pair `(2,7)` as an example and get the product, then sum the digits of the result as follows: `2 * 7 = 14`, and `1 + 4 = 5`. W...
["import itertools\n\ndef solve(a, b):\n primes = set([2] + [n for n in range(3, b, 2) if all(n % r for r in range(3, int(n**0.5)+1, 2))])\n return sum( sum(map(int, str(x*y))) in primes for x, y in itertools.combinations_with_replacement([p for p in primes if a <= p < b], 2) )", "from bisect import bisect_left\n...
{"fn_name": "solve", "inputs": [[0, 20], [2, 200], [2, 2000], [1000, 3000], [2000, 5000]], "outputs": [[14], [457], [17705], [12801], [25005]]}
INTRODUCTORY
PYTHON3
CODEWARS
38,443
def solve(a, b):
d206b5c6968cf7ec092410de72f4ad4c
UNKNOWN
In this kata, you will write a function that returns the positions and the values of the "peaks" (or local maxima) of a numeric array. For example, the array `arr = [0, 1, 2, 5, 1, 0]` has a peak at position `3` with a value of `5` (since `arr[3]` equals `5`). ~~~if-not:php,cpp,java,csharp The output will be returned...
["def pick_peaks(arr):\n pos = []\n prob_peak = False\n for i in range(1, len(arr)):\n if arr[i] > arr[i-1]:\n prob_peak = i\n elif arr[i] < arr[i-1] and prob_peak:\n pos.append(prob_peak)\n prob_peak = False\n return {'pos':pos, 'peaks':[arr[i] for i in pos]}"...
{"fn_name": "pick_peaks", "inputs": [[[1, 2, 3, 6, 4, 1, 2, 3, 2, 1]], [[3, 2, 3, 6, 4, 1, 2, 3, 2, 1, 2, 3]], [[3, 2, 3, 6, 4, 1, 2, 3, 2, 1, 2, 2, 2, 1]], [[2, 1, 3, 1, 2, 2, 2, 2, 1]], [[2, 1, 3, 1, 2, 2, 2, 2]], [[2, 1, 3, 2, 2, 2, 2, 5, 6]], [[2, 1, 3, 2, 2, 2, 2, 1]], [[1, 2, 5, 4, 3, 2, 3, 6, 4, 1, 2, 3, 3, 4, 5...
INTRODUCTORY
PYTHON3
CODEWARS
62,332
def pick_peaks(arr):
ee4a3beb6bca7ade6fe0fde59ef6aead
UNKNOWN
# Task In ChessLand there is a small but proud chess bishop with a recurring dream. In the dream the bishop finds itself on an `n × m` chessboard with mirrors along each edge, and it is not a bishop but a ray of light. This ray of light moves only along diagonals (the bishop can't imagine any other types of moves ...
["def chess_bishop_dream(b,p,d,k):\n yq,yr=divmod(p[0]+k*d[0],2*b[0])\n xq,xr=divmod(p[1]+k*d[1],2*b[1])\n return [min(yr, 2*b[0]-yr-1), min(xr, 2*b[1]-xr-1)]", "chess_bishop_dream=lambda b,p,d,k:[c-abs((q+k*e)%(2*c)-c+.5)-.5for c,q,e in zip(b,p,d)]", "def chess_bishop_dream(board_size, init_position, init_dir...
{"fn_name": "chess_bishop_dream", "inputs": [[[3, 7], [1, 2], [-1, 1], 13], [[1, 2], [0, 0], [1, 1], 6], [[2, 2], [1, 0], [1, 1], 12], [[1, 1], [0, 0], [1, -1], 1000000000], [[2, 3], [1, 2], [-1, -1], 41], [[17, 19], [14, 8], [1, -1], 239239], [[17, 19], [16, 18], [1, 1], 239239239]], "outputs": [[[0, 1]], [[0, 1]], [[...
INTRODUCTORY
PYTHON3
CODEWARS
3,616
def chess_bishop_dream(board_size, init_position, init_direction, k):
980cf4d4e75e7248f6608b25656eaf57
UNKNOWN
For all x in the range of integers [0, 2 ** n), let y[x] be the binary exclusive-or of x and x // 2. Find the sum of all numbers in y. Write a function sum_them that, given n, will return the value of the above sum. This can be implemented a simple loop as shown in the initial code. But once n starts getting to highe...
["def sum_them(n):\n return 2 ** (n - 1) * (2 ** n - 1)", "sum_them=lambda n: int('1'*n, 2)*(int('1'*n, 2)+1)//2 if n else 0", "def sum_them(n):\n return 2 ** (n*2-1) - 2 ** (n-1)", "sum_them=lambda n:int(n*'1'+~-n*'0'or'0',2)", "def sum_them(n):\n return 2**n*(2**n-1)>>1", "def sum_them(n):\n return n and i...
{"fn_name": "sum_them", "inputs": [[0], [1], [2], [3], [4]], "outputs": [[0], [1], [6], [28], [120]]}
INTRODUCTORY
PYTHON3
CODEWARS
592
def sum_them(n):
4bcc6806b5b5e60d1f6fa293dc13bdcd
UNKNOWN
Lеt's create function to play cards. Our rules: We have the preloaded `deck`: ``` deck = ['joker','2♣','3♣','4♣','5♣','6♣','7♣','8♣','9♣','10♣','J♣','Q♣','K♣','A♣', '2♦','3♦','4♦','5♦','6♦','7♦','8♦','9♦','10♦','J♦','Q♦','K♦','A♦', '2♥','3♥','4♥','5♥','6♥','7♥','8♥','9♥','10♥','J♥','Q♥...
["vals='2345678910JQKA'\ndef card_game(card_1, card_2, trump):\n print((card_1, card_2, trump))\n if card_1==card_2: return 'Someone cheats.'\n elif 'joker' in [card_1,card_2]:\n return ['The first card won.', 'The second card won.'][card_1!='joker']\n elif card_1[-1]==card_2[-1]:\n return ['T...
{"fn_name": "card_game", "inputs": [["Q\u2663", "3\u2663", "\u2666"], ["3\u2663", "Q\u2663", "\u2666"], ["5\u2665", "A\u2663", "\u2666"], ["8\u2660", "8\u2660", "\u2663"], ["2\u2666", "A\u2660", "\u2666"], ["A\u2660", "2\u2666", "\u2666"], ["joker", "joker", "\u2666"], ["joker", "10\u2663", "\u2660"], ["10\u2663", "jok...
INTRODUCTORY
PYTHON3
CODEWARS
6,266
def card_game(card_1, card_2, trump):
6918bb5f25cd942f21ae24bf8354b6bd
UNKNOWN
Write a function that takes two arguments, and returns a new array populated with the elements **that only appear once, in either one array or the other, taken only once**; display order should follow what appears in arr1 first, then arr2: ```python hot_singles([1, 2, 3, 3], [3, 2, 1, 4, 5]) # [4, 5] hot_singles(["ta...
["def hot_singles(arr1, arr2):\n a = []\n for x in arr1 + arr2:\n if x in set(arr1) ^ set(arr2) and x not in a: a.append(x)\n return a", "from collections import OrderedDict\nfrom itertools import chain\n\n\ndef hot_singles(arr1, arr2):\n diff = set(arr1).symmetric_difference(arr2)\n return [a for...
{"fn_name": "hot_singles", "inputs": [[["tartar", "blanket", "domino"], ["blanket"]], [[77, "basketweave"], [78, 42, "basketweave"]], [[100, 45, "ciao"], [100, 2, 3, 45, 5]], [[10, 200, 30], [10, 20, 3, 4, 5, 5, 5, 200]], [[1, 2, 3, 3], [3, 2, 1, 4, 5, 4]]], "outputs": [[["tartar", "domino"]], [[77, 78, 42]], [["ciao",...
INTRODUCTORY
PYTHON3
CODEWARS
1,537
def hot_singles(arr1, arr2):
beddde85cfb89b4f01a7ee74619cb2f0
UNKNOWN
Gigi is a clever monkey, living in the zoo, his teacher (animal keeper) recently taught him some knowledge of "0". In Gigi's eyes, "0" is a character contains some circle(maybe one, maybe two). So, a is a "0",b is a "0",6 is also a "0",and 8 have two "0" ,etc... Now, write some code to count how many "0"s in the tex...
["def countzero(s):\n return sum(1 if c in 'abdegopq069DOPQR' else 2 if c in '%&B8' else 0 for c in s.replace('()', '0'))", "def countzero(string):\n return sum(1 if c in 'abdegopq069DOPQR' else 2 if c in '%&B8' else 0 for c in string) + string.count('()')", "def countzero(string):\n return sum(map(\"abdegopq0...
{"fn_name": "countzero", "inputs": [[""], ["0"], ["0oO0oO"], ["1234567890"], ["abcdefghijklmnopqrstuvwxyz"], ["()"], ["E"], ["aA"], ["BRA"], ["%%"]], "outputs": [[0], [1], [6], [5], [8], [1], [0], [1], [3], [4]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,726
def countzero(string):
eb21649d4f304052a8e2719c60595146
UNKNOWN
Write a comparator for a list of phonetic words for the letters of the [greek alphabet](https://en.wikipedia.org/wiki/Greek_alphabet). A comparator is: > *a custom comparison function of two arguments (iterable elements) which should return a negative, zero or positive number depending on whether the first argument is...
["def greek_comparator(lhs, rhs):\n greek_alphabet = [\n 'alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta',\n 'eta', 'theta', 'iota', 'kappa', 'lambda', 'mu',\n 'nu', 'xi', 'omicron', 'pi', 'rho', 'sigma',\n 'tau', 'upsilon', 'phi', 'chi', 'psi', 'omega']\n l = len(greek_alphabet)\n...
{"fn_name": "greek_comparator", "inputs": [["chi", "chi"]], "outputs": [[0]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,206
def greek_comparator(lhs, rhs):
019b0ab59bc6e5a35a17f784e28f5e9f
UNKNOWN
You are the Dungeon Master for a public DnD game at your local comic shop and recently you've had some trouble keeping your players' info neat and organized so you've decided to write a bit of code to help keep them sorted! The goal of this code is to create an array of objects that stores a player's name and contact ...
["import re\n\ndef player_manager(players):\n return players and [ {'player': who, 'contact': int(num)}\n for who,num in re.findall(r'(.+?), (\\d+)(?:, )?', players)] or []", "def player_manager(players):\n return [{'player': a, 'contact': int(b)} for a, b in zip(*[iter(players.split(', ')...
{"fn_name": "player_manager", "inputs": [["a, 5"], ["jane, 801, dave, 123"], ["Amelia, 8165254325, Jessie, 9187162345, Marcus Kaine, 8018273245"], [""], [null]], "outputs": [[[{"player": "a", "contact": 5}]], [[{"player": "jane", "contact": 801}, {"player": "dave", "contact": 123}]], [[{"player": "Amelia", "contact": 8...
INTRODUCTORY
PYTHON3
CODEWARS
2,055
def player_manager(players):
8a806b008cb6d4dbd8e2c75921865cea
UNKNOWN
Chuck has lost count of how many asses he has kicked... Chuck stopped counting at 100,000 because he prefers to kick things in the face instead of counting. That's just who he is. To stop having to count like a mere mortal chuck developed his own special code using the hairs on his beard. You do not need to know the ...
["from re import search\n\n\ndef body_count(code):\n return bool(search(r'(?:[A-Z]\\d){5}\\.-[A-Z]%\\d\\.\\d{2}\\.', code))", "import re\n\npattern = re.compile('A8A8A8A8A8.-A%8.88.'.replace('A', '[A-Z]').replace('8', '[0-9]').replace('.', r'\\.'))\n\ndef body_count(code):\n return bool(pattern.search(code))", "i...
{"fn_name": "body_count", "inputs": [["A6C2E5Z9A4.-F%8.08."], ["PP P6A6T5F5S3.-Z%1.11.hgr"], ["A6A1E3A8M2.-Q%8.88."], ["d G8H1E2O9N3.-W%8.56. f"], ["B4A1D1I8B4.-E%8.76."], ["ffr65A C8K4D9U7V5.-Y%8.00."], [" 76 B2L4D0A8C6.-T%8.90. lkd"], ["B2L4D0A8C6.-T%8.90"], ["B2L4D0AFC6.-T%8.90."], ["B4A1D1I8B4"], ["B4A666...
INTRODUCTORY
PYTHON3
CODEWARS
1,212
def body_count(code):
be9d17cf49c6c75c5a0642fe129d46ad
UNKNOWN
Implement a function which behaves like the uniq command in UNIX. It takes as input a sequence and returns a sequence in which all duplicate elements following each other have been reduced to one instance. Example: ``` ["a", "a", "b", "b", "c", "a", "b", "c"] => ["a", "b", "c", "a", "b", "c"] ```
["from itertools import groupby\n\ndef uniq(seq): \n return [k for k,_ in groupby(seq)]", "def uniq(seq):\n if len(seq) == 0:\n return []\n rez = [seq[0]]\n for i in range(1, len(seq)):\n if seq[i] != rez[-1]:\n rez.append(seq[i])\n return rez", "from itertools import groupby\n\n...
{"fn_name": "uniq", "inputs": [[["a", "a", "b", "b", "c", "a", "b", "c", "c"]], [["a", "a", "a", "b", "b", "b", "c", "c", "c"]], [[]], [["foo"]], [["bar"]], [[""]], [[null, "a", "a"]]], "outputs": [[["a", "b", "c", "a", "b", "c"]], [["a", "b", "c"]], [[]], [["foo"]], [["bar"]], [[""]], [[null, "a"]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,326
def uniq(seq):
2b001b335711ba8142ad7fffd7b242d2
UNKNOWN
Do you have in mind the good old TicTacToe? Assuming that you get all the data in one array, you put a space around each value, `|` as a columns separator and multiple `-` as rows separator, with something like `["O", "X", " ", " ", "X", " ", "X", "O", " "]` you should be returning this structure (inclusive of new lin...
["def display_board(board, width):\n board = [c.center(3) for c in board]\n rows = [\"|\".join(board[n:n+width]) for n in range(0, len(board), width)]\n return (\"\\n\" + \"-\"*(4*width - 1) + \"\\n\").join(rows)", "def display_board(board, width):\n line = f'\\n{\"-\"*(4*width-1)}\\n'\n return line.join...
{"fn_name": "display_board", "inputs": [[["O", "X", "X", "O"], 2], [["O", "X", " ", " ", "X", " ", "X", "O", " "], 3], [["O", "X", " ", " ", "X", " ", "X", "O", " ", "O"], 5], [["O", "X", " ", " ", "X", " ", "X", "O", " ", "O"], 2], [["1", "2", "3", "4", "5", "1", "2", "3", "4", "5", "1", "2", "3", "4", "5", "1", "2", ...
INTRODUCTORY
PYTHON3
CODEWARS
2,093
def display_board(board, width):
90d50c5357a370b840e1c481a375077e
UNKNOWN
# Task You are the manager of the famous rescue team: The Knights. Your task is to assign your knights to a rescue missions on an infinite 2D-plane. Your knights can move only by `n-knight` jumps. For example, if a knight has n = 2, they can only move exactly as a knight on a chess board. If n = 3, they can ...
["def knight_rescue(N,x,y):\n return (y - x) % 2 == 0 or any(n % 2 == 0 for n in N)\n", "def knight_rescue(N, x, y):\n return (x - y) % 2 == 0 or any(n % 2 == 0 for n in N)", "def knight_rescue(N,x,y):\n if x%2 == 0 and y%2==0:\n return True if any([i%2!=0 for i in N]) else (True if all([i%2==0 for i in...
{"fn_name": "knight_rescue", "inputs": [[[2], 2, 1], [[1], 10, 10], [[1], 1, 0], [[1, 2], 1, 0], [[1, 2, 3], 456546, 23532], [[1, 5, 3, 7, 9], 7, 8], [[1, 1, 1, 1, 1, 1, 1, 1, 1], 0, 1]], "outputs": [[true], [true], [false], [true], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,200
def knight_rescue(N,x,y):
9cdeb481a1f456f5641ed1b89fdc5355
UNKNOWN
You are given a sequence of a journey in London, UK. The sequence will contain bus **numbers** and TFL tube names as **strings** e.g. ```python ['Northern', 'Central', 243, 1, 'Victoria'] ``` Journeys will always only contain a combination of tube names and bus numbers. Each tube journey costs `£2.40` and each bus jou...
["def london_city_hacker(journey): \n # your code here\n tube = 2.40\n bus = 1.50\n total_cost = 0.00\n count = 0\n for link in journey:\n if isinstance(link, str):\n total_cost += tube\n count = 0\n else:\n if count == 0:\n total_cost += b...
{"fn_name": "london_city_hacker", "inputs": [[[12, "Central", "Circle", 21]], [["Piccidilly", 56]], [["Northern", "Central", "Circle"]], [["Piccidilly", 56, 93, 243]], [[386, 56, 1, 876]], [[]]], "outputs": [["\u00a37.80"], ["\u00a33.90"], ["\u00a37.20"], ["\u00a35.40"], ["\u00a33.00"], ["\u00a30.00"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,574
def london_city_hacker(journey):
befed8f4f4d1b2e43cfefbc89c529f52
UNKNOWN
Your friend has invited you to a party, and tells you to meet them in the line to get in. The one problem is it's a masked party. Everyone in line is wearing a colored mask, including your friend. Find which people in line could be your friend. Your friend has told you that he will be wearing a `RED` mask, and has **T...
["def redWith2Blues(i, line):\n return any(line[i-2+x:i+1+x].count('blue')==2 for x in range(3))\n\ndef friend_find(line):\n return sum( p=='red' and redWith2Blues(i,line) for i,p in enumerate(line))", "def friend_find(line):\n N = len(line)\n A = lambda i: line[i] == \"red\" and B(i)\n B = lambda i: C(i...
{"fn_name": "friend_find", "inputs": [[["blue", "blue", "red", "red", "blue", "green"]], [["blue", "red", "blue", "blue", "red", "blue", "red"]], [["brown", "brown", "red", "green"]], [["red", "blue", "blue", "red"]], [["red", "blue"]], [["blue", "green", "red", "green", "blue", "blue", "red"]], [["blue", "blue", "blue...
INTRODUCTORY
PYTHON3
CODEWARS
2,802
def friend_find(line):
3cffdcff08e3688a31c9fd013e4955b7
UNKNOWN
Pig Latin is an English language game where the goal is to hide the meaning of a word from people not aware of the rules. So, the goal of this kata is to wite a function that encodes a single word string to pig latin. The rules themselves are rather easy: 1) The word starts with a vowel(a,e,i,o,u) -> return the orig...
["VOWELS = set('aeiou')\n\ndef pig_latin(st):\n s = st.lower()\n if s.isalpha():\n if set(s) & VOWELS:\n if s[0] in VOWELS:\n s += 'w'\n while s[0] not in VOWELS:\n s = s[1:] + s[:1]\n return s + 'ay'", "def pig_latin(s):\n vowels = ['a', 'e', '...
{"fn_name": "pig_latin", "inputs": [["Hello"], ["CCCC"], ["tes3t5"], ["ay"], [""], ["YA"], ["123"], ["ya1"], ["yaYAya"], ["YayayA"]], "outputs": [["ellohay"], ["ccccay"], [null], ["ayway"], [null], ["ayay"], [null], [null], ["ayayayay"], ["ayayayay"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,493
def pig_latin(s):
f4c4a84ca483a5d3c65d96e78ca3b40b
UNKNOWN
Mrs Jefferson is a great teacher. One of her strategies that helped her to reach astonishing results in the learning process is to have some fun with her students. At school, she wants to make an arrangement of her class to play a certain game with her pupils. For that, she needs to create the arrangement with **the mi...
["def shortest_arrang(n):\n # For odd n, we can always construct n with 2 consecutive integers.\n if n % 2 == 1:\n return [n//2 + 1, n//2]\n\n # For even n, n is the sum of either an odd number or even number of\n # consecutive positive integers. Moreover, this property is exclusive.\n\n for i in ...
{"fn_name": "shortest_arrang", "inputs": [[10], [14], [16], [22], [65]], "outputs": [[[4, 3, 2, 1]], [[5, 4, 3, 2]], [[-1]], [[7, 6, 5, 4]], [[33, 32]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,721
def shortest_arrang(n):
58295868b8a262b4a521aed4f8efc51f
UNKNOWN
Your retro heavy metal band, VÄxën, originally started as kind of a joke, just because why would anyone want to use the crappy foosball table in your startup's game room when they could be rocking out at top volume in there instead? Yes, a joke, but now all the top tech companies are paying you top dollar to play at th...
["UMLAUTS = {'A': '\u00c4', 'E': '\u00cb', 'I': '\u00cf', 'O': '\u00d6', 'U': '\u00dc', 'Y': '\u0178',\n 'a': '\u00e4', 'e': '\u00eb', 'i': '\u00ef', 'o': '\u00f6', 'u': '\u00fc', 'y': '\u00ff'}\n\n\ndef heavy_metal_umlauts(s):\n return ''.join(UMLAUTS.get(a, a) for a in s)", "# -*- coding: utf-8 -*-\ndef ...
{"fn_name": "heavy_metal_umlauts", "inputs": [["Announcing the Macbook Air Guitar"], ["Facebook introduces new heavy metal reaction buttons"], ["Strong sales of Google's VR Metalheadsets send tech stock prices soaring"], ["Vegan Black Metal Chef hits the big time on Amazon TV"]], "outputs": [["\u00c4nn\u00f6\u00fcnc\u0...
INTRODUCTORY
PYTHON3
CODEWARS
2,558
def heavy_metal_umlauts(boring_text):
2531aba3fb65f54cb26ff41c9ce1e2d7
UNKNOWN
*This kata is based on [Project Euler Problem #349](https://projecteuler.net/problem=349). You may want to start with solving [this kata](https://www.codewars.com/kata/langtons-ant) first.* --- [Langton's ant](https://en.wikipedia.org/wiki/Langton%27s_ant) moves on a regular grid of squares that are coloured either b...
["move = [lambda p: (p[0]+1, p[1]), lambda p: (p[0], p[1]+1), lambda p: (p[0]-1, p[1]), lambda p: (p[0], p[1]-1)]\nstart, loop, size = 9977, 104, 12\n\ndef langtons_ant(n):\n pos, d, black, res = (0, 0), 0, set(), 0\n if n > start:\n x = (n - start)%loop\n res = size * (n-start-x)//loop\n n =...
{"fn_name": "langtons_ant", "inputs": [[0], [1], [2], [10], [100], [1000], [10000], [100000], [1000000], [10000000]], "outputs": [[0], [1], [2], [6], [20], [118], [720], [11108], [114952], [1153412]]}
INTRODUCTORY
PYTHON3
CODEWARS
8,487
def langtons_ant(n):
0e6cb51e7fdba2d3af05a6f696795118
UNKNOWN
**Introduction**  Little Petya very much likes sequences. However, recently he received a sequence as a gift from his mother.  Petya didn't like it at all! He decided to make a single replacement. After this replacement, Petya would like to the sequence in increasing order.  He asks himself: What is the lowest possible...
["def sort_number(a): \n a = sorted(a)\n return [1]+a if a.pop()!=1 else a+[2]", "def sort_number(a): \n if max(a) != 1:\n a.remove(max(a))\n a.append(1)\n else:\n a.remove(max(a))\n a.append(2)\n \n return sorted(a)\n", "def sort_number(a): \n a = sorted(a)\n m =...
{"fn_name": "sort_number", "inputs": [[[1, 2, 3, 4, 5]], [[4, 2, 1, 3, 5]], [[2, 3, 4, 5, 6]], [[2, 2, 2]], [[42]], [[5, 6, 1, 2, 3, 1, 3, 45, 7, 1000000000]], [[1, 1, 1]], [[1]], [[134]]], "outputs": [[[1, 1, 2, 3, 4]], [[1, 1, 2, 3, 4]], [[1, 2, 3, 4, 5]], [[1, 2, 2]], [[1]], [[1, 1, 1, 2, 3, 3, 5, 6, 7, 45]], [[1, 1...
INTRODUCTORY
PYTHON3
CODEWARS
1,423
def sort_number(a):
31d9b98a6ea7611f705a043b5534ddb9
UNKNOWN
Your task is to generate the Fibonacci sequence to `n` places, with each alternating value as `"skip"`. For example: `"1 skip 2 skip 5 skip 13 skip 34"` Return the result as a string You can presume that `n` is always a positive integer between (and including) 1 and 64.
["def skiponacci(n):\n s = '1'\n num = 1\n prv = 0\n for i in range(1,n):\n new = num + prv\n prv = num\n num = new\n if i%2 == 0:\n s = s + ' ' + str(num)\n else:\n s += ' skip'\n\n return s", "def skiponacci(n):\n fib = [1, 1][:n]\n for _ i...
{"fn_name": "skiponacci", "inputs": [[1], [5], [7]], "outputs": [["1"], ["1 skip 2 skip 5"], ["1 skip 2 skip 5 skip 13"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,452
def skiponacci(n):
0b7b9a08ee154bb15d6201794076bd88
UNKNOWN
What is an anagram? Well, two words are anagrams of each other if they both contain the same letters. For example: ``` 'abba' & 'baab' == true 'abba' & 'bbaa' == true 'abba' & 'abbba' == false 'abba' & 'abca' == false ``` Write a function that will find all the anagrams of a word from a list. You will be given two...
["def anagrams(word, words): return [item for item in words if sorted(item)==sorted(word)]", "from collections import Counter\n\ndef anagrams(word, words):\n counts = Counter(word)\n return [w for w in words if Counter(w) == counts]", "def anagrams(word, words):\n match = sorted(word)\n return [w for w in w...
{"fn_name": "anagrams", "inputs": [["abba", ["aabb", "abcd", "bbaa", "dada"]], ["racer", ["crazer", "carer", "racar", "caers", "racer"]], ["a", ["a", "b", "c", "d"]], ["ab", ["cc", "ac", "bc", "cd", "ab", "ba", "racar", "caers", "racer"]], ["abba", ["a", "b", "c", "d", "aabb", "bbaa", "abab", "baba", "baab", "abcd", "a...
INTRODUCTORY
PYTHON3
CODEWARS
5,256
def anagrams(word, words):
9b35c12f15a69569a51c76f1500fa6a2
UNKNOWN
You need to swap the head and the tail of the specified array: the head (the first half) of array moves to the end, the tail (the second half) moves to the start. The middle element (if it exists) leaves on the same position. Return new array. For example: ``` [ 1, 2, 3, 4, 5 ] => [ 4, 5, 3, 1, 2 ] \...
["def swap_head_tail(a):\n r, l = (len(a)+1)//2, len(a)//2\n return a[r:] + a[l:r] + a[:l]", "def swap_head_tail(lst):\n n, d = divmod(len(lst), 2)\n return lst[n+d:] + [lst[n]] * d + lst[:n]", "def swap_head_tail(arr):\n if len(arr) == 1: return arr\n n = len(arr)//2\n res,res2 = arr[:n],arr[-n:]...
{"fn_name": "swap_head_tail", "inputs": [[[-1, 2]], [[1, 2, -3, 4, 5, 6, -7, 8]]], "outputs": [[[2, -1]], [[5, 6, -7, 8, 1, 2, -3, 4]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,083
def swap_head_tail(arr):
af230fa7cb16b2535aec2ef87c422410
UNKNOWN
# Task Given a square `matrix`, your task is to reverse the order of elements on both of its longest diagonals. The longest diagonals of a square matrix are defined as follows: * the first longest diagonal goes from the top left corner to the bottom right one; * the second longest diagonal goes from the top right cor...
["def reverse_on_diagonals(matrix):\n copy = [ line[:] for line in matrix ]\n for i in range(len(matrix)):\n copy[i][i] = matrix[-1-i][-1-i]\n copy[i][-1-i] = matrix[-1-i][i]\n \n return copy", "def reverse_on_diagonals(matrix):\n l = len(matrix)\n for i in range(l // 2):\n j =...
{"fn_name": "reverse_on_diagonals", "inputs": [[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[239]]], [[[1, 10], [100, 1000]]], [[[43, 455, 32, 103], [102, 988, 298, 981], [309, 21, 53, 64], [2, 22, 35, 291]]]], "outputs": [[[[9, 2, 7], [4, 5, 6], [3, 8, 1]]], [[[239]]], [[[1000, 100], [10, 1]]], [[[291, 455, 32, 2], [102, 53...
INTRODUCTORY
PYTHON3
CODEWARS
2,653
def reverse_on_diagonals(matrix):
adc356bf148e17597e515e395db98350
UNKNOWN
Implement function which will return sum of roots of a quadratic equation rounded to 2 decimal places, if there are any possible roots, else return **None/null/nil/nothing**. If you use discriminant,when discriminant = 0, x1 = x2 = root => return sum of both roots. There will always be valid arguments. Quadratic equa...
["def roots(a,b,c):\n if b**2>=4*a*c:\n return round(-b/a,2)", "def roots(a,b,c):\n import math\n d = b ** 2 - 4 * a * c\n if d > 0:\n return round(-2 * b / (2 * a), 2)\n elif d == 0:\n x = -b / (2 * a)\n return x * 2\n else:\n return None", "def roots(a,b,c):\n r...
{"fn_name": "roots", "inputs": [[1, -35, -23], [6, 0, -24], [-5, 21, 0], [6, 4, 8], [1, 5, -24], [3, 11, 6], [2, 2, 9], [1, -1.6666666666666667, -26], [1, 6, 10], [7, -2, -5], [1, 8, 20], [2, 3, -2], [1, 4, 12], [3, -2, -5], [3, 4, 9], [5, 4, 0], [4, -5, 0], [1, 4, 9], [1, 0, -49], [2, 8, 8], [1, 0, -0.16], [1, 6, 12],...
INTRODUCTORY
PYTHON3
CODEWARS
1,587
def roots(a,b,c):
e3275599138bacedbeb430dc2d25941e
UNKNOWN
## Story There are four warriors, they need to go through a dark tunnel. Tunnel is very narrow, every time only can let two warriors through, and there are lot of dangerous traps. Fortunately, they have a lamp that can illuminate the tunnel to avoid being trapped by the trap. In order to pass this tunnel, they need f...
["def shortest_time(speed):\n a,b,c,d = sorted(speed)\n return a+b+d + min(2*b, a+c)", "from itertools import combinations\n\ndef shortest_time(xs, ys=[]):\n if len(xs) == 2:\n return max(xs)\n result = 999999999\n for i, j in combinations(range(len(xs)), 2):\n m = max(xs[i], xs[j])\n ...
{"fn_name": "shortest_time", "inputs": [[[3, 4, 5, 6]], [[3, 7, 10, 18]], [[5, 5, 6, 7]], [[5, 6, 30, 40]]], "outputs": [[21], [41], [27], [63]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,068
def shortest_time(speed):
58a9934f072e619853deb9b26567841d
UNKNOWN
In this Kata, you will be given two positive integers `a` and `b` and your task will be to apply the following operations: ``` i) If a = 0 or b = 0, return [a,b]. Otherwise, go to step (ii); ii) If a ≥ 2*b, set a = a - 2*b, and repeat step (i). Otherwise, go to step (iii); iii) If b ≥ 2*a, set b = b - 2*a, and repeat ...
["def solve(a,b):\n if not (a and b): return [a, b]\n if a >= 2*b: return solve(a%(2*b), b)\n if b >= 2*a: return solve(a, b%(2*a))\n return [a, b]", "def solve(a,b):\n '''\n Used the % operator instead of repeated subtraction of a - 2*b or b - 2*a\n Because as long as a > 2*b, the repeated subtrac...
{"fn_name": "solve", "inputs": [[6, 19], [2, 1], [22, 5], [2, 10], [8796203, 7556], [7, 11], [19394, 19394]], "outputs": [[[6, 7]], [[0, 1]], [[0, 1]], [[2, 2]], [[1019, 1442]], [[7, 11]], [[19394, 19394]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,987
def solve(a,b):
94909da5ff62857a6e88dc74b1fcee78
UNKNOWN
Some languages like Chinese, Japanese, and Thai do not have spaces between words. However, most natural languages processing tasks like part-of-speech tagging require texts that have segmented words. A simple and reasonably effective algorithm to segment a sentence into its component words is called "MaxMatch". ## Max...
["def max_match(s):\n result = []\n \n while s:\n for size in range(len(s), 0, -1):\n word = s[:size]\n if word in VALID_WORDS:\n break\n \n result.append(word)\n s = s[size:]\n \n return result", "# KenKamau's solution\ndef max_match(st):\...
{"fn_name": "max_match", "inputs": [[""]], "outputs": [[[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,348
def max_match(sentence):
973b08434c6e2ec9ed55eeaa3e2fff36
UNKNOWN
# Task Imagine `n` horizontal lines and `m` vertical lines. Some of these lines intersect, creating rectangles. How many rectangles are there? # Examples For `n=2, m=2,` the result should be `1`. there is only one 1x1 rectangle. For `n=2, m=3`, the result should be `3`. there are two 1x1 rectangles and one 1x2 r...
["def rectangles(n, m):\n return m * n * (m - 1) * (n - 1) / 4", "def rectangles(n, m):\n return n*m*(n-1)*(m-1)//4", "rectangles=lambda n,m:n*~-n*m*~-m//4", "def rectangles(n, m):\n return ((m-1) * (n-1) * n * m) / 4;", "def rectangles(n, m):\n result = 0\n \n if n < 2 or m < 2:\n return result\...
{"fn_name": "rectangles", "inputs": [[2, 3], [2, 2], [1, 1], [0, 1], [3, 3], [100, 100]], "outputs": [[3], [1], [0], [0], [9], [24502500]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,131
def rectangles(n, m):
32b6c8287e1b40ff6d859015667eee0e
UNKNOWN
You will be given a fruit which a farmer has harvested, your job is to see if you should buy or sell. You will be given 3 pairs of fruit. Your task is to trade your harvested fruit back into your harvested fruit via the intermediate pair, you should return a string of 3 actions. if you have harvested apples, you woul...
["def buy_or_sell(pairs, harvested_fruit):\n \n currentFruit = harvested_fruit\n actions = list()\n \n for pair in pairs:\n \n if currentFruit not in pair: return 'ERROR'\n \n if currentFruit == pair[0]:\n \n actions.append('buy')\n currentFruit = pair[1]\...
{"fn_name": "buy_or_sell", "inputs": [[[["apple", "orange"], ["orange", "pear"], ["apple", "pear"]], "apple"], [[["orange", "apple"], ["orange", "pear"], ["pear", "apple"]], "apple"], [[["apple", "orange"], ["pear", "orange"], ["apple", "pear"]], "apple"], [[["orange", "apple"], ["pear", "orange"], ["pear", "apple"]], ...
INTRODUCTORY
PYTHON3
CODEWARS
3,259
def buy_or_sell(pairs, harvested_fruit):
b8adfd4249e66c4590a74709d699d27b
UNKNOWN
Maya writes weekly articles to a well known magazine, but she is missing one word each time she is about to send the article to the editor. The article is not complete without this word. Maya has a friend, Dan, and he is very good with words, but he doesn't like to just give them away. He texts Maya a number and she ne...
["hidden=lambda n: \"\".join(\"oblietadnm\"[int(d)] for d in str(n))", "trans = dict(zip('6174329805','abdeilmnot'))\n\ndef hidden(num):\n return ''.join( trans[char] for char in str(num) )", "def hidden(num):\n return str(num).translate(str.maketrans(\"6174329805\", \"abdeilmnot\"))", "def hidden(num):\n d = ...
{"fn_name": "hidden", "inputs": [[637], [7468], [49632], [1425], [6250], [12674], [4735], [7345], [3850], [2394], [2068], [137], [1065], [6509], [3549], [5394], [56124], [968], [103247], [67935], [7415], [2687], [261], [8054], [942547]], "outputs": [["aid"], ["dean"], ["email"], ["belt"], ["alto"], ["blade"], ["edit"],...
INTRODUCTORY
PYTHON3
CODEWARS
1,766
def hidden(num):
809e72f70a5088d9015abd0bb7563e82
UNKNOWN
# Task Call two arms equally strong if the heaviest weights they each are able to lift are equal. Call two people equally strong if their strongest arms are equally strong (the strongest arm can be both the right and the left), and so are their weakest arms. Given your and your friend's arms' lifting capabilities ...
["def are_equally_strong(your_left, your_right, friends_left, friends_right):\n return sorted([your_left, your_right]) == sorted([friends_left, friends_right])", "def are_equally_strong(yl,yr,fl,fr):\n return (yl==fl and yr==fr) or (yl==fr and yr==fl)", "def are_equally_strong(yl, yr, fl, fr):\n return {yl, yr} ==...
{"fn_name": "are_equally_strong", "inputs": [[10, 15, 15, 10], [15, 10, 15, 10], [10, 10, 10, 10], [15, 10, 15, 9], [10, 5, 5, 10], [1, 10, 10, 0], [10, 5, 11, 4]], "outputs": [[true], [true], [true], [false], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,321
def are_equally_strong(your_left, your_right, friends_left, friends_right):
f3db9368aca19f978ff7128d419f0197
UNKNOWN
One of the first algorithm used for approximating the integer square root of a positive integer `n` is known as "Hero's method", named after the first-century Greek mathematician Hero of Alexandria who gave the first description of the method. Hero's method can be obtained from Newton's method which came 16 centuries ...
["def int_rac(n, guess):\n \"\"\"Integer Square Root of an Integer\"\"\"\n x = guess\n cnt = 1\n while True:\n newx = (x + n // x) // 2 \n if abs(x - newx) < 1:\n return cnt\n x = newx\n cnt += 1", "def int_rac(n, guess):\n cnt = 0\n \n while True:\n cn...
{"fn_name": "int_rac", "inputs": [[25, 1], [125348, 300], [125348981764, 356243], [236, 12], [48981764, 8000], [6999, 700], [16000, 400], [16000, 100], [2500, 60], [250000, 600], [95367431640625, 1], [9094947017729282379150390625, 1], [835871232077058, 1], [246391990316004, 1], [403832254158749, 1], [217414278071071, 1...
INTRODUCTORY
PYTHON3
CODEWARS
1,145
def int_rac(n, guess):
5485f24441a9afbbe90f3da1a989ef48
UNKNOWN
This is the first step to understanding FizzBuzz. Your inputs: a positive integer, n, greater than or equal to one. n is provided, you have NO CONTROL over its value. Your expected output is an array of positive integers from 1 to n (inclusive). Your job is to write an algorithm that gets you from the input to the...
["def pre_fizz(n):\n #your code here\n return list(range(1, n+1))", "def pre_fizz(n):\n return [i + 1 for i in range(0, n)]", "def pre_fizz(n):\n \"\"\"Make a list from 1 to n\"\"\"\n return list(range(1, n+1))", "def pre_fizz(n):\n return [x for x in range(1, n+1)]", "pre_fizz=lambda n: list(range(1,...
{"fn_name": "pre_fizz", "inputs": [[1], [2], [3], [4], [5]], "outputs": [[[1]], [[1, 2]], [[1, 2, 3]], [[1, 2, 3, 4]], [[1, 2, 3, 4, 5]]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,390
def pre_fizz(n):
924546685fe55209ee4b54b27ec5028e
UNKNOWN
Given a string of characters, I want the function `findMiddle()`/`find_middle()` to return the middle number in the product of each digit in the string. Example: 's7d8jd9' -> 7, 8, 9 -> 7\*8\*9=504, thus 0 should be returned as an integer. Not all strings will contain digits. In this case and the case for any non-str...
["from operator import mul\nfrom functools import reduce\n\ndef find_middle(s):\n if not s or not isinstance(s,str): return -1\n \n lstDig = [int(c) for c in s if c.isnumeric()]\n if not lstDig: return -1\n \n prod = str( reduce(mul,lstDig) )\n i = (len(prod) - 1) // 2\n return int(prod[i:-i ...
{"fn_name": "find_middle", "inputs": [["s7d8jd9"], ["58jd9fgh/fgh6s.,sdf"], ["s7d8jd9dfg4d"], ["s7d8j"], ["asd.fasd.gasdfgsdfgh-sdfghsdfg/asdfga=sdfg"], ["44555"], [null], [[1, 2, 3, 4, 5, 6]], [["a", "b", "c"]], ["5d8jd9fgh/fgh6s.,sdf8sdf9sdf98 3 0"], [" "], ["e^6*9=#asdfd7-4"], ["s7d8jd9qwertqwrt v654ed1frg6...
INTRODUCTORY
PYTHON3
CODEWARS
5,920
def find_middle(string):
06104ec8efb6dac06f89b416f1bb8d79
UNKNOWN
The most basic encryption method is to map a char to another char by a certain math rule. Because every char has an ASCII value, we can manipulate this value with a simple math expression. For example 'a' + 1 would give us 'b', because 'a' value is 97 and 'b' value is 98. You will need to write a method which does ex...
["def encrypt(text, rule):\n return \"\".join(chr((ord(i)+rule)%256) for i in text)", "def encrypt(text, rule):\n return \"\".join(chr((ord(c) + rule) % 256) for c in text)", "def encrypt(text, key):\n return \"\".join(chr((ord(ch) + key) & 255) for ch in text)", "def encrypt(text, rule):\n return ''.join(c...
{"fn_name": "encrypt", "inputs": [["", 1], ["a", 1], ["please encrypt me", 2]], "outputs": [[""], ["b"], ["rngcug\"gpet{rv\"og"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,079
def encrypt(text, rule):
ecffe57a6bfaa93863167f1929f14b3a
UNKNOWN
The objective is to disambiguate two given names: the original with another Let's start simple, and just work with plain ascii strings. The function ```could_be``` is given the original name and another one to test against. ```python # should return True if the other name could be the same person > could_be("Chuc...
["def could_be(original, another):\n if not another.strip(): return False\n return all(name in original.split() for name in another.split())", "def could_be(original, another):\n original, another = (set(s.split()) for s in (original, another))\n return bool(another) and another <= original", "def could_be(...
{"fn_name": "could_be", "inputs": [["Carlos Ray Norris", "Carlos Ray Norris"], ["Carlos Ray Norris", "Carlos Ray"], ["Carlos Ray Norris", "Ray Norris"], ["Carlos Ray Norris", "Carlos Norris"], ["Carlos Ray Norris", "Norris"], ["Carlos Ray Norris", "Carlos"], ["Carlos Ray Norris", "Norris Carlos"], ["Carlos Ray Norris",...
INTRODUCTORY
PYTHON3
CODEWARS
1,452
def could_be(original, another):
f132372fe3d54ec7c34baa68ab260cb6
UNKNOWN
The Padovan sequence is the sequence of integers `P(n)` defined by the initial values `P(0)=P(1)=P(2)=1` and the recurrence relation `P(n)=P(n-2)+P(n-3)` The first few values of `P(n)` are `1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 86, 114, 151, 200, 265, ...` ### Task The task is to write a met...
["def padovan(n):\n p0 = p1 = p2 = 1\n for i in range(n):\n p0, p1, p2 = p1, p2, p0 + p1\n return p0", "from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef padovan(n):\n return n<3 or padovan(n-2) + padovan(n-3)", "from functools import lru_cache\n\n@lru_cache()\ndef padovan(n):\n ret...
{"fn_name": "padovan", "inputs": [[100]], "outputs": [[1177482265857]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,541
def padovan(n):
265f88a102e99104546c4ee982ec9589
UNKNOWN
## Problem Determine whether a positive integer number is **colorful** or not. `263` is a colorful number because `[2, 6, 3, 2*6, 6*3, 2*6*3]` are all different; whereas `236` is not colorful, because `[2, 3, 6, 2*3, 3*6, 2*3*6]` have `6` twice. So take all consecutive subsets of digits, take their product and ensur...
["def colorful(number):\n base_result = []\n for x in str(number):\n base_result.append(int(x))\n for y in range(len(base_result) - 1):\n temp = base_result[y] * base_result[y + 1]\n base_result.append(temp)\n # Should you really eval the last value ? :shrug: If so, would use eval\n ...
{"fn_name": "colorful", "inputs": [[5], [23], [263], [235789], [50], [13], [236], [2357893]], "outputs": [[true], [true], [true], [true], [false], [false], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,036
def colorful(number):
ec6fce2e85ab454da835d33983b47d6a
UNKNOWN
You are given a length of string and two thumbtacks. On thumbtack goes into the focus point *F₀* with coordinates *x₀* and *y₀*, and the other does into point *F₁* with points *x₁* and *y₁*. The string is then tied at the ends to the thumbtacks and has length *l* excluding the knots at the ends. If you pull the string ...
["dist = lambda p1, p2: ((p1['x']-p2['x'])**2+(p1['y']-p2['y'])**2)**0.5\nellipse_contains_point = lambda f0, f1, l, p : dist(p, f0)+dist(p, f1)<=l", "from math import hypot\n\ndef ellipse_contains_point(f0, f1, l, p): \n d0 = hypot(f0[\"x\"] - p[\"x\"], f0[\"y\"] - p[\"y\"])\n d1 = hypot(f1[\"x\"] - p[\"x\"], f1...
{"fn_name": "ellipse_contains_point", "inputs": [[{"x": 0, "y": 0}, {"x": 0, "y": 0}, 2, {"x": 0, "y": 0}], [{"x": 0, "y": 0}, {"x": 0, "y": 0}, 2, {"x": 1, "y": 1}]], "outputs": [[true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,213
def ellipse_contains_point(f0, f1, l, p):
ad961a88eb654871db7cfae070c1bbf5
UNKNOWN
Speedcubing is the hobby involving solving a variety of twisty puzzles, the most famous being the 3x3x3 puzzle or Rubik's Cube, as quickly as possible. In the majority of Speedcubing competitions, a Cuber solves a scrambled cube 5 times, and their result is found by taking the average of the middle 3 solves (ie. the s...
["def cube_times(times):\n return (round((sum(times) - (min(times) + max(times)))/3 , 2), min(times))", "def cube_times(times):\n times = sorted(times)\n return (round(sum(times[1:-1])/3,2), times[0])", "from statistics import mean\n\ndef cube_times(times):\n return (round(mean(sorted(times)[1:4]), 2), min(...
{"fn_name": "cube_times", "inputs": [[[9.5, 7.6, 11.4, 10.5, 8.1]], [[13.4, 12.3, 9.5, 11.9, 20.8]], [[28.3, 14.5, 17.3, 8.9, 10.1]]], "outputs": [[[9.37, 7.6]], [[12.53, 9.5]], [[13.97, 8.9]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,322
def cube_times(times):
95acb7f10cd37d99050ed6dff96c92da
UNKNOWN
Have a look at the following numbers. ``` n | score ---+------- 1 | 50 2 | 150 3 | 300 4 | 500 5 | 750 ``` Can you find a pattern in it? If so, then write a function `getScore(n)`/`get_score(n)`/`GetScore(n)` which returns the score for any positive number `n`: ```c++ int getScore(1) = return 50; int getS...
["def get_score(n):\n return n * (n + 1) * 25", "def get_score(n):\n return 50*(n*(n+1))/2\n \n \n \n", "get_score = lambda n: 25 * n * (n + 1)", "get_score = lambda n, a=0: sum(a+i*50 for i in range(n+1))", "def get_score(n):\n return sum([x*50 for x in range(n+1)])", "def get_score(n):\n return 2...
{"fn_name": "get_score", "inputs": [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [20], [30], [100], [123], [1000], [1234], [10000], [12345]], "outputs": [[50], [150], [300], [500], [750], [1050], [1400], [1800], [2250], [2750], [10500], [23250], [252500], [381300], [25025000], [38099750], [2500250000], [381028425...
INTRODUCTORY
PYTHON3
CODEWARS
465
def get_score(n):
cc7b90ca0fca6360e250f1133060548b
UNKNOWN
There are some perfect squares with a particular property. For example the number ```n = 256``` is a perfect square, its square root is ```16```. If we change the position of the digits of n, we may obtain another perfect square``` 625``` (square root = 25). With these three digits ```2```,```5``` and ```6``` we can ge...
["from itertools import count, permutations\n\ndef next_perfectsq_perm(limit_below, k):\n for n in count(int(limit_below**.5)+1):\n s = str(n**2)\n if '0' not in s:\n sq_set = {x for x in (int(''.join(p)) for p in permutations(s)) if (x**.5).is_integer()}\n if len(sq_set) == k:\n ...
{"fn_name": "next_perfectsq_perm", "inputs": [[100, 2], [100, 3], [100, 4], [500, 2], [1000, 3], [100000, 4], [144, 2], [145, 2], [440, 2], [441, 2], [257, 2]], "outputs": [[441], [961], [81796], [625], [9216], [298116], [625], [625], [441], [625], [441]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,555
def next_perfectsq_perm(lower_limit, k):
f62484600046d0013a4400779e03a925
UNKNOWN
A little weird green frog speaks in a very strange variation of English: it reverses sentence, omitting all puntuation marks `, ; ( ) - ` except the final exclamation, question or period. We urgently need help with building a proper translator. To simplify the task, we always use lower-case letters. Apostrophes are fo...
["import re\n\ndef frogify(s):\n return ' '.join( ' '.join(re.findall(r'[a-z]+', sentence)[::-1]) + punct for sentence,punct in re.findall(r'(.*?)([.!?])', s) )", "import re\n\ndef frogify(s):\n delimiters = set([\".\", \"!\", \"?\"])\n sentences = re.split(\"([\\!\\.\\?])\", re.sub(\"[,\\;\\)\\(-]\", \"\", s)...
{"fn_name": "frogify", "inputs": [["i am a frog."], ["can you do it?"], ["seems like you understand!"], ["multisentence is good. is not it?"], ["green, red or orange - we all just frogs, do not you think so?"]], "outputs": [["frog a am i."], ["it do you can?"], ["understand you like seems!"], ["good is multisentence. i...
INTRODUCTORY
PYTHON3
CODEWARS
3,257
def frogify(s):
37086e3998f52304fbff1c0fca95bc39
UNKNOWN
Take a sentence (string) and reverse each word in the sentence. Do not reverse the order of the words, just the letters in each word. If there is punctuation, it should be interpreted as a regular character; no special rules. If there is spacing before/after the input string, leave them there. String will not be emp...
["def reverser(sentence):\n return ' '.join(i[::-1] for i in sentence.split(' '))", "def reverser(s):\n return \" \".join(w[::-1] for w in s.split(\" \"))", "import re\ndef reverser(sentence):\n return ''.join(w[::-1] if ' ' not in w else w for w in re.findall(r'(?:\\w+)|(?:\\s+)', sentence)) ", "from re impo...
{"fn_name": "reverser", "inputs": [["How now brown cow"], ["racecar"], ["Hi mom"], [" "], [" "], ["go away"], ["I like noodles"], ["The red pen wrote on the wall"], ["Green trucks drive fast"], ["Pink trucks drive slow"]], "outputs": [["woH won nworb woc"], ["racecar"], ["iH mom"], [" "], [" "], ["og yawa"], ["I ekil...
INTRODUCTORY
PYTHON3
CODEWARS
1,362
def reverser(sentence):
f34480b44a9a9c30e5e61c7fa8bcd9ba
UNKNOWN
# Task: Given a list of numbers, determine whether the sum of its elements is odd or even. Give your answer as a string matching `"odd"` or `"even"`. If the input array is empty consider it as: `[0]` (array with a zero). ## Example: ``` odd_or_even([0]) == "even" odd_or_even([0, 1, 4]) == "odd" odd_or...
["def odd_or_even(arr):\n return 'even' if sum(arr) % 2 == 0 else 'odd'", "def odd_or_even(arr):\n if sum(arr)%2==0:\n return 'even'\n else:\n return 'odd'", "def odd_or_even(arr):\n return ('even', 'odd')[sum(arr) % 2]", "def odd_or_even(arr):\n return ['even','odd'][sum(arr)%2]", "def odd...
{"fn_name": "odd_or_even", "inputs": [[[0, 1, 2]], [[0, 1, 3]], [[1023, 1, 2]]], "outputs": [["odd"], ["even"], ["even"]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,286
def odd_or_even(arr):
4890d2305270c9219abf72953b969f4c
UNKNOWN
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
PYTHON3
CODEWARS
1,750
def is_isogram(string):
95f31392cadeb1cd808480743fc39a7d
UNKNOWN
#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
PYTHON3
CODEWARS
898
def archers_ready(archers):
3b310e44bc30c8753d625e3333d7ac32
UNKNOWN
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
PYTHON3
CODEWARS
13,883
def area_or_perimeter(l , w):
87dc46832b6174fabe5c7423a7316bed
UNKNOWN
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
PYTHON3
CODEWARS
1,581
def cost(mins):
9a830acbbc21f3619c86e385117e3dba
UNKNOWN
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
PYTHON3
CODEWARS
821
def is_negative_zero(n):
3782715656887c098a8fcae83197d7ba
UNKNOWN
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
PYTHON3
CODEWARS
3,726
def indices(n, d):
6ea108ebd683fe3e01801f3b6a9aa2a2
UNKNOWN
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
PYTHON3
CODEWARS
1,521
def digits(num):
5035054290efa75f3ce9427d8141ac0c
UNKNOWN
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
PYTHON3
CODEWARS
1,347
def lostSheep(friday,saturday,total):
6a27c8e0bc0da29f0f2f40819d7e2bc2
UNKNOWN
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
PYTHON3
CODEWARS
1,977
def count_smileys(arr):
58303f89213020c6d1aca91d7d266ee9
UNKNOWN
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
PYTHON3
CODEWARS
3,020
def did_we_win(plays):
29196cc3ad8b56375e518f8bb0864d9c
UNKNOWN
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
PYTHON3
CODEWARS
1,399
def count_pal(n):
0adeef4e36c0b50f1cd6f3d5dac43be7
UNKNOWN
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
PYTHON3
CODEWARS
8,381
def solve(a, b):
f3b1d8f67ec2d5522f64535cb13adb53
UNKNOWN
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
PYTHON3
CODEWARS
1,984
def find_spaceship(astromap):
7704ecb40b7457083c07e9db82305d81
UNKNOWN
### 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
PYTHON3
CODEWARS
6,326
def combine_names(first, last):
c56824adc3a28fa869b4c3ea78d95b06
UNKNOWN
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
PYTHON3
CODEWARS
2,184
def remove_chars(s):
26bb2422c5621cbb73547400ec6a5b86
UNKNOWN
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
PYTHON3
CODEWARS
1,970
def min_unfairness(arr,k):
a1feb8c5d4a9ec24319a87561c0cd6c5
UNKNOWN
## 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
PYTHON3
CODEWARS
1,446
def uncollapse(digits):
14bb3449c59b66c1d54179f99275ef98
UNKNOWN
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
PYTHON3
CODEWARS
6,146
def artificial_rain(garden):
27b6eb97842aafee7d9988bfe05d41cf
UNKNOWN
# 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
PYTHON3
CODEWARS
1,346
def fraction(a, b):
7c871f17f31d5a4b669ae262d065f44b
UNKNOWN
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
PYTHON3
CODEWARS
1,117
def generate_pairs(n):
94d28c740fab8ea28d4a19cc92b47fb4
UNKNOWN
# 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
PYTHON3
CODEWARS
2,036
def is_in_middle(s):
f5a33fa4884b5a3e33ede48c3a2d24bc
UNKNOWN
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
PYTHON3
CODEWARS
12,704
def change_case(identifier, targetCase):
9309aeaec067ac9c11bdca9a196918a9
UNKNOWN
## 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
PYTHON3
CODEWARS
1,015
def profitLoss(records):
39e67919fb211dc0c822f0df15185a07
UNKNOWN
## 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
PYTHON3
CODEWARS
5,788
def yellow_be_gone(s):
dd9d855229a31130283504eae51d6f79
UNKNOWN
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
PYTHON3
CODEWARS
1,461
def find_lowest_int(k):
ffdaea9b53a36d6808e00231d4552509
UNKNOWN
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
PYTHON3
CODEWARS
1,277
def repeat_sum(l):
415de8424b0be9eab199831c9d5fba73
UNKNOWN
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
PYTHON3
CODEWARS
14,877
def men_still_standing(cards):
464ebcb1ee21fde9a366bed9ced1a470
UNKNOWN
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
PYTHON3
CODEWARS
2,544
def next_higher(value):
ce2713f019213f84b0076ec53aa640f7
UNKNOWN
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
PYTHON3
CODEWARS
1,776
def freq_seq(s, sep):
904a1587a9b546939f55e1fab77d180d
UNKNOWN
# 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
PYTHON3
CODEWARS
12,352
def is_thue_morse(seq):
9937ae390eda33785fbdec16fbeddf7c
UNKNOWN
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
PYTHON3
CODEWARS
1,226
def elevator_distance(array):
bfcbaabb551773ee2967653956cbb285
UNKNOWN
# 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
PYTHON3
CODEWARS
38,106
def fold_cube(nums):
ecdde50bf9b24e28ce10c81073bcf67c
UNKNOWN
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
PYTHON3
CODEWARS
926
def you_are_a_cube(cube):
a931970146414128c9c3c3a80b1bb3ba
UNKNOWN
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
PYTHON3
CODEWARS
1,366
def solve(st):
82942651a5ee6d9d805f1754de76edc9
UNKNOWN
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
PYTHON3
CODEWARS
2,736
def switch_endian(n, bits):
702a1cf0f621fccee5eea6227e49ecf0
UNKNOWN
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
PYTHON3
CODEWARS
2,026
def compare(s1, s2):
9034f50837140f5efa4f77ec738e3142
UNKNOWN
# 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
PYTHON3
CODEWARS
19,458
def is_palindrome(string):
97ce8696317690a35ef96af96c5d78d2
UNKNOWN
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
PYTHON3
CODEWARS
1,587
def tram(stops, descending, onboarding):
e2e5c9537ccb7cd6685ef3303fcf1f0f
UNKNOWN
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
PYTHON3
CODEWARS
1,519
def no_ifs_no_buts(a, b):
e7888786810c259944beae2e3288dec2
UNKNOWN
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
PYTHON3
CODEWARS
1,998
def yoga(classroom, poses):
f4003e70ae03a6a590cd5b5cb69e1861
UNKNOWN
.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
PYTHON3
CODEWARS
4,066
def count_sixes(n):
83a7840b6385a4a9fa1584f08beb573d
UNKNOWN
# 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
PYTHON3
CODEWARS
1,336
def find_missing_number(numbers):
99026f79befdf0c53ffa78194edad4ad
UNKNOWN
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
PYTHON3
CODEWARS
8,278
def find(n,z):
04d1e218ef5dcf41318eea5c9bbda610
UNKNOWN
## 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
PYTHON3
CODEWARS
1,698
def split_odd_and_even(n):
e36d8db97880d313acf65a1b8d30db9f
UNKNOWN
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
PYTHON3
CODEWARS
1,746
def compare_versions(version1, version2):
ecf63640df9a662b48b648db467fc861
UNKNOWN
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
PYTHON3
CODEWARS
2,902
def proc_arr(arr):
4efb92bcaf9224516b087bfadb085bcb
UNKNOWN
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
PYTHON3
CODEWARS
2,916
def loose_change(cents):
a9770a0aa986cb7b15fb01aae034c222
UNKNOWN
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
PYTHON3
CODEWARS
10,504
def solve(a,b):
c758f07bbc2eec918344da1eebaec089
UNKNOWN
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
PYTHON3
CODEWARS
4,478
def mult_primefactor_sum(a, b):
6232c6857073116053bc7d8e05e70d77
UNKNOWN
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
PYTHON3
CODEWARS
1,829
def to_seconds(time):
caac478416858a334396a6bfdbedc05f
UNKNOWN
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
PYTHON3
CODEWARS
4,723
def jumbled_string(s, n):
3dbe5dd66df0dd25a030377334a924f7
UNKNOWN
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
PYTHON3
CODEWARS
2,796
def ball_probability(balls):
cde28f8856cf8162d05022fae9a4f95f
UNKNOWN
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
PYTHON3
CODEWARS
12,803
def mango(quantity, price):
442a1a6a8926907695575c81cddc887f
UNKNOWN
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
PYTHON3
CODEWARS
1,673
def isMultiple(a, b, n):