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
664afe69ee38f6e589de07cbc7fc72f3
UNKNOWN
=====Problem Statement===== The provided code stub reads two integers from STDIN, a and b. Add code to print three lines where: The first line contains the sum of the two numbers. The second line contains the difference of the two numbers (first - second). The third line contains the product of the two numbers. =====E...
["# Enter your code here. Read input from STDIN. Print output to STDOUT\na=int(input())\nb=int(input())\nprint((a+b))\nprint((a-b))\nprint((a*b))\n", "def __starting_point():\n a = int(input())\n b = int(input())\n \n print((a + b))\n print((a - b))\n print((a * b))\n\n__starting_point()"]
{"inputs": ["3\n2"], "outputs": ["5\n1\n6"]}
INTRODUCTORY
PYTHON3
HACKERRANK
308
if __name__ == '__main__': a = int(input()) b = int(input())
aefd8a835223c126ed36c8ceb989617d
UNKNOWN
=====Problem Statement===== Mr. Vincent works in a door mat manufacturing company. One day, he designed a new door mat with the following specifications: Mat size must be NXM. (N is an odd natural number, M and is 3 times N.) The design should have 'WELCOME' written in the center. The design pattern should only use |, ...
["N, M = list(map(int,input().split())) # More than 6 lines of code will result in 0 score. Blank lines are not counted.\nfor i in range(1,N,2): \n print((int((M-3*i)/2)*'-'+(i*'.|.')+int((M-3*i)/2)*'-'))\nprint((int((M-7)/2)*'-'+'WELCOME'+int((M-7)/2)*'-'))\nfor i in range(N-2,-1,-2): \n print((int((M-3*i)/2)*'-...
{"inputs": ["7 21"], "outputs": ["---------.|.---------\n------.|..|..|.------\n---.|..|..|..|..|.---\n-------WELCOME-------\n---.|..|..|..|..|.---\n------.|..|..|.------\n---------.|.---------"]}
INTRODUCTORY
PYTHON3
HACKERRANK
673
# Enter your code here. Read input from STDIN. Print output to STDOUT
2cb4b3feeafacbfe304889a8a3f552ed
UNKNOWN
=====Problem Statement===== A valid postal code P have to fullfil both below requirements: 1. P must be a number in the range from 100000 to 999999 inclusive. 2. P must not contain more than one alternating repetitive digit pair. Alternating repetitive digits are digits which repeat immediately after the next digit. ...
["import re\np = input().strip()\nrange_check = bool(re.match(r'^[1-9][0-9]{5}$',p))\nrepeat_check = len(re.findall(r'(?=([0-9])[0-9]\\1)',p))\nprint((range_check == True and repeat_check<2))\n", "import re\n\nnum = input()\nprint(bool(re.match(r'^[1-9][\\d]{5}$', num) and len(re.findall(r'(\\d)(?=\\d\\1)', num))<2 ))"...
{"inputs": ["110000"], "outputs": ["False"]}
INTRODUCTORY
PYTHON3
HACKERRANK
321
regex_integer_in_range = r"_________" # Do not delete 'r'. regex_alternating_repetitive_digit_pair = r"_________" # Do not delete 'r'. import re P = input() print (bool(re.match(regex_integer_in_range, P)) and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)
c4f8f7c1adc6fea79bce750b939717e9
UNKNOWN
=====Function Descriptions===== We have seen the applications of union, intersection, difference and symmetric difference operations, but these operations do not make any changes or mutations to the set. We can use the following operations to create mutations to a set: .update() or |= Update the set by adding element...
["n = int(input())\na = set(map(int,input().split()))\nN = int(input())\nfor i in range(N):\n cmd = input().split()\n opt = cmd[0]\n s = set(map(int,input().split()))\n if (opt == 'update'):\n a |= s\n elif (opt == 'intersection_update'):\n a &= s\n elif (opt == 'difference_update'):\n ...
{"inputs": ["16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 24 52\n4\nintersection_update 10\n2 3 5 6 8 9 1 4 7 11\nupdate 2\n55 66\nsymmetric_difference_update 5\n22 7 35 62 58\ndifference_update 7\n11 22 35 55 58 62 66"], "outputs": ["38"]}
INTRODUCTORY
PYTHON3
HACKERRANK
1,210
# Enter your code here. Read input from STDIN. Print output to STDOUT
0a40438378715edc5e95976f2cfb38a0
UNKNOWN
=====Problem Statement===== The itertools module standardizes a core set of fast, memory efficient tools that are useful by themselves or in combination. Together, they form an iterator algebra making it possible to construct specialized tools succinctly and efficiently in pure Python. You are given a list of N lowerc...
["from itertools import combinations\nn = int(input())\nar = input().split()\nk = int(input())\ncomb_list = list(combinations(ar,k))\na_list = [e for e in comb_list if 'a' in e]\nprint((len(a_list) / len(comb_list)))\n", "#!/usr/bin/env python3\n\nimport string\nsymbols = string.ascii_lowercase\n\nfrom itertools import...
{"inputs": ["4\na a c d\n2"], "outputs": ["0.833333333333"]}
INTRODUCTORY
PYTHON3
HACKERRANK
657
# Enter your code here. Read input from STDIN. Print output to STDOUT
f3b9269f18d17ee37bf1c133837f9e87
UNKNOWN
=====Problem Statement===== The defaultdict tool is a container in the collections class of Python. It's similar to the usual dictionary (dict) container, but the only difference is that a defaultdict will have a default value if that key has not been set yet. If you didn't use a defaultdict you'd have to check to see ...
["from collections import defaultdict\nd = defaultdict(list)\nn,m=list(map(int,input().split()))\nfor i in range(n):\n w = input()\n d[w].append(str(i+1))\nfor j in range(m):\n w = input()\n print((' '.join(d[w]) or -1))\n", "#!/usr/bin/env python3\n\nfrom collections import defaultdict\n\ndef __starting_po...
{"inputs": ["5 2\na\na\nb\na\nb\na\nb"], "outputs": ["1 2 4\n3 5"]}
INTRODUCTORY
PYTHON3
HACKERRANK
744
# Enter your code here. Read input from STDIN. Print output to STDOUT
2154af0a62325149fe836af21b748dce
UNKNOWN
=====Function Descriptions===== HTML Hypertext Markup Language is a standard markup language used for creating World Wide Web pages. Parsing Parsing is the process of syntactic analysis of a string of symbols. It involves resolving a string into its component parts and describing their syntactic roles. HTMLParser An ...
["import re\nfrom html.parser import HTMLParser\n\nclass MyHTMLParser(HTMLParser):\n def handle_starttag(self, tag, attrs):\n print(\"Start\".ljust(6) + \":\", tag)\n for at in attrs:\n print(\"-> {} > {}\".format(at[0], at[1]))\n def handle_endtag(self, tag):\n print(\"End\".ljust...
{"inputs": ["2\n<html><head><title>HTML Parser - I</title></head>\n<body data-modal-target class='1'><h1>HackerRank</h1><br /></body></html>"], "outputs": ["Start : html\nStart : head\nStart : title\nEnd : title\nEnd : head\nStart : body\n-> data-modal-target > None\n-> class > 1\nStart : h1\nEnd : h1\nEmpty : br...
INTRODUCTORY
PYTHON3
HACKERRANK
697
# Enter your code here. Read input from STDIN. Print output to STDOUT
1b57a4a6dc43c77808c8f0be83ce774b
UNKNOWN
=====Problem Statement===== You are given a positive integer N. Your task is to print a palindromic triangle of size N. For example, a palindromic triangle of size 5 is: 1 121 12321 1234321 123454321 You can't take more than two lines. The first line (a for-statement) is already written for you. You have to complete ...
["for i in range(1,int(input())+1): #More than 2 lines will result in 0 score. Do not leave a blank line also\n print(((10**i//9)**2))\n"]
{"inputs": ["5"], "outputs": ["1\n121\n12321\n1234321\n123454321"]}
INTRODUCTORY
PYTHON3
HACKERRANK
141
for i in range(1,int(input())+1): #More than 2 lines will result in 0 score. Do not leave a blank line also print
4639cc7693fb05098a3c1b4b1c6654fc
UNKNOWN
=====Problem Statement===== You are given a function f(X) = X^2. You are also given K lists. The ith list consists of N_i elements. You have to pick one element from each list so that the value from the equation below is maximized: S = (f(X_1) + f(X_2) + ... + f(X_k))%M X_i denotes the element picked from the ith list...
["import itertools\n\nk, m = list(map(int,input().split()))\n\nmain_ar = []\nfor i in range(k):\n ar = list(map(int,input().split()))\n main_ar.append(ar[1:])\n\nall_combination = itertools.product(*main_ar)\nresult = 0\nfor single_combination in all_combination: \n result = max(sum([x*x for x in single_comb...
{"inputs": ["3 1000\n2 5 4\n3 7 8 9\n5 5 7 8 9 10"], "outputs": ["206"]}
INTRODUCTORY
PYTHON3
HACKERRANK
610
# Enter your code here. Read input from STDIN. Print output to STDOUT
064041b7797e456e67a5bdbee51a2b1d
UNKNOWN
=====Function Descriptions===== collections.OrderedDict An OrderedDict is a dictionary that remembers the order of the keys that were inserted first. If a new entry overwrites an existing entry, the original insertion position is left unchanged. Example Code >>> from collections import OrderedDict >>> >>> ordinary_d...
["import collections, re\nn = int(input())\nitem_od = collections.OrderedDict()\nfor i in range(n):\n record_list = re.split(r'(\\d+)$',input().strip())\n item_name = record_list[0]\n item_price = int(record_list[1])\n if item_name not in item_od:\n item_od[item_name]=item_price\n else:\n i...
{"inputs": ["9\nBANANA FRIES 12\nPOTATO CHIPS 30\nAPPLE JUICE 10\nCANDY 5\nAPPLE JUICE 10\nCANDY 5\nCANDY 5\nCANDY 5\nPOTATO CHIPS 30"], "outputs": ["BANANA FRIES 12\nPOTATO CHIPS 60\nAPPLE JUICE 20\nCANDY 20"]}
INTRODUCTORY
PYTHON3
HACKERRANK
980
# Enter your code here. Read input from STDIN. Print output to STDOUT
429cd569903e6ec3b99a25bdd4520608
UNKNOWN
=====Problem Statement===== You are given a spreadsheet that contains a list of N athletes and their details (such as age, height, weight and so on). You are required to sort the data based on the Kth attribute and print the final resulting table. Follow the example given below for better understanding. image Note th...
["n, m = map(int,input().split())\nar = []\nfor i in range(n):\n ar.append(list(map(int,input().split())))\nk = int(input())\nar = sorted(ar,key = lambda x:x[k])\nfor i in ar:\n [print(x,end=' ') for x in i]\n print('')\n", "#!/bin/python3\n\nimport sys\n\ndef __starting_point():\n n, m = input().strip().sp...
{"inputs": ["5 3\n10 2 5\n7 1 0\n9 9 9\n1 23 12\n6 5 9\n1"], "outputs": ["7 1 0\n10 2 5\n6 5 9\n9 9 9\n1 23 12"]}
INTRODUCTORY
PYTHON3
HACKERRANK
655
#!/bin/python3 import math import os import random import re import sys if __name__ == '__main__': nm = input().split() n = int(nm[0]) m = int(nm[1]) arr = [] for _ in range(n): arr.append(list(map(int, input().rstrip().split()))) k = int(input())
2bf554d3e4c95e394d66e72a6442fd52
UNKNOWN
=====Function Descriptions===== The NumPy module also comes with a number of built-in routines for linear algebra calculations. These can be found in the sub-module linalg. linalg.det The linalg.det tool computes the determinant of an array. print numpy.linalg.det([[1 , 2], [2, 1]]) #Output : -3.0 linalg.eig ...
["import numpy\nn = int(input())\nar = []\nfor i in range(n):\n tmp = list(map(float,input().split()))\n ar.append(tmp)\nnp_ar = numpy.array(ar,float)\nprint((numpy.linalg.det(np_ar)))\n", "import numpy as np\n\nn = int(input().strip())\narray = np.array([[float(x) for x in input().strip().split()] for _ in range...
{"inputs": ["2\n1.1 1.1\n1.1 1.1"], "outputs": ["0.0"]}
INTRODUCTORY
PYTHON3
HACKERRANK
377
import numpy
eb7abbebdf7240322859b3a254116687
UNKNOWN
=====Problem Statement===== In this challenge, the user enters a string and a substring. You have to print the number of times that the substring occurs in the given string. String traversal will take place from left to right, not from right to left. NOTE: String letters are case-sensitive. =====Input Format===== The...
["# Enter your code here. Read input from STDIN. Print output to STDOUT\ns=input()\nss=input()\ncnt=0\nlen_s=len(s)\nlen_ss=len(ss)\nfor i in range(0,len_s):\n tmp=s[i:i+len_ss]\n if(tmp==ss):\n cnt=cnt+1\nprint(cnt)\n", "def count_substring(string, sub_string):\n res = 0\n len_sub = len(sub_string)\...
{"inputs": ["ABCDCDC\nCDC"], "outputs": ["2"]}
INTRODUCTORY
PYTHON3
HACKERRANK
490
def count_substring(string, sub_string): return if __name__ == '__main__': string = input().strip() sub_string = input().strip() count = count_substring(string, sub_string) print(count)
a36299c0cc15a27a4e5901bb2cb14f80
UNKNOWN
=====Function Descriptions===== zip([iterable, ...]) This function returns a list of tuples. The ith tuple contains the ith element from each of the argument sequences or iterables. If the argument sequences are of unequal lengths, then the returned list is truncated to the length of the shortest argument sequence. S...
["n, x = list(map(int,input().split()))\nar = [0 for i in range(n)]\nfor i in range(x):\n temp_ar=list(map(float,input().split()))\n for j in range(n):\n ar[j] += temp_ar[j]\nfor i in range(n):\n print((ar[i]/x))\n", "#!/usr/bin/env python3\n\ndef __starting_point():\n st_num, sb_num = list(map(int, ...
{"inputs": ["5 3\n89 90 78 93 80\n90 91 85 88 86\n91 92 83 89 90.5"], "outputs": ["90.0 \n91.0 \n82.0 \n90.0 \n85.5"]}
INTRODUCTORY
PYTHON3
HACKERRANK
575
# Enter your code here. Read input from STDIN. Print output to STDOUT
67cebaf29ad3c17bab6c3b5bbf7d1ad3
UNKNOWN
=====Problem Statement===== ABC is a right triangle, 90°, at B. Therefore, ANGLE{ABC} = 90°. Point M is the midpoint of hypotenuse AC. You are given the lengths AB and BC. Your task is to find ANGLE{MBC} (angle θ°, as shown in the figure) in degrees. =====Input Format===== The first contains the length of side AB. The...
["import math\nab = float(input())\nbc = float(input())\nac = math.sqrt((ab*ab)+(bc*bc))\nbm = ac / 2.0\nmc = bm\n#let, \nb = mc\nc = bm\na = bc\n#where b=c\nangel_b_radian = math.acos(a / (2*b))\nangel_b_degree = int(round((180 * angel_b_radian) / math.pi))\noutput_str = str(angel_b_degree)+'\u00b0'\nprint(output_str)...
{"inputs": ["10\n10"], "outputs": ["45\u00b0"]}
INTRODUCTORY
PYTHON3
HACKERRANK
582
# Enter your code here. Read input from STDIN. Print output to STDOUT
6dfb7c008931e8d8b02189f93340e712
UNKNOWN
=====Problem Statement===== Neo has a complex matrix script. The matrix script is a NXM grid of strings. It consists of alphanumeric characters, spaces and symbols (!,@,#,$,%,&). To decode the script, Neo needs to read each column and select only the alphanumeric characters and connect them. Neo reads the column from t...
["import re\nn, m = list(map(int,input().split()))\ncharacter_ar = [''] * (n*m)\nfor i in range(n):\n line = input()\n for j in range(m):\n character_ar[i+(j*n)]=line[j]\ndecoded_str = ''.join(character_ar)\nfinal_decoded_str = re.sub(r'(?<=[A-Za-z0-9])([ !@#$%&]+)(?=[A-Za-z0-9])',' ',decoded_str)\nprint(f...
{"inputs": ["7 3\nTsi\nh%x\ni #\nsM \n$a \n#t%\nir!"], "outputs": ["This is Matrix# %!"]}
INTRODUCTORY
PYTHON3
HACKERRANK
660
#!/bin/python3 import math import os import random import re import sys first_multiple_input = input().rstrip().split() n = int(first_multiple_input[0]) m = int(first_multiple_input[1]) matrix = [] for _ in range(n): matrix_item = input() matrix.append(matrix_item)
b9400e161dc992b8bc7cdd8c74449689
UNKNOWN
=====Function Descriptions===== The eval() expression is a very powerful built-in function of Python. It helps in evaluating an expression. The expression can be a Python statement, or a code object. For example: >>> eval("9 + 5") 14 >>> x = 2 >>> eval("x + 3") 5 Here, eval() can also be used to work with Python keyw...
["input()\n", "#!/usr/bin/env python3\n\ndef __starting_point():\n input().strip()\n__starting_point()"]
{"inputs": ["print(2 + 3)"], "outputs": ["5"]}
INTRODUCTORY
PYTHON3
HACKERRANK
107
# Enter your code here. Read input from STDIN. Print output to STDOUT
6c125112fb67ec840da05e10cc890210
UNKNOWN
=====Problem Statement===== There is a horizontal row of n cubes. The length of each cube is given. You need to create a new vertical pile of cubes. The new pile should follow these directions: if cube_i is on top of cube_j then sideLength_j ≥ sideLength_i. When stacking the cubes, you can only pick up either the leftm...
["from collections import deque\ncas = int(input())\nfor t in range(cas):\n n = int(input())\n dq = deque(list(map(int,input().split())))\n possible = True\n element = (2**31)+1\n while dq:\n left_element = dq[0]\n right_element = dq[-1]\n if left_element>=right_element and element>=...
{"inputs": ["2\n6\n4 3 2 1 3 4\n3\n1 3 2\n"], "outputs": ["Yes\nNo\n"]}
INTRODUCTORY
PYTHON3
HACKERRANK
1,315
# Enter your code here. Read input from STDIN. Print output to STDOUT
f8f6700100689364c58949fe4d7d4873
UNKNOWN
=====Problem Statement===== When users post an update on social media,such as a URL, image, status update etc., other users in their network are able to view this new post on their news feed. Users can also see exactly when the post was published, i.e, how many hours, minutes or seconds ago. Since sometimes posts are p...
["import datetime\ncas = int(input())\nfor t in range(cas):\n timestamp1 = input().strip()\n timestamp2 = input().strip()\n time_format = \"%a %d %b %Y %H:%M:%S %z\"\n time_second1 = datetime.datetime.strptime(timestamp1,time_format)\n time_second2 = datetime.datetime.strptime(timestamp2,time_format)\n ...
{"inputs": ["2\nSun 10 May 2015 13:54:36 -0700\nSun 10 May 2015 13:54:36 -0000\nSat 02 May 2015 19:54:36 +0530\nFri 01 May 2015 13:54:36 -0000"], "outputs": ["25200\n88200"]}
INTRODUCTORY
PYTHON3
HACKERRANK
867
#!/bin/python3 import math import os import random import re import sys # Complete the time_delta function below. def time_delta(t1, t2): if __name__ == '__main__': fptr = open(os.environ['OUTPUT_PATH'], 'w') t = int(input()) for t_itr in range(t): t1 = input() t2 = input() d...
ccd08d4f8fd54f96c001609780d80071
UNKNOWN
=====Problem Statement===== You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa. =====Example===== Www.HackerRank.com → wWW.hACKERrANK.COM Pythonist 2 → pYTHONIST 2 =====Input Format===== A single line containing a string S. =====O...
["def swap_case(s):\n newstring = \"\"\n \n for item in s:\n if item.isupper():\n newstring += item.lower()\n else:\n newstring += item.upper()\n \n return newstring\n", "def swap_case(s):\n out = ''\n for ind, let in enumerate(s):\n if let.isalpha...
{"fn_name": "swap_case", "inputs": [["HackerRank.com presents \"Pythonist 2\"."]], "outputs": ["hACKERrANK.COM PRESENTS \"pYTHONIST 2\"."]}
INTRODUCTORY
PYTHON3
HACKERRANK
513
def swap_case(s): return if __name__ == '__main__': s = input() result = swap_case(s) print(result)
478467351e797ce778c2a7ae5eaab44f
UNKNOWN
=====Function Descriptions===== .symmetric_difference() The .symmetric_difference() operator returns a set with all the elements that are in the set and the iterable but not both. Sometimes, a ^ operator is used in place of the .symmetric_difference() tool, but it only operates on the set of elements in set. The set i...
["e = int(input())\neng = set(map(int,input().split())) \nf = int(input())\nfre = set(map(int,input().split()))\nprint((len(eng ^ fre)))\n", "#!/usr/bin/env python3\n\ndef __starting_point():\n n = int(input().strip())\n english = set(map(int, input().strip().split(' ')))\n m = int(input().strip())\n french...
{"inputs": ["9\n1 2 3 4 5 6 7 8 9\n9\n10 1 2 3 11 21 55 6 8"], "outputs": ["8"]}
INTRODUCTORY
PYTHON3
HACKERRANK
446
# Enter your code here. Read input from STDIN. Print output to STDOUT
2ad6b4e666b3c39ac6faf6dfc62df2fe
UNKNOWN
=====Function Descriptions===== Python has built-in string validation methods for basic data. It can check if a string is composed of alphabetical characters, alphanumeric characters, digits, etc. str.isalnum() This method checks if all the characters of a string are alphanumeric (a-z, A-Z and 0-9). >>> print 'ab123'...
["# Enter your code here. Read input from STDIN. Print output to STDOUT\ninputStr=input()\nresalnum = False\nresalpha = False\nresdigit = False\nreslower = False\nresupper = False\nfor i in inputStr:\n if(i.isalnum()):\n resalnum=True\n if(i.isalpha()):\n resalpha=True\n if(i.isdigit()):\n ...
{"inputs": ["qA2"], "outputs": ["True\nTrue\nTrue\nTrue\nTrue"]}
INTRODUCTORY
PYTHON3
HACKERRANK
831
if __name__ == '__main__': s = input()
24655525c67de984dbfeee4aa2f843c8
UNKNOWN
=====Function Descriptions===== itertools.combinations_with_replacement(iterable, r) This tool returns length subsequences of elements from the input iterable allowing individual elements to be repeated more than once. Combinations are emitted in lexicographic sorted order. So, if the input iterable is sorted, the co...
["from itertools import *\ns,n = input().split()\nn = int(n)\ns = sorted(s)\nfor j in combinations_with_replacement(s,n):\n print((''.join(j)))\n", "#!/usr/bin/env python3\n\nfrom itertools import combinations_with_replacement\n\ndef __starting_point():\n in_data = list(input().strip().split(' '))\n \n for ...
{"inputs": ["HACK 2"], "outputs": ["AA\nAC\nAH\nAK\nCC\nCH\nCK\nHH\nHK\nKK"]}
INTRODUCTORY
PYTHON3
HACKERRANK
445
# Enter your code here. Read input from STDIN. Print output to STDOUT
013822ed13ee23ada4a102ee2f9fc79b
UNKNOWN
=====Problem Statement===== CSS colors are defined using a hexadecimal (HEX) notation for the combination of Red, Green, and Blue color values (RGB). Specifications of HEX Color Code It must start with a '#' symbol. It can have 3 or 6 digits. Each digit is in the range of 0 to F. (1, 2, 3, 4, 5, 6, 7, 8, 9, 0, A, B, ...
["import re\nn = int(input())\nfor t in range(n):\n s = input()\n match_result = re.findall(r'(#[0-9A-Fa-f]{3}|#[0-9A-Fa-f]{6})(?:[;,.)]{1})',s)\n for i in match_result:\n if i != '':\n print(i)\n", "import re\n\nn = int(input().strip())\ninside = False\nfor _ in range(n):\n line = input()...
{"inputs": ["11\n#BED\n{\n color: #FfFdF8; background-color:#aef;\n font-size: 123px;\n\n}\n#Cab\n{\n background-color: #ABC;\n border: 2px dashed #fff;\n}"], "outputs": ["#FfFdF8\n#aef\n#ABC\n#fff"]}
INTRODUCTORY
PYTHON3
HACKERRANK
654
# Enter your code here. Read input from STDIN. Print output to STDOUT
21b347154ac3a5078e76e07203106839
UNKNOWN
=====Problem Statement===== You are given a string S. Your task is to find out whether is a valid regex or not. =====Input Format===== The first line contains integer T, the number of test cases. The next T lines contains the string S. =====Constraints===== 0<T<100 =====Output Format===== Print "True" or "False" for...
["import re\nn = int(input())\nfor i in range(n):\n s = input()\n try:\n re.compile(s)\n print(True)\n except Exception as e:\n print(False)\n", "#!/usr/bin/env python3\n\nimport re\n\ndef __starting_point():\n t = int(input().strip())\n \n for _ in range(t):\n try:\n ...
{"inputs": ["2\n.*\\+\n.*+"], "outputs": ["True\nFalse"]}
INTRODUCTORY
PYTHON3
HACKERRANK
475
# Enter your code here. Read input from STDIN. Print output to STDOUT
3cfd87a8f57b391e7b978cc1a873e5f9
UNKNOWN
=====Function Descriptions===== .difference() The tool .difference() returns a set with all the elements from the set that are not in an iterable. Sometimes the - operator is used in place of the .difference() tool, but it only operates on the set of elements in set. Set is immutable to the .difference() operation (or...
["e = int(input())\neng = set(map(int,input().split())) \nf = int(input())\nfre = set(map(int,input().split()))\nprint((len(eng - fre)))\n", "#!/usr/bin/env python3\n\ndef __starting_point():\n n = int(input().strip())\n english = set(map(int, input().strip().split(' ')))\n m = int(input().strip())\n french...
{"inputs": ["9\n1 2 3 4 5 6 7 8 9\n9\n10 1 2 3 11 21 55 6 8"], "outputs": ["4"]}
INTRODUCTORY
PYTHON3
HACKERRANK
436
# Enter your code here. Read input from STDIN. Print output to STDOUT
0d1edf4399593305127db81f35680698
UNKNOWN
=====Problem Statement===== Here is a sample line of code that can be executed in Python: print("Hello, World!") You can just as easily store a string as a variable and then print it to stdout: my_string = "Hello, World!" print(my_string) The above code will print Hello, World! on your screen. Try it yourself in the ...
["def __starting_point():\n print(\"Hello, World!\")\n\n__starting_point()"]
{"inputs": [""], "outputs": ["Hello, World!"]}
INTRODUCTORY
PYTHON3
HACKERRANK
79
print("")
60a3a0ca04dca00e2d30c266dac63687
UNKNOWN
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is lexicographically smalle...
["n,l = map(int,input().split())\na = []\nfor i in range(n):\n a.append(input())\n \na.sort()\nprint(\"\".join(str(i) for i in a))", "n,l = [int(x) for x in input().split()]\ns = []\nfor i in range(n):\n s.append(input())\ns.sort()\n\nprint(\"\".join(s))", "n, l = map(int, input().split( ))\nt = list()\nfor i in ran...
{"inputs": ["3 3\ndxx\naxx\ncxx\n"], "outputs": ["axxcxxdxx\n"]}
INTRODUCTORY
PYTHON3
ATCODER.JP
18,815
30d073b697e7f43ee2842f1ec74fabf1
UNKNOWN
We are still with squared integers. Given 4 integers `a, b, c, d` we form the sum of the squares of `a` and `b` and then the sum of the squares of `c` and `d`. We multiply the two sums hence a number `n` and we try to decompose `n` in a sum of two squares `e` and `f` (e and f integers >= 0) so that `n = e² + f²`. Mo...
["def prod2sum(a, b, c, d):\n e = sorted([abs(a*d-b*c), abs(a*c+b*d)])\n f = sorted([abs(a*c-b*d), abs(a*d+b*c)])\n if e == f:\n return [e]\n else:\n return sorted([e, f])\n\n", "def prod2sum(a, b, c, d):\n r1 = sorted([abs(a*c-b*d),abs(a*d+b*c)])\n r2 = sorted([abs(a*c+b*d),abs(a*d-b*c)...
{"fn_name": "prod2sum", "inputs": [[1, 2, 1, 3], [2, 3, 4, 5], [1, 2, 2, 3], [1, 1, 3, 5], [10, 11, 12, 13], [1, 20, -4, -5], [100, 100, 100, 100], [0, 0, 0, 0], [-14, 12, -10, 8], [7, 96, -1, 81], [112, 0, 0, 1]], "outputs": [[[[1, 7], [5, 5]]], [[[2, 23], [7, 22]]], [[[1, 8], [4, 7]]], [[[2, 8]]], [[[2, 263], [23, 26...
INTRODUCTORY
PYTHON3
CODEWARS
3,227
def prod2sum(a, b, c, d):
b916178c8aa3f1ee1dee900e0c0ac636
UNKNOWN
Your task is to write a function which counts the number of squares contained in an ASCII art picture. The input pictures contain rectangles---some of them squares---drawn with the characters `-`, `|`, and `+`, where `-` and `|` are used to represent horizontal and vertical sides, and `+` is used to represent corners ...
["def count_squares(lines):\n def s(i, j, z):\n try:\n return (\n '+' == lines[i+z][j] == lines[i][j+z] == lines[i+z][j+z]\n and all(lines[i][c] in '-+' for c in range(j+1, j+z))\n and all(lines[i+z][c] in '-+' for c in range(j+1, j+z))\n ...
{"fn_name": "count_squares", "inputs": [[["+--+ +----+", "| | | | +-+", "| | +----+ | |", "+--+ +-+"]], [["+-----+", "| |", "+-----+"]], [["+---+", "| |", "| +-+-+", "| | | |", "+-+-+ |", " | |", " +---+"]], [["+-+-+", "| | |", "+-+-+", "| | |", "+-+-+"]], [["+---+", "| |", "| |",...
INTRODUCTORY
PYTHON3
CODEWARS
7,666
def count_squares(lines):
74e5178cab2d5f563590aca48825bb45
UNKNOWN
For this game of `BINGO`, you will receive a single array of 10 numbers from 1 to 26 as an input. Duplicate numbers within the array are possible. Each number corresponds to their alphabetical order letter (e.g. 1 = A. 2 = B, etc). Write a function where you will win the game if your numbers can spell `"BINGO"`. They ...
["BINGO = {ord(c)-64 for c in \"BINGO\"}\n\ndef bingo(lst): \n return \"WIN\" if set(lst) >= BINGO else \"LOSE\"", "def bingo(array): \n return \"WIN\" if all(i in array for i in [2,9,14,7,15]) else \"LOSE\"", "def bingo(array):\n ctr = 0\n for i in [2, 9, 14, 7, 15]:\n if i in list(set(array)):\n ...
{"fn_name": "bingo", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[20, 12, 23, 14, 6, 22, 12, 17, 2, 26]], [[1, 2, 3, 7, 5, 14, 7, 15, 9, 10]], [[5, 2, 13, 7, 5, 14, 17, 15, 9, 10]]], "outputs": [["LOSE"], ["LOSE"], ["WIN"], ["WIN"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,159
def bingo(array):
ee517dace9c54c0460411a114f220a42
UNKNOWN
Kate and Michael want to buy a pizza and share it. Depending on the price of the pizza, they are going to divide the costs: * If the pizza is less than €5,- Michael invites Kate, so Michael pays the full price. * Otherwise Kate will contribute 1/3 of the price, but no more than €10 (she's broke :-) and Michael pays th...
["def michael_pays(cost):\n return round(cost if cost < 5 else max(cost*2/3, cost-10), 2)", "def michael_pays(c):\n return round(c if c < 5 else c * 2 / 3 if c <= 30 else c - 10, 2)", "def michael_pays(costs):\n if costs < 5:\n michael = costs\n else:\n kate = min(costs / 3, 10)\n micha...
{"fn_name": "michael_pays", "inputs": [[15], [4], [4.99], [5], [30], [80], [22], [5.9181], [28.789], [4.325]], "outputs": [[10], [4], [4.99], [3.33], [20], [70], [14.67], [3.95], [19.19], [4.33]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,457
def michael_pays(costs):
4f5607e089e3f82abbd88c9091ef1b32
UNKNOWN
You've arrived at a carnival and head straight for the duck shooting tent. Why wouldn't you? You will be given a set amount of ammo, and an aim rating of between 1 and 0. No your aim is not always perfect - hey maybe someone fiddled with the sights on the gun... Anyway your task is to calculate how many successful sh...
["def duck_shoot(ammo, aim, ducks):\n return ducks.replace('2', 'X', int(ammo * aim))", "duck_shoot = lambda am, aim, d: d.replace('2','X', int(am*aim))", "def duck_shoot(ammo, aim, ducks):\n b = 0\n b += int(aim * ammo)\n return ducks.replace('2','X', b)\n", "duck_shoot=lambda a,b,c:c.replace('2','X',int(a...
{"fn_name": "duck_shoot", "inputs": [[4, 0.64, "|~~2~~~22~2~~22~2~~~~2~~~|"], [9, 0.22, "|~~~~~~~2~2~~~|"], [6, 0.41, "|~~~~~22~2~~~~~|"], [8, 0.05, "|2~~~~|"], [8, 0.92, "|~~~~2~2~~~~~22~~2~~~~2~~~2|"]], "outputs": [["|~~X~~~X2~2~~22~2~~~~2~~~|"], ["|~~~~~~~X~2~~~|"], ["|~~~~~XX~2~~~~~|"], ["|2~~~~|"], ["|~~~~X~X~~~~~...
INTRODUCTORY
PYTHON3
CODEWARS
1,755
def duck_shoot(ammo, aim, ducks):
f622647d715fe8c7542187db3d984b69
UNKNOWN
In the world of birding there are four-letter codes for the common names of birds. These codes are created by some simple rules: * If the bird's name has only one word, the code takes the first four letters of that word. * If the name is made up of two words, the code takes the first two letters of each word. * If th...
["import re\n\nSPLITTER = re.compile(r\"[\\s-]\")\n\ndef birdify(lst):\n return ''.join(x[:4//len(lst)] for x in lst) + ('' if len(lst)!=3 else lst[-1][1])\n\ndef bird_code(arr):\n return [birdify(SPLITTER.split(name)).upper() for name in arr]", "def bird_code(arr):\n codes = []\n \n for name in arr:\n ...
{"fn_name": "bird_code", "inputs": [[["American Redstart", "Northern Cardinal", "Pine Grosbeak", "Barred Owl", "Starling", "Cooper's Hawk", "Pigeon"]], [["Great Crested Flycatcher", "Bobolink", "American White Pelican", "Red-Tailed Hawk", "Eastern Screech Owl", "Blue Jay"]], [["Black-Crowned Night Heron", "Northern Moc...
INTRODUCTORY
PYTHON3
CODEWARS
4,097
def bird_code(arr):
eedd552f1b78429402e7314a6b94647c
UNKNOWN
Complete the function to determine the number of bits required to convert integer `A` to integer `B` (where `A` and `B` >= 0) The upper limit for `A` and `B` is 2^(16), `int.MaxValue` or similar. For example, you can change 31 to 14 by flipping the 4th and 0th bit: ``` 31 0 0 0 1 1 1 1 1 14 0 0 0 0 1 1 1 0 --- -...
["def convert_bits(a,b):\n return bin(a^b).count(\"1\")", "def convert_bits(a, b):\n return f'{a^b:b}'.count('1')", "def convert_bits(a, b):\n return str(bin(a ^ b)).count('1')", "def convert_bits(a, b):\n return format(a ^ b, 'b').count('1')", "def convert_bits(a, b):\n difference=bin(a^b)[2:]\n retu...
{"fn_name": "convert_bits", "inputs": [[31, 14], [7, 17], [31, 0], [0, 0], [127681, 127681], [312312312, 5645657], [43, 2009989843]], "outputs": [[2], [3], [5], [0], [0], [13], [17]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,011
def convert_bits(a, b):
4090bed183a91a9da476ef109944daca
UNKNOWN
There's a waiting room with N chairs set in single row. Chairs are consecutively numbered from 1 to N. First is closest to the entrance (which is exit as well). For some reason people choose a chair in the following way 1. Find a place as far from other people as possible 2. Find a place as close to exit as possible...
["def last_chair(n):\n return n - 1", "def last_chair(n):\n # Propn:\n # Given there are n seats, n >= 2. The (n-1)th seat is always the\n # last to be taken (taken in iteration n).\n # Proof:\n # Suppose that, for some n >= 2, the (n-1)th seat is taken on\n # iteration i > 2. The nth seat ...
{"fn_name": "last_chair", "inputs": [[10]], "outputs": [[9]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,096
def last_chair(n):
412f7715a6f6402692df53dca8fa9bf8
UNKNOWN
Given an array of arguments, representing system call arguments keys and values, join it into a single, space-delimited string. You don't need to care about the application name -- your task is only about parameters. Each element of the given array can be: * a single string, * a single string array, * an array of two ...
["def args_to_string(args):\n L = []\n for arg in args:\n if isinstance(arg, str):\n L.append(arg)\n elif len(arg) == 1:\n L.append(arg[0])\n elif len(arg[0]) == 1:\n L.append('-' + ' '.join(arg))\n else:\n L.append('--' + ' '.join(arg))\n ...
{"fn_name": "args_to_string", "inputs": [[["foo"]], [["f"]], [[["f"]]], [[["foo", "bar"]]], [[["f", "bar"]]], [[["foo", "bar"], ["baz", "qux"]]], [[["foo"], "bar", ["baz", "qux"], ["xyzzy", "a"], "a", ["a"], ["a", "plugh"]]], [[]], [[["---"], "---", ["---", "---"], ["-----", "-"], "-", ["-"], ["-", "-----"]]]], "output...
INTRODUCTORY
PYTHON3
CODEWARS
2,844
def args_to_string(args):
fd5b950d54d68ec7677b64a82616161e
UNKNOWN
Pete and his mate Phil are out in the countryside shooting clay pigeons with a shotgun - amazing fun. They decide to have a competition. 3 rounds, 2 shots each. Winner is the one with the most hits. Some of the clays have something attached to create lots of smoke when hit, guarenteed by the packaging to generate 'r...
["def shoot(results):\n pete = phil = 0\n \n for shots, double in results:\n pete += shots[\"P1\"].count(\"X\") * (1 + double)\n phil += shots[\"P2\"].count(\"X\") * (1 + double)\n \n return \"Pete Wins!\" if pete > phil else \"Phil Wins!\" if phil > pete else \"Draw!\"", "def shoot(results...
{"fn_name": "shoot", "inputs": [[[[{"P1": "XX", "P2": "XO"}, true], [{"P1": "OX", "P2": "OO"}, false], [{"P1": "XX", "P2": "OX"}, true]]], [[[{"P1": "XX", "P2": "XO"}, false], [{"P1": "OX", "P2": "XX"}, false], [{"P1": "OO", "P2": "XX"}, true]]], [[[{"P1": "OO", "P2": "XX"}, false], [{"P1": "OO", "P2": "XX"}, false], [...
INTRODUCTORY
PYTHON3
CODEWARS
2,791
def shoot(results):
07a099af80cfb2b0621f0194a1ba187f
UNKNOWN
What adds up =========== Given three arrays of integers your task is to create an algorithm that finds the numbers in the first two arrays whose sum is equal to any number in the third. The return value should be an array containing the values from the argument arrays that adds up. The sort order of the resulting arra...
["def addsup(a1, a2, a3):\n return [[x,y,x+y] for x in a1 for y in a2 if x+y in a3]", "from itertools import product\n\ndef addsup(a1, a2, a3):\n goal = set(a3).__contains__\n return [[x, y, x+y] for x,y in product(a1, a2) if goal(x+y)]", "def addsup(a, b, t):\n t = set(t)\n return [[m, n, m+n] for m in a ...
{"fn_name": "addsup", "inputs": [[[], [1, 2, 3], [5, 2, 3]], [[1, 3, 4], [], [4, 6, 5]], [[1, 2, 3], [4, 5, 6], []]], "outputs": [[[]], [[]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,571
def addsup(a1, a2, a3):
0693185e09aafe315fc3afecce6e0c0f
UNKNOWN
In this Kata, you will check if it is possible to convert a string to a palindrome by changing one character. For instance: ```Haskell solve ("abbx") = True, because we can convert 'x' to 'a' and get a palindrome. solve ("abba") = False, because we cannot get a palindrome by changing any character. solve ("abcba") ...
["def solve(s):\n v = sum(s[i] != s[-1-i] for i in range((len(s))//2) )\n return v == 1 or not v and len(s)%2", "solve=lambda s:any(s[:y]+c+s[y+1:]==(s[:y]+c+s[y+1:])[::-1]!=s for y,x in enumerate(s)for c in set(s))", "def solve(s):\n d = sum(1 for i in range(len(s) // 2) if s[i] != s[-i-1])\n return d == 1...
{"fn_name": "solve", "inputs": [["abba"], ["abbaa"], ["abbx"], ["aa"], ["ab"], ["abcba"]], "outputs": [[false], [true], [true], [false], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,743
def solve(s):
e5604f72f0392d087dc5b56f66ed3dea
UNKNOWN
Your job at E-Corp is both boring and difficult. It isn't made any easier by the fact that everyone constantly wants to have a meeting with you, and that the meeting rooms are always taken! In this kata, you will be given an array. Each value represents a meeting room. Your job? Find the **first** empty one and return...
["def meeting(rooms):\n try:\n return rooms.index('O')\n except ValueError:\n return 'None available!'\n", "def meeting(rooms):\n return rooms.index(\"O\") if \"O\" in rooms else \"None available!\"", "def meeting(rooms):\n return next((i for i, r in enumerate(rooms) if r == 'O'), 'None availa...
{"fn_name": "meeting", "inputs": [[["X", "O", "X"]], [["O", "X", "X", "X", "X"]], [["X", "X", "O", "X", "X"]], [["X"]]], "outputs": [[1], [0], [2], ["None available!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,268
def meeting(rooms):
ff8deea0a7799f3a44e00f38771a5cc0
UNKNOWN
Kevin is noticing his space run out! Write a function that removes the spaces from the values and returns an array showing the space decreasing. For example, running this function on the array ['i', 'have','no','space'] would produce ['i','ihave','ihaveno','ihavenospace'].
["from itertools import accumulate\n\ndef spacey(a):\n return list(accumulate(a))", "def spacey(array):\n return [''.join(array[:i+1]) for i in range(len(array))]", "def spacey(array):\n strr = ''\n out = []\n for el in array:\n strr += str(el)\n out.append(strr)\n return out", "def spac...
{"fn_name": "spacey", "inputs": [[["kevin", "has", "no", "space"]], [["this", "cheese", "has", "no", "holes"]]], "outputs": [[["kevin", "kevinhas", "kevinhasno", "kevinhasnospace"]], [["this", "thischeese", "thischeesehas", "thischeesehasno", "thischeesehasnoholes"]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,209
def spacey(array):
cc372c2bcff4c6397071755da24436d1
UNKNOWN
Will you make it? You were camping with your friends far away from home, but when it's time to go back, you realize that your fuel is running out and the nearest pump is ```50``` miles away! You know that on average, your car runs on about ```25``` miles per gallon. There are ```2``` gallons left. Considering these fa...
["'''\nVasyl Zakharuk\nPython Core 355\nCodewars Kata: Will you make it?\n''' \ndef zero_fuel(distance_to_pump, mpg, fuel_left):\n if fuel_left >= distance_to_pump / mpg:\n print(\"We got to the pump\")\n return True\n else:\n print(\"We pushed the car to the pump(((\")\n return False\...
{"fn_name": "zero_fuel", "inputs": [[50, 25, 2], [60, 30, 3], [70, 25, 1], [100, 25, 3]], "outputs": [[true], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
14,214
def zero_fuel(distance_to_pump, mpg, fuel_left):
0f6be9bf2ee7c0bcb7291b42562e6102
UNKNOWN
Step through my `green glass door`. You can take the `moon`, but not the `sun`. You can take your `slippers`, but not your `sandals`. You can go through `yelling`, but not `shouting`. You can't run through `fast`, but you can run with `speed`. You can take a `sheet`, but not your `blanket`. You can wear your `gla...
["def step_through_with(s):\n return any(m == n for m, n in zip(s, s[1:]))", "import re\ndef step_through_with(s): return re.compile(r'([a-z])\\1', re.I).search(s) is not None", "def step_through_with(s):\n prev = '' \n for letter in s:\n if prev == letter:\n return True\n prev = le...
{"fn_name": "step_through_with", "inputs": [["moon"], ["test"], ["glasses"], ["airplane"], ["free"], ["branch"], ["aardvark"]], "outputs": [[true], [false], [true], [false], [true], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,057
def step_through_with(s):
b729528085f85d4918e19cd9fe4a017b
UNKNOWN
Consider the following series: `1, 2, 4, 8, 16, 22, 26, 38, 62, 74, 102, 104, 108, 116, 122` It is generated as follows: * For single digit integers, add the number to itself to get the next element. * For other integers, multiply all the non-zero digits and add the result to the original number to get the next elem...
["from operator import mul\nfrom functools import reduce\n\ndef genSequence(n):\n yield n\n while True:\n n += reduce(mul, [int(d) for d in str(n) if d != '0']) if n > 9 else n\n yield n\n\ndef extract(seq, v):\n return sorted(seq).index(v)\n\ndef convergence(n):\n gen1, genN = genSequence(1),...
{"fn_name": "convergence", "inputs": [[3], [5], [10], [15], [500], [5000]], "outputs": [[5], [6], [5], [2], [29], [283]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,656
def convergence(n):
98f2621b7fc8c4227d126f806d093509
UNKNOWN
You will be given a string (x) featuring a cat 'C', a dog 'D' and a mouse 'm'. The rest of the string will be made up of '.'. You need to find out if the cat can catch the mouse from it's current position. The cat can jump (j) characters. Also, the cat cannot jump over the dog. So: if j = 5: ```..C.....m.``` ret...
["def cat_mouse(x,j):\n d, c, m = x.find('D'), x.find('C'), x.find('m')\n if -1 in [d, c, m]:\n return 'boring without all three'\n if abs(c - m) <= j:\n return 'Protected!' if c < d < m or m < d < c else 'Caught!' \n return 'Escaped!'", "def cat_mouse(x, j):\n try:\n cat, dog, mouse...
{"fn_name": "cat_mouse", "inputs": [["..D.....C.m", 2], ["............C.............D..m...", 8], ["m.C...", 5], [".CD......m.", 10], [".CD......m.", 1]], "outputs": [["Caught!"], ["Escaped!"], ["boring without all three"], ["Protected!"], ["Escaped!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,002
def cat_mouse(x,j):
89f9269cb1b938082fa5bbca507cea60
UNKNOWN
You're playing a game with a friend involving a bag of marbles. In the bag are ten marbles: * 1 smooth red marble * 4 bumpy red marbles * 2 bumpy yellow marbles * 1 smooth yellow marble * 1 bumpy green marble * 1 smooth green marble You can see that the probability of picking a smooth red marble from the bag is `1 / ...
["def color_probability(color, texture):\n marbles = {\"smooth\": {\"red\": 1, \"yellow\": 1, \"green\": 1, \"total\": 3}, \"bumpy\": {\"red\": 4, \"yellow\": 2, \"green\": 1, \"total\": 7}}\n return \"{}\".format(marbles[texture][color] / marbles[texture][\"total\"])[:4]", "def color_probability(color, texture):...
{"fn_name": "color_probability", "inputs": [["red", "bumpy"], ["green", "bumpy"], ["yellow", "smooth"], ["red", "smooth"], ["green", "smooth"], ["yellow", "bumpy"]], "outputs": [["0.57"], ["0.14"], ["0.33"], ["0.33"], ["0.33"], ["0.28"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,494
def color_probability(color, texture):
53ce9f9582bffd857397d3ee89a8aeab
UNKNOWN
Passer ratings are the generally accepted standard for evaluating NFL quarterbacks. I knew a rating of 100 is pretty good, but never knew what makes up the rating. So out of curiosity I took a look at the wikipedia page and had an idea or my first kata: https://en.wikipedia.org/wiki/Passer_rating ## Formula There are...
["def passer_rating(att, yds, comp, td, ints):\n limit = lambda x: min(max(x, 0), 2.375)\n \n att = float(att) # for python 2 compatibility\n \n A = ((comp / att) - .3) * 5\n B = ((yds / att) - 3) * .25\n C = (td / att) * 20\n D = 2.375 - ((ints / att) * 25)\n \n A, B, C, D = map(limit,...
{"fn_name": "passer_rating", "inputs": [[432, 3554, 291, 28, 2], [5, 76, 4, 1, 0], [48, 192, 19, 2, 3], [1, 2, 1, 1, 0], [34, 172, 20, 1, 1], [10, 17, 2, 0, 1]], "outputs": [[112.2], [158.3], [39.6], [118.8], [69.7], [0.0]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,284
def passer_rating(att, yds, comp, td, ints):
4de600e34dfb073821230e39e0ffbe25
UNKNOWN
You will be given a vector of strings. You must sort it alphabetically (case-sensitive, and based on the ASCII values of the chars) and then return the first value. The returned value must be a string, and have `"***"` between each of its letters. You should not remove or add elements from/to the array.
["def two_sort(lst):\n return '***'.join(min(lst))", "def two_sort(array):\n return '***'.join(min(array))", "def two_sort(arr):\n return '***'.join(sorted(arr)[0])", "def two_sort(a):\n a = sorted(a)\n result = \"***\".join(a[0])\n return result", "def two_sort(array):\n return '***'.join(sorted(a...
{"fn_name": "two_sort", "inputs": [[["bitcoin", "take", "over", "the", "world", "maybe", "who", "knows", "perhaps"]], [["turns", "out", "random", "test", "cases", "are", "easier", "than", "writing", "out", "basic", "ones"]], [["lets", "talk", "about", "javascript", "the", "best", "language"]], [["i", "want", "to", "tra...
INTRODUCTORY
PYTHON3
CODEWARS
14,760
def two_sort(array):
eb036d49c27dd032f8274ebd8f339fa9
UNKNOWN
Help a fruit packer sort out the bad apples. There are 7 varieties of apples, all packaged as pairs and stacked in a fruit box. Some of the apples are spoiled. The fruit packer will have to make sure the spoiled apples are either removed from the fruit box or replaced. Below is the breakdown: Apple varieties are rep...
["def bad_apples(apples):\n lst, notFull = [], []\n for a,b in apples:\n if (bool(a) ^ bool(b)) and notFull: lst[notFull.pop()].append(a or b) # One bad and partially full box already present: fill it (as second element)\n elif a and b: lst.append([a,b]) ...
{"fn_name": "bad_apples", "inputs": [[[]], [[[0, 0], [0, 0]]], [[[0, 0], [0, 0], [0, 1], [0, 0], [0, 0]]], [[[0, 0], [3, 7], [0, 5]]], [[[1, 3], [7, 6], [7, 2], [1, 3], [2, 3], [4, 5], [7, 6]]], [[[1, 2], [6, 1], [5, 2], [6, 3], [1, 4], [2, 5], [7, 6], [0, 1]]], [[[0, 0], [1, 0], [0, 2], [3, 0], [4, 0], [0, 5], [0, 6],...
INTRODUCTORY
PYTHON3
CODEWARS
4,803
def bad_apples(apples):
5765520bbb1aa128e23d4ae0c5008595
UNKNOWN
In a far away country called AlgoLandia, there are `N` islands numbered `1` to `N`. Each island is denoted by `k[i]`. King Algolas, king of AlgoLandia, built `N - 1` bridges in the country. A bridge is built between islands `k[i]` and `k[i+1]`. Bridges are two-ways and are expensive to build. The problem is that there...
["from itertools import groupby\n\ndef find_needed_guards(islands):\n return sum(sum(1 for _ in g)>>1 for k,g in groupby(islands) if not k)", "def find_needed_guards(k):\n b = ''.join('1' if g else '0' for g in k)\n return sum(len(ng) // 2 for ng in b.split(\"1\"))", "def find_needed_guards(k):\n \n prev...
{"fn_name": "find_needed_guards", "inputs": [[[true, true, false, true, false]], [[false, false, true, false, false]], [[false, false, false, false, false]], [[false, false, false, false, false, false]], [[false, false]], [[true, false]], [[false, false, false, true, false, false, false, true]], [[false, false, true, f...
INTRODUCTORY
PYTHON3
CODEWARS
1,730
def find_needed_guards(k):
f4521ee73a5b1e896f01baa869ebc1ec
UNKNOWN
# Background My TV remote control has arrow buttons and an `OK` button. I can use these to move a "cursor" on a logical screen keyboard to type words... # Keyboard The screen "keyboard" layout looks like this #tvkb { width : 400px; border: 5px solid gray; border-collapse: collapse; } #tvkb td { ...
["import re\n\nH, W = 6, 8\nKEYBOARD = \"abcde123fghij456klmno789pqrst.@0uvwxyz_/* \"\nMAP = {c: (i//W, i%W) for i,c in enumerate(KEYBOARD)}\n\n\ndef manhattan(*pts):\n dxy = [abs(z2-z1) for z1,z2 in zip(*pts)]\n return 1 + sum( min(dz, Z-dz) for dz,Z in zip(dxy, (H,W)) )\n\ndef toggle(m):\n ups, end ...
{"fn_name": "tv_remote", "inputs": [["Code Wars"], ["does"], ["your"], ["solution"], ["work"], ["for"], ["these"], ["words"], ["DOES"], ["YOUR"], ["SOLUTION"], ["WORK"], ["FOR"], ["THESE"], ["WORDS"], ["Does"], ["Your"], ["Solution"], ["Work"], ["For"], ["These"], ["Words"], ["A"], ["AADVARKS"], ["A/A/A/A/"], ["1234567...
INTRODUCTORY
PYTHON3
CODEWARS
9,707
def tv_remote(words):
aa31e98a223c8221b69adf570dad81a6
UNKNOWN
Imagine if there were no order of operations. Instead, you would do the problem from left to right. For example, the equation `$a +b *c /d$` would become `$(((a+b)*c)//d)$` (`Math.floor(((a+b)*c)/d)` in JS). Return `None`/`null` (depending on your language) if the equation is `""`. ### Task: Given an equation with a...
["def no_order(equation):\n equation = equation.replace(' ', '')\n equation = equation.replace('+', ')+')\n equation = equation.replace('-', ')-')\n equation = equation.replace('*', ')*')\n equation = equation.replace('/', ')//')\n equation = equation.replace('%', ')%')\n equation = equation.replac...
{"fn_name": "no_order", "inputs": [["2 + 3- 4*1 ^ 3"], ["7 * 3 - 3/ 10 0"], ["1 20% 0 + 9"], ["6 9* 2+6 / 0"]], "outputs": [[1], [0], [null], [null]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,081
def no_order(equation):
405c5b4f99ce4856e6e3441f06b414b0
UNKNOWN
# Introduction Hamsters are rodents belonging to the subfamily Cricetinae. The subfamily contains about 25 species, classified in six or seven genera. They have become established as popular small house pets, and, partly because they are easy to breed in captivity, hamsters are often used as laboratory animals. # T...
["def hamster_me(code, message):\n code, dct = sorted(set(code)), {}\n for c1,c2 in zip(code, code[1:] + [chr(ord(\"z\") + ord(code[0]) - ord(\"a\"))]):\n for n in range(ord(c1), ord(c2)+1):\n dct[chr( (n-97)%26 + 97 )] = c1 + str(n-ord(c1)+1)\n return ''.join(dct[c] for c in message)", "def ...
{"fn_name": "hamster_me", "inputs": [["hamster", "hamster"], ["hamster", "helpme"], ["hmster", "hamster"], ["hhhhammmstteree", "hamster"], ["f", "abcdefghijklmnopqrstuvwxyz"]], "outputs": [["h1a1m1s1t1e1r1"], ["h1e1h5m4m1e1"], ["h1t8m1s1t1e1r1"], ["h1a1m1s1t1e1r1"], ["f22f23f24f25f26f1f2f3f4f5f6f7f8f9f10f11f12f13f14f15...
INTRODUCTORY
PYTHON3
CODEWARS
3,533
def hamster_me(code, message):
22788fa8ffaaf1a8e04146acdabb9fc1
UNKNOWN
Two tortoises named ***A*** and ***B*** must run a race. ***A*** starts with an average speed of ```720 feet per hour```. Young ***B*** knows she runs faster than ***A***, and furthermore has not finished her cabbage. When she starts, at last, she can see that ***A*** has a `70 feet lead` but ***B***'s speed is `850 f...
["import math\n\ndef race(v1, v2, g):\n if v2 < v1: return None\n seconds = 0.1\n while (v1/3600) * seconds + g >= (v2/3600) * seconds:\n seconds += 0.05\n hours = seconds / 3600\n hoursRest = seconds % 3600\n minutes = hoursRest / 60\n seconds = hoursRest % 60\n return [math.floor(hours)...
{"fn_name": "race", "inputs": [[720, 850, 70], [80, 91, 37], [80, 100, 40], [720, 850, 37], [720, 850, 370], [120, 850, 37], [820, 850, 550], [820, 81, 550]], "outputs": [[[0, 32, 18]], [[3, 21, 49]], [[2, 0, 0]], [[0, 17, 4]], [[2, 50, 46]], [[0, 3, 2]], [[18, 20, 0]], [null]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,418
def race(v1, v2, g):
75bbcbb54132f0000833df944f2cb43c
UNKNOWN
You drop a ball from a given height. After each bounce, the ball returns to some fixed proportion of its previous height. If the ball bounces to height 1 or less, we consider it to have stopped bouncing. Return the number of bounces it takes for the ball to stop moving. ``` bouncingBall(initialHeight, bouncingProporti...
["import math\n\ndef bouncing_ball(initial, proportion):\n return math.ceil(math.log(initial, 1/proportion))", "def bouncing_ball(initial, proportion):\n count = 0\n while initial > 1:\n initial = initial * proportion\n count = count + 1\n return count", "def bouncing_ball(i, p , n = 0):\n ...
{"fn_name": "bouncing_ball", "inputs": [[2, 0.5], [4, 0.5], [10, 0.1], [100, 0.1], [9, 0.3], [30, 0.3]], "outputs": [[1], [2], [1], [2], [2], [3]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,438
def bouncing_ball(initial, proportion):
602bd199c1fde39ee48012e7bc27f3ca
UNKNOWN
Given a set of elements (integers or string characters) that may occur more than once, we need to know the amount of subsets that none of their values have repetitions. Let's see with an example: ``` set numbers = {1, 2, 3, 4} ``` The subsets are: ``` {{1}, {2}, {3}, {4}, {1,2}, {1,3}, {1,4}, {2,3}, {2,4},{3,4}, {1,...
["def est_subsets(arr):\n return 2**len(set(arr)) - 1", "est_subsets = lambda a: 2 ** len(set(a)) - 1", "est_subsets=lambda n:2 ** len(set(n)) - 1", "from math import factorial\nfrom collections import Counter\n\ndef C(n, r):\n return factorial(n) // factorial(r) // factorial(n-r)\n \ndef est_subsets(arr):\n ...
{"fn_name": "est_subsets", "inputs": [[[1, 2, 3, 4]], [["a", "b", "c", "d", "d"]]], "outputs": [[15], [15]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,247
def est_subsets(arr):
ca6245798ed7f557d3dda32a4e95546a
UNKNOWN
It's tricky keeping track of who is owed what when spending money in a group. Write a function to balance the books. * The function should take one parameter: an object/dict with two or more name-value pairs which represent the members of the group and the amount spent by each. * The function should return an object/d...
["def split_the_bill(x):\n diff = sum(x.values())/float(len(x))\n return {k: round(x[k]-diff, 2) for k in x}", "def split_the_bill(spendings):\n fair_amount = sum(spendings.values()) / float(len(spendings))\n return {name: round(amount - fair_amount, 2) for name, amount in spendings.items()}\n", "def split_...
{"fn_name": "split_the_bill", "inputs": [[{"A": 20, "B": 15, "C": 10}], [{"A": 40, "B": 25, "X": 10}], [{"A": 40, "B": 25, "C": 10, "D": 153, "E": 58}], [{"A": 475, "B": 384, "C": 223, "D": 111, "E": 19}], [{"A": 20348, "B": 493045, "C": 2948, "D": 139847, "E": 48937534, "F": 1938724, "G": 4, "H": 2084}]], "outputs": [...
INTRODUCTORY
PYTHON3
CODEWARS
1,352
def split_the_bill(x):
7323b0da72eeb2a9ae41c4e05b99b354
UNKNOWN
## Witamy! You are in Poland and want to order a drink. You need to ask "One beer please": "Jedno piwo poprosze" ``` java Translator.orderingBeers(1) = "Jedno piwo poprosze" ``` But let's say you are really thirsty and want several beers. Then you need to count in Polish. And more difficult, you need to understand t...
["def ordering_beers(beers):\n assert 0 <= beers < 100\n \n units = [\"\", \"jeden\", \"dwa\", \"trzy\", \"cztery\", \"piec\", \"szesc\" , \"siedem\", \"osiem\", \"dziewiec\",\n \"dziesiec\", \"jedenascie\", \"dwanascie\", \"trzynascie\", \"czternascie\", \"pietnascie\", \"szesnascie\", \"siedemnasc...
{"fn_name": "ordering_beers", "inputs": [[0], [1], [2], [3], [4], [5], [8], [10], [11], [12], [13], [14], [15], [16], [20], [21], [22], [28], [33], [44], [55], [98], [99]], "outputs": [["Woda mineralna poprosze"], ["Jedno piwo poprosze"], ["Dwa piwa poprosze"], ["Trzy piwa poprosze"], ["Cztery piwa poprosze"], ["Piec p...
INTRODUCTORY
PYTHON3
CODEWARS
12,092
def ordering_beers(beers):
aa7c573f84d96991134578ef413d1c68
UNKNOWN
Third day at your new cryptoanalyst job and you come across your toughest assignment yet. Your job is to implement a simple keyword cipher. A keyword cipher is a type of monoalphabetic substitution where two parameters are provided as such (string, keyword). The string is encrypted by taking the keyword, dropping any l...
["abc = \"abcdefghijklmnopqrstuvwxyz\"\n\ndef keyword_cipher(s, keyword, key=\"\"):\n for c in keyword + abc:\n if c not in key:\n key += c\n return s.lower().translate(str.maketrans(abc, key))", "from string import ascii_lowercase\n\ndef keyword_cipher(a, b):\n return a.lower().translate(str...
{"fn_name": "keyword_cipher", "inputs": [["Welcome home", "secret"], ["hello", "wednesday"], ["HELLO", "wednesday"], ["HeLlO", "wednesday"], ["WELCOME HOME", "gridlocked"], ["alpha bravo charlie", "delta"], ["Home Base", "seven"], ["basecamp", "covert"], ["one two three", "rails"], ["Test", "unbuntu"]], "outputs": [["w...
INTRODUCTORY
PYTHON3
CODEWARS
2,373
def keyword_cipher(msg, keyword):
6b5a34b08672f3dd6461d574c600b742
UNKNOWN
Create a function that takes a string as a parameter and does the following, in this order: 1. replaces every letter with the letter following it in the alphabet (see note below) 2. makes any vowels capital 3. makes any consonants lower case **Note:** the alphabet should wrap around, so `Z` becomes `A` So, for examp...
["def changer(s):\n return s.lower().translate(str.maketrans('abcdefghijklmnopqrstuvwxyz', 'bcdEfghIjklmnOpqrstUvwxyzA'))", "changer=lambda s: \"\".join([a if not a.isalpha() else chr((ord(a)-96)%26+97).upper() if a in \"zdhnt\" else chr(ord(a)+1) for a in s.lower()])", "table = str.maketrans(\"abcdefghijklmnopqrstu...
{"fn_name": "changer", "inputs": [["Cat30"], ["Alice"], ["sponge1"], ["Hello World"], ["dogs"], ["z"]], "outputs": [["dbU30"], ["bmjdf"], ["tqpOhf1"], ["Ifmmp xpsmE"], ["Epht"], ["A"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,890
def changer(string):
ef5677b1bd05b7ea70366deac7fcc7b5
UNKNOWN
Complete the method so that it formats the words into a single comma separated value. The last word should be separated by the word 'and' instead of a comma. The method takes in an array of strings and returns a single formatted string. Empty string values should be ignored. Empty arrays or null/nil values being passed...
["def format_words(words):\n return ', '.join(word for word in words if word)[::-1].replace(',', 'dna ', 1)[::-1] if words else ''", "def format_words(words):\n # reject falsey words\n if not words: return \"\"\n \n # ignoring empty strings\n words = [word for word in words if word]\n \n number_...
{"fn_name": "format_words", "inputs": [[["one", "two", "three", "four"]], [["one"]], [["one", "", "three"]], [["", "", "three"]], [["one", "two", ""]], [[]], [null], [[""]]], "outputs": [["one, two, three and four"], ["one"], ["one and three"], ["three"], ["one and two"], [""], [""], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,306
def format_words(words):
95f1d1fffabe1c409c2f269c94a4b48a
UNKNOWN
# Task let F(N) be the sum square of digits of N. So: `F(1) = 1, F(3) = 9, F(123) = 14` Choose a number A, the sequence {A0, A1, ...} is defined as followed: ``` A0 = A A1 = F(A0) A2 = F(A1) ... ``` if A = 123, we have: ``` 123 → 14(1 x 1 + 2 x 2 + 3 x 3) → 17(1 x 1 + 4 x 4) → 50(1 ...
["from itertools import count\n\n# Couldn't find the pattern of why it's 1 or 8, I'm sad :(\ndef repeat_sequence_len(n):\n memo = {}\n for i in count():\n if n in memo: return i - memo[n]\n memo[n] = i\n n = sum(d*d for d in map(int, str(n)))", "def F(n):\n return sum(int(d)**2 for d in st...
{"fn_name": "repeat_sequence_len", "inputs": [[1], [85], [810], [812], [818], [833]], "outputs": [[1], [8], [8], [8], [1], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,321
def repeat_sequence_len(n):
494072e07e0d306096e8474836fc74f8
UNKNOWN
You get a new job working for Eggman Movers. Your first task is to write a method that will allow the admin staff to enter a person’s name and return what that person's role is in the company. You will be given an array of object literals holding the current employees of the company. You code must find the employee ...
["employees = [{'first_name': 'Ollie', 'last_name': 'Hepburn', 'role': 'Boss'}, {'first_name': 'Morty', 'last_name': 'Smith', 'role': 'Truck Driver'}, {'first_name': 'Peter', 'last_name': 'Ross', 'role': 'Warehouse Manager'}, {'first_name': 'Cal', 'last_name': 'Neil', 'role': 'Sales Assistant'}, {'first_name': 'Jesse',...
{"fn_name": "find_employees_role", "inputs": [["Dipper Pines"], ["Morty Smith"], ["Anna Bell"], ["Anna"], ["Bell Anna"], ["Jewel Bell"], ["Bell Jewel"]], "outputs": [["Does not work here!"], ["Truck Driver"], ["Admin"], ["Does not work here!"], ["Does not work here!"], ["Receptionist"], ["Does not work here!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,257
employees = [{'first_name': 'Ollie', 'last_name': 'Hepburn', 'role': 'Boss'}, {'first_name': 'Morty', 'last_name': 'Smith', 'role': 'Truck Driver'}, {'first_name': 'Peter', 'last_name': 'Ross', 'role': 'Warehouse Manager'}, {'first_name': 'Cal', 'last_name': 'Neil', 'role': 'Sales Assistant'}, {'first_name': 'Jesse', ...
e5b1bb9b0e8ea13f8a15e292ac8ab8ea
UNKNOWN
Remove the parentheses = In this kata you are given a string for example: ```python "example(unwanted thing)example" ``` Your task is to remove everything inside the parentheses as well as the parentheses themselves. The example above would return: ```python "exampleexample" ``` Other than parentheses only letters...
["def remove_parentheses(s):\n lvl,out = 0,[]\n for c in s:\n lvl += c=='('\n if not lvl: out.append(c)\n lvl -= c==')' \n return ''.join(out)", "import re\n\ndef remove_parentheses(s):\n while (t := re.sub(r'\\([^()]*\\)', '', s)) != s:\n s = t\n return s", "def remove_par...
{"fn_name": "remove_parentheses", "inputs": [["example(unwanted thing)example"], ["example (unwanted thing) example"], ["a (bc d)e"], ["a(b(c))"], ["hello example (words(more words) here) something"], ["(first group) (second group) (third group)"]], "outputs": [["exampleexample"], ["example example"], ["a e"], ["a"], ...
INTRODUCTORY
PYTHON3
CODEWARS
2,469
def remove_parentheses(s):
eff6c56f00df7a1d032642033574d67b
UNKNOWN
In this Kata, you will be given a string that has lowercase letters and numbers. Your task is to compare the number groupings and return the largest number. Numbers will not have leading zeros. For example, `solve("gh12cdy695m1") = 695`, because this is the largest of all number groupings. Good luck! Please also t...
["import re\n\n\ndef solve(s):\n return max(map(int,re.findall(r\"(\\d+)\", s)))", "def solve(s):\n largest = 0\n number = 0\n \n for char in s:\n if char.isdigit():\n number = number * 10 + int(char)\n if largest < number:\n largest = number\n else:\n ...
{"fn_name": "solve", "inputs": [["gh12cdy695m1"], ["2ti9iei7qhr5"], ["vih61w8oohj5"], ["f7g42g16hcu5"], ["lu1j8qbbb85"]], "outputs": [[695], [9], [61], [42], [85]]}
INTRODUCTORY
PYTHON3
CODEWARS
23,578
def solve(s):
074a731ac350db44801e04ed949f8af6
UNKNOWN
#Bubbleing around Since everybody hates chaos and loves sorted lists we should implement some more sorting algorithms. Your task is to implement a Bubble sort (for some help look at https://en.wikipedia.org/wiki/Bubble_sort) and return a list of snapshots after **each change** of the initial list. e.g. If the initi...
["def bubble(l):\n ret = []\n for i in range(len(l) - 1, 0, -1):\n for j in range(i):\n if l[j] > l[j + 1]:\n l[j], l[j + 1] = l[j + 1], l[j]\n ret.append(l[:])\n return ret", "def bubble(l):\n bubbling,bubbles = True, []\n while bubbling :\n bubblin...
{"fn_name": "bubble", "inputs": [[[]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[1, 3, 3, 7, 4, 2]]], "outputs": [[[]], [[]], [[[1, 3, 3, 4, 7, 2], [1, 3, 3, 4, 2, 7], [1, 3, 3, 2, 4, 7], [1, 3, 2, 3, 4, 7], [1, 2, 3, 3, 4, 7]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,881
def bubble(l):
efc343cd2ec0e956727e2cc2d7fd490a
UNKNOWN
Paul is an excellent coder and sits high on the CW leaderboard. He solves kata like a banshee but would also like to lead a normal life, with other activities. But he just can't stop solving all the kata!! Given an array (x) you need to calculate the Paul Misery Score. The values are worth the following points: kata ...
["def paul(x):\n points = {'life': 0, 'eating': 1, 'kata': 5, 'Petes kata': 10}\n misery = sum(map(points.get, x))\n return ['Miserable!', 'Sad!', 'Happy!', 'Super happy!']\\\n [(misery<40)+(misery<70)+(misery<100)]", "def paul(x):\n val = x.count(\"kata\")*5 + x.count(\"Petes kata\")*10 + x.coun...
{"fn_name": "paul", "inputs": [[["life", "eating", "life"]], [["life", "Petes kata", "Petes kata", "Petes kata", "eating"]], [["Petes kata", "Petes kata", "eating", "Petes kata", "Petes kata", "eating"]]], "outputs": [["Super happy!"], ["Super happy!"], ["Happy!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,373
def paul(x):
707f15645066c71b5a7357bdf4f78e8b
UNKNOWN
# Task Yesterday you found some shoes in your room. Each shoe is described by two values: ``` type indicates if it's a left or a right shoe; size is the size of the shoe. ``` Your task is to check whether it is possible to pair the shoes you found in such a way that each pair consists of a right and a left shoe of an...
["def pair_of_shoes(a):\n return sorted(s for lr, s in a if lr == 1) == sorted(s for lr, s in a if lr == 0)", "from collections import defaultdict\ndef pair_of_shoes(shoes):\n sz = defaultdict(list)\n for i in shoes:\n sz[i[1]].append(i[0])\n return all( (i[1].count(1) == i[1].count(0)) for i in sz.i...
{"fn_name": "pair_of_shoes", "inputs": [[[[0, 21], [1, 23], [1, 21], [0, 23]]], [[[0, 21], [1, 23], [1, 21], [1, 23]]], [[[0, 23], [1, 21], [1, 23], [0, 21], [1, 22], [0, 22]]], [[[0, 23], [1, 21], [1, 23], [0, 21]]], [[[0, 23], [1, 21], [1, 22], [0, 21]]], [[[0, 23]]], [[[0, 23], [1, 23]]], [[[0, 23], [1, 23], [1, 23]...
INTRODUCTORY
PYTHON3
CODEWARS
1,630
def pair_of_shoes(shoes):
dcbff2ceafa291ed7180c5a76a01c375
UNKNOWN
# Task The string is called `prime` if it cannot be constructed by concatenating some (more than one) equal strings together. For example, "abac" is prime, but "xyxy" is not("xyxy"="xy"+"xy"). Given a string determine if it is prime or not. # Input/Output - `[input]` string `s` string containing only lower...
["def prime_string(s):\n return (s + s).find(s, 1) == len(s)", "import re\ndef prime_string(s):\n return not not re.sub(r\"^(.+)\\1+$\",\"\",s)", "def prime_string(s):\n n=len(s)\n return all(s!= s[:i]*(n//i) for i in range(1,n//2 +1))\n \n \n \n \n", "def prime_string(s):\n n = len(s)\n return n ==...
{"fn_name": "prime_string", "inputs": [["abac"], ["abab"], ["aaaa"], ["x"], ["abc"], ["fdsyffdsyffdsyffdsyffdsyf"], ["utdutdtdutd"], ["abba"]], "outputs": [[true], [false], [false], [true], [true], [false], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,096
def prime_string(s):
ada4e2f9aa172c08fbc28d8686baa0fd
UNKNOWN
Your task is to create a function called ```sum_arrays()``` in Python or ```addArrays``` in Javascript, which takes two arrays consisting of integers, and returns the sum of those two arrays. The twist is that (for example) ```[3,2,9]``` does not equal ``` 3 + 2 + 9```, it would equal ```'3' + '2' + '9'``` converted t...
["def sum_arrays(*args):\n if all(x == [] for x in args) or all(x == [0] for x in args):\n return []\n elif any(x == [] for x in args):\n return max(args)\n else:\n s = sum(int(''.join(map(str, x))) for x in args)\n minus = s < 0\n return [int(x) * -1 if minus and i == 0 else int...
{"fn_name": "sum_arrays", "inputs": [[[3, 2, 9], [1, 2]], [[4, 7, 3], [1, 2, 3]], [[1], [5, 7, 6]], [[3, 2, 6, 6], [-7, 2, 2, 8]], [[-4, 5, 7, 3, 6], [5, 3, 4, 5]], [[], []], [[0], []], [[], [1, 2]], [[1, 4, 5], []], [[0], [0]]], "outputs": [[[3, 4, 1]], [[5, 9, 6]], [[5, 7, 7]], [[-3, 9, 6, 2]], [[-4, 0, 3, 9, 1]], [[...
INTRODUCTORY
PYTHON3
CODEWARS
6,283
def sum_arrays(array1,array2):
b3274d470b978f70f87904e158f17e9f
UNKNOWN
Create a function that transforms any positive number to a string representing the number in words. The function should work for all numbers between 0 and 999999. ### Examples ``` number2words(0) ==> "zero" number2words(1) ==> "one" number2words(9) ==> "nine" number2words(10) ==> "ten" number2words(17) ==> ...
["words = \"zero one two three four five six seven eight nine\" + \\\n\" ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty\" + \\\n\" thirty forty fifty sixty seventy eighty ninety\"\nwords = words.split(\" \")\n\ndef number2words(n):\n if n < 20:\n return words[n]\n el...
{"fn_name": "number2words", "inputs": [[0], [1], [8], [5], [9], [10], [19], [20], [22], [54], [80], [98], [100], [301], [793], [800], [650], [1000], [1003], [3052], [7300], [7217], [8340], [99997], [888887]], "outputs": [["zero"], ["one"], ["eight"], ["five"], ["nine"], ["ten"], ["nineteen"], ["twenty"], ["twenty-two"]...
INTRODUCTORY
PYTHON3
CODEWARS
9,503
def number2words(n):
8b02f30ebca48d51f13153b549ca13c8
UNKNOWN
## Your Story "A *piano* in the home meant something." - *Fried Green Tomatoes at the Whistle Stop Cafe* You've just realized a childhood dream by getting a beautiful and beautiful-sounding upright piano from a friend who was leaving the country. You immediately started doing things like playing "Heart and Soul" over ...
["def black_or_white_key(key_press_count):\n return \"black\" if (key_press_count - 1) % 88 % 12 in [1, 4, 6, 9, 11] else \"white\"\n", "w, b = \"white\", \"black\"\nkeyboard = [w, b, w, w, b, w, b, w, w, b, w, b]\n\ndef black_or_white_key(count):\n return keyboard[(count - 1) % 88 % 12]", "def black_or_white_key...
{"fn_name": "black_or_white_key", "inputs": [[1], [5], [12], [42], [88], [89], [92], [100], [111], [200], [2017]], "outputs": [["white"], ["black"], ["black"], ["white"], ["white"], ["white"], ["white"], ["black"], ["white"], ["black"], ["white"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,588
def black_or_white_key(key_press_count):
35949138265dcd0af705ffdd3273276d
UNKNOWN
# A History Lesson Tetris is a puzzle video game originally designed and programmed by Soviet Russian software engineer Alexey Pajitnov. The first playable version was completed on June 6, 1984. Pajitnov derived its name from combining the Greek numerical prefix tetra- (the falling pieces contain 4 segments) and tenni...
["points = [0, 40, 100, 300, 1200]\n\ndef get_score(arr) -> int:\n cleared = 0\n score = 0\n for lines in arr:\n level = cleared // 10\n score += (level+1) * points[lines]\n cleared += lines\n return score", "def get_score(arr) -> int:\n return sum([0, 40, 100, 300, 1200][n] * (1 + (...
{"fn_name": "get_score", "inputs": [[[0, 1, 2, 3, 4]], [[0, 1, 1, 3, 0, 2, 1, 2]], [[2, 0, 4, 2, 2, 3, 0, 0, 3, 3]], [[0]], [[]]], "outputs": [[1640], [620], [3300], [0], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,216
def get_score(arr) -> int:
26570fd53c60cb0ed4382258fc560f89
UNKNOWN
# Task You are given two strings s and t of the same length, consisting of uppercase English letters. Your task is to find the minimum number of "replacement operations" needed to get some `anagram` of the string t from the string s. A replacement operation is performed by picking exactly one character from the string...
["from collections import Counter\n\ndef create_anagram(s, t):\n return sum((Counter(s) - Counter(t)).values())", "def create_anagram(s, t):\n return sum(max(0, s.count(c) - t.count(c)) for c in set(s))", "def create_anagram(s, t):\n for c in s: t = t.replace(c, \"\", 1)\n return len(t)", "def create_anagra...
{"fn_name": "create_anagram", "inputs": [["AABAA", "BBAAA"], ["OVGHK", "RPGUC"], ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAB", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAC"]], "outputs": [[1], [4], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,164
def create_anagram(s, t):
056e3ab1adf3ec59e8d336be820a0a12
UNKNOWN
Complete the square sum function so that it squares each number passed into it and then sums the results together. For example, for `[1, 2, 2]` it should return `9` because `1^2 + 2^2 + 2^2 = 9`. ```if:racket In Racket, use a list instead of an array, so '(1 2 3) should return 9. ```
["def square_sum(numbers):\n return sum(x ** 2 for x in numbers)", "def square_sum(numbers):\n return sum(x * x for x in numbers) ", "def square_sum(numbers):\n return sum(map(lambda x: x**2,numbers))", "def square_sum(numbers):\n res = 0\n for num in numbers:\n res = res + num*num\n return res...
{"fn_name": "square_sum", "inputs": [[[1, 2]], [[0, 3, 4, 5]], [[]], [[-1, -2]], [[-1, 0, 1]]], "outputs": [[5], [50], [0], [5], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
10,977
def square_sum(numbers):
0e7c2dd1f5a3bcc68bcb643dd91c2ffb
UNKNOWN
# Task Given a `sequence` of integers, check whether it is possible to obtain a strictly increasing sequence by erasing no more than one element from it. # Example For `sequence = [1, 3, 2, 1]`, the output should be `false`; For `sequence = [1, 3, 2]`, the output should be `true`. # Input/Output - `[input]` ...
["def almost_increasing_sequence(sequence):\n save, first = -float('inf'), True\n for i,x in enumerate(sequence):\n if x > save: save = x\n elif first:\n if i == 1 or x > sequence[i-2]: save = x\n first = False\n else: return False\n return True", "is_increasing_seque...
{"fn_name": "almost_increasing_sequence", "inputs": [[[1, 3, 2, 1]], [[1, 3, 2]], [[1, 2, 3]], [[1, 2, 3, 1]], [[1, 4, 10, 4, 2]], [[10, 1, 2, 3, 4, 5]], [[1, 1, 1, 2, 3]], [[0, -2, 5, 6]], [[1, 1]], [[4, 5, 6, 1, 2, 3]], [[149, 15, 23, 32, 41, 48, 58, 66, 69, 75, 81, 91, 178, 100, 109, 118, 128, 134, 143]]], "outputs"...
INTRODUCTORY
PYTHON3
CODEWARS
2,788
def almost_increasing_sequence(sequence):
a1c7f2ab78f3f9bb8c05315530a8a17a
UNKNOWN
## Task Write a function that accepts two arguments and generates a sequence containing the integers from the first argument to the second inclusive. ## Input Pair of integers greater than or equal to `0`. The second argument will always be greater than or equal to the first. ## Example ```python generate_intege...
["def generate_integers(m, n): \n return list(range(m,n+1))", "def generate_integers(m, n): \n return [*range(m, n + 1)]", "def generate_integers(m, n):\n return [i for i in range(m,n+1)]\n", "def generate_integers(m, n):\n ans = []\n for each in range(m,n+1):\n ans.append(each)\n return ans", ...
{"fn_name": "generate_integers", "inputs": [[2, 5]], "outputs": [[[2, 3, 4, 5]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,030
def generate_integers(m, n):
f4871c39039da88117347362c1c7d001
UNKNOWN
# Story&Task There are three parties in parliament. The "Conservative Party", the "Reformist Party", and a group of independants. You are a member of the “Conservative Party” and you party is trying to pass a bill. The “Reformist Party” is trying to block it. In order for a bill to pass, it must have a majority vo...
["def pass_the_bill(total, conservative, reformist):\n ind = total - conservative - reformist\n majority = total//2 + 1\n if conservative > majority:\n return 0\n elif conservative + ind < majority:\n return -1\n else:\n return majority - conservative", "def pass_the_bill(t, c, r):\n...
{"fn_name": "pass_the_bill", "inputs": [[8, 3, 3], [13, 4, 7], [7, 4, 3], [11, 4, 1], [11, 5, 1], [11, 6, 1], [11, 4, 4], [11, 5, 4], [11, 5, 5], [11, 4, 6], [11, 4, 5], [15, 9, 3], [16, 7, 8], [16, 8, 7], [16, 1, 8]], "outputs": [[2], [-1], [0], [2], [1], [0], [2], [1], [1], [-1], [2], [0], [-1], [1], [-1]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,898
def pass_the_bill(total_members, conservative_party_members, reformist_party_members):
1254d3e76ce1e3239bb125a3d4e66d45
UNKNOWN
*This kata is based on [Project Euler Problem 539](https://projecteuler.net/problem=539)* ##Object Find the last number between 1 and `n` (inclusive) that survives the elimination process ####How It Works Start with the first number on the left then remove every other number moving right until you reach the the end...
["def last_man_standing(n):\n dir, lst = -1, range(2,n+1,2)\n while len(lst) != 1:\n lst = lst[len(lst)%2 or dir == 1 ::2]\n dir = -dir\n return lst[0]", "from math import log\n\ndef last_man_standing(n):\n return 1 + sum((((n >> i) | (i + 1)) % 2) << i for i in range(int(log(n, 2))))", "def l...
{"fn_name": "last_man_standing", "inputs": [[9], [10], [100], [1000], [50000]], "outputs": [[6], [8], [54], [510], [22358]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,210
def last_man_standing(n):
1a124f3ee441e907e0e9782794e197d4
UNKNOWN
Write a code that receives an array of numbers or strings, goes one by one through it while taking one value out, leaving one value in, taking, leaving, and back again to the beginning until all values are out. It's like a circle of people who decide that every second person will leave it, until the last person is th...
["from collections import deque\n\ndef yes_no(arr):\n d, result = deque(arr), []\n while d:\n result.append(d.popleft())\n d.rotate(-1)\n return result", "def yes_no(arr):\n result = []\n while arr:\n result.append(arr.pop(0))\n if arr:\n arr.append(arr.pop(0))\n ...
{"fn_name": "yes_no", "inputs": [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [["this", "code", "is", "right", "the"]], [[]], [["a"]], [["a", "b"]]], "outputs": [[[1, 3, 5, 7, 9, 2, 6, 10, 8, 4]], [["this", "is", "the", "right", "code"]], [[]], [["a"]], [["a", "b"]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,944
def yes_no(arr):
108461bcbfef06eb3f11fd80cec96a49
UNKNOWN
Write a function `take_umbrella()` that takes two arguments: a string representing the current weather and a float representing the chance of rain today. Your function should return `True` or `False` based on the following criteria. * You should take an umbrella if it's currently raining or if it's cloudy and the cha...
["def take_umbrella(weather, rain_chance):\n # Your code here.\n return (weather=='cloudy' and rain_chance>0.20) or weather=='rainy' or (weather=='sunny' and rain_chance>0.5)", "def take_umbrella(weather, rain_chance):\n return rain_chance > {'sunny': 0.5, 'cloudy': 0.2, 'rainy': -1}[weather]", "def take_umbre...
{"fn_name": "take_umbrella", "inputs": [["sunny", 0.4], ["rainy", 0.0], ["cloudy", 0.2]], "outputs": [[false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,713
def take_umbrella(weather, rain_chance):
e7da92895337b3f65a3c4878fd12236d
UNKNOWN
Write a program that, given a word, computes the scrabble score for that word. ## Letter Values You'll need these: ``` Letter Value A, E, I, O, U, L, N, R, S, T 1 D, G 2 B, C, M, P 3 F, H, V, W, Y 4 K ...
["def scrabble_score(st): \n x = 0\n for y in st:\n if 'a' in y.lower():\n x += 1\n if 'e' in y.lower():\n x += 1\n if 'i' in y.lower():\n x += 1\n if 'o' in y.lower():\n x += 1\n if 'u' in y.lower():\n x += 1\n if 'l...
{"fn_name": "scrabble_score", "inputs": [[""], ["a"], ["street"], ["STREET"], [" a"], ["st re et"], ["f"], ["quirky"], ["MULTIBILLIONAIRE"], ["alacrity"]], "outputs": [[0], [1], [6], [6], [1], [6], [4], [22], [20], [13]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,496
def scrabble_score(st):
87278b9516f2b6d147c45c22198d74ed
UNKNOWN
You have n dices each one having s sides numbered from 1 to s. How many outcomes add up to a specified number k? For example if we roll four normal six-sided dices we have four outcomes that add up to 5. (1, 1, 1, 2) (1, 1, 2, 1) (1, 2, 1, 1) (2, 1, 1, 1)
["def outcome(n, s, k): \n if n == 1: return 1 if 0 < k <= s else 0\n return sum(outcome(n - 1, s, k - j - 1) for j in range(s)) if k > 0 else 0", "def outcome(n, s, k):\n return n <= k <= n*s and (n in (1, k) or sum(outcome(n-1, s, k-x-1) for x in range(min(s, k-n+1))))", "def outcome(n, s, k):\n if n =...
{"fn_name": "outcome", "inputs": [[1, 6, 0], [1, 0, 1], [0, 6, 1], [1, 6, 1], [1, 6, 2], [1, 6, 3], [1, 6, 4], [1, 6, 5], [1, 6, 6], [1, 6, 7], [2, 6, 1], [2, 6, 2], [2, 6, 3], [2, 6, 4], [2, 6, 5], [2, 6, 6], [2, 6, 7], [2, 6, 8], [2, 6, 9], [2, 6, 10], [2, 6, 11], [2, 6, 12], [2, 6, 13], [3, 6, 6], [3, 6, 9], [3, 6, ...
INTRODUCTORY
PYTHON3
CODEWARS
1,715
def outcome(n, s, k):
d78ce9bb1a42d59a93eed90d3a63da0b
UNKNOWN
# One is the loneliest number ## Task The range of vision of a digit is its own value. `1` can see one digit to the left and one digit to the right,` 2` can see two digits, and so on. Thus, the loneliness of a digit `N` is the sum of the digits which it can see. Given a non-negative integer, your funtion must deter...
["def loneliest(n):\n a = list(map(int, str(n)))\n b = [(sum(a[max(0, i - x):i+x+1]) - x, x) for i, x in enumerate(a)]\n return (min(b)[0], 1) in b", "def loneliest(n): \n def loneliness(it):\n i,v = it\n return sum(lst[max(0,i-v):i+v+1])-v, abs(v-1)\n \n lst = list(map(int,str(n)))\n ...
{"fn_name": "loneliest", "inputs": [[34315], [123456], [8854778], [65432165432], [0], [1], [11111]], "outputs": [[true], [true], [false], [false], [false], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,954
def loneliest(number):
5adadc32eb4238b864213a287c24893f
UNKNOWN
Many years ago, Roman numbers were defined by only `4` digits: `I, V, X, L`, which represented `1, 5, 10, 50`. These were the only digits used. The value of a sequence was simply the sum of digits in it. For instance: ``` IV = VI = 6 IX = XI = 11 XXL = LXX = XLX = 70 ``` It is easy to see that this system is ambiguous,...
["INITIAL = [0, 4, 10, 20, 35, 56, 83, 116, 155, 198, 244, 292]\n\ndef solve(n):\n return INITIAL[n] if n < 12 else 292 + (49 * (n-11))", "from functools import lru_cache\n\nDIGITS = [1, 5, 10, 50]\nTHRESHOLD = 12\n\ndef solve_naive (n):\n minimal = n * min(DIGITS)\n maximal = n * max(DIGITS)\n return maxim...
{"fn_name": "solve", "inputs": [[1], [2], [3], [4], [5], [6], [10], [10000000]], "outputs": [[4], [10], [20], [35], [56], [83], [244], [489999753]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,724
def solve(n):
78fd814c01ab6a8ac4fd329b77e4e984
UNKNOWN
There are just some things you can't do on television. In this case, you've just come back from having a "delicious" Barth burger and you're set to give an interview. The Barth burger has made you queezy, and you've forgotten some of the import rules of the "You Can't Do That on Television" set. If you say any of the ...
["import re\n\nWATER_PATTERN = re.compile(r\"water|wet|wash\", re.I)\nSLIME_PATTERN = re.compile(r\"\\bI don't know\\b|slime\", re.I)\n\n\ndef bucket_of(said):\n water = WATER_PATTERN.search(said)\n slime = SLIME_PATTERN.search(said)\n\n if water:\n return 'sludge' if slime else 'water'\n\n return 's...
{"fn_name": "bucket_of", "inputs": [["water"], ["wet"], ["wash"], ["i don't know"], ["slime"], ["wet water"], ["slime water"], ["I don't know if this will work"], ["I don't know if this will work without watering it first."], [""], ["is there SLIME in that?!"], ["i won't say anything"], ["WaTeR?"], ["but i can say slud...
INTRODUCTORY
PYTHON3
CODEWARS
3,556
def bucket_of(said):
9b45b2d4440d5bfe137bcffcce871e67
UNKNOWN
# Introduction You are the developer working on a website which features a large counter on its homepage, proudly displaying the number of happy customers who have downloaded your companies software. You have been tasked with adding an effect to this counter to make it more interesting. Instead of just displaying ...
["def counter_effect(hit_count):\n return [[i for i in range(int(hit_count[x]) + 1)] for x in range(4)]", "def counter_effect(n):\n return [list(range(int(x)+1)) for x in n]", "def counter_effect(hit):\n b = []\n for i in str(hit):\n a = []\n for k in range(int(i)+1):\n a.append(k)\...
{"fn_name": "counter_effect", "inputs": [["1250"], ["0050"], ["0000"]], "outputs": [[[[0, 1], [0, 1, 2], [0, 1, 2, 3, 4, 5], [0]]], [[[0], [0], [0, 1, 2, 3, 4, 5], [0]]], [[[0], [0], [0], [0]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
545
def counter_effect(hit_count):
9dc40b73201dbcb571136d54a4fad4cb
UNKNOWN
**Step 1:** Create a function called `encode()` to replace all the lowercase vowels in a given string with numbers according to the following pattern: ``` a -> 1 e -> 2 i -> 3 o -> 4 u -> 5 ``` For example, `encode("hello")` would return `"h2ll4"`. There is no need to worry about uppercase vowels in this kata. **Step...
["def encode(s, t=str.maketrans(\"aeiou\", \"12345\")):\n return s.translate(t)\n \ndef decode(s, t=str.maketrans(\"12345\", \"aeiou\")):\n return s.translate(t)", "CIPHER = (\"aeiou\", \"12345\")\n\ndef encode(st):\n return st.translate(str.maketrans(CIPHER[0], CIPHER[1]))\n \ndef decode(st):\n retur...
{"fn_name": "encode", "inputs": [["hello"], ["How are you today?"], ["This is an encoding test."]], "outputs": [["h2ll4"], ["H4w 1r2 y45 t4d1y?"], ["Th3s 3s 1n 2nc4d3ng t2st."]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,392
def encode(st):
5ada4c8084a3198ca45905a4e0134434
UNKNOWN
Given an array of integers, return the smallest common factors of all integers in the array. When i say **Smallest Common Factor** i mean the smallest number above 1 that can divide all numbers in the array without a remainder. If there are no common factors above 1, return 1 (technically 1 is always a common factor)...
["def scf(lst):\n return next((k for k in range(2, 1 + min(lst, default=1)) if all(n % k == 0 for n in lst)), 1)\n", "from functools import reduce\nfrom math import floor, gcd, sqrt\n\ndef smallest_factor(n):\n return next((d for d in range(2, floor(sqrt(n)) + 1) if n % d == 0), n)\n\ndef scf(nums):\n return 1...
{"fn_name": "scf", "inputs": [[[200, 30, 18, 8, 64, 34]], [[21, 45, 51, 27, 33]], [[133, 147, 427, 266]], [[3, 5, 7]], [[]]], "outputs": [[2], [3], [7], [1], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,523
def scf(lst):
068469bbf3cd1650a67e2b6ec0276db0
UNKNOWN
# Task Timed Reading is an educational tool used in many schools to improve and advance reading skills. A young elementary student has just finished his very first timed reading exercise. Unfortunately he's not a very good reader yet, so whenever he encountered a word longer than maxLength, he simply skipped it and re...
["import re\ndef timed_reading(max_length, text):\n return sum(len(i) <= max_length for i in re.findall('\\w+', text))", "def timed_reading(max_length, text):\n count = 0\n for punctuation_mark in '!.,?\\'\\\"_-)(':\n text = text.replace(punctuation_mark , '')\n listed_text = text.split(\" \")\n\n ...
{"fn_name": "timed_reading", "inputs": [[4, "The Fox asked the stork, 'How is the soup?'"], [1, "..."], [3, "This play was good for us."], [3, "Suddenly he stopped, and glanced up at the houses"], [6, "Zebras evolved among the Old World horses within the last four million years."], [5, "Although zebra species may have ...
INTRODUCTORY
PYTHON3
CODEWARS
1,799
def timed_reading(max_length, text):
97b0d4b1ad9c9a7ad48e6796ff4f94db
UNKNOWN
This kata is all about adding numbers. You will create a function named add. This function will return the sum of all the arguments. Sounds easy, doesn't it?? Well here's the twist. The inputs will gradually increase with their index as parameter to the function. ```python add(3,4,5) #returns (3*1)+(4*2)+(5*3)=26 ...
["def add(*args):\n return sum((i+1)*v for i,v in enumerate(args))", "def add(*args):\n return sum(n * i for i, n in enumerate(args, 1))", "def add(*args):\n return sum(i * x for i, x in enumerate(args, 1))", "def add(*args):\n return sum(pos * value for pos, value in enumerate(args, 1))\n", "def add(*args)...
{"fn_name": "add", "inputs": [[100, 200, 300], [2], [4, -3, -2], [-1, -2, -3, -4]], "outputs": [[1400], [2], [-8], [-30]]}
INTRODUCTORY
PYTHON3
CODEWARS
677
def add(*args):
02f28df6714ff61671f3ed45f8704bdc
UNKNOWN
In the following 6 digit number: ``` 283910 ``` `91` is the greatest sequence of 2 consecutive digits. In the following 10 digit number: ``` 1234567890 ``` `67890` is the greatest sequence of 5 consecutive digits. Complete the solution so that it returns the greatest sequence of five consecutive digits found withi...
["def solution(digits):\n numlist = [int(digits[i:i+5]) for i in range(0,len(digits)-4)]\n return max(numlist)", "def solution(digits):\n return int(max(digits[a:a + 5] for a in range(len(digits) - 4)))", "def solution(digits):\n result = -1;\n for i in range(len(digits)):\n current = int(digits[i...
{"fn_name": "solution", "inputs": [["1234567898765"]], "outputs": [[98765]]}
INTRODUCTORY
PYTHON3
CODEWARS
20,343
def solution(digits):
87c6394baad06228c7584dc487693279
UNKNOWN
The task is very simple. You must to return pyramids. Given a number ```n``` you print a pyramid with ```n``` floors For example , given a ```n=4``` you must to print this pyramid: ``` /\ / \ / \ /______\ ``` Other example, given a ```n=6``` you must to print this pyramid: ``` /\ / \ ...
["def pyramid(n):\n return '\\n'.join(\"/{}\\\\\".format(\" _\"[r==n-1] * r*2).center(2*n).rstrip() for r in range(n)) + '\\n'", "def pyramid(n):\n return '\\n'.join(('/%s\\\\' % (' _'[i == n-1] * i*2)).rjust(n+i+1) for i in range(n)) + '\\n'", "def pyramid(n):\n return \"\".join(\n f\"{' ' * (n - i - 1...
{"fn_name": "pyramid", "inputs": [[4], [6], [10]], "outputs": [[" /\\\n / \\\n / \\\n/______\\\n"], [" /\\\n / \\\n / \\\n / \\\n / \\\n/__________\\\n"], [" /\\\n / \\\n / \\\n / \\\n / \\\n / \\\n / \\\n / ...
INTRODUCTORY
PYTHON3
CODEWARS
1,575
def pyramid(n):
bee80d82fed1823dbaf21be7e43387a1
UNKNOWN
Complete the function/method so that it returns the url with anything after the anchor (`#`) removed. ## Examples ```python # returns 'www.codewars.com' remove_url_anchor('www.codewars.com#about') # returns 'www.codewars.com?page=1' remove_url_anchor('www.codewars.com?page=1') ```
["def remove_url_anchor(url):\n return url.split('#')[0]", "def remove_url_anchor(url):\n return url.partition('#')[0]", "def remove_url_anchor(url):\n import re\n return re.sub('#.*$','',url)", "def remove_url_anchor(url):\n index = url.find('#')\n return url[:index] if index >= 0 else url", "def remove_url_...
{"fn_name": "remove_url_anchor", "inputs": [["www.codewars.com#about"], ["www.codewars.com/katas/?page=1#about"], ["www.codewars.com/katas/"]], "outputs": [["www.codewars.com"], ["www.codewars.com/katas/?page=1"], ["www.codewars.com/katas/"]]}
INTRODUCTORY
PYTHON3
CODEWARS
14,173
def remove_url_anchor(url):
362dd6c37e6b91027ee49dd68b1128bb
UNKNOWN
You are given a string of numbers between 0-9. Find the average of these numbers and return it as a floored whole number (ie: no decimal places) written out as a string. Eg: "zero nine five two" -> "four" If the string is empty or includes a number greater than 9, return "n/a"
["N = ['zero','one','two','three','four','five','six','seven','eight','nine']\n\ndef average_string(s):\n try:\n return N[sum(N.index(w) for w in s.split()) // len(s.split())]\n except (ZeroDivisionError, ValueError):\n return 'n/a'", "def average_string(s):\n if not s:\n return 'n/a'\n\n ...
{"fn_name": "average_string", "inputs": [["zero nine five two"], ["four six two three"], ["one two three four five"], ["five four"], ["zero zero zero zero zero"], ["one one eight one"], ["one"], [""], ["ten"], ["pippi"]], "outputs": [["four"], ["three"], ["three"], ["four"], ["zero"], ["two"], ["one"], ["n/a"], ["n/a"]...
INTRODUCTORY
PYTHON3
CODEWARS
5,763
def average_string(s):
66c906d2c56cf3b09d84fdb99d2f5958
UNKNOWN
As a part of this Kata, you need to create a function that when provided with a triplet, returns the index of the numerical element that lies between the other two elements. The input to the function will be an array of three distinct numbers (Haskell: a tuple). For example: gimme([2, 3, 1]) => 0 *2* is the num...
["def gimme(inputArray):\n # Implement this function\n return inputArray.index(sorted(inputArray)[1])", "def gimme(input_array):\n return input_array.index(sorted(input_array)[1])\n", "gimme=lambda l:l.index(sorted(l)[1])", "def gimme(lst):\n return lst.index(sorted(lst)[len(lst)//2])\n", "def gimme(arr):\n...
{"fn_name": "gimme", "inputs": [[[2, 3, 1]], [[5, 10, 14]], [[1, 3, 4]], [[15, 10, 14]], [[-0.41, -23, 4]], [[-15, -10, 14]]], "outputs": [[0], [1], [1], [2], [0], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
17,612
def gimme(input_array):
b6b52a7db61e5eef8d5ceba7b1af7fff
UNKNOWN
Given an integer, if the length of it's digits is a perfect square, return a square block of sqroot(length) * sqroot(length). If not, simply return "Not a perfect square!". Examples: 1212 returns: >1212 Note: 4 digits so 2 squared (2x2 perfect square). 2 digits on each line. 123123123 returns: >123123123 Note:...
["def square_it(digits):\n s = str(digits)\n n = len(s)**0.5\n if n != int(n):\n return \"Not a perfect square!\"\n n = int(n)\n return \"\\n\".join(s[i*n:i*n+n] for i in range(int(n)))", "square_it=lambda n:len(str(n))**.5%1and\"Not a perfect square!\"or'\\n'.join(map(''.join,zip(*[iter(str(n))]*...
{"fn_name": "square_it", "inputs": [[4547286933343749825161701915681956276108219454705210545289005317346009798484488964285906487], [90189877259570782117221886144647133351119464323162996566552951010740268249057549708185088193991122784476567524182655933233701139127237445845740732409435163234477841573580660927256314688880...
INTRODUCTORY
PYTHON3
CODEWARS
1,779
def square_it(digits):
4a603d99c6eca2f0f10033bed596fadd
UNKNOWN
# Task Given string `s`, which contains only letters from `a to z` in lowercase. A set of alphabet is given by `abcdefghijklmnopqrstuvwxyz`. 2 sets of alphabets mean 2 or more alphabets. Your task is to find the missing letter(s). You may need to output them by the order a-z. It is possible that there is more ...
["from collections import Counter\nfrom string import ascii_lowercase\n\ndef missing_alphabets(s):\n c = Counter(s)\n m = max(c.values())\n return ''.join(letter * (m - c[letter]) for letter in ascii_lowercase)", "from collections import Counter\nfrom string import ascii_lowercase as alphabet\n\ndef missing_al...
{"fn_name": "missing_alphabets", "inputs": [["abcdefghijklmnopqrstuvwxy"], ["abcdefghijklmnopqrstuvwxyz"], ["aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy"], ["abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxy"], ["codewars"]], "outputs": [["z"], [""], ["zz"], ["ayzz"], ["bfghijklmnpqtuvxyz"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,696
def missing_alphabets(s):
4338d733d5b1ea43da6529da82a90cbc
UNKNOWN
A few years ago, Aaron left his old school and registered at another due to security reasons. Now he wishes to find Jane, one of his schoolmates and good friends. There are `n` schools numbered from 1 to `n`. One can travel between each pair of schools by buying a ticket. The ticket between schools `i` and `j` costs `...
["def find_jane(n):\n return (n - 1) // 2", "import math\ndef find_jane(n):\n return math.ceil((n-2)/2)", "def find_jane(n):\n return (n-1) // 2\n \n\"\"\"\n1,2,3,...,n\ncost = (a+b) % (n+1)\n\nbest association is:\n b = n+1-a -> cost=0\n \n 1 2 3 4 5 -> 1 <-> 5\n 2 <-> 4\n\...
{"fn_name": "find_jane", "inputs": [[2], [10]], "outputs": [[0], [4]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,176
def find_jane(n):