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
79d5c9550cb1c41da9caec7bc626715c
UNKNOWN
# Task Given an array of integers, sum consecutive even numbers and consecutive odd numbers. Repeat the process while it can be done and return the length of the final array. # Example For `arr = [2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]` The result should be `6`. ``` [2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9] --> 2+2+6 0+2+0 5+5+7+7 3+3+9 [2, 1, 10, 5, 2, 24, 4, 15 ] --> 2+24+4 [2, 1, 10, 5, 30, 15 ] The length of final array is 6 ``` # Input/Output - `[input]` integer array `arr` A non-empty array, `1 ≤ arr.length ≤ 1000` `0 ≤ arr[i] ≤ 1000` - `[output]` an integer The length of the final array
["from itertools import groupby\n\ndef sum_groups(arr):\n newarr = [sum(j) for i,j in groupby(arr, key = lambda x: x % 2 == 0)]\n return len(newarr) if newarr == arr else sum_groups(newarr)", "def sum_groups(arr):\n lenArr, arr = -1, arr[:]\n while lenArr != len(arr):\n parity, lenArr, next = -1, len(arr), []\n while arr:\n val = arr.pop()\n if parity != val%2:\n next.append(val)\n parity = val%2\n else:\n next[-1] += val\n arr = next\n return len(arr)", "from itertools import groupby\n\n\ndef sum_groups(lst):\n l = -1\n while l != len(lst):\n l, lst = len(lst), [sum(g) for _, g in groupby(lst, key=lambda n: n % 2)]\n return l", "from itertools import groupby\n\ndef sum_groups(arr):\n reduced = [sum(gp) for _, gp in groupby(arr, key = lambda x: x % 2)]\n return len(reduced) if reduced == arr else sum_groups(reduced)", "from itertools import groupby\n\ndef sum_groups(arr):\n while True:\n n = len(arr)\n arr = [sum(grp) for key, grp in groupby(arr, key=lambda x: x % 2)]\n if len(arr) == n:\n return n", "from itertools import groupby\n\n\ndef sum_groups(arr):\n nums = list(arr)\n while True:\n tmp = [sum(g) for _, g in groupby(nums, key=lambda a: a % 2)]\n if nums == tmp:\n return len(nums)\n nums = tmp\n", "from itertools import groupby, dropwhile, tee, islice\n\ndef sum_groups(arr):\n def it(a):\n while 1:\n yield a\n a = [sum(g) for _, g in groupby(a, key=lambda k: k % 2)]\n it1, it2 = tee(it(arr))\n return len(next(dropwhile(lambda x: x[0] != x[1], zip(it1, islice(it2, 1, None))))[1])", "from itertools import groupby\n\ndef sum_groups(arr):\n while True:\n res = [sum(i) for _, i in groupby(arr, lambda x: x & 1)]\n if arr == res: return len(arr)\n arr = res", "import itertools\n\ndef sum_groups(arr):\n prev_len = 1\n while prev_len != len(arr):\n prev_len = len(arr)\n arr = [\n sum(g) for k, g in itertools.groupby(\n arr, key=lambda x: x % 2 == 0\n )\n ]\n return len(arr)\n", "import re\n\n\ndef sum_groups(arr):\n return len(\n re.sub(\"0{2,}\", \"0\",\n re.sub(\"1+\", lambda match: \"1\" if len(match.group(0)) % 2 else \"0\",\n \"\".join(str(elem % 2) for elem in arr))))"]
{"fn_name": "sum_groups", "inputs": [[[2, 1, 2, 2, 6, 5, 0, 2, 0, 5, 5, 7, 7, 4, 3, 3, 9]], [[2, 1, 2, 2, 6, 5, 0, 2, 0, 3, 3, 3, 9, 2]], [[2]], [[1, 2]], [[1, 1, 2, 2]]], "outputs": [[6], [5], [1], [2], [1]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,469
def sum_groups(arr):
38ce6b5d46294db156a2a14994362278
UNKNOWN
In this kata you're expected to sort an array of 32-bit integers in ascending order of the number of **on** bits they have. E.g Given the array **[7, 6, 15, 8]** - 7 has **3 on** bits (000...0**111**) - 6 has **2 on** bits (000...00**11**) - 15 has **4 on** bits (000...**1111**) - 8 has **1 on** bit (000...**1**000) So the array in sorted order would be **[8, 6, 7, 15]**. In cases where two numbers have the same number of bits, compare their real values instead. E.g between 10 **(...1010)** and 12 **(...1100)**, they both have the same number of **on** bits '**2**' but the integer 10 is less than 12 so it comes first in sorted order. Your task is to write the function `sortBybit()` that takes an array of integers and sort them as described above. ```if-not:haskell Note: Your function should modify the input rather than creating a new array. ```
["def sort_by_bit(arr): \n return sorted(arr, key=lambda x: (bin(x).count(\"1\"), x))", "def sort_by_bit(a):\n return sorted(a, key=lambda x: (bin(x).count(\"1\"), x))", "def sort_by_bit(arr): \n return sorted(arr, key=lambda n: (bin(n).count(\"1\"), n))", "def sort_by_bit(lst): \n return sorted(lst, key=lambda n: (f\"{n:b}\".count(\"1\"), n))\n", "def sort_by_bit(a):\n for i in range(len(a)):\n for j in range(i+1, len(a)):\n if bin(a[i]).count('1') > bin(a[j]).count('1'):\n a[i], a[j] = a[j], a[i]\n elif bin(a[i]).count('1') == bin(a[j]).count('1'):\n if a[i] > a[j]:\n a[i], a[j] = a[j], a[i]\n return a", "def sort_by_bit(arr):\n return [val[1] for val in sorted([[\"{0:b}\".format(val).count('1'),val] for val in arr])]", "def sort_by_bit(arr):\n return sorted(arr, key=lambda x: (str('{:032b}'.format(x)).count('1'), x))\n", "def sort_by_bit(arr):\n return sorted(sorted(arr), key=lambda i: bin(i)[2:].count('1'))", "def sort_by_bit(arr): \n return sorted(arr, key=lambda x: (count(x), x))\ndef count(n):\n return bin(n)[2:].count(\"1\")", "def sort_by_bit(x): \n on_bits = [f\"{i:b}\".count(\"1\") for i in x]\n sorted_tups = sorted(zip(on_bits, x))\n return list(list(zip(*sorted_tups))[1])"]
{"fn_name": "sort_by_bit", "inputs": [[[3, 8, 3, 6, 5, 7, 9, 1]], [[9, 4, 5, 3, 5, 7, 2, 56, 8, 2, 6, 8, 0]]], "outputs": [[[1, 8, 3, 3, 5, 6, 9, 7]], [[0, 2, 2, 4, 8, 8, 3, 5, 5, 6, 9, 7, 56]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,295
def sort_by_bit(arr):
c6fc557e02cc1975dd66d59bf6f1e768
UNKNOWN
A palindrome is a series of characters that read the same forwards as backwards such as "hannah", "racecar" and "lol". For this Kata you need to write a function that takes a string of characters and returns the length, as an integer value, of longest alphanumeric palindrome that could be made by combining the characters in any order but using each character only once. The function should not be case sensitive. For example if passed "Hannah" it should return 6 and if passed "aabbcc_yYx_" it should return 9 because one possible palindrome would be "abcyxycba".
["from collections import Counter\n\ndef longest_palindrome(s):\n c = Counter(filter(str.isalnum, s.lower()))\n return sum(v//2*2 for v in c.values()) + any(v%2 for v in c.values())", "from collections import Counter\nimport re\n\ndef longest_palindrome(s):\n n, odds, c = 0, 0, Counter(re.sub(r'\\W+|_', '', s.lower()))\n for v in c.values():\n x,r = divmod(v,2)\n n += 2*x\n odds += r\n return n + bool(odds)", "from collections import Counter\n\ndef longest_palindrome(s):\n freq = Counter(c for c in s.lower() if c.isalnum())\n even, odd = [], []\n for k, v in freq.items():\n if v % 2: odd.append(v-1)\n else: even.append(v)\n return sum(even) + (sum(odd) + 1 if odd else 0)", "def longest_palindrome(s):\n new_s = ''.join([x for x in s.lower() if x.isalnum()])\n k = [new_s.count(x) for x in set(new_s)]\n\n res = 0\n for x in k:\n if x%2==0:res += x\n else:res += (x-1)\n \n return res+1 if any(x%2==1 for x in k) else res\n", "from collections import Counter\ndef longest_palindrome(s):\n if s == \"\":\n return 0\n s = s.upper()\n x = Counter(s)\n len = 0\n flag = False\n for i in x:\n if i.isalnum():\n if x[i] % 2 == 0:\n len+=x[i]\n else:\n flag=True\n len+= (x[i]-1)\n if flag == True:\n return len+1\n return len", "from collections import Counter\nfrom string import ascii_letters, digits\n\ndef longest_palindrome(data):\n cnt = Counter([d for d in data.lower() if d in ascii_letters + digits])\n even = sum([n for n in list(cnt.values()) if n % 2 == 0 ]) \n odd = sorted( [n for n in list(cnt.values()) if n % 2 != 0] )[::-1]\n if len(odd) == 0:\n ans = even\n if len(odd) == 1:\n ans = even + odd[0]\n if len(odd) > 1:\n ans = even + odd[0] + sum([n-1 for n in odd[1:]])\n\n return ans\n\n \n", "from collections import Counter\n\ndef longest_palindrome(string):\n possibles, has_odd = 0, False\n for char, c in Counter(string.lower()).items():\n if not char.isalnum():\n continue\n if c & 1:\n possibles += (c - 1)\n has_odd = True\n else:\n possibles += c\n return possibles + (1 if has_odd else 0)", "from collections import Counter\n\ndef longest_palindrome(s):\n d, r = Counter([x for x in s.lower() if x.isalnum()]), 0\n for x in d.values():\n r += x // 2 * 2 + (x % 2 >> r % 2)\n return r", "from collections import Counter\n\ndef longest_palindrome(s):\n flag = res = 0\n for v in Counter(map(str.lower, filter(str.isalnum, s))).values():\n flag |= v&1\n res += v>>1<<1 # This is just for fun, don't write that\n return res + flag", "import re\n\ndef longest_palindrome(s):\n s = list(re.sub('[\\W_]+', '', s.lower()))\n solution = 0\n j = 0\n letter_count = 0\n for letter in s:\n letter_count = s.count(letter)\n if letter_count % 2 == 0:\n solution += letter_count\n else:\n solution += letter_count - 1\n j = 1\n s = [i for i in s if i != letter]\n return solution + j"]
{"fn_name": "longest_palindrome", "inputs": [["A"], ["Hannah"], ["xyz__a_/b0110//a_zyx"], ["$aaabbbccddd_!jJpqlQx_.///yYabababhii_"], [""]], "outputs": [[1], [6], [13], [25], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,243
def longest_palindrome(s):
0f30985584ac39ea4bf25a8e15ffb656
UNKNOWN
Write a function ```python vowel_2_index``` that takes in a string and replaces all the vowels [a,e,i,o,u] with their respective positions within that string. E.g: ```python vowel_2_index('this is my string') == 'th3s 6s my str15ng' vowel_2_index('Codewars is the best site in the world') == 'C2d4w6rs 10s th15 b18st s23t25 27n th32 w35rld' vowel_2_index('') == '' ``` Your function should be case insensitive to the vowels.
["def vowel_2_index(string):\n vowels = 'aeiouAEIOU'\n return ''.join(x if x not in vowels else str(n + 1) for n,x in enumerate(string))", "import re\n\ndef vowel_2_index(string):\n return re.sub(\"[aeiou]\",lambda m:str(m.end()),string,0,re.I)", "def vowel_2_index(string):\n vowels = frozenset('aeiouAEIOU')\n return ''.join([str(i+1) if c in vowels else c for i, c in enumerate(string)])", "def vowel_2_index(string):\n return ''.join([str(i + 1) if x.lower() in 'aeiou' else x for i, x in enumerate(string)])", "vowel_2_index=lambda s:''.join(str(i)if e in'aiueoAIUEO' else e for i,e in enumerate(s,1))", "def vowel_2_index(string):\n vowels = 'aeiouAEIOU'\n return ''.join(str(i) if v in vowels else v for i,v in enumerate(string, 1))", "def vowel_2_index(s):\n return \"\".join(str(i + 1) if s[i].lower() in \"aeuoi\" else s[i] for i in range(len(s))) ", "def vowel_2_index(string):\n return ''.join([str(c+1) if l.lower() in 'aeiou' else l for c, l in enumerate(string)])", "def vowel_2_index(string):\n return ''.join(c if c not in 'aeiouAEIOU' else str(i+1) for i,c in enumerate(string))", "import re\n\ndef vowel_2_index(string):\n return re.sub(r'[aeiou]', lambda m: str(m.start(0) + 1), string, flags=re.IGNORECASE)", "def vowel_2_index(string):\n return ''.join(str(i) if c in 'aeiouAEIOU' else c for i, c in enumerate(string, 1))", "def vowel_2_index(string):\n return ''.join( [str(i+1) if string[i].lower() in \"aeiou\" else string[i] for i in range(len(string))])", "vowel_2_index=lambda s: ''.join([str(i+1) if x.lower() in \"aeiou\" else x for i,x in enumerate(s)])\n", "import re\n\ndef vowel_2_index(string):\n return re.sub(\n re.compile('[euioa]', re.I),\n lambda match: str(match.start() + 1),\n string\n )", "def vowel_2_index(string):\n ret = \"\"\n for i in range(len(string)):\n if string[i] in \"aeiouAEIOU\":\n ret=ret+str(i+1)\n else:\n ret=ret+string[i]\n return ret\n", "VOWELS = {'a', 'A', 'e', 'E', 'i', 'I', 'o', 'O', 'u', 'U'}\n\n\ndef vowel_2_index(string):\n return ''.join(str(i) if a in VOWELS else a\n for i, a in enumerate(string, start=1))\n", "import re\ndef vowel_2_index(string):\n pattern = re.compile(r'([aeiouAEIOU])')\n for i in re.finditer(pattern, string):\n s = str(i.start() + 1)\n string = string.replace(i.group(), s, 1)\n return string\n\n", "def vowel_2_index(str_to_switch):\n result = \"\"\n vowels = \"aeiouAEIOU\"\n for index, ch in enumerate(str_to_switch):\n if ch in vowels:\n result += str(index+1)\n else:\n result += ch\n return result", "def vowel_2_index(s):\n vowels = 'aeiouAEIOU'\n returnStr = ''\n for i in range(len(s)):\n if s[i] in vowels:\n returnStr+=str(i+1)\n else:\n returnStr += s[i]\n return returnStr", "def vowel_2_index(string):\n vowels = \"aAeEiIoOuU\"\n \n r = []\n for i, item in enumerate(string, 1):\n if item not in vowels:\n r.append(item)\n else:\n r.append(str(i))\n \n return \"\".join(r)"]
{"fn_name": "vowel_2_index", "inputs": [["this is my string"], ["Codewars is the best site in the world"], ["Tomorrow is going to be raining"], [""], ["90's cornhole Austin, pickled butcher yr messenger bag gastropub next level leggings listicle meditation try-hard Vice. Taxidermy gastropub gentrify, meh fap organic ennui fingerstache pickled vegan. Seitan sustainable PBR&B cornhole VHS. Jean shorts actually bitters ugh blog Intelligentsia. Artisan Kickstarter DIY, fixie cliche salvia lo-fi four loko. PBR&B Odd Future ugh fingerstache cray Wes Anderson chia typewriter iPhone bespoke four loko, Intelligentsia photo booth direct trade. Aesthetic Tumblr Portland XOXO squid, synth viral listicle skateboard four dollar toast cornhole Blue Bottle semiotics."]], "outputs": [["th3s 6s my str15ng"], ["C2d4w6rs 10s th15 b18st s23t25 27n th32 w35rld"], ["T2m4rr7w 10s g1415ng t20 b23 r2627n29ng"], [""], ["90's c7rnh11l13 1516st19n, p24ckl28d b32tch36r yr m43ss46ng49r b53g g57str61p63b n67xt l72v74l l78gg81ngs l87st90cl93 m96d98t100t102103n try-h111rd V116c118. T122x124d126rmy g132str136p138b g142ntr146fy, m152h f156p 159rg162n164c 167nn170171 f174ng177rst181ch184 p187ckl191d v195g197n. S202203t205n s209st212213n215bl218 PBR&B c227rnh231l233 VHS. J241242n sh247rts 252ct255256lly b262tt265rs 269gh bl275g 278nt281ll284g286nts290291. 294rt297s299n K303ckst308rt311r D315Y, f320x322323 cl327ch330 s333lv336337 l340-f343 f346347r l351k353. PBR&B 362dd F367t369r371 373gh f378ng381rst385ch388 cr392y W396s 399nd402rs405n ch410411 typ416wr419t421r 424Ph427n429 b432sp435k437 f440441r l445k447, 450nt453ll456g458nts462463 ph467t469 b472473th d478r480ct tr486d488. 491492sth496t498c T502mblr P509rtl513nd X518X520 sq524525d, synth v536r538l l542st545cl548 sk552t554b556557rd f562563r d567ll570r t574575st c580rnh584l586 Bl590591 B594ttl598 s601m603604t606cs."]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,201
def vowel_2_index(string):
21701f3f384ccbbb4ab6321829b4846d
UNKNOWN
You have managed to intercept an important message and you are trying to read it. You realise that the message has been encoded and can be decoded by switching each letter with a corresponding letter. You also notice that each letter is paired with the letter that it coincides with when the alphabet is reversed. For example: "a" is encoded with "z", "b" with "y", "c" with "x", etc You read the first sentence: ``` "r slkv mlylwb wvxlwvh gsrh nvhhztv" ``` After a few minutes you manage to decode it: ``` "i hope nobody decodes this message" ``` Create a function that will instantly decode any of these messages You can assume no punctuation or capitals, only lower case letters, but remember spaces!
["from string import ascii_lowercase as alphabet\n\n\ndef decode(message):\n return message.translate(str.maketrans(alphabet, alphabet[::-1]))", "def decode(message):\n return message.translate(str.maketrans('abcdefghijklmnopqrstuvwxyz','zyxwvutsrqponmlkjihgfedcba'))", "def decode(message):\n return ''.join([chr(ord('z')-(ord(x)-ord('a'))) if x!=' ' else ' ' for x in list(message)])", "def decode(m):\n return m.translate({k: v for k, v in zip(range(97, 123), range(122, 96, -1))})", "def decode(message):\n output = ''\n for letter in message:\n if letter != \" \":\n output += chr(ord(\"z\") - (ord(letter) - ord(\"a\")))\n else:\n output += letter\n return output\n", "from string import ascii_lowercase as abc\n\ndef decode(message):\n cipher_map = dict(zip(list(abc[::-1]), list(abc)))\n \n return ''.join([cipher_map[c] if c in cipher_map else c for c in message])", "from string import ascii_lowercase as alphabet\n\ndef decode(message):\n dictionary = str.maketrans(alphabet, alphabet[::-1])\n return message.translate(dictionary)", "def decode(message):\n import string\n ltrs = dict(list(zip(string.ascii_lowercase, string.ascii_lowercase[::-1])))\n return ''.join(ltrs.get(c, ' ') for c in message)\n", "decode=lambda s:''.join(chr(219-ord(c)-155*(c<'a'))for c in s)", "def decode(message):\n res=\"\"\n c=0\n for i in range(0, len(message)):\n if message[i]==\"a\":\n res+=\"z\"\n elif message[i]==\"z\":\n res+=\"a\"\n elif message[i]==\"b\":\n res+=\"y\"\n elif message[i]==\"y\":\n res+=\"b\"\n elif message[i]==\"c\":\n res+=\"x\"\n elif message[i]==\"x\":\n res+=\"c\"\n elif message[i]==\"d\":\n res+=\"w\"\n elif message[i]==\"w\":\n res+=\"d\"\n elif message[i]==\"e\":\n res+=\"v\"\n elif message[i]==\"v\":\n res+=\"e\"\n elif message[i]==\"f\":\n res+=\"u\"\n elif message[i]==\"u\":\n res+=\"f\"\n elif message[i]==\"g\":\n res+=\"t\"\n elif message[i]==\"t\":\n res+=\"g\"\n elif message[i]==\"h\":\n res+=\"s\"\n elif message[i]==\"s\":\n res+=\"h\"\n elif message[i]==\"i\":\n res+=\"r\"\n elif message[i]==\"r\":\n res+=\"i\"\n elif message[i]==\"j\":\n res+=\"q\"\n elif message[i]==\"q\":\n res+=\"j\"\n elif message[i]==\"k\":\n res+=\"p\"\n elif message[i]==\"p\":\n res+=\"k\"\n elif message[i]==\"l\":\n res+=\"o\"\n elif message[i]==\"o\":\n res+=\"l\"\n elif message[i]==\"m\":\n res+=\"n\"\n elif message[i]==\"n\":\n res+=\"m\"\n else:\n res+=\" \"\n return res"]
{"fn_name": "decode", "inputs": [["sr"], ["svool"], ["r slkv mlylwb wvxlwvh gsrh nvhhztv"], ["qzezxirkg rh z srts ovevo wbmznrx fmgbkvw zmw rmgvikivgvw kiltiznnrmt ozmtfztv rg szh yvvm hgzmwziwravw rm gsv vxnzxirkg ozmtfztv hkvxrurxzgrlm zolmthrwv sgno zmw xhh rg rh lmv lu gsv gsivv vhhvmgrzo gvxsmloltrvh lu dliow drwv dvy xlmgvmg kilwfxgrlm gsv nzqlirgb lu dvyhrgvh vnkolb rg zmw rg rh hfkkligvw yb zoo nlwvim dvy yildhvih drgslfg koftrmh"], ["gsv vrtsgs hbnkslmb dzh qvzm hryvorfh urmzo nzqli xlnklhrgrlmzo kilqvxg lxxfkbrmt srn rmgvinrggvmgob"], ["husbands ask repeated resolved but laughter debating"], ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"], [" "], [""], ["thelastrandomsentence"]], "outputs": [["hi"], ["hello"], ["i hope nobody decodes this message"], ["javacript is a high level dynamic untyped and interpreted programming language it has been standardized in the ecmacript language specification alongside html and css it is one of the three essential technologies of world wide web content production the majority of websites employ it and it is supported by all modern web browsers without plugins"], ["the eighth symphony was jean sibelius final major compositional project occupying him intermittently"], ["sfhyzmwh zhp ivkvzgvw ivhloevw yfg ozftsgvi wvyzgrmt"], ["zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"], [" "], [""], ["gsvozhgizmwlnhvmgvmxv"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,983
def decode(message):
545536ee5498cd4d231fb6649344f89f
UNKNOWN
Jump is a simple one-player game: You are initially at the first cell of an array of cells containing non-negative integers; At each step you can jump ahead in the array as far as the integer at the current cell, or any smaller number of cells. You win if there is a path that allows you to jump from one cell to another, eventually jumping past the end of the array, otherwise you lose. For instance, if the array contains the integers `[2, 0, 3, 5, 0, 0, 3, 0, 0, 3, 1, 0]`, you can win by jumping from **2**, to **3**, to **5**, to **3**, to **3**, then past the end of the array. You can also directly jump from from the initial cell(first cell) past the end of the array if they are integers to the right of that cell. E.g `[6, 1, 1]` is winnable `[6]` is **not** winnable Note: You can **not** jump from the last cell! `[1, 1, 3]` is **not** winnable ## ----- Your task is to complete the function `canJump()` that determines if a given game is winnable. ### More Examples ``` javascript canJump([5]) //=> false canJump([2, 5]) //=> true canJump([3, 0, 2, 3]) //=> true (3 to 2 then past end of array) canJump([4, 1, 2, 0, 1]) //=> false canJump([5, 0, 0, 0]) //=> true canJump([1, 1]) //=> false ```
["def can_jump(arr):\n if arr[0] == 0 or len(arr) == 1:\n return False\n \n if arr[0] >= len(arr):\n return True\n \n for jump in range(1, arr[0] +1):\n if can_jump(arr[jump:]):\n return True\n \n return False\n", "def can_jump(arr):\n last = len(arr)\n for i in reversed(range(len(arr)-1)):\n if arr[i] >= last-i: last = i\n return not last", "from functools import lru_cache\n\ndef can_jump(arr):\n @lru_cache(maxsize=None)\n def rec(i):\n if i >= len(arr)-1: return i >= len(arr)\n return any(rec(i+j) for j in range(1, arr[i]+1))\n return rec(0)", "def can_jump(arr):\n length = len(arr)\n i = length - 2\n while i >= 0:\n if arr[i] + i >= length:\n length = i\n i-=1\n return length == 0", "def can_jump(lst):\n l = len(lst)\n for i in range(l - 2, -1, -1):\n if lst[i] >= l - i:\n l = i\n return l == 0", "def can_jump(arr):\n x = len(arr)-1; p = []; i = 0; j = arr[i]; n = i+j\n if not x or not(arr[0]): return False\n while True:\n if x<n: return True\n while j and (n==x or not arr[n]): j -= 1; n = i+j\n if not j:\n if not p: return False\n j = p.pop(); i -= j; j -= 1; continue\n p.append(j); i += j; j = arr[i]; n = i+j\n", "def can_jump(arr, i=0):\n return i >= len(arr) or (\n i < len(arr) - 1\n and arr[i]\n and any(can_jump(arr, i + j) for j in range(1, arr[i] + 1))\n )", "def can_jump(arr):\n if len(arr) <= 1 or arr[0] == 0:\n return False\n if arr[0] >= len(arr):\n return True\n return any(can_jump(arr[i+1:]) for i in range(arr[0]))\n", "def can_jump(lst):\n p, l = lst[0], len(lst)\n if l == 1:\n return False\n if p >= l:\n return True\n for i in range(1, p+1):\n if lst[i] and can_jump(lst[i:]):\n return True\n return False", "def can_jump(A):\n z=len(A)\n for i in range(z-1)[::-1]:z=(z,i)[z<=i+A[i]]\n return z==0"]
{"fn_name": "can_jump", "inputs": [[[11, 6, 11, 0, 2, 1, 14, 3, 7, 6, 2, 1, 10, 6, 0, 0, 8, 10, 2, 12, 13, 11, 14, 6, 1, 4, 14, 3, 10, 4, 14, 2, 3, 10, 8, 13, 14, 8, 2, 13, 11, 14, 0, 1, 6, 2, 1, 6, 8, 2, 0, 12, 4, 9, 2, 6, 8, 14, 4, 14, 4, 10, 8, 7, 12, 11, 0, 3, 8, 0, 13, 9, 9, 11, 10, 13, 12, 1, 0, 10, 14, 6, 1, 11, 7, 8, 6, 2, 1, 3, 1, 1, 0, 3, 5, 11, 13, 8, 4, 9, 9, 7, 6, 2, 10, 13, 6, 12, 10, 2, 0, 3, 14, 6, 6, 7, 13, 12, 11, 5, 2, 0, 12, 2, 11, 8]], [[2, 0, 1, 5, 0, 0, 3, 0, 0, 3, 1, 0]], [[5]], [[2, 5]], [[5, 0, 0, 0]], [[1, 1]], [[3, 0, 2, 3]], [[4, 1, 2, 0, 1]]], "outputs": [[true], [true], [false], [true], [true], [false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,056
def can_jump(arr):
36c76937fb2a12cd28cd9a9dc1068f18
UNKNOWN
Your task is to calculate logical value of boolean array. Test arrays are one-dimensional and their size is in the range 1-50. Links referring to logical operations: [AND](https://en.wikipedia.org/wiki/Logical_conjunction), [OR](https://en.wikipedia.org/wiki/Logical_disjunction) and [XOR](https://en.wikipedia.org/wiki/Exclusive_or). You should begin at the first value, and repeatedly apply the logical operation across the remaining elements in the array sequentially. First Example: Input: true, true, false, operator: AND Steps: true AND true -> true, true AND false -> false Output: false Second Example: Input: true, true, false, operator: OR Steps: true OR true -> true, true OR false -> true Output: true Third Example: Input: true, true, false, operator: XOR Steps: true XOR true -> false, false XOR false -> false Output: false ___ Input: boolean array, string with operator' s name: 'AND', 'OR', 'XOR'. Output: calculated boolean
["import operator\nfrom functools import reduce\n\nOPS = {\n \"AND\": operator.and_,\n \"OR\" : operator.or_,\n \"XOR\": operator.xor\n}\n\ndef logical_calc(array, op):\n return reduce(OPS[op], array)\n", "from operator import and_, or_, xor\nfrom functools import reduce\n\nOPERATOR = {'AND': and_, 'OR': or_, 'XOR': xor}\n\n\ndef logical_calc(array, op):\n return reduce(OPERATOR[op], array)\n", "def logical_calc(array, op):\n ops = {\n \"AND\" : lambda x,y: x & y,\n \"OR\" : lambda x,y: x | y,\n \"XOR\" : lambda x,y: x ^ y\n }\n \n from functools import reduce\n return reduce(ops[op], array)", "def logical_calc(array, op):\n res = array[0]\n for x in array[1:]:\n if op == \"AND\":\n res &= x\n elif op == \"OR\":\n res |= x\n else:\n res ^= x\n \n return res #boolean", "def logical_calc(array, op):\n s = ' ' + op.lower().replace('xor', '^') + ' '\n return eval(s.join(str(x) for x in array))", "from functools import reduce\n\ndef logical_calc(array, op):\n return reduce(lambda x,y: {'OR': x or y, 'AND': x and y, 'XOR': x ^ y}[op], array)", "def logical_calc(array, op):\n res = array[0]\n for i in array[1:]:\n if op == 'AND':\n res = res and i\n elif op == 'OR':\n res = res or i\n elif op == 'XOR':\n res = res != i\n return res", "def logical_calc(array, op):\n result = False\n if len(array) == 1: return array[0]\n \n if op == \"AND\": result = array[0] and array[1]\n if op == \"OR\": result = array[0] or array[1]\n if op == \"XOR\": result = array[0] ^ array[1]\n \n for n in range(2,len(array)):\n if op == \"AND\":\n result = result and array[n]\n if op == \"OR\":\n result = result or array[n]\n if op == \"XOR\":\n result = result ^ array[n]\n \n return result", "from operator import and_, or_, xor\nfrom functools import reduce\n\ndef logical_calc(array, op_str):\n op = {\"AND\": and_, \"OR\": or_, \"XOR\": xor}[op_str]\n return reduce(op, array)", "def logical_calc(array, op): \n return {'AND':all(array), 'OR':any(array)}.get(op) if op!='XOR'else __import__('functools').reduce(lambda x,y: x^y, array)", "def logical_calc(arr, op):\n return eval((\" ^ \" if op == \"XOR\" else \" \" + op.lower() + \" \").join(str(x) for x in arr))", "from functools import reduce\ndef logical_calc(array, op):\n if op == 'AND':\n return reduce((lambda x, y: x and y), array)\n elif op == 'OR':\n return reduce((lambda x, y: x or y), array)\n else:\n return reduce((lambda x, y: x ^ y), array)\n#This one fucked my mind for two days & here i got then! :p\n#Completed by Ammar on 1/8/2019 at 09:51PM.\n", "ops = {'AND': '&', 'OR': '|', 'XOR': '^'}\ndef logical_calc(array, op):\n return bool(eval(ops[op].join([str(int(i)) for i in array])))", "from operator import and_, xor, or_\nfrom functools import reduce\n\n\ndef logical_calc(array, op):\n operations = {\"AND\": and_, \"OR\": or_, \"XOR\": xor}\n\n return reduce(operations[op], array)\n", "from operator import and_, or_, xor\nfrom functools import reduce\n\nlogical_calc = lambda xs, op: reduce({ 'AND': and_, 'OR': or_, 'XOR': xor }.get(op), xs)", "import operator\nfrom functools import reduce\n\ndef logical_calc(array, op):\n op = '__{}__'.format(op.lower())\n op = getattr(operator, op)\n return reduce(op, array)\n", "from functools import reduce\n\ndef logical_calc(array, op):\n if op == 'AND':\n return reduce(lambda x, y: x and y, array)\n elif op == 'OR':\n return reduce(lambda x, y: x or y, array)\n elif op == 'XOR':\n return reduce(lambda x, y: x != y, array)", "def logical_calc(array, op):\n return eval({ 'AND': '&', 'OR': '|', 'XOR': '^' }[op].join(map(str, array)))", "from functools import reduce\nfrom operator import ixor\nfrom typing import List\n\ndef logical_calc(array: List[bool], op: str) -> bool:\n \"\"\" Calculate logical value of boolean array. \"\"\"\n return {\n \"AND\": lambda: all(array),\n \"OR\": lambda: any(array),\n \"XOR\": lambda: reduce(ixor, array)\n }.get(op)()", "def logical_calc(array, op):\n out=array.pop(0)\n for x in array: out={'AND':x&out, 'OR':x|out, 'XOR': x^out}[op]\n return out", "def logical_calc(array, op):\n return {'AND': all, 'OR': any, 'XOR': lambda a: sum(a) % 2}[op](array)", "def logical_calc(array, op):\n if op == 'AND':\n for item in array:\n if item is False: return False\n return True\n \n elif op == 'OR':\n for item in array:\n if item is True: return True\n return False\n \n else:\n a = len([a for a in array if a is True])\n if a%2!=0 and a > 0:\n return True\n return False", "from functools import reduce; logical_calc=lambda array, op: reduce(lambda a,b: a and b if op==\"AND\" else a or b if op==\"OR\" else a!=b, array)", "def logical_calc(array, op):\n if op=='AND': return all(array)\n elif op=='OR': return any(array)\n else: return sum(array)%2==1", "def logical_calc(array, op):\n if op == 'AND': return False not in array\n if op == 'OR': return True in array\n \n result = array[0]\n \n for index in range(1, len(array)):\n result ^= array[index]\n \n return result", "def logical_calc(arr, op):\n return all(arr) if op == 'AND' else any(arr) if op == 'OR' else arr.count(True) % 2", "def logical_calc(array, op):\n #dictionary\n \n return eval({'AND':'&','OR':'|'}.get(op,'^').join(str(i) for i in array))\n \n #string\n #return eval((op.lower() if op!='XOR' else '^').join(' '+str(i)+' ' for i in array))\n", "def logical_calc(array, op):\n # convert bool array values to str and join them with the specified operator\n # return the results using eval() on the resulting string\n return eval({'AND': '&', 'OR': '|', 'XOR': '^'}[op].join(map(str, array)))", "import functools\n\ndef logical_calc(array, op):\n return {\"AND\": all, \"OR\":any, \"XOR\":xor}[op](array)\n \ndef xor(array):\n return functools.reduce(lambda x, y: x != y, array)", "def logical_calc(array, op):\n if op == \"AND\":\n return all(boolian for boolian in array)\n elif op == \"OR\":\n return any(boolian for boolian in array)\n else:\n return sum(array) % 2", "def logical_calc(array, op):\n if op == 'AND':\n return all(array)\n elif op == 'OR':\n return any(array)\n else:\n return array.count(True) % 2", "def logical_calc(array, op):\n ans = array[0]\n for i in array[1:]:\n if op == \"AND\":\n ans = ans & i\n elif op == \"OR\":\n ans = ans | i\n else :\n ans = ans ^ i\n return ans", "def logical_calc(array, op):\n ans=array[0]\n for operator in array[1:]:\n \n if op==\"AND\": ans=ans and operator\n elif op==\"OR\": ans=ans or operator\n else: ans=ans ^ operator\n return ans\n \n# return #boolean\n", "def logical_calc(arr, op):\n\n answer = arr[0]\n\n if op == \"AND\":\n for i in range(len(arr)-1):\n answer &= arr[i+1]\n\n if op == \"OR\":\n for i in range(len(arr)-1):\n answer |= arr[i+1]\n\n if op == \"XOR\":\n for i in range(len(arr)-1):\n answer ^= arr[i+1]\n \n return answer", "def logical_calc(arr, op):\n \n answer = arr[0]\n \n if len(arr)>=2:\n\n if op == \"AND\":\n for i in range(len(arr)-1):\n answer &= arr[i+1]\n\n if op == \"OR\":\n for i in range(len(arr)-1):\n answer |= arr[i+1]\n\n if op == \"XOR\":\n for i in range(len(arr)-1):\n answer ^= arr[i+1]\n\n return answer", "def logical_calc(array, op):\n curr = array[0]\n for x in range(1, len(array)):\n if op == \"AND\":\n curr = array[x] and curr\n if op == \"OR\":\n curr = array[x] or curr\n if op == \"XOR\":\n curr = (array[x] and not curr) or (not array[x] and curr)\n return curr", "from functools import reduce\nlogical_calc = lambda l,op:reduce(lambda a,b:a and b if op == 'AND' else a or b if op == 'OR' else a != b,l)", "def logical_calc(array, op):\n start=array[0]\n for i in range(1,len(array)):\n if op==\"AND\":\n start=start and array[i]\n elif op==\"OR\":\n start=start or array[i]\n elif op==\"XOR\":\n if start==array[i]:\n start=False \n else:\n start=True\n return start", "def logical_calc(array, op):\n if op == 'AND':\n return not False in array\n elif op == 'OR':\n return True in array\n elif op == 'XOR':\n return (array.count(True) % 2) != 0", "def logical_calc(array, op):\n ops = {'XOR': ' ^ ',\n 'AND' : ' and ',\n 'OR' : ' or '}\n \n return eval(ops[op].join([str(v) for v in array]))\n", "from functools import reduce\n\ndef logical_calc(array, op):\n return all(array) if op == 'AND' else any(array) if op == 'OR' else reduce(lambda x,y: x != y, array)", "def logical_calc(array, op):\n state = None\n operation = None\n\n if op == \"AND\":\n for i in range(len(array)):\n state = array[i] if i == 0 else state and array[i]\n elif op == \"OR\":\n for i in range(len(array)):\n state = array[i] if i == 0 else state or array[i]\n elif op == \"XOR\":\n for i in range(len(array)):\n state = array[i] if i == 0 else state ^ array[i]\n else:\n return f\"input - {op} - not recognized\"\n \n return state", "\n\ndef logical_calc(array, op):\n print(array)\n print(op)\n print(len(array))\n count_True = 0\n count_False = 0\n for line in array:\n if line == True:\n count_True += 1\n else: count_False += 1\n print(count_False)\n print(count_True)\n if op == 'AND':\n if count_True == len(array):\n return True\n else: return False\n elif op == 'OR':\n if count_False == len(array):\n return False\n else: return True\n elif op == 'XOR':\n if count_True % 2 == 0:\n return False\n else: return True", "import operator\nfrom functools import reduce\n\ndef logical_calc(array, op):\n return reduce(getattr(operator, '__{}__'.format(op.lower())), array) ", "def logical_calc(array, op):\n if len(array)==1:\n return array[0]\n else:\n if op.lower()=='and':\n s=array[0] & array[1]\n for i in range(2,len(array)):\n s=s & array[i]\n return s\n elif op.lower()=='or':\n s=array[0] | array[1]\n for i in range(2,len(array)):\n s=s | array[i]\n return s\n if op.lower()=='xor':\n s=array[0] ^ array[1]\n for i in range(2,len(array)):\n s=s ^ array[i]\n return s", "logical_calc=lambda a,o:__import__('functools').reduce({'AND':lambda a,b:a&b,'OR':lambda a,b:a|b,'XOR':lambda a,b:a^b}[o],a,o=='AND')", "def logical_calc(array, op):\n bool = array[0]\n for x in range(1, len(array)):\n if op == 'AND':\n bool = array[x] & bool\n if op == 'OR':\n bool = array[x] | bool\n if op == 'XOR':\n bool = array[x] ^ bool\n return bool", "from functools import reduce\n\ndef logical_calc(array, op):\n operators = {\n 'AND': all(array),\n 'OR': any(array),\n 'XOR': reduce(lambda x, y: x ^ y, array)\n }\n return operators[op]", "dict = {\n True: 1,\n False: 2\n}\n\n\ndef logical_calc(array, op):\n print(array, op)\n arrn = []\n length = len(array)\n for x in array:\n arrn.append(dict[x])\n if op == \"XOR\":\n if sum(arrn) == 1:\n return True\n elif sum(arrn) == 2:\n return False\n else:\n i = 0\n x = array[0]\n while i < len(array) - 1:\n x = x == array[i + 1]\n i += 1\n if x:\n return False\n else:\n return True\n elif sum(arrn) == length and op == \"AND\":\n return True\n elif array.count(False) == length:\n return False\n elif (sum(arrn) != length or sum(arrn) != length * 2) and op == \"OR\":\n return True\n else:\n return False", "def logical_calc(array, op):\n print(array, op)\n if(op == \"AND\"):\n if(array.count(False)):\n return False\n elif(op == \"OR\"):\n if(array.count(True) == 0):\n return False\n else:\n if(array.count(True) % 2 == 0):\n return False\n return True", "import distutils\n\ndef quick_op(op, old, new):\n if op == \"AND\":\n return old and new\n elif op == \"OR\":\n return old or new\n elif op == \"XOR\":\n return old ^ new\n\ndef logical_calc(array, op):\n latest_operation = array[0]\n array.pop(0)\n for item in array:\n latest_operation = quick_op(op, latest_operation, item)\n return latest_operation", "def logical_calc(array, op):\n if op == 'XOR':\n result = array[0]\n for element in array[1:]:\n if element == result:\n result = False\n else:\n result = True\n return result\n return all(array) if op =='AND' else any(array)", "from functools import reduce\n\ndef logical_calc(array, op):\n oper = op.lower() if op != \"XOR\" else '^'\n return reduce(lambda x, y: eval(f'{x} {oper} {y}'), array)", "def logical_calc(array, op):\n if op == 'AND':\n return array.count(False) == 0\n elif op == 'OR':\n return array.count(True) != 0\n else:\n return array.count(True) % 2 == 1", "from operator import __and__, __or__, __xor__ \n\noperators = {\n 'AND': __and__,\n 'OR': __or__,\n 'XOR': __xor__\n}\n\ndef logical_calc(arr, op):\n acc = arr[0]\n \n for item in arr[1:]:\n acc = operators[op](acc, item)\n \n return acc", "from operator import and_\nfrom operator import or_\nfrom operator import xor\nfrom functools import reduce\n\ndef logical_calc(array, op):\n if op == \"XOR\":\n return reduce(xor, array)\n elif op == \"AND\":\n return reduce(and_, array)\n elif op == \"OR\":\n return reduce(or_, array)", "def logical_calc(array, op):\n bool = array[0] == True\n for i in range(1, len(array)):\n if op == \"AND\":\n bool = bool & array[i]\n elif op == \"OR\":\n bool = bool | array[i]\n elif op == \"XOR\":\n bool = bool ^ array[i]\n return bool == True", "def logical_calc(array, op):\n if op == 'AND':\n for bool in array:\n if bool == False:\n return False\n return True\n elif op == 'OR':\n for bool in array:\n if bool == True:\n return True\n return False\n else:\n aux = array[0]\n i = 1\n while i < len(array):\n if aux != array[i]:\n aux = True\n else:\n aux = False\n i+=1\n return aux", "def logical_calc(array, op):\n return eval(' {} '.format({\"AND\": 'and', \"OR\": 'or'}.get(op, '^')).join(str(x) for x in array))", "def logical_calc(array, op):\n val = array.pop()\n for i in array:\n if op == 'AND':\n if not i:\n return False\n elif op == 'OR':\n if i:\n return True\n else:\n val ^= i;\n return val", "def logical_calc(array, op):\n print(array, op)\n if op=='AND':\n return False not in array\n if op=='OR':\n return True in array or (True in array and False in array)\n if op=='XOR':\n return array.count(True)%2!=0 or (True in array and array.count(False)%2!=0)", "def logical_calc(array, op):\n if op == 'XOR':\n op = '^'\n op = op.lower()\n array = [str(i) for i in array]\n arr2 = []\n for i in range(len(array)):\n arr2.append(array[i])\n arr2.append(op)\n arr2 = arr2[0:-1]\n \n return eval(' '.join(arr2))\n\n", "import functools\ndef logical_calc(array, op):\n if op == \"AND\":\n return functools.reduce(lambda prev, curr: prev and curr, array)\n if op == \"OR\":\n return functools.reduce(lambda prev, curr: prev or curr, array)\n if op == \"XOR\":\n return functools.reduce(lambda prev, curr: prev ^ curr, array)", "def logical_calc(array, op):\n \n if False in array and op == \"AND\":\n return False\n elif op == \"AND\":\n return True\n elif True in array and op == \"OR\":\n return True\n elif op == \"OR\":\n return False\n elif int(array.count(True)) % 2 == 0 and int(array.count(False)) % 2 == 0 and op == 'XOR':\n return False\n elif int(array.count(True)) % 2 == 1 and op == 'XOR':\n return True\n elif int(array.count(False)) % 2 == 1 and int(array.count(True)) % 2 == 1 and op == 'XOR':\n return False\n elif int(array.count(False)) % 2 == 1 and op == 'XOR':\n return False\n \n", "from functools import reduce\n\ndef logical_calc(array, op):\n if op == 'AND':\n value = reduce((lambda x, y: x and y), array) \n elif op == 'OR':\n value = reduce((lambda x, y: x or y), array) \n else:\n value = reduce((lambda x, y: x ^ y), array) \n \n return value", "def logical_calc(array, op):\n log = array[0]\n for i in array[1:51]:\n if op == \"AND\":\n log = log and i\n elif op == \"OR\":\n log = log or i\n else:\n log = log ^ i\n return log\n", "def logical_calc(array, op):\n if op == \"AND\":\n return False not in array \n elif op == \"OR\":\n return True in array\n elif op == \"XOR\":\n s1=sum(array)\n if s1%2 == 0:\n return False\n else:\n return True\n", "def logical_calc(array, op):\n bool = array[0]\n if op == \"AND\":\n for n in range(len(array) - 1):\n bool = bool and array[n + 1]\n elif op == \"OR\":\n for n in range(len(array) - 1):\n bool = bool or array[n + 1]\n elif op == \"XOR\":\n for n in range(len(array) - 1):\n bool = (bool or array[n + 1]) and not (bool and array[n + 1])\n else:\n bool = False\n return bool", "def logical_calc(array, op):\n logic = \"\"\n if op == \"XOR\":\n op = \"^\"\n \n for x in array[0:len(array)-1]:\n logic = logic + \" \" + str(x) + \" \" + op.lower()\n \n logic = logic + \" \" + str(array[-1])\n \n ans = eval(logic.strip())\n \n return ans", "def logical_calc(arr, log):\n x = {'AND': 'and', 'OR': 'or', 'XOR': '!='}\n y = arr.pop(0)\n while len(arr) > 0:\n y = eval(str(y) + f' {x[log]} ' + str(arr.pop(0)))\n return y", "def xor(a,b):\n return a+b-2*a*b\n\ndef logical_calc(array, op):\n if op =='OR':\n result = array[0]\n for value in range(1,len(array)):\n result = result or array[value]\n return result\n if op=='AND':\n result = array[0]\n for value in range(1,len(array)):\n result = result and array[value]\n return result\n if op=='XOR':\n result = array[0]\n for value in range(1,len(array)):\n result = xor(result,array[value])\n return result", "def logical_calc(array, op):\n a = array[0]\n if op == 'AND':\n for i in range(len(array)-1):\n a = a and array[i+1]\n return bool(a)\n elif op == 'OR':\n for i in range(len(array)-1):\n a = a or array[i+1]\n return bool(a)\n elif op == 'XOR':\n for i in range(len(array)-1):\n a = a != array[i+1]\n return bool(a)\n", "from functools import reduce\ndef logical_calc(array, op):\n return {\n 'AND': all(array),\n 'OR' : any(array),\n 'XOR': reduce(lambda x,y: x ^ y, array)\n }.get(op)", "def logical_calc(array, op):\n print((array, op))\n if op == \"AND\":\n return not (False in array)\n if op == \"OR\":\n return (True in array)\n status = False\n for bool in array:\n status = bool ^ status \n \n return status\n", "import functools\n\ndef logical_calc(array, op):\n arr = {\n \"AND\":lambda a,b: a and b,\n \"OR\":lambda a,b: a or b,\n \"XOR\":lambda a,b: a != b\n }\n return functools.reduce(arr[op],array)", "from functools import reduce\nimport operator\n\ndef logical_calc(array, op):\n if op == \"AND\":\n o = operator.and_\n elif op == \"OR\":\n o = operator.or_\n elif op == \"XOR\":\n o = operator.xor\n \n return reduce(o, array)", "def logical_calc(array, op):\n if op == \"AND\":\n return all(array)\n elif op == \"OR\":\n return any(array)\n elif op == \"XOR\":\n return array.count(True) % 2 != 0", "def logical_calc(array, op):\n return eval(f' {op.lower() if op != \"XOR\" else \"^\"} '.join(map(str, array)))", "from operator import __and__, __or__, __xor__\nfrom functools import reduce\n\ndef logical_calc(a, op):\n if op == \"AND\":\n return reduce(__and__, a)\n if op == \"OR\":\n return reduce(__or__, a)\n else:\n return reduce(__xor__, a)", "def logical_calc(array, op):\n import functools\n if op==\"AND\":\n return functools.reduce(lambda i,j:i and j, array)\n elif op==\"OR\":\n return functools.reduce(lambda i,j:i or j, array)\n elif op==\"XOR\":\n return functools.reduce(lambda i,j:i ^ j, array)\n", "from functools import reduce\n\ndef logical_calc(array, op):\n if op == \"AND\": return reduce(lambda a,b: a and b, array)\n if op == \"OR\": return reduce(lambda a,b: a or b, array)\n return reduce(lambda a,b: a ^ b, array)", "from functools import reduce\ndef logical_calc(array, op):\n if op=='XOR':\n op='^'\n return reduce(lambda a,b:eval(str(a)+' '+op.lower()+' '+str(b)),array)", "def logical_calc(array, op):\n c = len(array)\n res = array[0]\n for i in range(c-1):\n if op=='AND':\n res = res and array[i+1]\n if op=='OR':\n res = res or array[i+1]\n if op=='XOR':\n res = res != array[i+1]\n return res", "def logical_calc(array, op):\n first = array[0]\n for i in range(0, len(array)-1):\n if op == \"AND\":\n first = array[i+1] and first\n elif op == \"OR\":\n first = array[i+1] or first\n elif op == \"XOR\":\n first = array[i+1] ^ first\n return first", "def logical_calc(array, op):\n res = array[0]\n if op == \"AND\":\n for i in range(1,len(array)):\n res *= array[i]\n elif op == \"OR\":\n for i in range(1,len(array)):\n res |= array[i]\n else:\n for i in range(1,len(array)):\n res ^= array[i]\n return res", "def logical_calc(array, op):\n op = op.lower()\n if op == \"xor\":\n op = \"!=\"\n for id in range(len(array)-1):\n array[id+1]=eval(str(array[id])+\" \"+op+\" \"+str(array[id+1]))\n return array[-1]#boolean", "from functools import reduce\n\ndef logical_calc(array, op):\n return {\n 'AND': reduce(lambda x, y: x & y, array),\n 'OR': reduce(lambda x, y: x | y, array),\n 'XOR': reduce(lambda x, y: x ^ y, array)\n }.get(op)", "def logical_calc(ar, op):\n if op == 'AND':\n return (False not in ar)\n elif op == 'OR':\n return (True in ar)\n elif op == 'XOR':\n if len(ar) == 2:\n return not (ar[0] == ar[1])\n elif len(ar) > 2:\n a = ar.pop(0)\n b = ar.pop(0)\n ar.insert(0,not (a == b))\n return logical_calc(ar, op)\n elif len(ar) == 1:\n return ar[0]", "from functools import reduce\n\n\ndef logical_calc(array, op):\n if op == 'AND':\n l = lambda x, y: x and y\n elif op == 'OR':\n l = lambda x, y: x or y\n else:\n l = lambda x, y: x ^ y\n return reduce(l, array)"]
{"fn_name": "logical_calc", "inputs": [[[true, true, true, false], "AND"], [[true, true, true, false], "OR"], [[true, true, true, false], "XOR"], [[true, true, false, false], "AND"], [[true, true, false, false], "OR"], [[true, true, false, false], "XOR"], [[true, false, false, false], "AND"], [[true, false, false, false], "OR"], [[true, false, false, false], "XOR"], [[true, true], "AND"], [[true, true], "OR"], [[true, true], "XOR"], [[false, false], "AND"], [[false, false], "OR"], [[false, false], "XOR"], [[false], "AND"], [[false], "OR"], [[false], "XOR"], [[true], "AND"], [[true], "OR"], [[true], "XOR"]], "outputs": [[false], [true], [true], [false], [true], [false], [false], [true], [true], [true], [true], [false], [false], [false], [false], [false], [false], [false], [true], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
24,875
def logical_calc(array, op):
bd2a4df7738ac1e393d36813d1c84b90
UNKNOWN
You need to write a function, that returns the first non-repeated character in the given string. For example for string `"test"` function should return `'e'`. For string `"teeter"` function should return `'r'`. If a string contains all unique characters, then return just the first character of the string. Example: for input `"trend"` function should return `'t'` You can assume, that the input string has always non-zero length. If there is no repeating character, return `null` in JS or Java, and `None` in Python.
["def first_non_repeated(s):\n return next((c for c in s if s.count(c) == 1), None)", "def first_non_repeated(s):\n for c in s:\n if s.count(c) == 1: return c", "from collections import Counter\n\ndef first_non_repeated(s):\n return next((k for k,v in Counter(s).items() if v==1), None)", "def first_non_repeated(string):\n for i in range(len(string.upper())):\n e = string[i]\n if (string.lower().count(e) == 1):\n return e\n return None", "def first_non_repeated(s):\n print(s)\n return next((i for i in s if s.count(i) == 1), None)", "def first_non_repeated(s):\n for a in s:\n if s.count(a) == 1:\n return a\n return None", "def first_non_repeated(s):\n return next((x for x in s if s.count(x) == 1), None)", "def first_non_repeated(s):\n for character in s:\n if s.count(character) == 1:\n return character\n break", "def first_non_repeated(s):\n for el in s:\n if s.count(el) == 1:\n return el", "def first_non_repeated(s):\n sets = unique, repeated = set(), set()\n for c in s: sets[c in unique].add(c)\n return next((c for c in s if c not in repeated), None)"]
{"fn_name": "first_non_repeated", "inputs": [["test"], ["teeter"], ["1122321235121222"], ["rend"]], "outputs": [["e"], ["r"], ["5"], ["r"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,210
def first_non_repeated(s):
f9d7ccacf9c6790b3153be5237dec6a8
UNKNOWN
Similarly to the [previous kata](https://www.codewars.com/kata/string-subpattern-recognition-i/), you will need to return a boolean value if the base string can be expressed as the repetition of one subpattern. This time there are two small changes: * if a subpattern has been used, it will be repeated at least twice, meaning the subpattern has to be shorter than the original string; * the strings you will be given might or might not be created repeating a given subpattern, then shuffling the result. For example: ```python has_subpattern("a") == False #no repeated shorter sub-pattern, just one character has_subpattern("aaaa") == True #just one character repeated has_subpattern("abcd") == False #no repetitions has_subpattern("babababababababa") == True #repeated "ba" has_subpattern("bbabbaaabbaaaabb") == True #same as above, just shuffled ``` Strings will never be empty and can be composed of any character (just consider upper- and lowercase letters as different entities) and can be pretty long (keep an eye on performances!). If you liked it, go for either the [previous kata](https://www.codewars.com/kata/string-subpattern-recognition-i/) or the [next kata](https://www.codewars.com/kata/string-subpattern-recognition-iii/) of the series!
["from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\ndef has_subpattern(string):\n return reduce(gcd, Counter(string).values()) != 1", "from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\ndef has_subpattern(s):\n return reduce(gcd, Counter(s).values()) > 1", "from collections import Counter\nfrom functools import reduce\nimport fractions\n\n\ndef gcd(*values):\n return reduce(fractions.gcd, values)\n\n\ndef has_subpattern(s):\n return gcd(*Counter(s).values()) != 1", "from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\n\ndef has_subpattern(string):\n return reduce(gcd, Counter(string).values()) > 1", "from functools import reduce\nfrom math import gcd\n\ndef has_subpattern(stg):\n return reduce(gcd, set(stg.count(c) for c in set(stg)), 0) > 1", "from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\ndef has_subpattern(string):\n prev, *counts = set(Counter(string).values())\n if prev == 1 and not counts:\n return False\n \n for c in counts:\n prev = gcd(prev, c)\n if prev == 1:\n return False;\n return True", "from re import findall;\nfrom functools import reduce\ngcd=lambda a,b: gcd(b,a%b) if b else a;\nhas_subpattern=lambda s: len(s)>1 and reduce(gcd, (len(e[0]+e[1]) for e in findall(r\"(.)(\\1*)\", \"\".join(sorted(s)))))>1", "from functools import reduce as R\nfrom collections import Counter as C\nfrom math import gcd as G\ndef has_subpattern(s): \n return R(G,set(C(s).values())) != 1", "from collections import Counter\nfrom math import gcd\nfrom functools import reduce\ndef has_subpattern(string):\n cnt = list(Counter(string).values())\n v = reduce(gcd, cnt, max(cnt))\n return v != 1\n", "from collections import Counter\nfrom math import gcd\ndef has_subpattern(string):\n temp=Counter(string)\n if temp.most_common(1)[0][1]==1:\n return False\n res=sorted(temp.items(), key=lambda x:x[1])\n if len(res)==1:\n return True\n check=res[-1][1]\n for i in range(1, len(res)):\n check=min(check, gcd(res[i][1], res[i-1][1]))\n if check==1:\n return False\n for i in res: \n if i[1]%check!=0:\n return False\n return True"]
{"fn_name": "has_subpattern", "inputs": [["a"], ["aaaa"], ["abcd"], ["babababababababa"], ["ababababa"], ["123a123a123a"], ["123A123a123a"], ["12aa13a21233"], ["12aa13a21233A"], ["abcdabcaccd"]], "outputs": [[false], [true], [false], [true], [false], [true], [false], [true], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,346
def has_subpattern(string):
aba6a37d04996f4d179cdddf7da04815
UNKNOWN
# Task Your task is to find the sum for the range `0 ... m` for all powers from `0 ... n. # Example For `m = 2, n = 3`, the result should be `20` `0^0+1^0+2^0 + 0^1+1^1+2^1 + 0^2+1^2+2^2 + 0^3+1^3+2^3 = 20` Note, that no output ever exceeds 2e9. # Input/Output - `[input]` integer m `0 <= m <= 50000` - `[input]` integer `n` `0 <= n <= 9` - `[output]` an integer(double in C#) The sum value.
["def S2N(m, n):\n return sum(i**j for i in range(m+1) for j in range(n+1))", "def S2N(m,n):\n return sum((a**(n+1)-1)//(a-1) if a!=1 else n+1 for a in range(m+1))", "def S2N(m, n):\n result = 0\n for x in range(n+1):\n for y in range(m+1):\n result += y**x\n return result", "def S2N(m,n):\n return sum(base**pow for pow in range(n+1) for base in range(m+1))", "def S2N(m, n):\n return sum(b ** e for b in range(m + 1) for e in range(n + 1))", "def S2N(m,n,x=-1,s=0):\n while x < m: \n p = -1; x+=1\n while p < n: \n p+=1; s += (x**p)\n return s", "def S2N(m, n):\n amounts = (lambda x: x + 1,\n lambda x: x * (x+1)/2,\n lambda x: x * (x+1) * (2*x + 1) / 6,\n lambda x: x**2 * (x+1)**2 / 4,\n lambda x: x * (x+1) * (2*x + 1) * (3*x**2 + 3*x - 1) / 30,\n lambda x: x**2 * (x+1)**2 * (2*x**2 + 2*x - 1) / 12,\n lambda x: x * (x+1) * (2*x + 1) * (3*x**4 + 6*x**3 - 3*x + 1) / 42,\n lambda x: x**2 * (x+1)**2 * (3*x**4 + 6*x**3 - x**2 - 4*x + 2) / 24,\n lambda x: x * (x+1) * (2*x + 1) \\\n * (5*x**6 + 15*x**5 + 5*x**4 - 15*x**3 - x**2 + 9*x - 3) / 90,\n lambda x: x**2 * (x+1)**2 * (x**2 + x - 1) \\\n * (2*x**4 + 4*x**3 - x**2 - 3*x + 3) / 20)\n return sum(amounts[i](m) for i in range(n+1))\n", "def S2N(m, n):\n return sum(sum(i ** j for i in range(m + 1)) for j in range(n + 1))", "def S2N(m, n):\n s=0\n for x in range(m+1):\n s+=sum(x**y for y in range(n+1))\n return s", "def S2N(m, n):\n result=0\n for i in range(0,m+1):\n for j in range(0,n+1):\n result+=i**j\n return result"]
{"fn_name": "S2N", "inputs": [[2, 3], [3, 5], [10, 9], [1, 1], [0, 0], [300, 2], [567, 2], [37, 4], [36, 4]], "outputs": [[20], [434], [1762344782], [3], [1], [9090501], [61083856], [15335280], [13409059]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,758
def S2N(m, n):
8a7e7b73be50c096312383379b0fc261
UNKNOWN
For this problem you must create a program that says who ate the last cookie. If the input is a string then "Zach" ate the cookie. If the input is a float or an int then "Monica" ate the cookie. If the input is anything else "the dog" ate the cookie. The way to return the statement is: "Who ate the last cookie? It was (name)!" Ex: Input = "hi" --> Output = "Who ate the last cookie? It was Zach! (The reason you return Zach is because the input is a string) Note: Make sure you return the correct message with correct spaces and punctuation. Please leave feedback for this kata. Cheers!
["def cookie(x):\n return \"Who ate the last cookie? It was %s!\" % {str:\"Zach\", float:\"Monica\", int:\"Monica\"}.get(type(x), \"the dog\")", "def cookie(x):\n try:\n who = {int: 'Monica', float: 'Monica', str: 'Zach'}[type(x)]\n except KeyError:\n who = 'the dog'\n return 'Who ate the last cookie? It was %s!' % who", "def cookie(x):\n #Good Luck\n if type(x) == type('x'):\n name = \"Zach\"\n elif type(x) == type(42) or type(x) == type(3.14):\n name = \"Monica\"\n else:\n name = \"the dog\"\n return \"Who ate the last cookie? It was %s!\"%name", "def cookie(x):\n return f'Who ate the last cookie? It was {\"Zach\" if type(x) is str else \"Monica\" if type(x) in [int, float] else \"the dog\"}!'", "CULPRITS = {\n str: 'Zach',\n int: 'Monica', float: 'Monica'\n}\n\ndef cookie(x):\n return \"Who ate the last cookie? It was {}!\".format(CULPRITS.get(type(x), 'the dog'))", "def cookie(x):\n return 'Who ate the last cookie? It was %s!' % ('the dog', 'Monica', 'Zach')[\n (type(x) in (int, float)) + 2 * (type(x) == str)]", "def cookie(x):\n return f\"Who ate the last cookie? It was {'the dog' if isinstance(x, bool) else 'Zach' if isinstance(x, str) else 'Monica'}!\"", "def cookie(x):\n result = ''\n if isinstance(x, str):\n result = \"Who ate the last cookie? It was Zach!\"\n elif isinstance(x, float) and type(x) is not bool:\n result = 'Who ate the last cookie? It was Monica!'\n elif isinstance(x, int) and type(x) is not bool:\n result = 'Who ate the last cookie? It was Monica!'\n else:\n result = 'Who ate the last cookie? It was the dog!'\n return result", "def cookie(x):\n pre = 'Who ate the last cookie? It was '\n post = 'the dog'\n punc = '!'\n if type(x) == str:\n post = \"Zach\"\n elif type(x) == int or type(x) == float:\n post = \"Monica\"\n return pre + post + punc", "def cookie(x):\n types = {\n 'str': 'Zach',\n 'int': 'Monica',\n 'float': 'Monica'\n }\n \n return 'Who ate the last cookie? It was {0}!'.format(\n types.get(type(x).__name__, 'the dog'))\n", "d={'str':'Zach', 'int':'Monica', 'float':'Monica'}\ndef cookie(x):\n return f\"Who ate the last cookie? It was {d.get(type(x).__name__,'the dog')}!\"", "def cookie(x):\n d = {'str':'Zach', 'float':'Monica', 'int':'Monica'}\n return f\"Who ate the last cookie? It was {d.get(type(x).__name__, 'the dog')}!\"", "def cookie(x):\n if isinstance(x, str):\n return \"Who ate the last cookie? It was Zach!\"\n elif isinstance(x, bool):\n return \"Who ate the last cookie? It was the dog!\"\n elif isinstance(x, (float, int)):\n return \"Who ate the last cookie? It was Monica!\"\n else:\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n if type(x) == str:\n x = 'Zach'\n elif type(x) ==int or type(x) == float:\n x = 'Monica'\n else:\n x = 'the dog'\n return f\"Who ate the last cookie? It was {x}!\"", "def cookie(x):\n return \"Who ate the last cookie? It was {}!\".format({str:\"Zach\", float:\"Monica\", int:\"Monica\"}.get(type(x), \"the dog\"))", "def cookie(x):\n if type(x) is str:\n return \"Who ate the last cookie? It was Zach!\"\n elif type(x) is bool:\n return \"Who ate the last cookie? It was the dog!\"\n return \"Who ate the last cookie? It was Monica!\"", "def cookie(x):\n name = {isinstance(x, y): z for z, y in dict(Zach=str, Monica=(int, float), _dog=bool).items()}.get(1, '_dog').replace('_', 'the ')\n return f\"Who ate the last cookie? It was {name}!\"", "def cookie(x):\n name = dict(zip((isinstance(x, t) for t in (str, (int, float), bool)), ('Zach', 'Monica', 'the dog'))).get(1, 'the dog')\n return f\"Who ate the last cookie? It was {name}!\"", "def cookie(x):\n name = 'Zach' if isinstance(x, str) else \\\n 'Monica' if (isinstance(x, float) or isinstance(x, int)) and not isinstance(x, bool) else \\\n 'the dog'\n return f\"Who ate the last cookie? It was {name}!\"", "def cookie(x):\n return 'Who ate the last cookie? It was {}!'.format({str: 'Zach', int: 'Monica', float: 'Monica', bool: 'the dog'}.get(type(x)))", "from typing import Any\n\ndef cookie(x: Any) -> str:\n \"\"\" Get an information who ate the last cookie. \"\"\"\n cookie_eaters = {\n type(x) is str: \"Zach\",\n type(x) in (float, int): \"Monica\"\n }\n return f\"Who ate the last cookie? It was {cookie_eaters.get(True, 'the dog')}!\"", "def cookie(x):\n choice = {str : 'Zach', int : 'Monica', float : 'Monica'}\n return f'Who ate the last cookie? It was {choice.get(type(x), \"the dog\")}!'", "def cookie(x):\n if type(x) == float or type(x) == int:\n name = \"Monica\"\n elif type(x) == str:\n name = \"Zach\"\n else:\n name = \"the dog\"\n \n return (f\"Who ate the last cookie? It was {name}!\")", "def cookie(x):\n #Good Luck\n if type(x) is str:\n return \"Who ate the last cookie? It was Zach!\"\n elif isinstance(x, float):\n return \"Who ate the last cookie? It was Monica!\"\n if type(x) is int:\n return \"Who ate the last cookie? It was Monica!\"\n else:\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n WHO = {str: 'Zach', float: 'Monica', int: 'Monica'}\n return 'Who ate the last cookie? It was {}!'.format(WHO.get(type(x), 'the dog'))", "def cookie(x):\n who = 'the dog'\n if isinstance(x, str):\n who = 'Zach'\n elif isinstance(x, float) or isinstance(x, int):\n who = 'Monica'\n \n if isinstance(x, bool):\n who = 'the dog'\n \n return f\"Who ate the last cookie? It was {who}!\"", "def cookie(x):\n #Good Luck\n if type(x) == str:\n return \"Who ate the last cookie? It was Zach!\"\n \n elif type(x) == int:\n return \"Who ate the last cookie? It was Monica!\"\n \n elif type(x) == float:\n return \"Who ate the last cookie? It was Monica!\"\n \n else:#elif type(x) != int or float or str:\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n print(x)\n if type(x) is str:\n return \"Who ate the last cookie? It was Zach!\"\n elif type(x) is bool:\n return \"Who ate the last cookie? It was the dog!\"\n elif type(x) is float or int:\n return \"Who ate the last cookie? It was Monica!\"\n else:\n return \"Who ate the last cookie? It was the dog!\"\n", "def cookie(x):\n name = \"Monica\" if type(x) == int or type(x) == float else \"the dog\" if type(x) == bool else \"Zach\"\n return \"Who ate the last cookie? It was {}!\".format(name)", "def cookie(x):\n name = {\n 'str': 'Zach',\n 'int': 'Monica',\n 'float': 'Monica',\n 'bool': 'the dog',\n }[type(x).__name__]\n return f\"Who ate the last cookie? It was {name}!\"\n", "def cookie(x):\n if isinstance(x, bool):\n return \"Who ate the last cookie? It was the dog!\"\n if isinstance(x, str):\n return \"Who ate the last cookie? It was Zach!\"\n if isinstance(x, float):\n return \"Who ate the last cookie? It was Monica!\"\n if isinstance(x, int):\n return \"Who ate the last cookie? It was Monica!\"\n", "def cookie(x):\n a={str:'Zach',int:'Monica',float:'Monica'}\n if type(x) in a.keys():\n return f\"Who ate the last cookie? It was {a[type(x)]}!\"\n else:\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n if isinstance(x,str):\n name = 'Zach'\n elif not isinstance(x,(float,int)) or x in [True,False]:\n name = 'the dog'\n else:\n name = 'Monica'\n return f\"Who ate the last cookie? It was {name}!\"", "def cookie(x):\n #Good Luck\n print(x,type(x))\n if isinstance(x,str):\n return 'Who ate the last cookie? It was Zach!'\n elif isinstance(x,(int,float)) and not isinstance(x,bool):\n return 'Who ate the last cookie? It was Monica!'\n else:\n return 'Who ate the last cookie? It was the dog!'", "def cookie(x):\n ergebnis=''\n \n if type(x)==str:\n ergebnis=\"Who ate the last cookie? It was Zach!\"\n elif type(x) in (int,float):\n ergebnis=\"Who ate the last cookie? It was Monica!\"\n else:\n ergebnis=\"Who ate the last cookie? It was the dog!\"\n \n return ergebnis ", "def cookie(x):\n name = \"\"\n if x is str(x):\n name=\"Zach!\"\n elif x is float(x) or x is int(x):\n name=\"Monica!\"\n else:\n name=\"the dog!\"\n \n return f\"Who ate the last cookie? It was {name}\"\n #Good Luck\n", "def cookie(x):\n return f'Who ate the last cookie? It was {\"Zach\" if type(x) is str else \"Monica\" if type(x) in [float, int] else \"the dog\"}!'\n\n\n\n", "def cookie(x):\n if type(x) == str: return \"Who ate the last cookie? It was Zach!\"\n if type(x) == float or type(x) == int: return \"Who ate the last cookie? It was Monica!\"\n else: return \"Who ate the last cookie? It was the dog!\"\n \n \n'''If the input is a string then \"Zach\" ate the cookie. If the input is a float\nor an int then \"Monica\" ate the cookie. If the input is anything else \"the dog\" ate\nthe cookie. \nThe way to return the statement is: \"Who ate the last cookie? It was (name)!'''", "def cookie(x): \n if isinstance(x, bool):\n name = 'the dog'\n elif isinstance(x,str):\n name = 'Zach' \n else:\n name = 'Monica'\n return \"Who ate the last cookie? It was {}!\".format(name)", "def cookie(x): \n if isinstance(x, bool):\n return \"Who ate the last cookie? It was the dog!\"\n elif isinstance(x,str):\n return \"Who ate the last cookie? It was Zach!\" \n else:\n return \"Who ate the last cookie? It was Monica!\"", "def cookie(x):\n if isinstance(x, str): return 'Who ate the last cookie? It was Zach!'\n elif type(x) in (int, float): return 'Who ate the last cookie? It was Monica!'\n else: return 'Who ate the last cookie? It was the dog!'\n", "def cookie(x):\n #Good Luck\n if isinstance(x, bool):\n return \"Who ate the last cookie? It was the dog!\"\n if isinstance(x, int) or isinstance(x, float):\n return \"Who ate the last cookie? It was Monica!\"\n if isinstance(x, str):\n return \"Who ate the last cookie? It was Zach!\"\n else:\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n tp = str(type(x))\n if tp == \"<class 'str'>\":\n return f'Who ate the last cookie? It was Zach!'\n elif tp == \"<class 'float'>\" or tp == \"<class 'int'>\":\n return f'Who ate the last cookie? It was Monica!'\n elif tp == \"<class 'bool'>\":\n return f'Who ate the last cookie? It was the dog!'", "def cookie(x):\n if type(x) == type('Ryan'):\n return \"Who ate the last cookie? It was Zach!\"\n elif type(x) == type(1.2) or type(x) == type(1):\n return \"Who ate the last cookie? It was Monica!\"\n else:\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n s = 'Who ate the last cookie? It was '\n if type(x) == str:\n return s + 'Zach!'\n elif type(x) == int or type(x) == float:\n return s + 'Monica!'\n else:\n return s + 'the dog!'\n", "def cookie(x):\n who = 'the dog'\n\n if isinstance(x, str):\n who = 'Zach'\n elif (isinstance(x, float) or isinstance(x, int)) and not isinstance(x, bool):\n who = 'Monica'\n \n return f'Who ate the last cookie? It was {who}!'", "def cookie(x):\n eaters = {str:\"Zach\", float:\"Monica\", int:\"Monica\"}\n try: return 'Who ate the last cookie? It was {}!'.format(eaters[type(x)])\n except: return 'Who ate the last cookie? It was the dog!'", "def cookie(x):\n print(x)\n return \"Who ate the last cookie? It was Zach!\" if isinstance(x,str)\\\n else \"Who ate the last cookie? It was Monica!\" \\\n if (isinstance(x,int) or isinstance(x,float)) and not isinstance(x,bool)\\\n else \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n return \"Who ate the last cookie? It was %s\" % {str:'Zach',int:'Monica',float:'Monica',bool:'the dog'}.get(type(x))+\"!\"", "def cookie(x):\n d={type(x)==str:'Zach',type(x)==int or type(x)==float:'Monica',type(x)==bool:'the dog'}\n return f'Who ate the last cookie? It was {d.get(1)}!'\n", "def cookie(x):\n if isinstance(x, str):\n name = \"Zach\"\n elif x ==True or x==False:\n name = \"the dog\"\n elif isinstance(x, (float,int)):\n name = \"Monica\"\n \n else:\n name = \"the dog\" \n return f\"Who ate the last cookie? It was {name}!\"", "def cookie(x):\n who = \"Who ate the last cookie? It was \"\n if isinstance(x, bool): return who + \"the dog!\"\n if isinstance(x, str): return who + \"Zach!\"\n if isinstance(x, int) or isinstance(x, float): return who + \"Monica!\"\n return who + \"the dog!\"", "def cookie(x):\n culprit = ''\n if isinstance(x,str):\n culprit = 'Zach' \n \n elif isinstance(x,float):\n culprit = 'Monica' \n\n elif x == 26:\n culprit = 'Monica' \n \n else:\n culprit = 'the dog' \n \n return f'Who ate the last cookie? It was {culprit}!'", "def cookie(x):\n if type(x) == str: return \"Who ate the last cookie? It was Zach!\"\n if type(x) in [int, float]: return \"Who ate the last cookie? It was Monica!\"\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n return 'Who ate the last cookie? It was %s!' % ('Zach' if isinstance(x, str) else \\\n 'Monica' if type(x) == int or isinstance(x, float) else 'the dog')", "def cookie(x):\n if isinstance(x, bool): return \"Who ate the last cookie? It was the dog!\"\n if isinstance(x, str): return \"Who ate the last cookie? It was Zach!\"\n if isinstance(x, (int,float)): return \"Who ate the last cookie? It was Monica!\"\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n print((type(x)))\n if type(x) is str:\n return \"Who ate the last cookie? It was Zach!\"\n elif type(x) is float or type(x) is int:\n return \"Who ate the last cookie? It was Monica!\"\n else:\n return \"Who ate the last cookie? It was the dog!\"\n", "def cookie(x):\n return \"Who ate the last cookie? It was \" + ({\n str: 'Zach',\n float: 'Monica',\n int: 'Monica'\n }.get(type(x)) if type(x) in [str, float, int] else 'the dog') + \"!\"", "def cookie(x):\n z = \"Zach\"\n m = \"Monica\"\n d = \"the dog\"\n if isinstance(x, str):\n return f\"Who ate the last cookie? It was {z}!\"\n elif isinstance(x, bool):\n return f\"Who ate the last cookie? It was {d}!\"\n elif isinstance(x, int) or isinstance(x, float):\n return f\"Who ate the last cookie? It was {m}!\"\n else:\n return f\"Who ate the last cookie? It was {d}!\"", "def cookie(x):\n name = ''\n \n if isinstance(x, str):\n name = 'Zach'\n elif isinstance(x, (float, int)) and type(x) is int or type(x) is float:\n name = 'Monica'\n else:\n name = 'the dog'\n \n return 'Who ate the last cookie? It was {}!'.format(name)\n", "def cookie(x):\n if type(x) is str: busted = \"Zach\"\n elif type(x) in (int, float): busted = \"Monica\"\n else: busted = \"the dog\"\n return f\"Who ate the last cookie? It was {busted}!\"", "def cookie(x):\n #Good Luck\n return \"Who ate the last cookie? It was Zach!\" if type(x)==str \\\n else \"Who ate the last cookie? It was Monica!\" if type(x)==int or type(x)==float \\\n else \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n if isinstance(x,bool): return 'Who ate the last cookie? It was the dog!'\n if isinstance(x,str): return 'Who ate the last cookie? It was Zach!'\n if isinstance(x,(float,int)): return 'Who ate the last cookie? It was Monica!'\n return 'Who ate the last cookie? It was the dog!'", "def cookie(x):\n name = 'Zach' if type(x) == str else 'Monica' if type(x) in (int, float) else 'the dog'\n return \"Who ate the last cookie? It was {}!\".format(name)", "def cookie(x):\n if type(x) == str :\n return \"Who ate the last cookie? It was Zach!\"\n elif type(x) == float :\n return \"Who ate the last cookie? It was Monica!\"\n elif type(x) == int :\n return \"Who ate the last cookie? It was Monica!\"\n else:\n return \"Who ate the last cookie? It was the dog!\"\ncookie(2.5)\n", "def cookie(x):\n if isinstance(x,bool):\n name='the dog'\n elif isinstance(x,int) or isinstance(x,float):\n name='Monica'\n elif isinstance(x,str):\n name='Zach'\n return f\"Who ate the last cookie? It was {name}!\"", "def cookie(x):\n name=\"\"\n if type(x)==str:\n name=\"Zach\"\n elif type(x)==float or type(x)==int:\n name=\"Monica\"\n else:\n name=\"the dog\"\n \n return 'Who ate the last cookie? It was '+name+'!'", "def cookie(x):\n if type(x) in (int, float):\n return 'Who ate the last cookie? It was Monica!'\n elif type(x) == str:\n return 'Who ate the last cookie? It was Zach!'\n return 'Who ate the last cookie? It was the dog!'", "def cookie(x):\n WHOATETHECOOKIE = \"\"\n if x == str(x):\n WHOATETHECOOKIE = \"Zach!\"\n elif x == bool(x):\n WHOATETHECOOKIE = \"the dog!\"\n else:\n WHOATETHECOOKIE = \"Monica!\"\n\n return \"Who ate the last cookie? It was \" + WHOATETHECOOKIE", "def cookie(x):\n res = isinstance(x, str) \n nu = isinstance(x, float)\n num = isinstance(x, int)\n if res == True:\n return \"Who ate the last cookie? It was Zach!\"\n elif x == True or x == False:\n return \"Who ate the last cookie? It was the dog!\"\n elif nu == True or num == True:\n return \"Who ate the last cookie? It was Monica!\"\n", "names = {\n str: 'Zach',\n float: 'Monica',\n int: 'Monica',\n}\ndef cookie(x):\n return f\"Who ate the last cookie? It was {names.get(type(x),'the dog')}!\"", "def cookie(x):\n if isinstance(x, str):\n return \"Who ate the last cookie? It was Zach!\"\n elif str(x).replace('.', '').isdigit():\n return \"Who ate the last cookie? It was Monica!\"\n else:\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n return \"Who ate the last cookie? It was Zach!\" if type(x) == str else \"Who ate the last cookie? It was Monica!\" if type(x) in [int, float] else \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n if type(x)==str:\n return \"Who ate the last cookie? It was Zach!\"\n elif type(x)==int:\n return \"Who ate the last cookie? It was Monica!\"\n elif type(x)==float:\n return \"Who ate the last cookie? It was Monica!\"\n elif type(x)==bool:\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n return \"Who ate the last cookie? It was \" + (\"Zach!\" if isinstance(x,str) else \"the dog!\" if isinstance(x,bool) else \"Monica!\")", "def cookie(x):\n return \"Who ate the last cookie? It was Zach!\" if str(x) == x else \\\n \"Who ate the last cookie? It was Monica!\" if isinstance(x, float) or type(x) is int else \\\n \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n if type(x)==bool:\n return \"Who ate the last cookie? It was the dog!\"\n else:\n return [\"Who ate the last cookie? It was Zach!\",\"Who ate the last cookie? It was Monica!\"][type(x)!=str]", "def cookie(x):\n switcher = {\n str: \"Zach!\",\n float: \"Monica!\",\n int: \"Monica!\",\n bool: \"the dog!\"\n }\n return \"Who ate the last cookie? It was \" + switcher.get(type(x))\n", "def cookie(x):\n result = \"Who ate the last cookie? It was \"\n if isinstance(x,str):\n result += \"Zach\"\n elif (isinstance(x,int) or isinstance(x,float)) and not isinstance(x,bool):\n result += \"Monica\"\n else:\n result += \"the dog\"\n result += \"!\"\n return result", "def cookie(x):\n return \"Who ate the last cookie? It was {}!\".format(\"Zach\" if isinstance(x, str) else \"the dog\" if isinstance(x, bool) else\"Monica\" if isinstance(x, int) or isinstance(x, float) else \"the dog\")", "def cookie(x):\n if x == True or x == False:\n return \"Who ate the last cookie? It was the dog!\"\n elif x == str(x):\n return \"Who ate the last cookie? It was Zach!\"\n elif x == float(x):\n return \"Who ate the last cookie? It was Monica!\"", "def cookie(x):\n return \"Who ate the last cookie? It was Zach!\" if type(x) == str else \"Who ate the last cookie? It was the dog!\" if type(x) == bool else \"Who ate the last cookie? It was Monica!\"", "def cookie(x):\n if x==26:\n return \"Who ate the last cookie? It was Monica!\"\n if isinstance(x, str):\n return \"Who ate the last cookie? It was Zach!\"\n if isinstance(x, float):\n return \"Who ate the last cookie? It was Monica!\"\n else:\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n culprit = 'the dog'\n if type(x) == type(''):\n culprit = 'Zach'\n elif type(x) == type(1) or type(x) == type(1.1):\n culprit = 'Monica'\n return('Who ate the last cookie? It was {0}!'.format(culprit))", "def cookie(x):\n name = 'Zach' if type(x) is str else 'Monica' if type(\n x) in (float,int) else 'the dog'\n return f'Who ate the last cookie? It was {name}!'\n", "def cookie(x):\n if type(x) is float or type(x) is int:\n return \"Who ate the last cookie? It was Monica!\"\n if isinstance(x, str):\n return \"Who ate the last cookie? It was Zach!\"\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n template = 'Who ate the last cookie?'\n if type(x) is str:\n return template + ' It was Zach!'\n elif type(x) is float or type(x) is int:\n return template + ' It was Monica!'\n else:\n return template + ' It was the dog!'\n", "def cookie(x):\n return f\"Who ate the last cookie? It was {'Zach' if isinstance(x, str) else 'the dog' if isinstance(x, bool) else 'Monica' if isinstance(x, int) or isinstance(x, float) else 'the dog'}!\"", "def cookie(x):\n if (isinstance(x,int) or isinstance(x,float)) and not isinstance(x,bool):\n return \"Who ate the last cookie? It was Monica!\"\n elif isinstance(x,str):\n return \"Who ate the last cookie? It was Zach!\"\n else:\n return \"Who ate the last cookie? It was the dog!\"\n", "def cookie(x):\n if type(x) == str:\n return \"Who ate the last cookie? It was Zach!\"\n if type(x) == float or type(x) == int:\n return \"Who ate the last cookie? It was Monica!\"\n if type(x) == bool:\n return \"Who ate the last cookie? It was the dog!\"\n else:\n return f\"Who ate the last cookie? It was {x}!\"", "def cookie(x):\n if x==True or x == False:\n return \"Who ate the last cookie? It was the dog!\"\n if isinstance(x, (int,float)):\n return \"Who ate the last cookie? It was Monica!\"\n elif isinstance(x , str):\n return \"Who ate the last cookie? It was Zach!\"\n else:\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n if type(x) == str:\n name = \"Zach\"\n elif type(x) in [float, int]:\n name = \"Monica\"\n else:\n name = 'the dog'\n \n \n return f\"Who ate the last cookie? It was {name}!\"", "def cookie(x):\n output = 'Zach' if type(x)==str else 'Monica' if type(x)==int or type (x)==float else 'the dog'\n return \"Who ate the last cookie? It was {}!\".format(output)", "def cookie(x):\n name = \"Zach\" if type(x) == str else \"Monica\" if type(x) == int or type(x) == float else \"the dog\"\n result = (f\"Who ate the last cookie? It was {name}!\")\n return result", "def cookie(x):\n return f'Who ate the last cookie? It was {\"Zach\" if type(x) is str else \"Monica\" if type(x) is int or type(x) is float else \"the dog\" }!'\n", "def cookie(x):\n #Good Luck\n if x == True or x == False:\n return \"Who ate the last cookie? It was the dog!\"\n if isinstance(x, int) or isinstance(x, float):\n return \"Who ate the last cookie? It was Monica!\"\n if isinstance(x, str):\n return \"Who ate the last cookie? It was Zach!\"\n return \"Who ate the last cookie? It was the dog!\"", "def cookie(x):\n if type(x) == type('Zach'):\n return 'Who ate the last cookie? It was Zach!'\n elif type(x) == type(1) or type(x) == type(2.5):\n return 'Who ate the last cookie? It was Monica!'\n else:\n return 'Who ate the last cookie? It was the dog!'", "def cookie(x):\n if isinstance(x, str): return \"Who ate the last cookie? It was Zach!\"\n if isinstance(x, bool): return \"Who ate the last cookie? It was the dog!\"\n if isinstance(x, (float, int)) : return \"Who ate the last cookie? It was Monica!\"\n return \"Who ate the last cookie? It was the dog!\"\n", "def cookie(x):\n if x == True or x == False:\n return \"Who ate the last cookie? It was the dog!\"\n elif x == str(x):\n return \"Who ate the last cookie? It was Zach!\"\n elif x == int(x) or float(x):\n return \"Who ate the last cookie? It was Monica!\"", "def cookie(x):\n #Good Luck\n if type(x) == bool:\n return \"Who ate the last cookie? It was the dog!\"\n if isinstance(x,str):\n return \"Who ate the last cookie? It was Zach!\"\n if isinstance(x,int) or isinstance(x,float):\n return \"Who ate the last cookie? It was Monica!\"\n\n"]
{"fn_name": "cookie", "inputs": [["Ryan"], [2.3], [26], [true], ["True"], [false], [1.98528462]], "outputs": [["Who ate the last cookie? It was Zach!"], ["Who ate the last cookie? It was Monica!"], ["Who ate the last cookie? It was Monica!"], ["Who ate the last cookie? It was the dog!"], ["Who ate the last cookie? It was Zach!"], ["Who ate the last cookie? It was the dog!"], ["Who ate the last cookie? It was Monica!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
26,281
def cookie(x):
3fb433326a8c5939b6a8174b508197f0
UNKNOWN
For this kata, you are given three points ```(x1,y1,z1)```, ```(x2,y2,z2)```, and ```(x3,y3,z3)``` that lie on a straight line in 3-dimensional space. You have to figure out which point lies in between the other two. Your function should return 1, 2, or 3 to indicate which point is the in-between one.
["def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):\n return sorted(((x1, y1, z1, 1), (x2, y2, z2, 2), (x3, y3, z3, 3)))[1][3]\n", "def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):\n return max(\n ((x2-x3)**2 + (y2-y3)**2 + (z2-z3)**2, 1),\n ((x1-x3)**2 + (y1-y3)**2 + (z1-z3)**2, 2),\n ((x2-x1)**2 + (y2-y1)**2 + (z2-z1)**2, 3),\n )[1]", "def middle_point(*coords):\n return sorted((coords[i*3:i*3+3], i+1) for i in range(3))[1][-1]\n", "import math\n\ndef middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):\n \n distances = [ math.pow(x1 -x2, 2.0) + math.pow(y1 -y2, 2.0) + math.pow(z1 -z2, 2.0), #d12\n math.pow(x1 -x3, 2.0) + math.pow(y1 -y3, 2.0) + math.pow(z1 -z3, 2.0), #d13\n math.pow(x3 -x2, 2.0) + math.pow(y3 -y2, 2.0) + math.pow(z3 -z2, 2.0)] #d23\n \n maximum = max(distances)\n index = distances.index(maximum)\n \n return 3 - index;", "def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):\n import math\n\n\n def dist(x1, y1, z1, x2, y2, z2):\n return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2 + (z1 - z2) ** 2)\n\n if math.fabs(dist(x1, y1, z1,x2, y2, z2)+dist(x1, y1, z1,x3, y3, z3) - dist(x2, y2, z2,x3, y3, z3))<0.1:\n return 1\n\n if math.fabs(dist(x2, y2, z2,x1, y1, z1)+dist(x2, y2, z2,x3, y3, z3) - dist(x1, y1, z1,x3, y3, z3))<0.1:\n return 2\n\n return 3", "def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):\n return sorted([(x1, y1, z1, 1), (x2, y2, z2, 2), (x3, y3, z3, 3)])[1][-1]", "def middle_point(*args):\n sortLst = sorted( args[i:i+3] for i in range(0,9,3) )\n return [i for i in range(0,9,3) if args[i:i+3] == sortLst[1]][0]/3 + 1", "middle_point=lambda*a:sorted(a[i-3:i]+(i//3,)for i in(3,6,9))[1][3]", "def middle_point(*coords):\n c = sorted((coords[i::3] for i in range(3)), key=lambda c: -len(set(c)))[0]\n return c.index(sorted(c)[1]) + 1\n", "def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):\n x2x3 = x2 <= x1 <= x3 if x2 < x3 else x3 <= x1 <= x2\n y2y3 = y2 <= y1 <= y3 if y2 < y3 else y3 <= y1 <= y2\n z2z3 = z2 <= z1 <= z3 if z2 < z3 else z3 <= z1 <= z2\n x1x3 = x1 <= x2 <= x3 if x1 < x3 else x3 <= x2 <= x1\n y1y3 = y1 <= y2 <= y3 if y1 < y3 else y3 <= y2 <= y1\n z1z3 = z1 <= z2 <= z3 if z1 < z3 else z3 <= z2 <= z1\n x1x2 = x1 <= x3 <= x2 if x1 < x2 else x2 <= x3 <= x1\n y1y2 = y1 <= y3 <= y2 if y1 < y2 else y2 <= y3 <= y1\n z1z2 = z1 <= z3 <= z2 if z1 < z2 else z2 <= z3 <= z1\n if x2x3 and y2y3 and z2z3: return 1\n if x1x3 and y1y3 and z1z3: return 2\n if x1x2 and y1y2 and z1z2: return 3\n"]
{"fn_name": "middle_point", "inputs": [[1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 2, 0, 6, -2, 8, 3, 0, 4], [0.25, 0.5, 0.75, 3.25, -0.5, -0.25, 1.0, 0.25, 0.5], [1, 0, 4, 5, 0, 6, -7, 0, 0], [-1, 0, 2, -2, 4, -1, -3, 8, -4]], "outputs": [[2], [3], [3], [1], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,648
def middle_point(x1, y1, z1, x2, y2, z2, x3, y3, z3):
86753815a40dc1315890b986850ec6b2
UNKNOWN
# Task Find the integer from `a` to `b` (included) with the greatest number of divisors. For example: ``` divNum(15, 30) ==> 24 divNum(1, 2) ==> 2 divNum(0, 0) ==> 0 divNum(52, 156) ==> 120 ``` If there are several numbers that have the same (maximum) number of divisors, the smallest among them should be returned. Return the string `"Error"` if `a > b`.
["import numpy as np\ns = np.ones(100000)\nfor i in range(2, 100000):\n s[i::i] += 1\n\ndef div_num(a, b):\n return max(range(a, b+1), key=lambda i: (s[i], -i), default='Error')", "def div_num(a, b):\n return 'Error' if a > b else sorted([i for i in range(a, b + 1)], key=lambda k:(-divisors(k), k))[0]\n \ndef divisors(n): \n d = {i for i in range(1, int(n**0.5 +.99)) if n % i == 0} \n return len(d | {n // i for i in d})", "def div_num(a, b):\n return \"Error\" if a > b else min((-divcount(n), n) for n in range(a, b+1))[1]\n\n\ndef divcount(n):\n c = 1 + (n > 1)\n for k in range(2, int(n**0.5) + 1):\n if n % k == 0:\n c += 2 - (k == n // k)\n return c", "def div_num(a, b):\n return \"Error\" if a > b else min((-divcount(n), n) for n in range(a, b+1))[1]\n\n\ndef divcount(n):\n return 1 + (n > 1) + sum(2 - (k == n // k) for k in range(2, int(n**0.5) + 1) if n % k == 0)\n", "div = lambda x:len(set(sum([[i,x//i] for i in range(2,int(x**.5)+1) if not x%i],[])))\nd = {**{1:1,2:2},**{i:div(i) for i in range(3,12000)}}\ndiv_num=lambda a,b:max([[j,i] for i,j in d.items() if a<=i<=b],key=lambda x:x[0],default=[0,'Error'])[1]", "def divisors(n):\n ans = set()\n for i in range(1, int(n**.5)+1):\n if not n%i:\n ans |= {i, n//i}\n return len(ans)\n\ndef div_num(a, b):\n if a > b:\n return \"Error\"\n return sorted(((n, divisors(n)) for n in range(a, b+1)), key=lambda x: x[1],reverse=1)[0][0]", "import math\ndef divisorGenerator(n): #\u6c42\u6240\u6709\u9664\u6570\n large_divisors = []\n for i in range(1, int(math.sqrt(n) + 1)):\n if n % i == 0:\n yield i\n if i*i != n:\n large_divisors.append(n / i)\n for divisor in reversed(large_divisors):\n yield divisor\ndef div_num(a, b): \n div_num = []\n if a > b:\n return 'Error'\n for i in range(a,b+1):\n div_num.append(len(list(divisorGenerator(i))))\n max_num = max(div_num)\n max_index = div_num.index(max_num)\n return a+max_index", "from functools import lru_cache\n\n@lru_cache(maxsize=None)\ndef count(n):\n x = n**0.5\n return 2 * sum(n%y == 0 for y in range(1, int(x+1))) - (x%1 == 0)\n\ndef div_num(a, b):\n if a > b: return \"Error\"\n return max(range(a, b+1), key=count)", "def div_num(a, b):\n if a > b:\n return \"Error\"\n return min((-divnum(n), n) for n in range(a, b+1))[1]\n\n\ndef divnum(n):\n d = {1, n}\n for k in range(2, int(n ** 0.5) + 1):\n if n % k == 0:\n d.add(k)\n d.add(n // k)\n return len(d)\n", "def div_num(a,b):\n if a>b: return \"Error\"\n if a==1 and b==2: return 2\n number = None\n precedente = 0\n for nombre in range(a,b+1):\n diviseurs = [1,nombre]\n candidat = 2\n while candidat < nombre // candidat:\n if nombre % candidat == 0: # candidat est un diviseur de nombre\n diviseurs.append(candidat)\n diviseurs.append(nombre // candidat)\n candidat += 1\n if candidat * candidat == nombre: # nombre est un carr\u00e9\n diviseurs.append(candidat)\n if precedente < len(diviseurs):\n number = nombre\n precedente = len(diviseurs)\n return number"]
{"fn_name": "div_num", "inputs": [[15, 30], [1, 2], [52, 156], [159, 4], [15, 48]], "outputs": [[24], [2], [120], ["Error"], [48]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,351
def div_num(a, b):
294036a2657f504b5c65195a9b96c7b7
UNKNOWN
ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but **exactly** 4 digits or exactly 6 digits. If the function is passed a valid PIN string, return `true`, else return `false`. ## Examples ``` "1234" --> true "12345" --> false "a234" --> false ```
["def validate_pin(pin):\n return len(pin) in (4, 6) and pin.isdigit()", "def validate_pin(pin):\n return len(pin) in [4, 6] and pin.isdigit()\n", "validate_pin = lambda pin: len(pin) in (4, 6) and pin.isdigit()", "def merge(array1,array2):\n array3 = []\n i = 0\n j = 0\n while (i < len(array1) and j < len(array2)):\n if (array1[i] < array2[j]):\n array3.append(array1[i])\n i = i + 1\n else:\n array3.append(array2[j])\n j = j + 1\n return array3 + array1[i:] + array2[j:]\n \ndef validate_pin(pin):\n #return true or false\n \n key = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']\n \n # check conditions\n if len(pin) == 6 or len(pin) == 4:\n p = [i for i in pin]\n m = merge(key, p)\n \n # check lengths\n if len(set(m)) == len(key):\n return True\n return False\n else:\n return False", "def validate_pin(pin):\n \"\"\"\n Returns True if pin is a string of 4 or 6 digits, False otherwise.\n \"\"\"\n \n # First check that pin is a string of length 4 or 6\n if(type(pin) != str or len(pin) not in [4, 6]):\n return(False)\n\n # If any character is not a digit, return False\n for c in pin:\n if c not in \"0123456789\":\n return(False)\n\n # If all the characters are digits, return True\n return(True)\n", "def validate_pin(pin):\n import re\n if len(pin) == 4 or len(pin) == 6: #not 4 or 6 digits\n if re.search('[^0-9]', pin) == None : #contains non-digit chars\n return True\n \n return False", "import re\n\ndef validate_pin(pin):\n return re.match(r'(?:\\d{4}|\\d{6})\\Z', pin) is not None", "def validate_pin(pin):\n return pin.isdigit() and len(str(pin)) in [4, 6]", "def validate_pin(pin):\n if pin.isnumeric() and len(pin) in [4,6]:\n return True\n return False\n", "import re\ndef validate_pin(pin):\n '''\\d only digits\n {} = number of digits with \\d\n | = or\n so, saying \"accept all 4 or 6 elements if the're just digits'''\n if re.fullmatch(\"\\d{4}|\\d{6}\", pin):\n return True\n else:\n return False", "import re\n\n\ndef validate_pin(pin):\n #return true or false\n return bool(re.fullmatch(\"\\d{4}|\\d{6}\", pin))", "def validate_pin(pin):\n if(len(pin) != 4 and len(pin) != 6):\n return False\n for i in range(len(pin)):\n try:\n int(pin[i])\n if(i == len(pin) - 1):\n return True\n except ValueError:\n break\n return False", "digits = [str(n) for n in range(10)]\n\ndef validate_pin(pin):\n return (len(pin) == 4 or len(pin) == 6) and all(p in digits for p in pin)\n", "def validate_pin(pin):\n return pin.isdigit() and (len(pin) == 4 or len(pin) == 6)", "def validate_pin(pin):\n\n num={'0','1','2','3','4','5','6','7','8','9'}\n pin_set=set(pin)\n \n if (len(pin)==4 or len(pin)==6) and pin_set.issubset(num):\n return True\n else:\n return False", "def validate_pin(pin):\n \n if (type(pin)==int or str(pin).isdigit()==True) and (len(str(pin))==6 or len(str(pin))==4):\n return True\n else:\n return False", "def validate_pin(pin):\n if len(pin) == 4 or len(pin)== 6:\n forbiden = \".,' /\\n=-`~!@#$%^&*)(_+|}{:?><\\\"'\\\\qwertuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM\"\n for i in forbiden:\n if i in pin:\n return False\n return True\n else: return False", "import re\n\ndef validate_pin(pin):\n return bool(re.search('^[0-9]{4}\\Z$|^[0-9]{6}\\Z$', pin))", "def validate_pin(pin):\n return {\n 6: True if [1 for x in pin if x.isdigit()].count(1) == 6 and len(pin) == 6 else False,\n 4: True if [1 for x in pin if x.isdigit()].count(1) == 4 and len(pin) == 4 else False,\n }.get(len(pin), False)", "validate_pin=lambda p:p.isdigit() and len(p)in(4,6)", "def validate_pin(pin):\n return all((pin.isdigit(), len(pin)==4 or len(pin)==6))", "import re\n\ndef validate_pin(pin):\n matches = re.findall(\"\\d\", pin)\n\n if len(pin) == 4:\n return len(matches) == 4\n elif len(pin) == 6:\n return len(matches) == 6\n else:\n return False", "from re import compile\n\np = compile(r\"\\A(\\d{4}|\\d{6})\\Z\")\n\n\ndef validate_pin(pin):\n return bool(p.match(pin))\n", "def validate_pin(pin):\n l = len(pin)\n if((l==4 or l ==6) and pin.isnumeric()):\n return True\n return False", "def validate_pin(pin):\n if (len(pin) != 4 and len(pin) != 6) or pin.isdigit() == False:\n code = False\n else:\n code = True\n\n return code", "import re\n\ndef validate_pin(pin):\n return True if re.match('^(?:\\d{4}|\\d{6})\\Z', pin) else False", "def validate_pin(pin):\n return True if ((len(pin) == 4 or len(pin) == 6) and pin.isnumeric()) else False\n", "def validate_pin(pin):\n if len(pin) == 4 or len(pin) == 6:\n if pin.isnumeric() == True:\n return True\n else:\n return False\n else:\n return False\n", "def validate_pin(pin):\n return pin.isdecimal() and len(pin) in (4,6)", "def validate_pin(num):\n return True if len(num) in [4,6] and num.isdigit() else False"]
{"fn_name": "validate_pin", "inputs": [["1"], ["12"], ["123"], ["12345"], ["1234567"], ["-1234"], ["-12345"], ["1.234"], ["00000000"], ["a234"], [".234"], ["1234"], ["0000"], ["1111"], ["123456"], ["098765"], ["000000"], ["090909"]], "outputs": [[false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [true], [true], [true], [true], [true], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,368
def validate_pin(pin):
22ff1ba096aaab41b98da07eafc8bb4a
UNKNOWN
Lot of junior developer can be stuck when they need to change the access permission to a file or a directory in an Unix-like operating systems. To do that they can use the `chmod` command and with some magic trick they can change the permissionof a file or a directory. For more information about the `chmod` command you can take a look at the [wikipedia page](https://en.wikipedia.org/wiki/Chmod). `chmod` provides two types of syntax that can be used for changing permissions. An absolute form using octal to denote which permissions bits are set e.g: 766. Your goal in this kata is to define the octal you need to use in order to set yout permission correctly. Here is the list of the permission you can set with the octal representation of this one. - User - read (4) - write (2) - execute (1) - Group - read (4) - write (2) - execute (1) - Other - read (4) - write (2) - execute (1) The method take a hash in argument this one can have a maximum of 3 keys (`owner`,`group`,`other`). Each key will have a 3 chars string to represent the permission, for example the string `rw-` say that the user want the permission `read`, `write` without the `execute`. If a key is missing set the permission to `---` **Note**: `chmod` allow you to set some special flags too (`setuid`, `setgid`, `sticky bit`) but to keep some simplicity for this kata we will ignore this one.
["def chmod_calculator(perm):\n perms = { \"r\": 4, \"w\": 2, \"x\": 1 }\n value = \"\"\n for permission in [\"user\", \"group\", \"other\"]:\n value += str(sum(perms.get(x, 0) for x in perm.get(permission, \"\")))\n \n return value", "def chmod_calculator(perm): \n return str(sum([wbin(perm[k]) * {\"user\":100, \"group\":10, \"other\":1}[k] for k in perm])).zfill(3)\n\ndef wbin(w):\n return int(w.translate(str.maketrans('rwx-', '1110')), 2)", "def chmod_calculator(perm):\n dic = {'rwx':'7', 'rw-': '6', 'r-x':'5', 'r--':'4', '-wx':'3', '--x': '1', '-w-':'2', '---':'0', '0':'0'}\n if not perm:\n return '000'\n else:\n def m(r):\n return dic[perm.get(r, '0')]\n return m('user') + m('group') + m('other')", "from functools import partial\n\ntrans = str.maketrans(\"rwx-\", \"1110\")\nbase2 = partial(int, base=2)\n\ndef chmod_calculator(perm):\n return \"{}{}{}\".format(*map(base2, (perm.get(k, '---').translate(trans) for k in (\"user\", \"group\", \"other\"))))", "def chmod_calculator(p):\n d = {'r':4,'w':2,'x':1,'-':0}\n ob = {'user':'0','group':'0','other':'0'}\n for i,j in p.items():\n ob[i]=str(sum(map(lambda x:d[x],j)))\n return ''.join(ob.values())", "TABLE = str.maketrans('rwx-','1110')\nFIELDS = 'user group other'.split()\n\ndef chmod_calculator(perm):\n return ''.join( str(int( perm.get(p,'---').translate(TABLE), 2 )) for p in FIELDS )", "from functools import reduce\nfrom operator import or_\n\nSHIFTS = {'user': 6, 'group': 3, 'other': 0}\n\ndef chmod_calculator(perm):\n return format(reduce(or_, (\n (('r' in p) << 2 | ('w' in p) << 1 | ('x' in p)) << SHIFTS[user]\n for user, p in perm.items()\n ), 0), '03o')", "def chmod_calculator(perm):\n oct = \"\"\n for j in ['user', 'group', 'other']:\n try:\n oct += str(sum([ 2 ** (2 - i[0]) for i in list(enumerate(perm[j], 0)) if i[1] != '-']))\n except:\n oct += \"0\"\n return oct", "def chmod_calculator(perm):\n val = {\"r\": 4, \"w\": 2, \"x\": 1, \"-\": 0}\n scope = (\"user\", \"group\", \"other\")\n return \"\".join(str(sum(val[c] for c in perm.get(s, \"---\"))) for s in scope)", "def chmod_calculator(perm):\n try:\n u = sum(2**(2-i) for i, x in enumerate(perm['user']) if x != \"-\")\n except:\n u = 0\n try:\n g = sum(2**(2-i) for i, x in enumerate(perm['group']) if x != \"-\")\n except:\n g = 0\n try:\n o = sum(2 ** (2 - i) for i, x in enumerate(perm['other']) if x != \"-\")\n except:\n o = 0\n return str(u) + str(g) +str(o)"]
{"fn_name": "chmod_calculator", "inputs": [[{"user": "rwx", "group": "r-x", "other": "r-x"}], [{"user": "rwx", "group": "r--", "other": "r--"}], [{"user": "r-x", "group": "r-x", "other": "---"}], [{"group": "rwx"}], [{}]], "outputs": [["755"], ["744"], ["550"], ["070"], ["000"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,663
def chmod_calculator(perm):
a1fa69b5c854d76380802d4fb8c59cbc
UNKNOWN
Your task is very simple. Given an input string s, case\_sensitive(s), check whether all letters are lowercase or not. Return True/False and a list of all the entries that are not lowercase in order of their appearance in s. For example, case\_sensitive('codewars') returns [True, []], but case\_sensitive('codeWaRs') returns [False, ['W', 'R']]. Goodluck :) Have a look at my other katas! Alphabetically ordered Find Nearest square number Not prime numbers
["def case_sensitive(s):\n return [s.islower() or not s, [c for c in s if c.isupper()]]", "l,case_sensitive=lambda s:[not any(s),s],lambda s:l([x for x in s if x.isupper()])", "def case_sensitive(s):l=list(filter(str.isupper,s));return[not l,l]", "def case_sensitive(s):\n return [not s or s.islower(), [c for c in s if c.isupper()]]", "def case_sensitive(s):\n result = [char for char in s if char.isupper()]\n return [ result == [], result ]", "def case_sensitive(s):\n l = [x for x in s if x.isupper()]\n return [l == [], l]", "def case_sensitive(s):\n lst = [x for x in s if x.isupper()]\n return [len(lst) == 0, lst]", "def case_sensitive(s):\n res = list(filter(str.isupper, s))\n return [not res, res]", "def case_sensitive(s):\n x = [c for c in list(s) if not c.islower()]\n return [not bool(x), x]", "def case_sensitive(s):\n uppers = [c for c in s if c.isupper()]\n return [not uppers, uppers]"]
{"fn_name": "case_sensitive", "inputs": [["asd"], ["cellS"], ["z"], [""]], "outputs": [[[true, []]], [[false, ["S"]]], [[true, []]], [[true, []]]]}
INTRODUCTORY
PYTHON3
CODEWARS
947
def case_sensitive(s):
1dddb3ea6b79511d4019f7e2496ce659
UNKNOWN
You throw a ball vertically upwards with an initial speed `v (in km per hour)`. The height `h` of the ball at each time `t` is given by `h = v*t - 0.5*g*t*t` where `g` is Earth's gravity `(g ~ 9.81 m/s**2)`. A device is recording at every **tenth of second** the height of the ball. For example with `v = 15 km/h` the device gets something of the following form: `(0, 0.0), (1, 0.367...), (2, 0.637...), (3, 0.808...), (4, 0.881..) ...` where the first number is the time in tenth of second and the second number the height in meter. # Task Write a function `max_ball` with parameter `v (in km per hour)` that returns the `time in tenth of second` of the maximum height recorded by the device. # Examples: `max_ball(15) should return 4` `max_ball(25) should return 7` # Notes - Remember to convert the velocity from km/h to m/s or from m/s in km/h when necessary. - The maximum height recorded by the device is not necessarily the maximum height reached by the ball.
["\"\"\"\nh = vt-0.5gt^2\nlet h = 0 [that is, when the ball has returned to the ground]\n=> 0 = vt-0.5gt^2\n=> 0.5gt^2 = vt\n=> 0.5gt = v\n=> t = 2v/g - the total time the ball is in the air.\n=> t at max height = v/g\n\"\"\"\n\ndef max_ball(v0):\n return round(10*v0/9.81/3.6)", "def max_ball(v0):\n return round(10*v0/9.81/3.6)", "def max_ball(v):\n return round(v / 3.5316)\n \n \n", "def max_ball(v0, g=9.81):\n v = v0 / 3.6\n prev = 0\n for i in range(1000):\n t = i * 0.1\n h = v*t - 0.5*g*t*t\n if h < prev:\n return i - 1\n prev = h", "def max_ball(v0):\n return round( v0/3.6/9.81*10 )", "def max_ball(v0):\n # acceleration\n g = 9.81 \n # height from ground, u is time in s, v speed in m/s\n def h(u):\n return v*u - 0.5*g*u*u\n # from km/h to m/s\n v = v0 * 1000 / 3600.0\n # in t = v/g the derivative is 0, the height is max\n t = v / g\n # record done every 0.1 s; tm is in tenth of second\n tm = int(t*10)\n # device max is before (<=) or after tm (>)\n h1 = h( tm/10.0 )\n h2 = h( (tm+1)/10.0 )\n mx = max( h1, h2 )\n # is the recorded max before or after the theoric max\n if (mx == h( tm/10.0 )):\n return tm\n else:\n return tm+1", "max_ball=lambda v0:round(v0*1000/360/9.81)", "def max_ball(v0):\n v = v0 * (1000/3600)\n g = 9.81\n t = 0\n record = []\n while v * t - 0.5 * g * t * t >= 0:\n h = v * t - 0.5 * g * t * t\n record.append(h)\n t += 0.1\n return (record.index(max(record)))", "from itertools import count\ndef max_ball(v0):\n g = 9.81\n c = count(0, 0.1)\n hh = -0.1\n while True:\n t = next(c)\n h = v0*1000/3600*t - 0.5*g*t*t\n if h-hh>0:\n hh = h\n else:\n return int(round(t*10, 2))-1\n", "def max_ball(v0):\n return round(10 * (v0 / 3.6) / 9.81)"]
{"fn_name": "max_ball", "inputs": [[37], [45], [99], [85], [136], [52], [16], [127], [137], [14]], "outputs": [[10], [13], [28], [24], [39], [15], [5], [36], [39], [4]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,927
def max_ball(v0):
50c493931f5032e9cb385817fb7b3930
UNKNOWN
An abundant number or excessive number is a number for which the sum of its proper divisors is greater than the number itself. The integer 12 is the first abundant number. Its proper divisors are 1, 2, 3, 4 and 6 for a total of 16 (> 12). Derive function `abundantNumber(num)/abundant_number(num)` which returns `true/True/.true.` if `num` is abundant, `false/False/.false.` if not.
["def abundant_number(num):\n return (sum([e for e in range(1,num) if num%e==0]) > num)", "def abundant_number(n):\n return sum(m for m in range(1, n) if n % m == 0) > n", "def abundant_number(num):\n return sum(i for i in range(1, num//2 + 1) if not num % i) > num", "def abundant_number(num):\n # O(sqrt(num))\n sum_divisors = 1\n int_sqrt = int(num ** 0.5)\n for div in range(2, int_sqrt + 1):\n if num % div == 0:\n # Add the factor and its complement\n # If num == 12 and div == 2, add 2 and 6\n sum_divisors += div + num // div\n if int_sqrt ** 2 == num: # We count the square root twice if num is a perfect square\n sum_divisors -= int_sqrt\n return sum_divisors > num", "def abundant_number(num):\n return sum(i for i in range(1, num // 2 + 1) if num % i == 0) > num", "def abundant_number(num):\n # Your code here\n return sum([x for x in range(1,num) if num%x==0])>num", "def abundant_number(n):\n return sum(n//i+i for i in range(2,int(n**.5)+1) if n%i==0)+1 > n"]
{"fn_name": "abundant_number", "inputs": [[12], [18], [37], [120], [77], [118], [5830], [11410], [14771], [11690]], "outputs": [[true], [true], [false], [true], [false], [false], [true], [true], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,065
def abundant_number(num):
e9959c0ca431d164a9ebe269ae14aa7a
UNKNOWN
[Haikus](https://en.wikipedia.org/wiki/Haiku_in_English) are short poems in a three-line format, with 17 syllables arranged in a 5–7–5 pattern. Your task is to check if the supplied text is a haiku or not. ### About syllables [Syllables](https://en.wikipedia.org/wiki/Syllable) are the phonological building blocks of words. *In this kata*, a syllable is a part of a word including a vowel ("a-e-i-o-u-y") or a group of vowels (e.g. "ou", "ee", "ay"). A few examples: "tea", "can", "to·day", "week·end", "el·e·phant". **However**, silent "E"s **do not** create syllables. *In this kata*, an "E" is considered silent if it's alone at the end of the word, preceded by one (or more) consonant(s) and there is at least one other syllable in the word. Examples: "age", "ar·range", "con·crete"; but not in "she", "blue", "de·gree". Some more examples: * one syllable words: "cat", "cool", "sprout", "like", "eye", "squeeze" * two syllables words: "ac·count", "hon·est", "beau·ty", "a·live", "be·cause", "re·store" ## Examples ``` An old silent pond... A frog jumps into the pond, splash! Silence again. ``` ...should return `True`, as this is a valid 5–7–5 haiku: ``` An old si·lent pond... # 5 syllables A frog jumps in·to the pond, # 7 splash! Si·lence a·gain. # 5 ``` Another example: ``` Autumn moonlight - a worm digs silently into the chestnut. ``` ...should return `False`, because the number of syllables per line is not correct: ``` Au·tumn moon·light - # 4 syllables a worm digs si·lent·ly # 6 in·to the chest·nut. # 5 ``` --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-)
["import re\n\nPATTERN = re.compile(r'[aeyuio]+[^aeyuio ]*((?=e\\b)e)?', flags=re.I)\n\n\ndef is_haiku(text):\n return [5,7,5] == [check(s) for s in text.split(\"\\n\")]\n \ndef check(s):\n return sum(1 for _ in PATTERN.finditer(s))\n", "import re\n\ndef is_haiku(text):\n def count_syllables(line):\n return len(re.findall(r'[aeiouy]{2,}|[aiouy]|e\\B|\\b[^\\Waeiouy]*e\\b', line, re.I))\n return tuple(map(count_syllables, text.splitlines())) == (5, 7, 5)", "import re\ndef is_haiku(text):\n \n def parse_line (line):\n word_pattern = r'[^\\W\\d_]+'\n return re.findall(word_pattern, line)\n \n def count_syllables(word):\n vowel_pattern = r'[aeiouy]+'\n vowels = re.findall(vowel_pattern, word, re.I)\n ends_in_e = lambda seq: seq[-1] == 'e'\n if vowels and ends_in_e(vowels) and ends_in_e(word):\n vowels.pop()\n return max(len(vowels), 1)\n \n syllables = [sum(map(count_syllables, parse_line(line)))\n for line in text.splitlines()]\n return syllables == [5, 7, 5]\n \n", "def is_haiku(text):\n import string\n vow = 'aeiouy'\n\n def syl_in_word(word):\n if word is '':\n return 0\n syls = sum([1 for ind, l in enumerate(word[:-1]) if (l in vow) and word[ind + 1] not in vow])\n if word[-1] in vow:\n if word[-1] != 'e' or (len(word)>1 and word[-2] in vow) or syls == 0:\n syls += 1\n return syls\n\n strings = text.split('\\n')\n syls = []\n for s in strings:\n # lower and clear punctuation\n s = ''.join([c for c in s.lower() if c not in string.punctuation])\n syls.append(sum([syl_in_word(word) for word in s.split(' ')]))\n\n return syls == [5, 7, 5]", "def is_haiku(s,v='aeiouy'):\n C=[]\n for x in[a.strip('.;:!?,').split()for a in s.lower().split('\\n')]:\n t=''\n for y in x:\n if y.endswith('e')and any(c in y[:-1]for c in v):y=y[:-1]\n for c in y:t+=c if c in v else' 'if t and t[-1]!=' 'else''\n t+=' '\n C+=[len(t.split())]\n return C==[5,7,5]", "def is_haiku(text):\n temp=text.replace(\".\",\"\").replace(\",\",\"\").replace(\"-\",\"\").replace(\"?\",\"\").replace(\"!\",\"\").replace(\"#\",\"\").replace(\";\",\"\").replace(\"/\",\"\").replace(\":\",\"\").replace(\")\",\"\").replace(\"()\",\"\")\n temp=temp.lower()\n temp=temp.split(\"\\n\")\n haiku=[]\n count=0\n for i in temp:\n for word in i.split():\n count+=syllable(word)\n haiku.append(count)\n count=0\n if len(haiku)!=3:\n return False \n return True if (haiku[0]==5 and haiku[1]==7 and haiku[2]==5) else False\ndef syllable(text):\n count=0\n index=0\n while index<len(text):\n if text[index] in \"aeiouy\":\n if text[index]==\"e\" and index==len(text)-1:\n break\n count+=1\n while (index+1)<len(text): \n if not (text[index+1] in \"aeiouy\"):\n break\n index+=1\n index+=1\n if count==0:\n count=1\n return count", "import re\n\nsyllables = re.compile(r'[aeyuio]+[^aeyuio ]*((?=e\\b)e)?', flags=re.I) #consonant + vowel, ends with e, ignore case\n\n\ndef is_haiku(text):\n return [5,7,5] == [check(s) for s in text.split(\"\\n\")]\n \ndef check(s):\n return sum(1 for _ in syllables.finditer(s))", "import re, string\ndef is_haiku(text):\n text = text.translate(str.maketrans('', '', string.punctuation))\n text = text.lower().splitlines() # Convert text to lowercase and split by lines\n # Count as a syllable if consonant followed by vowel\n sylRegex = re.compile(r'[^aeiouy\\s][aeiouy]') #consonant vowel\n syl2Regex = re.compile(r''' #for edge cases\n (ia[^lgn])|(riet)|\n (iu)|([^tn]io[^nr])|(ii)|\n ([aeiouym]bl$)|(aeiou){3}|(^mc)|(ism$)|\n (([^aeiouy])\\1l$)|([^l]lien)|\n (^coa[dglx].)|([^gq]ua[^auieol])|(dnt$)''', re.VERBOSE)\n endsERegex = re.compile(r'[^aeiouy][aeiouy][aeiou]*[^e\\s]+e(?:\\s|$)') # -1 syllable if the word ends with \"e\"\n endsE2Regex = re.compile(r'^\\b[ea]\\w{1,2}e(?:\\s|$)') # age, aide, edge\n beginVRegex = re.compile(r'\\b[aeiouy]') # +1 syllable if the word begins with a vowel\n exceptions_add = re.compile(r'''(triangle)''') #based on random case failures\n exceptions_minus = re.compile(r'''(obvious)''')\n\n# Counts for each line\n count = []\n for i in range(len(text)):\n syl = len(sylRegex.findall(text[i])) + len(syl2Regex.findall(text[i]))\n endsE_set1 = set(endsERegex.findall(text[i]))\n endsE_set2 = set(endsE2Regex.findall(text[i]))\n endsE = len(endsE_set1.union(endsE_set2))\n \n count.append(syl - endsE + len(beginVRegex.findall(text[i])) + len(exceptions_add.findall(text[i]))-len(exceptions_minus.findall(text[i])))\n print((text[i]))\n print((sylRegex.findall(text[i])))\n print((syl2Regex.findall(text[i])))\n print((endsERegex.findall(text[i])))\n print((endsERegex.findall(text[i])))\n print((beginVRegex.findall(text[i])))\n print(count) \n \n return count==[5,7,5]\n", "#https://www.codewars.com/kata/5c765a4f29e50e391e1414d4/train/python\ndef is_haiku(text):\n is_haiku = True\n vowel_list = [\"a\", \"e\", \"i\", \"o\", \"u\", \"y\"]\n haiku = text.splitlines()\n if len(haiku) != 3:\n return False\n for line in range(0,3):\n syllable = 0\n haiku[line] = haiku[line].split(\" \") \n for word in haiku[line]:\n current_syllable = 0\n silent_e = False\n word = word.lower()\n word = \"\".join(filter(str.isalnum, word))\n if len(word) == 1 and word in vowel_list:\n current_syllable += 1\n elif len(word) >= 2:\n if word[0] in vowel_list:\n current_syllable += 1\n silent_e = True\n for position in range(1,len(word)):\n if (word[position] in vowel_list) and (word[position-1] not in vowel_list):\n current_syllable += 1\n silent_e = True\n if current_syllable != 1 and silent_e == True and word[-1] == \"e\" and word[-2] not in vowel_list:\n current_syllable -= 1\n syllable += current_syllable\n if line == 0 or line == 2:\n if syllable != 5:\n is_haiku = False\n elif line == 1:\n if syllable != 7:\n is_haiku = False\n if is_haiku == False:\n return is_haiku\n return is_haiku", "def is_haiku(text):\n \"\"\"\n Given lines of text, determines if those lines constitute a haiku\n \"\"\"\n syllables_per_line = []\n lines = text.splitlines()\n for i in range(len(lines)):\n line = lines[i].split(\" \")\n syllables = 0\n for word in line:\n syllables += count_syllables(word)\n syllables_per_line.append(syllables)\n if syllables_per_line == [5, 7, 5]:\n return True\n else:\n return False\n \n\ndef count_syllables(word):\n \"\"\"\n Given a word, count the number of syllables\n \"\"\"\n syllables_in_word = 0\n vowels = 'aeiouy'\n word = \"\".join(filter(str.isalnum, word))\n word = word.lower()\n if len(word) > 0:\n if word[0] in vowels:\n syllables_in_word = 1\n if len(word) > 1:\n i = 0\n # count consonant, vowel pairs\n while i < len(word)-1:\n if (word[i] not in vowels) & (word[i+1] in vowels):\n syllables_in_word += 1\n i += 1\n i += 1\n # take care of silent 'e'\n # last part of if for double vowel word endings: ex. pursue, levee\n if (syllables_in_word > 1) & (word.endswith('e')) & (word[len(word)-2] not in vowels):\n syllables_in_word -= 1\n # print(f\"word: {word}, syllables: {syllables_in_word}\")\n return syllables_in_word"]
{"fn_name": "is_haiku", "inputs": [["An old silent pond...\nA frog jumps into the pond,\nsplash! Silence again."], ["An old silent pond...\nA frog jumps into the pond, splash!\nSilence again."], ["An old silent pond...\nA frog jumps into the pond,\nsplash!\nSilence again."], ["An old silent pond... A frog jumps into the pond, splash! Silence again."], ["Autumn moonlight -\na worm digs silently\ninto the chestnut."], [""], ["\n\n"], ["My code is cool, right?\nJava # Pyhton ; Ruby // Go:\nI know them all, yay! ;-)"], ["Edge case the urge come;\nFurthermore eye the garage.\nLike literature!"], ["a e i o u\noo ee ay ie ey oa ie\ny a e i o"]], "outputs": [[true], [false], [false], [false], [false], [false], [false], [true], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
8,266
def is_haiku(text):
424c055834c29c9acc2b5b35f708f549
UNKNOWN
# Task Consider a string of lowercase Latin letters and space characters (" "). First, rearrange the letters in each word `alphabetically`. And then rearrange the words in ascending order of the sum of their characters' `ASCII` values. If two or more words have the same `ASCII` value, rearrange them by their length in ascending order; If their length still equals to each other, rearrange them `alphabetically`. Finally, return the result. # Example For `s = "batman is bruce wayne"`, the result should be `"is bceru aenwy aamntb"`. ``` After rearranging the letters the string turns into "aamntb is bceru aenwy". The ASCII values of each word are: [627, 220, 529, 548]. After sorting the words the following string is obtained: "is bceru aenwy aamntb" (with ASCII values of [220, 529, 548, 627]).``` For `s = "peter parker is spiderman"`, the result should be `"is eeprt aekprr adeimnprs"` `(ASCII values: [220, 554, 645, 963])` # Input/Output - `[input]` string `s` A string of lowercase words. Each word is separated by exactly one space character. - `[output]` a string
["def revamp(s):\n words = [''.join(sorted(word)) for word in s.split()]\n words.sort(key=lambda word: (sum(map(ord, word)), len(word), word))\n return ' '.join(words)", "def revamp(s):\n words = [\"\".join(sorted(word)) for word in s.split()]\n return \" \".join(sorted(words, key = lambda word: (sum(ord(c) for c in word), len(word), word)))", "revamp = lambda s: ' '.join(sorted( map(lambda x: ''.join(sorted(x)), s.split()), key = lambda w: (sum(map(ord,w)), len(w), w) ))", "revamp=lambda s:\" \".join(sorted([\"\".join(sorted(i))for i in s.split()],key=lambda x:(sum(map(ord, x)),len(x),x)))", "def revamp(s):\n return ' '.join(sorted([''.join(sorted(w)) for w in s.split()], key = lambda w: (sum(ord(c) for c in w), w)))", "def revamp(s):\n s = [''.join(sorted(i)) for i in s.split()]\n return ' '.join(sorted(s, key = lambda x: (sum(ord(i) for i in x) , len(x), x)))", "def revamp(s):\n words = s.split()\n words = [\"\".join(sorted(w)) for w in words]\n words = sorted(words, key=lambda w: (sum(ord(i) for i in w), w))\n return \" \".join(words)", "def revamp(s):\n return ' '.join([x for x in sorted((''.join(sorted(x)) for x\n in s.split()), key=lambda x: (sum(map(ord, x)), x))])", "def revamp(s):\n return \" \".join(sorted((\"\".join(sorted(x)) for x in s.split()), key=lambda x: (sum(map(ord, x)), len(x), x)))", "def revamp(s):\n wds = sorted(''.join(sorted(c for c in wd)) for wd in s.split())\n return \" \".join(sorted(wds, key=lambda w : sum(ord(c) for c in w)))\n"]
{"fn_name": "revamp", "inputs": [["batman is bruce wayne"], ["peter parker is spiderman"], ["codewars is great"], ["airplanes in the night sky"]], "outputs": [["is bceru aenwy aabmnt"], ["is eeprt aekprr adeimnprs"], ["is aegrt acdeorsw"], ["in eht ksy ghint aaeilnprs"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,548
def revamp(s):
9aaeb6093966c33c03cb2879aff237e1
UNKNOWN
I need some help with my math homework. I have a number of problems I need to return the derivative for. They will all be of the form: ax^b, A and B are both integers, but can be positive or negative. Note: - if b is 1, then the equation will be ax. - if b is 0, then the equation will be 0. Examples: 3x^3 -> 9x^2 3x^2 -> 6x 3x -> 3 3 -> 0 3x^-1 -> -3x^-2 -3x^-2 -> 6x^-3 If you don't remember how derivatives work, here's a link with some basic rules: https://www.mathsisfun.com/calculus/derivatives-rules.html
["def get_derivative(s):\n if '^' in s:\n f,t = map(int, s.split('x^'))\n return '{}x'.format(f*t) if t==2 else '{}x^{}'.format(f*t, t-1)\n elif 'x' in s: return s[:-1]\n else: return '0'", "def get_derivative(s):\n if 'x' not in s: return '0'\n if '^' not in s: return s.replace('x', '')\n a, b = [int(n) for n in s.split('x^')]\n a *= b\n b -= 1\n if b == 1: return '{}x'.format(a)\n return '{}x^{}'.format(a, b)", "def get_derivative(s):\n if 'x' not in s:\n return '0'\n a = int(s.split('x')[0])\n b = 1\n parts = s.split('^')\n if len(parts) > 1:\n b = int(parts[1])\n if b == 2:\n return str(a * b) + 'x'\n elif b == 1:\n return str(a * b)\n return str(a * b) + 'x^' + str(b-1) ", "def get_derivative(s):\n if \"x\" not in s:\n return \"0\"\n elif s[-1] == \"x\":\n return s[:-1]\n else:\n b, e = [int(p) for p in s.split(\"x^\")]\n return f\"{b*e}x{'^'+str(e-1) if e != 2 else ''}\"", "def get_derivative(string):\n if not 'x' in string:\n return '0'\n if not '^' in string:\n return string[:-1]\n coef, exp = list(map(int, string.split('x^')))\n return f\"{coef * exp}x^{exp - 1}\" if exp != 2 else f\"{coef * exp}x\"\n", "def get_derivative(f):\n a, b = map(int, (f + '^%d' % ('x' in f)).replace('x', '').split('^')[:2])\n return {0: '0', 1: '%d' % a, 2: '%dx' % (a*b)}.get(b, '%dx^%d' % (a*b, b-1))", "import re\n\ndef get_derivative(s):\n a,b = map(int, re.sub(r'^(\\d+)$', r'\\1x^0', re.sub(r'x$', 'x^1', s)).split(\"x^\"))\n return re.sub(r'\\^1$|x\\^0', '', \"{}x^{}\".format(a*b, b-1*bool(b)))", "def get_derivative(string):\n if string.endswith('x'):\n return string[:-1]\n if 'x^' not in string:\n return '0'\n a, b = string.split('x^')\n return 'x^'.join([str(int(a)*int(b)), str(int(b)-1)]) if b != '2' else str(int(a)*2)+'x'", "def get_derivative(str):\n if 'x' not in str: return '0'\n if '^' not in str: return str[:-1]\n a,b = str.split('^')\n na = int(a[:-1]) * int(b)\n b = int(b)-1\n if b == 1: \n return '{}x'.format(na)\n else:\n return '{}x^{}'.format(na,b)\n", "def get_derivative(string):\n if string.endswith('x'):\n return string.split('x')[0]\n elif len(string) == 1:\n return '0'\n else:\n s = list(map(int, string.split(\"x^\")))\n second = s[1] - 1\n return f\"{s[0] * s[1]}x{'^' + str(second) if second != 1 else ''}\""]
{"fn_name": "get_derivative", "inputs": [["3x^3"], ["3x^2"], ["3x"], ["3"], ["3x^-1"], ["-3x^-1"], ["-3x^10"], ["-954x^2"]], "outputs": [["9x^2"], ["6x"], ["3"], ["0"], ["-3x^-2"], ["3x^-2"], ["-30x^9"], ["-1908x"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,534
def get_derivative(s):
664a2270714db6cca611dd9743c61077
UNKNOWN
There are some stones on Bob's table in a row, and each of them can be red, green or blue, indicated by the characters `R`, `G`, and `B`. Help Bob find the minimum number of stones he needs to remove from the table so that the stones in each pair of adjacent stones have different colours. Examples: ``` "RGBRGBRGGB" => 1 "RGGRGBBRGRR" => 3 "RRRRGGGGBBBB" => 9 ```
["def solution(s):\n st=[1 for i in range(1,len(s)) if s[i-1]==s[i]]\n return sum(st)", "def solution(s):\n return sum(1 for i in range(len(s)) if i and s[i-1]==s[i])", "def solution(s):\n r = s\n for i in range(9):\n r = r.replace('RR', 'R').replace('GG', 'G').replace('BB', 'B')\n\n return len(s) - len(r)", "def solution(stones):\n return sum(a==b for a,b in zip(stones, stones[1:]))", "from itertools import groupby\n\ndef solution(stones):\n return sum(len(list(l))-1 for _,l in groupby(stones))", "import re\n\ndef solution(stones):\n return sum( len(m[0])-1 for m in re.finditer(r'(.)\\1+',stones) )", "from itertools import groupby\n\n\ndef solution(stones):\n return sum(len(list(grp))-1 for _, grp in groupby(stones))", "def solution(stones):\n result = 0\n for i in range(len(stones)-1):\n if stones[i]==stones[i+1]:\n result += 1\n return result", "def solution(stones):\n # Do some magic\n num = 0\n for i in range(len(stones) - 1):\n if stones[i] == stones[i+1]:\n num += 1\n \n return num\n# if stones[0] == stones[1]:\n# stones.replace(stones[1], '', 1)\n# print(stones)\n", "def solution(stones):\n counter = -1\n previous_stone = stones[0]\n\n for stone in stones:\n if previous_stone == stone:\n counter += 1\n\n else: previous_stone = stone\n\n return counter"]
{"fn_name": "solution", "inputs": [["RRGGBB"], ["RGBRGB"], ["BGRBBGGBRRR"], ["GBBBGGRRGRB"], ["GBRGGRBBBBRRGGGB"]], "outputs": [[3], [0], [4], [4], [7]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,439
def solution(stones):
f1a43e21fe2bc21d937d2c952bfde87d
UNKNOWN
Create the function ```consecutive(arr)``` that takes an array of integers and return the minimum number of integers needed to make the contents of ```arr``` consecutive from the lowest number to the highest number. For example: If ```arr``` contains [4, 8, 6] then the output should be 2 because two numbers need to be added to the array (5 and 7) to make it a consecutive array of numbers from 4 to 8. Numbers in ```arr``` will be unique.
["def consecutive(arr):\n return max(arr) - min(arr) + 1 - len(arr) if arr else 0", "def consecutive(arr):\n #your code here\n if len(arr) == 1 or len(arr) == 0:\n return 0\n mn, mx = min(arr), max(arr)\n s = set(arr)\n return mx - mn - len(s) + 1", "consecutive=lambda a:len(a)and-~max(a)-min(a)-len(a)", "def consecutive(arr):\n try:\n return max(arr) - min(arr) - len(arr) + 1\n except:\n return 0", "def consecutive(arr):\n if len(arr) <= 1:\n return 0\n return (max(arr) - min(arr) + 1) - len(arr)", "def consecutive(arr):\n if len(arr)<2 :\n return 0;\n arr.sort();\n return arr[-1]-arr[0]-len(arr)+1;", "def consecutive(arr):\n l = len(arr)\n return max(arr) - min(arr) + 1 - l if l>1 else 0", "def consecutive(arr):\n arr = sorted(arr)\n return arr[-1] - arr[0] - len(arr[1:]) if len(arr) > 0 else 0", "def consecutive(arr):\n if not arr:\n return 0\n return max(max(arr)-min(arr)-len(arr)+1,0)", "def consecutive(arr):\n return len(range(min(arr),max(arr)+1))-len(arr) if arr else 0"]
{"fn_name": "consecutive", "inputs": [[[4, 8, 6]], [[1, 2, 3, 4]], [[]], [[1]], [[-10]], [[1, -1]], [[-10, -9]], [[0]], [[10, -10]], [[-10, 10]]], "outputs": [[2], [0], [0], [0], [0], [1], [0], [0], [19], [19]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,091
def consecutive(arr):
f716c06d359c30deb4ae09cae947d2da
UNKNOWN
I have the `par` value for each hole on a golf course and my stroke `score` on each hole. I have them stored as strings, because I wrote them down on a sheet of paper. Right now, I'm using those strings to calculate my golf score by hand: take the difference between my actual `score` and the `par` of the hole, and add up the results for all 18 holes. For example: * If I took 7 shots on a hole where the par was 5, my score would be: 7 - 5 = 2 * If I got a hole-in-one where the par was 4, my score would be: 1 - 4 = -3. Doing all this math by hand is really hard! Can you help make my life easier? ## Task Overview Complete the function which accepts two strings and calculates the golf score of a game. Both strings will be of length 18, and each character in the string will be a number between 1 and 9 inclusive.
["def golf_score_calculator(par, score):\n return sum(int(b) - int(a) for a, b in zip(par, score))", "def golf_score_calculator(p, s):\n return sum([int(s[i])-int(p[i]) for i in range(len(p))])", "def golf_score_calculator(par, score):\n return sum(map(int, score)) - sum(map(int, par))", "def golf_score_calculator(*par_score):\n return sum(int(b)-int(a) for a,b in zip(*par_score) )", "def golf_score_calculator(par_string, score_string):\n \n return sum(map(int,list(score_string))) - sum(map(int,list(par_string)))", "def digitsum(x):\n total = 0\n for letter in str(x):\n total += ord(letter)-48\n return total\n\n\ndef golf_score_calculator(par, score):\n return digitsum(score) - digitsum(par)\n", "def golf_score_calculator(par_string, score_string):\n score = 0\n for i in range(0,18):\n score -= int(par_string[i]) - int(score_string[i])\n return score", "def golf_score_calculator(par_string, score_string):\n # Convert each string into a list of integers\n par_list = list(map(int, par_string))\n score_list = list(map(int, score_string))\n \n # Use a for loop thru both lists to calculate difference for each hole\n differences = [i-j for i,j in zip(score_list, par_list)]\n \n # Summate all values in differences list for score\n return sum(differences)\n pass", "def golf_score_calculator(par_stg, score_stg):\n return sum((int(s) - int(p)) for (s, p) in zip(score_stg, par_stg))", "def golf_score_calculator(par_string, score_string):\n return sum(b-a for a,b in zip(map(int, par_string), map(int, score_string)))"]
{"fn_name": "golf_score_calculator", "inputs": [["443454444344544443", "353445334534445344"], ["123456123456123456", "123456123456123456"]], "outputs": [[-1], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,620
def golf_score_calculator(par_string, score_string):
51148a1275020a006fe12620420646eb
UNKNOWN
The written representation of a number (with 4 or more digits) can be split into three parts in various different ways. For example, the written number 1234 can be split as [1 | 2 | 34] or [1 | 23 | 4] or [12 | 3 | 4]. Given a written number, find the highest possible product from splitting it into three parts and multiplying those parts together. For example: - product of [1 | 2 | 34] = 1 \* 2 \* 34 = 68 - product of [1 | 23 | 4] = 1 \* 23 \* 4 = 92 - product of [12 | 3 | 4] = 12 \* 3 \* 4 = 144 So maximumProductOfParts(1234) = 144 For a longer string there will be many possible different ways to split it into parts. For example, 8675309 could be split as: - [8 | 6 | 75309] - [867 | 530 | 9] - [8 | 67 | 5309] - [86 | 75 | 309] or any other option that splits the string into three parts each containing at least one digit.
["from functools import reduce\nfrom operator import mul\n\ndef maximum_product_of_parts(n):\n s = str(n)\n return max(reduce(mul, map(int, (s[:i], s[i:j], s[j:])))\n for i in range(1,len(s)-1) for j in range(i+1,len(s)))", "from functools import reduce, partial\nfrom operator import mul\nproduct = partial(reduce, mul) \n\ndef maximum_product_of_parts(n):\n s = str(n)\n l = len(s)\n return max(product(map(int, (s[:i], s[i:j], s[j:]))) for i in range(1, l-1) for j in range(i+1, l))", "def maximum_product_of_parts(number):\n s, n, result = str(number), len(str(number)), 0\n for i in range(1, n - 1):\n for j in range(i + 1, n):\n start, middle, end = s[0:i], s[i:j], s[j:]\n result = max(result, int(start) * int(middle) * int(end))\n return result", "def maximum_product_of_parts(n:int)->int:\n n = str(n)\n return max([int(n[:i])*int(n[i:j])*int(n[j:]) for i in range(1,len(n)+1) for j in range(i+1,len(n))])", "import itertools\n\ndef maximum_product_of_parts(n):\n s = str(n)\n return max(\n int(s[:i]) * int(s[i:j]) * int(s[j:])\n for i, j in itertools.combinations(range(1, len(s)), 2)\n )", "def maximum_product_of_parts(n):\n n = str(n)\n s=[]\n for i in range(1,len(n)-1):\n for h in range(i+1,len(n)):\n f,m,l = int(n[0:i]),int(n[i:h]),int(n[h:])\n s.append(f*m*l)\n return max(s)", "def maximum_product_of_parts(n):\n products = []\n \n n = str(n)\n l = len(n)\n for i in range(1, l - 1) :\n for j in range(i + 1, l) :\n k = int(n[:i]) * int(n[i : j]) * int(n[j : l])\n products.append(k)\n return max(products)", "maximum_product_of_parts=lambda n:(lambda s:max(int(s[:i])*int(s[i:j])*int(s[j:])for j in range(2,len(s))for i in range(1,j)))(str(n))", "def maximum_product_of_parts(n):\n ns = str(n)\n return max(int(ns[:b])*int(ns[b:c])*int(ns[c:]) for a in range(len(ns)-2) for b in range(a+1,len(ns)-1) for c in range(b+1,len(ns)))\n", "def maximum_product_of_parts(s):\n s = str(s)\n subs = []\n for i in range(1, len(s)-1):\n for j in range(i+1, len(s)):\n subs.append([int(x) for x in [s[0:i], s[i:j], s[j:]]])\n return max([x*y*z for [x,y,z] in subs])\n"]
{"fn_name": "maximum_product_of_parts", "inputs": [[1234], [4321], [4224]], "outputs": [[144], [252], [352]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,298
def maximum_product_of_parts(n):
34e703b88b577df692021d55d285865f
UNKNOWN
# Summary: Given a number, `num`, return the shortest amount of `steps` it would take from 1, to land exactly on that number. # Description: A `step` is defined as either: - Adding 1 to the number: `num += 1` - Doubling the number: `num *= 2` You will always start from the number `1` and you will have to return the shortest count of steps it would take to land exactly on that number. `1 <= num <= 10000` Examples: `num == 3` would return `2` steps: ``` 1 -- +1 --> 2: 1 step 2 -- +1 --> 3: 2 steps 2 steps ``` `num == 12` would return `4` steps: ``` 1 -- +1 --> 2: 1 step 2 -- +1 --> 3: 2 steps 3 -- x2 --> 6: 3 steps 6 -- x2 --> 12: 4 steps 4 steps ``` `num == 16` would return `4` steps: ``` 1 -- +1 --> 2: 1 step 2 -- x2 --> 4: 2 steps 4 -- x2 --> 8: 3 steps 8 -- x2 --> 16: 4 steps 4 steps ```
["def shortest_steps_to_num(num):\n steps = 0\n \n while num != 1:\n if num % 2:\n num -= 1\n else:\n num //= 2\n \n steps += 1\n \n return steps", "def shortest_steps_to_num(num):\n return num.bit_length() + bin(num).count('1') - 2", "def shortest_steps_to_num(num):\n x=0\n while num>1:\n if num%2: num-=1\n else: num/=2\n x+=1\n return x\n", "def shortest_steps_to_num(n):\n return bin(n).count('1') + n.bit_length() - 2 ", "def shortest_steps_to_num(num):\n return 0 if num == 1 else 1 + shortest_steps_to_num(num - 1 if num % 2 else num / 2)\n", "def shortest_steps_to_num(n):\n return (\n 0 if n == 1 else\n 1 + shortest_steps_to_num(n-1) if n % 2 else\n 1 + shortest_steps_to_num(n//2)\n )", "def shortest_steps_to_num(n):\n step = 0\n while n > 1:\n n, step = n // 2, step + 1 + n % 2\n return step", "def shortest_steps_to_num(num):\n s = bin(num)\n return len(s) + s.count('1') - 4", "def shortest_steps_to_num(num):\n steps = 0\n while num > 1:\n if num % 2 == 0:\n num = num // 2\n elif num == 3:\n num -= 1\n else:\n num -= 1\n steps += 1\n return steps\n", "def shortest_steps_to_num(num):\n a= str(bin(num))[3:]\n return len(a)+a.count('1')"]
{"fn_name": "shortest_steps_to_num", "inputs": [[2], [3], [4], [5], [6], [7], [8], [9], [10], [20], [30], [40], [50], [11], [24], [37], [19], [48], [59], [65], [73], [83], [64], [99], [100], [10000], [1500], [1534], [1978], [2763], [9999], [2673], [4578], [9876], [2659], [7777], [9364], [7280], [4998], [9283], [8234], [7622], [800], [782], [674], [4467], [1233], [3678], [7892], [5672]], "outputs": [[1], [2], [2], [3], [3], [4], [3], [4], [4], [5], [7], [6], [7], [5], [5], [7], [6], [6], [9], [7], [8], [9], [6], [9], [8], [17], [16], [18], [17], [17], [20], [16], [17], [18], [16], [18], [17], [17], [17], [17], [16], [19], [11], [13], [12], [18], [14], [18], [19], [16]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,389
def shortest_steps_to_num(num):
e7d515f09add7c8a8d6a22628d72bdf9
UNKNOWN
Prior to having fancy iPhones, teenagers would wear out their thumbs sending SMS messages on candybar-shaped feature phones with 3x4 numeric keypads. ------- ------- ------- | | | ABC | | DEF | | 1 | | 2 | | 3 | ------- ------- ------- ------- ------- ------- | GHI | | JKL | | MNO | | 4 | | 5 | | 6 | ------- ------- ------- ------- ------- ------- |PQRS | | TUV | | WXYZ| | 7 | | 8 | | 9 | ------- ------- ------- ------- ------- ------- | | |space| | | | * | | 0 | | # | ------- ------- ------- Prior to the development of T9 (predictive text entry) systems, the method to type words was called "multi-tap" and involved pressing a button repeatedly to cycle through the possible values. For example, to type a letter `"R"` you would press the `7` key three times (as the screen display for the current character cycles through `P->Q->R->S->7`). A character is "locked in" once the user presses a different key or pauses for a short period of time (thus, no extra button presses are required beyond what is needed for each letter individually). The zero key handles spaces, with one press of the key producing a space and two presses producing a zero. In order to send the message `"WHERE DO U WANT 2 MEET L8R"` a teen would have to actually do 47 button presses. No wonder they abbreviated. For this assignment, write a module that can calculate the amount of button presses required for any phrase. Punctuation can be ignored for this exercise. Likewise, you can assume the phone doesn't distinguish between upper/lowercase characters (but you should allow your module to accept input in either for convenience). Hint: While it wouldn't take too long to hard code the amount of keypresses for all 26 letters by hand, try to avoid doing so! (Imagine you work at a phone manufacturer who might be testing out different keyboard layouts, and you want to be able to test new ones rapidly.)
["BUTTONS = [ '1', 'abc2', 'def3',\n 'ghi4', 'jkl5', 'mno6',\n 'pqrs7', 'tuv8', 'wxyz9',\n '*', ' 0', '#' ]\ndef presses(phrase):\n return sum(1 + button.find(c) for c in phrase.lower() for button in BUTTONS if c in button)", "def presses(phrase):\n x = 0\n for letter in phrase:\n if letter.lower() in list('1*#adgjmptw '): x+= 1\n elif letter.lower() in list('0behknqux'): x+= 2\n elif letter.lower() in list('cfilorvy'): x+= 3\n elif letter.lower() in list('234568sz'): x+= 4\n elif letter.lower() in list('79'): x+= 5\n return x\n", "buttons = [\n '1',\n 'abc2',\n 'def3',\n 'ghi4',\n 'jkl5',\n 'mno6',\n 'pqrs7',\n 'tuv8',\n 'wxyz9',\n '*',\n ' 0',\n '#'\n]\n\ndef getPresses(c):\n for button in buttons:\n if c in button:\n return button.index(c) + 1\n return 0\n\ndef presses(phrase):\n return sum(getPresses(c) for c in phrase.lower())\n", "presses = lambda s: sum((c in b) * (1 + b.find(c)) for c in s.lower() for b in\n '1,abc2,def3,ghi4,jkl5,mno6,pqrs7,tuv8,wxyz9,*, 0,#'.split(\",\"))", "def presses(phrase):\n numbers = ['*','#','1','ABC2', 'DEF3', 'GHI4', 'JKL5', 'MNO6', 'PQRS7', 'TUV8', 'WXYZ9', ' 0']\n print(phrase)\n phrase = phrase.upper()\n result = 0\n \n for letter in phrase:\n for n in numbers:\n if letter in n:\n result = result + n.index(letter) + 1\n return result", "layout = [' 0', '1', 'abc2', 'def3', 'ghi4', 'jkl5', 'mno6', 'pqrs7', 'tuv8', 'wxyz9']\nD_LAYOUT = { l: i+1 for touch in layout for i,l in enumerate(touch) }\nDEFAULT = 1\n\ndef presses(phrase):\n return sum( D_LAYOUT.get(l, DEFAULT) for l in phrase.lower() )", "def presses(phrase):\n return sum(map(int, phrase.upper().translate(str.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZ *#1234567890', '123123123123123123412312341111444445452'))))", "def presses(phrase):\n phrase = phrase.upper()\n counter = 0\n s = set(phrase)\n alphabet = [chr(x) for x in range(65,91)]\n for x in range(10):\n if x != 1:\n result = (3, 0, 4)[(not x) + (x in [7,9])*2]\n part = alphabet[:result] or [' ']\n part.append(str(x))\n alphabet = alphabet[result:]\n for i,c in enumerate(part, 1):\n if c in s:\n res = phrase.count(c)\n counter += res * i\n s.remove(c)\n else:\n for ch in ['1', '*', '#']:\n counter += 1 * phrase.count(ch)\n return counter", "def presses(phrase):\n #your code here\n dict_1 = {'1':1,'A':1,'B':2,'C':3,'2':4,'D':1,'E':2,'F':3,'3':4,'G':1,'H':2,'I':3,'4':4,'J':1,'K':2,'L':3,'5':4,'M':1,'N':2,'O':3,'6':4,'P':1,'Q':2,'R':3,'S':4,'7':5,'T':1,'U':2,'V':3,'8':4,'W':1,'X':2,'Y':3,'Z':4,'9':5,'*':1,' ':1,'0':2,'#':1}\n s = 0\n for x in phrase:\n if x.upper() in dict_1:\n s += dict_1[x.upper()]\n return s\n"]
{"fn_name": "presses", "inputs": [["LOL"], ["HOW R U"], ["WHERE DO U WANT 2 MEET L8R"], ["lol"], ["0"], ["ZER0"], ["1"], ["IS NE1 OUT THERE"], ["#"], ["#codewars #rocks"]], "outputs": [[9], [13], [47], [9], [2], [11], [1], [31], [1], [36]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,043
def presses(phrase):
ae98c5c2ac38994cc34f165cc6d0bac1
UNKNOWN
Consider integer coordinates x, y in the Cartesian plan and three functions f, g, h defined by: ``` f: 1 <= x <= n, 1 <= y <= n --> f(x, y) = min(x, y) g: 1 <= x <= n, 1 <= y <= n --> g(x, y) = max(x, y) h: 1 <= x <= n, 1 <= y <= n --> h(x, y) = x + y ``` where n is a given integer (n >= 1, guaranteed) and x, y are integers. In the table below you can see the value of the function f with n = 6. ---|*0* |*1*|*2*|*3*|*4*|*5*|*6*| -- |--|--|--|--|--|--|--| *6*|- |1 |2 |3 |4 |5 |6 | *5*|- |1 |2 |3 |4 |5 |5 | *4*|- |1 |2 |3 |4 |4 |4 | *3*|- |1 |2 |3 |3 |3 |3 | *2*|- |1 |2 |2 |2 |2 |2 | *1*|- |1 |1 |1 |1 |1 |1 | *0*|- |- |- |- |- |- |- | The task is to calculate the sum of f(x, y), g(x, y) and h(x, y) for all integers x and y such that (1 <= x <= n, 1 <= y <= n). The function sumin (sum of f) will take n as a parameter and return the sum of min(x, y) in the domain 1 <= x <= n, 1 <= y <= n. The function sumax (sum of g) will take n as a parameter and return the sum of max(x, y) in the same domain. The function sumsum (sum of h) will take n as a parameter and return the sum of x + y in the same domain. #Examples: ``` sumin(6) --> 91 sumin(45) --> 31395 sumin(999) --> 332833500 sumin(5000) --> 41679167500 sumax(6) --> 161 sumax(45) --> 61755 sumax(999) --> 665167500 sumax(5000) --> 83345832500 sumsum(6) --> 252 sumsum(45) --> 93150 sumsum(999) --> 998001000 sumsum(5000) --> 125025000000 ``` #Hint: 1. Try to avoid nested loops 2. Note that h = f + g
["def sumin(n):\n return n * (n + 1) * (2 * n + 1) // 6\n \ndef sumax(n):\n return n * (n + 1) * (4 * n - 1) // 6\n \ndef sumsum(n):\n return n * n * (n + 1)\n\n", "def sumin(n):\n# return sum(min(x+1,y+1) for y in range(n) for x in range(n))\n return sum((i+1)*(2*(n-i)-1) for i in range(n))\n \ndef sumax(n):\n# return sum(max(x+1,y+1) for y in range(n) for x in range(n))\n return sum((n-i)*(2*(n-i)-1) for i in range(n))\ndef sumsum(n):\n return sumin(n) + sumax(n)", "def sumin(n):\n return n * (n+1) * (2*n+1) / 6\n \ndef sumax(n):\n return n * (n + 1) * (4*n -1) / 6\n \ndef sumsum(n):\n return n * n * (n+1)", "def sumin(n):\n return sum(i*i for i in range(1,n+1))\n \ndef sumax(n):\n return n**3 - sumin(n-1)\n \ndef sumsum(n):\n return n**3 + n**2", "# https://en.wikipedia.org/wiki/Square_pyramidal_number\ndef sumin(n):\n return n * (n + 1) * (2 * n + 1) / 6\ndef sumax(n):\n return n * (n + 1) * (4 * n - 1) / 6\ndef sumsum(n):\n return sumin(n) + sumax(n)", "def sumin(n):\n return sum( (1+i)*i//2 + i*(n-i) for i in range(1, n+1) )\n \ndef sumax(n):\n return sum( i*i + (i+1+n)*(n-i)//2 for i in range(1, n+1) )\n \ndef sumsum(n):\n return sumin(n) + sumax(n)\n", "## Sometimes a few lines of math go a long way!\n\ndef sumin(n):\n return n*(n+1)*(2*n+1)/6\n\ndef sumax(n):\n return n*(n+1)*(2*n+1)/3 - n*(n+1)/2\n \ndef sumsum(n):\n return sumax(n)+sumin(n)\n", "sumin = lambda n: n * (n + 1) * (2 * n + 1) // 6\n \nsumax = lambda n: n * (n + 1) * (4 * n - 1) // 6\n \nsumsum = lambda n: sumin(n) + sumax(n)", "def sumin(n):\n \n lst = [i for i in range(1,n+1)]\n summa = sum(lst)\n delta = summa\n for x in lst:\n delta -=x\n summa+=delta\n return summa \n \ndef sumax(n):\n lst = [i for i in range(1,n+1)]\n summa = 0\n delta = sum(lst)\n for x in lst:\n summa+=delta\n delta +=x\n \n \n return summa \n \ndef sumsum(n):\n return sumin(n)+sumax(n)"]
{"fn_name": "sumin", "inputs": [[5], [6], [8], [15], [100], [365], [730], [4000]], "outputs": [[55], [91], [204], [1240], [338350], [16275715], [129938905], [21341334000]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,082
def sumin(n):
9940105db597562f4090bc06b0ddbc62
UNKNOWN
In this kata, your task is to create a function that takes a single list as an argument and returns a flattened list. The input list will have a maximum of one level of nesting (list(s) inside of a list). ```python # no nesting [1, 2, 3] # one level of nesting [1, [2, 3]] ``` --- # Examples ```python >>> flatten_me(['!', '?']) ['!', '?'] >>> flatten_me([1, [2, 3], 4]) [1, 2, 3, 4] >>> flatten_me([['a', 'b'], 'c', ['d']]) ['a', 'b', 'c', 'd'] >>> flatten_me([[True, False], ['!'], ['?'], [71, '@']]) [True, False, '!', '?', 71, '@'] ``` Good luck!
["def flatten_me(lst):\n res = []\n for l in lst:\n if isinstance(l, list):\n res.extend(l)\n else:\n res.append(l)\n return res\n", "def flatten_me(nput):\n output = []\n for itm in nput:\n if isinstance(itm, list):\n output += flatten_me(itm)\n else:\n output += [itm]\n return output", "def flatten_me(lst):\n res = []\n for i in lst:\n if type(i) is list:\n res += i\n else:\n res.append(i)\n return res\n", "# boo for this kata\ndef flatten_me(a):\n result = []\n for i in a:\n if isinstance(i, list):\n result += flatten_me(i)\n else:\n result.append(i)\n return result\n", "from collections import Iterable\nfrom itertools import chain\n\ndef flatten_me(lst):\n return list(chain(*(x if isinstance(x,Iterable) else [x] for x in lst)))\n", "def flatten_me(lst):\n from itertools import chain\n return list(chain.from_iterable([el] if not isinstance(el, list) else el for el in lst))", "def flatten_me(lst):\n result = []\n for item in lst:\n if isinstance(item, list):\n result.extend(item)\n else:\n result.append(item)\n return result\n", "def flatten_me(lst):\n res = []\n for x in lst:\n if type(x) == list: \n for y in x: res.append(y)\n else:\n res.append(x)\n return res\n", "def flatten_me(lst):\n out = []\n for item in lst:\n if type(item) is list: out += (x for x in item)\n else: out.append(item)\n return out\n", "def flatten_me(lst):\n return [v for sub in [e if type(e) == list else [e] for e in lst] for v in sub]"]
{"fn_name": "flatten_me", "inputs": [[[1, [2, 3], 4]], [[["a", "b"], "c", ["d"]]], [["!", "?"]]], "outputs": [[[1, 2, 3, 4]], [["a", "b", "c", "d"]], [["!", "?"]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,742
def flatten_me(lst):
7b215d4f965f30bea76903ed8be6eb04
UNKNOWN
Have you heard about Megamind? Megamind and Metro Man are two aliens who came to earth. Megamind wanted to destroy the earth, while Metro Man wanted to stop him and protect mankind. After a lot of fighting, Megamind finally threw Metro Man up into the sky. Metro Man was defeated and was never seen again. Megamind wanted to be a super villain. He believed that the difference between a villain and a super villain is nothing but presentation. Megamind became bored, as he had nobody or nothing to fight against since Metro Man was gone. So, he wanted to create another hero against whom he would fight for recreation. But accidentally, another villain named Hal Stewart was created in the process, who also wanted to destroy the earth. Also, at some point Megamind had fallen in love with a pretty girl named Roxanne Ritchi. This changed him into a new man. Now he wants to stop Hal Stewart for the sake of his love. So, the ultimate fight starts now. * Megamind has unlimited supply of guns named Magic-48. Each of these guns has `shots` rounds of magic spells. * Megamind has perfect aim. If he shoots a magic spell it will definitely hit Hal Stewart. Once hit, it decreases the energy level of Hal Stewart by `dps` units. * However, since there are exactly `shots` rounds of magic spells in each of these guns, he may need to swap an old gun with a fully loaded one. This takes some time. Let’s call it swapping period. * Since Hal Stewart is a mutant, he has regeneration power. His energy level increases by `regen` unit during a swapping period. * Hal Stewart will be defeated immediately once his energy level becomes zero or negative. * Hal Stewart initially has the energy level of `hp` and Megamind has a fully loaded gun in his hand. * Given the values of `hp`, `dps`, `shots` and `regen`, find the minimum number of times Megamind needs to shoot to defeat Hal Stewart. If it is not possible to defeat him, return `-1` instead. # Example Suppose, `hp` = 13, `dps` = 4, `shots` = 3 and `regen` = 1. There are 3 rounds of spells in the gun. Megamind shoots all of them. Hal Stewart’s energy level decreases by 12 units, and thus his energy level becomes 1. Since Megamind’s gun is now empty, he will get a new gun and thus it’s a swapping period. At this time, Hal Stewart’s energy level will increase by 1 unit and will become 2. However, when Megamind shoots the next spell, Hal’s energy level will drop by 4 units and will become −2, thus defeating him. So it takes 4 shoots in total to defeat Hal Stewart. However, in this same example if Hal’s regeneration power was 50 instead of 1, it would have been impossible to defeat Hal.
["from math import ceil\n\ndef mega_mind(hp, dps, shots, regen):\n if dps*shots >= hp: return ceil(hp / dps)\n if dps*shots <= regen: return -1\n\n number_of_regenerations = ceil((hp - dps*shots) / (dps*shots - regen))\n return ceil((hp + regen*number_of_regenerations) / dps)", "from math import ceil\n\ndef mega_mind(hp, dps, shots, regen):\n if hp > dps * shots <= regen:\n return -1\n n = 0\n while True:\n s = min(int(ceil(hp / dps)), shots)\n n += s\n hp -= dps * s\n if hp <= 0:\n break\n hp += regen\n return n", "def mega_mind(hp, dps, shots, regen):\n chp = hp\n ans = 0\n while True:\n r = (chp + dps - 1) // dps\n if r <= shots:\n return ans + r\n chp -= (dps * shots - regen)\n ans += shots\n if chp >= hp:\n return -1", "from math import ceil\n\ndef mega_mind(hp, dps, shots, regen):\n damage = dps * shots\n if hp > damage <= regen: return -1\n if hp <= damage: return ceil(hp / dps)\n full = (hp - regen) // (damage - regen)\n if damage*full == hp + (full-1)*regen: return full*shots\n left = hp + full*(regen - damage)\n return full*shots + ceil(left / dps)", "from math import ceil\ndef mega_mind(hp, dps, shots, regen):\n print(hp,dps,shots,regen)\n if hp>dps*shots and regen>=dps*shots: return -1\n if hp<=dps*shots:\n return ceil(hp/dps)\n a=ceil((hp-dps*shots)/(-regen+dps*shots))\n return a*shots + ceil((hp+a*regen-a*dps*shots)/dps)", "def mega_mind(hp, dps, shots, regen):\n if (hp > dps*shots) and dps * shots <= regen:\n return -1\n res = 0; num_shots = 0\n if hp > dps*shots:\n num_rounds = (hp-dps*shots)//(dps*shots-regen)\n res = num_rounds * shots\n hp -= num_rounds * (dps*shots-regen)\n while hp > 0:\n hp -= dps\n res += 1\n num_shots += 1\n if hp > 0 and num_shots == shots:\n hp += regen\n num_shots = 0\n return res", "import math\n\ndef mega_mind(hp, dps, shots, regen):\n if regen - dps * shots >= 0 and hp - dps * shots > 0:\n return -1\n if hp - dps * shots <= 0:\n return math.ceil(hp / dps)\n n = 0\n while hp - dps * shots > 0:\n hp -= (dps * shots - regen)\n n += 1\n return math.ceil(hp / dps) + n * shots", "def mega_mind(hp, dps, shots, regen):\n if hp> dps*shots and dps*shots<=regen:\n return -1\n total_shot = 0 #Initalize shot counter\n barell = shots #Initalize first gun\n while hp>0:\n if hp>dps*shots: #Machine gun mode\n if barell==0: #Reload\n barell+=shots\n hp+=regen\n else: #Shoot\n barell-=shots\n hp-=dps*shots\n total_shot+=shots\n else: #Gun mode\n if barell==0: #Reload\n barell+=shots\n hp+=regen\n else: #Shoot\n barell-=1\n hp-=dps\n total_shot+=1\n return total_shot\n", "def mega_mind(hp, dps, shots, regen):\n print((hp, dps, shots, regen))\n if dps * shots < hp and dps * shots <= regen: \n return -1\n dps_round = dps * shots\n if hp - dps_round <= 0:\n return hp // dps + (0 if hp % dps == 0 else 1)\n hp -= dps_round\n round = hp // (dps_round - regen)\n hp -= round * (dps_round - regen)\n if hp == 0:\n return (round + 1) * shots\n hp += regen\n print((round, hp))\n return shots * (round + 1) + hp // dps + (0 if hp % dps == 0 else 1)\n \n \n", "def mega_mind(hp, dps, shots, regen):\n if regen < dps*shots or hp <= shots*dps:\n cnt = 0\n while hp > shots*dps:\n hp = hp - shots*dps + regen\n cnt += shots\n \n for i in range(hp):\n hp = hp - dps\n cnt+= 1\n if hp <= 0:\n return cnt\n return -1"]
{"fn_name": "mega_mind", "inputs": [[12, 4, 3, 2], [9, 4, 2, 7], [13, 4, 3, 1], [13, 4, 3, 50], [36, 4, 3, 2], [15, 4, 3, 12], [100000, 99999, 100000, 100000], [100000, 100000, 100000, 100000], [100000, 1, 50000, 49999], [100000, 1, 1000, 999], [17, 4, 4, 16], [23, 4, 4, 13], [1, 4, 4, 15], [22, 4, 4, 13], [16, 4, 4, 16], [20, 4, 4, 15]], "outputs": [[3], [4], [4], [-1], [11], [-1], [2], [1], [2500050000], [99001000], [-1], [16], [1], [12], [4], [20]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,073
def mega_mind(hp, dps, shots, regen):
f55e6297f9374ccae592583b34371528
UNKNOWN
A new task for you! You have to create a method, that corrects a given time string. There was a problem in addition, so many of the time strings are broken. Time-Format is european. So from "00:00:00" to "23:59:59". Some examples: "09:10:01" -> "09:10:01" "11:70:10" -> "12:10:10" "19:99:99" -> "20:40:39" "24:01:01" -> "00:01:01" If the input-string is null or empty return exactly this value! (empty string for C++) If the time-string-format is invalid, return null. (empty string for C++) Have fun coding it and please don't forget to vote and rank this kata! :-) I have created other katas. Have a look if you like coding and challenges.
["def time_correct(t):\n if not t: return t\n try:\n h, m, s = map(int, t.split(':'))\n if s >= 60: s -= 60; m += 1\n if m >= 60: m -= 60; h += 1\n return '%02d:%02d:%02d' % (h % 24, m, s)\n except: pass", "import re\n\n\ndef time_correct(t):\n if not t:\n return t\n \n if not re.match(\"\\d\\d:\\d\\d:\\d\\d$\", t):\n return None\n \n hours, minutes, seconds = [int(x) for x in t.split(':')]\n \n if seconds >= 60:\n minutes += 1\n seconds -= 60\n if minutes >= 60:\n hours += 1\n minutes -= 60\n if hours >= 24:\n hours = hours % 24\n \n return \"{0:0>2}:{1:0>2}:{2:0>2}\".format(hours, minutes, seconds)", "def time_correct(t):\n try:\n if t==\"\":\n return \"\"\n if len(t)!=8:\n return None\n h,m,s=[int(x) for x in t.split(\":\")]\n if s>=60:\n s-=60\n m+=1\n if m>=60:\n m-=60\n h+=1\n if h>=24:\n h=h%24\n return '%02d:%02d:%02d'%(h,m,s)\n except:\n return None", "from typing import Union\nfrom re import compile\n\nr = compile(r\"(\\d\\d):(\\d\\d):(\\d\\d)\")\n\n\ndef time_correct(t: Union[str, None]) -> Union[str, None]:\n if not t:\n return t\n\n f = r.fullmatch(t)\n if f:\n h, m, s = list(map(int, f.groups()))\n h, m = divmod(h * 3600 + m * 60 + s, 3600)\n m, s = divmod(m, 60)\n\n return f\"{h % 24:02}:{m:02}:{s:02}\"\n", "def time_correct(t):\n try:\n h, m, s = (int(n) for n in t.split(\":\") if len(n) == 2)\n except (AttributeError, ValueError):\n return \"\" if t == \"\" else None\n s, m = s % 60, m + s // 60\n m, h = m % 60, (h + m // 60) % 24\n return f\"{h:02d}:{m:02d}:{s:02d}\"", "def time_correct(t):\n if not t: return t\n try:\n h, m, s = [int(x) for x in t.split(':') if len(x) == 2]\n if s >= 60: s -= 60; m += 1\n if m >= 60: m -= 60; h += 1\n return f'{h%24:02}:{m:02}:{s:02}'\n except: pass", "def time_correct(t):\n if not t :\n return t\n if len(t) != 8:\n return None\n for x in range(8):\n if (x+1) % 3 == 0:\n if t[x] != ':':\n return None\n else:\n if not t[x].isnumeric():\n return None\n hrs, mins, secs = (int(x) for x in t.split(':'))\n mins = mins + secs // 60\n hrs = (hrs + mins // 60) % 24\n mins, secs = mins % 60, secs % 60\n return str(hrs).zfill(2) + ':' + str(mins).zfill(2) + ':' + str(secs).zfill(2)\n \n \n", "import re\n\ndef time_correct(t):\n if not t:\n return t\n if re.match(r'\\d\\d:\\d\\d:\\d\\d$', t):\n hours, minutes, seconds = list(map(int, t.split(':')))\n d_minutes, seconds = divmod(seconds, 60)\n d_hours, minutes = divmod(minutes + d_minutes, 60)\n hours = (hours + d_hours) % 24\n return '{:02d}:{:02d}:{:02d}'.format(hours, minutes, seconds)\n", "import re\n\ndef time_correct(t):\n if not t:\n return t\n \n if not re.match('^\\d\\d:\\d\\d:\\d\\d$', t):\n return None\n \n h, m, s = map(int, t.split(':'))\n \n o, s = divmod(s, 60)\n o, m = divmod(m + o, 60)\n o, h = divmod(h + o, 24)\n \n return '%02d:%02d:%02d' % (h, m, s)", "def time_correct(t):\n if t == \"\":\n return \"\"\n \n from re import findall, VERBOSE\n \n try:\n time = findall(\"\"\"\\A\n (\\d{2}):\n (\\d{2}):\n (\\d{2})\n \\Z\"\"\", t, VERBOSE)\n\n hr,mn,sc = [int(x) for x in time[0]]\n \n mn += sc // 60\n sc %= 60\n hr += mn // 60\n mn %= 60\n hr %= 24\n \n return \"{:02d}:{:02d}:{:02d}\".format(hr, mn, sc)\n except:\n return None", "import re\n\ndef time_correct(t):\n if t == '':\n return ''\n if not t or not re.search(\"[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\", t):\n return None\n time = list(map(int, t.split(':')))\n for i in range(2, 0, -1):\n time[i-1] += 1 * time[i] // 60\n time[i] = ('0' + str(time[i] % 60))[-2:]\n time[0] = ('0' + str(time[0]%24))[-2:]\n return ':'.join(time)", "import re\n\ndef time_correct(t):\n if not t : return t\n if not bool(re.match(r\"\\d{2}:\\d{2}:\\d{2}$\",t)) : return None\n h,m,s=map(int,t.split(\":\"))\n sec=h*3600+m*60+s\n sec%=(3600*24)\n return \"{:02}:{:02}:{:02}\".format(sec//3600,(sec%3600)//60,sec%60)", "import re\n\ndef time_correct(t):\n if not t: return t\n \n m = re.findall(r'^(\\d{2}):(\\d{2}):(\\d{2})$', t)\n if m:\n h, m, s = map(int, m[0])\n if s >= 60:\n m += 1\n s %= 60 \n if m >= 60:\n h += 1\n m %= 60\n h %= 24\n return f\"{h:02}:{m:02}:{s:02}\"", "def time_correct(t):\n if t == '':\n return ''\n try:\n h,m,s = map(int,t.split(':'))\n m += 1 if s>=60 else 0\n s %= 60\n h += 1 if m>=60 else 0\n m %= 60\n h %= 24\n return f'{h:02}:{m:02}:{s:02}'\n except:\n return None", "def time_correct(t):\n if t is None:\n return\n if t == \"\":\n return \"\"\n if len(t) != 8:\n return\n try:\n h, m, s = [int(i) for i in t.split(':')]\n except:\n return\n if s >= 60:\n s = s - 60\n m = m + 1\n if m >= 60:\n m = m - 60\n h = h + 1\n h = h % 24\n return ':'.join([str(h).rjust(2,'0'), str(m).rjust(2,'0'), str(s).rjust(2,'0')])\n", "def time_correct(t):\n if not t: return t \n try:\n h, m, s = t.split(':')\n if (len(h) != 2) or (len(m) != 2) or (len(s) != 2) : return None\n h, m, s = list(map(int, t.split(':')))\n if s >= 60: s -= 60; m += 1\n if m >= 60: m -= 60; h += 1\n return '%02d:%02d:%02d' % (h%24, m, s)\n except:\n pass\n", "def time_correct(t):\n if t is None or t == \"\":\n return t \n x = [int(string) for string in t.split(\":\") if string.isnumeric()]\n if len(x) != 3 or t.count(\":\") != 2:\n return None\n x[1] += x[2]//60\n x[2] %= 60\n x[0] += x[1]//60\n x[1] %= 60\n x[0] %= 24\n return f\"{x[0]:02}:{x[1]:02}:{x[2]:02}\"\n \n", "import re\n\ndef time_correct(t):\n if t == '':\n return ''\n \n if t is None or len(t.split(':')) != 3:\n return None\n \n try:\n p = re.compile('^\\d{2}$')\n \n h, m, s = [int(n) for n in t.split(':') if p.search(n)]\n \n except:\n return None\n \n if s >= 60: \n m += (s // 60)\n s = (s - ((s // 60 ) * 60))\n if m >= 60:\n h += (m // 60)\n m = (m - ((m // 60 ) * 60))\n \n if h == 24:\n h = 0\n elif h > 24:\n h = h % 24\n \n return f\"{'0' + str(h) if h < 10 else h}:{'0' + str(m) if m < 10 else m}:{'0' + str(s) if s < 10 else s}\"\n", "def time_correct(t):\n if not t:\n return t\n \n t = t.split(':')\n if len(t) != 3 or not all(len(u) == 2 and u.isdecimal() for u in t):\n return None\n \n hr, min, sec = map(int, t)\n min, sec = min + sec // 60, sec % 60\n hr, min = (hr + min // 60) % 24, min % 60\n return f'{hr:02}:{min:02}:{sec:02}'", "from re import match\ndef time_correct(t):\n if not t:return t\n if match(\"\\d{2}:\\d{2}:\\d{2}\",t):\n hour,minute,second=map(int,t.split(\":\"))\n m,second=divmod(second,60)\n minute+=m\n h,minute=divmod(minute,60)\n hour=(hour+h)%24\n return f\"{hour:0>2d}:{minute:0>2d}:{second:0>2d}\"", "def time_correct(t=None):\n if t=='':\n return ''\n elif t==None or len(t)!=8 or t[2]!=':' or t[5]!=':':\n return None\n elif (t[0:2]+t[3:5]+t[6:]).isdigit():\n if int(t[6:])>=60:\n ts=str(int(t[6:])%60).zfill(2)\n tsp=int(t[6:])//60\n else:\n ts=t[6:].zfill(2)\n tsp=0\n if int(t[3:5])+tsp>=60:\n tm=str((int(t[3:5])+tsp)%60).zfill(2)\n tmp=(int(t[3:5])+tsp)//60\n else:\n tm=str(int(t[3:5])+tsp).zfill(2)\n tmp=0\n if int(t[0:2])+tmp>=24:\n th=str((int(t[0:2])+tmp)%24).zfill(2)\n else:\n th=str(int(t[:2])+tmp).zfill(2)\n return th+':'+tm+':'+ts\n else:\n return None\n", "import re\n\ndef time_correct(t):\n #messy\n if not t: return t\n if not re.match(r'^[0-9]{2}:[0-9]{2}:[0-9]{2}$', str(t)): return None\n tl = list(map(int, t.split(':')))\n for i in range(2, 0, -1):\n while tl[i] >= 60:\n tl[i] -= 60\n tl[i-1] += 1\n while tl[0] >= 24:\n tl[0] -= 24\n return ':'.join([\"{:02d}\".format(te) for te in tl])\n", "def time_correct(t):\n \n try:\n if t == None:\n return None\n \n if t == \"\":\n return \"\"\n \n if len(t) < 8:\n return None\n \n for char in t:\n if not (char.isdigit() or char == ':'):\n return None\n \n # get numerical values from string\n times = t.split(':')\n hours = int(times[0])\n minutes = int(times[1])\n seconds = int(times[2])\n \n # correct values\n minutes += seconds // 60 \n seconds = seconds % 60\n hours += minutes // 60 \n minutes = minutes % 60\n hours = hours % 24\n \n #process values into string format\n hours = str(hours) if len(str(hours))==2 else ('0' + str(hours))\n minutes = str(minutes) if len(str(minutes))==2 else ('0' + str(minutes))\n seconds = str(seconds) if len(str(seconds))==2 else ('0' + str(seconds))\n \n return f\"{hours}:{minutes}:{seconds}\"\n\n except:\n return None\n", "from re import match\ndef time_correct(t):\n if not t:\n return t\n elif not match(\"\\d\\d\\:\\d\\d\\:\\d\\d\", t):\n return None\n fragments = list(map(int, t.split(\":\")))\n if fragments[2] >= 60:\n fragments[1] += 1\n fragments[2] -= 60\n if fragments[1] >= 60:\n fragments[0] += 1\n fragments[1] -= 60\n fragments[0] %= 24\n return \"{:02}:{:02}:{:02}\".format(*fragments)", "import re\ndef time_correct(t):\n if not t: return t\n if not re.fullmatch('^\\d\\d:\\d\\d:\\d\\d$',t):\n return None\n \n h,m,s = map(int,t.split(':'))\n return'{:02d}'.format((h+(m+s//60)//60)%24)+':'+'{:02d}'.format((m+s//60)%60)+':'+'{:02d}'.format(s%60) ", "import re\ndef time_correct(t):\n if t == '':\n return ''\n if t and re.search(r'[0-9]{2}:[0-9]{2}:[0-9]{2}', t):\n sec = int(t[-2:])\n min = int(t[3:5])\n hr = int(t[:2])\n if sec > 59:\n sec -= 60\n min += 1\n if min > 59:\n min -= 60\n hr += 1\n if hr > 23:\n hr -= hr//24*24\n return '{:02d}:{:02d}:{:02d}'.format(hr, min, sec)\n return None", "def time_correct(t):\n # check for emptiness\n if not t:\n return t\n # check only for the allowed symbols\n for i in t:\n if i not in \"1234567890:\":\n return None\n # check for length\n slot = t.split(\":\")\n for k,i in enumerate(slot):\n try:\n if len(slot[k])>2:\n return None\n slot[k]=int(slot[k])\n except ValueError:\n return None\n if len(slot)!=3:\n return None\n # point, you can't iterate, 24 - h, 60 - m,s \n slot[1] += slot[2]//60 \n slot[0] += slot[1]//60 \n slot[2] = slot[2]%60\n slot[1] = slot[1]%60\n slot[0] = slot[0]%24 \n return \":\".join([str(x).zfill(2) for x in slot])\n \n # https://stackoverflow.com/questions/733454/best-way-to-format-integer-as-string-with-leading-zeros\n", "import re\ndef time_correct(t):\n if t == None: return None\n pattern = r\"[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\"\n if re.search(pattern, t):\n t = t.split(':')[::-1]\n for i in range(0,2):\n if int(t[i]) > 59:\n t[i+1] = str(int(t[i+1]) + int(t[i]) // 60)\n t[i] = str(int(t[i]) % 60)\n t[2] = str(int(t[2]) % 24)\n return ':'.join(i.zfill(2) for i in t[::-1])\n else:\n if len(t) > 0: return None\n else:\n return t", "from re import match\nfrom time import strftime\nfrom time import gmtime\ndef time_correct(t):\n if not t: return t\n if not match('\\d{2}:\\d{2}:\\d{2}',t): return None\n hrs,mnt,sec = [int(x) for x in t.split(\":\")]\n total = (hrs * 3600 + mnt * 60 + sec)\n return strftime(\"%H:%M:%S\", gmtime(total))\n", "from re import match\n\ndef time_correct(t):\n if not t:\n return t\n \n if not match(\"^\\d{2}\\:\\d{2}\\:\\d{2}$\", t):\n return None\n \n arr = [int(s) for s in t.split(':')]\n \n for i in range(2, 0, -1):\n if arr[i] > 59:\n arr[i - 1] += arr[i] // 60\n arr[i] = arr[i] % 60\n \n arr[0] = arr[0] % 24\n return ':'.join(str(num).zfill(2) for num in arr)", "import re\nfrom datetime import time\n\ndef time_correct(t):\n print(t)\n if not t:\n return t\n if not re.match(r\"\\d\\d:\\d\\d:\\d\\d\", t):\n return None\n H,M,S = [int(item) for item in t.split(\":\")]\n \n m,s = (M + S//60),S%60\n h,m = (H + m//60)%24,m%60\n \n return str(time(h,m,s))", "def time_correct(t):\n if t is None: return None\n if t is '': return ''\n try:\n h,m,s = map(int, t.split(':'))\n m += s // 60\n s = s % 60\n h += m // 60\n m = m % 60\n h = h % 24\n return '{:02}:{:02}:{:02}'.format(h,m,s)\n except:\n return None", "def time_correct(t):\n if t == \"\": return \"\"\n if not t: return None\n if len(t.split(\":\")) != 3: return None\n h, m, s = t.split(\":\")\n if not h.isdigit() or not m.isdigit() or not s.isdigit(): return None\n if len(h)!=2 or len(m)!=2 or len(s)!=2: return None\n sec = int(s)%60\n min = (int(m) + int(s)//60)%60\n hour = (int(h) + (int(m) + int(s)//60)//60)%24\n return \"{:02}:{:02}:{:02}\".format(hour, min, sec)", "import re\ndef time_correct(t):\n if t is None or t=='':\n return t\n if not re.match('[0-9][0-9]:[0-9][0-9]:[0-9][0-9]$',t):\n return None\n h,m,s = map(int, t.split(':'))\n if s>59:\n s-=60\n m+=1\n if m>59:\n m-=60\n h+=1\n while h>23:\n h-=24\n return ':'.join(f'{x:02}' for x in [h,m,s])", "from re import match\n\nis_valid = lambda s: isinstance(s, str) and bool(match(r'^\\d\\d:\\d\\d:\\d\\d$', s))\n\ndef time_correct(sd):\n if sd == '': return sd\n if is_valid(sd):\n h, m, s = list(map(int, sd.split(':')))\n q, r = divmod(s, 60)\n m, s = m + q, r\n q, r = divmod(m, 60)\n h, m = (h + q) % 24, r\n return f'{h:02}:{m:02}:{s:02}'", "def time_correct(t):\n if t=='':\n return ''\n elif t:\n l=t.split(':')\n if len(l)==3 and all(i.isdigit() for i in l):\n a,b=divmod(int(l[2]),60)\n l[2]=str(b).zfill(2)\n c,d=divmod(int(l[1])+a,60)\n l[1]=str(d).zfill(2)\n l[0]=str((int(l[0])+c)%24).zfill(2)\n return ':'.join(l)", "import re\n\ndef time_correct(time_string):\n if time_string in (\"\", None): return time_string\n if not re.fullmatch(r\"\\d\\d:\\d\\d:\\d\\d\", time_string): return None\n h, m, s = map(int, time_string.split(\":\"))\n total_seconds = 3600 * h + 60 * m + s\n final_seconds = total_seconds % 60\n final_minutes = (total_seconds // 60) % 60\n final_hours = (total_seconds // 3600) % 24\n return f\"{final_hours:02d}:{final_minutes:02d}:{final_seconds:02d}\"", "from re import compile\n\nREGEX = compile(r\"(\\d{2}):(\\d{2}):(\\d{2})\").search\n\ndef time_correct(t):\n if not t: return t\n try:\n H, M, S = map(int, REGEX(t).groups())\n q, S = divmod(S, 60)\n q, M = divmod(M+q, 60)\n H = (H+q)%24\n return f\"{H:02}:{M:02}:{S:02}\"\n except AttributeError:\n pass", "def time_correct(t):\n try:\n k = t.split(\":\")\n\n except:\n return None\n if t==\"\":\n return \"\"\n if len(k)<3:\n return None\n p = []\n res = 0\n for a in k[::-1]:\n if len(str(a))!=2:\n return None\n if len(p)<2:\n try:\n p.append(format((int(a)+res)%60, '02d'))\n except:\n return None\n res = (int(a) + res - int(p[-1]))//60\n else:\n try:\n p.append((format((int(a)+res)%24, '02d')))\n except:\n return None\n return \":\".join(p[::-1])", "import re\ndef time_correct(t):\n if t == '': \n return \"\"\n if not t: return \n if not re.match(r'\\d{2}:\\d{2}:\\d{2}', t):\n return None\n s = int(t[6:])\n m = int(t[3:5])\n h = int(t[:2])\n if s >= 60:\n m += s // 60\n s = s % 60\n if m >= 60:\n h += m // 60\n m = m % 60\n if h >= 24:\n h = h % 24\n return ':'.join(str(i).zfill(2) for i in [h, m, s])", "def time_correct(t):\n if t == \"\": return \"\"\n if not t or len(t) != 8 or not (t[0:2] + t[3:5] + t[6:8]).isdigit() or not t[2] + t[5] == \"::\": return None\n return \"%s:%s:%s\" %(str((int(t[0:2]) + ((int(t[3:5]) + (int(t[6:8]) // 60)) // 60)) % 24).zfill(2), \\\n str((int(t[3:5]) + (int(t[6:8]) // 60)) % 60).zfill(2), str(int(t[6:8]) % 60).zfill(2))", "import re\n\ndef time_correct(t):\n if t is None or not t:\n return t\n if not re.match(r'^(\\d\\d:){2}\\d\\d$', t):\n return None\n seconds = sum(int(c, 10) * 60 ** (2-i) for i, c in enumerate(t.split(':')))\n return '{:02d}:{:02d}:{:02d}'.format(seconds // 3600 % 24, seconds // 60 % 60, seconds % 60)", "def time_correct(t):\n print(t)\n if t is not None:\n if not t:\n return \"\"\n t=t.split(\":\")\n if sum(1 for x in t if x.isdigit() and len(x)==2) == 3:\n out=[]\n to_add=0\n for i,v in enumerate(t[::-1]):\n v=int(v)+to_add\n if i < 2:\n to_add=v//60\n out.append((\"0\"+str(v%60))[-2:])\n else:\n out.append((\"0\"+str(v%24))[-2:])\n return ':'.join(out[::-1])", "import re\ndef time_correct(t):\n if t and re.match(r\"\\d\\d:\\d\\d:\\d\\d\", t):\n h,m,s = t.split(\":\")\n seconds = int(s)\n minutes = int(m) + seconds // 60\n hours = int(h) + minutes // 60\n return \"%02d:%02d:%02d\" % (hours % 24, minutes % 60, seconds % 60)\n return None if t != '' else ''\n", "def time_correct(t):\n import re\n if t==None:\n return None\n if t==\"\":\n return \"\"\n r = re.compile('\\d\\d:\\d\\d:\\d\\d')\n if r.match(t) == None:\n return None\n \n sec = int(t[6:])\n mnt = int(t[3:5])\n hr = int(t[0:2])\n \n if sec > 59:\n sec = sec % 60\n mnt += 1\n if mnt > 59:\n mnt = mnt % 60\n hr += 1\n hr = hr % 24\n \n return str(hr).zfill(2)+\":\"+str(mnt).zfill(2)+\":\"+str(sec).zfill(2)", "def time_correct(t):\n try:\n if t == None: return t\n if t == \"\": return t\n if len(t) == 8:\n if t.count(\":\") > 0:\n t = t.split(\":\")\n if t[0] == \"00\":\n first = 0\n else:\n first = int(t[0])\n second = int(t[1])\n third = int(t[2])\n if third >= 60:\n third -= 60\n second += 1\n if second >= 60:\n second -= 60\n first += 1\n while first >= 24:\n first -= 24\n return \"{}:{}:{}\".format(str(first).zfill(2), str(second).zfill(2), str(third).zfill(2))\n except:\n return None", "import re\n\ndef fmt(t):\n t = f\"{t}\"\n return t if len(t) == 2 else \"0\"+t\n\ndef time_correct(t):\n if t is None: return None\n if t == \"\": return \"\"\n if not re.fullmatch(r\"\\d{2}:\\d{2}:\\d{2}\", t): return None\n s = sum(int(x)*(60**i) for i,x in enumerate(t.split(\":\")[::-1]))\n h,m,s = s//3600%24, s//60%60, s%60\n return f\"{fmt(h)}:{fmt(m)}:{fmt(s)}\"", "def time_correct(t):\n if not t:\n return t\n try:\n h,m,s=map(int,t.split(':'))\n if s>=60:\n s-=60\n m+=1\n if m>=60:\n m-=60\n h+=1\n h%=24\n return '{:02d}:{:02d}:{:02d}'.format(h,m,s)\n except:\n return None", "def time_correct(time):\n if not time:\n return time\n try:\n hours, minutes, seconds = time.split(':')\n except ValueError:\n return None\n for time in (hours, minutes, seconds):\n if len(time) != 2 or not time.isnumeric():\n return None\n try:\n seconds = int(hours) * 3600 + int(minutes) * 60 + int(seconds)\n except ValueError:\n return None\n hours = seconds // 3600\n seconds -= hours * 3600\n hours %= 24\n minutes = seconds // 60\n seconds -= minutes * 60\n final = []\n for time in (hours, minutes, seconds):\n final.append(str(time).zfill(2))\n return ':'.join(final)", "import re\n\ndef time_correct(t):\n pattern = r\"^[0-9][0-9]:[0-9][0-9]:[0-9][0-9]$\"\n\n if t == \"\":\n return \"\"\n elif t == None:\n return None\n\n if re.match(pattern, t):\n time = t.split(\":\")\n\n hour = int(time[0])\n minute = int(time[1])\n second = int(time[2])\n\n if second >= 60:\n second = second % 60\n carry = 1\n minute = minute + carry\n carry = 0\n\n if minute >= 60:\n minute = minute % 60\n carry = 1\n hour = hour + carry\n\n if hour >= 24:\n hour = hour % 24\n\n hour = str(hour)\n minute = str(minute)\n second = str(second)\n if len(hour) == 1:\n hour = \"0\" + hour\n if len(minute) == 1:\n minute = \"0\" + minute\n if len(second) == 1:\n second = \"0\" + second\n\n return hour + \":\" + minute + \":\" + second\n else:\n return None", "import re\nimport datetime as dt\ndef time_correct(text):\n if not text:\n return text\n try:\n h, m, s = map(int, re.match(r'^(\\d{2}):(\\d{2}):(\\d{2})$', text).groups())\n mo, m = divmod(m - 1, 60)\n return ((dt.datetime.combine(dt.date(1,1,1),dt.time((h + mo)%24, m + 1, 1)) + dt.timedelta(seconds=s - 1))).strftime('%H:%M:%S')\n except AttributeError:\n return None #your code here", "def time_correct( t ):\n if t is None:\n return None\n if t == \"\":\n return \"\"\n if t.count( \":\" ) != 2 or len( t ) != 8:\n return None\n tt = t.replace( \":\", \"\" )\n if (not tt.isdigit()):\n return None\n h, m, s = int( tt[ 0:2 ] ), int( tt[ 2:4 ] ), int( tt[ 4: ] )\n if s >= 60:\n m += 1\n s %= 60\n if m >= 60:\n h += 1\n m %= 60\n h %= 24\n return \"{:02d}:{:02d}:{:02d}\".format( h, m, s )\n", "import re\n\ndef time_correct(t):\n if not t:\n return t\n \n if not re.match(\"\\d\\d:\\d\\d:\\d\\d$\", t):\n return None\n \n hours,minutes,seconds = t.split(':')\n hours,minutes,seconds = int(hours), int(minutes), int(seconds)\n \n while seconds > 59:\n minutes+=1\n seconds-=60\n\n \n while minutes > 59:\n hours+=1\n minutes-=60\n\n \n while hours >= 24:\n hours-=24\n \n return '{:02}:{:02}:{:02}'.format(hours,minutes,seconds)\n \n", "import re\n\ndef valid_format(s):\n return bool(re.match('^\\d\\d:\\d\\d:\\d\\d$', s))\n\ndef time_correct(t):\n if not t:\n return t\n if not valid_format(t):\n return None\n h, m, s = map(int, t.split(':'))\n total = 3600 * h + 60 * m + s\n s = total % 60\n m = (total // 60) % 60\n h = (total - m * 60 - s) // 3600 % 24\n \n return \"{:02d}:{:02d}:{:02d}\".format(h, m, s)", "import re\n\ndef time_correct(t):\n if not isinstance(t, str):\n return None\n if t == '':\n return t\n if not re.match(r'^\\d{2}:\\d{2}:\\d{2}$', t):\n return None\n \n t_tot = sum(60**i * int(e) for i, e in enumerate(t.split(':')[::-1]))\n return f'{t_tot // 3600 % 24:02}:{t_tot // 60 % 60:02}:{t_tot % 60:02}'\n", "from datetime import datetime\n\ndef time_correct(t):\n if t == '': return ''\n if not t: return None\n t = t.split(':')\n if len(t) < 3: return None\n \n try:\n t = list(map(int, t))\n except:\n return None\n\n seco = t[2] % 60\n minu = t[1] % 60 + t[2] // 60\n hour = t[0] % 24 + t[1] // 60\n\n hour = str(hour % 24 + minu // 60).zfill(2)\n minu = str(minu % 60 + seco // 60).zfill(2)\n seco = str(seco % 60).zfill(2)\n \n return ':'.join([hour, minu, seco])", "def time_correct(t):\n if t == '':\n return t\n if not t or len(t.split(':')) != 3 :\n return None\n elif any( (not i.isdigit() for i in t.replace(':', ''))):\n return None\n elif any((len(i) != 2 for i in t.split(':'))): \n return None\n else:\n h, m, s = list(map(int, t.split(':')))\n if m < 60 and s < 60 and h < 24:\n return t\n else:\n s_1 = s%60\n s_2 = s//60\n m_1 = (s_2 +m)%60\n m_2 = (s_2 + m)//60\n h_1 = h + m_2 if (h + m_2)<24 else (h + m_2)%24\n return '{:02d}:{:02d}:{:02d}'.format(h_1, m_1, s_1)\n", "def time_correct(t):\n if t == \"\" : return \"\"\n if not t or \"+\" in t: return None\n try:\n h,m,s = map(int,t.split(':'))\n except:\n return None\n m += s//60\n s = s % 60\n h += m //60\n m = m %60\n h = h%24\n return f'{h:02}:{m:02}:{s:02}'", "def time_correct(t):\n if not t: return t\n if len(t)!=8 or t[2]!=':' or t[5]!=\":\" or any(not t[i].isdigit() for i in (0,1,3,4,6,7)): \n return None\n h,m,s=[int(t[o:o+2]) for o in (0,3,6)]\n if s>59:\n m+=s//60\n s%=60\n if m>59:\n h+=m//60\n m%=60\n h%=24\n return '{:02}:{:02}:{:02}'.format(h,m,s)", "import re\ndef time_correct(x):\n if x==None or x==\"\":\n return(x)\n x1=0\n x2=0\n for i in x:\n if 48<=ord(i)<=57:\n x1+=1\n elif ord(i)==58:\n x2+=1\n if not(x1==6 and x2==2):\n return(None)\n x=x.split(\":\")\n s1=int(x[0])\n s2=int(x[1])\n s3=int(x[2])\n s=(s1*3600+s2*60+s3)%86400\n s1=str(s//3600)\n s2=str((s%3600)//60)\n s3=str(s%60)\n if len(s1)==1:\n s1=\"0\"+s1\n if len(s2)==1:\n s2=\"0\"+s2\n if len(s3)==1:\n s3=\"0\"+s3\n return(s1+\":\"+s2+\":\"+s3)", "def time_correct(t):\n if t == '':\n return ''\n elif t == None:\n return None\n tmp = [0, 0, 0]\n for i in t:\n if '0' <= i <= '9':\n tmp[0] += 1\n elif i == ':':\n tmp[1] += 1\n else:\n tmp[2] += 1\n if not (tmp[0] == 6 and tmp[1] == 2):\n return None\n else:\n tt = list(map(int, t.split(':')))\n tt[1]+=tt[2]//60\n tt[0]+=tt[1]//60\n tt[2]%=60\n tt[1]%=60\n tt[0] -= tt[0]//24 * 24\n return \"%02d:%02d:%02d\"%(tt[0],tt[1],tt[2])", "import time\nimport re\ndef time_correct(t):\n if t == \"\":\n return \"\"\n else:\n if t is None or not re.match(r\"\\d{2}:\\d{2}:\\d{2}\", t):\n return None\n else:\n h, m, s = [int(i) for i in t.split(\":\")]\n return f\"{time.strftime('%H:%M:%S', time.gmtime(3600*h + 60*m + s))}\"", "def time_correct(t):\n if t=='':return t\n try:\n t = t.split(':')\n assert(len(t) == 3) \n assert(len(t[1])==2)\n assert(len(t[2])==2)\n t = list(map(int, t))\n if t[2] > 59: t[1], t[2] = t[1]+1, t[2]-60\n if t[1] > 59: t[0], t[1] = t[0]+1, t[1]-60\n t[0] %= 24\n t = [\"%02d\" % _ for _ in t]\n return ':'.join(t)\n except Exception as e: print(e)", "import re\ndef time_correct(t):\n if(t in [None,\"\"]):\n return t\n if(not(re.match(r\"\\d\\d\\:\\d\\d\\:\\d\\d\",t))):\n return None\n\n parts = list(map(int,t.split(':')))\n for i in range(2,0,-1):\n parts[i-1] += parts[i]//60\n parts[i] %= 60\n parts[0] %= 24\n return \":\".join(\"{:02}\".format(p) for p in parts)\n", "import re\ndef time_correct(t):\n if not t: return t\n if not re.match(r\"(\\d{2}:){2}\\d{2}\", t): return None\n h, m, s = map(int, t.split(\":\"))\n t = h * 3600 + m * 60 + s\n h = t // 3600 % 24; t %= 3600\n m = t // 60; t %= 60\n return f\"{h:0>2}:{m:0>2}:{t:0>2}\"", "import re\ndef time_correct(t):\n if t in [\"\", None]: return t\n if not re.match(r\"(\\d{2}:){2}\\d{2}\", t): return None\n h, m, s = map(int, t.split(\":\"))\n t = h * 3600 + m * 60 + s\n h = t // 3600 % 24; t %= 3600\n m = t // 60; t %= 60\n return f\"{h:0>2}:{m:0>2}:{t:0>2}\"", "import re\ndef time_correct(t):\n if t and re.search(r'\\d{2}:\\d{2}:\\d{2}', t): \n h, m, s = [int(s) for s in t.split(':')]\n m, s = m+(s//60), s%60\n h, m = h+(m//60), m%60\n h = h%24\n return f'{h:02}:{m:02}:{s:02}'\n else:\n return '' if t=='' else None", "def time_correct(t):\n if t == \"\":\n return t\n\n if not t or \":\" not in t or len(t.split(\":\")) != 3 or any(c.isalpha() for c in t) or any(not c.isdigit() and c != \":\" for c in t):\n return None\n\n h, m, s = (int(i) for i in t.split(\":\"))\n\n if s > 59:\n m += 1\n s -= 60\n\n if m > 59:\n h += 1\n m -= 60\n\n while h > 23:\n h -= 24\n\n return \":\".join([str(h).rjust(2, \"0\"), str(m).rjust(2, \"0\"), str(s).rjust(2, \"0\")])\n", "def time_correct(t):\n if t == \"\":\n return \"\"\n elif t == None:\n return None\n elif len(t) != 8 or len(t.split(':')) != 3 or not all(x.isdigit() for x in t.split(':')):\n return None\n \n t_list = [int(x) for x in t.split(':')]\n if t_list[2] > 59:\n t_list[1] += 1\n t_list[2] -= 60\n if t_list[1] > 59:\n t_list[0] += 1\n t_list[1] -= 60\n while t_list[0] >= 24:\n t_list[0] -= 24\n return '{:02d}:{:02d}:{:02d}'.format(t_list[0],t_list[1],t_list[2])", "def time_correct(t):\n if t is None:\n return None\n if t == \"\":\n return\"\"\n if len(t) < 8:\n return None\n count = 0\n for letter in t:\n if letter not in \"0123456789:\":\n return None\n if letter in \"0123456789\":\n count += 1\n if count > 6:\n return None\n x = int(t[-2:])\n y = int(t[3:5])\n z = int(t[:2])\n if x >= 60:\n x = x - 60\n y = y + 1\n if y >= 60:\n y = y - 60\n z = z + 1\n if z >= 24:\n z = z - ((z // 24) * 24)\n\n if z <= 9:\n z = \"0\" + str(z)\n if y <= 9:\n y = \"0\" + str(y)\n if x <= 9:\n x = \"0\" + str(x)\n\n return str(z) + \":\" + str(y) + \":\" + str(x)", "def is_valid_int(s):\n if len(s) != 2:\n return False\n\n try:\n int(s)\n return True\n except ValueError:\n return False\n\ndef time_correct(t):\n\n if t == None: return None\n elif t == \"\": return \"\"\n \n t_lst = t.split(':')\n \n if len(t_lst) != 3: return None\n\n if not is_valid_int(t_lst[0]) or not is_valid_int(t_lst[1]) or not is_valid_int(t_lst[2]):\n return None\n\n\n\n t_lst = [int(val) for val in t_lst]\n\n seconds = t_lst[2]\n minutes = t_lst[1]\n hours = t_lst[0]\n\n if seconds > 59:\n minutes += int(seconds / 60)\n seconds = seconds % 60\n \n if minutes > 59:\n hours += int(minutes / 60)\n minutes = minutes % 60\n\n if hours >= 24:\n hours = int(hours % 24)\n \n return '{:02d}:{:02d}:{:02d}'.format(hours,minutes,seconds)", "import re\ndef time_correct(t):\n if t == '':\n return t\n if t == None:\n return None\n if re.match('\\d\\d:\\d\\d:\\d\\d$',t): \n h,m,s = [int(i) for i in t.split(':')]\n if s > 59:\n m += 1\n s -= 60\n if m > 59:\n h += 1\n m -= 60\n while h > 23:\n h -= 24\n return '{:02d}:{:02d}:{:02d}'.format(h,m,s)\n", "time_correct = lambda t: t if not t else '{:02d}:{:02d}:{:02d}'.format(*((lambda q: [(q//3600)%24, (q%3600)//60 ,q%60] ) (sum([a*b for a, b in zip([3600,60,1],map(int, t.split(':')))])))) if __import__('re').match(\"^\\d\\d:\\d\\d:\\d\\d$\", t) else None", "import re\ndef time_correct(t):\n if t == '':\n return ''\n if not t or not re.search(\"[0-9][0-9]:[0-9][0-9]:[0-9][0-9]\", t):\n return None \n t= t.split(':')\n hour, min, sec = [int(x) for x in t]\n if sec > 59:\n min += (sec / 60)\n sec %= 60\n if min > 59:\n hour += (min / 60)\n min %= 60\n if hour > 23:\n hour %= 24\n return \"%02d:%02d:%02d\" %(hour, min, sec)\n", "def time_correct(t):\n if t is None or len(t) == 0:\n return t\n nums = t.split(\":\")\n if len(nums) != 3:\n return None\n for num in nums:\n if not num.isdigit():\n return None\n hour, min, sec = [int(x) for x in nums]\n if sec > 59:\n min += (sec / 60)\n sec %= 60\n if min > 59:\n hour += (min / 60)\n min %= 60\n if hour > 23:\n hour %= 24\n return \"%02d:%02d:%02d\" %(hour, min, sec)\n \n", "from re import match\n\ndef pad(n):\n return \"0\" + str(n) if n < 10 else str(n)\n\ndef time_correct(t):\n if not t: return t\n if not match('\\d{2}:\\d{2}:\\d{2}', t): return None\n h, m, s = map(int, t.split(\":\"))\n secs = (h * 3600 + m * 60 + s) % (24 * 3600)\n h, m, s = secs // 3600, (secs % 3600) // 60, secs % 60\n return \":\".join(map(pad, [h, m, s]))", "import re\n\ndef time_correct(t):\n if t == None or t == '':\n return t\n t_pattern = re.compile(r'\\d\\d:\\d\\d:\\d\\d')\n if t_pattern.search(t) == None:\n return None\n hours, minutes, seconds = [int(x) for x in t.split(':')]\n if seconds > 59:\n seconds = seconds - 60\n minutes = minutes + 1\n if minutes > 59:\n minutes = minutes - 60\n hours = hours + 1\n if hours == 24:\n hours = 0\n if hours > 24:\n hours = hours%24\n return '{:02}:{:02}:{:02}'.format(hours, minutes, seconds)\n\n\n \n \n", "def time_correct(t):\n if t is None: return None\n if t == '': return ''\n if len(t) != 8: return None\n t = t.split(':')\n if len(t) != 3 or sum(1 for v in t if not v.isdigit()) != 0: return None\n t = [int(a) for a in t]\n s = (t[0] * 3600 + t[1] * 60 + t[2]) % (3600 * 24)\n return \"%02d:%02d:%02d\" % (s // 3600, s % 3600 // 60, s % 60)", "from re import match\n\ndef time_correct(t):\n if not t:\n return t\n g = match('^(\\d{2}):(\\d{2}):(\\d{2})$', t)\n if g:\n h, m, s = map(int, g.groups())\n m += s // 60\n s %= 60\n h = (h + (m // 60)) % 24\n m %= 60\n return '{:02}:{:02}:{:02}'.format(h, m, s)", "def time_correct(t):\n\n if t == None:\n return None\n elif t == \"\":\n return \"\"\n elif len(t) != 8:\n return None\n \n time = t.split(':')\n \n if len(time) != 3:\n return None\n for i in time:\n if i.isdigit() == False:\n return None\n \n sec = [int(time[2]) // 60, int(time[2]) % 60]\n min = [(int(time[1]) + sec[0]) // 60 , (int(time[1]) + sec[0]) % 60]\n hour = [(int(time[0]) + min[0]) % 24]\n \n time = [hour[0], min[1], sec[1]]\n right_time = []\n for time_unit in time:\n if time_unit < 10:\n time_unit = '0' + str(time_unit)\n right_time.append(time_unit)\n else:\n time_unit = str(time_unit)\n right_time.append(time_unit)\n \n result = ':'.join(right_time)\n return result\n \n", "def time_correct(t):\n if not t: return t\n if any([len(t) != 8, t[2] != \":\", t[5] != \":\", not all(x.isdigit() for x in t.split(\":\"))]):\n return None\n else:\n n = sum(int(x)*y for x, y in zip(t.split(\":\"),[3600, 60, 1]))\n return \"{:02d}:{:02d}:{:02d}\".format((n//3600)%24, n//60 - (n//3600)*60, n%60)\n\n", "def time_correct(t):\n try:\n h = t.split(\":\")[0]\n m = t.split(\":\")[1]\n s = t.split(\":\")[2]\n \n if h[0]==0: h = h[1]\n if m[0]==0: m = m[1]\n if s[0]==0: s = s[1]\n \n h = int(h)\n m = int(m)\n s = int(s)\n \n while s > 59:\n m += 1\n s -= 60\n while m > 59:\n h += 1\n m -= 60\n while h > 23:\n h -= 24\n \n h = str(h)\n m = str(m)\n s = str(s)\n \n if len(h)==1: h = \"0\" + h\n if len(m)==1: m = \"0\" + m\n if len(s)==1: s = \"0\" + s\n \n return \":\".join([h,m,s])\n except:\n return '' if t=='' else None", "def time_correct(t):\n try:\n if not t: return t\n if not len(t) == 8: return None\n h, m, s = map(int, t.split(':'))\n s, m = s%60, m + (s - (s%60)) // 60\n m, h = m%60, h + (m - (m%60)) // 60\n h %= 24\n return f'{h:02}:{m:02}:{s:02}'\n except:\n return None", "from re import match\n\ndef time_correct(t):\n if not t: return t\n if not bool(match(r'\\d{2}:\\d{2}:\\d{2}', t)): return None\n \n h, m, s = map(int, t.split(':'))\n if s > 59: \n m += s // 60\n s %= 60\n if m > 59: \n h += m // 60\n m %= 60\n if h > 23:\n h %= 24\n return '{:02d}:{:02d}:{:02d}'.format(h, m, s)", "def time_correct(t):\n if t == \"\":\n return \"\"\n try:\n if t is None:\n return None\n elif len(t) != 8:\n return None\n else:\n a, b, c = map(int, t.split(':'))\n if c >= 60:\n c -= 60\n b += 1\n if b >= 60:\n b -= 60\n a += 1\n if a >= 24:\n a = a % 24\n return '%02d:%02d:%02d' % (a,b,c)\n except:\n return None", "def time_correct(t):\n if len(str(t))==0:\n return \"\"\n time = str(t).split(':')\n for i in time:\n if len(i)!=2:\n return None \n if len(time) != 3:\n return None\n else:\n try:\n t = [int(i) for i in time]\n except Exception:\n return None\n while t[2]>59:\n t[1]+=1\n t[2]-=60\n while t[1]>59:\n t[0]+=1\n t[1]-=60\n t[0]=t[0]%24\n t = [str(i) for i in t]\n for i in range(3):\n if len(t[i])==1:\n t[i] = \"0\"+t[i]\n ans = ':'.join(t)\n return ans\n \n \n", "import re\ndef time_correct(time):\n if time == None:\n return None\n elif time == '':\n return ''\n pattern = re.compile('[0-9][0-9]:[0-9][0-9]:[0-9][0-9]')\n if pattern.match(time):\n t = time.split(':')\n hours = int(t[0])\n minutes = int(t[1])\n seconds = int(t[2])\n while seconds >= 60:\n seconds -= 60\n minutes += 1\n while minutes >= 60:\n minutes -= 60\n hours += 1\n while hours >= 24:\n hours -= 24\n return str(\"{:02d}\".format(hours)) + ':' + str(\"{:02d}\".format(minutes)) + ':' + str(\"{:02d}\".format(seconds))", "import re\n\ndef time_correct(s):\n try:\n assert re.match(r\"^\\d\\d:\\d\\d:\\d\\d$\", s)\n a, b, c = [int(x) for x in s.split(\":\")]\n except:\n return \"\" if s == \"\" else None\n b += c // 60\n a += b // 60\n return \":\".join(\"{:>02}\".format(x % y) for x, y in zip([a, b, c], [24, 60, 60]))", "def time_correct(t):\n if t == \"\":\n return \"\"\n try:\n t = t.split(\":\")\n except:\n return None\n if len(t) != 3 or not all([i.isdigit() for i in t]):\n return None\n try:\n h, m, s = int(t[0]), int(t[1]), int(t[2])\n \n m = m + s//60\n s = s%60\n h = h + m//60\n m = m%60\n h = h%24\n \n return str(h).zfill(2) + \":\" + str(m).zfill(2) + \":\" + str(s).zfill(2)\n except:\n return None", "def time_correct(t):\n if not t: return t\n time = t.split(\":\")\n if len(time) != 3 or len(t) != 8: return None\n try:\n time[0] = int(time[0])\n except:\n return None\n try:\n time[1] = int(time[1])\n except:\n return None\n try:\n time[2] = int(time[2])\n except:\n return None\n return \"{:02d}:{:02d}:{:02d}\".format((time[0]+(time[1]+time[2]//60)//60)%24,(time[1]+time[2]//60)%60,time[2]%60)", "def time_correct(t:str):\n returnlst = []\n add = 0 \n number = 0\n if t == '':\n return ''\n if t == None or len(t.split(':')) != 3:\n return None\n\n for ind,val in [(ind,val) for ind, val in enumerate(t.split(':')[::-1])]:\n try:\n if any(ops in val for ops in ['+','-','/','\\\\','*','=']): \n return None\n if len(val) == 2:\n number = int(val)\n else:\n return None\n except ValueError:\n return None\n if ind == 2:\n number += add\n returnlst.append(str(number % 24).zfill(2))\n else:\n number += add\n add = int(number/60)\n returnlst.append(str(number % 60).zfill(2))\n return ':'.join(returnlst[::-1]) ", "def time_correct(t):\n if t == '':\n return ''\n if t is None:\n return None\n if not __import__('re').match(r'^\\d\\d:\\d\\d:\\d\\d',t):\n return None\n h,m,s = [int(x) for x in t.split(':')]\n while s >= 60:\n s -= 60\n m += 1\n while m >= 60:\n m -= 60\n h += 1\n while h >= 24:\n h -= 24\n return '{:02d}:{:02d}:{:02d}'.format(h,m,s)", "def time_correct(t):\n if not t:\n return t\n try:\n h, m, s = map(int, t.split(':'))\n except ValueError:\n return None\n \n m, s = m + s//60, s % 60\n h, m = h + m//60, m % 60\n h = h % 24\n return '{:02d}:{:02d}:{:02d}'.format(h, m, s)", "def time_correct(t):\n if t == '':\n return ''\n elif t == None or len(t) != 8 or len(t) == 8 and not (t[:2].isdigit() and t[2] == ':' and t[3:5].isdigit() and t[5] == ':' and t[6:].isdigit()):\n return None\n else:\n h, m, s = int(t[:2]), int(t[3:5]), int(t[6:])\n m = m + s // 60\n s = s % 60\n h = h + m // 60\n m = m % 60\n h = h % 24\n return str(h).zfill(2) + ':' + str(m).zfill(2) + ':' + str(s).zfill(2)\n", "import re\ndef time_correct(t):\n if t is None or t==\"\":\n return t\n elif re.match(r'\\d{2}:\\d{2}:\\d{2}',t) is not None:\n v=(int(t[0:2])*3600)+(int(t[3:5])*60)+int(t[6:])\n if v>86400:\n while v>86400:\n v-=86400\n return \"{:02d}:{:02d}:{:02d}\".format(int(v/3600),int((v%3600)/60),(v%36000)%60)\n else:\n return None\n", "def time_correct(t):\n if not t:\n return t\n try:\n h,m,s = map(int,t.split(':'))\n m += s//60\n s %= 60\n h += m//60\n m %= 60\n h %= 24\n return f'{h:02}:{m:02}:{s:02}'\n except:\n return None", "def time_correct(t):\n if not t: return t\n try:\n h, m, s = t.split(':')\n h, m, s = int(h), int(m), int(s)\n except ValueError:\n return None\n m += s//60\n s %= 60\n h += m // 60\n m %= 60\n h %= 24\n fill = lambda n: str(n).zfill(2)\n return '{}:{}:{}'.format(fill(h), fill(m), fill(s))", "def time_correct(t):\n if not t:\n return t\n r = [int(i) for i in t.split(':') if i.isdigit() and len(i) == 2]\n if len(r) != 3 or t.count(':') != 2:\n return None\n return '{:02}:{:02}:{:02}'.format((r[0] + (r[1] + r[2]//60)//60) % 24 , (r[1] + r[2]//60)%60, r[2]%60)", "import re\n\ndef time_correct(t):\n if not t: return t\n\n pattern = r'\\d{2}:\\d{2}:\\d{2}'\n \n if not re.match(pattern, t): return None\n\n hours, minutes, seconds = map(int, t.split(':'))\n\n minutes, seconds = minutes + (seconds // 60), seconds % 60\n hours, minutes = (hours + (minutes // 60)) % 24, minutes % 60\n\n return '{:0>2}:{:0>2}:{:0>2}'.format(hours, minutes, seconds)"]
{"fn_name": "time_correct", "inputs": [[null], [""], ["001122"], ["00;11;22"], ["0a:1c:22"], ["09:10:01"], ["11:70:10"], ["19:99:99"], ["24:01:01"], ["52:01:01"], ["14:59:94"]], "outputs": [[null], [""], [null], [null], [null], ["09:10:01"], ["12:10:10"], ["20:40:39"], ["00:01:01"], ["04:01:01"], ["15:00:34"]]}
INTRODUCTORY
PYTHON3
CODEWARS
45,820
def time_correct(t):
c74b221d1d33cf0acc898087cfd7d028
UNKNOWN
Complete the function which returns the weekday according to the input number: * `1` returns `"Sunday"` * `2` returns `"Monday"` * `3` returns `"Tuesday"` * `4` returns `"Wednesday"` * `5` returns `"Thursday"` * `6` returns `"Friday"` * `7` returns `"Saturday"` * Otherwise returns `"Wrong, please enter a number between 1 and 7"`
["WEEKDAY = {\n 1: 'Sunday',\n 2: 'Monday',\n 3: 'Tuesday',\n 4: 'Wednesday',\n 5: 'Thursday',\n 6: 'Friday',\n 7: 'Saturday' }\nERROR = 'Wrong, please enter a number between 1 and 7'\n\n\ndef whatday(n):\n return WEEKDAY.get(n, ERROR)\n", "def whatday(num):\n switcher = {\n 1:'Sunday',\n 2:'Monday',\n 3:'Tuesday',\n 4:'Wednesday',\n 5:'Thursday',\n 6:'Friday',\n 7:'Saturday'\n }\n return switcher.get(num, 'Wrong, please enter a number between 1 and 7')\n", "def whatday(num):\n days = ('Sun', 'Mon', 'Tues', 'Wednes', 'Thurs', 'Fri', 'Satur')\n return days[num-1] + 'day' if 0 < num < 8 else 'Wrong, please enter a number between 1 and 7' ", "def whatday(num):\n days={1:'Sunday', 2:'Monday',3:'Tuesday',4:'Wednesday',5:'Thursday',6:'Friday',7:'Saturday'}\n WRONG_VALUE=\"Wrong, please enter a number between 1 and 7\"\n return days.get(num,WRONG_VALUE)", "def whatday(num):\n return {1: 'Sunday', 2: 'Monday', 3: 'Tuesday', 4: 'Wednesday', 5: 'Thursday', 6: 'Friday', 7: 'Saturday'}.get(num, \"Wrong, please enter a number between 1 and 7\")\n", "whatday=lambda n:'Wrong, please enter a number between 1 and 7'*(n>7or n<1)or __import__('calendar').day_name[n-2]", "WEEK =' Sunday Monday Tuesday Wednesday Thursday Friday Saturday'.split(\" \")\n\ndef whatday(n):\n return WEEK[n] if 0<n<8 else 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n days = {1: \"Sunday\",2: \"Monday\",3: \"Tuesday\",4: \"Wednesday\",5: \"Thursday\",6: \"Friday\",7: \"Saturday\"}\n if num not in days:\n return \"Wrong, please enter a number between 1 and 7\"\n return days[num]\n \n \n \n", "def whatday(num):\n weekday = {1:'Sunday',\n 2:'Monday',\n 3:'Tuesday',\n 4:'Wednesday',\n 5:'Thursday',\n 6:'Friday',\n 7:'Saturday'}\n try:\n return weekday[num]\n except:\n return(\"Wrong, please enter a number between 1 and 7\")", "def whatday(num):\n DAYS = {\n 1 : \"Sunday\", \n 2 : \"Monday\", \n 3 : \"Tuesday\", \n 4 : \"Wednesday\", \n 5 : \"Thursday\", \n 6 : \"Friday\", \n 7 : \"Saturday\",\n }\n WRONG_DAY = 'Wrong, please enter a number between 1 and 7'\n return DAYS.get(num, WRONG_DAY)", "def whatday(num):\n lst = [\"Wrong, please enter a number between 1 and 7\", \"Sunday\", \"Monday\", \n \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n return lst[num] if num > 0 and num < 8 else lst[0]", "def whatday(num):\n l=[\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"]\n if(0<num<=7):\n for i in range(1,8):\n if(i==num):\n return(l[i-1]) \n else:\n return\"Wrong, please enter a number between 1 and 7\"\n", "days = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n\ndef whatday(num):\n if 0 < num < 8:\n return days[num - 1]\n return \"Wrong, please enter a number between 1 and 7\"\n", "def whatday(num):\n return ('Wrong, please enter a number between 1 and 7', 'Sunday', 'Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')[1 <= num <= 7 and num] ", "from datetime import datetime\n\ndef whatday(n):\n return datetime(2019, 2, 2 + n).strftime(\"%A\") if 1 <= n <= 7 else 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n return {1: \"Sunday\", 2: \"Monday\", 3: \"Tuesday\", 4: \"Wednesday\", 5: \"Thursday\", \n 6: \"Friday\", 7: \"Saturday\"}.get(num, \"Wrong, please enter a number between 1 and 7\")\n \n # between 1 and 7 (inclusive) ...\n", "def whatday(num):\n return dict(zip('2345671', __import__('calendar').day_name)).get(str(num), 'Wrong, please enter a number between 1 and 7')", "def whatday(num):\n return ([\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"][num-1:num]+['Wrong, please enter a number between 1 and 7'])[0]", "def whatday(numb):\n if numb not in range (1,8):\n return \"Wrong, please enter a number between 1 and 7\"\n elif numb == 1:\n return \"Sunday\"\n elif numb == 2:\n return \"Monday\" \n elif numb == 3:\n return \"Tuesday\"\n elif numb == 4:\n return \"Wednesday\"\n elif numb == 5:\n return \"Thursday\"\n elif numb == 6:\n return \"Friday\"\n elif numb == 7:\n return \"Saturday\"", "def whatday(num):\n d = {1: \"Sunday\", 2: \"Monday\", 3: \"Tuesday\", 4: \"Wednesday\", 5: \"Thursday\", 6: \"Friday\", 7: \"Saturday\"}\n try:\n return d[num]\n except KeyError:\n return \"Wrong, please enter a number between 1 and 7\"\n", "def whatday(n):\n if n<1 or n>7: return 'Wrong, please enter a number between 1 and 7'\n return ' Sunday Monday Tuesday Wednesday Thursday Friday Saturday'.split(' ')[n]\n", "L = {1: 'Sunday', 2: 'Monday', 3: 'Tuesday', 4: 'Wednesday', 5: 'Thursday', 6: 'Friday', 7: 'Saturday'}\n\nwhatday = lambda n: L.get(n, 'Wrong, please enter a number between 1 and 7')", "def whatday(num):\n day=['Wrong, please enter a number between 1 and 7',\n \"Sunday\",\n \"Monday\",\n \"Tuesday\",\n \"Wednesday\",\n \"Thursday\",\n \"Friday\",\n \"Saturday\"]\n try:\n return day[num]\n except:\n return day[0]", "def whatday(num):\n days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']\n if num > 7 or num <= 0:\n return \"Wrong, please enter a number between 1 and 7\"\n for index, x in enumerate(days, 1):\n if num == index:\n return x", "def whatday(num):\n days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']\n if num > 7 or num <= 0:\n return \"Wrong, please enter a number between 1 and 7\"\n for index, x in enumerate(days, 1):\n if num == index:\n return x\n# if 0 >= num > 7:\n# return \"Wrong, please enter a number between 1 and 7\"\n", "whatday = lambda n:'SMTWTFSuouehranneduit snr u es r s'[n-1::7].rstrip()+'day' if 0<n<8 else 'Wrong, please enter a number between 1 and 7'", "import calendar\nfrom collections import deque\n\ndef whatday(num: int) -> str:\n \"\"\" Get weekday according to the input number (days rotated by 1). \"\"\"\n days = deque(list(calendar.day_name))\n days.rotate(1)\n return dict(zip(list(range(1, 8)), days)).get(num, \"Wrong, please enter a number between 1 and 7\")", "def whatday(num):\n # Put your code here\n if(1<=num<=7):\n if(num==1):\n return \"Sunday\"\n elif(num==2):\n return \"Monday\"\n elif(num==3):\n return \"Tuesday\"\n elif(num==4):\n return \"Wednesday\"\n elif(num==5):\n return \"Thursday\"\n elif(num==6):\n return \"Friday\"\n else:\n return \"Saturday\"\n else:\n return \"Wrong, please enter a number between 1 and 7\"", "whatday=lambda n:{1:\"Sunday\",2:\"Monday\",3:\"Tuesday\",4:\"Wednesday\",5:\"Thursday\",6:\"Friday\",7:\"Saturday\"}.get(n,'Wrong, please enter a number between 1 and 7')", "def whatday(num):\n day = ['Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']\n return day[num % 7] if num in range(1, 8) else \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n days_of_week = {\n 1: 'Sunday', 2: 'Monday', 3: 'Tuesday', 4: 'Wednesday', 5: 'Thursday', 6: 'Friday', 7: 'Saturday'\n }\n \n return days_of_week.get(num, 'Wrong, please enter a number between 1 and 7')", "def whatday(num):\n day_of_week = {1:\"Sunday\",2:\"Monday\",3:\"Tuesday\",4:\"Wednesday\",5:\"Thursday\",6:\"Friday\",7:\"Saturday\"}\n if num > 7 or num < 1:\n return 'Wrong, please enter a number between 1 and 7'\n else:\n return day_of_week[num] ", "def whatday(num):\n if (num <= 0) or (num > 7): return \"Wrong, please enter a number between 1 and 7\"\n if num ==1: return 'Sunday'\n if num ==2: return 'Monday'\n if num ==3: return 'Tuesday'\n if num ==4: return 'Wednesday'\n if num ==5: return 'Thursday'\n if num ==6: return 'Friday'\n if num ==7: return 'Saturday'\n", "wd = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']\ndef whatday(num):\n if num < 1 or num > 7:\n return 'Wrong, please enter a number between 1 and 7'\n return wd[num - 1]\n", "import calendar\n\ndef whatday(n):\n if not 1 <= n <= 7:\n return \"Wrong, please enter a number between 1 and 7\"\n return calendar.day_name[(n - 2) % 7] # Change index to Monday = 0 and Sunday = 6", "def whatday(num):\n return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', \\\n 'Saturday'][num-1] if num in range(1,8) else \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n week = {1:'Sunday', 2:'Monday', 3:'Tuesday', 4:'Wednesday', 5:'Thursday', 6:'Friday', 7:'Saturday'}\n if num in week.keys():\n return week.get(num)\n else:\n return 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n d = {1: \"Sunday\",\n 2: \"Monday\",\n 3: \"Tuesday\",\n 4: \"Wednesday\",\n 5: \"Thursday\",\n 6: \"Friday\",\n 7: \"Saturday\"}\n return d.get(num) if num > 0 and num < 8 else 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n DICK={1:\"Sunday\",2:\"Monday\",3:\"Tuesday\", 4:\"Wednesday\",5:\"Thursday\",6:\"Friday\",7:\"Saturday\"}\n return DICK[num] if 0<num<8 else \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n days = {\n 1 : \"Sunday\",\n 2 : \"Monday\",\n 3 : \"Tuesday\",\n 4 : \"Wednesday\",\n 5 : \"Thursday\",\n 6 : \"Friday\",\n 7 : \"Saturday\"\n }\n \n if 0 < num <= 7:\n return days.get(num)\n else:\n return 'Wrong, please enter a number between 1 and 7'", "from calendar import day_name\ndef whatday(n):\n return 'Wrong, please enter a number between 1 and 7' if n>7 or n<1 else day_name[n-2]", "from calendar import day_name\ndef whatday(num):\n d={}\n c=2\n for i in list(day_name):\n if i=='Sunday':\n d[1]=i\n else:\n d[c]=i\n c+=1\n return d.get(num,'Wrong, please enter a number between 1 and 7')", "X = {\n 1 : \"Sunday\",\n 2 : \"Monday\",\n 3 : \"Tuesday\",\n 4 : \"Wednesday\",\n 5 : \"Thursday\",\n 6 : \"Friday\",\n 7 : \"Saturday\"\n}\n\ndef whatday(num):\n return X.get(num, \"Wrong, please enter a number between 1 and 7\")", "def whatday(num):\n dict={\n 2:\"Monday\",\n 3:\"Tuesday\",\n 4:\"Wednesday\",\n 5:\"Thursday\",\n 6:\"Friday\",\n 7:\"Saturday\",\n 1:\"Sunday\"\n }\n return dict.get(num,'Wrong, please enter a number between 1 and 7')", "days = {\n 1: 'Sunday',\n 2: 'Monday',\n 3: 'Tuesday',\n 4: 'Wednesday',\n 5: 'Thursday',\n 6: 'Friday',\n 7: 'Saturday' }\n\nwrong_num = 'Wrong, please enter a number between 1 and 7'\n\ndef whatday(num):\n # Put your code here\n return days.get(num, wrong_num)", "def whatday(num):\n dic = {\"Sunday\": 1,\n \"Monday\": 2,\n \"Tuesday\":3,\n \"Wednesday\": 4,\n \"Thursday\" : 5,\n \"Friday\" : 6,\n \"Saturday\" : 7,}\n for key, value in list(dic.items()):\n if dic[key] == num and num <= 7:\n return key\n return 'Wrong, please enter a number between 1 and 7'\n\n# test.assert_equals(whatday(1), 'Sunday')\n# test.assert_equals(whatday(2), 'Monday')\n# test.assert_equals(whatday(3), 'Tuesday')\n", "def whatday(num):\n dict_ = {1: 'Sunday', 2: 'Monday', 3: 'Tuesday', 4: 'Wednesday', 5: 'Thursday', 6: 'Friday', 7: 'Saturday'}\n return dict_.get(num, 'Wrong, please enter a number between 1 and 7')", "def whatday(n):\n weekdays = {\n 1: \"Sunday\",\n 2: \"Monday\",\n 3: \"Tuesday\",\n 4: \"Wednesday\",\n 5: \"Thursday\",\n 6: \"Friday\",\n 7: \"Saturday\"\n }\n return weekdays.get(n, \"Wrong, please enter a number between 1 and 7\")", "def whatday(num):\n weekdays = {1: 'Sunday', 2: 'Monday', 3: 'Tuesday', 4: 'Wednesday', 5: 'Thursday', 6: 'Friday', 7: 'Saturday'}\n wrong = 'Wrong, please enter a number between 1 and 7'\n return weekdays.get(num, wrong)", "def whatday(num):\n nums=[1,2,3,4,5,6,7]\n days=['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']\n \n d_o_w=dict(list(zip(nums,days)))\n if num in list(d_o_w.keys()):\n return d_o_w[num]\n else:\n return \"Wrong, please enter a number between 1 and 7\"\n", "import calendar\n\ndef whatday(num):\n ll = ['Sunday'] + list(calendar.day_name)[:-1]\n print(num, ll)\n return ll[num - 1] if num in range(1, 8) else 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n msg = ['Wrong, please enter a number between 1 and 7', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']\n return msg[num] if num in range(1, 8) else msg[0]", "INDEX_TO_WEEKDAY = {\n 1:\"Sunday\", 2:\"Monday\", 3:\"Tuesday\",\n 4:\"Wednesday\", 5:\"Thursday\", 6:\"Friday\",\n 7:\"Saturday\" }\n\ndef whatday(num) -> str:\n try:\n return INDEX_TO_WEEKDAY[num]\n except LookupError:\n return \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n days = {2:\"Monday\",3:\"Tuesday\",4:\"Wednesday\",5:\"Thursday\",6:\"Friday\",7:\"Saturday\",1:\"Sunday\"}\n try: return days[num]\n except: return 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n dict ={1: 'Monday', 2: 'Tuesday', 3: 'Wednesday', 4: 'Thursday', 5: 'Friday', 6: 'Saturday', 0: 'Sunday'}\n return dict.get(num-1, 'Wrong, please enter a number between 1 and 7')", "def whatday(num):\n try:\n a = zip(range(1, 8), [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"])\n adict = dict(a)\n return adict[num]\n except:\n return \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n return [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"][num-1] if num-1 in range(7) else \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n array = [0, 'Sunday', 'Monday','Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']\n return 'Wrong, please enter a number between 1 and 7' if num == 0 or num>7 else array[num]", "def whatday(num):\n return {1: \"Sunday\", 2: \"Monday\", 3: \"Tuesday\", 4: \"Wednesday\", 5: \"Thursday\", 6: \"Friday\", 7: \"Saturday\"}.get(num, \"Wrong, please enter a number between 1 and 7\")\n # dictionary method get() returns the value for the inserted key or the default message if the value is not found\n", "def whatday(num):\n if num <= 0 or num > 7: return \"Wrong, please enter a number between 1 and 7\"\n weekdays = [\"\", \"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n return weekdays[num]", "def whatday(num):\n weekdays = {\n 1: 'Sunday',\n 2: 'Monday',\n 3: 'Tuesday',\n 4: 'Wednesday',\n 5: 'Thursday',\n 6: 'Friday',\n 7: 'Saturday'\n }\n return weekdays[num] if 0 < num <=7 else 'Wrong, please enter a number between 1 and 7'\n # Put your code here\n", "wd = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\ndef whatday(num):\n return wd[num-1] if num-1 in range(7) else \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n dic = {1: \"Sunday\",\n 2: \"Monday\",\n 3: \"Tuesday\",\n 4: \"Wednesday\",\n 5: \"Thursday\",\n 6: \"Friday\",\n 7: \"Saturday\"}\n return dic[num] if num in dic.keys() else 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n arr = {1:'Sunday', 2:'Monday', 3:'Tuesday',4:'Wednesday', 5:'Thursday',\n 6:'Friday',7:'Saturday'}\n \n if num <= 7 and num > 0: return arr[num]\n else: return 'Wrong, please enter a number between 1 and 7'", "def whatday(num=''):\n if num > 7 or num == 0:\n return 'Wrong, please enter a number between 1 and 7'\n else:\n return {1 : 'Sunday',\n 2 : 'Monday',\n 3 : 'Tuesday',\n 4 : 'Wednesday',\n 5 : 'Thursday',\n 6 : 'Friday',\n 7 : 'Saturday'}.get(num)\n", "def whatday(num):\n return {1 : \"Sunday\",2 : \"Monday\",3 : \"Tuesday\",4 : \"Wednesday\",5 : \"Thursday\",6 : \"Friday\",7 : \"Saturday\"}[num] if num < 8 and num > 0 else 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n weeks = {1:\"Sunday\",2:\"Monday\",3:\"Tuesday\",4:\"Wednesday\",5:\"Thursday\",6:\"Friday\",7:\"Saturday\"}\n return weeks.get(num,\"Wrong, please enter a number between 1 and 7\")", "def whatday(num):\n k = {1: \"Sunday\", 2: \"Monday\", 3: \"Tuesday\", 4: \"Wednesday\", 5: \"Thursday\", 6: \"Friday\", 7: \"Saturday\"}\n if num in list(k.keys()):\n return k[num]\n else:\n return 'Wrong, please enter a number between 1 and 7'\n# Put your code here\n", "def whatday(num):\n days = {\n 1:'Sunday',\n 2:'Monday',\n 3:'Tuesday',\n 4:'Wednesday',\n 5:'Thursday',\n 6:'Friday',\n 7:'Saturday',\n }\n try:\n return days[num]\n except KeyError as e:\n return 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n \n day = [\"Wrong, please enter a number between 1 and 7\",\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n \n if num <= 7:\n return day[num]\n \n else:\n return \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n d = {1: \"Sunday\",\n 2: \"Monday\",\n 3: \"Tuesday\",\n 4: \"Wednesday\",\n 5: \"Thursday\",\n 6: \"Friday\",\n 7: \"Saturday\"}\n if 1 <= num <= 7:\n return d[num]\n else:\n return 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n days = {\n 1: \"Sunday\", \n 2: \"Monday\", \n 3: \"Tuesday\", \n 4: \"Wednesday\", \n 5: \"Thursday\", \n 6: \"Friday\", \n 7: \"Saturday\"}\n return days.get(num) if num in days.keys() else \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n print(num)\n days = {\n 1: \"Sunday\", \n 2: \"Monday\", \n 3: \"Tuesday\", \n 4: \"Wednesday\", \n 5: \"Thursday\", \n 6: \"Friday\", \n 7: \"Saturday\"}\n return days.get(num) if num in days.keys() else \"Wrong, please enter a number between 1 and 7\"", "def whatday(Va\u00f0lahei\u00f0arvegavinnuverkf\u00e6rageymslusk\u00fara\u00fatidyralyklakippuhringur):\n if Va\u00f0lahei\u00f0arvegavinnuverkf\u00e6rageymslusk\u00fara\u00fatidyralyklakippuhringur == 1:\n return 'Sunday'\n elif Va\u00f0lahei\u00f0arvegavinnuverkf\u00e6rageymslusk\u00fara\u00fatidyralyklakippuhringur == 2:\n return 'Monday'\n elif Va\u00f0lahei\u00f0arvegavinnuverkf\u00e6rageymslusk\u00fara\u00fatidyralyklakippuhringur == 3:\n return 'Tuesday'\n elif Va\u00f0lahei\u00f0arvegavinnuverkf\u00e6rageymslusk\u00fara\u00fatidyralyklakippuhringur == 4:\n return 'Wednesday'\n elif Va\u00f0lahei\u00f0arvegavinnuverkf\u00e6rageymslusk\u00fara\u00fatidyralyklakippuhringur == 5:\n return 'Thursday'\n elif Va\u00f0lahei\u00f0arvegavinnuverkf\u00e6rageymslusk\u00fara\u00fatidyralyklakippuhringur == 6:\n return 'Friday'\n elif Va\u00f0lahei\u00f0arvegavinnuverkf\u00e6rageymslusk\u00fara\u00fatidyralyklakippuhringur == 7:\n return 'Saturday'\n return \"Wrong, please enter a number between 1 and 7\"", "def whatday(n):\n if 0<n<8:\n \n return['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'][n-1].title()\n else:\n return \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n if num <= 0 or num > 7:\n return \"Wrong, please enter a number between 1 and 7\"\n else:\n if num == 1:\n return \"Sunday\"\n elif num == 2:\n return \"Monday\"\n elif num == 3:\n return \"Tuesday\"\n elif num == 4:\n return \"Wednesday\"\n elif num == 5:\n return \"Thursday\"\n elif num == 6:\n return \"Friday\"\n else:\n return \"Saturday\"", "def whatday(num):\n if num == 1:\n return 'Sunday'\n elif num == 2:\n return 'Monday'\n elif num == 3:\n return 'Tuesday'\n elif num == 4:\n return 'Wednesday'\n elif num == 5:\n return 'Thursday'\n elif num == 6:\n return 'Friday'\n elif num == 7:\n return 'Saturday'\n elif num > 7:\n return \"Wrong, please enter a number between 1 and 7\"\n elif num == 0:\n return \"Wrong, please enter a number between 1 and 7\"\n", "def whatday(num):\n l=[\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"]\n return l[num-1] if 0<num<8 else \"Wrong, please enter a number between 1 and 7\"\n", "def whatday(n):\n l=['','Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Wrong, please enter a number between 1 and 7']\n return l[n] if 0<n<8 else l[8]", "def whatday(num):\n return (\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\")[num-1] if 0<num<=7 else 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n \n d = {1:\"Sunday\", \n 2:\"Monday\",\n 3:\"Tuesday\",\n 4:\"Wednesday\",\n 5:\"Thursday\",\n 6:\"Friday\",\n 7:\"Saturday\",\n }\n \n if num < 8 and num > 0:\n return d[num]\n else: \n return \"Wrong, please enter a number between 1 and 7\"\n \n", "def whatday(num):\n lst=[\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"]\n return lst[num-1] if 0<num<8 else \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n if num == 1:\n result = \"Sunday\"\n elif num == 2:\n result = \"Monday\"\n elif num == 3:\n result = \"Tuesday\"\n elif num == 4:\n result = \"Wednesday\"\n elif num == 5:\n result = \"Thursday\"\n elif num == 6:\n result = \"Friday\"\n elif num == 7:\n result = \"Saturday\"\n else:\n result = \"Wrong, please enter a number between 1 and 7\"\n return result", "def whatday(num):\n err=\"Wrong, please enter a number between 1 and 7\"\n try : return [err,\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"][int(num)]\n except : return err ", "DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']\n\ndef whatday(num):\n return DAYS[num - 1] if 1 <= num <= 7 else 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n x = {1:\"Sunday\", 2:\"Monday\", 3:\"Tuesday\", 4:\"Wednesday\", 5:\"Thursday\", 6:\"Friday\", 7:\"Saturday\"}\n if num in x:\n return x[num]\n else:\n return \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n if num == 2:\n return \"Monday\"\n elif num == 3:\n return \"Tuesday\"\n elif num == 4:\n return \"Wednesday\"\n elif num == 5:\n return \"Thursday\"\n elif num == 6:\n return \"Friday\"\n elif num == 7:\n return \"Saturday\"\n elif num == 1:\n return \"Sunday\"\n else:\n return 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n l=[0,'Sunday',\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"]\n return \"Wrong, please enter a number between 1 and 7\" if num>7 or num<1 else l[num]", "def whatday(num):\n return {1: \"Sunday\", 2: \"Monday\", 3: \"Tuesday\", 4: \"Wednesday\", 5: \"Thursday\", 6: \"Friday\", 7: \"Saturday\"}.setdefault(num, 'Wrong, please enter a number between 1 and 7')", "def whatday(num):\n days = {\n 1: \"Sunday\",\n 2: \"Monday\",\n 3: \"Tuesday\",\n 4: \"Wednesday\",\n 5: \"Thursday\",\n 6: \"Friday\",\n 7: \"Saturday\"\n }\n return days.get(num) if num > 0 and num < 8 else 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n if num in [1,2,3,4,5,6,7]:\n return ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'][num-1]\n else:\n return 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n days = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n return days[num - 1] if num <= len(days) and num != 0 else 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n Dict_days = {\n 1 : \"Sunday\",\n 2 : \"Monday\",\n 3 : \"Tuesday\",\n 4 : \"Wednesday\",\n 5 : \"Thursday\",\n 6 : \"Friday\",\n 7 : \"Saturday\"\n }\n \n return Dict_days.get(num, 'Wrong, please enter a number between 1 and 7')", "def whatday(num):\n d = {\n 1: \"Sunday\",\n 2: \"Monday\",\n 3: \"Tuesday\",\n 4: \"Wednesday\",\n 5: \"Thursday\",\n 6: \"Friday\",\n 7: \"Saturday\"\n }\n \n return d.get(num) if num in d else 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n if num <= 0 or num >= 8: return \"Wrong, please enter a number between 1 and 7\"\n\n days = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n return days[num-1]\n", "def whatday(num):\n week_dic = {\n 1: 'Sunday',\n 2: 'Monday',\n 3: 'Tuesday',\n 4: 'Wednesday',\n 5: 'Thursday',\n 6: 'Friday',\n 7: 'Saturday'\n }\n \n if num in week_dic:\n return week_dic[num]\n \n return 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n arr = [\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\", \"Thursday\", \"Friday\", \"Saturday\"]\n if num > 0 and num < 8:\n return str(arr[num-1])\n else:\n return \"Wrong, please enter a number between 1 and 7\"", "def whatday(num):\n # Put your code here\n weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] \n if num in range(1,8):\n return weekdays[num - 1]\n return 'Wrong, please enter a number between 1 and 7'", "weekdays = {1:'Sunday',\n 2:'Monday',\n 3:'Tuesday',\n 4:'Wednesday',\n 5:'Thursday',\n 6:'Friday',\n 7:'Saturday'}\n\ndef whatday(num):\n try:\n return weekdays[num]\n except:\n return 'Wrong, please enter a number between 1 and 7'", "def whatday(num):\n print(num)\n days = [\"Sunday\",\"Monday\",\"Tuesday\", \"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"] \n return days.pop(num-1) if num <= len(days) and num >0 else \"Wrong, please enter a number between 1 and 7\"\n"]
{"fn_name": "whatday", "inputs": [[1], [2], [3], [4], [5], [6], [7], [0], [8], [20]], "outputs": [["Sunday"], ["Monday"], ["Tuesday"], ["Wednesday"], ["Thursday"], ["Friday"], ["Saturday"], ["Wrong, please enter a number between 1 and 7"], ["Wrong, please enter a number between 1 and 7"], ["Wrong, please enter a number between 1 and 7"]]}
INTRODUCTORY
PYTHON3
CODEWARS
27,810
def whatday(num):
591c6cfb7095b09c0f0617df013ea315
UNKNOWN
# Task You are given n rectangular boxes, the ith box has the length lengthi, the width widthi and the height heighti. Your task is to check if it is possible to pack all boxes into one so that inside each box there is no more than one another box (which, in turn, can contain at most one another box, and so on). More formally, your task is to check whether there is such sequence of n different numbers pi (1 ≤ pi ≤ n) that for each 1 ≤ i < n the box number pi can be put into the box number pi+1. A box can be put into another box if all sides of the first one are less than the respective ones of the second one. You can rotate each box as you wish, i.e. you can `swap` its length, width and height if necessary. # Example For `length = [1, 3, 2], width = [1, 3, 2] and height = [1, 3, 2]`, the output should be `true`; For `length = [1, 1], width = [1, 1] and height = [1, 1],` the output should be `false`; For `length = [3, 1, 2], width = [3, 1, 2] and height = [3, 2, 1]`, the output should be `false`. # Input/Output - `[input]` integer array `length` Array of positive integers. Constraints: `1 ≤ length.length ≤ 100,` `1 ≤ length[i] ≤ 2000.` - `[input]` integer array `width` Array of positive integers. Constraints: `width.length = length.length,` `1 ≤ width[i] ≤ 2000.` - `[input]` integer array `height` Array of positive integers. Constraints: `height.length = length.length,` `1 ≤ height[i] ≤ 2000.` - `[output]` a boolean value `true` if it is possible to put all boxes into one, `false` otherwise.
["def boxes_packing(l, w, h):\n boxes = sorted(sorted(t) for t in zip(l, w, h))\n return all( s < l for b1,b2 in zip(boxes[:-1], boxes[1:]) for s,l in zip(b1,b2))", "def boxes_packing(length, width, height):\n boxes = sorted([sorted(b) for b in zip(length, width, height)])\n return all(all(x < y for x, y in zip(a, b)) for a, b in zip(boxes, boxes[1:]))", "def boxes_packing(length, width, height):\n boxes = sorted(range(len(width)), key=lambda i: length[i]*width[i]*height[i])\n for i in range(len(boxes)-1):\n x = boxes[i]\n y = boxes[i+1]\n rotations_x = [[length[x], width[x], height[x]],\n [length[x], height[x], width[x]],\n [width[x], length[x], height[x]],\n [width[x], height[x], length[x]],\n [height[x], length[x], width[x]],\n [height[x], width[x], length[x]]]\n for lx, wx, hx in rotations_x:\n if lx < length[y] and wx < width[y] and hx < height[y]:\n break\n else:\n return False\n return True", "def boxes_packing(l,w,h):\n return all(len(i)==len(set(i))and list(i)==sorted(i)for i in list(zip(*sorted(sorted(i)for i in list(zip(l,w,h))))))", "def boxes_packing(length, width, height):\n incr = lambda s: all(x < y for x, y in zip(s, s[1:]))\n return all(incr(s) for s in zip(*sorted(sorted(b) for b in zip(length, width, height))))", "def boxes_packing(length, width, height):\n boxes=sorted([sorted(t,reverse=True) for t in zip(length,width,height)],reverse=True)\n for b1,b2 in zip(boxes[:-1],boxes[1:]):\n if b1[0]<=b2[0] or b1[1]<=b2[1] or b1[2]<=b2[2]:\n return False\n return True", "def boxes_packing(*args):\n boxes = sorted(map(sorted, zip(*args)))\n return all(dimension_1 < dimension_2 \n for box_1, box_2 in zip(boxes, boxes[1:]) \n for dimension_1, dimension_2 in zip(box_1, box_2))", "def boxes_packing(length, width, height):\n boxes = sorted(map(sorted, zip(length, width, height)))\n return all(all(d1 < d2 for d1, d2 in zip(smaller, larger)) for smaller, larger in zip(boxes, boxes[1:]))", "from itertools import tee, chain,starmap\nfrom operator import lt\n\n# found at https://docs.python.org/3.6/library/itertools.html\ndef pairwise(iterable):\n \"s -> (s0,s1), (s1,s2), (s2, s3), ...\"\n a, b = tee(iterable)\n next(b, None)\n return zip(a, b)\n\ndef boxes_packing(length, width, height):\n boxes = map(sorted, sorted(zip(length, width, height), key=lambda b: b[0] * b[1] * b[2]))\n return all(starmap(lt, chain.from_iterable(zip(*a) for a in pairwise(boxes))))", "def boxes_packing(length, width, height):\n L = list(map(sorted, zip(length, width, height)))\n return all(all(x<y for x,y in zip(b1, b2)) or all(x>y for x,y in zip(b1, b2)) for i,b1 in enumerate(L) for b2 in L[i+1:])"]
{"fn_name": "boxes_packing", "inputs": [[[1, 3, 2], [1, 3, 2], [1, 3, 2]], [[1, 1], [1, 1], [1, 1]], [[3, 1, 2], [3, 1, 2], [3, 2, 1]], [[2], [3], [4]], [[5, 7, 4, 1, 2], [4, 10, 3, 1, 4], [6, 5, 5, 1, 2]], [[6, 4], [5, 3], [4, 5]], [[6, 3], [5, 4], [4, 5]], [[6, 3], [5, 5], [4, 4]], [[883, 807], [772, 887], [950, 957]], [[6, 5], [5, 3], [4, 4]], [[4, 10, 3, 1, 4], [5, 7, 4, 1, 2], [6, 5, 5, 1, 2]], [[10, 8, 6, 4, 1], [7, 7, 6, 3, 2], [9, 6, 3, 2, 1]]], "outputs": [[true], [false], [false], [true], [true], [true], [true], [true], [true], [true], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,925
def boxes_packing(length, width, height):
4e8c10d9b15cadd6bedbeffd1fcc2848
UNKNOWN
Welcome. In this kata you are required to, given a string, replace every letter with its position in the alphabet. If anything in the text isn't a letter, ignore it and don't return it. `"a" = 1`, `"b" = 2`, etc. ## Example ```python alphabet_position("The sunset sets at twelve o' clock.") ``` Should return `"20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11"` (as a string)
["def alphabet_position(text):\n return ' '.join(str(ord(c) - 96) for c in text.lower() if c.isalpha())", "def alphabet_position(s):\n return \" \".join(str(ord(c)-ord(\"a\")+1) for c in s.lower() if c.isalpha())\n", "alphabet = 'abcdefghijklmnopqrstuvwxyz'\n\ndef alphabet_position(text):\n if type(text) == str:\n text = text.lower()\n result = ''\n for letter in text:\n if letter.isalpha() == True:\n result = result + ' ' + str(alphabet.index(letter) + 1)\n return result.lstrip(' ')", "from string import ascii_lowercase\n\n\ndef alphabet_position(text):\n return ' '.join(str(ascii_lowercase.index(n.lower()) + 1) for n in text if n.isalpha())", "import string\n\ndef alphabet_position(text):\n return \" \".join([str(string.lowercase.index(letter.lower())+1) for letter in list(text) if letter.isalpha()])", "def get_positions(text):\n for char in text:\n pos = ord(char)\n if pos >= 65 and pos <= 90:\n yield pos - 64\n if pos >= 97 and pos <= 122:\n yield pos - 96\n\ndef alphabet_position(text):\n return \" \".join((str(char) for char in get_positions(text)))\n", "def alphabet_position(text):\n alphabet = { 'a' : 1,\n 'b' : 2,\n 'c' : 3,\n 'd' : 4,\n 'e' : 5,\n 'f' : 6,\n 'g' : 7,\n 'h' : 8,\n 'i' : 9,\n 'j' : 10,\n 'k' : 11,\n 'l' : 12,\n 'm' : 13,\n 'n' : 14,\n 'o' : 15,\n 'p' : 16,\n 'q' : 17,\n 'r' : 18,\n 's' : 19,\n 't' : 20,\n 'u' : 21,\n 'v' : 22,\n 'w' : 23,\n 'x' : 24,\n 'y' : 25,\n 'z' : 26, }\n inds = []\n for x in text.lower():\n if x in alphabet:\n inds.append(alphabet[x])\n return ' '.join(([str(x) for x in inds]))\n\n", "def alphabet_position(text):\n al = 'abcdefghijklmnopqrstuvwxyz'\n return \" \".join(filter(lambda a: a != '0', [str(al.find(c) + 1) for c in text.lower()]))", "def alphabet_position(text):\n \n upper_alpha = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n lower_alpha = \"abcdefghijklmnopqrstuvwxyz\"\n l = [] \n \n for i in text:\n if i in upper_alpha:\n index = upper_alpha.index(i) + 1\n l.append(str(index))\n elif i in lower_alpha:\n index = lower_alpha.index(i) + 1\n l.append(str(index)) \n return \" \" .join(l)", "#import string so we can generate the alphabets using string.ascii\nimport string\n\ndef alphabet_position(text):\n lower_case_text = text.lower() #convert the given text into all lowercase letters\n alphabet = string.ascii_lowercase # generate lowercase letters from the string module\n number = list(range(1, 27)) #generate numbers from 1-26\n dict_alphabet_number = dict(list(zip(alphabet, number))) # combine the aphabets in a dictionary using dict and zip\n collector = [] # create a container to old the numbers generated from the loop\n \n for element in lower_case_text: \n if element in alphabet:\n collector.append(str(dict_alphabet_number[element])) \n return ' '.join(collector)\n \n \n \n"]
{"fn_name": "alphabet_position", "inputs": [["-.-'"]], "outputs": [[""]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,491
def alphabet_position(text):
c4cad86a3420097aa60978f496b279c4
UNKNOWN
All of the animals are having a feast! Each animal is bringing one dish. There is just one rule: the dish must start and end with the same letters as the animal's name. For example, the great blue heron is bringing garlic naan and the chickadee is bringing chocolate cake. Write a function `feast` that takes the animal's name and dish as arguments and returns true or false to indicate whether the beast is allowed to bring the dish to the feast. Assume that `beast` and `dish` are always lowercase strings, and that each has at least two letters. `beast` and `dish` may contain hyphens and spaces, but these will not appear at the beginning or end of the string. They will not contain numerals.
["def feast(beast, dish):\n return beast[0]==dish[0] and dish[-1]==beast[-1]", "def feast(beast, dish):\n return beast[0] == dish[0] and beast[-1] == dish[-1] ", "def feast(beast, dish):\n return beast.startswith(dish[0]) and beast.endswith(dish[-1])", "def feast(beast, dish):\n \"\"\" (str, str) -> bool\n Return true if dish and beast start and end with same letters.\n \"\"\"\n return beast[0] == dish[0] and beast[-1] == dish[-1]", "def feast(beast, dish):\n return True if beast[:1] == dish[:1] and beast[-1] == dish [-1] else False", "def feast(beast, dish):\n if beast[0] == dish[0] and beast[-1] == dish[-1]:\n return True\n else:\n return False", "def feast(b, d):\n return b[::len(b)-1] == d[::len(d)-1]", "feast = lambda beast, dish: beast[0].lower()==dish[0].lower() and beast[-1].lower()==dish[-1].lower()", "feast = lambda beast, dish: beast[0] == dish[0] and beast[-1] == dish[-1]", "feast = lambda beast, dish: all([beast[i] == dish[i] for i in [0,-1]])", "feast = lambda b, d: (b[0], b[-1]) == (d[0], d[-1])", "def feast(beast, dish): \n return [beast[0], beast[-1]] == [dish[0], dish[-1]]\n \n", "def feast(beast, dish):\n # your code here\n pass\n b = beast.replace(\" \",\"\")\n length_b = len(b)\n \n d = dish.replace(\" \",\"\")\n length_d = len(d)\n \n new_b = b[0] + b[-1]\n new_d = d[0] + d[-1]\n \n return new_b == new_d", "def feast(beast, dish):\n return beast[0] + beast[-1] == dish[0] + dish[-1]", "def feast(beast: str, dish: str) -> bool:\n \"\"\"Return true if dish and beast start and end with same letters.\"\"\"\n return beast[0] == dish[0] and beast[-1] == dish[-1]", "def feast(beast, dish):\n dish_valid = (beast[0], beast[-1]) == (dish[0], dish[-1])\n return dish_valid\n", "def feast(beast, dish):\n return beast.endswith(dish[-1]) and beast.startswith(dish[0])", "def feast(beast, dish):\n return True if (beast[0], beast[-1]) == (dish[0], dish[-1]) else False\n pass", "def feast(beast, dish):\n return True if beast[0]==dish[0] and beast[::-1][0]==dish[::-1][0] else False", "def feast(beast, dish):\n \"\"\" (str, str) -> bool\n Return true if beast and dish start and end with same char.\n \"\"\"\n return beast[0] == dish[0] and beast[-1] == dish[-1] ", "def feast(beast, dish):\n if beast[0] == dish[0] and beast[-1] == dish[-1]:\n return True\n return False", "def feast(b, d):\n return b[0]+b[-1] == d[0]+d[-1]", "def feast(beast, dish):\n return beast[::len(beast)-1] == dish[::len(dish)-1]", "import re\n\ndef feast(beast, dish):\n return re.sub(r'\\B(.*)\\B', '', beast) == re.sub(r'\\B(.*)\\B', '', dish)", "feast = lambda a,b : 2==(lambda a,b,z,j : (lambda f, arg : sum([f(*a) for a in arg]))((lambda a,b : a==b),[[a[j],b[j]],[a[z],b[z]]]))(a,b,(lambda: 777).__code__.co_nlocals,-(lambda _: 777).__code__.co_nlocals)", "def feast(beast, dish): # your code here\n \n \n return dish.startswith(beast[0]) and dish.endswith(beast[-1])", "def feast(beast, dish):\n print(beast[1])\n print(beast[-1])\n print(dish[1])\n print(dish[-1])\n if beast[0] == dish[0] and beast[-1] == dish[-1]:\n return True\n else:\n return False", "def feast(beast, dish):\n x = beast[0] + beast[len(beast)-1]\n y = dish[0] + dish[len(dish)-1]\n if x == y:\n return True\n else:\n return False\n", "def feast(beast, dish):\n return (dish.startswith(beast[0]) and dish.endswith(beast[len(beast)-1]))", "feast = lambda beast, dish: beast[-1::1-len(beast)] == dish[-1::1-len(dish)]", "feast=lambda b,d:b[0]==d[0] and b[-1]==d[-1]", "feast=lambda s,d:(s[0],s[-1])==(d[0],d[-1])", "def feast(b,d):\n return b[0]==d[0] and b[-1]==d[-1]", "def feast(beast, dish):\n a = beast[0]\n b = beast[len(beast)-1]\n c = dish[0]\n d = dish[len(dish)-1]\n if a.lower() == c.lower() and b.lower() == d.lower():\n return True\n else:\n return False\n", "def feast(beast, dish):\n return beast[0:1] == dish[0:1] and beast[::-1][0:1] == dish[::-1][0:1]", "def feast(beast, dish):\n print(beast, dish)\n return beast[-1] == dish[-1] and beast[0] == dish[0]", "def feast(beast, dish):\n return beast.startswith(dish[:1]) & beast.endswith(dish[-1])", "def feast(beast, dish):\n return True if beast[::len(beast)-1] == dish[::len(dish)-1] else False", "def feast(beast, dish):\n res = False\n return beast[0] == dish[0] and beast[len(beast)-1] == dish[len(dish)-1]", "def feast(beast, dish):\n print(beast, dish)\n return beast[0] + beast[-1] == dish[0]+dish[-1]", "def feast(beast, dish):\n return beast and dish and beast[0] == dish[0] and beast[-1] == dish[-1]", "def feast(b, d):\n return d[0] == b[0] and d[-1] == b[-1]", "def feast(beast, dish):\n if beast[0] == dish[0] and beast[-1] == dish[-1]: return True\n else: return False\n \n \n# All of the animals are having a feast! Each animal is bringing one dish.\n# There is just one rule: the dish must start and end with the same letters \n# as the animal's name. For example, the great blue heron is bringing garlic\n# naan and the chickadee is bringing chocolate cake.\n\n", "def feast(beast, dish):\n return ''.join(beast.split())[0]==''.join(dish.split())[0] and ''.join(beast.split())[-1]==''.join(dish.split())[-1]", "def feast(beast, dish):\n for char in beast:\n if beast[0] == dish[0] and beast[-1] == dish[-1]:\n return True\n else:\n return False", "def feast(beast, dish):\n a = beast[0] + beast[-1]\n b = dish[0] + dish[-1]\n return a == b", "def feast(beast, dish):\n # your code here\n return (beast[0:1] == dish[0:1] and beast[-1:-2:-1] == dish[-1:-2:-1])", "def feast(beast, dish):\n bf, bl = beast[0], beast[-1]\n df, dl = dish[0], dish[-1]\n return (bf, bl) == (df, dl)", "def feast(beast, dish):\n return dish[0] == beast[0] and beast[-1] == dish[-1]\n\n", "def feast(beast, dish):\n beastList = list(beast)\n dishList = list(dish)\n if beastList[0] == dishList[0] and beastList[-1] == dishList[-1]: \n return True\n else: \n return False", "def feast(beast, dish):\n x = \"\".join(c for c in beast.split(\" \"))\n y = \"\".join(c for c in dish.split(\" \"))\n return (y[0] == x[0] and y[-1] == x[-1])\n", "def feast(beast, dish):\n return True if beast[0] == dish [0] and beast[-1] == dish[-1] else False\n\n\n\nfeast(\"brown bear\",\"bear claw\" )", "def feast(beast, dish):\n return all(beast[i]==dish[i] for i in (-1,0))", "def feast(beast, dish):\n if dish[len(dish)-1] != beast[len(beast)-1] and beast[0] != dish[0]:\n return False\n if dish[len(dish)-1] == beast[len(beast)-1] and beast[0] == dish[0]:\n return True\n else:\n return False", "def feast(beast: str, dish: str) -> bool:\n return True if dish.startswith(beast[0]) and dish.endswith(beast[-1]) else False", "def feast(beast, dish):\n first = beast[0]\n last = beast[-1]\n first1 = dish[0]\n last1 = dish[-1]\n if first == first1 and last == last1:\n return True\n else:\n return False", "def feast(beast, dish):\n beast\n if beast[0] == dish[0] and beast[-1] == dish[-1]:\n return True\n else:\n return False", "def feast(beast, dish):\n if beast[0] == dish[0] and beast[-1] == dish[-1]:\n return True\n elif beast[0] != dish[0] or beast[-1] != dish[-1]:\n return False", "def feast(beast, dish):\n \n beast.replace(' ','')\n beast_ls = [x for x in beast]\n \n dish.replace(' ','')\n dish_ls = [x for x in dish]\n \n if beast_ls[0] == dish_ls[0] and beast_ls[-1] == dish_ls[-1]:\n return True\n else:\n return False\n", "def feast(beast, dish):\n x=len(beast)\n y=len(dish)\n if (dish[0]==beast[0])and(beast[x-1]==dish[y-1]):\n return True\n else:\n return False\n # your code here\n pass", "def feast(beast, dish):\n firstletter = beast[0]\n lastletter = beast[-1]\n firstletterdish = dish[0]\n lastletterdish = dish[-1]\n return (firstletter,lastletter) == (firstletterdish,lastletterdish)", "def feast(b, d):\n return [b[0] == d[0], b[-1] == d[-1]] == [True, True]", "def feast(beast, dish):\n animalbegin=beast[0]\n animalend=beast[len(beast)-1]\n dishbegin=dish[0]\n dishend=dish[len(dish)-1]\n if animalbegin==dishbegin and animalend==dishend:\n return True\n return False", "def feast(b, d):\n result = False\n if d[0] == b[0] and d[-1] == b[-1]:\n result = True\n return result", "def feast(beast, dish):\n return True if dish[0] == beast[0] and dish[len(dish) - 1] == beast[len(beast) -1] else False", "def feast(beast, dish):\n return True if (beast.split()[0][0] == dish.split()[0][0]) and (beast.split()[-1][-1] == dish.split()[-1][-1]) else False\n", "def feast(beast, dish):\n dish_allowed = (beast[0] == dish[0]) and (beast[-1] == dish[-1])\n return dish_allowed", "def feast(beast, dish):\n # your code here\n return beast.startswith(dish[0]) and beast.endswith(dish[-1])\n # don't have to put True or False, as if they will return means its true\n", "def feast(beast, dish):\n # your code here\n if str(beast[0]) == str(dish[0]) and beast[-1] == dish[-1]:\n return True\n else:\n return False", "def feast(beast, dish):\n b_list = list(beast)\n d_list = list(dish)\n if b_list[0] == d_list[0] and b_list[-1] == d_list[-1]:\n return True\n else:\n return False", "def feast(beast, dish):\n fbeast, lbeast = beast[0], beast[-1]\n fdish, ldish = dish[0], dish[-1]\n\n return fbeast == fdish and lbeast == ldish", "def feast(beast, dish):\n print(beast, dish)\n return True if beast[-1] == dish[-1] and beast[0] == dish[0]else False", "def feast(beast, dish):\n # your code here\n print((beast+'*','-',dish+'*'))\n if beast[0] == dish[0]:\n if beast[-1] == dish[-1]:\n return True\n else:\n return False\n \n else:\n return False\n", "def feast(beast, dish):\n print(beast,dish)\n if beast[0]==dish[0] and beast[-1]==dish[-1]:\n return True\n else:\n return False\n # your code here\n pass", "def feast(beast, dish):\n for i in beast:\n if beast[0] == dish[0]:\n if beast[-1] == dish[-1]:\n return True\n else:\n return False\n else:\n return False\n \n \n", "def feast(beast, dish):\n lower1= beast.lower()\n lower2= dish.lower()\n list1 = lower1[0]\n list2 = lower2[0]\n list3 = lower1[-1]\n list4 = lower2[-1]\n if list1 == list2 and list3 == list4:\n return True\n else:\n return False", "def feast(beast, dish):\n if beast[0] == dish[0] and beast[-1] == dish[-1]:\n return True\n else:\n return False\n\n\n #lengthf = len(first)\n # lengths = len(second)\n # if second in first[-lengths:]:\n # return True\n # else:\n # return False\n", "#input - two strings\n#ouput - boolean\n#edge cases - empty string?, all lower case letters, hyphens and spaces are allowed but not at beginning or end of string\n#assumptions/end goal - this function needs to return true if first and last letters of beast are same as dish. Return false if not.\n\n#sample data\n#(\"great blue heron\", \"garlic naan\") = True\n#(\"chick-a-dee\", \"chocolate cake\") = True\n#(\"chickadee\", \"chocolate croissant\") = False\n#(\"german*8shephard\", \"gluten snack\") = False\n\n\n#function feast takes two arguments, beast & dish\ndef feast(beast, dish):\n#heck if the first letter and last letters are the same and return True if they are\n return beast[0] == dish[0] and beast[-1] == dish[-1]\n", "def feast(beast, dish):\n if (beast and dish) != \"\":\n if beast[0] == dish[0] and beast[-1] == dish[-1]:\n return True\n else:\n return False\n else:\n return False", "feast = lambda beast,dish: beast.startswith(dish[0]) and beast.endswith(dish[-1])", "feast = lambda beast, dish: dish.startswith(beast[0]) and dish.endswith(beast[-1])", "def feast(beast, dish):\n f, s=beast[0], beast[-1]\n return dish[0]==f and dish[-1]==s", "def feast(beast, dish):\n \n \n # your code here\n x = beast[0]\n y = dish[0]\n z = beast[-1]\n k = dish[-1]\n if (x == y) and (z == k):\n return True\n else:\n return False\n", "def feast(beast, dish):\n #if beast[0]==dish[0] and beast[-1]==dish[-1]:\n # return True\n #else:\n # return False\n #return beast[0]==dish[0] and beast[-1]==dish[-1]\n return beast.startswith(dish[0]) and beast.endswith(dish[-1])", "def feast(beast, dish):\n # your code here\n pass\n indexBeast = len(beast)\n indexDish = len(dish)\n beast1 = beast[0]\n beastLast = beast[indexBeast-1]\n dish1 = dish[0]\n dishLast = dish[indexDish-1]\n \n if beast1 == dish1 and beastLast == dishLast:\n return True\n else :\n return False", "def feast(beast, dish):\n bfirst = beast[0]\n blast = beast[-1]\n dfirst = dish[0]\n dlast = dish[-1]\n if bfirst == dfirst and blast == dlast:\n return(True)\n else:\n return(False)", "def feast(beast, dish):\n # your code here\n \n if beast[-1].lower() == dish[-1].lower() and beast[0].lower() == dish[0].lower() :\n return True\n else:\n return False\n", "def feast(beast, dish):\n beast = beast.lower()\n dish = dish.lower()\n return beast[0] == dish[0] and beast[-1] == dish[-1]", "def feast(beast, dish):\n # if beast[0] == dish[0] and beast[last index] == dish[last index] return True \n return beast[0] == dish[0] and beast[-1] == dish[-1]\n", "def feast(beast, dish):\n start = beast.startswith(dish[0])\n finish = beast.endswith(dish[-1:])\n \n if start and finish:\n return True\n return False", "def feast(b, d):\n x = [b[0] , b[len(b)-1]]\n y = [d[0] , d[len(d)-1]]\n return x==y\n", "def feast(beast, dish):\n start = beast.startswith(dish[:1])\n end = beast.endswith(dish[-1:])\n return start and end\n", "def feast(beast, dish):\n beast = beast.lower()\n dish = dish.lower()\n if beast[-1] == dish[-1] and beast[0] == dish[0]:\n return True\n else:\n return False\n \nfeast(\"Faris\",\"Mangos\")", "def feast(beast, dish):\n is_valid = True\n if beast[0] == dish[0] and beast[len(beast) - 1] == dish[len(dish) - 1]:\n is_valid = True\n return is_valid\n else:\n is_valid = False\n return is_valid\n", "def feast(beast, dish):\n a = beast[0]\n b = beast[-1]\n c = dish[0]\n d = dish[-1]\n if a == c:\n if b == d:\n return True\n else:\n return False \n elif a != c:\n return False", "import unittest\n\n\ndef feast(beast, dish):\n return True if beast[0] == dish[0] and beast[-1] == dish[-1] else False\n \n \nclass TestFeast(unittest.TestCase):\n def test_should_return_false_when_given_first_char_and_end_char_of_beast_name_is_not_same_with_dish(self):\n beast, dish = \"brown bear\", \"bear claw\"\n actual = feast(beast, dish)\n self.assertEqual(actual, False)\n\n def test_should_return_true_when_given_first_char_and_end_char_of_beast_name_is_same_with_dish(self):\n beast, dish = \"great blue heron\", \"garlic naan\"\n actual = feast(beast, dish)\n self.assertEqual(actual, True)\n", "def feast(beast, dish):\n a=len(dish)-1\n if beast[0]==dish[0] and beast[len(beast)-1]==dish[a]: \n return True\n else:\n return False", "def feast(beast, dish):\n print(beast, dish)\n # your code here\n return dish.startswith(beast[0]) and dish.endswith(beast[-1])", "def feast(beast, dish):\n \n l1 = len(beast) - 1\n l2 = len(dish) - 1\n \n \n return beast[0] == dish[0] and beast[l1] == dish[l2]", "def feast(beast, dish):\n if beast[-1] == dish[-1] and beast[0] == dish[0]:\n return True\n return False"]
{"fn_name": "feast", "inputs": [["great blue heron", "garlic naan"], ["chickadee", "chocolate cake"], ["brown bear", "bear claw"], ["marmot", "mulberry tart"], ["porcupine", "pie"], ["cat", "yogurt"], ["electric eel", "lasagna"], ["slow loris", "salsas"], ["ox", "orange lox"], ["blue-footed booby", "blueberry"], ["fruit-fly", "blueberry"]], "outputs": [[true], [true], [false], [true], [true], [false], [false], [true], [true], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
16,315
def feast(beast, dish):
7aec952afdf5f849964667cdb63544fe
UNKNOWN
Write a function that rearranges an integer into its largest possible value. ```python super_size(123456) # 654321 super_size(105) # 510 super_size(12) # 21 ``` ``` haskell superSize 123456 `shouldBe` 654321 superSize 105 `shouldBe` 510 superSize 12 `shouldBe` 21 ``` If the argument passed through is single digit or is already the maximum possible integer, your function should simply return it.
["def super_size(n):\n return int(''.join(sorted(str(n), reverse = True)))", "def super_size(n):\n b = list(str(n))\n b.sort(reverse=True)\n return int(\"\".join(b))\n", "def super_size(n):\n return int(''.join(sorted(str(n)))[::-1])", "super_size=lambda n: int(\"\".join(sorted(str(n),reverse=True)))", "def super_size(n):\n list_ = sorted(list(str(n)))\n list_.reverse()\n return int(''.join(tuple(list_)))", "def super_size(n):\n return int(''.join(sorted([i for i in str(n)])[::-1]))", "def super_size(n):\n arr = list(map(int,str(n)))\n arr.sort(reverse=True)\n strings = [str(integer) for integer in arr]\n a_string = \"\".join(strings)\n an_integer = int(a_string)\n return an_integer", "def super_size(n):\n x = sorted(list(str(n)), reverse=True)\n return int(''.join(x))\n #your code here\n", "def super_size(n):\n #your code here\n return int(''.join(str(x) for x in sorted([int(a) for a in str(n)], reverse=True)))\n", "def super_size(n):\n digits = sorted([d for d in str(n)],reverse=True)\n return int( ''.join(digits))\n\n", "def super_size(n):\n # your code here\n new = list(str(n))\n new = sorted(new, reverse=True)\n new = ''.join(new)\n return int(new)", "def super_size(n: int) -> int:\n \"\"\" Rearrange the integer into its largest possible value. \"\"\"\n return int(\"\".join(list(sorted(str(n), reverse=True))))", "def super_size(n):\n \n digitList = list(str(n))\n \n if len(digitList) == 1:\n return n\n else:\n digitList.sort()\n digitList.reverse()\n \n largestValue = ''\n for digit in digitList:\n largestValue += digit\n \n return int(largestValue)", "def super_size(n):\n if n < 0:\n raise ValueError\n elif n < 10:\n return n\n else:\n ans = sorted(str(n), reverse=True)\n return int(\"\".join(ans))", "def super_size(n):\n l = [int(i) for i in str(n)]\n s = \"\"\n while len(l) > 0 :\n s += str(l.pop( l.index(max(l)) ))\n return int(s)", "def super_size(n):\n l = list(str(n))\n l = sorted(l, reverse = True)\n return int(''.join(l))", "def super_size(num):\n res = [x for x in str(num)] \n Sorted_res = sorted(res, reverse=True)\n Sorted_string = ''.join(Sorted_res)\n return int(Sorted_string)\n", "def super_size(n):\n li = list()\n p = ''\n for i in str(n):\n li.append((i))\n for j in range(len(li)):\n p+=max(li)\n li.remove(max(li))\n return int(p)", "def super_size(n):\n lista1 = list(str(n))\n lista = []\n for num in lista1:\n lista.append(num)\n \n for i in range(0, len(lista)):\n lista[i] = int(lista[i])\n \n lista.sort(reverse = True)\n lista_buna = int(''.join(str(i) for i in lista))\n return lista_buna\n", "def super_size(n):\n num_str = list(str(n))\n num_str.sort(reverse=True)\n res = int(\"\".join(num_str))\n return(res)\n\n", "def super_size(n):\n li = list(str(n))\n li.sort(reverse = True)\n return int(''.join(li))", "def super_size(n):\n li = list(str(n)) \n li.sort() \n li.reverse() \n temp = ''\n for i in range(len(li)):\n temp += li[i]\n return int(temp)", "def super_size(n):\n return int(''.join(sorted(str(n)[::-1]))[::-1])", "def super_size(n): \n return int(''.join(list([str(x) for x in sorted([int(i) for i in str(n)], reverse=True)])))\n \n", "def super_size(n):\n list = [str(i) for i in str(n)]\n list.sort(reverse=True)\n result = int(\"\".join(list))\n return result", "def super_size(n):\n result = \"\"\n num = sorted([int(d) for d in str(n)])[::-1]\n for n in num:\n result += str(n) \n return int(result)", "def super_size(n):\n temp = sorted(str(n), reverse=True)\n temp2 = ''\n for i in temp:\n temp2 += i\n return int(temp2)", "def super_size(n):\n a = sorted(str(n), reverse=True)\n str1 = ''\n for i in a:\n str1 += i\n return int(str1)", "def super_size(n):\n # sorted returns a list with the sorted elements of the input string\n return int(\"\".join(sorted(str(n), reverse=True)))", "def super_size(n):\n digits = [int(i) for i in str(n)]\n new_int = \"\"\n while digits:\n new_int += str(max(digits))\n digits.remove(max(digits))\n return int(new_int)", "def super_size(n):\n lst = sorted([int(c) for c in str(n)], reverse=True)\n return int(''.join([str(i) for i in lst]))", "def super_size(n):\n #your code here\n q = []\n for i in str(n):\n q.append(i)\n\n q.sort(reverse=True)\n q = ''.join(q)\n return int(q)", "def super_size(n):\n a = str(n)\n c = list(a)\n d = sorted(c,reverse = True)\n z = ''\n for i in d:\n z +=i\n return int(z) \n \n", "def super_size(n):\n lis = []\n for i in str(n):\n lis.append(i)\n lis.sort(reverse = True)\n x = int(''.join(lis))\n return x", "def super_size(n):\n x = list(str(n))\n z = []\n for k in x:\n z.append(int(k))\n z.sort()\n z = z[::-1]\n y = ''\n for k in z:\n y += str(k)\n y = int(y)\n return y\n \n \n #your code here\n", "def super_size(n):\n s = ''\n a = sorted(str(n))[::-1]\n print(a)\n for j in a:\n s += str(j)\n return int(s)\n", "def super_size(n):\n n_list = (sorted([int(number) for number in str(n)], reverse = True))\n return int(\"\".join(str(number) for number in n_list))", "def super_size(n):\n bigest = \"\"\n amount = len(str(n))\n numbers = []\n n = str(n)\n for i in range(amount):\n numbers.append(n[i])\n numbers.sort(reverse = True)\n for i in range(amount):\n bigest += numbers[i]\n bigest = int(bigest)\n return(bigest)", "def super_size(n):\n n_list = [i for i in str(n)]\n n_list.sort(reverse=True)\n return int(\"\".join(n_list))", "def super_size(n):\n p = list(str(n))\n p.sort()\n return int(''.join(reversed(p)))", "def super_size(n):\n st = \"\".join(sorted(str(n), reverse = True))\n return int(st)", "def super_size(n):\n st = \"\".join(sorted(list(str(n)), reverse=True))\n return int(st)\n \n", "def super_size(n):\n a = list(str(n))\n a.sort(reverse=True)\n n = \"\".join(a)\n n = int(n)\n return n", "def super_size(n):\n num=str(n)\n arr=[]\n for i in range(0,len(num)):\n arr.append(num[i])\n arr.sort(reverse=True)\n return int(''.join(arr))\n", "def super_size(n):\n a = []\n for i in range(len(str(n))):\n a.append(n%10)\n n //= 10\n a = list(reversed(sorted(a)))\n num = 0\n for i in a:\n num = num * 10 + i\n return num", "def super_size(n):\n ln = []\n for x in str(n):\n ln.append(x)\n ln.sort()\n ln.reverse()\n return int(''.join(ln))", "def super_size(n):\n b = list(str(n))\n b.sort()\n r = ''\n for i in b[::-1]:\n r += i\n return int(r)\n", "def super_size(n):\n n_str = str(n)\n str_sort = sorted(n_str, reverse = True)\n output = \"\"\n for num in str_sort:\n output = output + num\n return int(output)", "def super_size(n):\n arr = [x for x in str(n)]\n arr.sort(reverse = True)\n return int(''.join(arr))", "def super_size(n):\n uporz = list(str(n))\n uporz.sort(reverse=True)\n return int(''.join(uporz))", "super_size = lambda n : int(\"\".join(sorted([digit for digit in str(n)])[::-1]))\n", "def super_size(n):\n #your code here\n convert_to_str = str(n)\n lst = convert_to_str.split()\n for elem in convert_to_str:\n lst.append(elem)\n lst.pop(0)\n num_list = []\n for num in lst:\n num_list.append(int(num))\n srt = sorted(num_list, reverse = True)\n string = \"\".join(str(srt))\n rep1 = string.replace(\"[\", \"\")\n rep2 = rep1.replace(\"]\", \"\")\n rep3 = rep2.replace(\",\", \"\")\n rep4 = rep3.replace(\" \", \"\")\n return int(rep4)", "def super_size(n):\n l = [int(i) for i in str(n)]\n l.sort(reverse = True)\n return int(\"\".join([str(i) for i in l]))", "def super_size(n):\n res = \"\"\n n = list(str(n))\n for i in range(len(n)):\n res += str(max(n))\n n.remove(max(n))\n return int(res)", "def super_size(n):\n n = str(n)\n a = n[:]\n b = []\n for elem in a:\n b += elem\n b.sort()\n b.reverse()\n s = \"\"\n s = s.join(b)\n m = int(s)\n\n return m", "def super_size(n):\n l = []\n s = ''\n for i in str(n):\n l.append(int(i))\n for i in sorted(l,reverse=True):\n s += str(i)\n return int(s)", "def super_size(n):\n lst = list(str(n))\n lst.sort()\n return int(''.join(lst[::-1]))", "def super_size(n):\n a = [i for i in str(n)]\n out = ''\n while len(a):\n out = out + max(a)\n a.remove(max(a))\n \n return int(out)", "def super_size(n):\n return int(''.join(reversed(sorted([*str(n)]))))", "from functools import reduce\ndef super_size(n):\n car=sorted([int(x) for x in str(n)], reverse=True)\n van=(str(a) for a in car)\n return int(\"\".join(van))\n", "def super_size(m):\n arr = [int(x) for x in str(m)]\n n = len(arr)\n result = ''\n for i in range(n-1): \n for j in range(0, n-i-1): \n if arr[j] > arr[j+1] : \n arr[j], arr[j+1] = arr[j+1], arr[j]\n arr.reverse() \n string_new = [str(i) for i in arr] \n result = int(\"\".join(string_new)) \n return(result) ", "def super_size(n):\n lst=[i for i in str(n)]\n return int(''.join(sorted(lst,reverse=True)))\n\n", "def super_size(n):\n n_str = str(n)\n n_sorted = sorted(n_str, reverse=True)\n output_str = \"\" \n for num in n_sorted:\n output_str = output_str + num\n if n_str == n_sorted:\n return int(n_str)\n else: \n return int(output_str)\n", "def super_size(n):\n num = [int(x) for x in str(n)] # convert to list\n num.sort(reverse=True) #sort descending\n num_str = [str(x) for x in num] #convert list ints to strs, there's got to be a less stupid way\n big_num_str = \"\".join(num_str) #join into a integer\n return int(big_num_str)", "def super_size(n):\n x = sorted([int(x) for x in str(n)])[::-1]\n return int(''.join(map(str, x)))", "def super_size(n):\n ints = [int(thing) for thing in list(str(n))]\n ints = sorted(ints, reverse=True)\n strings = [str(integ) for integ in ints]\n new_str = ''.join(strings)\n return int(new_str)\n \n \n \n", "def super_size(n):\n n = list(str(n))\n ans = \"\"\n while len(n) > 0: \n temp = max(n)\n ans += temp\n n.remove(temp)\n return int(ans)", "def super_size(n):\n \n list = []\n textNb = \"\"\n \n for nb in str(n):\n list.append(nb)\n \n list.sort(reverse=True)\n \n for ch in list:\n textNb += ch\n \n return int(textNb)\n \n", "def super_size(n):\n x =[i for i in str(n)]\n x = sorted(x, reverse= True)\n return int(\"\".join(x))", "def super_size(n):\n items = [int(x) for x in str(n)]\n items.sort(reverse=True)\n itemStr = \"\".join(str(d) for d in items)\n return int(itemStr)", "def super_size(n):\n sorted_integers = sorted(str(n), reverse=True)\n supersized_n = int(\"\".join(sorted_integers))\n return supersized_n", "def super_size(n):\n nn = str(n)\n num = []\n for i in nn:\n num.append(int(i))\n numnum = sorted(num)\n numnum.reverse()\n for i in numnum:\n return int(''.join(str(i) for i in numnum))", "def super_size(n):\n #your code here\n b = sorted([int(x) for x in str(n)], reverse=True)\n return int(\"\".join(map(str, b)))", "def super_size(n):\n n_str = str(n)\n n_sorted = sorted(n_str, reverse=True)\n res = int(\"\".join(n_sorted))\n return res\n\n\n", "def super_size(n):\n s = sorted(list(str(n)))\n s.reverse()\n return int(''.join(s))", "def super_size(n):\n a=[0,0,0,0,0,0,0,0,0,0]\n while n>=1:\n a[n%10]+=1\n n//=10\n ans=0\n for i in range(9,-1,-1):\n while a[i]:\n ans*=10\n ans+=i\n a[i]-=1\n return ans", "def super_size(n):\n n = str(n)\n n = sorted(n)\n n = ''.join(n)\n return int(n[::-1])", "def super_size(n):\n temp = [int(x) for x in str(n)]\n temp.sort(reverse=True)\n strings = [str(integer) for integer in temp]\n a_string = \"\".join(strings)\n an_integer = int(a_string)\n return an_integer\n #your code here\n", "def super_size(n):\n sort_numbers = sorted(str(n))\n sort_numbers.reverse()\n return int(''.join(map(str,sort_numbers)))", "def super_size(n):\n if len(str(n)) > 1:\n array_numbers = map(int, str(n))\n sorted_arrays = sorted(array_numbers, reverse=True)\n strings = [str(sorted_array) for sorted_array in sorted_arrays]\n a_string = \"\".join(strings)\n result = int(a_string)\n return result\n else:\n return n", "def super_size(n):\n return int(''.join(sorted([*str(n)], reverse=True)))", "def super_size(n):\n singleValues = []\n x=1\n result=0\n \n while n >= 1:\n singleValues.append(n % 10)\n print((n%10))\n n = int(n / 10)\n \n\n singleValues.sort()\n print(singleValues)\n\n for i in singleValues:\n result = result + i * x\n x = x*10\n\n print(result)\n return(int(result))\n", "def super_size(n):\n #your code here\n \n s = [int(i) for i in str(n)]\n s.sort(reverse = True)\n s = [str(x) for x in s]\n res = int(\"\".join(s))\n return res\n\n \n \n \n", "def super_size(n):\n w = list(str(n))\n w.sort(reverse=True)\n return int(''.join(w))", "def super_size(n):\n n_list = list(str(n))\n n_list.sort(reverse=True)\n n_string = ''.join(n_list)\n return int(n_string)\n", "def super_size(n):\n m=str(n)\n l=list()\n for i in range(len(m)):\n l.append(int(m[i]))\n k=sorted(l, reverse = True)\n res=list()\n for i in range(len(k)):\n res.append(str(k[i]))\n f=''.join(res)\n return int(f)", "def super_size(n):\n list1=[]\n for i in str(n):\n list1.append(i)\n list1.sort()\n list1.reverse()\n return int(''.join(list1))", "def super_size(n):\n n1 = [int(i) for i in list(str(n))]\n n1.sort(reverse = True)\n n1 = int(\"\".join([str(i) for i in n1]))\n return n1", "def super_size(n):\n L = [int(i) for i in str(n)]\n L.sort(reverse = True)\n S = [str(i) for i in L]\n A = \"\".join(S)\n return int(A)", "def super_size(n):\n #your code here\n a = []\n b = len(str(n))\n for i in range(b):\n n = str(n)\n a.append(n[i])\n \n a = sorted(a)\n a = a[::-1]\n c = ''\n for i in range(b):\n c+=a[i]\n \n return int(c)\n", "def super_size(n):\n n_str = str(n)\n n_sorted = sorted(n_str, reverse = True)\n sorted_str = \"\" \n for i in n_sorted:\n sorted_str += i\n return int(sorted_str)", "def super_size(n):\n a = sorted(str(n), reverse = True)\n b = int(''.join(a))\n return b", "def super_size(n):\n big = list(str(n))\n big.sort(reverse=True)\n return int(\"\".join(big))\n\n", "def super_size(n):\n \"\"\"Function that rearranges an integer into its largest possible value.\n :param int n\n integer to rearranges\n \"\"\"\n number_list = list(str(n))\n number_list.sort(reverse=True)\n return int(''.join(number_list))", "def super_size(n):\n size_str = ''\n size_list = [int(i) for i in str(n)]\n for _ in range(len(size_list)):\n i = max(size_list)\n size_str+=str(i)\n size_list.remove(i)\n return int(size_str)\n \n", "def super_size(n):\n ll = list()\n while n != 0:\n ll.append(n % 10)\n n //= 10\n ll = sorted(ll, reverse = True)\n res = 0\n \n for digit in ll:\n res = res * 10 + digit\n\n return res", "def super_size(n):\n n_str = str(n)\n n_sorted = sorted(n_str, reverse=True)\n n_joined = ''\n\n for i in n_sorted:\n n_joined += i\n\n n_reverse = int(n_joined)\n return n_reverse\n"]
{"fn_name": "super_size", "inputs": [[69], [513], [2017], [414], [608719], [123456789], [700000000001], [666666], [2], [0]], "outputs": [[96], [531], [7210], [441], [987610], [987654321], [710000000000], [666666], [2], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
16,406
def super_size(n):
b5a673ea731c28216a0d44e8dac5bf87
UNKNOWN
# Task **Your task** is to implement function `printNumber` (`print_number` in C/C++ and Python `Kata.printNumber` in Java) that returns string that represents given number in text format (see examples below). Arguments: - `number` — Number that we need to print (`num` in C/C++/Java) - `char` — Character for building number (`ch` in C/C++/Java) # Examples ```c,python print_number(99, '$') //Should return //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n //$ $\n //$ $$$$ $$$$ $$$$ $$$$ $$$$ $\n //$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $\n //$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $\n //$ $$ $$ $$ $$ $$ $$ $$$$ $$$$ $\n //$ $$ $$ $$ $$ $$ $$ $$ $$ $\n //$ $$$$ $$$$ $$$$ $$ $$ $\n //$ $\n //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ print_number(12345, '*') //Should return //****************************************\n //* *\n //* ** **** **** ** ** ****** *\n //* *** ** ** ** ** ** ** ** *\n //* * ** ** ** ** ** ***** *\n //* ** ** ** ***** ** *\n //* ** ** ** ** ** ** *\n //* ****** ****** **** ** ***** *\n //* *\n //**************************************** print_number(67890, '@') //Should return //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n //@ @\n //@ @@ @@@@@@ @@@@ @@@@ @@@@ @\n //@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @\n //@ @@@@ @@ @@@@ @@ @@ @@ @@ @\n //@ @@ @@ @@ @@@@ @@@@ @@ @@ @\n //@ @@ @@ @@ @@ @@ @@ @@ @@ @\n //@ @@@@ @@ @@@@ @@ @@@@ @\n //@ @\n //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ``` >***Note, that***: - Number should be `0 <= number <= 99999` and have `5 digits` (should have zeros at the start if needed) - Test cases contains only valid values (integers that are 0 <= number <= 99999) and characters - Numbers should have the same shape as in the examples (6x6 by the way) - Returned string should be joined by `\n` character (except of the end) - Returned string should have 1 character *(height)* border (use the same character as for number) + padding (1 character in height vertical and 2 horizontal with ` `) around borders and 1 character margin between "digits" *Suggestions and translations are welcome.*
["L = (\n (' #### ', ' ## ', ' #### ', ' #### ', '## ##', '######', ' ## ', '######', ' #### ', ' #### ').__getitem__,\n ('## ##', ' ### ', '## ##', '## ##', '## ##', '## ', ' ## ', '## ##', '## ##', '## ##').__getitem__,\n ('## ##', '# ## ', ' ## ', ' ## ', '## ##', '##### ', ' #### ', ' ## ', ' #### ', '## ##').__getitem__,\n ('## ##', ' ## ', ' ## ', ' ## ', ' #####', ' ##', '## ##', ' ## ', ' #### ', ' #### ').__getitem__,\n ('## ##', ' ## ', ' ## ', '## ##', ' ##', ' ##', '## ##', ' ## ', '## ##', ' ## ').__getitem__,\n (' #### ', '######', '######', ' #### ', ' ##', '##### ', ' #### ', ' ## ', ' #### ', ' ## ').__getitem__\n)\n\ndef print_number(number, char): \n s1, s2, l = '#'*40, f\"#{' '*38}#\", list(map(int, f\"{number:05}\"))\n return '\\n'.join([s1, s2] + [f\"# {' '.join(map(L[i], l))} #\" for i in range(6)] + [s2, s1]).replace('#', char)", "# Build digit templates from the given examples in the instructions\nexample_text = r\"\"\"\n//* ** **** **** ** ** ****** *\\n\n//* *** ** ** ** ** ** ** ** *\\n\n//* * ** ** ** ** ** ***** *\\n\n//* ** ** ** ***** ** *\\n\n//* ** ** ** ** ** ** *\\n\n//* ****** ****** **** ** ***** *\\n\n//@ @@ @@@@@@ @@@@ @@@@ @@@@ @\\n\n//@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @\\n\n//@ @@@@ @@ @@@@ @@ @@ @@ @@ @\\n\n//@ @@ @@ @@ @@@@ @@@@ @@ @@ @\\n\n//@ @@ @@ @@ @@ @@ @@ @@ @@ @\\n\n//@ @@@@ @@ @@@@ @@ @@@@ @\\n\n\"\"\"\n# Clean/standardise the source text\nexample_text = [\n l[5:-4] \n for l in example_text.replace('@', '*').split('\\n') \n if l.strip()\n]\n# Extract the 7x6 super digits\nSUPER_DIGITS = []\nfor super_line in [example_text[:6], example_text[6:]]:\n for i in range(5):\n SUPER_DIGITS.append([line[i * 7:(i + 1) * 7] for line in super_line])\n# Move the 0 from the end to start\nSUPER_DIGITS.insert(0, SUPER_DIGITS.pop(-1))\n\n\ndef print_number(number, char): \n # Pad to 5 digits\n digits = str(number).rjust(5, '0')\n \n # Add the digits (each one has a trailing space)\n lines = ['' for _ in range(6)]\n for d in digits:\n for i in range(6):\n lines[i] += SUPER_DIGITS[int(d)][i]\n \n # Justify\n lines = [f' {l} ' for l in lines]\n width = len(lines[0])\n # Add header\n lines.insert(0, '*' * width)\n lines.insert(1, ' ' * width)\n # Add footer\n lines.append(' ' * width)\n lines.append('*' * width)\n # Add border\n lines = [f'*{l}*' for l in lines]\n # Concatenate and substitute\n return '\\n'.join(lines).replace('*', char)\n", "def print_number(number, char): \n separator_arr = [' ' for i in range(10)]\n separator_arr[0] = char\n separator_arr[9] = char\n border_arr = [char for i in range(10)] \n char_2 = char * 2\n char_3 = char * 3\n char_4 = char * 4\n char_5 = char * 5\n char_6 = char * 6\n space_2 = ' ' * 2\n space_3 = ' ' * 3\n space_4 = ' ' * 4\n space_6 = ' ' * 6\n sccccs = f' {char_4} '\n ccsscc = f'{char_2}{space_2}{char_2}'\n ssccss = f'{space_2}{char_2}{space_2}'\n sssccs = f'{space_3}{char_2} '\n sccsss = f' {char_2}{space_3}'\n sssscc = f'{space_4}{char_2}'\n ccssss = f'{char_2}{space_4}'\n cccccs = f'{char_5} '\n sssccs = f'{space_3}{char_2} '\n digits = {\n '0' : [char_6, space_6, sccccs, ccsscc, ccsscc, \n ccsscc, ccsscc, sccccs, space_6, char_6],\n '1' : [char_6, space_6, ssccss, f' {char_3}{space_2}', f'{char} {char_2}{space_2}', \n ssccss, ssccss, char_6, space_6, char_6],\n '2' : [char_6, space_6, sccccs, ccsscc, sssccs, \n ssccss, sccsss, char_6, space_6, char_6],\n '3' : [char_6, space_6, sccccs, ccsscc, sssccs, \n sssccs, ccsscc, sccccs, space_6, char_6],\n '4' : [char_6, space_6, ccsscc, ccsscc, ccsscc, \n f' {char_5}', sssscc, sssscc, space_6, char_6],\n '5' : [char_6, space_6, char_6, ccssss, cccccs, \n sssscc, sssscc, cccccs, space_6, char_6],\n '6' : [char_6, space_6, sssccs, ssccss, sccccs, \n ccsscc, ccsscc, sccccs, space_6, char_6],\n '7' : [char_6, space_6, char_6, ccsscc, sssccs, \n ssccss, sccsss, sccsss, space_6, char_6],\n '8' : [char_6, space_6, sccccs, ccsscc, sccccs, \n sccccs, ccsscc, sccccs, space_6, char_6],\n '9' : [char_6, space_6, sccccs, ccsscc, ccsscc, \n sccccs, ssccss, sccsss, space_6, char_6], \n }\n \n def normalize(n):\n if n > 9999:\n return str(n)\n else:\n return str(n).rjust(5, '0')\n num = normalize(number)\n final_result = []\n for i in range(10):\n final_result.append(f'{border_arr[i]}{separator_arr[i]}{separator_arr[i]}{digits[num[0]][i]}{separator_arr[i]}'\n f'{digits[num[1]][i]}{separator_arr[i]}{digits[num[2]][i]}{separator_arr[i]}' \n f'{digits[num[3]][i]}{separator_arr[i]}{digits[num[4]][i]}{separator_arr[i]}{separator_arr[i]}{border_arr[i]}')\n\n return '\\n'.join(final_result)\n \n \n \n \n \n", "import sys\ndef print_number(num, char): \n num = str(num).rjust(5,'0')\n A = [[\" **** \",\" ** \",\" **** \",\" **** \",\"** **\",\"******\",\" ** \",\"******\",\" **** \",\" **** \"],\n [\"** **\",\" *** \",\"** **\",\"** **\",\"** **\",\"** \",\" ** \",\"** **\",\"** **\",\"** **\"],\n [\"** **\",\"* ** \",\" ** \",\" ** \",\"** **\",\"***** \",\" **** \",\" ** \",\" **** \",\"** **\"],\n [\"** **\",\" ** \",\" ** \",\" ** \",\" *****\",\" **\",\"** **\",\" ** \",\" **** \",\" **** \"],\n [\"** **\",\" ** \",\" ** \",\"** **\",\" **\",\" **\",\"** **\",\" ** \",\"** **\",\" ** \"],\n [\" **** \",\"******\",\"******\",\" **** \",\" **\",\"***** \",\" **** \",\" ** \",\" **** \",\" ** \"]]\n Out = '\\n'.join([char*40,char+\" \"*38+char,\"\"])\n for r in range(6):\n Out +=char+\" \"+' '.join(A[r][int(c)].replace(\"*\",char) for c in num)+' '+char+'\\n'\n Out += '\\n'.join([char+\" \"*38+char,char*40])\n return Out\n", "def print_number(number, char): \n dct = {'1': [' ** ', ' *** ', '* ** ', ' ** ', ' ** ', '******'],\n '2': [' **** ', '** **', ' ** ', ' ** ', ' ** ', '******'],\n '3': [' **** ', '** **', ' ** ', ' ** ', '** **', ' **** '],\n '4': ['** **', '** **', '** **', ' *****', ' **', ' **'],\n '5': ['******', '** ', '***** ', ' **', ' **', '***** '],\n '6': [' ** ', ' ** ', ' **** ', '** **', '** **', ' **** '],\n '7': ['******', '** **', ' ** ', ' ** ', ' ** ', ' ** '],\n '8': [' **** ', '** **', ' **** ', ' **** ', '** **', ' **** '],\n '9': [' **** ', '** **', '** **', ' **** ', ' ** ', ' ** '],\n '0': [' **** ', '** **', '** **', '** **', '** **', ' **** '] }\n s = str(number).zfill(5)\n top = [char*40, char + ' '*38 + char]\n bottom = [char + ' '*38 + char, char*40]\n middle = []\n for i in range(6):\n row = []\n for dig in s:\n row.append(dct[dig][i].replace('*', char) + ' ') \n middle.append('{0} {1} {0}'.format(char, ''.join(row)))\n return '\\n'.join(top + middle + bottom)\n\n \n", "def print_number(number, char): \n def str_cif(tupl, sym):\n rez = ''\n for i in tupl:\n if i == 1:\n rez += sym\n else:\n rez += ' '\n return rez\n razv = (((0,1,1,1,1,0),\n (1,1,0,0,1,1),\n (1,1,0,0,1,1),\n (1,1,0,0,1,1),\n (1,1,0,0,1,1),\n (0,1,1,1,1,0)),\n \n ((0,0,1,1,0,0),\n (0,1,1,1,0,0),\n (1,0,1,1,0,0),\n (0,0,1,1,0,0),\n (0,0,1,1,0,0),\n (1,1,1,1,1,1)),\n \n ((0,1,1,1,1,0),\n (1,1,0,0,1,1),\n (0,0,0,1,1,0),\n (0,0,1,1,0,0),\n (0,1,1,0,0,0),\n (1,1,1,1,1,1)),\n \n ((0,1,1,1,1,0),\n (1,1,0,0,1,1),\n (0,0,0,1,1,0),\n (0,0,0,1,1,0),\n (1,1,0,0,1,1),\n (0,1,1,1,1,0)),\n \n ((1,1,0,0,1,1),\n (1,1,0,0,1,1),\n (1,1,0,0,1,1),\n (0,1,1,1,1,1),\n (0,0,0,0,1,1),\n (0,0,0,0,1,1)),\n \n ((1,1,1,1,1,1),\n (1,1,0,0,0,0),\n (1,1,1,1,1,0),\n (0,0,0,0,1,1),\n (0,0,0,0,1,1),\n (1,1,1,1,1,0)),\n \n ((0,0,0,1,1,0),\n (0,0,1,1,0,0),\n (0,1,1,1,1,0),\n (1,1,0,0,1,1),\n (1,1,0,0,1,1),\n (0,1,1,1,1,0)),\n \n ((1,1,1,1,1,1),\n (1,1,0,0,1,1),\n (0,0,0,1,1,0),\n (0,0,1,1,0,0),\n (0,1,1,0,0,0),\n (0,1,1,0,0,0)),\n \n ((0,1,1,1,1,0),\n (1,1,0,0,1,1),\n (0,1,1,1,1,0),\n (0,1,1,1,1,0),\n (1,1,0,0,1,1),\n (0,1,1,1,1,0)),\n \n ((0,1,1,1,1,0),\n (1,1,0,0,1,1),\n (1,1,0,0,1,1),\n (0,1,1,1,1,0),\n (0,0,1,1,0,0),\n (0,1,1,0,0,0)))\n shap = char * 40 + '\\n' + char + ' ' * 38 + char + '\\n'\n podv = char + ' ' * 38 + char + '\\n' + char * 40\n str_number = '0' * (5 - len(str(number))) + str(number)\n num_prn = [int(i) for i in str_number]\n body = ''\n for i in range(6):\n body += char + ' '\n for n in num_prn:\n body += str_cif(razv[n][i], char) + ' '\n body += ' ' + char + '\\n'\n return shap + body + podv\n", "L = (\n (\" .... \", \".. ..\", \".. ..\", \".. ..\", \".. ..\", \" .... \"),\n (\" .. \", \" ... \", \". .. \", \" .. \", \" .. \", \"......\"),\n (\" .... \", \".. ..\", \" .. \", \" .. \", \" .. \", \"......\"),\n (\" .... \", \".. ..\", \" .. \", \" .. \", \".. ..\", \" .... \"),\n (\".. ..\", \".. ..\", \".. ..\", \" .....\", \" ..\", \" ..\"),\n (\"......\", \".. \", \"..... \", \" ..\", \" ..\", \"..... \"),\n (\" .. \", \" .. \", \" .... \", \".. ..\", \".. ..\", \" .... \"),\n (\"......\", \".. ..\", \" .. \", \" .. \", \" .. \", \" .. \"),\n (\" .... \", \".. ..\", \" .... \", \" .... \", \".. ..\", \" .... \"),\n (\" .... \", \".. ..\", \".. ..\", \" .... \", \" .. \", \" .. \")\n)\n\ndef print_number(number, char): \n s1, s2, l = '.'*40, f\".{' '*38}.\", list(map(int, f\"{number:05}\"))\n return '\\n'.join([s1, s2] + [f\". {' '.join(L[x][i] for x in l)} .\" for i in range(6)] + [s2, s1]).replace('.', char)", "def modify(M,n,r,c):\n if n==0:\n M[r][c]=' '\n M[r][c+5]=' '\n M[r+1][c+2]=' '\n M[r+1][c+3]=' '\n M[r+2][c+2]=' '\n M[r+2][c+3]=' '\n M[r+3][c+2]=' '\n M[r+3][c+3]=' '\n M[r+4][c+2]=' '\n M[r+4][c+3]=' '\n M[r+5][c]=' '\n M[r+5][c+5]=' '\n if n==1:\n M[r][c]=' '\n M[r][c+1]=' '\n M[r][c+4]=' '\n M[r][c+5]=' '\n M[r+1][c]=' '\n M[r+1][c+4]=' '\n M[r+1][c+5]=' '\n M[r+2][c+1]=' '\n M[r+2][c+4]=' '\n M[r+2][c+5]=' '\n M[r+3][c]=' '\n M[r+3][c+1]=' '\n M[r+3][c+4]=' '\n M[r+3][c+5]=' '\n M[r+4][c]=' '\n M[r+4][c+1]=' '\n M[r+4][c+4]=' '\n M[r+4][c+5]=' '\n if n==2:\n M[r][c]=' '\n M[r][c+5]=' '\n M[r+1][c+2]=' '\n M[r+1][c+3]=' '\n M[r+2][c]=' '\n M[r+2][c+1]=' '\n M[r+2][c+2]=' '\n M[r+2][c+5]=' '\n M[r+3][c]=' '\n M[r+3][c+1]=' '\n M[r+3][c+4]=' '\n M[r+3][c+5]=' '\n M[r+4][c]=' '\n M[r+4][c+3]=' '\n M[r+4][c+4]=' '\n M[r+4][c+5]=' '\n if n==3:\n M[r][c]=' '\n M[r][c+5]=' '\n M[r+1][c+2]=' '\n M[r+1][c+3]=' '\n M[r+2][c]=' '\n M[r+2][c+1]=' '\n M[r+2][c+2]=' '\n M[r+2][c+5]=' '\n M[r+3][c]=' '\n M[r+3][c+1]=' '\n M[r+3][c+2]=' '\n M[r+3][c+5]=' '\n M[r+4][c+2]=' '\n M[r+4][c+3]=' '\n M[r+5][c]=' '\n M[r+5][c+5]=' '\n if n==4:\n M[r][c+2]=' '\n M[r][c+3]=' '\n M[r+1][c+2]=' '\n M[r+1][c+3]=' '\n M[r+2][c+2]=' '\n M[r+2][c+3]=' '\n M[r+3][c]=' '\n M[r+4][c]=' '\n M[r+4][c+1]=' '\n M[r+4][c+2]=' '\n M[r+4][c+3]=' '\n M[r+5][c]=' '\n M[r+5][c+1]=' '\n M[r+5][c+2]=' '\n M[r+5][c+3]=' '\n if n==5:\n M[r+1][c+2]=' '\n M[r+1][c+3]=' '\n M[r+1][c+4]=' '\n M[r+1][c+5]=' '\n M[r+2][c+5]=' '\n M[r+3][c]=' '\n M[r+3][c+1]=' '\n M[r+3][c+2]=' '\n M[r+3][c+3]=' '\n M[r+4][c]=' '\n M[r+4][c+1]=' '\n M[r+4][c+2]=' '\n M[r+4][c+3]=' '\n M[r+5][c+5]=' '\n if n==6:\n M[r][c]=' '\n M[r][c+1]=' '\n M[r][c+2]=' '\n M[r][c+5]=' '\n M[r+1][c]=' '\n M[r+1][c+1]=' '\n M[r+1][c+4]=' '\n M[r+1][c+5]=' '\n M[r+2][c]=' '\n M[r+2][c+5]=' '\n M[r+3][c+2]=' '\n M[r+3][c+3]=' '\n M[r+4][c+2]=' '\n M[r+4][c+3]=' '\n M[r+5][c]=' '\n M[r+5][c+5]=' '\n if n==7:\n M[r+1][c+2]=' '\n M[r+1][c+3]=' '\n M[r+2][c]=' '\n M[r+2][c+1]=' '\n M[r+2][c+2]=' '\n M[r+2][c+5]=' '\n M[r+3][c]=' '\n M[r+3][c+1]=' '\n M[r+3][c+4]=' '\n M[r+3][c+5]=' '\n M[r+4][c]=' '\n M[r+4][c+3]=' '\n M[r+4][c+4]=' '\n M[r+4][c+5]=' '\n M[r+5][c]=' '\n M[r+5][c+3]=' '\n M[r+5][c+4]=' '\n M[r+5][c+5]=' '\n if n==8:\n M[r][c]=' '\n M[r][c+5]=' '\n M[r+1][c+2]=' '\n M[r+1][c+3]=' '\n M[r+2][c]=' '\n M[r+2][c+5]=' '\n M[r+3][c]=' '\n M[r+3][c+5]=' '\n M[r+4][c+2]=' '\n M[r+4][c+3]=' '\n M[r+5][c]=' '\n M[r+5][c+5]=' '\n if n==9:\n M[r][c]=' '\n M[r][c+5]=' '\n M[r+1][c+2]=' '\n M[r+1][c+3]=' '\n M[r+2][c+2]=' '\n M[r+2][c+3]=' '\n M[r+3][c]=' '\n M[r+3][c+5]=' '\n M[r+4][c]=' '\n M[r+4][c+1]=' '\n M[r+4][c+4]=' '\n M[r+4][c+5]=' '\n M[r+5][c]=' '\n M[r+5][c+3]=' '\n M[r+5][c+4]=' '\n M[r+5][c+5]=' '\n \ndef print_number(number, char): \n M=[[char for _ in range(40)] for _ in range(10)]\n for i in range(1,39):\n M[1][i]=' '\n M[8][i]=' '\n for i in range(2,8):\n for j in [1,2,9,16,23,30,37,38]:M[i][j]=' '\n N=str(number).zfill(5)\n P=[(2,3),(2,10),(2,17),(2,24),(2,31)]\n for i in range(5):\n r,c=P[i]\n modify(M,int(N[i]),r,c)\n o=''\n for e in M:o+=''.join(e)+'\\n'\n return o[:-1]"]
{"fn_name": "print_number", "inputs": [[99, "$"], [12345, "*"], [67890, "@"]], "outputs": [["$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$\n$ $\n$ $$$$ $$$$ $$$$ $$$$ $$$$ $\n$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $\n$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $$ $\n$ $$ $$ $$ $$ $$ $$ $$$$ $$$$ $\n$ $$ $$ $$ $$ $$ $$ $$ $$ $\n$ $$$$ $$$$ $$$$ $$ $$ $\n$ $\n$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"], ["****************************************\n* *\n* ** **** **** ** ** ****** *\n* *** ** ** ** ** ** ** ** *\n* * ** ** ** ** ** ***** *\n* ** ** ** ***** ** *\n* ** ** ** ** ** ** *\n* ****** ****** **** ** ***** *\n* *\n****************************************"], ["@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n@ @\n@ @@ @@@@@@ @@@@ @@@@ @@@@ @\n@ @@ @@ @@ @@ @@ @@ @@ @@ @@ @\n@ @@@@ @@ @@@@ @@ @@ @@ @@ @\n@ @@ @@ @@ @@@@ @@@@ @@ @@ @\n@ @@ @@ @@ @@ @@ @@ @@ @@ @\n@ @@@@ @@ @@@@ @@ @@@@ @\n@ @\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"]]}
INTRODUCTORY
PYTHON3
CODEWARS
15,622
def print_number(number, char):
767bcde33579fe51c6c8da91bd77bdb3
UNKNOWN
Write a function that takes a string and returns an array of the repeated characters (letters, numbers, whitespace) in the string. If a charater is repeated more than once, only show it once in the result array. Characters should be shown **by the order of their first repetition**. Note that this may be different from the order of first appearance of the character. Characters are case sensitive. For F# return a "char list" ## Examples: ```python remember("apple") => returns ["p"] remember("apPle") => returns [] # no repeats, "p" != "P" remember("pippi") => returns ["p","i"] # show "p" only once remember('Pippi') => returns ["p","i"] # "p" is repeated first ```
["def remember(str_):\n seen = set()\n res = []\n for i in str_: \n res.append(i) if i in seen and i not in res else seen.add(i)\n return res\n", "from collections import Counter\n\ndef remember(str_):\n seen, lst = Counter(), []\n for c in str_:\n if seen[c] == 1: lst.append(c)\n seen[c] += 1\n return lst", "\ndef remember(str_):\n return [c for i,c in enumerate(str_) if str_[:i].count(c) == 1]", "def remember(stg):\n return [c for i, c in enumerate(stg) if stg[:i].count(c) == 1]", "def remember(s):\n li,final = [],[]\n for i in s:\n if i not in li : li.append(i)\n else : final.append(i)\n return sorted(set(final), key=final.index)", "def remember(str_):\n d = {}\n seen = set()\n for c in str_:\n if c in seen:\n d[c] = 1\n seen.add(c)\n return list(d)", "def remember(str):\n lst = []\n for i, j in enumerate(str):\n if j in str[:i] and j not in lst:\n lst.append(j)\n return lst\n\n", "def remember(str_):\n first_occured, reported = [], []\n for letter in str_:\n if letter not in first_occured:\n first_occured.append(letter)\n elif letter not in reported:\n reported.append(letter)\n return reported", "from enum import Enum\n\nState = Enum('State', 'NONE SEEN APPENDED')\n\ndef remember(str_):\n states = {}\n result = []\n for c in str_:\n state = states.get(c, State.NONE)\n if state is State.NONE:\n states[c] = State.SEEN\n elif state is State.SEEN:\n result.append(c)\n states[c] = State.APPENDED\n return result\n", "import re\ndef remember(str):\n t = []\n for j,i in enumerate(str):\n if str[:j+1].count(i)>1 and i not in t:\n t.append(i)\n return t"]
{"fn_name": "remember", "inputs": [["apple"], ["limbojackassin the garden"], ["11pinguin"], ["Claustrophobic"], ["apPle"], ["11 pinguin"], ["pippi"], ["Pippi"], ["kamehameha"], [""]], "outputs": [[["p"]], [["a", "s", "i", " ", "e", "n"]], [["1", "i", "n"]], [["o"]], [[]], [["1", "i", "n"]], [["p", "i"]], [["p", "i"]], [["a", "m", "e", "h"]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,848
def remember(str_):
ee35bf5c0bbf6b5664c3e35f5b22ab53
UNKNOWN
## Task Given a positive integer as input, return the output as a string in the following format: Each element, corresponding to a digit of the number, multiplied by a power of 10 in such a way that with the sum of these elements you can obtain the original number. ## Examples Input | Output --- | --- 0 | "" 56 | "5\*10+6" 60 | "6\*10" 999 | "9\*100+9\*10+9" 10004 | "1\*10000+4" Note: `input >= 0`
["def simplify(n): \n output = []\n exp = 0\n \n while n:\n n, r = divmod(n, 10)\n if r:\n output.append(f\"{r}*{10**exp}\" if exp else f\"{r}\")\n exp += 1\n \n return \"+\".join(output[::-1])", "def simplify(number):\n num = str(number)\n result = []\n for i, d in enumerate(num, start=1):\n if d == \"0\":\n continue\n elif i == len(num):\n result.append(d)\n else:\n result.append(d + \"*\" + \"1\" + \"0\" * (len(num) - i))\n return \"+\".join(result)\n", "def simplify(n):\n n = str(n)\n return \"\".join([\"+\"+n[i]+(\"*1\"+\"0\"*(len(n)-i-1) if len(n)-i-1>0 else \"\") for i in range(0, len(n)) if n[i]!=\"0\"])[1:]\n # . . . :D\n", "def simplify(number): \n if number == 0: return ''\n res = ''\n number = str(number)\n for i in range(len(number)):\n if number[i] == '0': continue\n res += f'{number[i]}*{10**(len(number)-i-1)}+'\n res = res.replace('*1+', '')\n if res[-1] == '+':\n return res[:-1]\n return res", "def simplify(n, m=0): \n return '' if not n else f'{[\"\",\"+\"][m]}{str(n)}' if n<10 else f'{[\"\",\"+\"][m]}{str(n)[0]}*1{\"0\"*(len(str(n))-1)}' + simplify(int(str(n)[1:]),1) ", "def simplify(s): \n a = [i for i in str(s)]\n r =\"\"\n l = len(a)\n for i in range(len(a)):\n if a[i] == \"0\": continue \n if len(r) > 0: r+= \"+\"\n r += a[i]\n if i < len(a) -1: \n r+= \"*1\" + \"0\"*(len(a) - i - 1) \n return r", "def simplify(number: int) -> str:\n digits = str(number)\n res = [f\"{n}*1{'0' * i}\" for i, n in zip(list(range(len(digits) - 1, 0, -1)), digits) if n != '0']\n return '+'.join(res + ([digits[-1]] if digits[-1] != '0' else []))\n", "def simplify(number):\n if number == 0:\n return \"\"\n terms = [\n f\"{c}*{10**i}\" if i else str(c)\n for i, c in enumerate(str(number)[::-1])\n if c > \"0\"\n ]\n return \"+\".join(reversed(terms))", "def simplify(n):\n s = str(n)\n l = len(s)\n result = []\n for i, d in enumerate(s, 1):\n if int(d):\n p = \"\" if l == i else f\"*{10**(l-i)}\"\n result.append(f\"{d}{p}\")\n return \"+\".join(result)\n\n\n# s = str(n)\n# return \"+\".join(f\"{d}{f'*{10**(-i)}' if i else ''}\" for i, d in enumerate(s, -len(s)+1) if int(d))\n", "def simplify(n):\n return \"+\".join([f\"{x}*{10**i}\" if i else x for i, x in enumerate(str(n)[::-1]) if x != \"0\"][::-1])"]
{"fn_name": "simplify", "inputs": [[8964631], [56], [999], [11], [991], [47], [234], [196587], [660], [600], [9090], [10104], [80008], [90000], [0]], "outputs": [["8*1000000+9*100000+6*10000+4*1000+6*100+3*10+1"], ["5*10+6"], ["9*100+9*10+9"], ["1*10+1"], ["9*100+9*10+1"], ["4*10+7"], ["2*100+3*10+4"], ["1*100000+9*10000+6*1000+5*100+8*10+7"], ["6*100+6*10"], ["6*100"], ["9*1000+9*10"], ["1*10000+1*100+4"], ["8*10000+8"], ["9*10000"], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,565
def simplify(n):
52bc32f29db9ac68523324d06844c893
UNKNOWN
A Narcissistic Number is a number of length n in which the sum of its digits to the power of n is equal to the original number. If this seems confusing, refer to the example below. Ex: 153, where n = 3 (number of digits in 153) 1^(3) + 5^(3) + 3^(3) = 153 Write a method is_narcissistic(i) (in Haskell: isNarcissistic :: Integer -> Bool) which returns whether or not i is a Narcissistic Number.
["def is_narcissistic(n):\n num = str(n)\n length = len(num)\n return sum(int(a) ** length for a in num) == n\n", "def is_narcissistic(i):\n return sum([int(n)**len(str(i)) for n in str(i)])==i", "def is_narcissistic(n):\n t = str(n)\n l = len(t)\n \n return n == sum(int(d) ** l for d in t)", "is_narcissistic = lambda n: sum(int(i) ** len(str(n)) for i in str(n)) == n", "def is_narcissistic(i):\n return sum(int(d) ** len(str(i)) for d in str(i)) == i", "def is_narcissistic(i):\n numbers = list(str(i))\n power = len(str(i))\n sum = 0\n\n for number in numbers:\n sum += (int(number) ** power)\n\n return sum == i\n \n \n\n", "def is_narcissistic(i):\n n = len(str(i))\n lst = list(str(i))\n answer = 0\n for value in lst:\n answer += int(value)**n\n return answer == i", "def is_narcissistic(i):\n digits = str(i)\n n = len(digits)\n return sum(int(d)**n for d in digits) == i", "def is_narcissistic(i):\n s = str(i)\n return sum(int(x) ** len(s) for x in s) == i", "def is_narcissistic(i):\n sum_of_digits = 0\n exponent = len(str(i))\n for digit in str(i):\n sum_of_digits += int(digit)**exponent\n return sum_of_digits == i"]
{"fn_name": "is_narcissistic", "inputs": [[153], [370], [371], [407], [1634], [8208], [9474], [54748], [92727], [93084], [548834], [1741725], [4210818], [9800817], [9926315], [24678050], [88593477], [146511208], [472335975], [534494836], [912985153], [4679307774], [115132219018763992565095597973971522401]], "outputs": [[true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,236
def is_narcissistic(i):
d9ad2599df958a610ef478da0c934432
UNKNOWN
In a small town the population is `p0 = 1000` at the beginning of a year. The population regularly increases by `2 percent` per year and moreover `50` new inhabitants per year come to live in the town. How many years does the town need to see its population greater or equal to `p = 1200` inhabitants? ``` At the end of the first year there will be: 1000 + 1000 * 0.02 + 50 => 1070 inhabitants At the end of the 2nd year there will be: 1070 + 1070 * 0.02 + 50 => 1141 inhabitants (number of inhabitants is an integer) At the end of the 3rd year there will be: 1141 + 1141 * 0.02 + 50 => 1213 It will need 3 entire years. ``` More generally given parameters: `p0, percent, aug (inhabitants coming or leaving each year), p (population to surpass)` the function `nb_year` should return `n` number of entire years needed to get a population greater or equal to `p`. aug is an integer, percent a positive or null number, p0 and p are positive integers (> 0) ``` Examples: nb_year(1500, 5, 100, 5000) -> 15 nb_year(1500000, 2.5, 10000, 2000000) -> 10 ``` Note: Don't forget to convert the percent parameter as a percentage in the body of your function: if the parameter percent is 2 you have to convert it to 0.02.
["def nb_year(population, percent, aug, target):\n year = 0\n while population < target:\n population += population * percent / 100. + aug\n year += 1\n return year", "def nb_year(p0, percent, aug, p, years = 0):\n if p0 < p:\n return nb_year(p0 + int(p0 * percent / 100) + aug, percent, aug, p, years + 1)\n return years", "def nb_year(p0, percent, aug, p):\n return 0 if p0 >= p else nb_year(p0 + p0 * percent/100 + aug, percent, aug, p)+1\n", "def nb_year(p0, percent, aug, p):\n # base case\n if p0 >= p:\n return 0\n\n # recursive case\n _p = percent / 100.00\n p0 = p0 + round(p0 * _p) + aug # growth of population formula\n return 1 + nb_year(p0, percent, aug, p)\n", "from math import ceil, log\ndef nb_year(p0, percent, aug, p):\n if not percent: return ceil(1.*(p - p0) / aug)\n percent = 1 + percent / 100.\n r = aug / (1 - percent)\n return ceil(log((p - r) / (p0 - r), percent))", "def nb_year(p0, percent, aug, p):\n i = 0 \n while p0 < p:\n p0 = p0 + (p0 * percent * 0.01) + aug\n i += 1\n return i", "def nb_year(p0, percent, aug, p):\n current_population = p0\n years = 0\n while current_population < p:\n new_population = current_population + current_population * percent / 100 + aug\n current_population = new_population\n years += 1\n return years\n \n", "def nb_year(p0, percent, aug, p):\n y = 0\n while p0 < p: p0, y = p0 * (1 + percent / 100.0) + aug, y + 1\n return y", "from math import floor\n\ndef nb_year(p0, percent, aug, p):\n i = 1\n mult = 1 + percent / 100.0\n prev = p0\n while (prev < p):\n ne = floor((prev * mult + aug))\n prev = ne\n i += 1\n return (i - 1)", "def nb_year(p0, percent, aug, p):\n i = 0\n while p0 < p:\n p0 += p0*percent/100 + aug\n i += 1\n return i", "def nb_year(p0, percent, aug, p):\n # your code\n sum = p0\n percent_value = percent / 100\n years = 0\n while (sum < p):\n years +=1\n sum += sum*percent_value + aug\n return years", "# Growth of a Population\ndef nb_year(p0, percent, aug, p, n=0): # Added n=0.\n while p0 < p:\n p0 += aug + (p0 * percent / 100)\n n += 1\n return n", "def nb_year(p0, percent, aug, p):\n years = 0\n while p0 < p:\n p0 += ((p0/100)*percent) + aug\n years += 1\n return years\n\nprint(nb_year(1500000, 0.25, 1000, 2000000))", "def nb_year(x,p,a,y):\n t = 0\n while True:\n x += x*p/100 + a\n t += 1\n if x >= y:\n break\n return t", "def nb_year(p0, percent, ag, p):\n year = 0\n while p0 < p:\n year += 1\n p0 = p0 * (1+percent/100) + ag\n return year", "def nb_year(p0, percent, aug, p):\n year=0\n while p0 < p:\n p0=p0+p0*(percent/100)+aug\n year=year+1\n return year\n \n \n # your code\n", "def nb_year(y,e,a,r,s=0):\n while y<r:y+=y*e*.01+a;s+=1\n return s", "nb_year=n=lambda a,b,c,d,e=0:n(\na+a*b*.01+c\n,b,c,d,e+1)if a<d else e", "nb_year=lambda p0,percent,aug,p,c=0: c if p<=p0 else nb_year(p0*(1+percent/100)+aug,percent,aug,p,c+1)", "from itertools import accumulate\n\ndef nb_year(p0, pct, aug, p):\n return next(i for i, x in enumerate(accumulate([p0] * 1000, lambda px, _: px + .01 * pct * px + aug)) if x >= p)", "def nb_year(p0, percent, aug, p):\n pop=p0\n y=0\n while pop<p:pop*=(1+percent/100);pop+=aug;y+=1\n return y\n", "def nb_year(p0, percent, aug, p):\n n = p0 + p0* (percent/100) + aug\n nb= 1 \n while n < p:\n n = n + n*(percent/100) + aug\n nb += 1\n return(nb)\n \n\n\n\n\n"]
{"fn_name": "nb_year", "inputs": [[1500, 5, 100, 5000], [1500000, 2.5, 10000, 2000000], [1500000, 0.25, 1000, 2000000], [1500000, 0.25, -1000, 2000000], [1500000, 0.25, 1, 2000000], [1500000, 0.0, 10000, 2000000]], "outputs": [[15], [10], [94], [151], [116], [50]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,716
def nb_year(p0, percent, aug, p):
3ba88417db6ad015fcfb7b5e34d8e785
UNKNOWN
# Task N lamps are placed in a line, some are switched on and some are off. What is the smallest number of lamps that need to be switched so that on and off lamps will alternate with each other? You are given an array `a` of zeros and ones - `1` mean switched-on lamp and `0` means switched-off. Your task is to find the smallest number of lamps that need to be switched. # Example For `a = [1, 0, 0, 1, 1, 1, 0]`, the result should be `3`. ``` a --> 1 0 0 1 1 1 0 swith --> 0 1 0 became--> 0 1 0 1 0 1 0 ``` # Input/Output - `[input]` integer array `a` array of zeros and ones - initial lamp setup, 1 mean switched-on lamp and 0 means switched-off. `2 < a.length <= 1000` - `[output]` an integer minimum number of switches.
["def lamps(a):\n n = sum(1 for i, x in enumerate(a) if x != i % 2)\n return min(n, len(a) - n)", "def lamps(a):\n return min(sum(1 for i, n in enumerate(a) if n == i % 2), sum(1 for i, n in enumerate(a) if n != i % 2))", "def lamps(a):\n case1c = 0\n case2c = 0\n for i in range(len(a)):\n if i % 2 == 0:\n if a[i] == 1:\n case1c += 1\n else:\n case2c += 1\n else:\n if a[i] == 1:\n case2c += 1\n else:\n case1c += 1\n return min(case1c, case2c)", "def lamps(lst):\n starts_with_zero = sum(on ^ i & 1 for i, on in enumerate(lst))\n starts_with_one = sum(on ^ i & 1 for i, on in enumerate(lst, 1))\n return min(starts_with_zero, starts_with_one)", "import copy\n\n\ndef lamps(a):\n k = 0\n n = []\n b = copy.deepcopy(a)\n print(a)\n for c in range(1, len(a)):\n if a[c] == a[c - 1]:\n a[c] = 1 - a[c]\n k += 1\n if k == 0:\n return 0\n n.append(k)\n print(n)\n k = 1\n b[0] = 1 - b[0]\n print(b)\n for c in range(1, len(b)):\n if b[c] == b[c - 1]:\n b[c] = 1 - b[c]\n k += 1\n n.append(k)\n print(n)\n return min(n)\n", "def lamps(a):\n #coding and coding..\n n = sum([1 for x,y in enumerate(a) if y == x % 2])\n return min(len(a)-n,n)", "def lamps(a):\n r = sum(x == c % 2 for c, x in enumerate(a))\n return min(r, len(a) - r)", "def lamps(a):\n i, count = 0, 0\n \n for lamp in a:\n if lamp == i % 2:\n count += 1\n i += 1\n \n return min(count, i - count)", "from itertools import cycle\ndef lamps(a):\n dif=lambda a,b:sum(x!=y for x,y in zip(a,b))\n return min(dif(a,cycle([1,0])),dif(a,cycle([0,1])))", "from itertools import cycle\n\ndef lamps(a):\n return min(sum(x != y for x, y in zip(a, cycle([0, 1]))),\n sum(x != y for x, y in zip(a, cycle([1, 0]))))"]
{"fn_name": "lamps", "inputs": [[[1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1]], [[1, 0, 1]], [[1, 0, 1, 0]], [[0, 1, 0, 1, 0]], [[1, 0, 1, 0, 0, 1, 0, 1]], [[1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0]]], "outputs": [[5], [0], [0], [0], [4], [5]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,992
def lamps(a):
30b6c79ed53021e97d7357de65bb53d6
UNKNOWN
A population of bears consists of black bears, brown bears, and white bears. The input is an array of two elements. Determine whether the offspring of the two bears will return `'black'`, `'brown'`, `'white'`, `'dark brown'`, `'grey'`, `'light brown'`, or `'unknown'`. Elements in the the array will always be a string. ## Examples: bear_fur(['black', 'black']) returns 'black' bear_fur(['brown', 'brown']) returns 'brown' bear_fur(['white', 'white']) returns 'white' bear_fur(['black', 'brown']) returns 'dark brown' bear_fur(['black', 'white']) returns 'grey' bear_fur(['brown', 'white']) returns 'light brown' bear_fur(['yellow', 'magenta']) returns 'unknown'
["DEFAULT = 'unknown'\nCOLORS = {'black'+'brown': 'dark brown',\n 'black'+'white': 'grey',\n 'brown'+'white': 'light brown'}\n\ndef bear_fur(bears):\n b1,b2 = sorted(bears)\n return b1 if b1==b2 else COLORS.get(b1+b2, DEFAULT)\n", "def bear_fur(bears):\n return {('black', 'black') : 'black',\n ('black', 'white') : 'grey',\n ('black', 'brown') : 'dark brown',\n ('brown', 'brown') : 'brown',\n ('brown', 'white') : 'light brown',\n ('white', 'white') : 'white'\n }.get(tuple(sorted(bears)), 'unknown')", "bin_to_colors = {1: \"black\", 2: \"brown\", 3:\"dark brown\", 4: \"white\", 5: \"grey\", 6: \"light brown\"}\ncolors_to_bin = {v: k for k, v in bin_to_colors.items()}\n\ndef bear_fur(bears):\n return bin_to_colors.get(sum(colors_to_bin.get(k, 7) for k in set(bears)), \"unknown\")", "def bear_fur(bears):\n combos = { ('black', 'brown'): 'dark brown',\n ('black', 'white'): 'grey',\n ('brown', 'white'): 'light brown' }\n\n if bears[0] == bears[1]:\n return bears[0]\n else:\n colors = tuple(sorted(bears))\n if colors in combos:\n return combos[colors]\n else:\n return 'unknown'\n", "def bear_fur(bears):\n bears = \"\".join(bears)\n dict = {\n 'blackblack' : 'black',\n 'brownbrown' : 'brown',\n 'whitewhite' : 'white',\n 'brownblack' : 'dark brown',\n 'blackbrown' : 'dark brown',\n 'blackwhite' : 'grey',\n 'whiteblack' : 'grey',\n 'brownwhite' : 'light brown',\n 'whitebrown' : 'light brown'\n }\n return dict.get(bears, 'unknown')", "def bear_fur(bears):\n if bears[0] == bears[1]:\n return bears[0]\n if \"black\" in bears and \"white\" in bears:\n return \"grey\"\n if \"black\" in bears and \"brown\" in bears:\n return \"dark brown\"\n if \"white\" in bears and \"brown\" in bears:\n return \"light brown\"\n return \"unknown\"", "bear_fur = lambda bears, furs={('black', 'brown'): 'dark brown', ('black', 'white'): 'grey', ('brown', 'white'): 'light brown',('white', 'white'): 'white',('brown', 'brown'): 'brown',('black', 'black'): 'black',}: furs.get(tuple(sorted(bears)), 'unknown')", "def bear_fur(bears):\n s = set(bears)\n if s == {'black'}: return 'black'\n if s == {'brown'}: return 'brown'\n if s == {'white'}: return 'white'\n if s == {'black', 'brown'}: return 'dark brown'\n if s == {'black','white'}: return 'grey'\n if s == {'brown','white'}: return 'light brown'\n return 'unknown'", "def bear_fur(bears):\n look={(\"black\",\"brown\"):\"dark brown\",(\"black\",\"white\"):\"grey\",(\"brown\",\"white\"):\"light brown\"}\n b1,b2=bears\n if b1==b2 and b1 in {\"black\",\"brown\",\"white\"}:return b1\n return look.get(tuple(sorted([b1,b2])),\"unknown\")", "def bear_fur(bears):\n for i in range(len(bears)-1):\n if bears[i] =='black' and bears[i+1] =='black':\n return 'black'\n elif bears[i]=='white' and bears[i+1] == 'white':\n return 'white'\n elif bears[i]=='brown' and bears[i+1] == 'brown':\n return 'brown'\n elif bears[i] == 'black' and bears[i+1] == 'white':\n return 'grey'\n elif bears[i] == 'black' and bears[i+1] == 'brown':\n return 'dark brown'\n elif bears[i] == 'white' and bears[i+1] == 'black':\n return 'grey'\n elif bears[i] == 'white' and bears[i+1] == 'brown':\n return 'light brown'\n elif bears[i] == 'brown' and bears[i+1] == 'black':\n return 'dark brown'\n elif bears[i] == 'brown' and bears[i+1] == 'white':\n return 'light brown'\n else:\n return 'unknown'\n \n# first compare every combination where is only one color for bear\n# than check all situations where bear skin is different \n# and return the result\n \n \n"]
{"fn_name": "bear_fur", "inputs": [[["black", "black"]], [["white", "white"]], [["brown", "brown"]], [["black", "brown"]], [["black", "white"]], [["white", "brown"]], [["pink", "black"]]], "outputs": [["black"], ["white"], ["brown"], ["dark brown"], ["grey"], ["light brown"], ["unknown"]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,032
def bear_fur(bears):
1aad64b8894cf1816a03fd7d324988c1
UNKNOWN
In this Kata you are a game developer and have programmed the #1 MMORPG(Massively Multiplayer Online Role Playing Game) worldwide!!! Many suggestions came across you to make the game better, one of which you are interested in and will start working on at once. Players in the game have levels from 1 to 170, XP(short for experience) is required to increase the player's level and is obtained by doing all sorts of things in the game, a new player starts at level 1 with 0 XP. You want to add a feature that would enable the player to input a target level and the output would be how much XP the player must obtain in order for him/her to reach the target level...simple huh. Create a function called ```xp_to_target_lvl``` that takes 2 arguments(```current_xp``` and ```target_lvl```, both as integer) and returns the remaining XP for the player to reach the ```target_lvl``` formatted as a rounded down integer. Leveling up from level 1 to level 2 requires 314 XP, at first each level up requires 25% XP more than the previous level up, every 10 levels the percentage increase reduces by 1. See the examples for a better understanding. Keep in mind that when players reach level 170 they stop leveling up but they continue gaining experience. If one or both of the arguments are invalid(not given, not in correct format, not in range...etc) return "Input is invalid.". If the player has already reached the ```target_lvl``` return ```"You have already reached level target_lvl."```. Examples: ``` xp_to_target_lvl(0,5) => XP from lvl1 to lvl2 = 314 XP from lvl2 to lvl3 = 314 + (314*0.25) = 392 XP from lvl3 to lvl4 = 392 + (392*0.25) = 490 XP from lvl4 to lvl5 = 490 + (490*0.25) = 612 XP from lvl1 to target_lvl = 314 + 392 + 490 + 612 = 1808 XP from current_xp to target_lvl = 1808 - 0 = 1808 xp_to_target_lvl(12345,17) => XP from lvl1 to lvl2 = 314 XP from lvl2 to lvl3 = 314 + (314*0.25) = 392 XP from lvl3 to lvl4 = 392 + (392*0.25) = 490 ... XP from lvl9 to lvl10 = 1493 + (1493*0.25) = 1866 XP from lvl10 to lvl11 = 1866 + (1866*0.24) = 2313 << percentage increase is ... reduced by 1 (25 - 1 = 24) XP from lvl16 to lvl17 = 6779 + (6779*0.24) = 8405 XP from lvl1 to target_lvl = 314 + 392 + 490 + 612 + ... + 8405 = 41880 XP from current_xp to target_lvl = 41880 - 12345 = 29535 xp_to_target_lvl() => "Input is invalid." } xp_to_target_lvl(-31428.7,'47') => "Input is invalid." }> Invalid input xp_to_target_lvl(83749,0) => "Input is invalid." } xp_to_target_lvl(2017,4) => "You have already reached level 4." xp_to_target_lvl(0,1) => 'You have already reached level 1.' ``` Make sure you round down the XP required for each level up, rounding up will result in the output being slightly wrong.
["def xp_to_target_lvl(*args):\n if len(args) < 2:\n return 'Input is invalid.'\n \n current_xp, target_lvl = args\n \n if not isinstance(target_lvl, int):\n return 'Input is invalid.'\n \n if not (0 < target_lvl < 171):\n return 'Input is invalid.'\n \n if current_xp < 0:\n return 'Input is invalid.'\n \n level = 1\n xp = 314\n xp_bump = 25\n \n sum_ = 0\n while level < target_lvl:\n sum_ += xp\n level += 1\n xp_bump_reduction = level // 10\n xp += int(xp * (xp_bump - xp_bump_reduction) / 100)\n \n diff = sum_ - current_xp\n if diff <= 0:\n return 'You have already reached level {}.'.format(target_lvl)\n else:\n return diff\n", "def xp_to_target_lvl(current_xp=None, target_lvl=None):\n \n invalid = \"Input is invalid.\"\n if (type(target_lvl) is not int) or (type(current_xp) is not int):\n return invalid\n if current_xp < 0 or target_lvl < 1 or target_lvl > 170:\n return invalid\n if target_lvl == 1:\n return \"You have already reached level 1.\"\n \n needed_xp = 314\n if target_lvl > 2:\n needed_xp = calc_needed(target_lvl)\n \n if current_xp >= needed_xp:\n return \"You have already reached level %s.\" % target_lvl\n \n return needed_xp - current_xp\n \ndef calc_needed(target_lvl):\n increase = 25\n lvl_xp = needed_xp = 314\n \n for lvl in range(3, target_lvl+1):\n lvl_xp += int( lvl_xp * increase / 100 )\n needed_xp += lvl_xp\n if lvl % 10 == 0:\n increase -= 1\n \n return needed_xp\n \n", "from fractions import Fraction\n\ndef xp_to_target_lvl(current_xp=None, target_lvl=None):\n if not isinstance(current_xp, int) or not isinstance(target_lvl, int) or current_xp < 0 or not 1 <= target_lvl <= 170:\n return \"Input is invalid.\"\n increase, xp, total = Fraction(5, 4), 314, 0\n for i in range(2, target_lvl+1):\n if not i%10: increase -= Fraction(1, 100)\n total, xp = total+xp, int(xp*increase)\n return total - current_xp if total > current_xp else f\"You have already reached level {target_lvl}.\"", "from itertools import accumulate\n\nXPS = [0, 0, 314]\npercent = 125\nfor i in range(3, 170 + 1):\n XPS.append(XPS[-1] * percent // 100)\n if i % 10 == 0:\n percent -= 1\nXPS = list(accumulate(XPS))\n\ndef xp_to_target_lvl(current_xp=None, target_lvl=None):\n if not (\n isinstance(current_xp, int)\n and isinstance(target_lvl, int)\n and current_xp >= 0\n and 1 <= target_lvl <= 170\n ):\n return \"Input is invalid.\"\n required = XPS[target_lvl] - current_xp\n return required if required > 0 else f\"You have already reached level {target_lvl}.\"\n", "from itertools import accumulate\n\nXP=[0,0,314]\nfor i in range(2,170):\n XP.append(XP[-1]*(125-i//10)//100)\nXP=list(accumulate(XP))\n\ndef xp_to_target_lvl(xp=-1, lvl=0):\n try: \n if xp<0 or lvl<1: return 'Input is invalid.'\n res = XP[lvl]-xp\n return res if res>0 else f'You have already reached level {lvl}.'\n except: return 'Input is invalid.'", "def xp_to_target_lvl(current_xp='', target_lvl=''):\n # good luck ^_^\n if isinstance(current_xp,int) and isinstance(target_lvl,int):\n if current_xp>=0 and 1<=target_lvl<=170:\n a=[314]\n for i in range(2,target_lvl+2):\n a.append(int(a[-1]*(1.25-0.01*(i//10))))\n return sum(a[:target_lvl-1])-current_xp if sum(a[:target_lvl-1])-current_xp>0 else 'You have already reached level {}.'.format(target_lvl)\n return 'Input is invalid.'\n", "from math import floor\n\n\ndef xp_to_target_lvl(current_xp=-100, target_lvl=-100):\n if type(current_xp) != int or type(target_lvl) != int or current_xp + target_lvl <= 0 or target_lvl > 170 or target_lvl < 1:\n return \"Input is invalid.\"\n\n exp_req = 314\n inc = 25\n level = 1\n exp = 0\n while level < target_lvl:\n level += 1\n if level % 10 == 0:\n inc -= 1\n exp += exp_req\n exp_req = floor(exp_req + exp_req * inc / 100)\n\n if exp - current_xp <= 0:\n return f\"You have already reached level {target_lvl}.\"\n return exp - current_xp", "a,e,t,m = [0,314],314,314,.25\nfor i in range(2,170):\n x = int(e*(1+m))\n t += x\n a.append(t)\n e = x\n if not (i+1)%10:\n m -= .01\na[-1] = 769832696988485\n\ndef xp_to_target_lvl(e=None,lvl=None):\n try: \n if e<0 or lvl<1: return 'Input is invalid.'\n if lvl==1 or e >= a[max(lvl-1,0)]: return f'You have already reached level {lvl}.'\n return a[lvl-1] - e\n except:\n return 'Input is invalid.'", "from math import floor\n\ndef xp_to_target_lvl(*args):\n if len(args) != 2:\n return \"Input is invalid.\"\n \n current_xp = args[0]\n target_lvl = args[1]\n if type(current_xp) is not int or type(target_lvl) is not int or current_xp < 0 or target_lvl <= 0 or target_lvl > 170:\n return \"Input is invalid.\"\n \n req_xp = 0\n xp_lvl = 314\n for i in range(1,target_lvl):\n print(xp_lvl)\n req_xp += xp_lvl\n xp_lvl *= (1.25 - 0.01*((i+1)//10))\n xp_lvl = floor(xp_lvl)\n \n print(f\"\\n{req_xp}\")\n \n return req_xp - current_xp if req_xp > current_xp else f\"You have already reached level {target_lvl}.\"", "def xp_to_target_lvl(cur_xp = -1, lvl = -1):\n if not isinstance(cur_xp, int) or cur_xp < 0 or not isinstance(lvl, int) or lvl <= 0 or lvl > 170: \n return \"Input is invalid.\"\n \n count = 1\n xp = 0\n multipler = 25\n next_lvl = 314\n \n while count < lvl:\n count += 1\n if count == lvl: xp += next_lvl; print(xp, count); break\n if count % 10 == 0: multipler = float(multipler - 1)\n xp += next_lvl\n next_lvl = next_lvl + int(next_lvl * (multipler / 100))\n print(xp, count, multipler)\n \n result = xp - cur_xp\n if result > 0:\n return result\n else:\n return f'You have already reached level {lvl}.'"]
{"fn_name": "xp_to_target_lvl", "inputs": [[0, 5], [12345, 17], [313, 2], [832696988485, 170], [769832696988484, 170], [10395, 11], [31428, "47"], [1, 171], [7392984749, 900], [123, 0], [-987654321, 99], [999999, [101]], [10396, 11], [0, 1], [2017, 4], [769832696988485, 170]], "outputs": [[1808], [29535], [1], [769000000000000], [1], [1], ["Input is invalid."], ["Input is invalid."], ["Input is invalid."], ["Input is invalid."], ["Input is invalid."], ["Input is invalid."], ["You have already reached level 11."], ["You have already reached level 1."], ["You have already reached level 4."], ["You have already reached level 170."]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,251
def xp_to_target_lvl(current_xp=None, target_lvl=None):
85b7f2a10bd6a46a521023d94c9b957d
UNKNOWN
Timothy (age: 16) really likes to smoke. Unfortunately, he is too young to buy his own cigarettes and that's why he has to be extremely efficient in smoking. It's now your task to create a function that calculates how many cigarettes Timothy can smoke out of the given amounts of `bars` and `boxes`: - a bar has 10 boxes of cigarettes, - a box has 18 cigarettes, - out of 5 stubs (cigarettes ends) Timothy is able to roll a new one, - of course the self made cigarettes also have an end which can be used to create a new one... Please note that Timothy never starts smoking cigarettes that aren't "full size" so the amount of smoked cigarettes is always an integer.
["def start_smoking(bars, boxes):\n return int(22.5 * (10 * bars + boxes) - 0.5)", "def start_smoking(bars, boxes):\n return ((10 * bars + boxes) * 90 - bool(bars + boxes)) // 4", "def start_smoking(bars,boxes):\n total = bars * 10 * 18 + boxes * 18\n n = total\n while total >= 1: \n total /= 5\n n += total\n return int(n)", "def start_smoking(bars, boxes):\n new = (bars * 10 + boxes) * 18\n smoked = ends = 0\n \n while new:\n smoked += new\n ends += new\n new = ends // 5\n ends -= new * 5\n \n return smoked", "def start_smoking(bars,boxes):\n n = (bars * 10 + boxes) * 18\n count = 0\n while n > 4:\n n, rest = divmod(n, 5)\n count += n\n n += rest\n return (bars * 10 + boxes) * 18 + count\n", "def start_smoking(bars,boxes):\n a = []\n x = 180 * bars + 18 * boxes\n a.append(x+x//5)\n n = x % 5 + x//5\n while n >= 5:\n a.append(n//5)\n n = n % 5 + n // 5\n return sum(a) \n \n \n \n", "s,start_smoking=lambda n,r=0:n and n+s(*divmod(n+r,5)),lambda B,b:s(18*(10*B+b))", "from math import log\ndef start_smoking(bars,boxes):\n n=(bars*10+boxes)*18\n stubs=n\n while stubs>4:\n n+=stubs//5\n stubs=sum(divmod(stubs,5))\n return n", "def start_smoking(bars,boxes):\n cigarettes = bars * 10 * 18 + boxes * 18\n smoked = 0\n leftovers = 0\n # Tenemos esa cantidad de cigarrillos los fumamos nos quedamos sin cigarrillos:\n while True:\n smoked += cigarettes\n leftovers += cigarettes\n cigarettes = 0\n # Entonces ahora tenemos que usar los leftovers\n if leftovers >= 5:\n cigarettes += leftovers // 5\n leftovers = leftovers % 5\n else:\n return smoked", "def start_smoking(bars,boxes):\n c=(bars*10+boxes)*18\n r=0\n stub=0\n while(c>0):\n r+=c\n stub+=c\n c,stub=divmod(stub,5)\n return r"]
{"fn_name": "start_smoking", "inputs": [[0, 1], [1, 0], [1, 1]], "outputs": [[22], [224], [247]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,005
def start_smoking(bars,boxes):
8f2b7bcd7e180f7acdff32b2ace99fc1
UNKNOWN
Find the closest prime number under a certain integer ```n``` that has the maximum possible amount of even digits. For ```n = 1000```, the highest prime under ```1000``` is ```887```, having two even digits (8 twice) Naming ```f()```, the function that gives that prime, the above case and others will be like the following below. ``` f(1000) ---> 887 (even digits: 8, 8) f(1210) ---> 1201 (even digits: 2, 0) f(10000) ---> 8887 f(500) ---> 487 f(487) ---> 467 ``` Features of the random tests: ``` Number of tests = 28 1000 <= n <= 5000000 ``` Enjoy it!!
["from bisect import bisect_left as bisect\n\nn = 5000000\nsieve, PED, PED_DATA = [0]*((n>>1)+1), [], []\nfor i in range(3, n+1, 2):\n if not sieve[i>>1]:\n for j in range(i**2>>1, (n+1)>>1, i): sieve[j] = 1\n s = str(i)\n nEveD = sum(s.count(d) for d in \"02468\")\n if nEveD:\n PED.append(i)\n PED_DATA.append( (nEveD,len(s)-1) )\n\ndef f(n):\n idx = bisect(PED, n)-1\n m, (nEveD, l) = PED[idx], PED_DATA[idx]\n \n for c in range(idx):\n mc, (nEveDc, lc) = PED[idx-c], PED_DATA[idx-c]\n if nEveDc > nEveD:\n m, nEveD = mc, nEveDc\n if lc < nEveD: break\n return m", "def is_prime(n):\n #base cases handling\n if n == 2 or n == 3: return True #handles 2, 3\n if n < 2 or n%2 == 0: return False #handles 1 and even numbers\n if n < 9: return True #since 1, 2, 3, 4, 6 and 8 are handled, this leaves 5 and 7.\n if n%3 == 0: return False #handles multiples of 3\n r = int(n**0.5) #only check upto square root\n f = 5 #start from 5\n while f <= r:\n #print ('\\t', f)\n if n%f == 0: return False #essentially checks 6n - 1 for all n.\n if n%(f+2) == 0: return False #essentially checks 6n + 1 for all n.\n f +=6 #incrementing by 6.\n return True\n\ndef max_even_digits_in_prime(n):\n return (len(str(n)) - 1) or 1\n\ndef count_of_even_digits(n):\n count = 0\n for i in str(n):\n count+= (int(i) % 2 == 0)\n return count\n\ndef f(n):\n best_case = (0, 0) #keeps track of highest best case number seen[1], and its count of even digits[0]\n for x in range(n-1, 1, -1): #iterate in the reverse direction\n #print(x)\n if is_prime(x): #proceed for prime numbers\n even_digits = count_of_even_digits(x)\n max_even_digits = max_even_digits_in_prime(x)\n if best_case[0] < even_digits: #update best number seen so far\n best_case = (even_digits, x)\n if max_even_digits == best_case[0]: #best case answer, your work is done. No need to look for more numbers.\n print(best_case)\n return (best_case[1])", "import itertools\ncompress = itertools.compress\nfrom bisect import bisect_right,bisect_left\n\ndef prime(n):\n if n < 2:\n return []\n r = [False,True] * (n//2)+[True]\n r[1],r[2]=False, True\n for i in range(3,int(1 + n**0.5),2):\n if r[i]:\n r[i*i::2*i] = [False] * int((n+2*i-1-i*i)/(2*i))\n r = list(compress(list(range(len(r))),r))\n if r[-1] %2 == 0:\n r.pop() \n return r\nprimes = prime(5*10**6) \n\ndef even(n): \n even_count = 0 \n while n > 0: \n rem = n%10 \n if not rem%2: \n even_count += 1\n n //= 10\n return even_count\n\ndef f(n): \n n -= 1\n upper_bound = bisect_right(primes,n)\n best = -1 \n bestCount = 0\n for i in reversed(list(range(0,upper_bound))): \n if len(str(primes[i])) <= bestCount:\n break \n count = even(primes[i])\n if bestCount < count: \n best = primes[i]\n bestCount = count \n elif bestCount == count:\n if primes[i] > best: \n best = primes[i] \n bestCount = count \n return best\n", "import math\ndef check(nr): \n lim = int(nr ** 0.5)\n x = 0\n if nr == 2 or nr == 3:\n return True\n if nr % 2 == 0 or nr <= 1:\n return False\n if nr < 9:\n return True\n if nr % 3 == 0:\n return False\n i = 5\n while i <= lim:\n if nr % i == 0:\n return False\n if nr % (i + 2) == 0:\n return False\n i += 6\n return True\n \ndef biggest(nr):\n return (len(str(nr)) - 1) or 1\n\ndef count_even(nr):\n r = 0\n for i in str(nr):\n r += (int(i) % 2 == 0)\n return r\n \ndef f(n):\n nr = n - 1\n res = 0\n cmax = (0,0)\n while nr > 0:\n if check(nr):\n e = count_even(nr)\n b = biggest(nr)\n if e > cmax[0]:\n cmax = (e,nr)\n if b == cmax[0]:\n return cmax[1]\n nr -= 1\n\n", "isprime=lambda x:next((0 for i in range(3,int(x**.5)+1,2) if not x%i),1)\ndef f(n):\n limit = len(str(n)) - 1 - (str(n)[0] == '1')\n return next(i for i in range(n-([1,2][n&1]),1,-2) if isprime(i) and sum([not int(k)&1 for k in str(i)])==limit)", "evenDigits = ['0', '2', '4', '6', '8']\n\ndef primes(n):\n \"\"\" Returns a list of primes < n \"\"\"\n sieve = [True] * n\n for i in range(3,int(n**0.5)+1,2):\n if sieve[i]:\n sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)\n return [2] + [i for i in range(3,n,2) if sieve[i]]\n\ndef evenDigitCount(n):\n count = 0\n for c in str(n):\n if c in evenDigits:\n count += 1\n return count\n\ndef f(n):\n allPrimes = primes(n)\n p = allPrimes[0]\n mostEvenDigits = evenDigitCount(p)\n for prime in allPrimes:\n thisPrimesEvenDigits = evenDigitCount(prime)\n if thisPrimesEvenDigits >= mostEvenDigits:\n p = prime\n mostEvenDigits = thisPrimesEvenDigits\n \n return p\n", "def f(n):\n n = n - 1 if n % 2 == 0 else n - 2\n for i in range(n, 1, - 2):\n if len(str(i)) <= sum(1 for j in str(i) if int(j) % 2 == 0) + 1 + int(str(i)[0] == '1'):\n z = True\n for j in range(2, int(i ** 0.5) + 1):\n if i % j == 0:\n z = False\n break\n if z: return i\n"]
{"fn_name": "f", "inputs": [[1000], [10000], [500], [487]], "outputs": [[887], [8887], [487], [467]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,625
def f(n):
24212bad088fc4d24da53129fb217c75
UNKNOWN
Given a number, write a function to output its reverse digits. (e.g. given 123 the answer is 321) Numbers should preserve their sign; i.e. a negative number should still be negative when reversed. ### Examples ``` 123 -> 321 -456 -> -654 1000 -> 1 ```
["def reverse_number(n):\n \"\"\"\n Reverse a number, preserve negative sign\n \"\"\"\n s = str(n)\n ret = int(\"-{}\".format(s[:0:-1]) if \"-\" in s else s[::-1])\n return ret", "def reverse_number(n):\n rev = 0\n temp = n\n dig = 0\n if( n < 0):\n n = abs(n)\n while(n > 0):\n dig = n % 10\n rev = rev*10 + dig;\n n = n // 10\n if( temp < 0):\n return -rev\n else:\n return rev", "def reverse_number(n):\n if str(n)[0] == \"-\":\n return -int(str(n)[:0:-1])\n else:\n return int(str(n)[::-1])", "def reverse_number(n):\n return 0 if n == 0 else n/abs(n) * int(str(abs(n))[::-1])", "def reverse_number(n):\n return int(str(abs(n))[::-1]) * (-1)**(n<0)", "def reverse_number(n):\n return min(1, max(-1, n)) * int(str(abs(n))[::-1])", "reverse_number = lambda n: int(str(abs(n))[::-1]) * (1-2*(n<0))", "def reverse_number(n):\n r=str(n).replace('-','')[::-1]\n return int(r)if n>0 else -int(r)", "# Takes any input and reverses the digits. Preserves sign.\n\ndef reverse_number(number):\n if number >= 0:\n return int(str(number)[::-1])\n else:\n return -int(str(number)[:0:-1])\n", "def reverse_number(n):\n \n result = 0\n is_neg = False\n \n if n < 0:\n n = -n\n is_neg = True\n \n while n != 0:\n result *= 10\n result += n % 10\n n = int(n / 10)\n \n if is_neg:\n return -result\n else:\n return result\n", "def reverse_number(n):\n n_rev = int(\"\".join(reversed([c for c in str(n) if c.isdigit()])))\n return n_rev if n >= 0 else -n_rev", "def reverse_number(n):\n spacer = n < 0\n return int(['','-'][spacer] + str(n)[spacer:][::-1])", "def reverse_number(n):\n\n return int(str(n)[::-1]) if n > 0 else int(str(abs(n))[::-1]) * -1", "def reverse_number(n):\n if n < 0:\n return int(n.__str__()[1:][::-1]) * -1\n else:\n return int(n.__str__()[::-1])", "def reverse_number(n):\n return int(str(n)[::-1]) if n > 0 else -int(str(abs(n))[::-1])", "def reverse_number(n):\n return int(str(abs(n))[::-1]) * (-1 if n < 0 else 1)\n", "def reverse_number(n):\n return -int((str(n)[1::][::-1])) if n < 0 else int((str(n)[::-1]))", "def reverse_number(n):\n return int('-' * (n < 0) + ''.join(reversed(str(abs(n)))))", "def reverse_number(n):\n n = str(n)\n n = list(n)\n n.reverse()\n if n.count(\"-\") > 0:\n n.pop()\n n.insert(0, \"-\") \n \n a = str()\n for i in n:\n a += str(i)\n\n return int(a)", "def reverse_number(n):\n n=str(n)\n l=len(n)\n if n[0]=='-':\n n=int(n[:l*-1:-1])*-1\n else: n=n[::-1]\n return int(n)", "def reverse_number(n):\n si =len(str(n))\n i = si \n s = ''\n if n >= 0:\n while i > 0:\n s += str(n %10)\n n = n //10\n i -= 1\n return int(s)\n else:\n n = -1 * n\n while i > 1:\n s += str(n % 10)\n n = n // 10\n i -=1\n return -1 * int(s)\n", "from numpy import sign\n\ndef reverse_number(n):\n return sign(n) * int(str(abs(n))[::-1])", "reverse_number=lambda n: (-1 if n<0 else 1)*int(str(abs(n))[::-1])", "def reverse_number(n):\n if n >0: \n f = int(str(abs(n))[::-1])\n else:\n f = - int(str(abs(n))[::-1])\n return f", "def reverse_number(n):\n return -1*int(str(n*-1)[::-1]) if n<1 else int(str(n)[::-1])", "def reverse_number(n):\n return n//abs(n) * int(str(abs(n))[::-1]) if n != 0 else 0", "def reverse_number(n):\n if n < 0:\n s = str(n)[1:]\n return int(s[::-1]) * -1\n return int(str(n)[::-1])", "def reverse_number(n):\n sN = str(n)\n x = sN[::-1]\n new = ''\n for i in x:\n if i =='-':\n continue\n else:\n new+=i\n if n < 0:\n return -int(new)\n else:\n return int(new)", "def reverse_number(n):\n str_num = str(abs(n))[::-1]\n return -1 * int(str_num) if n < 0 else int(str_num)", "def reverse_number(n):\n return int(str(n).replace('-','')[::-1]) * (-1 if n < 0 else 1)", "def reverse_number(n):\n l_1 = str(n)\n if l_1[0] == '-':\n return int(l_1[0]+l_1[:0:-1])\n else:\n return int(l_1[::-1])", "def reverse_number(n):\n ans = 0\n if n>=0:\n while n>0:\n ans*=10\n ans+=n%10\n n=n//10\n print(ans)\n return(ans)\n elif n<0:\n n=n*(-1)\n while n>0:\n ans*=10\n ans+=n%10\n n=n//10\n print(ans)\n return(ans*(-1))", "def reverse_number(n):\n return int(str(n)[::-1]) if n>=0 else int('-'+str(-n)[::-1])", "def reverse_number(n):\n return int(str(n)[::-1] if n >=0 else \"-\"+str(n)[::-1][0:-1])", "def reverse_number(n):\n aux = n\n reverso = 0\n while abs(n)>0:\n ultimoDigito = abs(n)%10\n n=abs(n)//10\n reverso = reverso*10+ultimoDigito\n if aux>0:\n return reverso\n else:\n return reverso*(-1)", "def reverse_number(n):\n if n > 0: return int(str(n)[::-1])\n else: return -1 * int(str(n*-1)[::-1])", "def reverse_number(n):\n if n>=0:\n return int(str(n)[::-1])\n return int(str(n*-1)[::-1])*-1", "def reverse_number(n):\n number = str(n)\n list = []\n index = 0\n if n < 0:\n for i in number:\n if i.isdigit() == True:\n list.insert(0,i)\n\n new_num = \"\".join(list)\n return(0-int(new_num))\n else:\n for i in number:\n if i.isdigit() == True:\n list.insert(0,i)\n for i in list:\n while i == 0:\n index +=1\n else:\n break\n new_num = \"\".join(list[index::])\n return (int(new_num))", "def reverse_number(n):\n if n>=0:\n return int(str(n)[::-1])\n return int( \"-\" + (str(n)[1:] )[::-1] ) ", "def reverse_number(n):\n if n < 0:\n return 0 - int(str(n)[::-1][:-1])\n return int(str(n)[::-1])", "def reverse_number(n):\n return int(str(n)[::-1] if \"-\" not in str(n) else \"-\"+(str(n).replace(\"-\",\"\"))[::-1])", "def reverse_number(n):\n if n < 0:\n return -1 * int(str(n)[::-1][:-1])\n else:\n return int(str(n)[::-1])", "def reverse_number(n):\n \n if n>=0:\n\n d = [int(i) for i in str(n)]\n \n r = d[::-1]\n \n w = int(''.join(map(str,r)))\n \n return w\n \n if n<0:\n \n m = abs(n)\n \n d = [int(j) for j in str(m)]\n \n r = d[::-1]\n \n w = int(''.join(map(str,r)))\n \n return w*-1\n \n", "def reverse_number(n):\n x = int(str(abs(n))[::-1])\n return x if n>0 else -x", "def reverse_number(n):\n if n==0:\n return 0\n s=int(str(abs(n))[::-1])\n return n/abs(n)*s", "def reverse_number(n):\n a = str(n)[::-1]\n b = ''\n if '-' in a:\n b = '-' + a[:-1]\n return int(b)\n else:\n return int(a) ", "def reverse_number(n):\n if str(n)[0] == \"-\":\n return int(\"-{}\".format(str(n)[1:][::-1]))\n elif n == 0:\n return 0\n else:\n return int(str(n)[::-1].lstrip(\"0\"))", "def reverse_number(n):\n \n x = \"\"\n \n if n < 0:\n x += \"-\"\n \n n = abs(n)\n n = str(n)\n n = n[::-1]\n x += n\n \n x = int(x)\n return x", "def reverse_number(number):\n splitted = [x for x in str(number)]\n if '-' in splitted:\n splitted.remove('-')\n splitted.reverse()\n splitted.insert(0, '-')\n return int(''.join(splitted))\n\n else:\n splitted.reverse()\n return int(''.join(splitted))", "def reverse_number(n):\n if n < 0: return int(''.join([x for x in str(n)[1:][::-1]])) * -1\n else: return int(''.join([x for x in str(n)[::-1]]))", "def reverse_number(n):\n num = abs(n)\n if n < 0:\n return int(str(num)[::-1]) * -1\n else:\n return int(str(num)[::-1])", "def reverse_number(n):\n if abs(n)!=n:\n num = str(n)[::-1]\n return int('-'+num[:-1])\n return int(str(n)[::-1])", "def reverse_number(n):\n sign = -1 if n < 0 else 1\n return sign * int(str(n).replace('-','')[::-1])", "def reverse_number(n):\n s = str(abs(n))\n result = int(s[::-1])\n return result if n >=0 else -1*result\n", "def reverse_number(n):\n number=str(n)\n if n>=0:\n number=number[::-1]\n return int(number)\n number=number[-1:0:-1]\n return int(number)*-1", "def reverse_number(n):\n return int(str(abs(n))[::-1]) * (n < 0 and -1 or 1)", "def reverse_number(n):\n return int((n < 0 and '-' or '') + str(abs(n))[::-1])\n\n", "def reverse_number(n):\n if n<0:\n n=str(n)\n n=n[::-1]\n return -1*int(n.replace('-',''))\n else:\n n=str(n)\n n=n[::-1]\n return int(n)\n", "def reverse_number(n):\n if n < 0:\n return - int(str(n)[1:][::-1])\n try:\n return int(str(n).rstrip(\"0\")[::-1])\n except:\n return 0", "def reverse_number(n):\n if n == 0:\n return 0\n elif n < 0:\n ok = True\n n = -n\n else:\n ok = False\n \n while n % 10 == 0:\n n = n / 10\n \n aux = str(int(n))[::-1]\n \n if ok:\n return -int(aux)\n return int(aux)\n", "def reverse_number(n):\n return int(str(abs(n))[::-1]) *n//max(abs(n),1)", "def reverse_number(n):\n if n < 0:\n n = str(n)\n s = n[1:len(n)]\n new_n = n[0] + s[::-1]\n return int(new_n) \n else:\n n = str(n)\n n = n[::-1]\n return int(n)", "def reverse_number(n):\n res = []\n s = str(n)\n if s[0] == '-':\n res = \"-\" + s[:0:-1]\n else:\n res = s[::-1]\n return int(res)\n", "def reverse_number(n):\n return int(str(abs(n))[::-1]) * (1 if n >= 0 else -1)", "def reverse_number(n):\n x = str(n)\n if '-' in x:\n y = list(x)\n y.reverse()\n y.remove('-')\n return int(''.join(y)) * -1\n else:\n y = list(x)\n y.reverse()\n return int(''.join(y))", " #[f(x) if condition else g(x) for x in sequence]\n #[f(x) for x in sequence if condition]\ndef reverse_number(n):\n if str(n)[0]==\"-\":\n new = int(\"-\"+''.join([str(n)[1:][-1-i] for i in range(len(str(n))-1) ]))\n else:\n new = int(''.join([str(n)[-1-i] for i in range(len(str(n))) ]))\n\n if new ==0:\n return new\n else:\n return int(str(new).lstrip(\"0\"))\n", "def reverse_number(n):\n n = str(n)\n if \"-\" == n[0]:\n n = n[1:]\n n = n[::-1]\n n = \"-\" + n\n else:\n return int(n[::-1])\n return int(n)", "def reverse_number(n):\n neg = 0\n if abs(n) != n:\n n = -n\n neg = 1\n n = int(str(n)[::-1])\n return -n if neg == 1 else n", "def reverse_number(n):\n try : return int(str(n)[::-1])\n except : return -int(str(n)[::-1][:-1])", "def reverse_number(n):\n return int(str(abs(n))[::-1]) if n>-1 else -int(str(abs(n))[::-1])", "def reverse_number(n):\n if n < 0:\n return int('-' + str(abs(n))[::-1])\n return int(str(n)[::-1])", "def reverse_number(n):\n return int(str(n)[::-1].replace(\"-\", \"\")) * n / abs(n) if n != 0 else 0", "def reverse_number(n):\n \n digits = 0\n num = 0\n if(n >= 0):\n num = n\n sign_n = 1\n else:\n num = -n\n sign_n = -1\n \n # while loop to count the number of digits, stored in digits\n while(num >= 1):\n num /= 10\n digits += 1\n \n # Debugging print statement\n # print(\"digits = \" , digits)\n \n # Make n a positive number\n n = n * sign_n\n\n # for loop to store the digits of the positive part of n, strored as strings\n l_direct = list()\n for i in range(0,digits):\n l_direct.append(str(n % 10))\n n = int(n/10)\n #print(n)\n i += 1\n \n # Concatenate the elements of the list into a string\n s = \"\"\n for j in range(0, digits):\n s = s + l_direct[j] \n \n # We need to account for the case of an empty string, otherwise python will complain if we try \n # to convert an empty string to an integer\n if(s == ''):\n result = 0\n else:\n # restore the original sign of n\n result = int(s) * sign_n\n \n return result", "def reverse_number(num):\n ans = int(str(num)[::-1]) if num >= 0 else -int(str(-num)[::-1])\n return ans", "def reverse_number(n):\n return -int(str(n)[1:][::-1]) if n < 0 else int(str(n)[::-1])", "def reverse_number(n):\n\n number = n\n is_negative = False\n if n < 0:\n is_negative = True\n \n number = str(number)\n number = number.strip(\"-\")\n \n number = number[::-1]\n number = number.strip(\"0\")\n \n if number == \"\":\n number = \"0\"\n \n if is_negative:\n number = \"-\" + number\n \n return int(number)", "import unittest\n\n\ndef reverse_number(n):\n revered_num = int(str(abs(n))[::-1])\n\n if n < 0:\n return int('-{}'.format(revered_num))\n\n return revered_num\n\n \nclass TestReverseNumber(unittest.TestCase):\n def test_reverse_number_with_n_is_one_digit(self):\n n = 5\n actual = reverse_number(n)\n self.assertEqual(actual, 5)\n\n def test_reverse_number_with_negative_sign(self):\n n = -123\n actual = reverse_number(n)\n self.assertEqual(actual, -321)\n\n def test_reverse_number_without_any_sign(self):\n n = 123\n actual = reverse_number(n)\n self.assertEqual(actual, 321)\n\n def test_reverse_number_should_return_1_when_given_n_is_1000(self):\n n = 1000\n actual = reverse_number(n)\n self.assertEqual(actual, 1)\n", "def split(word): \n return [char for char in word] \n\ndef reverse_number(n):\n isNegative = False\n if n < 0:\n isNegative = True\n output = \"\"\n stringLst = split(str(n))\n stringLst.reverse() \n \n for i in stringLst:\n output += i\n \n if (isNegative):\n output = output.replace('-', '')\n result = int(output)\n return result*-1\n \n else:\n return int(output)", "def reverse_number(n):\n if n>0: return int(str(abs(n))[::-1])\n else: return int(str(abs(n))[::-1])*-1\n", "def reverse_number(n):\n res = int(str(abs(n))[:: -1])\n return res if n >= 0 else -res", "def reverse_number(n):\n return ((n>0)-(n<0)) * int(str(abs(n))[::-1])\n", "def reverse_number(n):\n try:\n return int(str(abs(n))[::-1]) * (n//abs(n))\n except ZeroDivisionError:\n return 0", "def reverse_number(n):\n \n result = \"\"\n \n if n == 0:\n \n return 0\n \n elif n > 0: # positive number case\n result = str(n)[::-1]\n \n return(int(result))\n \n else:\n result = (str(n)[1::])[::-1] # negative number case\n\n return(int(result)*-1) ", "def reverse_number(n):\n if str(n)[0] == '-':\n return -1 * int(str(n).split(\"-\")[1][::-1]) \n return int(str(n)[::-1]) ", "def reverse_number(n):\n try:\n return int(str(n)[::-1])\n except:\n return int(str(n)[:0:-1]) * -1", "def reverse_number(n):\n return int(''.join(reversed(str(abs(n))))) * (-1 if n < 0 else 1)", "def reverse_number(n):\n \n if n < 0 :\n a = str(n)[1:]\n return int(\"{}{}\".format(str(n)[0] , a[::-1]))\n else:\n return int(str(n)[::-1])", "def reverse_number(n):\n n = str(n)\n if int(n) < 0:\n return int(n[0] + n[:0:-1])\n else:\n return int(n[::-1])", "def reverse_number(n):\n s = ''\n if n<0 : s = '-'\n return int(s+''.join(i for i in reversed(str(abs(n)))))", "def reverse_number(n):\n print(n)\n if n >= 0:\n return int(str(n)[::-1])#\n #print(int(str(n)[::-1]))\n else:\n return -int(str(n)[:0:-1])\n #print(-int(str(n)[:0:-1]))\n", "def reverse_number(n):\n lst = [x for x in list(str(n))]\n lst.reverse()\n \n if n > -1:\n result = int(\"\".join(lst))\n\n else:\n result = int(\"\".join(lst[:-1])) * -1\n\n return result", "def reverse_number(n):\n return (1 - 2 * (n < 0)) * int(str(abs(n))[::-1])", "def reverse_number(n):\n n = str(n)\n if n[0] == '-':\n new_str = n[1:]\n new_str = new_str[::-1]\n new_str = '-' + new_str\n return int(new_str)\n else:\n new_str = n[::-1]\n return int(new_str)\n", "def reverse_number(n):\n n = int(str(abs(n))[::-1]) * (-1 if n < 0 else 1) \n return n", "def reverse_number(n):\n result=int(\"\".join(reversed(list(str(abs(n))))))\n if n>0:\n return result\n else:\n return -result"]
{"fn_name": "reverse_number", "inputs": [[123], [-123], [1000], [4321234], [5], [0], [98989898]], "outputs": [[321], [-321], [1], [4321234], [5], [0], [89898989]]}
INTRODUCTORY
PYTHON3
CODEWARS
17,095
def reverse_number(n):
a412fe6099e8cc8e96d099622aed2d0d
UNKNOWN
Hello everyone. I have a simple challenge for you today. In mathematics, the formula for finding the sum to infinity of a geometric sequence is: **ONLY IF** `-1 < r < 1` where: * `a` is the first term of the sequence * `r` is the common ratio of the sequence (calculated by dividing one term in the sequence by the previous term) For example: `1 + 0.5 + 0.25 + 0.125 + ... = 2` Your challenge is to calculate the sum to infinity of the given sequence. The solution must be rounded to 3 decimal places. If there are no solutions, for example if `r` is out of the above boundaries, return `"No Solutions"`. Hope you enjoy, let me know of any issues or improvements!
["def sum_to_infinity(sequence):\n return round(sequence[0]/(1-(sequence[1]/sequence[0])), 3) if abs(sequence[1]/sequence[0]) < 1 else \"No Solutions\"", "def sum_to_infinity(sequence):\n sequence = [float(x) for x in sequence]\n a, r = sequence[0], sequence[1] / sequence[0]\n if -1 < r < 1:\n return round(a / (1 - r), 3)\n return \"No Solutions\"", "def sum_to_infinity(sequence):\n x, y = sequence[:2]\n return round(x*x/(x-y), 3) if abs(x) > abs(y) else \"No Solutions\"", "def sum_to_infinity(sequence):\n r = sequence[1] / sequence[0]\n if abs(r) < 1:\n return round(sequence[0] / (1 - r), 3)\n return \"No Solutions\"", "def sum_to_infinity(arr):\n a, b = arr[:2]\n c = b / a\n return round(a / (1 - c), 3) if -1 < c < 1 else \"No Solutions\"", "def sum_to_infinity(seq):\n if len(seq) < 2:\n return 'No Solutions'\n r = seq[1] / seq[0]\n if r >= 1 or r <= -1:\n return 'No Solutions'\n return 1 if seq[0] == seq[1] else round(seq[0]/(1-r), 3)", "def sum_to_infinity(A):\n r = A[1] / A[0]\n if abs(r) >= 1:\n return \"No Solutions\"\n else:\n return round(A[0] / (1 - r), 3)", "sum_to_infinity = lambda l: 'No Solutions' if abs(l[1]) >= abs(l[0]) else round(l[0] / (1 - l[1] / l[0]), 3)", "def sum_to_infinity(sequence):\n a=sequence[0]\n r=sequence[1]/a\n return round(a/(1-r),3) if -1<r<1 else \"No Solutions\"", "def sum_to_infinity(seq):\n r=seq[1]/seq[0]\n return round(seq[0]/(1-r),3) if -1<r<1 else \"No Solutions\"", "def sum_to_infinity(a):\n return round(a[0] / (1 - a[1]/a[0]), 3) if -1 < a[1]/a[0] < 1 else 'No Solutions'\n", "def sum_to_infinity(sequence):\n r = sequence[2]/sequence[1]\n if not -1 < r < 1:\n return \"No Solutions\"\n return round(sequence[0]/(1-r),3)", "def sum_to_infinity(sequence):\n a = sequence[0]\n r = sequence[1]/sequence[0]\n #checking r is in range\n if r<=-1 or r>=1: #r mustn't be higher or equal than one and lower or equal minus one\n return \"No Solutions\"\n else: #there is formula to counting the sum of infinity geometric sequence\n return round(a/(1-r), 3) #rounded to 3 decimal places", "def sum_to_infinity(l):\n return round(l[0]/(1- l[1]/l[0]),3) if l[1]/l[0] < 1 and l[1]/l[0] > -1 else 'No Solutions'", "def sum_to_infinity(sequence):\n r = sequence[1] / sequence[0]\n if r <= -1 or r >= 1:\n return 'No Solutions'\n sum = sequence[0] / ( 1 - r )\n return round(sum, 3)", "def sum_to_infinity(sequence):\n # Good Luck!\n sum = 0\n print(sequence)\n if(len(sequence)>1):\n r = sequence[1]/sequence[0]\n print(r)\n if r<=-1 or r>=1:\n return 'No Solutions'\n sum = round(sequence[0]/(1-r),3)\n return sum\n \n return sequence[0] ", "def sum_to_infinity(sequence):\n r=sequence[1]/sequence[0]\n return round(sequence[0]/(1-r),3) if abs(r)<1 else 'No Solutions'", "def sum_to_infinity(sequence):\n if sequence[1]/sequence[0]<1 and sequence[1]/sequence[0]>-1:\n return float(str(round(sequence[0]/(1-sequence[1]/sequence[0]),3)))\n return \"No Solutions\"", "def sum_to_infinity(seq):\n r = seq[1]/seq[0]\n if not abs(r) < 1: \n return \"No Solutions\"\n res = seq[0]/(1-r)\n return round(res, 3)", "def sum_to_infinity(seq):\n r = seq[1]/seq[0]\n if not -1 < r < 1: \n return \"No Solutions\"\n res = seq[0]/(1-r)\n return round(res, 3)"]
{"fn_name": "sum_to_infinity", "inputs": [[[1, 0.5, 0.25, 0.125]], [[250, 100, 40, 16]], [[21, 4.2, 0.84, 0.168]], [[5, -2.5, 1.25, -0.625]]], "outputs": [[2], [416.667], [26.25], [3.333]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,508
def sum_to_infinity(sequence):
2afabb831774bebd7511fd1ecdf1c2a6
UNKNOWN
Given an array (or list or vector) of arrays (or, guess what, lists or vectors) of integers, your goal is to return the sum of a specific set of numbers, starting with elements whose position is equal to the main array length and going down by one at each step. Say for example the parent array (etc, etc) has 3 sub-arrays inside: you should consider the third element of the first sub-array, the second of the second array and the first element in the third one: `[[3, 2, 1, 0], [4, 6, 5, 3, 2], [9, 8, 7, 4]]` would have you considering `1` for `[3, 2, 1, 0]`, `6` for `[4, 6, 5, 3, 2]` and `9` for `[9, 8, 7, 4]`, which sums up to `16`. One small note is that not always each sub-array will have enough elements, in which case you should then use a default value (if provided) or `0` (if not provided), as shown in the test cases.
["def elements_sum(arr, d=0):\n return sum(r[i] if i<len(r) else d for i,r in enumerate(reversed(arr)))", "def elements_sum(arr, d=0):\n a=len(arr) \n res=0\n for i in arr:\n if len(i)>=a:\n res+=i[a-1]\n else:\n res+=d\n a-=1\n return res", "def elements_sum(arr, d=0):\n return sum(a[i] if len(a) > i else d for i, a in enumerate(arr[::-1]))", "def elements_sum(arr, d = 0):\n lf = len(arr) - 1\n return sum(n[lf - i] if n and len(n) > (lf - i) else d for i,n in enumerate(arr))", "def elements_sum(arr, d=0):\n count = len(arr) \n result = 0\n for i in arr:\n if len(i) >= count:\n result += i[count-1]\n else:\n result += d\n count -= 1\n return result", "def elements_sum(arr, d=0):\n return sum(lst[i] if i < len(lst) else d for i, lst in enumerate(arr[::-1]))\n", "def elements_sum(arr, d=0):\n summ = 0\n for i in arr:\n try:\n summ += i[len(arr)-(arr.index(i)+1)]\n except IndexError:\n summ += d\n return summ", "def elements_sum(arr, d=0):\n return sum([d if not arr[x] or (len(arr[x]) <= len(arr)-x-1) else arr[x][len(arr)-x-1] for x in range(len(arr))])\n\n", "def elements_sum(arr, *d):\n d = d[0] if d else 0\n c = []\n for k,v in enumerate(arr):\n try:\n c.append(arr[k][len(arr)-k-1])\n except:\n c.append(d)\n return sum(c)\n \n \n", "def elements_sum(arr, d=0):\n return sum([x[len(arr) - 1 - i] if len(arr) - 1 - i < len(x) else d for (i, x) in enumerate(arr)])"]
{"fn_name": "elements_sum", "inputs": [[[[3, 2, 1, 0], [4, 6, 5, 3, 2], [9, 8, 7, 4]]], [[[3], [4, 6, 5, 3, 2], [9, 8, 7, 4]]], [[[3, 2, 1, 0], [4, 6, 5, 3, 2], []]], [[[3, 2, 1, 0], [4, 6, 5, 3, 2], []], 5], [[[3, 2], [4], []]]], "outputs": [[16], [15], [7], [12], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,619
def elements_sum(arr, d=0):
b96b81384380c91dbfb0a953ec179e81
UNKNOWN
Write a simple parser that will parse and run Deadfish. Deadfish has 4 commands, each 1 character long: * `i` increments the value (initially `0`) * `d` decrements the value * `s` squares the value * `o` outputs the value into the return array Invalid characters should be ignored. ```python parse("iiisdoso") ==> [8, 64] ```
["def parse(data):\n value = 0\n res=[]\n for c in data:\n if c==\"i\": value+=1\n elif c==\"d\": value-=1\n elif c==\"s\": value*=value\n elif c==\"o\": res.append(value)\n return res", "def parse(data):\n arr = []\n value = 0\n for c in data:\n if c == \"i\":\n value += 1\n elif c == \"d\":\n value -= 1\n elif c == \"s\":\n value = value**2\n elif c == \"o\":\n arr.append(value)\n return arr", "def parse(data):\n action = {'i': lambda v, r: v + 1,\n 'd': lambda v, r: v - 1,\n 's': lambda v, r: v * v,\n 'o': lambda v, r: r.append(v) or v}\n v, r = 0, []\n for a in data:\n v = action[a](v, r) if a in action else v\n return r", "COMMANDS = {\n 'i': lambda x: x + 1,\n 'd': lambda x: x - 1,\n 's': lambda x: x * x,\n}\n\ndef parse(data):\n result, x = [], 0\n for c in data:\n if c == 'o':\n result.append(x)\n elif c in COMMANDS:\n x = COMMANDS[c](x)\n return result", "class Deadfish:\n commands = {\n 'i': lambda df: df.i(),\n 'd': lambda df: df.d(),\n 's': lambda df: df.s(),\n 'o': lambda df: df.o()\n }\n\n def __init__(self):\n self.value = 0\n self.outputs = []\n\n def i(self): self.value += 1\n def d(self): self.value -= 1\n def s(self): self.value **= 2\n def o(self): self.outputs.append(self.value)\n\n def apply(self, command):\n try: Deadfish.commands[command](self)\n except KeyError: pass\n\ndef parse(commands):\n df = Deadfish()\n [df.apply(c) for c in commands]\n return df.outputs\n", "def parse(data):\n v, r = 0, []\n for c in data:\n v, r = v + {'i': 1, 'd': -1, 's': v * (v - 1)}.get(c, 0), r + [v] * (c == 'o')\n return r", "def parse(data):\n result = []\n value = 0\n for command in data:\n if command == 'i':\n value += 1\n elif command == 'd':\n value -= 1\n elif command == 's':\n value = value**2\n elif command == 'o':\n result.append(value)\n return result", "def parse(data):\n def process_char(c):\n nonlocal v\n if c == \"i\": v += 1\n elif c == \"d\": v -= 1\n elif c == \"s\": v *= v\n elif c == \"o\": return True\n \n v = 0\n return [v for c in data if process_char(c)]", "def parse(s):\n ans = []\n num = 0\n for c in s:\n if c == 'i': num += 1\n if c == 'd': num -= 1\n if c == 's': num **= 2\n if c == 'o': ans.append(num)\n return ans", "def parse(data):\n curr = 0\n output = []\n for cmd in data:\n if cmd == \"i\":\n curr += 1\n elif cmd == \"d\":\n curr -= 1\n elif cmd == \"s\":\n curr *= curr\n elif cmd == \"o\":\n output.append(curr)\n return output"]
{"fn_name": "parse", "inputs": [["ooo"], ["ioioio"], ["idoiido"], ["isoisoiso"], ["codewars"]], "outputs": [[[0, 0, 0]], [[1, 2, 3]], [[0, 1]], [[1, 4, 25]], [[0]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,011
def parse(data):
35641894764fccae30d8cdb54703e990
UNKNOWN
Imagine there's a big cube consisting of n^3 small cubes. Calculate, how many small cubes are not visible from outside. For example, if we have a cube which has 4 cubes in a row, then the function should return 8, because there are 8 cubes inside our cube (2 cubes in each dimension)
["def not_visible_cubes(n):\n return max(n - 2, 0) ** 3", "def not_visible_cubes(n):\n return max(0,(n-2)) ** 3", "def not_visible_cubes(n):\n if n > 1:\n return (n-2)**3\n else:\n return 0", "def not_visible_cubes(n):\n if 0 <= n <= 2: return 0\n return (n - 2)**3", "import math\ndef not_visible_cubes(n):\n if (n < 2) : return 0\n else :\n# return long(math.pow(n-2,3))\n return (n-2)*(n-2)*(n-2)\n \n", "def not_visible_cubes(n):\n return pow(n-2, 3) if n>2 else 0", "def not_visible_cubes(n):\n return n > 2 and (n-2)**3", "def not_visible_cubes(n):\n if n == 0 or n == 1 or n == 2:\n return 0\n totalCubes = n*n*n\n cubesPerSide = n*n\n outsideCubes = cubesPerSide + 2*(cubesPerSide - n) + cubesPerSide - 2*n + 2*(cubesPerSide - (n + 2*(n - 1) + n - 2))\n return totalCubes - outsideCubes", "def not_visible_cubes(n):\n return pow(n-2,3) if n>1 else 0", "def not_visible_cubes(n):\n return (n-2) ** 3 if n > 2 else 0"]
{"fn_name": "not_visible_cubes", "inputs": [[0], [1], [2], [3], [4], [5], [7], [12], [18], [10002]], "outputs": [[0], [0], [0], [1], [8], [27], [125], [1000], [4096], [1000000000000]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,012
def not_visible_cubes(n):
ff265649e6e1a3012b373fbd3e8d21e8
UNKNOWN
# Task Given array of integers `sequence` and some integer `fixedElement`, output the number of `even` values in sequence before the first occurrence of `fixedElement` or `-1` if and only if `fixedElement` is not contained in sequence. # Input/Output `[input]` integer array `sequence` A non-empty array of positive integers. `4 ≤ sequence.length ≤ 100` `1 ≤ sequence[i] ≤ 9` `[input]` integer `fixedElement` An positive integer `1 ≤ fixedElement ≤ 9` `[output]` an integer # Example For `sequence = [1, 4, 2, 6, 3, 1] and fixedElement = 6`, the output should be `2`. There are `2` even numbers before `6`: `4 and 2` For `sequence = [2, 2, 2, 1] and fixedElement = 3`, the output should be `-1`. There is no `3` appears in `sequence`. So returns `-1`. For `sequence = [1, 3, 4, 3] and fixedElement = 3`, the output should be `0`. `3` appears in `sequence`, but there is no even number before `3`.
["def even_numbers_before_fixed(s, f):\n return len([x for x in s[:s.index(f)] if x%2 == 0]) if f in s else -1", "def even_numbers_before_fixed(sequence, fixed_element):\n ans = 0\n for s in sequence:\n if s == fixed_element:\n return ans\n ans += (s % 2 == 0)\n return -1", "def even_numbers_before_fixed(sequence, fixed_element):\n return len(list(filter(lambda x: x % 2 == 0, sequence[:sequence.index(fixed_element)]))) if fixed_element in sequence else -1", "def even_numbers_before_fixed(sequence, fixed_element):\n if fixed_element in sequence:\n i = sequence.index(fixed_element)\n return sum(1 for n in sequence[:i] if n % 2 == 0)\n else:\n return -1", "from itertools import islice\n\ndef even_numbers_before_fixed(sequence, fixed_element):\n try:\n i = sequence.index(fixed_element)\n except ValueError:\n return -1\n return sum(x % 2 == 0 for x in islice(sequence, i))", "def even_numbers_before_fixed(sequence, fixed_element):\n try:\n return sum(elem % 2 == 0 for elem in sequence[:sequence.index(fixed_element)])\n except ValueError:\n return -1", "def even_numbers_before_fixed(a, n):\n return sum(i%2 == 0 for i in a[:a.index(n)]) if n in a else -1", "def even_numbers_before_fixed(s, fe):\n if fe in s:\n idx = s.index(fe)\n return sum([(e+1)%2 for e in s[:idx]])\n else:\n return -1", "def even_numbers_before_fixed(seq,e):\n return sum(1-(n%2) for n in seq[:seq.index(e)]) if e in seq else -1", "def even_numbers_before_fixed(S, p):\n return sum(not e%2 for e in S[:S.index(p)]) if p in S else -1"]
{"fn_name": "even_numbers_before_fixed", "inputs": [[[1, 4, 2, 6, 3, 1], 6], [[2, 2, 2, 1], 3], [[2, 3, 4, 3], 3], [[1, 3, 4, 3], 3]], "outputs": [[2], [-1], [1], [0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,663
def even_numbers_before_fixed(sequence, fixed_element):
54b34315e11a42c24b84772d44437f29
UNKNOWN
## Description You are a *Fruit Ninja*, your skill is cutting fruit. All the fruit will be cut in half by your knife. For example: ``` [ "apple", "pear", "banana" ] --> ["app", "le", "pe", "ar", "ban", "ana"] ``` As you see, all fruits are cut in half. You should pay attention to `"apple"`: if you cannot cut a fruit into equal parts, then the first part will has a extra character. You should only cut the fruit, other things **should not be cut**, such as the `"bomb"`: ``` [ "apple", "pear", "banana", "bomb"] --> ["app", "le", "pe", "ar", "ban", "ana", "bomb"] ``` The valid fruit names are preloded for you as: ```python FRUIT_NAMES ``` ## Task ```if:javascript Complete function `cutFruits` that accepts argument `fruits`. Returns the result in accordance with the rules above. ``` ```if:ruby,python Complete function `cut_fruits` that accepts argument `fruits`. Returns the result in accordance with the rules above. ``` ```if:haskell Complete function cutFruits that accepts a String array/list. Returns the result in accordance with the rules above. ``` OK, that's all. I guess this is a 7kyu kata. If you agree, please rank it as 7kyu and vote `very`;-) If you think this kata is too easy or too hard, please shame me by rank it as you want and vote `somewhat` or `none` :[ --- ##### *[Click here](https://www.codewars.com/kata/search/?q=i+guess+this+is+a+kyu+kata) for more more "I guess this is ...kyu" katas!*
["FRUIT_NAMES = {'blueberry', 'pear', 'durian', 'ginkgo', 'peach', 'apple', 'cantaloupe', 'fig', 'mangosteen', 'watermelon', 'pineapple', 'cherry', 'pomegranate', 'carambola', 'hawthorn', 'persimmon', 'apricot', 'plum', 'litchi', 'mango', 'jujube', 'lemon', 'orange', 'tomato', 'banana', 'coconut', 'grape', 'pitaya'}\ndef cut(x):\n if x in FRUIT_NAMES:\n m = (len(x) + 1) // 2\n return [x[:m], x[m:]]\n return [x]\n\ndef cut_fruits(fruits):\n return [x for xs in map(cut, fruits) for x in xs]", "FRUIT_NAMES = {'blueberry', 'pear', 'durian', 'ginkgo', 'peach', 'apple', 'cantaloupe', 'fig', 'mangosteen', 'watermelon', 'pineapple', 'cherry', 'pomegranate', 'carambola', 'hawthorn', 'persimmon', 'apricot', 'plum', 'litchi', 'mango', 'jujube', 'lemon', 'orange', 'tomato', 'banana', 'coconut', 'grape', 'pitaya'}\nfrom itertools import chain\n\ndef cut_fruits(fruits):\n return list(chain(*map(cut,fruits)))\n\ndef cut(f):\n if f not in FRUIT_NAMES:\n yield f\n else:\n i = sum(divmod(len(f),2))\n yield f[:i]\n yield f[i:]", "FRUIT_NAMES = {'blueberry', 'pear', 'durian', 'ginkgo', 'peach', 'apple', 'cantaloupe', 'fig', 'mangosteen', 'watermelon', 'pineapple', 'cherry', 'pomegranate', 'carambola', 'hawthorn', 'persimmon', 'apricot', 'plum', 'litchi', 'mango', 'jujube', 'lemon', 'orange', 'tomato', 'banana', 'coconut', 'grape', 'pitaya'}\nimport math\ndef cut_fruits(fruits):\n cut_fruits = []\n for i in fruits:\n if i in FRUIT_NAMES:\n cut_fruits.extend([i[0:math.ceil(len(i)/2)],i[math.ceil(len(i)/2):]])\n else:\n cut_fruits.append(i)\n return cut_fruits", "FRUIT_NAMES = {'blueberry', 'pear', 'durian', 'ginkgo', 'peach', 'apple', 'cantaloupe', 'fig', 'mangosteen', 'watermelon', 'pineapple', 'cherry', 'pomegranate', 'carambola', 'hawthorn', 'persimmon', 'apricot', 'plum', 'litchi', 'mango', 'jujube', 'lemon', 'orange', 'tomato', 'banana', 'coconut', 'grape', 'pitaya'}\nfrom math import ceil\n\ndef cut_fruits(fruits):\n result = []\n for x in fruits:\n if x in FRUIT_NAMES:\n result.append(x[:ceil(len(x)/2)])\n result.append(x[ceil(len(x)/2):])\n else:\n result.append(x)\n return result\n", "FRUIT_NAMES = {'blueberry', 'pear', 'durian', 'ginkgo', 'peach', 'apple', 'cantaloupe', 'fig', 'mangosteen', 'watermelon', 'pineapple', 'cherry', 'pomegranate', 'carambola', 'hawthorn', 'persimmon', 'apricot', 'plum', 'litchi', 'mango', 'jujube', 'lemon', 'orange', 'tomato', 'banana', 'coconut', 'grape', 'pitaya'}\ndef cut_fruits(fruits):\n result = []\n for item in fruits:\n if item in FRUIT_NAMES:\n l = len(item)\n m = sum(divmod(l, 2))\n result.extend((item[:m], item[m:]))\n else:\n result.append(item)\n return result", "FRUIT_NAMES = {'blueberry', 'pear', 'durian', 'ginkgo', 'peach', 'apple', 'cantaloupe', 'fig', 'mangosteen', 'watermelon', 'pineapple', 'cherry', 'pomegranate', 'carambola', 'hawthorn', 'persimmon', 'apricot', 'plum', 'litchi', 'mango', 'jujube', 'lemon', 'orange', 'tomato', 'banana', 'coconut', 'grape', 'pitaya'}\nfrom math import ceil \n\ndef cut_fruits(fruits):\n res = []\n for fruit in fruits: \n if fruit in FRUIT_NAMES: \n med = ceil(len(fruit)/2)\n res.extend([fruit[: med], fruit[med: ]])\n else: \n res.append(fruit)\n return res", "FRUIT_NAMES = {'blueberry', 'pear', 'durian', 'ginkgo', 'peach', 'apple', 'cantaloupe', 'fig', 'mangosteen', 'watermelon', 'pineapple', 'cherry', 'pomegranate', 'carambola', 'hawthorn', 'persimmon', 'apricot', 'plum', 'litchi', 'mango', 'jujube', 'lemon', 'orange', 'tomato', 'banana', 'coconut', 'grape', 'pitaya'}\nF = {f:(f[:(len(f)+1)//2], f[(len(f)+1)//2:]) for f in FRUIT_NAMES}\n\ndef cut_fruits(fruits):\n return [e for t in [F.get(f, (f, '')) for f in fruits] for e in t if e]", "FRUIT_NAMES = {'blueberry', 'pear', 'durian', 'ginkgo', 'peach', 'apple', 'cantaloupe', 'fig', 'mangosteen', 'watermelon', 'pineapple', 'cherry', 'pomegranate', 'carambola', 'hawthorn', 'persimmon', 'apricot', 'plum', 'litchi', 'mango', 'jujube', 'lemon', 'orange', 'tomato', 'banana', 'coconut', 'grape', 'pitaya'}\ncut_fruits=lambda f,c=__import__('math').ceil,l=[]:l.clear()or f and[l.extend([e[:c(len(e)/2)],e[c(len(e)/2):]])if e in FRUIT_NAMES else l.append(e)for e in f][0]or l", "FRUIT_NAMES = {'blueberry', 'pear', 'durian', 'ginkgo', 'peach', 'apple', 'cantaloupe', 'fig', 'mangosteen', 'watermelon', 'pineapple', 'cherry', 'pomegranate', 'carambola', 'hawthorn', 'persimmon', 'apricot', 'plum', 'litchi', 'mango', 'jujube', 'lemon', 'orange', 'tomato', 'banana', 'coconut', 'grape', 'pitaya'}\nfrom itertools import *\nfrom math import *\ndef cut_fruits(fruits):\n def half(f):\n return [f[0:ceil(len(f)/2)], f[ceil(len(f)/2):]] if f in FRUIT_NAMES else [f]\n\n return list( chain(*[half(f) for f in fruits]) )", "FRUIT_NAMES = {'blueberry', 'pear', 'durian', 'ginkgo', 'peach', 'apple', 'cantaloupe', 'fig', 'mangosteen', 'watermelon', 'pineapple', 'cherry', 'pomegranate', 'carambola', 'hawthorn', 'persimmon', 'apricot', 'plum', 'litchi', 'mango', 'jujube', 'lemon', 'orange', 'tomato', 'banana', 'coconut', 'grape', 'pitaya'}\ndef cut_fruits(fruits):\n result = list()\n for val in fruits:\n if val in FRUIT_NAMES:\n if(len(val)%2==0):\n re = int(len(val)/2)\n result.append(val[:re])\n result.append(val[re:])\n else:\n re = int(len(val)/2)\n result.append(val[:re+1])\n result.append(val[re+1:])\n else:\n result.append(val)\n return(result)"]
{"fn_name": "cut_fruits", "inputs": [[["apple", "pear", "banana"]], [["apple", "pear", "banana", "bomb"]], [[]]], "outputs": [[["app", "le", "pe", "ar", "ban", "ana"]], [["app", "le", "pe", "ar", "ban", "ana", "bomb"]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,778
def cut_fruits(fruits):
d7e360425030ca997fbc82f73ae897e2
UNKNOWN
Write a function called calculate that takes 3 values. The first and third values are numbers. The second value is a character. If the character is "+" , "-", "*", or "/", the function will return the result of the corresponding mathematical function on the two numbers. If the string is not one of the specified characters, the function should return null (throw an `ArgumentException` in C#). Keep in mind, you cannot divide by zero. If an attempt to divide by zero is made, return null (throw an `ArgumentException` in C#)/(None in Python).
["def calculate(num1, operation, num2): \n # your code here\n try :\n return eval(\"{} {} {}\".format(num1, operation, num2))\n except (ZeroDivisionError, SyntaxError):\n return None", "def calculate(num1, operation, num2):\n ops = {\"+\": (lambda x, y: x + y), \"-\": (lambda x, y: x - y), \"*\": (lambda x, y: x * y), \"/\": (lambda x, y: x / y)}\n try: return ops[operation](num1, num2)\n except: return None", "\ndef calculate(num1, operation, num2):\n try:\n return eval(f'{num1}{operation}{num2}')\n except Exception:\n return", "def calculate(num1, oper, num2): \n return None if all((oper=='/',num2==0)) else {\n '+':lambda x,y:x+y,\n '-':lambda x,y:x-y,\n '/':lambda x,y:x/y,\n '*':lambda x,y:x*y,}.get(oper, lambda x,y:None)(num1,num2)\n", "from operator import add, sub, mul, truediv\nD = {'+':add, '-':sub, '*':mul, '/':truediv}\n\ndef calculate(num1, operation, num2): \n try:\n return D[operation](num1, num2)\n except (ZeroDivisionError, KeyError):\n return", "def calculate(num1, operation, num2):\n if operation == \"+\":\n c=num1 + num2\n return c\n if operation == \"-\":\n c=num1 - num2\n return c\n if operation == \"*\":\n c=num1 * num2\n return c\n if operation == \"/\":\n if num2 == 0:\n c=None\n return c\n c=num1 / num2\n return c\n else:\n c=None\n return c", "from operator import add, sub, mul\ndef calculate(num1, operation, num2): \n d = {'+': add, '-': sub, '*': mul, '/': lambda a, b: a / b if b else None}\n return d.get(operation, lambda a, b: None)(num1, num2)", "def calculate(num1, operation, num2): \n try: \n return eval(str(num1) + operation + str(num2))\n except: \n return None", "def calculate(*args): \n try:\n return eval(('').join(map(str, args)))\n except:\n return None", "from operator import add, sub, mul, truediv as div\n\noperators = {\n \"+\": add,\n \"-\": sub,\n \"*\": mul,\n \"/\": div,\n}\n\ndef calculate(n1, op, n2):\n return operators.get(op, lambda m, n: None)(n1, n2) if f\"{op}{n2}\" != \"/0\" else None"]
{"fn_name": "calculate", "inputs": [[3.2, "+", 8], [3.2, "-", 8], [3.2, "/", 8], [3.2, "*", 8], [-3, "+", 0], [-3, "-", 0], [-2, "/", -2], [-3, "*", 0], [-3, "/", 0], [-3, "w", 0], [-3, "w", 1]], "outputs": [[11.2], [-4.8], [0.4], [25.6], [-3], [-3], [1], [0], [null], [null], [null]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,266
def calculate(num1, operation, num2):
f110b0501d3cfca302a4ef9705536d5e
UNKNOWN
Create a function that takes a string and an integer (`n`). The function should return a string that repeats the input string `n` number of times. If anything other than a string is passed in you should return `"Not a string"` ## Example ``` "Hi", 2 --> "HiHi" 1234, 5 --> "Not a string" ```
["def repeat_it(string,n):\n return string * n if isinstance(string,str) else 'Not a string'", "def repeat_it(string,n):\n if type(string) is not str:\n return 'Not a string'\n return string * n", "repeat_it = lambda s, m: s*m if type(s) is str else \"Not a string\"", "def repeat_it(s, n):\n return s * n if isinstance(s, str) else 'Not a string'", "repeat_it = lambda s, m: s*m if isinstance(s, str) else \"Not a string\"", "def repeat_it(string, n):\n return string*n if isinstance(string, type(\"\")) else \"Not a string\"", "def repeat_it(string,n):\n return n * string if isinstance(string, str) else \"Not a string\"", "def repeat_it(string,n):\n if isinstance(string,str): \n return n*string\n else:\n return \"Not a string\"", "def repeat_it(string,n):\n if type(string) is str:\n return string*n\n return \"Not a string\"", "def repeat_it(string,n):\n return string * n if type(string) == type('1') else 'Not a string'", "def repeat_it(string: str, n: int) -> str:\n \"\"\" Get string that repeats the input string `n` number of time. \"\"\"\n if type(string) is str:\n return string * n\n else:\n return \"Not a string\"", "def repeat_it(string,n):\n return ''.join(string for i in range(n)) if type(string) == str else 'Not a string'", "def repeat_it(string,n):\n print( string)\n if type(string) == str:\n return string * n\n print(string*n)\n else:\n return 'Not a string'", "def repeat_it(string,n):\n print(type(string))\n return string*n if type(string) is str else 'Not a string'", "def repeat_it(string,n):\n if type(string) is not str:\n return \"Not a string\"#bitch\n return string * n", "def repeat_it(string,n):\n if (n == 0):\n return ''\n return string * n if type(string) == str else 'Not a string'", "def repeat_it(string: str, n: int) -> str:\n return string * n if isinstance(string, str) else \"Not a string\"\n", "repeat_it=lambda string,n: string*n if type(string)==str else \"Not a string\"", "def repeat_it(string,n):\n return \"Not a string\" if type(string) != str else ''.join([string for i in range (1, n + 1)])", "def repeat_it(string,n):\n return (string + repeat_it(string,n - 1) if n > 0 else \"\") if type(string) is str else \"Not a string\"", "repeat_it = lambda string, n: string * n if string and type(string) == type('') else 'Not a string'", "def repeat_it(string,n):\n return (''.join([string for x in range(n)]) if type(string) is str else 'Not a string')", "def repeat_it(string,n):\n if not isinstance(string, str):\n return \"Not a string\"\n s = \"\" \n for i in range(n):\n s += string\n return s\n", "def repeat_it(string,n):\n try:\n if str(string) == string:\n return string * n\n else: return \"Not a string\"\n except ValueError:\n return string * n", "def repeat_it(st,n):\n return st * n if type(st) == str else \"Not a string\"", "def repeat_it(string,n):\n if string==[] or string=={}:\n return 'Not a string'\n if isinstance(string,int):\n return 'Not a string'\n print(string)\n return string*n ", "def repeat_it(string,n):\n return string*n if type(string) == type('SSS') else \"Not a string\"", "def repeat_it(string,n):\n if type(string)==str:\n return string*n\n elif type(string)!=str:\n return \"Not a string\"", "def repeat_it(k,n):\n return k*n if isinstance(k ,str) else 'Not a string'", "def repeat_it(string,n):\n if type(string) == str:\n res = string * n\n else:\n res = 'Not a string'\n return res", "def repeat_it(string,n):\n return n * string if type(string) == type(\"a\") else \"Not a string\"", "def repeat_it(strng,n):\n if type(strng) != type(\"\"):\n return \"Not a string\"\n return strng * n", "def repeat_it(string,n):\n a = \"\"\n if isinstance(string, str):\n for i in range(0, n):\n a = a + string\n else:\n return \"Not a string\"\n return a", "def repeat_it(string,n):\n if isinstance(string, str):\n a = \"\"\n for i in range (1, n + 1):\n a += string\n return a\n else:\n return \"Not a string\"", "def repeat_it(a,n):\n if isinstance(a, str):\n return n*a\n else:\n return \"Not a string\"", "def repeat_it(string,n):\n return string * n if str(n).isdigit() and isinstance(string, str) else \"Not a string\"", "def repeat_it(strng, n):\n return strng*n if type(strng) == str else \"Not a string\"", "def repeat_it(string,n):\n if type(string) != type('aring'):\n return 'Not a string'\n return n * string\n", "def repeat_it(string,n):\n if not string or isinstance(string, int):\n return \"Not a string\"\n else: \n return string * n", "def repeat_it(string,n):\n return string*n if str(type(string)) == \"<class 'str'>\" else \"Not a string\"", "def repeat_it(string,n):\n str = ''\n bool = False\n for i in range(n):\n try:\n str += string\n except: \n bool = True\n return 'Not a string'\n if bool == False:\n return str", "repeat_it=lambda s,n:s*n if type(s) is str else 'Not a string'", "def repeat_it(string,n):\n if string == str(string):\n return str(string * n)\n else:\n return \"Not a string\"", "def repeat_it(string,n):\n if not str(string) == string:\n return 'Not a string'\n return string * n", "def repeat_it(string,n):\n if type(string) != str: return \"Not a string\" \n return_string = []\n for i in range(n):\n return_string.append(string)\n return \"\".join(return_string)\n", "repeat_it = lambda s, n: 'Not a string' if type(s) is not str else s * n", "def repeat_it(string,n):\n return string*n if (string !=[] and type(string)==str) else 'Not a string'", "def repeat_it(xs,n):\n if not isinstance(xs,str):\n return \"Not a string\"\n else:\n return xs * n", "def repeat_it(string,n):\n print(string,n)\n if string == str(string):\n return string*n if string else 'Not a string'\n else:\n return 'Not a string'", "def repeat_it(string,n):\n result = \"\"\n if type(string) != type('string'):\n return \"Not a string\"\n else:\n result += string * n\n return result", "repeat_it=lambda s, n: 'Not a string' if type(s)!=str else s*n", "def repeat_it(string,n):\n #your code here\n try:\n a = string.lower()\n return string*n\n except:\n return 'Not a string'", "def repeat_it(string,n):\n if not isinstance(string, str): return \"Not a string\"\n result = ''\n for s in range(0, n): result += string\n return result", "def repeat_it(s,n):\n return \"Not a string\" if s!=str(s) else s*n", "def repeat_it(m,n):\n if m == str(m):\n return m * n\n else:\n return \"Not a string\"", "def repeat_it(s,n):\n return s*n if s == str(s) else 'Not a string'", "def repeat_it(string,n):\n if n==0: \n return ''\n for i in range(n):\n if isinstance(string, str)==True:\n return string*n\n \n else: \n return \"Not a string\"\n", "def repeat_it(string,n):\n return 'Not a string' if type(string)==int\\\n or not string or string==False or string==True else n*string", "def repeat_it(s,n):\n return n*s if type(s)==str else \"Not a string\"", "def repeat_it(s,n):\n t = s\n if isinstance(s,str) and n != 0:\n for i in range(n-1):\n s += t\n return s\n if n == 0:\n return ''\n return 'Not a string'", "def repeat_it(string,n):\n return string * n if string.__class__ == str else 'Not a string'", "def repeat_it(sz, n):\n if type(sz) != str:\n return 'Not a string'\n else:\n return sz * n", "def repeat_it(string,n):\n if type(string) != type(\"\"):\n return \"Not a string\"\n else:\n return string*n", "def repeat_it(string,n):\n if type(string)==int:\n return 'Not a string'\n elif not string:\n return 'Not a string'\n try:\n for char in string:\n if char=='2':\n return string*n\n elif char.isdigit():\n return 'Not a string'\n return string*n\n except:\n return 'Not a string'\n", "def repeat_it(strng,n):\n return strng * n if type(strng) is str else 'Not a string'", "def repeat_it(string,n):\n try:\n if type(string) == str: return string * n\n else: return \"Not a string\"\n except:\n return \"Not a string\"", "def repeat_it(string,n):\n if type(string) == int or string == {} or string == [] or string == 1:\n return 'Not a string'\n else:\n return string * n", "def repeat_it(string,n):\n if type(string) == str:\n newString = \"\"\n for i in range (n):\n newString += string\n \n return newString\n else:\n return \"Not a string\"", "def repeat_it(string,n):\n if type(string) == str:\n return string*n\n else:\n return \"Not a string\"\n\nprint((repeat_it(1234, 2)))\n", "def repeat_it(string,n):\n if not isinstance(string, str):\n return \"Not a string\"\n return ''.join(string for i in range(n))", "def repeat_it(string,n):\n if isinstance(string, str):\n final = \"\"\n for i in range(n):\n final += string\n return final\n else:\n return \"Not a string\"\n", "def repeat_it(string, n):\n print(string, n)\n return string * n if type(string) == str else \"Not a string\"", "def repeat_it(string,n):\n try:\n string + \" \"\n except:\n return \"Not a string\"\n \n return string * n", "def repeat_it(string, n):\n# print(string, n)\n if isinstance(string, str):\n return string * n\n else:\n return \"Not a string\"", "def repeat_it(s,n):\n if type(s) == str:\n return s * n\n else:\n return \"Not a string\"", "def repeat_it(string,n):\n if type(string) is not str : return \"Not a string\"\n result = \"\"\n for _ in range(0, n): \n result += string\n return result", "def repeat_it(string,n):\n #your code here\n return \"Not a string\" if type(string) is not str else string * n \n \nprint(repeat_it(\"abc\", 3))", "def repeat_it(s,n):\n return s*n if type(s)==type(str(s)) else \"Not a string\"", "def repeat_it(s, n):\n if isinstance(s, str) and s: return s * n\n else: return 'Not a string'", "repeat_it = lambda x,y: x*y if type(x) == str else 'Not a string'", "def repeat_it(string,n):\n str_ = ''\n \n if not isinstance(string, str):\n return \"Not a string\"\n \n for i in range(n):\n str_ = str_+string\n \n return str_", "def repeat_it(s,n):\n if type(s)==str: return s*n\n return 'Not a string'", "def repeat_it(string,n):\n #your code her\n return n*string if type(string)==type('=') else \"Not a string\"", "def repeat_it(string: str,n: int) -> str:\n if not isinstance(string, str):\n return 'Not a string'\n return string * n", "def repeat_it(a,b):\n if type(a)==str and type(b)==int:\n return(a*b)\n else:\n return(\"Not a string\")", "def repeat_it(string,n):\n return str(string*n if isinstance(string, str) else 'Not a string')", "def repeat_it(string,n):\n if isinstance(string, int) or isinstance(string, float) or isinstance(string, dict) or isinstance(string, list):\n return \"Not a string\"\n return string * n", "def repeat_it(string,n):\n if type(string) is str:\n return n * string\n else:\n return 'Not a string'", "def repeat_it(s,n):\n if type(s) == str:\n x=1\n st=''\n while x<=n:\n st += s\n x += 1\n return st\n else:\n return \"Not a string\"\n#Completed by Ammar on 25/8/2019 at 12:07AM.\n", "def repeat_it(string,n):\n return string*n if isinstance(string,str) else 'Not a string' #I solved this Kata on 8/23/2019 01:11 AM...#Hussam'sCodingDiary", "def repeat_it(string,n):\n tipus = type(string)\n print((\"==>> \",string,n,tipus))\n if tipus == str:\n output = string * n\n return output\n else:\n return \"Not a string\"\n\n", "def repeat_it(string,n):\n try:\n if string*n == str(string)*n:\n return string*n\n else:\n return \"Not a string\"\n except:\n return \"Not a string\"", "def repeat_it(string,n):\n try:\n if len(string) > 0:\n return string * n\n else:\n return 'Not a string'\n except TypeError:\n return 'Not a string'", "def repeat_it(string,n):\n if type(string) is not str:\n return \"Not a string\"\n text = \"\"\n for i in range(n):\n text += string\n return text", "def repeat_it(string,n):\n if string.__class__()!='':\n return 'Not a string'\n return string*n", "def repeat_it(string,n):\n if string != str(string):\n return \"Not a string\"\n return string*n", "def repeat_it(string,n):\n return \"Not a string\" if not isinstance(string, str) else string + repeat_it(string,n-1) if n else \"\" "]
{"fn_name": "repeat_it", "inputs": [["*", 3], ["Hello", 11], ["243624", 22], [[], 3], [24, 3], [true, 3], ["Hello", 0]], "outputs": [["***"], ["HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello"], ["243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624243624"], ["Not a string"], ["Not a string"], ["Not a string"], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
13,441
def repeat_it(string,n):
41bf9a5c8cf037f78d421e4788e9772a
UNKNOWN
Write a function that takes a single array as an argument (containing multiple strings and/or positive numbers and/or arrays), and returns one of four possible string values, depending on the ordering of the lengths of the elements in the input array: Your function should return... - “Increasing” - if the lengths of the elements increase from left to right (although it is possible that some neighbouring elements may also be equal in length) - “Decreasing” - if the lengths of the elements decrease from left to right (although it is possible that some neighbouring elements may also be equal in length) - “Unsorted” - if the lengths of the elements fluctuate from left to right - “Constant” - if all element's lengths are the same. Numbers and Strings should be evaluated based on the number of characters or digits used to write them. Arrays should be evaluated based on the number of elements counted directly in the parent array (but not the number of elements contained in any sub-arrays). Happy coding! :)
["def order_type(arr):\n if not arr : return 'Constant'\n arr = list( map(len, [str(elt) if type(elt)==int else elt for elt in arr] ))\n cmp =sorted(arr)\n if arr == [arr[0]]*len(arr) : s='Constant'\n elif arr == cmp : s='Increasing'\n elif arr == cmp[::-1] : s='Decreasing'\n else : s='Unsorted'\n return s", "def order_type(arr):\n xs = [len(x) if hasattr(x, '__len__') else len(str(x)) for x in arr]\n ys = sorted(xs)\n return (\n 'Constant' if not xs or ys[0] == ys[-1] else\n 'Increasing' if xs == ys else\n 'Decreasing' if xs[::-1] == ys else\n 'Unsorted'\n )", "def order_type(arr):\n lengths = [len(e if isinstance(e, list) else str(e)) for e in arr]\n if len(set(lengths)) < 2:\n return \"Constant\"\n inc = sorted(lengths)\n return \"Increasing\" if inc == lengths else \"Decreasing\" if inc[::-1] == lengths else \"Unsorted\"", "from operator import le, ge\n\nsize = lambda x: len(str(x)) if type(x) == int else len(x)\n \ndef order_type(arr):\n L = list(map(size, arr))\n if len(set(L)) <= 1: return \"Constant\"\n if all(map(le, L, L[1:])): return \"Increasing\"\n if all(map(ge, L, L[1:])): return \"Decreasing\"\n return \"Unsorted\"", "from itertools import tee\n\ndef pairwise(iterable):\n a, b = tee(iterable)\n next(b, None)\n return zip(a, b)\n\ndef length(value):\n try:\n return len(value)\n except TypeError:\n return len(str(value))\n\ndef order_type(values):\n if len(values) <= 1:\n return 'Constant'\n deltas = [length(b) - length(a) for a, b in pairwise(values)]\n min_delta = min(deltas)\n max_delta = max(deltas)\n if min_delta == max_delta == 0:\n return 'Constant'\n if min_delta >= 0 and max_delta >= 0:\n return 'Increasing'\n if min_delta <= 0 and max_delta <= 0:\n return 'Decreasing'\n return 'Unsorted'", "def order_type(arr):\n len_stats = [len(str(x)) if type(x) == int else len(x) for x in arr]\n sorted_stats = sorted(len_stats)\n \n if not arr or sorted_stats[0] == sorted_stats[-1]:\n return \"Constant\"\n \n if len_stats == sorted_stats:\n return \"Increasing\"\n \n return \"Decreasing\" if len_stats == sorted_stats[::-1] else \"Unsorted\"", "def order_type(arr):\n l = [len(str(e)) if type(e) != list else len(e) for e in arr]\n return 'Constant' if len(set(l)) <= 1 else 'Increasing' if l == sorted(l) else 'Decreasing' if l == sorted(l)[::-1] else 'Unsorted'", "def order_type(arr):\n l = [len(str(i))if type(i)==int else len(i)for i in arr]\n return [[\"Decreasing\",\"Unsorted\"][l!=sorted(l)[::-1]],[\"Increasing\",\"Constant\"][len(set(l))<2]][sorted(l)==l]", "from collections import OrderedDict\ndef order_type(arr):\n res = OrderedDict([ \n (\"Constant\", True),\n (\"Increasing\", True),\n (\"Decreasing\", True),\n (\"Unsorted\", True)\n ])\n\n def get_length(element):\n try:\n return len(element)\n except:\n return len(str(element))\n\n for first, second in zip(arr, arr[1:]):\n length_of_first = get_length(first)\n length_of_second = get_length(second)\n if length_of_first > length_of_second:\n res[\"Increasing\"] = False\n res[\"Constant\"] = False\n if length_of_first < length_of_second:\n res[\"Decreasing\"] = False\n res[\"Constant\"] = False\n for k in res:\n if res[k]:\n return k"]
{"fn_name": "order_type", "inputs": [[[1, "b", ["p"], 2]], [[123, 1234, 12345, 123456]], [["a", "abc", "abcde", "ab"]], [[[1, 2, 3, 4], [5, 6, 7], [8, 9]]], [[1, 2, 3, 4, 56]], [[["ab", "cdef", "g"], ["hi", "jk", "lmnopq"], ["rst", "uv", "wx"], ["yz"]]], [[[1, 23, 456, 78910], ["abcdef", "ghijklmno", "pqrstuvwxy"], [[1, 23, 456, 78910, ["abcdef", "ghijklmno", "pqrstuvwxy"]], 1234]]], [[]], [["pippi", "pippi", "batuffulo", "pippi"]], [["pippi"]]], "outputs": [["Constant"], ["Increasing"], ["Unsorted"], ["Decreasing"], ["Increasing"], ["Decreasing"], ["Decreasing"], ["Constant"], ["Unsorted"], ["Constant"]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,541
def order_type(arr):
4452938ac724d7fa47b59e507cb46975
UNKNOWN
`Description:` Given an input array (`arr`) of positive integers, the objective is to return an output array where each index represents the amount of times an element appeared (frequency) in the input array. More specifically, the element at each index of the output array will be an array (bucket) containing integers that appeared index-amount-of-times. Otherwise, slot nulls (JavaScript, Java), None's (Python) nils (Ruby), or NULL's (C/C++) where appropriate. A valid array will always be provided. If an array of [1,2,3,4,4,5,5,5] is passed in, the expected output should be: [null, [1,2,3], [4], [5], null, null, null, null, null]. `Explanation:` ```python # bucketize(arr) ======> outputArray bucketize(1,2,3,4,4,5,5,5) ======> [None, [1, 2, 3], [4], [5], None, None, None, None, None] ``` An element cannot appear 0 times, so a null is placed at outputArray[0]. The elements 1, 2, and 3 appear once. This is why they are located at outputArray[1]. Notice the elements are grouped together in an array and sorted in ascending order. The element 4 appears twice. This is why it is located at outputArray[2]. The element 5 appears three times. This is why it is located at outputArray[3]. Although an integer could have possibly appeared four, five, six, seven, or eight times, this is not the case for this particular example. This is the reason why the elements at outputArray[4], outputArray[5], outputArray[6], outputArray[7], and outputArray[8] are all null values. `Examples:` ```python bucketize(2,2,4,4,6,6,9,9,9,9) ==> [None, None, [2,4,6], None, [9], None, None, None, None, None, None] bucketize(3,3,3,3,2) ============> [None, [2], None, None, [3], None] bucketize(5,5,5,5,5) ============> [None, None, None, None, None, [5]] bucketize(77,3,40,40,40) ========> [None, [3,77], None, [40], None, None] bucketize(16,7,5,3,6,23) ========> [None, [3,5,6,7,16,23], None, None, None, None, None] ```
["from collections import Counter\n\ndef bucketize(*arr):\n c = Counter(arr)\n c = {i: sorted([k for k, v in list(c.items()) if v == i]) for i in list(c.values())}\n return [c[e] if e in c else None for e in range(len(arr) + 1)]\n", "from collections import Counter\n\ndef bucketize(*a):\n D = {}\n for k,v in Counter(a).items():\n D[v] = sorted(D.get(v, []) + [k])\n return [D.get(i, None) for i in range(len(a)+1)]", "from collections import Counter\nfrom bisect import insort\n\ndef bucketize(*arr):\n c = Counter(arr)\n xs = [None] * (len(arr) + 1)\n for key, cnt in c.items():\n if xs[cnt] is None:\n xs[cnt] = []\n insort(xs[cnt], key)\n return xs", "def bucketize(*arr):\n d = {}\n for i in set(arr):\n r = arr.count(i)\n d[r] = d.get(r, []) + [i]\n return [sorted(d.get(i,None) or [])or None for i in range(len(arr) + 1)]", "def bucketize(*arr):\n bucket = (1+len(arr)) * [None]\n for x in sorted(set(arr)):\n l = bucket[arr.count(x)]\n if l is None:\n bucket[arr.count(x)] = []\n bucket[arr.count(x)].append(x)\n return bucket", "from collections import Counter\ndef bucketize(*arr):\n r=[None]*(len(arr)+1)\n c=Counter(arr)\n for k in sorted(c.keys()):\n v=c[k]\n if r[v]:\n r[v].append(k)\n else:\n r[v]=[k]\n return r", "from collections import Counter\n\ndef bucketize(*args):\n r = [None] * (len(args) + 1)\n for x, y in sorted(Counter(args).items()):\n if r[y] is None:\n r[y] = []\n r[y].append(x)\n return r", "from collections import Counter\n\ndef bucketize(*arr):\n result, arr_count = [None]*(len(arr) + 1), Counter(arr)\n for count in set(arr_count.values()):\n result[count] = sorted(v for v, c in arr_count.items() if c == count)\n return result", "def bucketize(*args):\n d = {i:[] for i in range(len(args)+1)}\n for x in sorted(set(args)):\n d[args.count(x)].append(x)\n return [i if i else None for i in d.values()]", "from collections import Counter\n\ndef bucketize(*arr):\n c = Counter(arr)\n return [sorted(k for k,v in c.items() if v==i) if i in c.values() else None for i in range(len(arr)+1)]"]
{"fn_name": "bucketize", "inputs": [[2, 2, 4, 4, 6, 6, 9, 9, 9, 9], [3, 3, 3, 3, 2], [5, 5, 5, 5, 5], [77, 3, 40, 40, 40], [16, 7, 5, 3, 6, 23]], "outputs": [[[null, null, [2, 4, 6], null, [9], null, null, null, null, null, null]], [[null, [2], null, null, [3], null]], [[null, null, null, null, null, [5]]], [[null, [3, 77], null, [40], null, null]], [[null, [3, 5, 6, 7, 16, 23], null, null, null, null, null]]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,281
def bucketize(*arr):
e10aa6bc0fb4390a76f1f45e2fd18409
UNKNOWN
You are given a list/array which contains only integers (positive and negative). Your job is to sum only the numbers that are the same and consecutive. The result should be one list. Extra credit if you solve it in one line. You can assume there is never an empty list/array and there will always be an integer. Same meaning: 1 == 1 1 != -1 #Examples: ``` [1,4,4,4,0,4,3,3,1] # should return [1,12,0,4,6,1] """So as you can see sum of consecutives 1 is 1 sum of 3 consecutives 4 is 12 sum of 0... and sum of 2 consecutives 3 is 6 ...""" [1,1,7,7,3] # should return [2,14,3] [-5,-5,7,7,12,0] # should return [-10,14,12,0] ```
["from itertools import groupby\n\ndef sum_consecutives(s):\n return [sum(group) for c, group in groupby(s)]", "def sum_consecutives(s):\n prev = None\n x = []\n for i in s:\n if i == prev:\n x[-1] += i\n else:\n x.append(i)\n prev = i\n return x", "from itertools import groupby\n\n\ndef sum_consecutives(nums):\n return [sum(g) for _, g in groupby(nums)]\n", "def sum_consecutives(s):\n n,a = [s[0]],s[0]\n for i in range(1,len(s)):\n if s[i] != a:\n n.append(s[i])\n a = s[i]\n elif s[i] == a:\n n[-1] += a\n return n", "def sum_consecutives(s):\n res = []\n last = None\n for n in s:\n if n != last:\n res.append(n)\n last = n\n else:\n res[-1] += n\n return res", "from itertools import groupby\n\ndef sum_consecutives(s):\n return [sum(grp) for _, grp in groupby(s)]", "from itertools import groupby\n\ndef sum_consecutives(xs):\n return [sum(g) for _, g in groupby(xs)]", "def sum_consecutives(s, i=0):\n ret , s = [], s+['']\n while i<len(s)-1:\n x = sims(s, i, s[i])\n ret.append(x[0])\n i = x[1]\n return ret \n \ndef sims(arr,i, sm):\n while arr[i] == arr[i+1]:\n i += 1\n sm += arr[i]\n return sm, i+1\n", "from itertools import groupby\n\n\ndef sum_consecutives(lst):\n return [sum(g) for _, g in groupby(lst)]", "import itertools\n\ndef sum_consecutives(s):\n return [sum(num) for g, num in itertools.groupby(s)]"]
{"fn_name": "sum_consecutives", "inputs": [[[1, 4, 4, 4, 0, 4, 3, 3, 1]], [[1, 1, 7, 7, 3]], [[-5, -5, 7, 7, 12, 0]], [[3, 3, 3, 3, 1]], [[2, 2, -4, 4, 5, 5, 6, 6, 6, 6, 6, 1]], [[1, 1, 1, 1, 1, 3]], [[1, -1, -2, 2, 3, -3, 4, -4]], [[0, 1, 1, 2, 2]]], "outputs": [[[1, 12, 0, 4, 6, 1]], [[2, 14, 3]], [[-10, 14, 12, 0]], [[12, 1]], [[4, -4, 4, 10, 30, 1]], [[5, 3]], [[1, -1, -2, 2, 3, -3, 4, -4]], [[0, 2, 4]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,569
def sum_consecutives(s):
cad00c6cab7d1559476e660cfd4bb7ff
UNKNOWN
In this Kata, you will be given two strings `a` and `b` and your task will be to return the characters that are not common in the two strings. For example: ```Haskell solve("xyab","xzca") = "ybzc" --The first string has 'yb' which is not in the second string. --The second string has 'zc' which is not in the first string. ``` Notice also that you return the characters from the first string concatenated with those from the second string. More examples in the tests cases. Good luck! Please also try [Simple remove duplicates](https://www.codewars.com/kata/5ba38ba180824a86850000f7)
["def solve(a,b):\n s = set(a)&set(b)\n return ''.join(c for c in a+b if c not in s)", "def solve(a,b):\n return \"\".join([c for c in a if not c in b]+[c for c in b if not c in a])", "def solve(a,b):\n unique=[]\n for i in a:\n if i not in b:\n unique.append(i)\n for i in b:\n if i not in a:\n unique.append(i)\n \n return \"\".join(unique) ", "def solve(a,b):\n res = \"\"\n for char in a + b:\n if char in a and char in b: continue\n res += char\n return res", "def solve(a, b):\n return \"\".join(c for c in a + b if c in set(a) ^ set(b))", "def solve(left, right):\n result = ''\n for char in left:\n if char not in right:\n result += char\n for char in right:\n if char not in left:\n result += char\n return result\n", "\ndef solve(a,b):\n string = a+b\n return ''.join([i for i in a if i not in b] + [i for i in b if i not in a])", "def solve(a,b):\n string = \"\"\n for i in a:\n if i not in b:\n string = string + i\n for i in b:\n if i not in a:\n string = string + i\n return string\n", "solve=lambda a,b:a.translate(str.maketrans(\"\",\"\",b))+b.translate(str.maketrans(\"\",\"\",a))", "def solve(a,b):\n\n e = [i for i in a if i not in b]\n f = [i for i in b if i not in a]\n\n return \"\".join(e) + \"\".join(f)"]
{"fn_name": "solve", "inputs": [["xyab", "xzca"], ["xyabb", "xzca"], ["abcd", "xyz"], ["xxx", "xzca"]], "outputs": [["ybzc"], ["ybbzc"], ["abcdxyz"], ["zca"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,441
def solve(a,b):
9303bdecc79e2bb61dcd2e243360fdff
UNKNOWN
You're looking through different hex codes, and having trouble telling the difference between #000001 and #100000 We need a way to tell which is red, and which is blue! That's where you create ```hex_color()```! It should read an RGB input, and return whichever value (red, blue, or green) is of greatest concentration! But, if multiple colors are of equal concentration, you should return their mix! ```python red + blue = magenta green + red = yellow blue + green = cyan red + blue + green = white ``` One last thing, if the string given is empty, or has all 0's, return black! Examples: ```python hex_color('087 255 054') == 'green' hex_color('181 181 170') == 'yellow' hex_color('000 000 000') == 'black' hex_color('001 001 001') == 'white' ```
["colors = {\n (1, 0, 0): 'red',\n (0, 1, 0): 'green',\n (0, 0, 1): 'blue',\n (1, 0, 1): 'magenta',\n (1, 1, 0): 'yellow',\n (0, 1, 1): 'cyan',\n (1, 1, 1): 'white',\n}\n\ndef hex_color(codes):\n codes = codes or '0 0 0'\n items = [int(c) for c in codes.split()]\n m = max(items)\n return colors[tuple(i == m for i in items)] if m else 'black'\n", "_COLORS = ['black', 'blue', 'green', 'cyan', 'red', 'magenta', 'yellow', 'white']\n\ndef hex_color(codes):\n colors = [int(color) for color in (codes or '0 0 0').split()]\n index = int(''.join('1' if color and color == max(colors) else '0' for color in colors), 2)\n return _COLORS[index]", "color_map = {0:\"black\", 1:\"red\", 2:\"green\", 3:\"yellow\", 4:\"blue\", 5:\"magenta\", 6:\"cyan\", 7:\"white\"}\n\ndef hex_color(codes):\n values, brightest, color, i = [], 0, 0, 0\n if not codes: codes = \"000 000 000\"\n for code in codes.split(\" \"):\n value = int(code)\n if value > brightest: \n brightest = value\n color = 2**i\n elif value == brightest != 0:\n color += 2**i\n i += 1\n return color_map[color]", "def hex_color(codes):\n if codes in ('', '000 000 000'):\n return 'black'\n r, g, b = (int(color) for color in codes.split())\n if r == g == b: return 'white'\n if r > g and r > b: return 'red'\n if g > r and g > b: return 'green' \n if b > r and b > g: return 'blue'\n if r == b: return 'magenta'\n if g == r: return 'yellow'\n if b == g: return 'cyan'", "colors = {1: \"red\", 2: \"green\", 4: \"blue\", 3: \"yellow\", 5: \"magenta\", 6: \"cyan\", 7: \"white\"}\n\ndef hex_color(codes):\n codes = [int(code) for code in codes.split()]\n most = max(codes, default=0)\n return colors[sum(2**i for i, code in enumerate(codes) if code == most)] if most else \"black\"\n", "def hex_color(s):\n a, b, c = [int(x) for x in s.split() or [0, 0, 0]]\n for n, r in [(0, \"black\"), (c, \"white\")]:\n if a == b == c == n:\n return r\n m = max(a, b, c)\n if m == a == b: return \"yellow\"\n if m == a == c: return \"magenta\"\n if m == b == c: return \"cyan\"\n return \"red\" if m == a else \"green\" if m == b else \"blue\"", "def hex_color(codes):\n if codes == '': return 'black'\n r,g,b = map(int,codes.split(' '))\n if 0 == r == g == b: return 'black'\n if r == g == b: return 'white'\n if r > g and r > b: return 'red'\n if g > r and g > b: return 'green'\n if b > g and b > r: return 'blue'\n if r > g and r == b: return 'magenta'\n if r > b and r == g: return 'yellow'\n if b > r and b == g: return 'cyan'", "def hex_color(codes):\n try:\n r, g, b = (int(a) for a in codes.split())\n except ValueError:\n return 'black'\n if r == g == b:\n return 'black' if r == 0 else 'white'\n if r > g and r > b:\n return 'red'\n elif g > r and g > b:\n return 'green'\n elif b > r and b > g:\n return 'blue'\n elif r == g:\n return 'yellow'\n elif g == b:\n return 'cyan'\n elif b == r:\n return 'magenta'", "def hex_color(codes):\n if codes == \"\": return 'black'\n r_, g_, b_ = map(int, codes.split())\n r, g, b, = max(r_, g_, b_)==r_, max(r_, g_, b_)==g_, max(r_, g_, b_)==b_\n \n if (r_, g_, b_) == (0, 0, 0):\n return 'black'\n elif r and g and b: return 'white'\n elif r and g: return 'yellow'\n elif r and b: return 'magenta'\n elif g and b: return 'cyan'\n elif r: return 'red'\n elif g: return 'green'\n elif b: return 'blue'", "def hex_color(codes):\n r,g,b = [ int(hex) for hex in (codes.split(' ') if codes != '' else '000') ]\n m = max(r,g,b)\n return ['black','red','green','yellow','blue','magenta','cyan','white'][(m>0) * ( 1*(r==m) + 2*(g==m) + 4*(b==m) )]"]
{"fn_name": "hex_color", "inputs": [[""], ["000 000 000"], ["121 245 255"], ["027 100 100"], ["021 021 021"], ["255 000 000"], ["000 147 000"], ["212 103 212"], ["101 101 092"]], "outputs": [["black"], ["black"], ["blue"], ["cyan"], ["white"], ["red"], ["green"], ["magenta"], ["yellow"]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,026
def hex_color(codes):
f85c55302146608e0b34f35f657db0bb
UNKNOWN
Our football team finished the championship. The result of each match look like "x:y". Results of all matches are recorded in the collection. For example: ```["3:1", "2:2", "0:1", ...]``` Write a function that takes such collection and counts the points of our team in the championship. Rules for counting points for each match: - if x>y - 3 points - if x<y - 0 point - if x=y - 1 point Notes: - there are 10 matches in the championship - 0 <= x <= 4 - 0 <= y <= 4
["def points(games):\n count = 0\n for score in games:\n res = score.split(':')\n if res[0]>res[1]:\n count += 3\n elif res[0] == res[1]:\n count += 1\n return count", "def points(a):\n return sum((x >= y) + 2 * (x > y) for x, y in (s.split(\":\") for s in a))", "def points(games):\n count = 0\n for match in games:\n x = match.split(\":\")\n if x[0] > x[1]:\n count += 3\n elif x[0] == x[1]:\n count += 1\n return count", "def points(games):\n return sum([0,1,3][1+(g[0]>g[2])-(g[0]<g[2])] for g in games)", "def points(games):\n return sum(3 if x > y else 0 if x < y else 1 for x, y in (score.split(\":\") for score in games))", "def points(games):\n result = 0\n for item in games:\n result += 3 if item[0] > item[2] else 0 \n result += 1 if item[0] == item[2] else 0\n return result", "points = lambda g: sum((x>y)*3 or x==y for x,_,y in g)", "def points(games):\n sum=0\n for g in games:\n s=g.split(':')\n if(s[0]>s[1]):\n sum+=3\n elif(s[0] == s[1]):\n sum+=1\n return(sum)\n", "def points(games):\n def convert(game):\n x, y = int(game[0]), int(game[2])\n return 3 if x > y else 1 if x == y else 0\n return sum(convert(game) for game in games)", "def points(games): \n total = 0\n a = len(games) \n for i in range(0,a): \n a = games[i].split(':') \n if a[0] > a[1]: \n total = total + 3 \n if a[0] == a[1]: \n total = total + 1 \n if a[0] < a[1]: \n total = total + 0 \n return total\n", "points = lambda g: sum((x==y)+(x>y)*3 for x,_,y in g)", "def points(games):\n def score(x):\n if x[0] > x[2]:\n return 3\n elif x[0] < x[2]:\n return 0\n else:\n return 1\n return sum(score(x) for x in games)", "def score_game(x, y):\n if x > y:\n return 3\n if x < y:\n return 0\n return 1\n\ndef points(games):\n return sum(score_game(*game.split(':')) for game in games)\n", "def points(games):\n return sum(3*(x > y) + (x == y) for x, _, y in games)", "def points(arr):\n L = []\n for i in arr:\n L1 = i.split(\":\")\n if L1[0] > L1[1]:\n L.append(3)\n elif L1[0] < L1[1]:\n L.append(0)\n elif L1[0] == L1[1]:\n L.append(1)\n return sum(L)", "def points(games):\n \n points = 0\n \n for i in range (len(games)) :\n match = games[i]\n x = match[0]\n y = match[2]\n \n if x > y : points += 3\n elif x == y : points += 1\n \n return points\n\npoints(['1:0','2:0','3:0','4:0','2:1','3:1','4:1','3:2','4:2','4:3'])", "def points(games):\n points = 0\n for game in games:\n x = int(game[0])\n y = int(game[2])\n if x>y:\n points += 3\n elif x==y:\n points += 1\n return points", "def points(games):\n points = 0\n for i in range(len(games)):\n if games[i][0] > games[i][2]:\n points += 3\n elif games[i][0] == games[i][2]:\n points += 1\n return points", "def points(games):\n l=[]\n x=0\n z=0\n n=(' '.join(games))\n for i in n:\n if i!=' ' and i!=':':\n l.append(i)\n x+=1\n if x==2:\n if int(l[0])>int(l[1]):\n z+=3\n elif int(l[0])<int(l[1]):\n z+=0\n else:\n z+=1\n l.clear()\n x-=2 \n return z", "def points(games):\n pnts, lst = 0, [i for i in games]\n \n for j in range(len(lst)):\n if lst[j][0] > lst[j][2]:\n pnts += 3\n if lst[j][0] == lst[j][2]:\n pnts += 1\n\n return pnts", "points=lambda Q:sum(3*(V[0]>V[2])+(V[0]==V[2])for V in Q)", "points=lambda c:sum(3*(h>g)+(h==g)for h,_,g in c)\n", "def points(games):\n points = 0\n for a in games:\n if a[0] > a[2]: points += 3\n elif a[0] == a[2]: points += 1\n return points", "def points(games):\n # good solution without condition ))))\n count = 0\n for i in games:\n if int(i[0]) > int(i[2]):\n count += 3\n elif int(i[0]) == int(i[2]):\n count += 1\n \n return count", "def points(games):\n pts = 0\n for i in games:\n if i[0] > i[2]:\n pts += 3\n elif i[0] == i[2]:\n pts += 1\n return pts\n", "points = lambda games: sum([ 3 if g[0] > g[-1] else 1 if g[0] == g[-1] else 0 for g in games ])\n", "def points(games):\n return sum( (x>=y)*(1+2*(x>y)) for x,y in map(lambda s: s.split(':'), games) )", "def points(games):\n return sum(3 if x[0] > x[2] else 0 if x[0] < x[2] else 1 for x in games)", "def points(games):\n diff = map(lambda x: int(x[0]) - int(x[-1]), games) # goal difference\n wins = map(lambda x: 3 if x > 0 else x, diff) # change wins to 3 points\n return sum(list(map(lambda x: 1 if x == 0 else x * (x > 0), wins))) # change draws and losses to 1 and 0 points", "def points(games):\n points = 0\n for game in games:\n x, y = game.split(\":\")\n points += [0, 1, 3][(x >= y) + (x > y)]\n return points", "from typing import List\n\ndef points(games: List[str]) -> int:\n \"\"\" Counts the points of the team in the championship. \"\"\"\n points = 0\n results = [(int(goals[0]), int(goals[1])) for goals in [score.split(\":\") for score in games]]\n for (scored_goals, lost_goals) in results:\n if scored_goals > lost_goals:\n points += 3\n elif scored_goals == lost_goals:\n points +=1\n return points", "def points(games):\n\n final = 0\n for score in games:\n x,y = score.split(\":\")\n if x > y:\n final += 3\n elif x == y:\n final += 1\n else:\n final + 0\n \n return final\n \n", "def points(games):\n def calculate(args): \n return 0 if args[1] > args[0] else (1 if args[1] == args[0] else 3)\n return sum([calculate(scores.split(':')) for scores in games])", "def points(games):\n points = 0\n\n for v in games:\n x = int(v[0])\n y = int(v[2])\n if x > y:\n points += 3\n elif x == y:\n points += 1\n\n return points", "def points(games):\n p = 0\n for game in games:\n x, y = game.split(':')\n p += 3 if x > y else 0 if x < y else 1\n return p\n", "def points(game_results):\n return sum(get_points(result) for result in game_results)\n\n\ndef get_points(result):\n left_score = int(result[0])\n right_score = int(result[-1])\n if left_score > right_score:\n return 3\n elif left_score < right_score:\n return 0\n elif left_score == right_score:\n return 1\n", "def points(games):\n sumx = 0\n for x in games:\n temp = x.split(':')\n if temp[0] == temp[1]:\n sumx += 1\n elif temp[0] > temp[1]:\n sumx += 3\n return sumx", "points=lambda games:sum(map(lambda p:3 if p[0]>p[2] else(1 if p[0]==p[2] else 0),games))", "def points(games):\n \n points = 0\n \n for game in games:\n x,y = game.split(':')\n if x > y: points += 3\n if x < y: points += 0\n if x == y: points += 1\n \n return points ", "import re\ndef points(games):\n match = re.findall(r'[0-9]', ''.join(games))\n p = 0\n for i in range(0, len(match), 2):\n if ord(match[i]) > ord(match[i + 1]): p += 3\n elif ord(match[i]) == ord(match[i + 1]): p += 1\n return p", "def points(games):\n return(sum([3 if (x > y) else 1 if (x == y) else 0 for (x, y) in (a.split(':') for a in games)]))\n", "def points(games):\n total_pts = 0\n\n for game in games:\n x, y = game.split(\":\")\n if x == y:\n total_pts += 1\n elif x > y:\n total_pts += 3\n \n return total_pts\n", "def points(scores):\n return sum([3 if s[0] > s[2] else 1 for s in scores if s[0] >= s[2]])", "def points(games):\n total = 0\n for x, _, y in games:\n if x > y: total += 3\n elif x == y: total += 1\n return total", "def points(games):\n res = 0\n for e in games:\n if e.split(':')[0] > e.split(':')[1]:\n res += 3\n elif e.split(':')[0] == e.split(':')[1]:\n res += 1\n return res", "def points(games):\n point=0\n for i in games:\n b=i.split(\":\")\n if int(b[0])>int(b[1]):\n point+=3\n elif int(b[0])<int(b[1]):\n point+=0\n elif int(b[0])==int(b[1]):\n point+=1\n return point\n", "def points(games):\n scores = (game.split(\":\") for game in games)\n return sum([0, 1, 3][(x >= y) + (x > y)] for x, y in scores)", "def points(games):\n\n g = 0\n\n for i in games:\n\n j = i.split(':')\n\n if j[0] > j[1]:\n g += 3\n\n elif j[0] == j[1]:\n g += 1\n\n return g\n", "def points(games):\n score = 0\n for x in games:\n if x[0] > x[2]:\n score += 3\n if x[0] == x[2]:\n score += 1\n print(score) \n return score \n", "def points(games):\n points = 0\n for each_str in games:\n x = int(each_str[0])\n y = int(each_str[2])\n if x > y:\n points += 3\n elif x == y:\n points += 1\n return points", "def points(games):\n points_res = 0\n for res_str in games:\n x = int(res_str[0])\n y = int(res_str[2])\n if x > y:\n points_res += 3\n elif x == y:\n points_res += 1\n return points_res\n", "def points(games):\n if not games:\n return 0\n x=games[0]\n if(int(x[0])>int(x[2])):\n return 3+points(games[1:])\n if(x[0]==x[2]):\n return 1+points(games[1:])\n return 0+points(games[1:])\n", "def points(games):\n result = 0\n for score in games:\n x, y = score.split(':')\n if x > y:\n result += 3\n if x == y:\n result += 1\n return result", "def points(games):\n score = 0\n for game in games :\n (x, y) = tuple(game.split(':'))\n if x > y :\n score+=3\n elif x==y :\n score+=1\n return score", "def points(games):\n si=0\n si= sum(3 if match[0]>match[2] else (1 if match[0]==match[2] else 0) for match in games) \n return si", "def points(games):\n points = 0\n \n for game in games:\n point = list(map(int, game.split(\":\")))\n if point[0] > point[1]:\n points += 3\n elif point[0] == point[1]:\n points += 1\n\n return points\n", "def points(games):\n count = 0\n for i in games:\n a,b = i.split(':')\n if a > b:\n count += 3\n elif a == b:\n count += 1\n else:\n continue\n \n return count \n \n", "def points(games):\n our_points = 0\n for game in games:\n if game[0] > game[2]:\n our_points = our_points + 3\n elif game[0] == game[2]:\n our_points = our_points + 1\n else:\n pass\n return our_points", "def points(games):\n points = 0\n for game in games:\n score = game.split(':')\n if score[0] > score[1]:\n points += 3\n elif score[0] == score[1]:\n points += 1\n return points", "def points(games):\n point = 0\n for score in games:\n x, y = map(int, score.split(':'))\n if x > y:\n point += 3\n elif x == y:\n point += 1\n return point"]
{"fn_name": "points", "inputs": [[["1:0", "2:0", "3:0", "4:0", "2:1", "3:1", "4:1", "3:2", "4:2", "4:3"]], [["1:1", "2:2", "3:3", "4:4", "2:2", "3:3", "4:4", "3:3", "4:4", "4:4"]], [["0:1", "0:2", "0:3", "0:4", "1:2", "1:3", "1:4", "2:3", "2:4", "3:4"]], [["1:0", "2:0", "3:0", "4:0", "2:1", "1:3", "1:4", "2:3", "2:4", "3:4"]], [["1:0", "2:0", "3:0", "4:4", "2:2", "3:3", "1:4", "2:3", "2:4", "3:4"]]], "outputs": [[30], [10], [0], [15], [12]]}
INTRODUCTORY
PYTHON3
CODEWARS
11,932
def points(games):
f8267498539980210317f7d649142a40
UNKNOWN
I've got a crazy mental illness. I dislike numbers a lot. But it's a little complicated: The number I'm afraid of depends on which day of the week it is... This is a concrete description of my mental illness: Monday --> 12 Tuesday --> numbers greater than 95 Wednesday --> 34 Thursday --> 0 Friday --> numbers divisible by 2 Saturday --> 56 Sunday --> 666 or -666 Write a function which takes a string (day of the week) and an integer (number to be tested) so it tells the doctor if I'm afraid or not. (return a boolean)
["def am_I_afraid(day,num):\n return {\n 'Monday': num == 12,\n 'Tuesday': num > 95,\n 'Wednesday': num == 34,\n 'Thursday': num == 0,\n 'Friday': num % 2 == 0,\n 'Saturday': num == 56,\n 'Sunday': num == 666 or num == -666,\n }[day]\n", "afraid = {\n 'Monday': lambda x: x == 12,\n 'Tuesday': lambda x: x > 95,\n 'Wednesday': lambda x: x == 34,\n 'Thursday': lambda x: x == 0,\n 'Friday': lambda x: x % 2 == 0,\n 'Saturday': lambda x: x == 56,\n 'Sunday': lambda x: abs(x) == 666,\n}\n\ndef am_I_afraid(day, num):\n return afraid[day](num)", "def am_I_afraid(day, x):\n return {'Mo': x == 12,\n 'Tu': x > 95,\n 'We': x == 34,\n 'Th': x == 0,\n 'Fr': x % 2 == 0,\n 'Sa': x == 56,\n 'Su': abs(x) == 666}[day[:2]]", "def am_I_afraid(day,num):\n if day==\"Monday\": return num==12\n if day==\"Tuesday\": return num>95\n if day==\"Wednesday\": return num==34\n if day==\"Thursday\": return num==0\n if day==\"Friday\": return num%2==0\n if day==\"Saturday\": return num==56\n if day==\"Sunday\": return num==666 or num==-666", "FUNCS = dict(zip('Monday Tuesday Wednesday Thursday Friday Saturday Sunday'.split(),\n (12..__eq__, \n 95..__lt__,\n 34..__eq__,\n 0..__eq__, \n lambda n: not n%2,\n 56..__eq__,\n lambda n: abs(n)==666)))\n\ndef am_I_afraid(day,n):\n return FUNCS[day](n)", "def am_I_afraid(day,num):\n #your code here\n rep = False\n lst1 = [('monday', 12), ('wednesday', 34), ('thursday', 0), ('saturday', 56), ('sunday', 666), ('sunday', -666)]\n\n input = (day.lower(), num) \n \n if input in lst1 or (input[0]=='tuesday' and input[1]>95) or (input[0]=='friday' and input[1]%2==0):\n rep = True\n return rep", "def am_I_afraid(day,num):\n return {'Monday' : num == 12, \n 'Tuesday' : num > 95, \n 'Wednesday' : num == 34, \n 'Thursday' : not num, \n 'Friday' : not (num % 2), \n 'Saturday' : num == 56, \n 'Sunday' : num == 666 or num == -666\n }[day]", "afraid = {\n \"Monday\": lambda n: n == 12,\n \"Tuesday\": lambda n: n > 95,\n \"Wednesday\": lambda n: n == 34,\n \"Thursday\": lambda n: n == 0,\n \"Friday\": lambda n: n % 2 == 0,\n \"Saturday\": lambda n: n == 56,\n \"Sunday\": lambda n: abs(n) == 666,\n}\n\ndef am_I_afraid(day, num):\n return afraid[day](num)", "def am_I_afraid(day, num):\n return {\"Monday\": num == 12,\n \"Tuesday\": num > 95,\n \"Wednesday\": num == 34,\n \"Thursday\": num == 0,\n \"Friday\": num % 2 == 0,\n \"Saturday\": num == 56,\n \"Sunday\": abs(num) == 666\n }[day]\n", "def am_I_afraid(day,num):\n if day == \"Monday\" and num == 12:\n return True\n if day == \"Tuesday\" and num > 95:\n return True\n if day == \"Wednesday\" and num == 34:\n return True\n if day == \"Thursday\" and num == 0:\n return True\n if day == \"Friday\" and num % 2 == 0:\n return True\n if day == \"Saturday\" and num == 56:\n return True\n if day == \"Sunday\" and abs(num) == 666:\n return True\n return False"]
{"fn_name": "am_I_afraid", "inputs": [["Monday", 13], ["Monday", 12], ["Tuesday", 0], ["Tuesday", 100], ["Tuesday", 95], ["Wednesday", 35], ["Wednesday", 34], ["Thursday", 2], ["Thursday", 0], ["Friday", 5], ["Friday", 4], ["Saturday", 55], ["Saturday", 56], ["Sunday", 55], ["Sunday", 666], ["Sunday", -666]], "outputs": [[false], [true], [false], [true], [false], [false], [true], [false], [true], [false], [true], [false], [true], [false], [true], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,463
def am_I_afraid(day,num):
16fb1d946f0fc044c99a5121412cfe46
UNKNOWN
The hamming distance of two equal-length strings is the number of positions, in which the two string differ. In other words, the number of character substitutions required to transform one string into the other. For this first Kata, you will write a function ```hamming_distance(a, b)``` with two equal-length strings containing only 0s and 1s as parameters. There is no need to test the parameters for validity (but you can, if you want).The function's output should be the hamming distance of the two strings as an integer. Example: ```python hamming_distance('100101', '101001') == 2 hamming_distance('1010', '0101') == 4 ```
["def hamming_distance(a, b):\n return sum(c != d for c, d in zip(a, b))\n", "def hamming_distance(a, b): return sum(ch1 != ch2 for ch1, ch2 in zip(a, b))", "def hamming_distance(a, b):\n result=0\n for i in range(len(a)):\n if a[i]!=b[i]:\n result+=1;\n return result;\n", "def hamming_distance(a, b): return sum(x != y for x, y in zip(a,b))", "def hamming_distance(a, b):\n return sum(y != x for y, x in zip(b, a))", "hamming_distance=lambda a,b:sum(1for x,y in zip(a,b)if x!=y)", "hamming_distance = lambda r, s: len([i for i in range(len(r)) if r[i] != s[i]])", "def hamming_distance(a, b):\n return sum(ca != cb for ca, cb in zip(a, b))", "def hamming_distance(a, b):\n return sum(b1 != b2 for b1, b2 in zip(a, b))", "def hamming_distance(a, b):\n return sum(abs(int(a[i]) - int(b[i])) for i in range(0, len(a)))\n \n \n"]
{"fn_name": "hamming_distance", "inputs": [["100101", "101001"], ["1010", "0101"], ["100101011011010010010", "101100010110010110101"]], "outputs": [[2], [4], [9]]}
INTRODUCTORY
PYTHON3
CODEWARS
883
def hamming_distance(a, b):
cc4d93a167d76e8327a0beadc3213e97
UNKNOWN
Given an array of one's and zero's that represents a positive binary number convert the number to two's complement value. Two's complement is the way most computers represent positive or negative integers. The most significant bit is negative. Examples: -8 4 2 1 [1,1,1,1] = -1 [1,0,0,0] = -8 [1,1,0,1] = -3 To get the two's complement negative notation of an integer, you take the number in binary. You then invert the digits, and add one to the result. For example: [0,0,1,0] = 2 in base 10 [1,1,0,1] <- Flip the bits Add 1 [1,1,1,0] = -2 However, the arrays can have varying lengths, not just limited to 4.
["def positive_to_negative(binary):\n return [1 - d if 1 in binary[i:] else d for i, d in enumerate(binary, 1)]\n", "def positive_to_negative(b):\n last = next((i for i in range(len(b) - 1, -1, -1) if b[i]), 0)\n return [1 - d for d in b[:last]] + b[last:]", "def positive_to_negative(arr):\n flip = [0 if n == 1 else 1 for n in arr]\n \n for i in range(len(flip)):\n if flip[-(i+1)] == 1:\n flip[-(i+1)] = 0\n else:\n flip[-(i+1)] = 1\n break\n return flip", "def positive_to_negative(binary):\n binary = [not i for i in binary] \n for i in range(len(binary)-1,-1,-1):\n if binary[i]:\n binary[i] = 0\n else:\n binary[i] = 1\n break \n \n return binary ", "def positive_to_negative(binary):\n flip = [int(not(e)) for e in binary]\n for i in range(len(flip)-1,-1,-1):\n if flip[i] == 0:\n flip[i] = 1\n break\n flip[i] = 0\n return flip", "def positive_to_negative(binary):\n b = []\n \n print(\"\uc6d0\ub798 \uc774\uc9c4\uc218 :\", binary)\n #range(1, 5) 1, 2, 3, 4\n for bit in binary:\n if bit == 1:\n b.append(0)\n else:\n b.append(1)\n print(\"1\uacfc 0 \ubc14\uafb8\uae30 :\", b)\n \n c = 1\n for i in range(len (b)):\n if b[-1-i] == 1 and c == 1:\n b[-1-i] = 0\n elif b[-1-i] == 0 and c == 1:\n c = 0\n b[-1-i] = 1\n else:\n pass \n \n \"\"\"\n b.reverse()\n print(\"\ubc30\uc5f4 \uc21c\uc11c \ubc14\uafb8\uae30 :\",b)\n \n c = 1\n for i in range(len (b)):\n if b[i] == 1 and c == 1:\n b[i] = 0\n elif b[i] == 0 and c == 1:\n c = 0\n b[i] = 1\n else:\n pass\n \n print(b)\n b.reverse() \"\"\"\n print(\"\ucd5c\uc885 :\",b)\n \n return b", "p = lambda b,c=1: [*p(b[:-1],1-b[-1]&c), 1-b[-1]^c] if len(b) else []\npositive_to_negative = p", "def positive_to_negative(b):\n return [int(d) for d in f\"{int(''.join(str(1 - d) for d in b), 2) + 1:b}\"] if 1 in b else b\n", "def positive_to_negative(binary):\n n = len(binary)\n end = 0\n for i in range(n - 1, -1, -1):\n if(binary[i] == 1):\n end = i\n break\n for i in range(end):\n binary[i] ^= 1\n return binary", "def positive_to_negative(binary):\n if sum(binary) == 0:\n return binary\n steps = []\n index = 0\n zero_counter = 0\n for bin_num in binary:\n if binary[index] == 0:\n zero_counter += 1\n binary[index] = 1\n elif binary[index] == 1:\n binary[index] = 0\n steps.append(0)\n\n index += 1\n fill = list(steps)\n fill[-1] = 1\n\n index = len(binary) - 1\n while index >= 0:\n if index != len(binary) -1:\n binary[index] += fill[index] + steps[index+1]\n else:\n binary[index] += fill[index]\n\n if binary[index] == 2:\n binary[index] -= 2\n steps[index] += 1\n\n index -= 1\n\n return binary"]
{"fn_name": "positive_to_negative", "inputs": [[[0, 0, 0, 0]], [[0, 0, 1, 0]], [[0, 0, 1, 1]], [[0, 1, 0, 0]]], "outputs": [[[0, 0, 0, 0]], [[1, 1, 1, 0]], [[1, 1, 0, 1]], [[1, 1, 0, 0]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,208
def positive_to_negative(binary):
5bfbd1ae7c417b3a0e2a74f1887e1381
UNKNOWN
Create a function that takes a Roman numeral as its argument and returns its value as a numeric decimal integer. You don't need to validate the form of the Roman numeral. Modern Roman numerals are written by expressing each decimal digit of the number to be encoded separately, starting with the leftmost digit and skipping any 0s. So 1990 is rendered "MCMXC" (1000 = M, 900 = CM, 90 = XC) and 2008 is rendered "MMVIII" (2000 = MM, 8 = VIII). The Roman numeral for 1666, "MDCLXVI", uses each letter in descending order. Example: ```python solution('XXI') # should return 21 ``` ```Elixir Solution.decode("XXI") # should return 21 ``` Help: ``` Symbol Value I 1 V 5 X 10 L 50 C 100 D 500 M 1,000 ``` *Courtesy of rosettacode.org*
["def solution(roman):\n dict = {\n \"M\": 1000,\n \"D\": 500,\n \"C\": 100,\n \"L\": 50,\n \"X\": 10,\n \"V\": 5,\n \"I\": 1\n }\n\n last, total = 0, 0\n for c in list(roman)[::-1]:\n if last == 0:\n total += dict[c]\n elif last > dict[c]:\n total -= dict[c]\n else:\n total += dict[c]\n last = dict[c]\n return total\n", "from functools import reduce\ndef solution(roman):\n d={'I':1, 'V':5 ,'X':10, 'L':50 ,'C':100, 'D':500,'M':1000}\n \n return reduce(lambda x,y: x+y if x>=y else y-x , (d[c] for c in roman))\n", "mapping = {\n 'C': 100,\n 'CC': 200,\n 'CCC': 300,\n 'CCCI': 301,\n 'CCCII': 302,\n 'CCCIII': 303,\n 'CCCIV': 304,\n 'CCCIX': 309,\n 'CCCL': 350,\n 'CCCLI': 351,\n 'CCCLII': 352,\n 'CCCLIII': 353,\n 'CCCLIV': 354,\n 'CCCLIX': 359,\n 'CCCLV': 355,\n 'CCCLVI': 356,\n 'CCCLVII': 357,\n 'CCCLVIII': 358,\n 'CCCLX': 360,\n 'CCCLXI': 361,\n 'CCCLXII': 362,\n 'CCCLXIII': 363,\n 'CCCLXIV': 364,\n 'CCCLXIX': 369,\n 'CCCLXV': 365,\n 'CCCLXVI': 366,\n 'CCCLXVII': 367,\n 'CCCLXVIII': 368,\n 'CCCLXX': 370,\n 'CCCLXXI': 371,\n 'CCCLXXII': 372,\n 'CCCLXXIII': 373,\n 'CCCLXXIV': 374,\n 'CCCLXXIX': 379,\n 'CCCLXXV': 375,\n 'CCCLXXVI': 376,\n 'CCCLXXVII': 377,\n 'CCCLXXVIII': 378,\n 'CCCLXXX': 380,\n 'CCCLXXXI': 381,\n 'CCCLXXXII': 382,\n 'CCCLXXXIII': 383,\n 'CCCLXXXIV': 384,\n 'CCCLXXXIX': 389,\n 'CCCLXXXV': 385,\n 'CCCLXXXVI': 386,\n 'CCCLXXXVII': 387,\n 'CCCLXXXVIII': 388,\n 'CCCV': 305,\n 'CCCVI': 306,\n 'CCCVII': 307,\n 'CCCVIII': 308,\n 'CCCX': 310,\n 'CCCXC': 390,\n 'CCCXCI': 391,\n 'CCCXCII': 392,\n 'CCCXCIII': 393,\n 'CCCXCIV': 394,\n 'CCCXCIX': 399,\n 'CCCXCV': 395,\n 'CCCXCVI': 396,\n 'CCCXCVII': 397,\n 'CCCXCVIII': 398,\n 'CCCXI': 311,\n 'CCCXII': 312,\n 'CCCXIII': 313,\n 'CCCXIV': 314,\n 'CCCXIX': 319,\n 'CCCXL': 340,\n 'CCCXLI': 341,\n 'CCCXLII': 342,\n 'CCCXLIII': 343,\n 'CCCXLIV': 344,\n 'CCCXLIX': 349,\n 'CCCXLV': 345,\n 'CCCXLVI': 346,\n 'CCCXLVII': 347,\n 'CCCXLVIII': 348,\n 'CCCXV': 315,\n 'CCCXVI': 316,\n 'CCCXVII': 317,\n 'CCCXVIII': 318,\n 'CCCXX': 320,\n 'CCCXXI': 321,\n 'CCCXXII': 322,\n 'CCCXXIII': 323,\n 'CCCXXIV': 324,\n 'CCCXXIX': 329,\n 'CCCXXV': 325,\n 'CCCXXVI': 326,\n 'CCCXXVII': 327,\n 'CCCXXVIII': 328,\n 'CCCXXX': 330,\n 'CCCXXXI': 331,\n 'CCCXXXII': 332,\n 'CCCXXXIII': 333,\n 'CCCXXXIV': 334,\n 'CCCXXXIX': 339,\n 'CCCXXXV': 335,\n 'CCCXXXVI': 336,\n 'CCCXXXVII': 337,\n 'CCCXXXVIII': 338,\n 'CCI': 201,\n 'CCII': 202,\n 'CCIII': 203,\n 'CCIV': 204,\n 'CCIX': 209,\n 'CCL': 250,\n 'CCLI': 251,\n 'CCLII': 252,\n 'CCLIII': 253,\n 'CCLIV': 254,\n 'CCLIX': 259,\n 'CCLV': 255,\n 'CCLVI': 256,\n 'CCLVII': 257,\n 'CCLVIII': 258,\n 'CCLX': 260,\n 'CCLXI': 261,\n 'CCLXII': 262,\n 'CCLXIII': 263,\n 'CCLXIV': 264,\n 'CCLXIX': 269,\n 'CCLXV': 265,\n 'CCLXVI': 266,\n 'CCLXVII': 267,\n 'CCLXVIII': 268,\n 'CCLXX': 270,\n 'CCLXXI': 271,\n 'CCLXXII': 272,\n 'CCLXXIII': 273,\n 'CCLXXIV': 274,\n 'CCLXXIX': 279,\n 'CCLXXV': 275,\n 'CCLXXVI': 276,\n 'CCLXXVII': 277,\n 'CCLXXVIII': 278,\n 'CCLXXX': 280,\n 'CCLXXXI': 281,\n 'CCLXXXII': 282,\n 'CCLXXXIII': 283,\n 'CCLXXXIV': 284,\n 'CCLXXXIX': 289,\n 'CCLXXXV': 285,\n 'CCLXXXVI': 286,\n 'CCLXXXVII': 287,\n 'CCLXXXVIII': 288,\n 'CCV': 205,\n 'CCVI': 206,\n 'CCVII': 207,\n 'CCVIII': 208,\n 'CCX': 210,\n 'CCXC': 290,\n 'CCXCI': 291,\n 'CCXCII': 292,\n 'CCXCIII': 293,\n 'CCXCIV': 294,\n 'CCXCIX': 299,\n 'CCXCV': 295,\n 'CCXCVI': 296,\n 'CCXCVII': 297,\n 'CCXCVIII': 298,\n 'CCXI': 211,\n 'CCXII': 212,\n 'CCXIII': 213,\n 'CCXIV': 214,\n 'CCXIX': 219,\n 'CCXL': 240,\n 'CCXLI': 241,\n 'CCXLII': 242,\n 'CCXLIII': 243,\n 'CCXLIV': 244,\n 'CCXLIX': 249,\n 'CCXLV': 245,\n 'CCXLVI': 246,\n 'CCXLVII': 247,\n 'CCXLVIII': 248,\n 'CCXV': 215,\n 'CCXVI': 216,\n 'CCXVII': 217,\n 'CCXVIII': 218,\n 'CCXX': 220,\n 'CCXXI': 221,\n 'CCXXII': 222,\n 'CCXXIII': 223,\n 'CCXXIV': 224,\n 'CCXXIX': 229,\n 'CCXXV': 225,\n 'CCXXVI': 226,\n 'CCXXVII': 227,\n 'CCXXVIII': 228,\n 'CCXXX': 230,\n 'CCXXXI': 231,\n 'CCXXXII': 232,\n 'CCXXXIII': 233,\n 'CCXXXIV': 234,\n 'CCXXXIX': 239,\n 'CCXXXV': 235,\n 'CCXXXVI': 236,\n 'CCXXXVII': 237,\n 'CCXXXVIII': 238,\n 'CD': 400,\n 'CDI': 401,\n 'CDII': 402,\n 'CDIII': 403,\n 'CDIV': 404,\n 'CDIX': 409,\n 'CDL': 450,\n 'CDLI': 451,\n 'CDLII': 452,\n 'CDLIII': 453,\n 'CDLIV': 454,\n 'CDLIX': 459,\n 'CDLV': 455,\n 'CDLVI': 456,\n 'CDLVII': 457,\n 'CDLVIII': 458,\n 'CDLX': 460,\n 'CDLXI': 461,\n 'CDLXII': 462,\n 'CDLXIII': 463,\n 'CDLXIV': 464,\n 'CDLXIX': 469,\n 'CDLXV': 465,\n 'CDLXVI': 466,\n 'CDLXVII': 467,\n 'CDLXVIII': 468,\n 'CDLXX': 470,\n 'CDLXXI': 471,\n 'CDLXXII': 472,\n 'CDLXXIII': 473,\n 'CDLXXIV': 474,\n 'CDLXXIX': 479,\n 'CDLXXV': 475,\n 'CDLXXVI': 476,\n 'CDLXXVII': 477,\n 'CDLXXVIII': 478,\n 'CDLXXX': 480,\n 'CDLXXXI': 481,\n 'CDLXXXII': 482,\n 'CDLXXXIII': 483,\n 'CDLXXXIV': 484,\n 'CDLXXXIX': 489,\n 'CDLXXXV': 485,\n 'CDLXXXVI': 486,\n 'CDLXXXVII': 487,\n 'CDLXXXVIII': 488,\n 'CDV': 405,\n 'CDVI': 406,\n 'CDVII': 407,\n 'CDVIII': 408,\n 'CDX': 410,\n 'CDXC': 490,\n 'CDXCI': 491,\n 'CDXCII': 492,\n 'CDXCIII': 493,\n 'CDXCIV': 494,\n 'CDXCIX': 499,\n 'CDXCV': 495,\n 'CDXCVI': 496,\n 'CDXCVII': 497,\n 'CDXCVIII': 498,\n 'CDXI': 411,\n 'CDXII': 412,\n 'CDXIII': 413,\n 'CDXIV': 414,\n 'CDXIX': 419,\n 'CDXL': 440,\n 'CDXLI': 441,\n 'CDXLII': 442,\n 'CDXLIII': 443,\n 'CDXLIV': 444,\n 'CDXLIX': 449,\n 'CDXLV': 445,\n 'CDXLVI': 446,\n 'CDXLVII': 447,\n 'CDXLVIII': 448,\n 'CDXV': 415,\n 'CDXVI': 416,\n 'CDXVII': 417,\n 'CDXVIII': 418,\n 'CDXX': 420,\n 'CDXXI': 421,\n 'CDXXII': 422,\n 'CDXXIII': 423,\n 'CDXXIV': 424,\n 'CDXXIX': 429,\n 'CDXXV': 425,\n 'CDXXVI': 426,\n 'CDXXVII': 427,\n 'CDXXVIII': 428,\n 'CDXXX': 430,\n 'CDXXXI': 431,\n 'CDXXXII': 432,\n 'CDXXXIII': 433,\n 'CDXXXIV': 434,\n 'CDXXXIX': 439,\n 'CDXXXV': 435,\n 'CDXXXVI': 436,\n 'CDXXXVII': 437,\n 'CDXXXVIII': 438,\n 'CI': 101,\n 'CII': 102,\n 'CIII': 103,\n 'CIV': 104,\n 'CIX': 109,\n 'CL': 150,\n 'CLI': 151,\n 'CLII': 152,\n 'CLIII': 153,\n 'CLIV': 154,\n 'CLIX': 159,\n 'CLV': 155,\n 'CLVI': 156,\n 'CLVII': 157,\n 'CLVIII': 158,\n 'CLX': 160,\n 'CLXI': 161,\n 'CLXII': 162,\n 'CLXIII': 163,\n 'CLXIV': 164,\n 'CLXIX': 169,\n 'CLXV': 165,\n 'CLXVI': 166,\n 'CLXVII': 167,\n 'CLXVIII': 168,\n 'CLXX': 170,\n 'CLXXI': 171,\n 'CLXXII': 172,\n 'CLXXIII': 173,\n 'CLXXIV': 174,\n 'CLXXIX': 179,\n 'CLXXV': 175,\n 'CLXXVI': 176,\n 'CLXXVII': 177,\n 'CLXXVIII': 178,\n 'CLXXX': 180,\n 'CLXXXI': 181,\n 'CLXXXII': 182,\n 'CLXXXIII': 183,\n 'CLXXXIV': 184,\n 'CLXXXIX': 189,\n 'CLXXXV': 185,\n 'CLXXXVI': 186,\n 'CLXXXVII': 187,\n 'CLXXXVIII': 188,\n 'CM': 900,\n 'CMI': 901,\n 'CMII': 902,\n 'CMIII': 903,\n 'CMIV': 904,\n 'CMIX': 909,\n 'CML': 950,\n 'CMLI': 951,\n 'CMLII': 952,\n 'CMLIII': 953,\n 'CMLIV': 954,\n 'CMLIX': 959,\n 'CMLV': 955,\n 'CMLVI': 956,\n 'CMLVII': 957,\n 'CMLVIII': 958,\n 'CMLX': 960,\n 'CMLXI': 961,\n 'CMLXII': 962,\n 'CMLXIII': 963,\n 'CMLXIV': 964,\n 'CMLXIX': 969,\n 'CMLXV': 965,\n 'CMLXVI': 966,\n 'CMLXVII': 967,\n 'CMLXVIII': 968,\n 'CMLXX': 970,\n 'CMLXXI': 971,\n 'CMLXXII': 972,\n 'CMLXXIII': 973,\n 'CMLXXIV': 974,\n 'CMLXXIX': 979,\n 'CMLXXV': 975,\n 'CMLXXVI': 976,\n 'CMLXXVII': 977,\n 'CMLXXVIII': 978,\n 'CMLXXX': 980,\n 'CMLXXXI': 981,\n 'CMLXXXII': 982,\n 'CMLXXXIII': 983,\n 'CMLXXXIV': 984,\n 'CMLXXXIX': 989,\n 'CMLXXXV': 985,\n 'CMLXXXVI': 986,\n 'CMLXXXVII': 987,\n 'CMLXXXVIII': 988,\n 'CMV': 905,\n 'CMVI': 906,\n 'CMVII': 907,\n 'CMVIII': 908,\n 'CMX': 910,\n 'CMXC': 990,\n 'CMXCI': 991,\n 'CMXCII': 992,\n 'CMXCIII': 993,\n 'CMXCIV': 994,\n 'CMXCIX': 999,\n 'CMXCV': 995,\n 'CMXCVI': 996,\n 'CMXCVII': 997,\n 'CMXCVIII': 998,\n 'CMXI': 911,\n 'CMXII': 912,\n 'CMXIII': 913,\n 'CMXIV': 914,\n 'CMXIX': 919,\n 'CMXL': 940,\n 'CMXLI': 941,\n 'CMXLII': 942,\n 'CMXLIII': 943,\n 'CMXLIV': 944,\n 'CMXLIX': 949,\n 'CMXLV': 945,\n 'CMXLVI': 946,\n 'CMXLVII': 947,\n 'CMXLVIII': 948,\n 'CMXV': 915,\n 'CMXVI': 916,\n 'CMXVII': 917,\n 'CMXVIII': 918,\n 'CMXX': 920,\n 'CMXXI': 921,\n 'CMXXII': 922,\n 'CMXXIII': 923,\n 'CMXXIV': 924,\n 'CMXXIX': 929,\n 'CMXXV': 925,\n 'CMXXVI': 926,\n 'CMXXVII': 927,\n 'CMXXVIII': 928,\n 'CMXXX': 930,\n 'CMXXXI': 931,\n 'CMXXXII': 932,\n 'CMXXXIII': 933,\n 'CMXXXIV': 934,\n 'CMXXXIX': 939,\n 'CMXXXV': 935,\n 'CMXXXVI': 936,\n 'CMXXXVII': 937,\n 'CMXXXVIII': 938,\n 'CV': 105,\n 'CVI': 106,\n 'CVII': 107,\n 'CVIII': 108,\n 'CX': 110,\n 'CXC': 190,\n 'CXCI': 191,\n 'CXCII': 192,\n 'CXCIII': 193,\n 'CXCIV': 194,\n 'CXCIX': 199,\n 'CXCV': 195,\n 'CXCVI': 196,\n 'CXCVII': 197,\n 'CXCVIII': 198,\n 'CXI': 111,\n 'CXII': 112,\n 'CXIII': 113,\n 'CXIV': 114,\n 'CXIX': 119,\n 'CXL': 140,\n 'CXLI': 141,\n 'CXLII': 142,\n 'CXLIII': 143,\n 'CXLIV': 144,\n 'CXLIX': 149,\n 'CXLV': 145,\n 'CXLVI': 146,\n 'CXLVII': 147,\n 'CXLVIII': 148,\n 'CXV': 115,\n 'CXVI': 116,\n 'CXVII': 117,\n 'CXVIII': 118,\n 'CXX': 120,\n 'CXXI': 121,\n 'CXXII': 122,\n 'CXXIII': 123,\n 'CXXIV': 124,\n 'CXXIX': 129,\n 'CXXV': 125,\n 'CXXVI': 126,\n 'CXXVII': 127,\n 'CXXVIII': 128,\n 'CXXX': 130,\n 'CXXXI': 131,\n 'CXXXII': 132,\n 'CXXXIII': 133,\n 'CXXXIV': 134,\n 'CXXXIX': 139,\n 'CXXXV': 135,\n 'CXXXVI': 136,\n 'CXXXVII': 137,\n 'CXXXVIII': 138,\n 'D': 500,\n 'DC': 600,\n 'DCC': 700,\n 'DCCC': 800,\n 'DCCCI': 801,\n 'DCCCII': 802,\n 'DCCCIII': 803,\n 'DCCCIV': 804,\n 'DCCCIX': 809,\n 'DCCCL': 850,\n 'DCCCLI': 851,\n 'DCCCLII': 852,\n 'DCCCLIII': 853,\n 'DCCCLIV': 854,\n 'DCCCLIX': 859,\n 'DCCCLV': 855,\n 'DCCCLVI': 856,\n 'DCCCLVII': 857,\n 'DCCCLVIII': 858,\n 'DCCCLX': 860,\n 'DCCCLXI': 861,\n 'DCCCLXII': 862,\n 'DCCCLXIII': 863,\n 'DCCCLXIV': 864,\n 'DCCCLXIX': 869,\n 'DCCCLXV': 865,\n 'DCCCLXVI': 866,\n 'DCCCLXVII': 867,\n 'DCCCLXVIII': 868,\n 'DCCCLXX': 870,\n 'DCCCLXXI': 871,\n 'DCCCLXXII': 872,\n 'DCCCLXXIII': 873,\n 'DCCCLXXIV': 874,\n 'DCCCLXXIX': 879,\n 'DCCCLXXV': 875,\n 'DCCCLXXVI': 876,\n 'DCCCLXXVII': 877,\n 'DCCCLXXVIII': 878,\n 'DCCCLXXX': 880,\n 'DCCCLXXXI': 881,\n 'DCCCLXXXII': 882,\n 'DCCCLXXXIII': 883,\n 'DCCCLXXXIV': 884,\n 'DCCCLXXXIX': 889,\n 'DCCCLXXXV': 885,\n 'DCCCLXXXVI': 886,\n 'DCCCLXXXVII': 887,\n 'DCCCLXXXVIII': 888,\n 'DCCCV': 805,\n 'DCCCVI': 806,\n 'DCCCVII': 807,\n 'DCCCVIII': 808,\n 'DCCCX': 810,\n 'DCCCXC': 890,\n 'DCCCXCI': 891,\n 'DCCCXCII': 892,\n 'DCCCXCIII': 893,\n 'DCCCXCIV': 894,\n 'DCCCXCIX': 899,\n 'DCCCXCV': 895,\n 'DCCCXCVI': 896,\n 'DCCCXCVII': 897,\n 'DCCCXCVIII': 898,\n 'DCCCXI': 811,\n 'DCCCXII': 812,\n 'DCCCXIII': 813,\n 'DCCCXIV': 814,\n 'DCCCXIX': 819,\n 'DCCCXL': 840,\n 'DCCCXLI': 841,\n 'DCCCXLII': 842,\n 'DCCCXLIII': 843,\n 'DCCCXLIV': 844,\n 'DCCCXLIX': 849,\n 'DCCCXLV': 845,\n 'DCCCXLVI': 846,\n 'DCCCXLVII': 847,\n 'DCCCXLVIII': 848,\n 'DCCCXV': 815,\n 'DCCCXVI': 816,\n 'DCCCXVII': 817,\n 'DCCCXVIII': 818,\n 'DCCCXX': 820,\n 'DCCCXXI': 821,\n 'DCCCXXII': 822,\n 'DCCCXXIII': 823,\n 'DCCCXXIV': 824,\n 'DCCCXXIX': 829,\n 'DCCCXXV': 825,\n 'DCCCXXVI': 826,\n 'DCCCXXVII': 827,\n 'DCCCXXVIII': 828,\n 'DCCCXXX': 830,\n 'DCCCXXXI': 831,\n 'DCCCXXXII': 832,\n 'DCCCXXXIII': 833,\n 'DCCCXXXIV': 834,\n 'DCCCXXXIX': 839,\n 'DCCCXXXV': 835,\n 'DCCCXXXVI': 836,\n 'DCCCXXXVII': 837,\n 'DCCCXXXVIII': 838,\n 'DCCI': 701,\n 'DCCII': 702,\n 'DCCIII': 703,\n 'DCCIV': 704,\n 'DCCIX': 709,\n 'DCCL': 750,\n 'DCCLI': 751,\n 'DCCLII': 752,\n 'DCCLIII': 753,\n 'DCCLIV': 754,\n 'DCCLIX': 759,\n 'DCCLV': 755,\n 'DCCLVI': 756,\n 'DCCLVII': 757,\n 'DCCLVIII': 758,\n 'DCCLX': 760,\n 'DCCLXI': 761,\n 'DCCLXII': 762,\n 'DCCLXIII': 763,\n 'DCCLXIV': 764,\n 'DCCLXIX': 769,\n 'DCCLXV': 765,\n 'DCCLXVI': 766,\n 'DCCLXVII': 767,\n 'DCCLXVIII': 768,\n 'DCCLXX': 770,\n 'DCCLXXI': 771,\n 'DCCLXXII': 772,\n 'DCCLXXIII': 773,\n 'DCCLXXIV': 774,\n 'DCCLXXIX': 779,\n 'DCCLXXV': 775,\n 'DCCLXXVI': 776,\n 'DCCLXXVII': 777,\n 'DCCLXXVIII': 778,\n 'DCCLXXX': 780,\n 'DCCLXXXI': 781,\n 'DCCLXXXII': 782,\n 'DCCLXXXIII': 783,\n 'DCCLXXXIV': 784,\n 'DCCLXXXIX': 789,\n 'DCCLXXXV': 785,\n 'DCCLXXXVI': 786,\n 'DCCLXXXVII': 787,\n 'DCCLXXXVIII': 788,\n 'DCCV': 705,\n 'DCCVI': 706,\n 'DCCVII': 707,\n 'DCCVIII': 708,\n 'DCCX': 710,\n 'DCCXC': 790,\n 'DCCXCI': 791,\n 'DCCXCII': 792,\n 'DCCXCIII': 793,\n 'DCCXCIV': 794,\n 'DCCXCIX': 799,\n 'DCCXCV': 795,\n 'DCCXCVI': 796,\n 'DCCXCVII': 797,\n 'DCCXCVIII': 798,\n 'DCCXI': 711,\n 'DCCXII': 712,\n 'DCCXIII': 713,\n 'DCCXIV': 714,\n 'DCCXIX': 719,\n 'DCCXL': 740,\n 'DCCXLI': 741,\n 'DCCXLII': 742,\n 'DCCXLIII': 743,\n 'DCCXLIV': 744,\n 'DCCXLIX': 749,\n 'DCCXLV': 745,\n 'DCCXLVI': 746,\n 'DCCXLVII': 747,\n 'DCCXLVIII': 748,\n 'DCCXV': 715,\n 'DCCXVI': 716,\n 'DCCXVII': 717,\n 'DCCXVIII': 718,\n 'DCCXX': 720,\n 'DCCXXI': 721,\n 'DCCXXII': 722,\n 'DCCXXIII': 723,\n 'DCCXXIV': 724,\n 'DCCXXIX': 729,\n 'DCCXXV': 725,\n 'DCCXXVI': 726,\n 'DCCXXVII': 727,\n 'DCCXXVIII': 728,\n 'DCCXXX': 730,\n 'DCCXXXI': 731,\n 'DCCXXXII': 732,\n 'DCCXXXIII': 733,\n 'DCCXXXIV': 734,\n 'DCCXXXIX': 739,\n 'DCCXXXV': 735,\n 'DCCXXXVI': 736,\n 'DCCXXXVII': 737,\n 'DCCXXXVIII': 738,\n 'DCI': 601,\n 'DCII': 602,\n 'DCIII': 603,\n 'DCIV': 604,\n 'DCIX': 609,\n 'DCL': 650,\n 'DCLI': 651,\n 'DCLII': 652,\n 'DCLIII': 653,\n 'DCLIV': 654,\n 'DCLIX': 659,\n 'DCLV': 655,\n 'DCLVI': 656,\n 'DCLVII': 657,\n 'DCLVIII': 658,\n 'DCLX': 660,\n 'DCLXI': 661,\n 'DCLXII': 662,\n 'DCLXIII': 663,\n 'DCLXIV': 664,\n 'DCLXIX': 669,\n 'DCLXV': 665,\n 'DCLXVI': 666,\n 'DCLXVII': 667,\n 'DCLXVIII': 668,\n 'DCLXX': 670,\n 'DCLXXI': 671,\n 'DCLXXII': 672,\n 'DCLXXIII': 673,\n 'DCLXXIV': 674,\n 'DCLXXIX': 679,\n 'DCLXXV': 675,\n 'DCLXXVI': 676,\n 'DCLXXVII': 677,\n 'DCLXXVIII': 678,\n 'DCLXXX': 680,\n 'DCLXXXI': 681,\n 'DCLXXXII': 682,\n 'DCLXXXIII': 683,\n 'DCLXXXIV': 684,\n 'DCLXXXIX': 689,\n 'DCLXXXV': 685,\n 'DCLXXXVI': 686,\n 'DCLXXXVII': 687,\n 'DCLXXXVIII': 688,\n 'DCV': 605,\n 'DCVI': 606,\n 'DCVII': 607,\n 'DCVIII': 608,\n 'DCX': 610,\n 'DCXC': 690,\n 'DCXCI': 691,\n 'DCXCII': 692,\n 'DCXCIII': 693,\n 'DCXCIV': 694,\n 'DCXCIX': 699,\n 'DCXCV': 695,\n 'DCXCVI': 696,\n 'DCXCVII': 697,\n 'DCXCVIII': 698,\n 'DCXI': 611,\n 'DCXII': 612,\n 'DCXIII': 613,\n 'DCXIV': 614,\n 'DCXIX': 619,\n 'DCXL': 640,\n 'DCXLI': 641,\n 'DCXLII': 642,\n 'DCXLIII': 643,\n 'DCXLIV': 644,\n 'DCXLIX': 649,\n 'DCXLV': 645,\n 'DCXLVI': 646,\n 'DCXLVII': 647,\n 'DCXLVIII': 648,\n 'DCXV': 615,\n 'DCXVI': 616,\n 'DCXVII': 617,\n 'DCXVIII': 618,\n 'DCXX': 620,\n 'DCXXI': 621,\n 'DCXXII': 622,\n 'DCXXIII': 623,\n 'DCXXIV': 624,\n 'DCXXIX': 629,\n 'DCXXV': 625,\n 'DCXXVI': 626,\n 'DCXXVII': 627,\n 'DCXXVIII': 628,\n 'DCXXX': 630,\n 'DCXXXI': 631,\n 'DCXXXII': 632,\n 'DCXXXIII': 633,\n 'DCXXXIV': 634,\n 'DCXXXIX': 639,\n 'DCXXXV': 635,\n 'DCXXXVI': 636,\n 'DCXXXVII': 637,\n 'DCXXXVIII': 638,\n 'DI': 501,\n 'DII': 502,\n 'DIII': 503,\n 'DIV': 504,\n 'DIX': 509,\n 'DL': 550,\n 'DLI': 551,\n 'DLII': 552,\n 'DLIII': 553,\n 'DLIV': 554,\n 'DLIX': 559,\n 'DLV': 555,\n 'DLVI': 556,\n 'DLVII': 557,\n 'DLVIII': 558,\n 'DLX': 560,\n 'DLXI': 561,\n 'DLXII': 562,\n 'DLXIII': 563,\n 'DLXIV': 564,\n 'DLXIX': 569,\n 'DLXV': 565,\n 'DLXVI': 566,\n 'DLXVII': 567,\n 'DLXVIII': 568,\n 'DLXX': 570,\n 'DLXXI': 571,\n 'DLXXII': 572,\n 'DLXXIII': 573,\n 'DLXXIV': 574,\n 'DLXXIX': 579,\n 'DLXXV': 575,\n 'DLXXVI': 576,\n 'DLXXVII': 577,\n 'DLXXVIII': 578,\n 'DLXXX': 580,\n 'DLXXXI': 581,\n 'DLXXXII': 582,\n 'DLXXXIII': 583,\n 'DLXXXIV': 584,\n 'DLXXXIX': 589,\n 'DLXXXV': 585,\n 'DLXXXVI': 586,\n 'DLXXXVII': 587,\n 'DLXXXVIII': 588,\n 'DV': 505,\n 'DVI': 506,\n 'DVII': 507,\n 'DVIII': 508,\n 'DX': 510,\n 'DXC': 590,\n 'DXCI': 591,\n 'DXCII': 592,\n 'DXCIII': 593,\n 'DXCIV': 594,\n 'DXCIX': 599,\n 'DXCV': 595,\n 'DXCVI': 596,\n 'DXCVII': 597,\n 'DXCVIII': 598,\n 'DXI': 511,\n 'DXII': 512,\n 'DXIII': 513,\n 'DXIV': 514,\n 'DXIX': 519,\n 'DXL': 540,\n 'DXLI': 541,\n 'DXLII': 542,\n 'DXLIII': 543,\n 'DXLIV': 544,\n 'DXLIX': 549,\n 'DXLV': 545,\n 'DXLVI': 546,\n 'DXLVII': 547,\n 'DXLVIII': 548,\n 'DXV': 515,\n 'DXVI': 516,\n 'DXVII': 517,\n 'DXVIII': 518,\n 'DXX': 520,\n 'DXXI': 521,\n 'DXXII': 522,\n 'DXXIII': 523,\n 'DXXIV': 524,\n 'DXXIX': 529,\n 'DXXV': 525,\n 'DXXVI': 526,\n 'DXXVII': 527,\n 'DXXVIII': 528,\n 'DXXX': 530,\n 'DXXXI': 531,\n 'DXXXII': 532,\n 'DXXXIII': 533,\n 'DXXXIV': 534,\n 'DXXXIX': 539,\n 'DXXXV': 535,\n 'DXXXVI': 536,\n 'DXXXVII': 537,\n 'DXXXVIII': 538,\n 'I': 1,\n 'II': 2,\n 'III': 3,\n 'IV': 4,\n 'IX': 9,\n 'L': 50,\n 'LI': 51,\n 'LII': 52,\n 'LIII': 53,\n 'LIV': 54,\n 'LIX': 59,\n 'LV': 55,\n 'LVI': 56,\n 'LVII': 57,\n 'LVIII': 58,\n 'LX': 60,\n 'LXI': 61,\n 'LXII': 62,\n 'LXIII': 63,\n 'LXIV': 64,\n 'LXIX': 69,\n 'LXV': 65,\n 'LXVI': 66,\n 'LXVII': 67,\n 'LXVIII': 68,\n 'LXX': 70,\n 'LXXI': 71,\n 'LXXII': 72,\n 'LXXIII': 73,\n 'LXXIV': 74,\n 'LXXIX': 79,\n 'LXXV': 75,\n 'LXXVI': 76,\n 'LXXVII': 77,\n 'LXXVIII': 78,\n 'LXXX': 80,\n 'LXXXI': 81,\n 'LXXXII': 82,\n 'LXXXIII': 83,\n 'LXXXIV': 84,\n 'LXXXIX': 89,\n 'LXXXV': 85,\n 'LXXXVI': 86,\n 'LXXXVII': 87,\n 'LXXXVIII': 88,\n 'M': 1000,\n 'MC': 1100,\n 'MCC': 1200,\n 'MCCC': 1300,\n 'MCCCI': 1301,\n 'MCCCII': 1302,\n 'MCCCIII': 1303,\n 'MCCCIV': 1304,\n 'MCCCIX': 1309,\n 'MCCCL': 1350,\n 'MCCCLI': 1351,\n 'MCCCLII': 1352,\n 'MCCCLIII': 1353,\n 'MCCCLIV': 1354,\n 'MCCCLIX': 1359,\n 'MCCCLV': 1355,\n 'MCCCLVI': 1356,\n 'MCCCLVII': 1357,\n 'MCCCLVIII': 1358,\n 'MCCCLX': 1360,\n 'MCCCLXI': 1361,\n 'MCCCLXII': 1362,\n 'MCCCLXIII': 1363,\n 'MCCCLXIV': 1364,\n 'MCCCLXIX': 1369,\n 'MCCCLXV': 1365,\n 'MCCCLXVI': 1366,\n 'MCCCLXVII': 1367,\n 'MCCCLXVIII': 1368,\n 'MCCCLXX': 1370,\n 'MCCCLXXI': 1371,\n 'MCCCLXXII': 1372,\n 'MCCCLXXIII': 1373,\n 'MCCCLXXIV': 1374,\n 'MCCCLXXIX': 1379,\n 'MCCCLXXV': 1375,\n 'MCCCLXXVI': 1376,\n 'MCCCLXXVII': 1377,\n 'MCCCLXXVIII': 1378,\n 'MCCCLXXX': 1380,\n 'MCCCLXXXI': 1381,\n 'MCCCLXXXII': 1382,\n 'MCCCLXXXIII': 1383,\n 'MCCCLXXXIV': 1384,\n 'MCCCLXXXIX': 1389,\n 'MCCCLXXXV': 1385,\n 'MCCCLXXXVI': 1386,\n 'MCCCLXXXVII': 1387,\n 'MCCCLXXXVIII': 1388,\n 'MCCCV': 1305,\n 'MCCCVI': 1306,\n 'MCCCVII': 1307,\n 'MCCCVIII': 1308,\n 'MCCCX': 1310,\n 'MCCCXC': 1390,\n 'MCCCXCI': 1391,\n 'MCCCXCII': 1392,\n 'MCCCXCIII': 1393,\n 'MCCCXCIV': 1394,\n 'MCCCXCIX': 1399,\n 'MCCCXCV': 1395,\n 'MCCCXCVI': 1396,\n 'MCCCXCVII': 1397,\n 'MCCCXCVIII': 1398,\n 'MCCCXI': 1311,\n 'MCCCXII': 1312,\n 'MCCCXIII': 1313,\n 'MCCCXIV': 1314,\n 'MCCCXIX': 1319,\n 'MCCCXL': 1340,\n 'MCCCXLI': 1341,\n 'MCCCXLII': 1342,\n 'MCCCXLIII': 1343,\n 'MCCCXLIV': 1344,\n 'MCCCXLIX': 1349,\n 'MCCCXLV': 1345,\n 'MCCCXLVI': 1346,\n 'MCCCXLVII': 1347,\n 'MCCCXLVIII': 1348,\n 'MCCCXV': 1315,\n 'MCCCXVI': 1316,\n 'MCCCXVII': 1317,\n 'MCCCXVIII': 1318,\n 'MCCCXX': 1320,\n 'MCCCXXI': 1321,\n 'MCCCXXII': 1322,\n 'MCCCXXIII': 1323,\n 'MCCCXXIV': 1324,\n 'MCCCXXIX': 1329,\n 'MCCCXXV': 1325,\n 'MCCCXXVI': 1326,\n 'MCCCXXVII': 1327,\n 'MCCCXXVIII': 1328,\n 'MCCCXXX': 1330,\n 'MCCCXXXI': 1331,\n 'MCCCXXXII': 1332,\n 'MCCCXXXIII': 1333,\n 'MCCCXXXIV': 1334,\n 'MCCCXXXIX': 1339,\n 'MCCCXXXV': 1335,\n 'MCCCXXXVI': 1336,\n 'MCCCXXXVII': 1337,\n 'MCCCXXXVIII': 1338,\n 'MCCI': 1201,\n 'MCCII': 1202,\n 'MCCIII': 1203,\n 'MCCIV': 1204,\n 'MCCIX': 1209,\n 'MCCL': 1250,\n 'MCCLI': 1251,\n 'MCCLII': 1252,\n 'MCCLIII': 1253,\n 'MCCLIV': 1254,\n 'MCCLIX': 1259,\n 'MCCLV': 1255,\n 'MCCLVI': 1256,\n 'MCCLVII': 1257,\n 'MCCLVIII': 1258,\n 'MCCLX': 1260,\n 'MCCLXI': 1261,\n 'MCCLXII': 1262,\n 'MCCLXIII': 1263,\n 'MCCLXIV': 1264,\n 'MCCLXIX': 1269,\n 'MCCLXV': 1265,\n 'MCCLXVI': 1266,\n 'MCCLXVII': 1267,\n 'MCCLXVIII': 1268,\n 'MCCLXX': 1270,\n 'MCCLXXI': 1271,\n 'MCCLXXII': 1272,\n 'MCCLXXIII': 1273,\n 'MCCLXXIV': 1274,\n 'MCCLXXIX': 1279,\n 'MCCLXXV': 1275,\n 'MCCLXXVI': 1276,\n 'MCCLXXVII': 1277,\n 'MCCLXXVIII': 1278,\n 'MCCLXXX': 1280,\n 'MCCLXXXI': 1281,\n 'MCCLXXXII': 1282,\n 'MCCLXXXIII': 1283,\n 'MCCLXXXIV': 1284,\n 'MCCLXXXIX': 1289,\n 'MCCLXXXV': 1285,\n 'MCCLXXXVI': 1286,\n 'MCCLXXXVII': 1287,\n 'MCCLXXXVIII': 1288,\n 'MCCV': 1205,\n 'MCCVI': 1206,\n 'MCCVII': 1207,\n 'MCCVIII': 1208,\n 'MCCX': 1210,\n 'MCCXC': 1290,\n 'MCCXCI': 1291,\n 'MCCXCII': 1292,\n 'MCCXCIII': 1293,\n 'MCCXCIV': 1294,\n 'MCCXCIX': 1299,\n 'MCCXCV': 1295,\n 'MCCXCVI': 1296,\n 'MCCXCVII': 1297,\n 'MCCXCVIII': 1298,\n 'MCCXI': 1211,\n 'MCCXII': 1212,\n 'MCCXIII': 1213,\n 'MCCXIV': 1214,\n 'MCCXIX': 1219,\n 'MCCXL': 1240,\n 'MCCXLI': 1241,\n 'MCCXLII': 1242,\n 'MCCXLIII': 1243,\n 'MCCXLIV': 1244,\n 'MCCXLIX': 1249,\n 'MCCXLV': 1245,\n 'MCCXLVI': 1246,\n 'MCCXLVII': 1247,\n 'MCCXLVIII': 1248,\n 'MCCXV': 1215,\n 'MCCXVI': 1216,\n 'MCCXVII': 1217,\n 'MCCXVIII': 1218,\n 'MCCXX': 1220,\n 'MCCXXI': 1221,\n 'MCCXXII': 1222,\n 'MCCXXIII': 1223,\n 'MCCXXIV': 1224,\n 'MCCXXIX': 1229,\n 'MCCXXV': 1225,\n 'MCCXXVI': 1226,\n 'MCCXXVII': 1227,\n 'MCCXXVIII': 1228,\n 'MCCXXX': 1230,\n 'MCCXXXI': 1231,\n 'MCCXXXII': 1232,\n 'MCCXXXIII': 1233,\n 'MCCXXXIV': 1234,\n 'MCCXXXIX': 1239,\n 'MCCXXXV': 1235,\n 'MCCXXXVI': 1236,\n 'MCCXXXVII': 1237,\n 'MCCXXXVIII': 1238,\n 'MCD': 1400,\n 'MCDI': 1401,\n 'MCDII': 1402,\n 'MCDIII': 1403,\n 'MCDIV': 1404,\n 'MCDIX': 1409,\n 'MCDL': 1450,\n 'MCDLI': 1451,\n 'MCDLII': 1452,\n 'MCDLIII': 1453,\n 'MCDLIV': 1454,\n 'MCDLIX': 1459,\n 'MCDLV': 1455,\n 'MCDLVI': 1456,\n 'MCDLVII': 1457,\n 'MCDLVIII': 1458,\n 'MCDLX': 1460,\n 'MCDLXI': 1461,\n 'MCDLXII': 1462,\n 'MCDLXIII': 1463,\n 'MCDLXIV': 1464,\n 'MCDLXIX': 1469,\n 'MCDLXV': 1465,\n 'MCDLXVI': 1466,\n 'MCDLXVII': 1467,\n 'MCDLXVIII': 1468,\n 'MCDLXX': 1470,\n 'MCDLXXI': 1471,\n 'MCDLXXII': 1472,\n 'MCDLXXIII': 1473,\n 'MCDLXXIV': 1474,\n 'MCDLXXIX': 1479,\n 'MCDLXXV': 1475,\n 'MCDLXXVI': 1476,\n 'MCDLXXVII': 1477,\n 'MCDLXXVIII': 1478,\n 'MCDLXXX': 1480,\n 'MCDLXXXI': 1481,\n 'MCDLXXXII': 1482,\n 'MCDLXXXIII': 1483,\n 'MCDLXXXIV': 1484,\n 'MCDLXXXIX': 1489,\n 'MCDLXXXV': 1485,\n 'MCDLXXXVI': 1486,\n 'MCDLXXXVII': 1487,\n 'MCDLXXXVIII': 1488,\n 'MCDV': 1405,\n 'MCDVI': 1406,\n 'MCDVII': 1407,\n 'MCDVIII': 1408,\n 'MCDX': 1410,\n 'MCDXC': 1490,\n 'MCDXCI': 1491,\n 'MCDXCII': 1492,\n 'MCDXCIII': 1493,\n 'MCDXCIV': 1494,\n 'MCDXCIX': 1499,\n 'MCDXCV': 1495,\n 'MCDXCVI': 1496,\n 'MCDXCVII': 1497,\n 'MCDXCVIII': 1498,\n 'MCDXI': 1411,\n 'MCDXII': 1412,\n 'MCDXIII': 1413,\n 'MCDXIV': 1414,\n 'MCDXIX': 1419,\n 'MCDXL': 1440,\n 'MCDXLI': 1441,\n 'MCDXLII': 1442,\n 'MCDXLIII': 1443,\n 'MCDXLIV': 1444,\n 'MCDXLIX': 1449,\n 'MCDXLV': 1445,\n 'MCDXLVI': 1446,\n 'MCDXLVII': 1447,\n 'MCDXLVIII': 1448,\n 'MCDXV': 1415,\n 'MCDXVI': 1416,\n 'MCDXVII': 1417,\n 'MCDXVIII': 1418,\n 'MCDXX': 1420,\n 'MCDXXI': 1421,\n 'MCDXXII': 1422,\n 'MCDXXIII': 1423,\n 'MCDXXIV': 1424,\n 'MCDXXIX': 1429,\n 'MCDXXV': 1425,\n 'MCDXXVI': 1426,\n 'MCDXXVII': 1427,\n 'MCDXXVIII': 1428,\n 'MCDXXX': 1430,\n 'MCDXXXI': 1431,\n 'MCDXXXII': 1432,\n 'MCDXXXIII': 1433,\n 'MCDXXXIV': 1434,\n 'MCDXXXIX': 1439,\n 'MCDXXXV': 1435,\n 'MCDXXXVI': 1436,\n 'MCDXXXVII': 1437,\n 'MCDXXXVIII': 1438,\n 'MCI': 1101,\n 'MCII': 1102,\n 'MCIII': 1103,\n 'MCIV': 1104,\n 'MCIX': 1109,\n 'MCL': 1150,\n 'MCLI': 1151,\n 'MCLII': 1152,\n 'MCLIII': 1153,\n 'MCLIV': 1154,\n 'MCLIX': 1159,\n 'MCLV': 1155,\n 'MCLVI': 1156,\n 'MCLVII': 1157,\n 'MCLVIII': 1158,\n 'MCLX': 1160,\n 'MCLXI': 1161,\n 'MCLXII': 1162,\n 'MCLXIII': 1163,\n 'MCLXIV': 1164,\n 'MCLXIX': 1169,\n 'MCLXV': 1165,\n 'MCLXVI': 1166,\n 'MCLXVII': 1167,\n 'MCLXVIII': 1168,\n 'MCLXX': 1170,\n 'MCLXXI': 1171,\n 'MCLXXII': 1172,\n 'MCLXXIII': 1173,\n 'MCLXXIV': 1174,\n 'MCLXXIX': 1179,\n 'MCLXXV': 1175,\n 'MCLXXVI': 1176,\n 'MCLXXVII': 1177,\n 'MCLXXVIII': 1178,\n 'MCLXXX': 1180,\n 'MCLXXXI': 1181,\n 'MCLXXXII': 1182,\n 'MCLXXXIII': 1183,\n 'MCLXXXIV': 1184,\n 'MCLXXXIX': 1189,\n 'MCLXXXV': 1185,\n 'MCLXXXVI': 1186,\n 'MCLXXXVII': 1187,\n 'MCLXXXVIII': 1188,\n 'MCM': 1900,\n 'MCMI': 1901,\n 'MCMII': 1902,\n 'MCMIII': 1903,\n 'MCMIV': 1904,\n 'MCMIX': 1909,\n 'MCML': 1950,\n 'MCMLI': 1951,\n 'MCMLII': 1952,\n 'MCMLIII': 1953,\n 'MCMLIV': 1954,\n 'MCMLIX': 1959,\n 'MCMLV': 1955,\n 'MCMLVI': 1956,\n 'MCMLVII': 1957,\n 'MCMLVIII': 1958,\n 'MCMLX': 1960,\n 'MCMLXI': 1961,\n 'MCMLXII': 1962,\n 'MCMLXIII': 1963,\n 'MCMLXIV': 1964,\n 'MCMLXIX': 1969,\n 'MCMLXV': 1965,\n 'MCMLXVI': 1966,\n 'MCMLXVII': 1967,\n 'MCMLXVIII': 1968,\n 'MCMLXX': 1970,\n 'MCMLXXI': 1971,\n 'MCMLXXII': 1972,\n 'MCMLXXIII': 1973,\n 'MCMLXXIV': 1974,\n 'MCMLXXIX': 1979,\n 'MCMLXXV': 1975,\n 'MCMLXXVI': 1976,\n 'MCMLXXVII': 1977,\n 'MCMLXXVIII': 1978,\n 'MCMLXXX': 1980,\n 'MCMLXXXI': 1981,\n 'MCMLXXXII': 1982,\n 'MCMLXXXIII': 1983,\n 'MCMLXXXIV': 1984,\n 'MCMLXXXIX': 1989,\n 'MCMLXXXV': 1985,\n 'MCMLXXXVI': 1986,\n 'MCMLXXXVII': 1987,\n 'MCMLXXXVIII': 1988,\n 'MCMV': 1905,\n 'MCMVI': 1906,\n 'MCMVII': 1907,\n 'MCMVIII': 1908,\n 'MCMX': 1910,\n 'MCMXC': 1990,\n 'MCMXCI': 1991,\n 'MCMXCII': 1992,\n 'MCMXCIII': 1993,\n 'MCMXCIV': 1994,\n 'MCMXCIX': 1999,\n 'MCMXCV': 1995,\n 'MCMXCVI': 1996,\n 'MCMXCVII': 1997,\n 'MCMXCVIII': 1998,\n 'MCMXI': 1911,\n 'MCMXII': 1912,\n 'MCMXIII': 1913,\n 'MCMXIV': 1914,\n 'MCMXIX': 1919,\n 'MCMXL': 1940,\n 'MCMXLI': 1941,\n 'MCMXLII': 1942,\n 'MCMXLIII': 1943,\n 'MCMXLIV': 1944,\n 'MCMXLIX': 1949,\n 'MCMXLV': 1945,\n 'MCMXLVI': 1946,\n 'MCMXLVII': 1947,\n 'MCMXLVIII': 1948,\n 'MCMXV': 1915,\n 'MCMXVI': 1916,\n 'MCMXVII': 1917,\n 'MCMXVIII': 1918,\n 'MCMXX': 1920,\n 'MCMXXI': 1921,\n 'MCMXXII': 1922,\n 'MCMXXIII': 1923,\n 'MCMXXIV': 1924,\n 'MCMXXIX': 1929,\n 'MCMXXV': 1925,\n 'MCMXXVI': 1926,\n 'MCMXXVII': 1927,\n 'MCMXXVIII': 1928,\n 'MCMXXX': 1930,\n 'MCMXXXI': 1931,\n 'MCMXXXII': 1932,\n 'MCMXXXIII': 1933,\n 'MCMXXXIV': 1934,\n 'MCMXXXIX': 1939,\n 'MCMXXXV': 1935,\n 'MCMXXXVI': 1936,\n 'MCMXXXVII': 1937,\n 'MCMXXXVIII': 1938,\n 'MCV': 1105,\n 'MCVI': 1106,\n 'MCVII': 1107,\n 'MCVIII': 1108,\n 'MCX': 1110,\n 'MCXC': 1190,\n 'MCXCI': 1191,\n 'MCXCII': 1192,\n 'MCXCIII': 1193,\n 'MCXCIV': 1194,\n 'MCXCIX': 1199,\n 'MCXCV': 1195,\n 'MCXCVI': 1196,\n 'MCXCVII': 1197,\n 'MCXCVIII': 1198,\n 'MCXI': 1111,\n 'MCXII': 1112,\n 'MCXIII': 1113,\n 'MCXIV': 1114,\n 'MCXIX': 1119,\n 'MCXL': 1140,\n 'MCXLI': 1141,\n 'MCXLII': 1142,\n 'MCXLIII': 1143,\n 'MCXLIV': 1144,\n 'MCXLIX': 1149,\n 'MCXLV': 1145,\n 'MCXLVI': 1146,\n 'MCXLVII': 1147,\n 'MCXLVIII': 1148,\n 'MCXV': 1115,\n 'MCXVI': 1116,\n 'MCXVII': 1117,\n 'MCXVIII': 1118,\n 'MCXX': 1120,\n 'MCXXI': 1121,\n 'MCXXII': 1122,\n 'MCXXIII': 1123,\n 'MCXXIV': 1124,\n 'MCXXIX': 1129,\n 'MCXXV': 1125,\n 'MCXXVI': 1126,\n 'MCXXVII': 1127,\n 'MCXXVIII': 1128,\n 'MCXXX': 1130,\n 'MCXXXI': 1131,\n 'MCXXXII': 1132,\n 'MCXXXIII': 1133,\n 'MCXXXIV': 1134,\n 'MCXXXIX': 1139,\n 'MCXXXV': 1135,\n 'MCXXXVI': 1136,\n 'MCXXXVII': 1137,\n 'MCXXXVIII': 1138,\n 'MD': 1500,\n 'MDC': 1600,\n 'MDCC': 1700,\n 'MDCCC': 1800,\n 'MDCCCI': 1801,\n 'MDCCCII': 1802,\n 'MDCCCIII': 1803,\n 'MDCCCIV': 1804,\n 'MDCCCIX': 1809,\n 'MDCCCL': 1850,\n 'MDCCCLI': 1851,\n 'MDCCCLII': 1852,\n 'MDCCCLIII': 1853,\n 'MDCCCLIV': 1854,\n 'MDCCCLIX': 1859,\n 'MDCCCLV': 1855,\n 'MDCCCLVI': 1856,\n 'MDCCCLVII': 1857,\n 'MDCCCLVIII': 1858,\n 'MDCCCLX': 1860,\n 'MDCCCLXI': 1861,\n 'MDCCCLXII': 1862,\n 'MDCCCLXIII': 1863,\n 'MDCCCLXIV': 1864,\n 'MDCCCLXIX': 1869,\n 'MDCCCLXV': 1865,\n 'MDCCCLXVI': 1866,\n 'MDCCCLXVII': 1867,\n 'MDCCCLXVIII': 1868,\n 'MDCCCLXX': 1870,\n 'MDCCCLXXI': 1871,\n 'MDCCCLXXII': 1872,\n 'MDCCCLXXIII': 1873,\n 'MDCCCLXXIV': 1874,\n 'MDCCCLXXIX': 1879,\n 'MDCCCLXXV': 1875,\n 'MDCCCLXXVI': 1876,\n 'MDCCCLXXVII': 1877,\n 'MDCCCLXXVIII': 1878,\n 'MDCCCLXXX': 1880,\n 'MDCCCLXXXI': 1881,\n 'MDCCCLXXXII': 1882,\n 'MDCCCLXXXIII': 1883,\n 'MDCCCLXXXIV': 1884,\n 'MDCCCLXXXIX': 1889,\n 'MDCCCLXXXV': 1885,\n 'MDCCCLXXXVI': 1886,\n 'MDCCCLXXXVII': 1887,\n 'MDCCCLXXXVIII': 1888,\n 'MDCCCV': 1805,\n 'MDCCCVI': 1806,\n 'MDCCCVII': 1807,\n 'MDCCCVIII': 1808,\n 'MDCCCX': 1810,\n 'MDCCCXC': 1890,\n 'MDCCCXCI': 1891,\n 'MDCCCXCII': 1892,\n 'MDCCCXCIII': 1893,\n 'MDCCCXCIV': 1894,\n 'MDCCCXCIX': 1899,\n 'MDCCCXCV': 1895,\n 'MDCCCXCVI': 1896,\n 'MDCCCXCVII': 1897,\n 'MDCCCXCVIII': 1898,\n 'MDCCCXI': 1811,\n 'MDCCCXII': 1812,\n 'MDCCCXIII': 1813,\n 'MDCCCXIV': 1814,\n 'MDCCCXIX': 1819,\n 'MDCCCXL': 1840,\n 'MDCCCXLI': 1841,\n 'MDCCCXLII': 1842,\n 'MDCCCXLIII': 1843,\n 'MDCCCXLIV': 1844,\n 'MDCCCXLIX': 1849,\n 'MDCCCXLV': 1845,\n 'MDCCCXLVI': 1846,\n 'MDCCCXLVII': 1847,\n 'MDCCCXLVIII': 1848,\n 'MDCCCXV': 1815,\n 'MDCCCXVI': 1816,\n 'MDCCCXVII': 1817,\n 'MDCCCXVIII': 1818,\n 'MDCCCXX': 1820,\n 'MDCCCXXI': 1821,\n 'MDCCCXXII': 1822,\n 'MDCCCXXIII': 1823,\n 'MDCCCXXIV': 1824,\n 'MDCCCXXIX': 1829,\n 'MDCCCXXV': 1825,\n 'MDCCCXXVI': 1826,\n 'MDCCCXXVII': 1827,\n 'MDCCCXXVIII': 1828,\n 'MDCCCXXX': 1830,\n 'MDCCCXXXI': 1831,\n 'MDCCCXXXII': 1832,\n 'MDCCCXXXIII': 1833,\n 'MDCCCXXXIV': 1834,\n 'MDCCCXXXIX': 1839,\n 'MDCCCXXXV': 1835,\n 'MDCCCXXXVI': 1836,\n 'MDCCCXXXVII': 1837,\n 'MDCCCXXXVIII': 1838,\n 'MDCCI': 1701,\n 'MDCCII': 1702,\n 'MDCCIII': 1703,\n 'MDCCIV': 1704,\n 'MDCCIX': 1709,\n 'MDCCL': 1750,\n 'MDCCLI': 1751,\n 'MDCCLII': 1752,\n 'MDCCLIII': 1753,\n 'MDCCLIV': 1754,\n 'MDCCLIX': 1759,\n 'MDCCLV': 1755,\n 'MDCCLVI': 1756,\n 'MDCCLVII': 1757,\n 'MDCCLVIII': 1758,\n 'MDCCLX': 1760,\n 'MDCCLXI': 1761,\n 'MDCCLXII': 1762,\n 'MDCCLXIII': 1763,\n 'MDCCLXIV': 1764,\n 'MDCCLXIX': 1769,\n 'MDCCLXV': 1765,\n 'MDCCLXVI': 1766,\n 'MDCCLXVII': 1767,\n 'MDCCLXVIII': 1768,\n 'MDCCLXX': 1770,\n 'MDCCLXXI': 1771,\n 'MDCCLXXII': 1772,\n 'MDCCLXXIII': 1773,\n 'MDCCLXXIV': 1774,\n 'MDCCLXXIX': 1779,\n 'MDCCLXXV': 1775,\n 'MDCCLXXVI': 1776,\n 'MDCCLXXVII': 1777,\n 'MDCCLXXVIII': 1778,\n 'MDCCLXXX': 1780,\n 'MDCCLXXXI': 1781,\n 'MDCCLXXXII': 1782,\n 'MDCCLXXXIII': 1783,\n 'MDCCLXXXIV': 1784,\n 'MDCCLXXXIX': 1789,\n 'MDCCLXXXV': 1785,\n 'MDCCLXXXVI': 1786,\n 'MDCCLXXXVII': 1787,\n 'MDCCLXXXVIII': 1788,\n 'MDCCV': 1705,\n 'MDCCVI': 1706,\n 'MDCCVII': 1707,\n 'MDCCVIII': 1708,\n 'MDCCX': 1710,\n 'MDCCXC': 1790,\n 'MDCCXCI': 1791,\n 'MDCCXCII': 1792,\n 'MDCCXCIII': 1793,\n 'MDCCXCIV': 1794,\n 'MDCCXCIX': 1799,\n 'MDCCXCV': 1795,\n 'MDCCXCVI': 1796,\n 'MDCCXCVII': 1797,\n 'MDCCXCVIII': 1798,\n 'MDCCXI': 1711,\n 'MDCCXII': 1712,\n 'MDCCXIII': 1713,\n 'MDCCXIV': 1714,\n 'MDCCXIX': 1719,\n 'MDCCXL': 1740,\n 'MDCCXLI': 1741,\n 'MDCCXLII': 1742,\n 'MDCCXLIII': 1743,\n 'MDCCXLIV': 1744,\n 'MDCCXLIX': 1749,\n 'MDCCXLV': 1745,\n 'MDCCXLVI': 1746,\n 'MDCCXLVII': 1747,\n 'MDCCXLVIII': 1748,\n 'MDCCXV': 1715,\n 'MDCCXVI': 1716,\n 'MDCCXVII': 1717,\n 'MDCCXVIII': 1718,\n 'MDCCXX': 1720,\n 'MDCCXXI': 1721,\n 'MDCCXXII': 1722,\n 'MDCCXXIII': 1723,\n 'MDCCXXIV': 1724,\n 'MDCCXXIX': 1729,\n 'MDCCXXV': 1725,\n 'MDCCXXVI': 1726,\n 'MDCCXXVII': 1727,\n 'MDCCXXVIII': 1728,\n 'MDCCXXX': 1730,\n 'MDCCXXXI': 1731,\n 'MDCCXXXII': 1732,\n 'MDCCXXXIII': 1733,\n 'MDCCXXXIV': 1734,\n 'MDCCXXXIX': 1739,\n 'MDCCXXXV': 1735,\n 'MDCCXXXVI': 1736,\n 'MDCCXXXVII': 1737,\n 'MDCCXXXVIII': 1738,\n 'MDCI': 1601,\n 'MDCII': 1602,\n 'MDCIII': 1603,\n 'MDCIV': 1604,\n 'MDCIX': 1609,\n 'MDCL': 1650,\n 'MDCLI': 1651,\n 'MDCLII': 1652,\n 'MDCLIII': 1653,\n 'MDCLIV': 1654,\n 'MDCLIX': 1659,\n 'MDCLV': 1655,\n 'MDCLVI': 1656,\n 'MDCLVII': 1657,\n 'MDCLVIII': 1658,\n 'MDCLX': 1660,\n 'MDCLXI': 1661,\n 'MDCLXII': 1662,\n 'MDCLXIII': 1663,\n 'MDCLXIV': 1664,\n 'MDCLXIX': 1669,\n 'MDCLXV': 1665,\n 'MDCLXVI': 1666,\n 'MDCLXVII': 1667,\n 'MDCLXVIII': 1668,\n 'MDCLXX': 1670,\n 'MDCLXXI': 1671,\n 'MDCLXXII': 1672,\n 'MDCLXXIII': 1673,\n 'MDCLXXIV': 1674,\n 'MDCLXXIX': 1679,\n 'MDCLXXV': 1675,\n 'MDCLXXVI': 1676,\n 'MDCLXXVII': 1677,\n 'MDCLXXVIII': 1678,\n 'MDCLXXX': 1680,\n 'MDCLXXXI': 1681,\n 'MDCLXXXII': 1682,\n 'MDCLXXXIII': 1683,\n 'MDCLXXXIV': 1684,\n 'MDCLXXXIX': 1689,\n 'MDCLXXXV': 1685,\n 'MDCLXXXVI': 1686,\n 'MDCLXXXVII': 1687,\n 'MDCLXXXVIII': 1688,\n 'MDCV': 1605,\n 'MDCVI': 1606,\n 'MDCVII': 1607,\n 'MDCVIII': 1608,\n 'MDCX': 1610,\n 'MDCXC': 1690,\n 'MDCXCI': 1691,\n 'MDCXCII': 1692,\n 'MDCXCIII': 1693,\n 'MDCXCIV': 1694,\n 'MDCXCIX': 1699,\n 'MDCXCV': 1695,\n 'MDCXCVI': 1696,\n 'MDCXCVII': 1697,\n 'MDCXCVIII': 1698,\n 'MDCXI': 1611,\n 'MDCXII': 1612,\n 'MDCXIII': 1613,\n 'MDCXIV': 1614,\n 'MDCXIX': 1619,\n 'MDCXL': 1640,\n 'MDCXLI': 1641,\n 'MDCXLII': 1642,\n 'MDCXLIII': 1643,\n 'MDCXLIV': 1644,\n 'MDCXLIX': 1649,\n 'MDCXLV': 1645,\n 'MDCXLVI': 1646,\n 'MDCXLVII': 1647,\n 'MDCXLVIII': 1648,\n 'MDCXV': 1615,\n 'MDCXVI': 1616,\n 'MDCXVII': 1617,\n 'MDCXVIII': 1618,\n 'MDCXX': 1620,\n 'MDCXXI': 1621,\n 'MDCXXII': 1622,\n 'MDCXXIII': 1623,\n 'MDCXXIV': 1624,\n 'MDCXXIX': 1629,\n 'MDCXXV': 1625,\n 'MDCXXVI': 1626,\n 'MDCXXVII': 1627,\n 'MDCXXVIII': 1628,\n 'MDCXXX': 1630,\n 'MDCXXXI': 1631,\n 'MDCXXXII': 1632,\n 'MDCXXXIII': 1633,\n 'MDCXXXIV': 1634,\n 'MDCXXXIX': 1639,\n 'MDCXXXV': 1635,\n 'MDCXXXVI': 1636,\n 'MDCXXXVII': 1637,\n 'MDCXXXVIII': 1638,\n 'MDI': 1501,\n 'MDII': 1502,\n 'MDIII': 1503,\n 'MDIV': 1504,\n 'MDIX': 1509,\n 'MDL': 1550,\n 'MDLI': 1551,\n 'MDLII': 1552,\n 'MDLIII': 1553,\n 'MDLIV': 1554,\n 'MDLIX': 1559,\n 'MDLV': 1555,\n 'MDLVI': 1556,\n 'MDLVII': 1557,\n 'MDLVIII': 1558,\n 'MDLX': 1560,\n 'MDLXI': 1561,\n 'MDLXII': 1562,\n 'MDLXIII': 1563,\n 'MDLXIV': 1564,\n 'MDLXIX': 1569,\n 'MDLXV': 1565,\n 'MDLXVI': 1566,\n 'MDLXVII': 1567,\n 'MDLXVIII': 1568,\n 'MDLXX': 1570,\n 'MDLXXI': 1571,\n 'MDLXXII': 1572,\n 'MDLXXIII': 1573,\n 'MDLXXIV': 1574,\n 'MDLXXIX': 1579,\n 'MDLXXV': 1575,\n 'MDLXXVI': 1576,\n 'MDLXXVII': 1577,\n 'MDLXXVIII': 1578,\n 'MDLXXX': 1580,\n 'MDLXXXI': 1581,\n 'MDLXXXII': 1582,\n 'MDLXXXIII': 1583,\n 'MDLXXXIV': 1584,\n 'MDLXXXIX': 1589,\n 'MDLXXXV': 1585,\n 'MDLXXXVI': 1586,\n 'MDLXXXVII': 1587,\n 'MDLXXXVIII': 1588,\n 'MDV': 1505,\n 'MDVI': 1506,\n 'MDVII': 1507,\n 'MDVIII': 1508,\n 'MDX': 1510,\n 'MDXC': 1590,\n 'MDXCI': 1591,\n 'MDXCII': 1592,\n 'MDXCIII': 1593,\n 'MDXCIV': 1594,\n 'MDXCIX': 1599,\n 'MDXCV': 1595,\n 'MDXCVI': 1596,\n 'MDXCVII': 1597,\n 'MDXCVIII': 1598,\n 'MDXI': 1511,\n 'MDXII': 1512,\n 'MDXIII': 1513,\n 'MDXIV': 1514,\n 'MDXIX': 1519,\n 'MDXL': 1540,\n 'MDXLI': 1541,\n 'MDXLII': 1542,\n 'MDXLIII': 1543,\n 'MDXLIV': 1544,\n 'MDXLIX': 1549,\n 'MDXLV': 1545,\n 'MDXLVI': 1546,\n 'MDXLVII': 1547,\n 'MDXLVIII': 1548,\n 'MDXV': 1515,\n 'MDXVI': 1516,\n 'MDXVII': 1517,\n 'MDXVIII': 1518,\n 'MDXX': 1520,\n 'MDXXI': 1521,\n 'MDXXII': 1522,\n 'MDXXIII': 1523,\n 'MDXXIV': 1524,\n 'MDXXIX': 1529,\n 'MDXXV': 1525,\n 'MDXXVI': 1526,\n 'MDXXVII': 1527,\n 'MDXXVIII': 1528,\n 'MDXXX': 1530,\n 'MDXXXI': 1531,\n 'MDXXXII': 1532,\n 'MDXXXIII': 1533,\n 'MDXXXIV': 1534,\n 'MDXXXIX': 1539,\n 'MDXXXV': 1535,\n 'MDXXXVI': 1536,\n 'MDXXXVII': 1537,\n 'MDXXXVIII': 1538,\n 'MI': 1001,\n 'MII': 1002,\n 'MIII': 1003,\n 'MIV': 1004,\n 'MIX': 1009,\n 'ML': 1050,\n 'MLI': 1051,\n 'MLII': 1052,\n 'MLIII': 1053,\n 'MLIV': 1054,\n 'MLIX': 1059,\n 'MLV': 1055,\n 'MLVI': 1056,\n 'MLVII': 1057,\n 'MLVIII': 1058,\n 'MLX': 1060,\n 'MLXI': 1061,\n 'MLXII': 1062,\n 'MLXIII': 1063,\n 'MLXIV': 1064,\n 'MLXIX': 1069,\n 'MLXV': 1065,\n 'MLXVI': 1066,\n 'MLXVII': 1067,\n 'MLXVIII': 1068,\n 'MLXX': 1070,\n 'MLXXI': 1071,\n 'MLXXII': 1072,\n 'MLXXIII': 1073,\n 'MLXXIV': 1074,\n 'MLXXIX': 1079,\n 'MLXXV': 1075,\n 'MLXXVI': 1076,\n 'MLXXVII': 1077,\n 'MLXXVIII': 1078,\n 'MLXXX': 1080,\n 'MLXXXI': 1081,\n 'MLXXXII': 1082,\n 'MLXXXIII': 1083,\n 'MLXXXIV': 1084,\n 'MLXXXIX': 1089,\n 'MLXXXV': 1085,\n 'MLXXXVI': 1086,\n 'MLXXXVII': 1087,\n 'MLXXXVIII': 1088,\n 'MM': 2000,\n 'MMC': 2100,\n 'MMCC': 2200,\n 'MMCCC': 2300,\n 'MMCCCI': 2301,\n 'MMCCCII': 2302,\n 'MMCCCIII': 2303,\n 'MMCCCIV': 2304,\n 'MMCCCIX': 2309,\n 'MMCCCL': 2350,\n 'MMCCCLI': 2351,\n 'MMCCCLII': 2352,\n 'MMCCCLIII': 2353,\n 'MMCCCLIV': 2354,\n 'MMCCCLIX': 2359,\n 'MMCCCLV': 2355,\n 'MMCCCLVI': 2356,\n 'MMCCCLVII': 2357,\n 'MMCCCLVIII': 2358,\n 'MMCCCLX': 2360,\n 'MMCCCLXI': 2361,\n 'MMCCCLXII': 2362,\n 'MMCCCLXIII': 2363,\n 'MMCCCLXIV': 2364,\n 'MMCCCLXIX': 2369,\n 'MMCCCLXV': 2365,\n 'MMCCCLXVI': 2366,\n 'MMCCCLXVII': 2367,\n 'MMCCCLXVIII': 2368,\n 'MMCCCLXX': 2370,\n 'MMCCCLXXI': 2371,\n 'MMCCCLXXII': 2372,\n 'MMCCCLXXIII': 2373,\n 'MMCCCLXXIV': 2374,\n 'MMCCCLXXIX': 2379,\n 'MMCCCLXXV': 2375,\n 'MMCCCLXXVI': 2376,\n 'MMCCCLXXVII': 2377,\n 'MMCCCLXXVIII': 2378,\n 'MMCCCLXXX': 2380,\n 'MMCCCLXXXI': 2381,\n 'MMCCCLXXXII': 2382,\n 'MMCCCLXXXIII': 2383,\n 'MMCCCLXXXIV': 2384,\n 'MMCCCLXXXIX': 2389,\n 'MMCCCLXXXV': 2385,\n 'MMCCCLXXXVI': 2386,\n 'MMCCCLXXXVII': 2387,\n 'MMCCCLXXXVIII': 2388,\n 'MMCCCV': 2305,\n 'MMCCCVI': 2306,\n 'MMCCCVII': 2307,\n 'MMCCCVIII': 2308,\n 'MMCCCX': 2310,\n 'MMCCCXC': 2390,\n 'MMCCCXCI': 2391,\n 'MMCCCXCII': 2392,\n 'MMCCCXCIII': 2393,\n 'MMCCCXCIV': 2394,\n 'MMCCCXCIX': 2399,\n 'MMCCCXCV': 2395,\n 'MMCCCXCVI': 2396,\n 'MMCCCXCVII': 2397,\n 'MMCCCXCVIII': 2398,\n 'MMCCCXI': 2311,\n 'MMCCCXII': 2312,\n 'MMCCCXIII': 2313,\n 'MMCCCXIV': 2314,\n 'MMCCCXIX': 2319,\n 'MMCCCXL': 2340,\n 'MMCCCXLI': 2341,\n 'MMCCCXLII': 2342,\n 'MMCCCXLIII': 2343,\n 'MMCCCXLIV': 2344,\n 'MMCCCXLIX': 2349,\n 'MMCCCXLV': 2345,\n 'MMCCCXLVI': 2346,\n 'MMCCCXLVII': 2347,\n 'MMCCCXLVIII': 2348,\n 'MMCCCXV': 2315,\n 'MMCCCXVI': 2316,\n 'MMCCCXVII': 2317,\n 'MMCCCXVIII': 2318,\n 'MMCCCXX': 2320,\n 'MMCCCXXI': 2321,\n 'MMCCCXXII': 2322,\n 'MMCCCXXIII': 2323,\n 'MMCCCXXIV': 2324,\n 'MMCCCXXIX': 2329,\n 'MMCCCXXV': 2325,\n 'MMCCCXXVI': 2326,\n 'MMCCCXXVII': 2327,\n 'MMCCCXXVIII': 2328,\n 'MMCCCXXX': 2330,\n 'MMCCCXXXI': 2331,\n 'MMCCCXXXII': 2332,\n 'MMCCCXXXIII': 2333,\n 'MMCCCXXXIV': 2334,\n 'MMCCCXXXIX': 2339,\n 'MMCCCXXXV': 2335,\n 'MMCCCXXXVI': 2336,\n 'MMCCCXXXVII': 2337,\n 'MMCCCXXXVIII': 2338,\n 'MMCCI': 2201,\n 'MMCCII': 2202,\n 'MMCCIII': 2203,\n 'MMCCIV': 2204,\n 'MMCCIX': 2209,\n 'MMCCL': 2250,\n 'MMCCLI': 2251,\n 'MMCCLII': 2252,\n 'MMCCLIII': 2253,\n 'MMCCLIV': 2254,\n 'MMCCLIX': 2259,\n 'MMCCLV': 2255,\n 'MMCCLVI': 2256,\n 'MMCCLVII': 2257,\n 'MMCCLVIII': 2258,\n 'MMCCLX': 2260,\n 'MMCCLXI': 2261,\n 'MMCCLXII': 2262,\n 'MMCCLXIII': 2263,\n 'MMCCLXIV': 2264,\n 'MMCCLXIX': 2269,\n 'MMCCLXV': 2265,\n 'MMCCLXVI': 2266,\n 'MMCCLXVII': 2267,\n 'MMCCLXVIII': 2268,\n 'MMCCLXX': 2270,\n 'MMCCLXXI': 2271,\n 'MMCCLXXII': 2272,\n 'MMCCLXXIII': 2273,\n 'MMCCLXXIV': 2274,\n 'MMCCLXXIX': 2279,\n 'MMCCLXXV': 2275,\n 'MMCCLXXVI': 2276,\n 'MMCCLXXVII': 2277,\n 'MMCCLXXVIII': 2278,\n 'MMCCLXXX': 2280,\n 'MMCCLXXXI': 2281,\n 'MMCCLXXXII': 2282,\n 'MMCCLXXXIII': 2283,\n 'MMCCLXXXIV': 2284,\n 'MMCCLXXXIX': 2289,\n 'MMCCLXXXV': 2285,\n 'MMCCLXXXVI': 2286,\n 'MMCCLXXXVII': 2287,\n 'MMCCLXXXVIII': 2288,\n 'MMCCV': 2205,\n 'MMCCVI': 2206,\n 'MMCCVII': 2207,\n 'MMCCVIII': 2208,\n 'MMCCX': 2210,\n 'MMCCXC': 2290,\n 'MMCCXCI': 2291,\n 'MMCCXCII': 2292,\n 'MMCCXCIII': 2293,\n 'MMCCXCIV': 2294,\n 'MMCCXCIX': 2299,\n 'MMCCXCV': 2295,\n 'MMCCXCVI': 2296,\n 'MMCCXCVII': 2297,\n 'MMCCXCVIII': 2298,\n 'MMCCXI': 2211,\n 'MMCCXII': 2212,\n 'MMCCXIII': 2213,\n 'MMCCXIV': 2214,\n 'MMCCXIX': 2219,\n 'MMCCXL': 2240,\n 'MMCCXLI': 2241,\n 'MMCCXLII': 2242,\n 'MMCCXLIII': 2243,\n 'MMCCXLIV': 2244,\n 'MMCCXLIX': 2249,\n 'MMCCXLV': 2245,\n 'MMCCXLVI': 2246,\n 'MMCCXLVII': 2247,\n 'MMCCXLVIII': 2248,\n 'MMCCXV': 2215,\n 'MMCCXVI': 2216,\n 'MMCCXVII': 2217,\n 'MMCCXVIII': 2218,\n 'MMCCXX': 2220,\n 'MMCCXXI': 2221,\n 'MMCCXXII': 2222,\n 'MMCCXXIII': 2223,\n 'MMCCXXIV': 2224,\n 'MMCCXXIX': 2229,\n 'MMCCXXV': 2225,\n 'MMCCXXVI': 2226,\n 'MMCCXXVII': 2227,\n 'MMCCXXVIII': 2228,\n 'MMCCXXX': 2230,\n 'MMCCXXXI': 2231,\n 'MMCCXXXII': 2232,\n 'MMCCXXXIII': 2233,\n 'MMCCXXXIV': 2234,\n 'MMCCXXXIX': 2239,\n 'MMCCXXXV': 2235,\n 'MMCCXXXVI': 2236,\n 'MMCCXXXVII': 2237,\n 'MMCCXXXVIII': 2238,\n 'MMCD': 2400,\n 'MMCDI': 2401,\n 'MMCDII': 2402,\n 'MMCDIII': 2403,\n 'MMCDIV': 2404,\n 'MMCDIX': 2409,\n 'MMCDL': 2450,\n 'MMCDLI': 2451,\n 'MMCDLII': 2452,\n 'MMCDLIII': 2453,\n 'MMCDLIV': 2454,\n 'MMCDLIX': 2459,\n 'MMCDLV': 2455,\n 'MMCDLVI': 2456,\n 'MMCDLVII': 2457,\n 'MMCDLVIII': 2458,\n 'MMCDLX': 2460,\n 'MMCDLXI': 2461,\n 'MMCDLXII': 2462,\n 'MMCDLXIII': 2463,\n 'MMCDLXIV': 2464,\n 'MMCDLXIX': 2469,\n 'MMCDLXV': 2465,\n 'MMCDLXVI': 2466,\n 'MMCDLXVII': 2467,\n 'MMCDLXVIII': 2468,\n 'MMCDLXX': 2470,\n 'MMCDLXXI': 2471,\n 'MMCDLXXII': 2472,\n 'MMCDLXXIII': 2473,\n 'MMCDLXXIV': 2474,\n 'MMCDLXXIX': 2479,\n 'MMCDLXXV': 2475,\n 'MMCDLXXVI': 2476,\n 'MMCDLXXVII': 2477,\n 'MMCDLXXVIII': 2478,\n 'MMCDLXXX': 2480,\n 'MMCDLXXXI': 2481,\n 'MMCDLXXXII': 2482,\n 'MMCDLXXXIII': 2483,\n 'MMCDLXXXIV': 2484,\n 'MMCDLXXXIX': 2489,\n 'MMCDLXXXV': 2485,\n 'MMCDLXXXVI': 2486,\n 'MMCDLXXXVII': 2487,\n 'MMCDLXXXVIII': 2488,\n 'MMCDV': 2405,\n 'MMCDVI': 2406,\n 'MMCDVII': 2407,\n 'MMCDVIII': 2408,\n 'MMCDX': 2410,\n 'MMCDXC': 2490,\n 'MMCDXCI': 2491,\n 'MMCDXCII': 2492,\n 'MMCDXCIII': 2493,\n 'MMCDXCIV': 2494,\n 'MMCDXCIX': 2499,\n 'MMCDXCV': 2495,\n 'MMCDXCVI': 2496,\n 'MMCDXCVII': 2497,\n 'MMCDXCVIII': 2498,\n 'MMCDXI': 2411,\n 'MMCDXII': 2412,\n 'MMCDXIII': 2413,\n 'MMCDXIV': 2414,\n 'MMCDXIX': 2419,\n 'MMCDXL': 2440,\n 'MMCDXLI': 2441,\n 'MMCDXLII': 2442,\n 'MMCDXLIII': 2443,\n 'MMCDXLIV': 2444,\n 'MMCDXLIX': 2449,\n 'MMCDXLV': 2445,\n 'MMCDXLVI': 2446,\n 'MMCDXLVII': 2447,\n 'MMCDXLVIII': 2448,\n 'MMCDXV': 2415,\n 'MMCDXVI': 2416,\n 'MMCDXVII': 2417,\n 'MMCDXVIII': 2418,\n 'MMCDXX': 2420,\n 'MMCDXXI': 2421,\n 'MMCDXXII': 2422,\n 'MMCDXXIII': 2423,\n 'MMCDXXIV': 2424,\n 'MMCDXXIX': 2429,\n 'MMCDXXV': 2425,\n 'MMCDXXVI': 2426,\n 'MMCDXXVII': 2427,\n 'MMCDXXVIII': 2428,\n 'MMCDXXX': 2430,\n 'MMCDXXXI': 2431,\n 'MMCDXXXII': 2432,\n 'MMCDXXXIII': 2433,\n 'MMCDXXXIV': 2434,\n 'MMCDXXXIX': 2439,\n 'MMCDXXXV': 2435,\n 'MMCDXXXVI': 2436,\n 'MMCDXXXVII': 2437,\n 'MMCDXXXVIII': 2438,\n 'MMCI': 2101,\n 'MMCII': 2102,\n 'MMCIII': 2103,\n 'MMCIV': 2104,\n 'MMCIX': 2109,\n 'MMCL': 2150,\n 'MMCLI': 2151,\n 'MMCLII': 2152,\n 'MMCLIII': 2153,\n 'MMCLIV': 2154,\n 'MMCLIX': 2159,\n 'MMCLV': 2155,\n 'MMCLVI': 2156,\n 'MMCLVII': 2157,\n 'MMCLVIII': 2158,\n 'MMCLX': 2160,\n 'MMCLXI': 2161,\n 'MMCLXII': 2162,\n 'MMCLXIII': 2163,\n 'MMCLXIV': 2164,\n 'MMCLXIX': 2169,\n 'MMCLXV': 2165,\n 'MMCLXVI': 2166,\n 'MMCLXVII': 2167,\n 'MMCLXVIII': 2168,\n 'MMCLXX': 2170,\n 'MMCLXXI': 2171,\n 'MMCLXXII': 2172,\n 'MMCLXXIII': 2173,\n 'MMCLXXIV': 2174,\n 'MMCLXXIX': 2179,\n 'MMCLXXV': 2175,\n 'MMCLXXVI': 2176,\n 'MMCLXXVII': 2177,\n 'MMCLXXVIII': 2178,\n 'MMCLXXX': 2180,\n 'MMCLXXXI': 2181,\n 'MMCLXXXII': 2182,\n 'MMCLXXXIII': 2183,\n 'MMCLXXXIV': 2184,\n 'MMCLXXXIX': 2189,\n 'MMCLXXXV': 2185,\n 'MMCLXXXVI': 2186,\n 'MMCLXXXVII': 2187,\n 'MMCLXXXVIII': 2188,\n 'MMCM': 2900,\n 'MMCMI': 2901,\n 'MMCMII': 2902,\n 'MMCMIII': 2903,\n 'MMCMIV': 2904,\n 'MMCMIX': 2909,\n 'MMCML': 2950,\n 'MMCMLI': 2951,\n 'MMCMLII': 2952,\n 'MMCMLIII': 2953,\n 'MMCMLIV': 2954,\n 'MMCMLIX': 2959,\n 'MMCMLV': 2955,\n 'MMCMLVI': 2956,\n 'MMCMLVII': 2957,\n 'MMCMLVIII': 2958,\n 'MMCMLX': 2960,\n 'MMCMLXI': 2961,\n 'MMCMLXII': 2962,\n 'MMCMLXIII': 2963,\n 'MMCMLXIV': 2964,\n 'MMCMLXIX': 2969,\n 'MMCMLXV': 2965,\n 'MMCMLXVI': 2966,\n 'MMCMLXVII': 2967,\n 'MMCMLXVIII': 2968,\n 'MMCMLXX': 2970,\n 'MMCMLXXI': 2971,\n 'MMCMLXXII': 2972,\n 'MMCMLXXIII': 2973,\n 'MMCMLXXIV': 2974,\n 'MMCMLXXIX': 2979,\n 'MMCMLXXV': 2975,\n 'MMCMLXXVI': 2976,\n 'MMCMLXXVII': 2977,\n 'MMCMLXXVIII': 2978,\n 'MMCMLXXX': 2980,\n 'MMCMLXXXI': 2981,\n 'MMCMLXXXII': 2982,\n 'MMCMLXXXIII': 2983,\n 'MMCMLXXXIV': 2984,\n 'MMCMLXXXIX': 2989,\n 'MMCMLXXXV': 2985,\n 'MMCMLXXXVI': 2986,\n 'MMCMLXXXVII': 2987,\n 'MMCMLXXXVIII': 2988,\n 'MMCMV': 2905,\n 'MMCMVI': 2906,\n 'MMCMVII': 2907,\n 'MMCMVIII': 2908,\n 'MMCMX': 2910,\n 'MMCMXC': 2990,\n 'MMCMXCI': 2991,\n 'MMCMXCII': 2992,\n 'MMCMXCIII': 2993,\n 'MMCMXCIV': 2994,\n 'MMCMXCIX': 2999,\n 'MMCMXCV': 2995,\n 'MMCMXCVI': 2996,\n 'MMCMXCVII': 2997,\n 'MMCMXCVIII': 2998,\n 'MMCMXI': 2911,\n 'MMCMXII': 2912,\n 'MMCMXIII': 2913,\n 'MMCMXIV': 2914,\n 'MMCMXIX': 2919,\n 'MMCMXL': 2940,\n 'MMCMXLI': 2941,\n 'MMCMXLII': 2942,\n 'MMCMXLIII': 2943,\n 'MMCMXLIV': 2944,\n 'MMCMXLIX': 2949,\n 'MMCMXLV': 2945,\n 'MMCMXLVI': 2946,\n 'MMCMXLVII': 2947,\n 'MMCMXLVIII': 2948,\n 'MMCMXV': 2915,\n 'MMCMXVI': 2916,\n 'MMCMXVII': 2917,\n 'MMCMXVIII': 2918,\n 'MMCMXX': 2920,\n 'MMCMXXI': 2921,\n 'MMCMXXII': 2922,\n 'MMCMXXIII': 2923,\n 'MMCMXXIV': 2924,\n 'MMCMXXIX': 2929,\n 'MMCMXXV': 2925,\n 'MMCMXXVI': 2926,\n 'MMCMXXVII': 2927,\n 'MMCMXXVIII': 2928,\n 'MMCMXXX': 2930,\n 'MMCMXXXI': 2931,\n 'MMCMXXXII': 2932,\n 'MMCMXXXIII': 2933,\n 'MMCMXXXIV': 2934,\n 'MMCMXXXIX': 2939,\n 'MMCMXXXV': 2935,\n 'MMCMXXXVI': 2936,\n 'MMCMXXXVII': 2937,\n 'MMCMXXXVIII': 2938,\n 'MMCV': 2105,\n 'MMCVI': 2106,\n 'MMCVII': 2107,\n 'MMCVIII': 2108,\n 'MMCX': 2110,\n 'MMCXC': 2190,\n 'MMCXCI': 2191,\n 'MMCXCII': 2192,\n 'MMCXCIII': 2193,\n 'MMCXCIV': 2194,\n 'MMCXCIX': 2199,\n 'MMCXCV': 2195,\n 'MMCXCVI': 2196,\n 'MMCXCVII': 2197,\n 'MMCXCVIII': 2198,\n 'MMCXI': 2111,\n 'MMCXII': 2112,\n 'MMCXIII': 2113,\n 'MMCXIV': 2114,\n 'MMCXIX': 2119,\n 'MMCXL': 2140,\n 'MMCXLI': 2141,\n 'MMCXLII': 2142,\n 'MMCXLIII': 2143,\n 'MMCXLIV': 2144,\n 'MMCXLIX': 2149,\n 'MMCXLV': 2145,\n 'MMCXLVI': 2146,\n 'MMCXLVII': 2147,\n 'MMCXLVIII': 2148,\n 'MMCXV': 2115,\n 'MMCXVI': 2116,\n 'MMCXVII': 2117,\n 'MMCXVIII': 2118,\n 'MMCXX': 2120,\n 'MMCXXI': 2121,\n 'MMCXXII': 2122,\n 'MMCXXIII': 2123,\n 'MMCXXIV': 2124,\n 'MMCXXIX': 2129,\n 'MMCXXV': 2125,\n 'MMCXXVI': 2126,\n 'MMCXXVII': 2127,\n 'MMCXXVIII': 2128,\n 'MMCXXX': 2130,\n 'MMCXXXI': 2131,\n 'MMCXXXII': 2132,\n 'MMCXXXIII': 2133,\n 'MMCXXXIV': 2134,\n 'MMCXXXIX': 2139,\n 'MMCXXXV': 2135,\n 'MMCXXXVI': 2136,\n 'MMCXXXVII': 2137,\n 'MMCXXXVIII': 2138,\n 'MMD': 2500,\n 'MMDC': 2600,\n 'MMDCC': 2700,\n 'MMDCCC': 2800,\n 'MMDCCCI': 2801,\n 'MMDCCCII': 2802,\n 'MMDCCCIII': 2803,\n 'MMDCCCIV': 2804,\n 'MMDCCCIX': 2809,\n 'MMDCCCL': 2850,\n 'MMDCCCLI': 2851,\n 'MMDCCCLII': 2852,\n 'MMDCCCLIII': 2853,\n 'MMDCCCLIV': 2854,\n 'MMDCCCLIX': 2859,\n 'MMDCCCLV': 2855,\n 'MMDCCCLVI': 2856,\n 'MMDCCCLVII': 2857,\n 'MMDCCCLVIII': 2858,\n 'MMDCCCLX': 2860,\n 'MMDCCCLXI': 2861,\n 'MMDCCCLXII': 2862,\n 'MMDCCCLXIII': 2863,\n 'MMDCCCLXIV': 2864,\n 'MMDCCCLXIX': 2869,\n 'MMDCCCLXV': 2865,\n 'MMDCCCLXVI': 2866,\n 'MMDCCCLXVII': 2867,\n 'MMDCCCLXVIII': 2868,\n 'MMDCCCLXX': 2870,\n 'MMDCCCLXXI': 2871,\n 'MMDCCCLXXII': 2872,\n 'MMDCCCLXXIII': 2873,\n 'MMDCCCLXXIV': 2874,\n 'MMDCCCLXXIX': 2879,\n 'MMDCCCLXXV': 2875,\n 'MMDCCCLXXVI': 2876,\n 'MMDCCCLXXVII': 2877,\n 'MMDCCCLXXVIII': 2878,\n 'MMDCCCLXXX': 2880,\n 'MMDCCCLXXXI': 2881,\n 'MMDCCCLXXXII': 2882,\n 'MMDCCCLXXXIII': 2883,\n 'MMDCCCLXXXIV': 2884,\n 'MMDCCCLXXXIX': 2889,\n 'MMDCCCLXXXV': 2885,\n 'MMDCCCLXXXVI': 2886,\n 'MMDCCCLXXXVII': 2887,\n 'MMDCCCLXXXVIII': 2888,\n 'MMDCCCV': 2805,\n 'MMDCCCVI': 2806,\n 'MMDCCCVII': 2807,\n 'MMDCCCVIII': 2808,\n 'MMDCCCX': 2810,\n 'MMDCCCXC': 2890,\n 'MMDCCCXCI': 2891,\n 'MMDCCCXCII': 2892,\n 'MMDCCCXCIII': 2893,\n 'MMDCCCXCIV': 2894,\n 'MMDCCCXCIX': 2899,\n 'MMDCCCXCV': 2895,\n 'MMDCCCXCVI': 2896,\n 'MMDCCCXCVII': 2897,\n 'MMDCCCXCVIII': 2898,\n 'MMDCCCXI': 2811,\n 'MMDCCCXII': 2812,\n 'MMDCCCXIII': 2813,\n 'MMDCCCXIV': 2814,\n 'MMDCCCXIX': 2819,\n 'MMDCCCXL': 2840,\n 'MMDCCCXLI': 2841,\n 'MMDCCCXLII': 2842,\n 'MMDCCCXLIII': 2843,\n 'MMDCCCXLIV': 2844,\n 'MMDCCCXLIX': 2849,\n 'MMDCCCXLV': 2845,\n 'MMDCCCXLVI': 2846,\n 'MMDCCCXLVII': 2847,\n 'MMDCCCXLVIII': 2848,\n 'MMDCCCXV': 2815,\n 'MMDCCCXVI': 2816,\n 'MMDCCCXVII': 2817,\n 'MMDCCCXVIII': 2818,\n 'MMDCCCXX': 2820,\n 'MMDCCCXXI': 2821,\n 'MMDCCCXXII': 2822,\n 'MMDCCCXXIII': 2823,\n 'MMDCCCXXIV': 2824,\n 'MMDCCCXXIX': 2829,\n 'MMDCCCXXV': 2825,\n 'MMDCCCXXVI': 2826,\n 'MMDCCCXXVII': 2827,\n 'MMDCCCXXVIII': 2828,\n 'MMDCCCXXX': 2830,\n 'MMDCCCXXXI': 2831,\n 'MMDCCCXXXII': 2832,\n 'MMDCCCXXXIII': 2833,\n 'MMDCCCXXXIV': 2834,\n 'MMDCCCXXXIX': 2839,\n 'MMDCCCXXXV': 2835,\n 'MMDCCCXXXVI': 2836,\n 'MMDCCCXXXVII': 2837,\n 'MMDCCCXXXVIII': 2838,\n 'MMDCCI': 2701,\n 'MMDCCII': 2702,\n 'MMDCCIII': 2703,\n 'MMDCCIV': 2704,\n 'MMDCCIX': 2709,\n 'MMDCCL': 2750,\n 'MMDCCLI': 2751,\n 'MMDCCLII': 2752,\n 'MMDCCLIII': 2753,\n 'MMDCCLIV': 2754,\n 'MMDCCLIX': 2759,\n 'MMDCCLV': 2755,\n 'MMDCCLVI': 2756,\n 'MMDCCLVII': 2757,\n 'MMDCCLVIII': 2758,\n 'MMDCCLX': 2760,\n 'MMDCCLXI': 2761,\n 'MMDCCLXII': 2762,\n 'MMDCCLXIII': 2763,\n 'MMDCCLXIV': 2764,\n 'MMDCCLXIX': 2769,\n 'MMDCCLXV': 2765,\n 'MMDCCLXVI': 2766,\n 'MMDCCLXVII': 2767,\n 'MMDCCLXVIII': 2768,\n 'MMDCCLXX': 2770,\n 'MMDCCLXXI': 2771,\n 'MMDCCLXXII': 2772,\n 'MMDCCLXXIII': 2773,\n 'MMDCCLXXIV': 2774,\n 'MMDCCLXXIX': 2779,\n 'MMDCCLXXV': 2775,\n 'MMDCCLXXVI': 2776,\n 'MMDCCLXXVII': 2777,\n 'MMDCCLXXVIII': 2778,\n 'MMDCCLXXX': 2780,\n 'MMDCCLXXXI': 2781,\n 'MMDCCLXXXII': 2782,\n 'MMDCCLXXXIII': 2783,\n 'MMDCCLXXXIV': 2784,\n 'MMDCCLXXXIX': 2789,\n 'MMDCCLXXXV': 2785,\n 'MMDCCLXXXVI': 2786,\n 'MMDCCLXXXVII': 2787,\n 'MMDCCLXXXVIII': 2788,\n 'MMDCCV': 2705,\n 'MMDCCVI': 2706,\n 'MMDCCVII': 2707,\n 'MMDCCVIII': 2708,\n 'MMDCCX': 2710,\n 'MMDCCXC': 2790,\n 'MMDCCXCI': 2791,\n 'MMDCCXCII': 2792,\n 'MMDCCXCIII': 2793,\n 'MMDCCXCIV': 2794,\n 'MMDCCXCIX': 2799,\n 'MMDCCXCV': 2795,\n 'MMDCCXCVI': 2796,\n 'MMDCCXCVII': 2797,\n 'MMDCCXCVIII': 2798,\n 'MMDCCXI': 2711,\n 'MMDCCXII': 2712,\n 'MMDCCXIII': 2713,\n 'MMDCCXIV': 2714,\n 'MMDCCXIX': 2719,\n 'MMDCCXL': 2740,\n 'MMDCCXLI': 2741,\n 'MMDCCXLII': 2742,\n 'MMDCCXLIII': 2743,\n 'MMDCCXLIV': 2744,\n 'MMDCCXLIX': 2749,\n 'MMDCCXLV': 2745,\n 'MMDCCXLVI': 2746,\n 'MMDCCXLVII': 2747,\n 'MMDCCXLVIII': 2748,\n 'MMDCCXV': 2715,\n 'MMDCCXVI': 2716,\n 'MMDCCXVII': 2717,\n 'MMDCCXVIII': 2718,\n 'MMDCCXX': 2720,\n 'MMDCCXXI': 2721,\n 'MMDCCXXII': 2722,\n 'MMDCCXXIII': 2723,\n 'MMDCCXXIV': 2724,\n 'MMDCCXXIX': 2729,\n 'MMDCCXXV': 2725,\n 'MMDCCXXVI': 2726,\n 'MMDCCXXVII': 2727,\n 'MMDCCXXVIII': 2728,\n 'MMDCCXXX': 2730,\n 'MMDCCXXXI': 2731,\n 'MMDCCXXXII': 2732,\n 'MMDCCXXXIII': 2733,\n 'MMDCCXXXIV': 2734,\n 'MMDCCXXXIX': 2739,\n 'MMDCCXXXV': 2735,\n 'MMDCCXXXVI': 2736,\n 'MMDCCXXXVII': 2737,\n 'MMDCCXXXVIII': 2738,\n 'MMDCI': 2601,\n 'MMDCII': 2602,\n 'MMDCIII': 2603,\n 'MMDCIV': 2604,\n 'MMDCIX': 2609,\n 'MMDCL': 2650,\n 'MMDCLI': 2651,\n 'MMDCLII': 2652,\n 'MMDCLIII': 2653,\n 'MMDCLIV': 2654,\n 'MMDCLIX': 2659,\n 'MMDCLV': 2655,\n 'MMDCLVI': 2656,\n 'MMDCLVII': 2657,\n 'MMDCLVIII': 2658,\n 'MMDCLX': 2660,\n 'MMDCLXI': 2661,\n 'MMDCLXII': 2662,\n 'MMDCLXIII': 2663,\n 'MMDCLXIV': 2664,\n 'MMDCLXIX': 2669,\n 'MMDCLXV': 2665,\n 'MMDCLXVI': 2666,\n 'MMDCLXVII': 2667,\n 'MMDCLXVIII': 2668,\n 'MMDCLXX': 2670,\n 'MMDCLXXI': 2671,\n 'MMDCLXXII': 2672,\n 'MMDCLXXIII': 2673,\n 'MMDCLXXIV': 2674,\n 'MMDCLXXIX': 2679,\n 'MMDCLXXV': 2675,\n 'MMDCLXXVI': 2676,\n 'MMDCLXXVII': 2677,\n 'MMDCLXXVIII': 2678,\n 'MMDCLXXX': 2680,\n 'MMDCLXXXI': 2681,\n 'MMDCLXXXII': 2682,\n 'MMDCLXXXIII': 2683,\n 'MMDCLXXXIV': 2684,\n 'MMDCLXXXIX': 2689,\n 'MMDCLXXXV': 2685,\n 'MMDCLXXXVI': 2686,\n 'MMDCLXXXVII': 2687,\n 'MMDCLXXXVIII': 2688,\n 'MMDCV': 2605,\n 'MMDCVI': 2606,\n 'MMDCVII': 2607,\n 'MMDCVIII': 2608,\n 'MMDCX': 2610,\n 'MMDCXC': 2690,\n 'MMDCXCI': 2691,\n 'MMDCXCII': 2692,\n 'MMDCXCIII': 2693,\n 'MMDCXCIV': 2694,\n 'MMDCXCIX': 2699,\n 'MMDCXCV': 2695,\n 'MMDCXCVI': 2696,\n 'MMDCXCVII': 2697,\n 'MMDCXCVIII': 2698,\n 'MMDCXI': 2611,\n 'MMDCXII': 2612,\n 'MMDCXIII': 2613,\n 'MMDCXIV': 2614,\n 'MMDCXIX': 2619,\n 'MMDCXL': 2640,\n 'MMDCXLI': 2641,\n 'MMDCXLII': 2642,\n 'MMDCXLIII': 2643,\n 'MMDCXLIV': 2644,\n 'MMDCXLIX': 2649,\n 'MMDCXLV': 2645,\n 'MMDCXLVI': 2646,\n 'MMDCXLVII': 2647,\n 'MMDCXLVIII': 2648,\n 'MMDCXV': 2615,\n 'MMDCXVI': 2616,\n 'MMDCXVII': 2617,\n 'MMDCXVIII': 2618,\n 'MMDCXX': 2620,\n 'MMDCXXI': 2621,\n 'MMDCXXII': 2622,\n 'MMDCXXIII': 2623,\n 'MMDCXXIV': 2624,\n 'MMDCXXIX': 2629,\n 'MMDCXXV': 2625,\n 'MMDCXXVI': 2626,\n 'MMDCXXVII': 2627,\n 'MMDCXXVIII': 2628,\n 'MMDCXXX': 2630,\n 'MMDCXXXI': 2631,\n 'MMDCXXXII': 2632,\n 'MMDCXXXIII': 2633,\n 'MMDCXXXIV': 2634,\n 'MMDCXXXIX': 2639,\n 'MMDCXXXV': 2635,\n 'MMDCXXXVI': 2636,\n 'MMDCXXXVII': 2637,\n 'MMDCXXXVIII': 2638,\n 'MMDI': 2501,\n 'MMDII': 2502,\n 'MMDIII': 2503,\n 'MMDIV': 2504,\n 'MMDIX': 2509,\n 'MMDL': 2550,\n 'MMDLI': 2551,\n 'MMDLII': 2552,\n 'MMDLIII': 2553,\n 'MMDLIV': 2554,\n 'MMDLIX': 2559,\n 'MMDLV': 2555,\n 'MMDLVI': 2556,\n 'MMDLVII': 2557,\n 'MMDLVIII': 2558,\n 'MMDLX': 2560,\n 'MMDLXI': 2561,\n 'MMDLXII': 2562,\n 'MMDLXIII': 2563,\n 'MMDLXIV': 2564,\n 'MMDLXIX': 2569,\n 'MMDLXV': 2565,\n 'MMDLXVI': 2566,\n 'MMDLXVII': 2567,\n 'MMDLXVIII': 2568,\n 'MMDLXX': 2570,\n 'MMDLXXI': 2571,\n 'MMDLXXII': 2572,\n 'MMDLXXIII': 2573,\n 'MMDLXXIV': 2574,\n 'MMDLXXIX': 2579,\n 'MMDLXXV': 2575,\n 'MMDLXXVI': 2576,\n 'MMDLXXVII': 2577,\n 'MMDLXXVIII': 2578,\n 'MMDLXXX': 2580,\n 'MMDLXXXI': 2581,\n 'MMDLXXXII': 2582,\n 'MMDLXXXIII': 2583,\n 'MMDLXXXIV': 2584,\n 'MMDLXXXIX': 2589,\n 'MMDLXXXV': 2585,\n 'MMDLXXXVI': 2586,\n 'MMDLXXXVII': 2587,\n 'MMDLXXXVIII': 2588,\n 'MMDV': 2505,\n 'MMDVI': 2506,\n 'MMDVII': 2507,\n 'MMDVIII': 2508,\n 'MMDX': 2510,\n 'MMDXC': 2590,\n 'MMDXCI': 2591,\n 'MMDXCII': 2592,\n 'MMDXCIII': 2593,\n 'MMDXCIV': 2594,\n 'MMDXCIX': 2599,\n 'MMDXCV': 2595,\n 'MMDXCVI': 2596,\n 'MMDXCVII': 2597,\n 'MMDXCVIII': 2598,\n 'MMDXI': 2511,\n 'MMDXII': 2512,\n 'MMDXIII': 2513,\n 'MMDXIV': 2514,\n 'MMDXIX': 2519,\n 'MMDXL': 2540,\n 'MMDXLI': 2541,\n 'MMDXLII': 2542,\n 'MMDXLIII': 2543,\n 'MMDXLIV': 2544,\n 'MMDXLIX': 2549,\n 'MMDXLV': 2545,\n 'MMDXLVI': 2546,\n 'MMDXLVII': 2547,\n 'MMDXLVIII': 2548,\n 'MMDXV': 2515,\n 'MMDXVI': 2516,\n 'MMDXVII': 2517,\n 'MMDXVIII': 2518,\n 'MMDXX': 2520,\n 'MMDXXI': 2521,\n 'MMDXXII': 2522,\n 'MMDXXIII': 2523,\n 'MMDXXIV': 2524,\n 'MMDXXIX': 2529,\n 'MMDXXV': 2525,\n 'MMDXXVI': 2526,\n 'MMDXXVII': 2527,\n 'MMDXXVIII': 2528,\n 'MMDXXX': 2530,\n 'MMDXXXI': 2531,\n 'MMDXXXII': 2532,\n 'MMDXXXIII': 2533,\n 'MMDXXXIV': 2534,\n 'MMDXXXIX': 2539,\n 'MMDXXXV': 2535,\n 'MMDXXXVI': 2536,\n 'MMDXXXVII': 2537,\n 'MMDXXXVIII': 2538,\n 'MMI': 2001,\n 'MMII': 2002,\n 'MMIII': 2003,\n 'MMIV': 2004,\n 'MMIX': 2009,\n 'MML': 2050,\n 'MMLI': 2051,\n 'MMLII': 2052,\n 'MMLIII': 2053,\n 'MMLIV': 2054,\n 'MMLIX': 2059,\n 'MMLV': 2055,\n 'MMLVI': 2056,\n 'MMLVII': 2057,\n 'MMLVIII': 2058,\n 'MMLX': 2060,\n 'MMLXI': 2061,\n 'MMLXII': 2062,\n 'MMLXIII': 2063,\n 'MMLXIV': 2064,\n 'MMLXIX': 2069,\n 'MMLXV': 2065,\n 'MMLXVI': 2066,\n 'MMLXVII': 2067,\n 'MMLXVIII': 2068,\n 'MMLXX': 2070,\n 'MMLXXI': 2071,\n 'MMLXXII': 2072,\n 'MMLXXIII': 2073,\n 'MMLXXIV': 2074,\n 'MMLXXIX': 2079,\n 'MMLXXV': 2075,\n 'MMLXXVI': 2076,\n 'MMLXXVII': 2077,\n 'MMLXXVIII': 2078,\n 'MMLXXX': 2080,\n 'MMLXXXI': 2081,\n 'MMLXXXII': 2082,\n 'MMLXXXIII': 2083,\n 'MMLXXXIV': 2084,\n 'MMLXXXIX': 2089,\n 'MMLXXXV': 2085,\n 'MMLXXXVI': 2086,\n 'MMLXXXVII': 2087,\n 'MMLXXXVIII': 2088,\n 'MMM': 3000,\n 'MMMC': 3100,\n 'MMMCC': 3200,\n 'MMMCCC': 3300,\n 'MMMCCCI': 3301,\n 'MMMCCCII': 3302,\n 'MMMCCCIII': 3303,\n 'MMMCCCIV': 3304,\n 'MMMCCCIX': 3309,\n 'MMMCCCL': 3350,\n 'MMMCCCLI': 3351,\n 'MMMCCCLII': 3352,\n 'MMMCCCLIII': 3353,\n 'MMMCCCLIV': 3354,\n 'MMMCCCLIX': 3359,\n 'MMMCCCLV': 3355,\n 'MMMCCCLVI': 3356,\n 'MMMCCCLVII': 3357,\n 'MMMCCCLVIII': 3358,\n 'MMMCCCLX': 3360,\n 'MMMCCCLXI': 3361,\n 'MMMCCCLXII': 3362,\n 'MMMCCCLXIII': 3363,\n 'MMMCCCLXIV': 3364,\n 'MMMCCCLXIX': 3369,\n 'MMMCCCLXV': 3365,\n 'MMMCCCLXVI': 3366,\n 'MMMCCCLXVII': 3367,\n 'MMMCCCLXVIII': 3368,\n 'MMMCCCLXX': 3370,\n 'MMMCCCLXXI': 3371,\n 'MMMCCCLXXII': 3372,\n 'MMMCCCLXXIII': 3373,\n 'MMMCCCLXXIV': 3374,\n 'MMMCCCLXXIX': 3379,\n 'MMMCCCLXXV': 3375,\n 'MMMCCCLXXVI': 3376,\n 'MMMCCCLXXVII': 3377,\n 'MMMCCCLXXVIII': 3378,\n 'MMMCCCLXXX': 3380,\n 'MMMCCCLXXXI': 3381,\n 'MMMCCCLXXXII': 3382,\n 'MMMCCCLXXXIII': 3383,\n 'MMMCCCLXXXIV': 3384,\n 'MMMCCCLXXXIX': 3389,\n 'MMMCCCLXXXV': 3385,\n 'MMMCCCLXXXVI': 3386,\n 'MMMCCCLXXXVII': 3387,\n 'MMMCCCLXXXVIII': 3388,\n 'MMMCCCV': 3305,\n 'MMMCCCVI': 3306,\n 'MMMCCCVII': 3307,\n 'MMMCCCVIII': 3308,\n 'MMMCCCX': 3310,\n 'MMMCCCXC': 3390,\n 'MMMCCCXCI': 3391,\n 'MMMCCCXCII': 3392,\n 'MMMCCCXCIII': 3393,\n 'MMMCCCXCIV': 3394,\n 'MMMCCCXCIX': 3399,\n 'MMMCCCXCV': 3395,\n 'MMMCCCXCVI': 3396,\n 'MMMCCCXCVII': 3397,\n 'MMMCCCXCVIII': 3398,\n 'MMMCCCXI': 3311,\n 'MMMCCCXII': 3312,\n 'MMMCCCXIII': 3313,\n 'MMMCCCXIV': 3314,\n 'MMMCCCXIX': 3319,\n 'MMMCCCXL': 3340,\n 'MMMCCCXLI': 3341,\n 'MMMCCCXLII': 3342,\n 'MMMCCCXLIII': 3343,\n 'MMMCCCXLIV': 3344,\n 'MMMCCCXLIX': 3349,\n 'MMMCCCXLV': 3345,\n 'MMMCCCXLVI': 3346,\n 'MMMCCCXLVII': 3347,\n 'MMMCCCXLVIII': 3348,\n 'MMMCCCXV': 3315,\n 'MMMCCCXVI': 3316,\n 'MMMCCCXVII': 3317,\n 'MMMCCCXVIII': 3318,\n 'MMMCCCXX': 3320,\n 'MMMCCCXXI': 3321,\n 'MMMCCCXXII': 3322,\n 'MMMCCCXXIII': 3323,\n 'MMMCCCXXIV': 3324,\n 'MMMCCCXXIX': 3329,\n 'MMMCCCXXV': 3325,\n 'MMMCCCXXVI': 3326,\n 'MMMCCCXXVII': 3327,\n 'MMMCCCXXVIII': 3328,\n 'MMMCCCXXX': 3330,\n 'MMMCCCXXXI': 3331,\n 'MMMCCCXXXII': 3332,\n 'MMMCCCXXXIII': 3333,\n 'MMMCCCXXXIV': 3334,\n 'MMMCCCXXXIX': 3339,\n 'MMMCCCXXXV': 3335,\n 'MMMCCCXXXVI': 3336,\n 'MMMCCCXXXVII': 3337,\n 'MMMCCCXXXVIII': 3338,\n 'MMMCCI': 3201,\n 'MMMCCII': 3202,\n 'MMMCCIII': 3203,\n 'MMMCCIV': 3204,\n 'MMMCCIX': 3209,\n 'MMMCCL': 3250,\n 'MMMCCLI': 3251,\n 'MMMCCLII': 3252,\n 'MMMCCLIII': 3253,\n 'MMMCCLIV': 3254,\n 'MMMCCLIX': 3259,\n 'MMMCCLV': 3255,\n 'MMMCCLVI': 3256,\n 'MMMCCLVII': 3257,\n 'MMMCCLVIII': 3258,\n 'MMMCCLX': 3260,\n 'MMMCCLXI': 3261,\n 'MMMCCLXII': 3262,\n 'MMMCCLXIII': 3263,\n 'MMMCCLXIV': 3264,\n 'MMMCCLXIX': 3269,\n 'MMMCCLXV': 3265,\n 'MMMCCLXVI': 3266,\n 'MMMCCLXVII': 3267,\n 'MMMCCLXVIII': 3268,\n 'MMMCCLXX': 3270,\n 'MMMCCLXXI': 3271,\n 'MMMCCLXXII': 3272,\n 'MMMCCLXXIII': 3273,\n 'MMMCCLXXIV': 3274,\n 'MMMCCLXXIX': 3279,\n 'MMMCCLXXV': 3275,\n 'MMMCCLXXVI': 3276,\n 'MMMCCLXXVII': 3277,\n 'MMMCCLXXVIII': 3278,\n 'MMMCCLXXX': 3280,\n 'MMMCCLXXXI': 3281,\n 'MMMCCLXXXII': 3282,\n 'MMMCCLXXXIII': 3283,\n 'MMMCCLXXXIV': 3284,\n 'MMMCCLXXXIX': 3289,\n 'MMMCCLXXXV': 3285,\n 'MMMCCLXXXVI': 3286,\n 'MMMCCLXXXVII': 3287,\n 'MMMCCLXXXVIII': 3288,\n 'MMMCCV': 3205,\n 'MMMCCVI': 3206,\n 'MMMCCVII': 3207,\n 'MMMCCVIII': 3208,\n 'MMMCCX': 3210,\n 'MMMCCXC': 3290,\n 'MMMCCXCI': 3291,\n 'MMMCCXCII': 3292,\n 'MMMCCXCIII': 3293,\n 'MMMCCXCIV': 3294,\n 'MMMCCXCIX': 3299,\n 'MMMCCXCV': 3295,\n 'MMMCCXCVI': 3296,\n 'MMMCCXCVII': 3297,\n 'MMMCCXCVIII': 3298,\n 'MMMCCXI': 3211,\n 'MMMCCXII': 3212,\n 'MMMCCXIII': 3213,\n 'MMMCCXIV': 3214,\n 'MMMCCXIX': 3219,\n 'MMMCCXL': 3240,\n 'MMMCCXLI': 3241,\n 'MMMCCXLII': 3242,\n 'MMMCCXLIII': 3243,\n 'MMMCCXLIV': 3244,\n 'MMMCCXLIX': 3249,\n 'MMMCCXLV': 3245,\n 'MMMCCXLVI': 3246,\n 'MMMCCXLVII': 3247,\n 'MMMCCXLVIII': 3248,\n 'MMMCCXV': 3215,\n 'MMMCCXVI': 3216,\n 'MMMCCXVII': 3217,\n 'MMMCCXVIII': 3218,\n 'MMMCCXX': 3220,\n 'MMMCCXXI': 3221,\n 'MMMCCXXII': 3222,\n 'MMMCCXXIII': 3223,\n 'MMMCCXXIV': 3224,\n 'MMMCCXXIX': 3229,\n 'MMMCCXXV': 3225,\n 'MMMCCXXVI': 3226,\n 'MMMCCXXVII': 3227,\n 'MMMCCXXVIII': 3228,\n 'MMMCCXXX': 3230,\n 'MMMCCXXXI': 3231,\n 'MMMCCXXXII': 3232,\n 'MMMCCXXXIII': 3233,\n 'MMMCCXXXIV': 3234,\n 'MMMCCXXXIX': 3239,\n 'MMMCCXXXV': 3235,\n 'MMMCCXXXVI': 3236,\n 'MMMCCXXXVII': 3237,\n 'MMMCCXXXVIII': 3238,\n 'MMMCD': 3400,\n 'MMMCDI': 3401,\n 'MMMCDII': 3402,\n 'MMMCDIII': 3403,\n 'MMMCDIV': 3404,\n 'MMMCDIX': 3409,\n 'MMMCDL': 3450,\n 'MMMCDLI': 3451,\n 'MMMCDLII': 3452,\n 'MMMCDLIII': 3453,\n 'MMMCDLIV': 3454,\n 'MMMCDLIX': 3459,\n 'MMMCDLV': 3455,\n 'MMMCDLVI': 3456,\n 'MMMCDLVII': 3457,\n 'MMMCDLVIII': 3458,\n 'MMMCDLX': 3460,\n 'MMMCDLXI': 3461,\n 'MMMCDLXII': 3462,\n 'MMMCDLXIII': 3463,\n 'MMMCDLXIV': 3464,\n 'MMMCDLXIX': 3469,\n 'MMMCDLXV': 3465,\n 'MMMCDLXVI': 3466,\n 'MMMCDLXVII': 3467,\n 'MMMCDLXVIII': 3468,\n 'MMMCDLXX': 3470,\n 'MMMCDLXXI': 3471,\n 'MMMCDLXXII': 3472,\n 'MMMCDLXXIII': 3473,\n 'MMMCDLXXIV': 3474,\n 'MMMCDLXXIX': 3479,\n 'MMMCDLXXV': 3475,\n 'MMMCDLXXVI': 3476,\n 'MMMCDLXXVII': 3477,\n 'MMMCDLXXVIII': 3478,\n 'MMMCDLXXX': 3480,\n 'MMMCDLXXXI': 3481,\n 'MMMCDLXXXII': 3482,\n 'MMMCDLXXXIII': 3483,\n 'MMMCDLXXXIV': 3484,\n 'MMMCDLXXXIX': 3489,\n 'MMMCDLXXXV': 3485,\n 'MMMCDLXXXVI': 3486,\n 'MMMCDLXXXVII': 3487,\n 'MMMCDLXXXVIII': 3488,\n 'MMMCDV': 3405,\n 'MMMCDVI': 3406,\n 'MMMCDVII': 3407,\n 'MMMCDVIII': 3408,\n 'MMMCDX': 3410,\n 'MMMCDXC': 3490,\n 'MMMCDXCI': 3491,\n 'MMMCDXCII': 3492,\n 'MMMCDXCIII': 3493,\n 'MMMCDXCIV': 3494,\n 'MMMCDXCIX': 3499,\n 'MMMCDXCV': 3495,\n 'MMMCDXCVI': 3496,\n 'MMMCDXCVII': 3497,\n 'MMMCDXCVIII': 3498,\n 'MMMCDXI': 3411,\n 'MMMCDXII': 3412,\n 'MMMCDXIII': 3413,\n 'MMMCDXIV': 3414,\n 'MMMCDXIX': 3419,\n 'MMMCDXL': 3440,\n 'MMMCDXLI': 3441,\n 'MMMCDXLII': 3442,\n 'MMMCDXLIII': 3443,\n 'MMMCDXLIV': 3444,\n 'MMMCDXLIX': 3449,\n 'MMMCDXLV': 3445,\n 'MMMCDXLVI': 3446,\n 'MMMCDXLVII': 3447,\n 'MMMCDXLVIII': 3448,\n 'MMMCDXV': 3415,\n 'MMMCDXVI': 3416,\n 'MMMCDXVII': 3417,\n 'MMMCDXVIII': 3418,\n 'MMMCDXX': 3420,\n 'MMMCDXXI': 3421,\n 'MMMCDXXII': 3422,\n 'MMMCDXXIII': 3423,\n 'MMMCDXXIV': 3424,\n 'MMMCDXXIX': 3429,\n 'MMMCDXXV': 3425,\n 'MMMCDXXVI': 3426,\n 'MMMCDXXVII': 3427,\n 'MMMCDXXVIII': 3428,\n 'MMMCDXXX': 3430,\n 'MMMCDXXXI': 3431,\n 'MMMCDXXXII': 3432,\n 'MMMCDXXXIII': 3433,\n 'MMMCDXXXIV': 3434,\n 'MMMCDXXXIX': 3439,\n 'MMMCDXXXV': 3435,\n 'MMMCDXXXVI': 3436,\n 'MMMCDXXXVII': 3437,\n 'MMMCDXXXVIII': 3438,\n 'MMMCI': 3101,\n 'MMMCII': 3102,\n 'MMMCIII': 3103,\n 'MMMCIV': 3104,\n 'MMMCIX': 3109,\n 'MMMCL': 3150,\n 'MMMCLI': 3151,\n 'MMMCLII': 3152,\n 'MMMCLIII': 3153,\n 'MMMCLIV': 3154,\n 'MMMCLIX': 3159,\n 'MMMCLV': 3155,\n 'MMMCLVI': 3156,\n 'MMMCLVII': 3157,\n 'MMMCLVIII': 3158,\n 'MMMCLX': 3160,\n 'MMMCLXI': 3161,\n 'MMMCLXII': 3162,\n 'MMMCLXIII': 3163,\n 'MMMCLXIV': 3164,\n 'MMMCLXIX': 3169,\n 'MMMCLXV': 3165,\n 'MMMCLXVI': 3166,\n 'MMMCLXVII': 3167,\n 'MMMCLXVIII': 3168,\n 'MMMCLXX': 3170,\n 'MMMCLXXI': 3171,\n 'MMMCLXXII': 3172,\n 'MMMCLXXIII': 3173,\n 'MMMCLXXIV': 3174,\n 'MMMCLXXIX': 3179,\n 'MMMCLXXV': 3175,\n 'MMMCLXXVI': 3176,\n 'MMMCLXXVII': 3177,\n 'MMMCLXXVIII': 3178,\n 'MMMCLXXX': 3180,\n 'MMMCLXXXI': 3181,\n 'MMMCLXXXII': 3182,\n 'MMMCLXXXIII': 3183,\n 'MMMCLXXXIV': 3184,\n 'MMMCLXXXIX': 3189,\n 'MMMCLXXXV': 3185,\n 'MMMCLXXXVI': 3186,\n 'MMMCLXXXVII': 3187,\n 'MMMCLXXXVIII': 3188,\n 'MMMCM': 3900,\n 'MMMCMI': 3901,\n 'MMMCMII': 3902,\n 'MMMCMIII': 3903,\n 'MMMCMIV': 3904,\n 'MMMCMIX': 3909,\n 'MMMCML': 3950,\n 'MMMCMLI': 3951,\n 'MMMCMLII': 3952,\n 'MMMCMLIII': 3953,\n 'MMMCMLIV': 3954,\n 'MMMCMLIX': 3959,\n 'MMMCMLV': 3955,\n 'MMMCMLVI': 3956,\n 'MMMCMLVII': 3957,\n 'MMMCMLVIII': 3958,\n 'MMMCMLX': 3960,\n 'MMMCMLXI': 3961,\n 'MMMCMLXII': 3962,\n 'MMMCMLXIII': 3963,\n 'MMMCMLXIV': 3964,\n 'MMMCMLXIX': 3969,\n 'MMMCMLXV': 3965,\n 'MMMCMLXVI': 3966,\n 'MMMCMLXVII': 3967,\n 'MMMCMLXVIII': 3968,\n 'MMMCMLXX': 3970,\n 'MMMCMLXXI': 3971,\n 'MMMCMLXXII': 3972,\n 'MMMCMLXXIII': 3973,\n 'MMMCMLXXIV': 3974,\n 'MMMCMLXXIX': 3979,\n 'MMMCMLXXV': 3975,\n 'MMMCMLXXVI': 3976,\n 'MMMCMLXXVII': 3977,\n 'MMMCMLXXVIII': 3978,\n 'MMMCMLXXX': 3980,\n 'MMMCMLXXXI': 3981,\n 'MMMCMLXXXII': 3982,\n 'MMMCMLXXXIII': 3983,\n 'MMMCMLXXXIV': 3984,\n 'MMMCMLXXXIX': 3989,\n 'MMMCMLXXXV': 3985,\n 'MMMCMLXXXVI': 3986,\n 'MMMCMLXXXVII': 3987,\n 'MMMCMLXXXVIII': 3988,\n 'MMMCMV': 3905,\n 'MMMCMVI': 3906,\n 'MMMCMVII': 3907,\n 'MMMCMVIII': 3908,\n 'MMMCMX': 3910,\n 'MMMCMXC': 3990,\n 'MMMCMXCI': 3991,\n 'MMMCMXCII': 3992,\n 'MMMCMXCIII': 3993,\n 'MMMCMXCIV': 3994,\n 'MMMCMXCIX': 3999,\n 'MMMCMXCV': 3995,\n 'MMMCMXCVI': 3996,\n 'MMMCMXCVII': 3997,\n 'MMMCMXCVIII': 3998,\n 'MMMCMXI': 3911,\n 'MMMCMXII': 3912,\n 'MMMCMXIII': 3913,\n 'MMMCMXIV': 3914,\n 'MMMCMXIX': 3919,\n 'MMMCMXL': 3940,\n 'MMMCMXLI': 3941,\n 'MMMCMXLII': 3942,\n 'MMMCMXLIII': 3943,\n 'MMMCMXLIV': 3944,\n 'MMMCMXLIX': 3949,\n 'MMMCMXLV': 3945,\n 'MMMCMXLVI': 3946,\n 'MMMCMXLVII': 3947,\n 'MMMCMXLVIII': 3948,\n 'MMMCMXV': 3915,\n 'MMMCMXVI': 3916,\n 'MMMCMXVII': 3917,\n 'MMMCMXVIII': 3918,\n 'MMMCMXX': 3920,\n 'MMMCMXXI': 3921,\n 'MMMCMXXII': 3922,\n 'MMMCMXXIII': 3923,\n 'MMMCMXXIV': 3924,\n 'MMMCMXXIX': 3929,\n 'MMMCMXXV': 3925,\n 'MMMCMXXVI': 3926,\n 'MMMCMXXVII': 3927,\n 'MMMCMXXVIII': 3928,\n 'MMMCMXXX': 3930,\n 'MMMCMXXXI': 3931,\n 'MMMCMXXXII': 3932,\n 'MMMCMXXXIII': 3933,\n 'MMMCMXXXIV': 3934,\n 'MMMCMXXXIX': 3939,\n 'MMMCMXXXV': 3935,\n 'MMMCMXXXVI': 3936,\n 'MMMCMXXXVII': 3937,\n 'MMMCMXXXVIII': 3938,\n 'MMMCV': 3105,\n 'MMMCVI': 3106,\n 'MMMCVII': 3107,\n 'MMMCVIII': 3108,\n 'MMMCX': 3110,\n 'MMMCXC': 3190,\n 'MMMCXCI': 3191,\n 'MMMCXCII': 3192,\n 'MMMCXCIII': 3193,\n 'MMMCXCIV': 3194,\n 'MMMCXCIX': 3199,\n 'MMMCXCV': 3195,\n 'MMMCXCVI': 3196,\n 'MMMCXCVII': 3197,\n 'MMMCXCVIII': 3198,\n 'MMMCXI': 3111,\n 'MMMCXII': 3112,\n 'MMMCXIII': 3113,\n 'MMMCXIV': 3114,\n 'MMMCXIX': 3119,\n 'MMMCXL': 3140,\n 'MMMCXLI': 3141,\n 'MMMCXLII': 3142,\n 'MMMCXLIII': 3143,\n 'MMMCXLIV': 3144,\n 'MMMCXLIX': 3149,\n 'MMMCXLV': 3145,\n 'MMMCXLVI': 3146,\n 'MMMCXLVII': 3147,\n 'MMMCXLVIII': 3148,\n 'MMMCXV': 3115,\n 'MMMCXVI': 3116,\n 'MMMCXVII': 3117,\n 'MMMCXVIII': 3118,\n 'MMMCXX': 3120,\n 'MMMCXXI': 3121,\n 'MMMCXXII': 3122,\n 'MMMCXXIII': 3123,\n 'MMMCXXIV': 3124,\n 'MMMCXXIX': 3129,\n 'MMMCXXV': 3125,\n 'MMMCXXVI': 3126,\n 'MMMCXXVII': 3127,\n 'MMMCXXVIII': 3128,\n 'MMMCXXX': 3130,\n 'MMMCXXXI': 3131,\n 'MMMCXXXII': 3132,\n 'MMMCXXXIII': 3133,\n 'MMMCXXXIV': 3134,\n 'MMMCXXXIX': 3139,\n 'MMMCXXXV': 3135,\n 'MMMCXXXVI': 3136,\n 'MMMCXXXVII': 3137,\n 'MMMCXXXVIII': 3138,\n 'MMMD': 3500,\n 'MMMDC': 3600,\n 'MMMDCC': 3700,\n 'MMMDCCC': 3800,\n 'MMMDCCCI': 3801,\n 'MMMDCCCII': 3802,\n 'MMMDCCCIII': 3803,\n 'MMMDCCCIV': 3804,\n 'MMMDCCCIX': 3809,\n 'MMMDCCCL': 3850,\n 'MMMDCCCLI': 3851,\n 'MMMDCCCLII': 3852,\n 'MMMDCCCLIII': 3853,\n 'MMMDCCCLIV': 3854,\n 'MMMDCCCLIX': 3859,\n 'MMMDCCCLV': 3855,\n 'MMMDCCCLVI': 3856,\n 'MMMDCCCLVII': 3857,\n 'MMMDCCCLVIII': 3858,\n 'MMMDCCCLX': 3860,\n 'MMMDCCCLXI': 3861,\n 'MMMDCCCLXII': 3862,\n 'MMMDCCCLXIII': 3863,\n 'MMMDCCCLXIV': 3864,\n 'MMMDCCCLXIX': 3869,\n 'MMMDCCCLXV': 3865,\n 'MMMDCCCLXVI': 3866,\n 'MMMDCCCLXVII': 3867,\n 'MMMDCCCLXVIII': 3868,\n 'MMMDCCCLXX': 3870,\n 'MMMDCCCLXXI': 3871,\n 'MMMDCCCLXXII': 3872,\n 'MMMDCCCLXXIII': 3873,\n 'MMMDCCCLXXIV': 3874,\n 'MMMDCCCLXXIX': 3879,\n 'MMMDCCCLXXV': 3875,\n 'MMMDCCCLXXVI': 3876,\n 'MMMDCCCLXXVII': 3877,\n 'MMMDCCCLXXVIII': 3878,\n 'MMMDCCCLXXX': 3880,\n 'MMMDCCCLXXXI': 3881,\n 'MMMDCCCLXXXII': 3882,\n 'MMMDCCCLXXXIII': 3883,\n 'MMMDCCCLXXXIV': 3884,\n 'MMMDCCCLXXXIX': 3889,\n 'MMMDCCCLXXXV': 3885,\n 'MMMDCCCLXXXVI': 3886,\n 'MMMDCCCLXXXVII': 3887,\n 'MMMDCCCLXXXVIII': 3888,\n 'MMMDCCCV': 3805,\n 'MMMDCCCVI': 3806,\n 'MMMDCCCVII': 3807,\n 'MMMDCCCVIII': 3808,\n 'MMMDCCCX': 3810,\n 'MMMDCCCXC': 3890,\n 'MMMDCCCXCI': 3891,\n 'MMMDCCCXCII': 3892,\n 'MMMDCCCXCIII': 3893,\n 'MMMDCCCXCIV': 3894,\n 'MMMDCCCXCIX': 3899,\n 'MMMDCCCXCV': 3895,\n 'MMMDCCCXCVI': 3896,\n 'MMMDCCCXCVII': 3897,\n 'MMMDCCCXCVIII': 3898,\n 'MMMDCCCXI': 3811,\n 'MMMDCCCXII': 3812,\n 'MMMDCCCXIII': 3813,\n 'MMMDCCCXIV': 3814,\n 'MMMDCCCXIX': 3819,\n 'MMMDCCCXL': 3840,\n 'MMMDCCCXLI': 3841,\n 'MMMDCCCXLII': 3842,\n 'MMMDCCCXLIII': 3843,\n 'MMMDCCCXLIV': 3844,\n 'MMMDCCCXLIX': 3849,\n 'MMMDCCCXLV': 3845,\n 'MMMDCCCXLVI': 3846,\n 'MMMDCCCXLVII': 3847,\n 'MMMDCCCXLVIII': 3848,\n 'MMMDCCCXV': 3815,\n 'MMMDCCCXVI': 3816,\n 'MMMDCCCXVII': 3817,\n 'MMMDCCCXVIII': 3818,\n 'MMMDCCCXX': 3820,\n 'MMMDCCCXXI': 3821,\n 'MMMDCCCXXII': 3822,\n 'MMMDCCCXXIII': 3823,\n 'MMMDCCCXXIV': 3824,\n 'MMMDCCCXXIX': 3829,\n 'MMMDCCCXXV': 3825,\n 'MMMDCCCXXVI': 3826,\n 'MMMDCCCXXVII': 3827,\n 'MMMDCCCXXVIII': 3828,\n 'MMMDCCCXXX': 3830,\n 'MMMDCCCXXXI': 3831,\n 'MMMDCCCXXXII': 3832,\n 'MMMDCCCXXXIII': 3833,\n 'MMMDCCCXXXIV': 3834,\n 'MMMDCCCXXXIX': 3839,\n 'MMMDCCCXXXV': 3835,\n 'MMMDCCCXXXVI': 3836,\n 'MMMDCCCXXXVII': 3837,\n 'MMMDCCCXXXVIII': 3838,\n 'MMMDCCI': 3701,\n 'MMMDCCII': 3702,\n 'MMMDCCIII': 3703,\n 'MMMDCCIV': 3704,\n 'MMMDCCIX': 3709,\n 'MMMDCCL': 3750,\n 'MMMDCCLI': 3751,\n 'MMMDCCLII': 3752,\n 'MMMDCCLIII': 3753,\n 'MMMDCCLIV': 3754,\n 'MMMDCCLIX': 3759,\n 'MMMDCCLV': 3755,\n 'MMMDCCLVI': 3756,\n 'MMMDCCLVII': 3757,\n 'MMMDCCLVIII': 3758,\n 'MMMDCCLX': 3760,\n 'MMMDCCLXI': 3761,\n 'MMMDCCLXII': 3762,\n 'MMMDCCLXIII': 3763,\n 'MMMDCCLXIV': 3764,\n 'MMMDCCLXIX': 3769,\n 'MMMDCCLXV': 3765,\n 'MMMDCCLXVI': 3766,\n 'MMMDCCLXVII': 3767,\n 'MMMDCCLXVIII': 3768,\n 'MMMDCCLXX': 3770,\n 'MMMDCCLXXI': 3771,\n 'MMMDCCLXXII': 3772,\n 'MMMDCCLXXIII': 3773,\n 'MMMDCCLXXIV': 3774,\n 'MMMDCCLXXIX': 3779,\n 'MMMDCCLXXV': 3775,\n 'MMMDCCLXXVI': 3776,\n 'MMMDCCLXXVII': 3777,\n 'MMMDCCLXXVIII': 3778,\n 'MMMDCCLXXX': 3780,\n 'MMMDCCLXXXI': 3781,\n 'MMMDCCLXXXII': 3782,\n 'MMMDCCLXXXIII': 3783,\n 'MMMDCCLXXXIV': 3784,\n 'MMMDCCLXXXIX': 3789,\n 'MMMDCCLXXXV': 3785,\n 'MMMDCCLXXXVI': 3786,\n 'MMMDCCLXXXVII': 3787,\n 'MMMDCCLXXXVIII': 3788,\n 'MMMDCCV': 3705,\n 'MMMDCCVI': 3706,\n 'MMMDCCVII': 3707,\n 'MMMDCCVIII': 3708,\n 'MMMDCCX': 3710,\n 'MMMDCCXC': 3790,\n 'MMMDCCXCI': 3791,\n 'MMMDCCXCII': 3792,\n 'MMMDCCXCIII': 3793,\n 'MMMDCCXCIV': 3794,\n 'MMMDCCXCIX': 3799,\n 'MMMDCCXCV': 3795,\n 'MMMDCCXCVI': 3796,\n 'MMMDCCXCVII': 3797,\n 'MMMDCCXCVIII': 3798,\n 'MMMDCCXI': 3711,\n 'MMMDCCXII': 3712,\n 'MMMDCCXIII': 3713,\n 'MMMDCCXIV': 3714,\n 'MMMDCCXIX': 3719,\n 'MMMDCCXL': 3740,\n 'MMMDCCXLI': 3741,\n 'MMMDCCXLII': 3742,\n 'MMMDCCXLIII': 3743,\n 'MMMDCCXLIV': 3744,\n 'MMMDCCXLIX': 3749,\n 'MMMDCCXLV': 3745,\n 'MMMDCCXLVI': 3746,\n 'MMMDCCXLVII': 3747,\n 'MMMDCCXLVIII': 3748,\n 'MMMDCCXV': 3715,\n 'MMMDCCXVI': 3716,\n 'MMMDCCXVII': 3717,\n 'MMMDCCXVIII': 3718,\n 'MMMDCCXX': 3720,\n 'MMMDCCXXI': 3721,\n 'MMMDCCXXII': 3722,\n 'MMMDCCXXIII': 3723,\n 'MMMDCCXXIV': 3724,\n 'MMMDCCXXIX': 3729,\n 'MMMDCCXXV': 3725,\n 'MMMDCCXXVI': 3726,\n 'MMMDCCXXVII': 3727,\n 'MMMDCCXXVIII': 3728,\n 'MMMDCCXXX': 3730,\n 'MMMDCCXXXI': 3731,\n 'MMMDCCXXXII': 3732,\n 'MMMDCCXXXIII': 3733,\n 'MMMDCCXXXIV': 3734,\n 'MMMDCCXXXIX': 3739,\n 'MMMDCCXXXV': 3735,\n 'MMMDCCXXXVI': 3736,\n 'MMMDCCXXXVII': 3737,\n 'MMMDCCXXXVIII': 3738,\n 'MMMDCI': 3601,\n 'MMMDCII': 3602,\n 'MMMDCIII': 3603,\n 'MMMDCIV': 3604,\n 'MMMDCIX': 3609,\n 'MMMDCL': 3650,\n 'MMMDCLI': 3651,\n 'MMMDCLII': 3652,\n 'MMMDCLIII': 3653,\n 'MMMDCLIV': 3654,\n 'MMMDCLIX': 3659,\n 'MMMDCLV': 3655,\n 'MMMDCLVI': 3656,\n 'MMMDCLVII': 3657,\n 'MMMDCLVIII': 3658,\n 'MMMDCLX': 3660,\n 'MMMDCLXI': 3661,\n 'MMMDCLXII': 3662,\n 'MMMDCLXIII': 3663,\n 'MMMDCLXIV': 3664,\n 'MMMDCLXIX': 3669,\n 'MMMDCLXV': 3665,\n 'MMMDCLXVI': 3666,\n 'MMMDCLXVII': 3667,\n 'MMMDCLXVIII': 3668,\n 'MMMDCLXX': 3670,\n 'MMMDCLXXI': 3671,\n 'MMMDCLXXII': 3672,\n 'MMMDCLXXIII': 3673,\n 'MMMDCLXXIV': 3674,\n 'MMMDCLXXIX': 3679,\n 'MMMDCLXXV': 3675,\n 'MMMDCLXXVI': 3676,\n 'MMMDCLXXVII': 3677,\n 'MMMDCLXXVIII': 3678,\n 'MMMDCLXXX': 3680,\n 'MMMDCLXXXI': 3681,\n 'MMMDCLXXXII': 3682,\n 'MMMDCLXXXIII': 3683,\n 'MMMDCLXXXIV': 3684,\n 'MMMDCLXXXIX': 3689,\n 'MMMDCLXXXV': 3685,\n 'MMMDCLXXXVI': 3686,\n 'MMMDCLXXXVII': 3687,\n 'MMMDCLXXXVIII': 3688,\n 'MMMDCV': 3605,\n 'MMMDCVI': 3606,\n 'MMMDCVII': 3607,\n 'MMMDCVIII': 3608,\n 'MMMDCX': 3610,\n 'MMMDCXC': 3690,\n 'MMMDCXCI': 3691,\n 'MMMDCXCII': 3692,\n 'MMMDCXCIII': 3693,\n 'MMMDCXCIV': 3694,\n 'MMMDCXCIX': 3699,\n 'MMMDCXCV': 3695,\n 'MMMDCXCVI': 3696,\n 'MMMDCXCVII': 3697,\n 'MMMDCXCVIII': 3698,\n 'MMMDCXI': 3611,\n 'MMMDCXII': 3612,\n 'MMMDCXIII': 3613,\n 'MMMDCXIV': 3614,\n 'MMMDCXIX': 3619,\n 'MMMDCXL': 3640,\n 'MMMDCXLI': 3641,\n 'MMMDCXLII': 3642,\n 'MMMDCXLIII': 3643,\n 'MMMDCXLIV': 3644,\n 'MMMDCXLIX': 3649,\n 'MMMDCXLV': 3645,\n 'MMMDCXLVI': 3646,\n 'MMMDCXLVII': 3647,\n 'MMMDCXLVIII': 3648,\n 'MMMDCXV': 3615,\n 'MMMDCXVI': 3616,\n 'MMMDCXVII': 3617,\n 'MMMDCXVIII': 3618,\n 'MMMDCXX': 3620,\n 'MMMDCXXI': 3621,\n 'MMMDCXXII': 3622,\n 'MMMDCXXIII': 3623,\n 'MMMDCXXIV': 3624,\n 'MMMDCXXIX': 3629,\n 'MMMDCXXV': 3625,\n 'MMMDCXXVI': 3626,\n 'MMMDCXXVII': 3627,\n 'MMMDCXXVIII': 3628,\n 'MMMDCXXX': 3630,\n 'MMMDCXXXI': 3631,\n 'MMMDCXXXII': 3632,\n 'MMMDCXXXIII': 3633,\n 'MMMDCXXXIV': 3634,\n 'MMMDCXXXIX': 3639,\n 'MMMDCXXXV': 3635,\n 'MMMDCXXXVI': 3636,\n 'MMMDCXXXVII': 3637,\n 'MMMDCXXXVIII': 3638,\n 'MMMDI': 3501,\n 'MMMDII': 3502,\n 'MMMDIII': 3503,\n 'MMMDIV': 3504,\n 'MMMDIX': 3509,\n 'MMMDL': 3550,\n 'MMMDLI': 3551,\n 'MMMDLII': 3552,\n 'MMMDLIII': 3553,\n 'MMMDLIV': 3554,\n 'MMMDLIX': 3559,\n 'MMMDLV': 3555,\n 'MMMDLVI': 3556,\n 'MMMDLVII': 3557,\n 'MMMDLVIII': 3558,\n 'MMMDLX': 3560,\n 'MMMDLXI': 3561,\n 'MMMDLXII': 3562,\n 'MMMDLXIII': 3563,\n 'MMMDLXIV': 3564,\n 'MMMDLXIX': 3569,\n 'MMMDLXV': 3565,\n 'MMMDLXVI': 3566,\n 'MMMDLXVII': 3567,\n 'MMMDLXVIII': 3568,\n 'MMMDLXX': 3570,\n 'MMMDLXXI': 3571,\n 'MMMDLXXII': 3572,\n 'MMMDLXXIII': 3573,\n 'MMMDLXXIV': 3574,\n 'MMMDLXXIX': 3579,\n 'MMMDLXXV': 3575,\n 'MMMDLXXVI': 3576,\n 'MMMDLXXVII': 3577,\n 'MMMDLXXVIII': 3578,\n 'MMMDLXXX': 3580,\n 'MMMDLXXXI': 3581,\n 'MMMDLXXXII': 3582,\n 'MMMDLXXXIII': 3583,\n 'MMMDLXXXIV': 3584,\n 'MMMDLXXXIX': 3589,\n 'MMMDLXXXV': 3585,\n 'MMMDLXXXVI': 3586,\n 'MMMDLXXXVII': 3587,\n 'MMMDLXXXVIII': 3588,\n 'MMMDV': 3505,\n 'MMMDVI': 3506,\n 'MMMDVII': 3507,\n 'MMMDVIII': 3508,\n 'MMMDX': 3510,\n 'MMMDXC': 3590,\n 'MMMDXCI': 3591,\n 'MMMDXCII': 3592,\n 'MMMDXCIII': 3593,\n 'MMMDXCIV': 3594,\n 'MMMDXCIX': 3599,\n 'MMMDXCV': 3595,\n 'MMMDXCVI': 3596,\n 'MMMDXCVII': 3597,\n 'MMMDXCVIII': 3598,\n 'MMMDXI': 3511,\n 'MMMDXII': 3512,\n 'MMMDXIII': 3513,\n 'MMMDXIV': 3514,\n 'MMMDXIX': 3519,\n 'MMMDXL': 3540,\n 'MMMDXLI': 3541,\n 'MMMDXLII': 3542,\n 'MMMDXLIII': 3543,\n 'MMMDXLIV': 3544,\n 'MMMDXLIX': 3549,\n 'MMMDXLV': 3545,\n 'MMMDXLVI': 3546,\n 'MMMDXLVII': 3547,\n 'MMMDXLVIII': 3548,\n 'MMMDXV': 3515,\n 'MMMDXVI': 3516,\n 'MMMDXVII': 3517,\n 'MMMDXVIII': 3518,\n 'MMMDXX': 3520,\n 'MMMDXXI': 3521,\n 'MMMDXXII': 3522,\n 'MMMDXXIII': 3523,\n 'MMMDXXIV': 3524,\n 'MMMDXXIX': 3529,\n 'MMMDXXV': 3525,\n 'MMMDXXVI': 3526,\n 'MMMDXXVII': 3527,\n 'MMMDXXVIII': 3528,\n 'MMMDXXX': 3530,\n 'MMMDXXXI': 3531,\n 'MMMDXXXII': 3532,\n 'MMMDXXXIII': 3533,\n 'MMMDXXXIV': 3534,\n 'MMMDXXXIX': 3539,\n 'MMMDXXXV': 3535,\n 'MMMDXXXVI': 3536,\n 'MMMDXXXVII': 3537,\n 'MMMDXXXVIII': 3538,\n 'MMMI': 3001,\n 'MMMII': 3002,\n 'MMMIII': 3003,\n 'MMMIV': 3004,\n 'MMMIX': 3009,\n 'MMML': 3050,\n 'MMMLI': 3051,\n 'MMMLII': 3052,\n 'MMMLIII': 3053,\n 'MMMLIV': 3054,\n 'MMMLIX': 3059,\n 'MMMLV': 3055,\n 'MMMLVI': 3056,\n 'MMMLVII': 3057,\n 'MMMLVIII': 3058,\n 'MMMLX': 3060,\n 'MMMLXI': 3061,\n 'MMMLXII': 3062,\n 'MMMLXIII': 3063,\n 'MMMLXIV': 3064,\n 'MMMLXIX': 3069,\n 'MMMLXV': 3065,\n 'MMMLXVI': 3066,\n 'MMMLXVII': 3067,\n 'MMMLXVIII': 3068,\n 'MMMLXX': 3070,\n 'MMMLXXI': 3071,\n 'MMMLXXII': 3072,\n 'MMMLXXIII': 3073,\n 'MMMLXXIV': 3074,\n 'MMMLXXIX': 3079,\n 'MMMLXXV': 3075,\n 'MMMLXXVI': 3076,\n 'MMMLXXVII': 3077,\n 'MMMLXXVIII': 3078,\n 'MMMLXXX': 3080,\n 'MMMLXXXI': 3081,\n 'MMMLXXXII': 3082,\n 'MMMLXXXIII': 3083,\n 'MMMLXXXIV': 3084,\n 'MMMLXXXIX': 3089,\n 'MMMLXXXV': 3085,\n 'MMMLXXXVI': 3086,\n 'MMMLXXXVII': 3087,\n 'MMMLXXXVIII': 3088,\n 'MMMV': 3005,\n 'MMMVI': 3006,\n 'MMMVII': 3007,\n 'MMMVIII': 3008,\n 'MMMX': 3010,\n 'MMMXC': 3090,\n 'MMMXCI': 3091,\n 'MMMXCII': 3092,\n 'MMMXCIII': 3093,\n 'MMMXCIV': 3094,\n 'MMMXCIX': 3099,\n 'MMMXCV': 3095,\n 'MMMXCVI': 3096,\n 'MMMXCVII': 3097,\n 'MMMXCVIII': 3098,\n 'MMMXI': 3011,\n 'MMMXII': 3012,\n 'MMMXIII': 3013,\n 'MMMXIV': 3014,\n 'MMMXIX': 3019,\n 'MMMXL': 3040,\n 'MMMXLI': 3041,\n 'MMMXLII': 3042,\n 'MMMXLIII': 3043,\n 'MMMXLIV': 3044,\n 'MMMXLIX': 3049,\n 'MMMXLV': 3045,\n 'MMMXLVI': 3046,\n 'MMMXLVII': 3047,\n 'MMMXLVIII': 3048,\n 'MMMXV': 3015,\n 'MMMXVI': 3016,\n 'MMMXVII': 3017,\n 'MMMXVIII': 3018,\n 'MMMXX': 3020,\n 'MMMXXI': 3021,\n 'MMMXXII': 3022,\n 'MMMXXIII': 3023,\n 'MMMXXIV': 3024,\n 'MMMXXIX': 3029,\n 'MMMXXV': 3025,\n 'MMMXXVI': 3026,\n 'MMMXXVII': 3027,\n 'MMMXXVIII': 3028,\n 'MMMXXX': 3030,\n 'MMMXXXI': 3031,\n 'MMMXXXII': 3032,\n 'MMMXXXIII': 3033,\n 'MMMXXXIV': 3034,\n 'MMMXXXIX': 3039,\n 'MMMXXXV': 3035,\n 'MMMXXXVI': 3036,\n 'MMMXXXVII': 3037,\n 'MMMXXXVIII': 3038,\n 'MMV': 2005,\n 'MMVI': 2006,\n 'MMVII': 2007,\n 'MMVIII': 2008,\n 'MMX': 2010,\n 'MMXC': 2090,\n 'MMXCI': 2091,\n 'MMXCII': 2092,\n 'MMXCIII': 2093,\n 'MMXCIV': 2094,\n 'MMXCIX': 2099,\n 'MMXCV': 2095,\n 'MMXCVI': 2096,\n 'MMXCVII': 2097,\n 'MMXCVIII': 2098,\n 'MMXI': 2011,\n 'MMXII': 2012,\n 'MMXIII': 2013,\n 'MMXIV': 2014,\n 'MMXIX': 2019,\n 'MMXL': 2040,\n 'MMXLI': 2041,\n 'MMXLII': 2042,\n 'MMXLIII': 2043,\n 'MMXLIV': 2044,\n 'MMXLIX': 2049,\n 'MMXLV': 2045,\n 'MMXLVI': 2046,\n 'MMXLVII': 2047,\n 'MMXLVIII': 2048,\n 'MMXV': 2015,\n 'MMXVI': 2016,\n 'MMXVII': 2017,\n 'MMXVIII': 2018,\n 'MMXX': 2020,\n 'MMXXI': 2021,\n 'MMXXII': 2022,\n 'MMXXIII': 2023,\n 'MMXXIV': 2024,\n 'MMXXIX': 2029,\n 'MMXXV': 2025,\n 'MMXXVI': 2026,\n 'MMXXVII': 2027,\n 'MMXXVIII': 2028,\n 'MMXXX': 2030,\n 'MMXXXI': 2031,\n 'MMXXXII': 2032,\n 'MMXXXIII': 2033,\n 'MMXXXIV': 2034,\n 'MMXXXIX': 2039,\n 'MMXXXV': 2035,\n 'MMXXXVI': 2036,\n 'MMXXXVII': 2037,\n 'MMXXXVIII': 2038,\n 'MV': 1005,\n 'MVI': 1006,\n 'MVII': 1007,\n 'MVIII': 1008,\n 'MX': 1010,\n 'MXC': 1090,\n 'MXCI': 1091,\n 'MXCII': 1092,\n 'MXCIII': 1093,\n 'MXCIV': 1094,\n 'MXCIX': 1099,\n 'MXCV': 1095,\n 'MXCVI': 1096,\n 'MXCVII': 1097,\n 'MXCVIII': 1098,\n 'MXI': 1011,\n 'MXII': 1012,\n 'MXIII': 1013,\n 'MXIV': 1014,\n 'MXIX': 1019,\n 'MXL': 1040,\n 'MXLI': 1041,\n 'MXLII': 1042,\n 'MXLIII': 1043,\n 'MXLIV': 1044,\n 'MXLIX': 1049,\n 'MXLV': 1045,\n 'MXLVI': 1046,\n 'MXLVII': 1047,\n 'MXLVIII': 1048,\n 'MXV': 1015,\n 'MXVI': 1016,\n 'MXVII': 1017,\n 'MXVIII': 1018,\n 'MXX': 1020,\n 'MXXI': 1021,\n 'MXXII': 1022,\n 'MXXIII': 1023,\n 'MXXIV': 1024,\n 'MXXIX': 1029,\n 'MXXV': 1025,\n 'MXXVI': 1026,\n 'MXXVII': 1027,\n 'MXXVIII': 1028,\n 'MXXX': 1030,\n 'MXXXI': 1031,\n 'MXXXII': 1032,\n 'MXXXIII': 1033,\n 'MXXXIV': 1034,\n 'MXXXIX': 1039,\n 'MXXXV': 1035,\n 'MXXXVI': 1036,\n 'MXXXVII': 1037,\n 'MXXXVIII': 1038,\n 'V': 5,\n 'VI': 6,\n 'VII': 7,\n 'VIII': 8,\n 'X': 10,\n 'XC': 90,\n 'XCI': 91,\n 'XCII': 92,\n 'XCIII': 93,\n 'XCIV': 94,\n 'XCIX': 99,\n 'XCV': 95,\n 'XCVI': 96,\n 'XCVII': 97,\n 'XCVIII': 98,\n 'XI': 11,\n 'XII': 12,\n 'XIII': 13,\n 'XIV': 14,\n 'XIX': 19,\n 'XL': 40,\n 'XLI': 41,\n 'XLII': 42,\n 'XLIII': 43,\n 'XLIV': 44,\n 'XLIX': 49,\n 'XLV': 45,\n 'XLVI': 46,\n 'XLVII': 47,\n 'XLVIII': 48,\n 'XV': 15,\n 'XVI': 16,\n 'XVII': 17,\n 'XVIII': 18,\n 'XX': 20,\n 'XXI': 21,\n 'XXII': 22,\n 'XXIII': 23,\n 'XXIV': 24,\n 'XXIX': 29,\n 'XXV': 25,\n 'XXVI': 26,\n 'XXVII': 27,\n 'XXVIII': 28,\n 'XXX': 30,\n 'XXXI': 31,\n 'XXXII': 32,\n 'XXXIII': 33,\n 'XXXIV': 34,\n 'XXXIX': 39,\n 'XXXV': 35,\n 'XXXVI': 36,\n 'XXXVII': 37,\n 'XXXVIII': 38,\n}\n\n\ndef solution(n):\n return mapping[n]", "SYMBOLS = (\n ('M', 1000),\n ('CM', 900),\n ('D', 500),\n ('CD', 400),\n ('C', 100),\n ('XC', 90),\n ('L', 50),\n ('XL', 40),\n ('X', 10),\n ('IX', 9),\n ('V', 5),\n ('IV', 4),\n ('I', 1),\n)\n\ndef solution(input):\n if not input:\n return 0\n for char, value in SYMBOLS:\n if input.startswith(char):\n return value + solution(input[len(char):])", "def solution(roman): \n romanic={\"M\":1000,\"D\":500,\"C\":100,\"L\":50,\"X\":10,\"V\":5,\"I\":1} \n number=0\n prev_num=0\n for i in roman: \n number+=romanic[i] \n if romanic[i]>prev_num: \n number=number-(2*prev_num)\n prev_num=romanic[i]\n return number\n", "values = [('M', 1000), ('CM', -200), ('D', 500), ('CD', -200),\n ('C', 100), ('XC', -20), ('L', 50), ('XL', -20),\n ('X', 10), ('IX', -2), ('V', 5), ('IV', -2),\n ('I', 1)]\ndef solution(roman):\n return sum(roman.count(s)*v for s,v in values)", "def solution(roman):\n ans = 0\n numerals = {\"M\":1000,\"D\":500,\"C\":100,\"L\":50,\"X\":10,\"V\":5,\"I\":1}\n for x in range(0,len(roman)):\n if x < len(roman)-1 and numerals[roman[x]] < numerals[roman[x+1]]:\n ans = ans - numerals[roman[x]]\n else:\n ans = ans + numerals[roman[x]]\n return ans", "import lzma, base64\n\nsolution = lambda r: lzma.decompress(base64.b64decode(\"\"\"\\\n /Td6WFo\n AAATm1r\n RGAgAhA\n RYAAAB0\n L+Wj4IT\n PDa5dAC\n +IBTAD\n CJOfKM\n Rt/y05\n ncAbPH\n e/ziZ5\n +lW9kF\n 9apVzeQmm\n psQxWSa1Vj\n Vw0eOX96iJ\n AQAOMdiyld0\n sRLijjQWnNEj\n SX+C4RCcTLw6\n bbBQ4gBNEtE/\n J8Xpew2izDFru\n zCker5is WtTkyf\n Bmh1cPQf uhXI5E\n Elng7n5P 7Az2pC ksO2lQlx4JKbk\n CMHbwaIh6 bK9e5p GyvWtQJb32tJ+s1j\n Nw4AEa0eX 7R9U7X ns57GeveiFAaaLdiwpGIf\n zNJytHpyxR jl/SQT EBPJ3/dJ7D1CpMr5lEVk3yRr\n Muo2eLSouN BHkDVz b6rQexAiAGqur2nqcP6iMUab7lJ\n 7Atsjv09bPz Mh/tzn 3Duiy4gfTajPi1GXYddhGNGPKu6Y\n T7VZO0gHZC8OoLkdG4TIzM b8qfQj0Krb/4D/KketjjIVXLSQscFD\n FRQ8NlZRz8S/uAACXvxhrB I5UkGzWXQB921RMO46lOq1Qpj/DAU+R\n yDhpaE3jagOIQ6t8tC+57aq26 6SHjln1K49lAj+0QxAa5itcNxqYvkNYb\n nWuZyHzEpIaj6M721gBPZGuq90WtHJ QfSmhkU3g8oYn4dXMfOYd/JxVNTFv0uER3h\n CdkSk4B+DEJBg0cS2CMoCEhmJ9R7Ux N2pYMYGoKrZ6kCTSXC+6Cn+bCfrOulsOTxWR+\n TBx/B4fyX/vSDY55/1LPURZfrWrKF3jTGJopUpacl4hajl3nuIW7V31oddC8+j7sfC\n LEWKiQgB5sp/SjtvvbPDVjibyvrOs975PIBz8jVo4W88FHwFZ7OSiaswWcZCINEj\n h5NgjvBB8nzbtA9Nc/KE0thSHUTeotlfpZO84FAiyCFpRMKcfLpnB/+BnLqL4D\n 3i0UJe OX7/LYhEhcl/oe8d4Eoz6zZwbYrMlc/W/Z13DUOYfIDuD2GqbWELZzkd\n rlqFSGv7T8bBwvhW3I9WfPCRJzU+Yruy8Yv2fKQKLDBPQLuQr7zbIsMM6Wq7pR9Xy\n ptgNFP7ebeDrK3/b1C4hQsrH6BHABWFdg31SbpCijEMAOXib5ZjWr+fSik6P6RLMzuY8\n v1u5z9cvy/BBokC2gu3XIVspV9CPSYw7dng3aA6JXvp3oYr6GYUnPNaRs8xWn6/l\n DxmBvS9EBq3zLapEaXOI0f+Ov2HBxwo6nqeqfu7skPEluQa8c1XCUnjJXpDc1q8aqr\n oQPfyJt80Z/kLYHqoyly82sTylBVByPbdGOx1aLU8DJcwPVoKldM+n6OxVa2sTZQ3+Kz5Un\n 3W3k1WL+6p8n5d0WO7Fm89A9rXPjC7RyMheWuvyjBzvMrDicRsoTbkKOlE9WgCBLwIUvJ9d77Y\n cGmxHZex4fn2exxXwObOfXDI67dnrEV9VqirXa05i+LCw2NmLa1O5qS6227qwrDRFX+Ge30Mce\n licP/W9tongIW1++1KuyAHYdTacDyNfaC1FhHW4VUcTwyjqXwmJ9OSFuxmkHH8Xs\n MgVopPAgd+aK8HmD2HLJ4Pm9dduyMPBuWx18btQUxgPL0EiB+1uhOupA6epIRCHuQp5 d\n 9/7QaZHwi+loqjcRnfocYK1oGHcF pjVMcOHy19U5I3IEGC9YH7kyMUSNfvxWCzynsz\n ZyL5d6wDfGq10sQzuHT0zBvp4a wKgt2P82d4Y4Ucahat42JzGunKGB34R1t+2H\n IBoV9R0Od4vsdKc2y8+SaNWN 3h5ru+y195DJ+ADp+XMz8omYShSDnmXwKe5H8\n pBIKzUTkny+mgMO5TTl3LN m1f64bRxbq8bQ8u5Fd/RyknXda8jeLZKy1daUum iO\n jWu24qGCtfMsIjA20wwk0l HX brW/Hw9VeMtG8pXRQsOEamAUfeyJdwRZOA35cpvauZOY\n lfS9Mo6bG3e28lh3vEo+s i1 up9tqkQ/QE+At+GJYzbJg9Vhn+T4Pont99BdW0NG9l\n NH+cIWItjDqN9ELhGuBAbK og eaVoVj4v9NA6GI0FpfSnI87b6DehE/D Ys\n iNvSwI/YojHiukqEnDZ+hiUgr xN1FyUwDjpF/3khOVikJjrcypyzbCNF\n iF+wXkiG4N57WF4xKvVRFYZJwpE TXznQ6KRBMVeA0HPReN P4PO UuXEQ\n boQTHjMF6CZ6zNtOUwpDWwabsmH7m zHROuVp/CU4nyYg3C+Xe OSr 8C1\n I3ZXS4OnhSaRVpw1fmKxVYz+zFxCMbj MN2zKyiKGxLycuDDtpk r\n mk0VwLYmECLn/+4AZLlvGYZgs9+dswl/R oOiTWrRLWYNCLwDuO\n NCquFYpXwPJ7OTfZmI/lSci0oxt6K1bCA+ LmwevjoFurWILV3m\n hJy91lo3FR75O+pTOFOXVqHREDIq54DhRhs +JX+k/56oDlL\n 8khxwGhFudFIJlMR+ocl4pcn5oal7b1yUv7P EQ6bhSzUGT\n 2DkhLG2xToc1FkSUCUs0ZBForTksg4oKeXY+wmzT5 d0ov8uhIs3\n RkU5d73LAX2WB3K8pSP7REvCXZN5GlmRpRNJyEoFfSF+EJBVHi amOIgs5/Jf\n HE9ZsEXrPyI9VkYUbA5zfuBuC6UbRFbGJv5kd0IYSbAGZQ+6Ip/n6XO0 FeUNdLXk8\n QNFBENfFfvSd7PYEPTpxHcUKRgoBXHitXZ8yyhsx98RQCnWJ37S2ZMqCyj7XG N1bTCXhXN\n C8SH/0qhB8eEMTI4MlZfQPN9GiK1rB+Kew7vXPlWUeVEM1yvdK6nip8ZmoVOOgj9dy +NfqJ1wN\n C6wTvnr4k7dBav1DI4r1M154EwJ5fQHtVq7huhJIHeVFFMIsJOJHwaw7HIOpAB+ra8Fi 0Rtsjudc\n co20P5sbAEOg50/JcF3wwsX6vLrPkXMrQ7wOHwvRS17E4gPZszd9fOPziqFUQTWn0qlv kt3DjZHz\n/ze4tiWlF94TLmcQTZUmsvJdWrMNVIt4itpjZQ71tkkFzYmdGl/67dIBwTSTxN3LxSefX mNbDPW9\nGPGTWnKXk61yp38Qa06gIHaxpBsRYotF8v4pFe8pJf23jrQYAmNsgnTjrEi/YteTy2GV /rCKdJA\nhX9K/GrNHuFaoq17s5AEjYBwQWFiRrIHltzynhi+xQHCTyzguBYLrT1BlAe433rIcY 1fTm0mxs\nKYwQiX2KR/w07P9g4NolasD9AaMUREJKbFe2DHoT C34ZqIGdqD67GXf3vNKT b41gBup2XJ\n 3Ae4ItCMgUkRcpAhfagPR YwuTzM BDdcOS1qh4mdxK471MjY ShqmAlAMOx8\n rcxtoAmdK4zCQg7WKTy+wv J7AwNX FACIORl3QZDAun/4B2L/ kcQZRqVnDbzde\n FyE/AGv2lKBQcVUTWs5LY /WHLkX +e4DaGLJSvBpS0JgM/w4 pH2JnU6mZ3YB\n UoQiKVB6E6Q+R5rSF78h o8ZWh1 Ze0dDrGjhvFlSwq1jzn wZ7 UeJJg6+\n rf39tvWMSrRkBbFF3WX uc7vqI HNL63rtNLDYk1lNSP91 uZ Et+c0\n 2PjNdK+aCUIJGBLiFG umzPTv Eb5i1TeV9rsqWAXO9+i y7lq\n r8W3HS348PkFoj7D5 TaWMTd GDkVzQJWOqKE0a2jlr/ Ajpo\n tE1f3mNbjnlP3gr 1j0Tfz HNJrXRuaUyruMQXZZu s4\n YmzQhagmlyLgC6 9bm0yu 8v7v6ILSbFEUtOo/j\n bljZ4G+CmEOhnt 7J5uOA a5bqP/fS2tXWFNq5u\n hCRpmP1C2lKIh ++Cvu0 Me8l9dy9ehafsxIG\n 5unn/tSbpZ6JU Qnx6Yf Y47uKb+W4yiX6D4t\n 8JvEHDtvot884paTfUy UuoVJ3Srm9Xcj2nJ\n VoUY5yr+bEdtU50V+ bNIm8TLp45w3MCD\n Co3Ry4SRQvsG/6l 0SszckG+2WefFa\n S6scWyVc9WX5HeW/ jixEi44ljwrNs2\n b6Brc3o2Sqd6n831d lgOO2nT+5rm18\n qdajthwQIdeJI12t FOPWTVVvuW+X6U\n 8p0aoC0KHtkIQRg sOmWEcALsRnKV+\n 1VvSiwDx4e71V LzQHHYIwTWdQa1\n Jc7IzK6CQKx V//Ai2P1TGA6wv\n gFmA2icc/ 8teq5Ef3CPO9COg\n pEA1OU9R yvpCuuWeBpNY8c\n LqCLorm hhkGBB7I0CXwuy5\n wx1tyUp H1qdSiGLomuoIO\n DWlFe21 OTWgfZ8f/yPXhZ\n 0EsElFT Mkxmwt8XJA3Yr\n GOGywvo bmHFrN9tpD6YD\n FAUCHa 6QSN4doeNIPUG\n O4TzQb Bg4hRqxxFXVI\n sxgb30 eVGwfxiUDvZ\n tjR0N3 UzlkXEMyQEc\n ZWU2AF STp4lJJtBY+\n yphBJE vt6PB2jIW2\n 1BR9fH Mx5qIAmAQh\n 0lkMnx Iw6EoryBGu\n mM0iMM sQjGLtB5EO\n IqoEDu gHditn3CoK\n WW5lsj BD3Qx/0qdJ\n CuS6GX x4FM2ebnO8fWKp\n ntfA8d LzSeUVtQdjr6baJF\n FvPKTx ROHoATjmcuuS8Za\n +k8hIE Y4QPMhGvw+rgmyO\n eS8ljL NRa+3ee2ejgRJ\n c7dN0u D2wdc+VotP3H\n gRwcVW CLXrUkFgFJ\n wEcr3+ hmfByOZqn\n qKf0LJ ka7Bshnwx\n 3Fo0Yc B4P6oE8\n kTBeuis rshRGerY\n N1H3fvn 1K0EZPQbP\nGS+o85xeZ/wyT2TJZ6RegMRdEdU/Haq0NXmXBLEQW7mgH7rBKJRWimm6vmrxhQewbVBdoszwppeYiIeukokoL0KUGtHWNUpaHG54bzeeH5mPrJ\nUDPEreNjIFmaxZ6Lib6q4MQOxaFwAAAABSbX0sVUXgFAAByhvQiQIAiLSQnrHEZ/sCAAAAAARZWg===\"\"\")).decode().split().index(r)", "def solution(roman):\n if roman == \"\": return 0\n if roman[:2] == \"IV\": return 4 + solution(roman[2:])\n if roman[:2] == \"IX\": return 9 + solution(roman[2:])\n if roman[:2] == \"XL\": return 40 + solution(roman[2:])\n if roman[:2] == \"XC\": return 90 + solution(roman[2:])\n if roman[:2] == \"CD\": return 400 + solution(roman[2:])\n if roman[:2] == \"CM\": return 900 + solution(roman[2:])\n if roman[0] == \"I\": return 1 + solution(roman[1:])\n if roman[0] == \"V\": return 5 + solution(roman[1:])\n if roman[0] == \"X\": return 10 + solution(roman[1:])\n if roman[0] == \"L\": return 50 + solution(roman[1:])\n if roman[0] == \"C\": return 100 + solution(roman[1:])\n if roman[0] == \"D\": return 500 + solution(roman[1:])\n if roman[0] == \"M\": return 1000 + solution(roman[1:])"]
{"fn_name": "solution", "inputs": [["XXI"], ["I"], ["IV"], ["MMVIII"], ["MDCLXVI"]], "outputs": [[21], [1], [4], [2008], [1666]]}
INTRODUCTORY
PYTHON3
CODEWARS
101,707
def solution(roman):
fb6b977a8713db52be416090680d2511
UNKNOWN
You get any card as an argument. Your task is to return a suit of this card. Our deck (is preloaded): ```python DECK = ['2S','3S','4S','5S','6S','7S','8S','9S','10S','JS','QS','KS','AS', '2D','3D','4D','5D','6D','7D','8D','9D','10D','JD','QD','KD','AD', '2H','3H','4H','5H','6H','7H','8H','9H','10H','JH','QH','KH','AH', '2C','3C','4C','5C','6C','7C','8C','9C','10C','JC','QC','KC','AC'] ``` ```python ('3C') -> return 'clubs' ('3D') -> return 'diamonds' ('3H') -> return 'hearts' ('3S') -> return 'spades' ```
["def define_suit(card):\n d = {'C': 'clubs', 'S':'spades', 'D':'diamonds','H':'hearts'}\n return d[card[-1]]\n", "def define_suit(card):\n return {'C':'clubs', 'S':'spades', 'D':'diamonds', 'H':'hearts'}[card[-1]]", "def define_suit(card):\n return {'C':'clubs','D':'diamonds','H':'hearts','S':'spades'}[card[-1]]", "def define_suit(card):\n suit = {'C':'clubs', 'D':'diamonds', 'H':'hearts', 'S':'spades'}\n return suit[card[-1]]", "def define_suit(card):\n a = { 'C':'clubs', 'D':'diamonds', 'H':'hearts', 'S':'spades'}\n return a.get(card[-1])", "def define_suit(card):\n return next(suit for suit in ['clubs', 'diamonds', 'hearts', 'spades'] if card[-1].lower() == suit[0])", "def define_suit(card):\n print(card)\n dict = {\"C\": 'clubs', \"S\": 'spades', \"D\": 'diamonds', \"H\": 'hearts'}\n return(dict[card[-1]])", "# What's the point of the preloaded deck?\nD = {'S':\"spades\", 'D':\"diamonds\", 'H':\"hearts\", 'C':\"clubs\"}\n\ndef define_suit(card):\n return D[card[-1]]", "def define_suit(card):\n return '{}'.format({'C':'clubs', 'S': 'spades', 'D': 'diamonds', 'H': 'hearts'}.get(card[-1]))", "suits={'S':\"spades\",'C':\"clubs\",'D':\"diamonds\",'H':\"hearts\"}\ndef define_suit(card):\n return suits[card[-1]]", "def define_suit(card):\n return {'C':'clubs', 'D':'diamonds', 'H':'hearts', 'S':'spades'}.get(card[-1])", "SUITS = 'diamonds clubs hearts spades clubs diamonds spades hearts'.split()\n\ndef define_suit(card):\n return SUITS[ord(card[-1])%7]\n \n", "define_suit = lambda card: {'C': 'clubs', 'S': 'spades', 'D': 'diamonds', 'H': 'hearts'}[card[-1]]", "def define_suit(card: str) -> str:\n \"\"\" Get a suit of given card. \"\"\"\n return {\n \"c\": \"clubs\",\n \"d\": \"diamonds\",\n \"h\": \"hearts\",\n \"s\": \"spades\"\n }.get(card[-1].lower())", "def define_suit(card):\n return \"clubs\" if 'C' in card else 'spades' if 'S' in card else 'diamonds' if 'D' in card else 'hearts'", "def define_suit(card):\n # Good luck\n return {\"C\":\"clubs\",\"S\":\"spades\",\"D\":\"diamonds\",\"H\":\"hearts\"}.pop(card[-1])", "def define_suit(card):\n return ['clubs', 'spades', 'diamonds', 'hearts'][('S' in card) + 2 * ('D' in card) + 3 * ('H' in card)]", "define_suit = lambda x:{'C':'clubs','D':'diamonds','H':'hearts','S':'spades'}[x[-1:]]", "def define_suit(card):\n DECK = ['2S','3S','4S','5S','6S','7S','8S','9S','10S','JS','QS','KS','AS',\n '2D','3D','4D','5D','6D','7D','8D','9D','10D','JD','QD','KD','AD',\n '2H','3H','4H','5H','6H','7H','8H','9H','10H','JH','QH','KH','AH',\n '2C','3C','4C','5C','6C','7C','8C','9C','10C','JC','QC','KC','AC']\n if card[-1] == 'S':\n return 'spades'\n elif card[-1] == 'C':\n return 'clubs'\n elif card[-1] == 'D':\n return 'diamonds'\n else:\n return 'hearts'", "def define_suit(card):\n if \"C\" in card: return 'clubs'\n if \"D\" in card: return 'diamonds'\n if \"H\" in card: return 'hearts'\n if \"S\" in card: return 'spades'\n \n\n# ('3C') -> return 'clubs'\n# ('3D') -> return 'diamonds'\n# ('3H') -> return 'hearts'\n# ('3S') -> return 'spades'\n", "def define_suit(card):\n for letter in card:\n if letter.upper() == 'C':\n return 'clubs'\n elif letter.upper() == 'S':\n return 'spades'\n elif letter.upper() == 'D':\n return 'diamonds'\n elif letter.upper() == 'H':\n return 'hearts'", "def define_suit(card):\n suits = {\n 'C': 'clubs',\n 'D': 'diamonds',\n 'H': 'hearts',\n 'S': 'spades',\n }\n if card[-1] not in suits:\n pass\n \n \n return suits[card[-1]]", "def define_suit(card):\n return 'clubs' if 'C' in card \\\n else 'diamonds' if 'D' in card \\\n else 'hearts' if 'H' in card \\\n else 'spades'", "def define_suit(card):\n for i in card:\n if \"S\" in card:\n return \"spades\"\n elif \"D\" in card:\n return \"diamonds\"\n elif \"H\" in card:\n return \"hearts\"\n elif \"C\" in card:\n return \"clubs\"", "def define_suit(card):\n\n if len(card) == 2:\n if card[1] == \"C\":\n return 'clubs'\n elif card[1] == \"D\":\n return 'diamonds'\n elif card[1] == \"H\":\n return 'hearts'\n elif card[1] == \"S\":\n return 'spades'\n else:\n if card[2] == \"C\":\n return 'clubs'\n elif card[2] == \"D\":\n return 'diamonds'\n elif card[2] == \"H\":\n return 'hearts'\n elif card[2] == \"S\":\n return 'spades'", "def define_suit(card):\n clubs = {\"C\": \"clubs\", \"D\": \"diamonds\", \"H\": \"hearts\", \"S\": \"spades\"}\n \n return clubs[card[-1]]", "def define_suit(card):\n letter = card[-1]\n if letter == \"C\":\n return 'clubs'\n elif letter == \"S\":\n return 'spades'\n elif letter == \"D\":\n return 'diamonds'\n else:\n return 'hearts'", "def define_suit(card):\n return 'clubs' if card.endswith('C')==True else 'diamonds' if card.endswith('D')==True else 'hearts' if card.endswith('H')==True else 'spades'", "m = {\n 'C': 'clubs',\n 'D': 'diamonds',\n 'H': 'hearts',\n 'S': 'spades'\n}\ndef define_suit(card):\n return m.get(card[-1])", "def define_suit(card):\n \n suite = card[-1]\n if card[-1] == 'S':\n return 'spades'\n elif card[-1] == 'D':\n return 'diamonds'\n elif card[-1] == 'H':\n return 'hearts'\n else:\n return 'clubs'", "def define_suit(card):\n # Good luck\n return 'clubs' if card[-1]=='C' \\\n else 'spades' if card[-1]=='S' \\\n else 'diamonds' if card[-1]=='D' \\\n else 'hearts' if card[-1]=='H' \\\n else None", "def define_suit(card):\n dicc={\n 'C':'clubs', \n 'D':'diamonds', \n 'H':'hearts', \n 'S':'spades'\n }\n return dicc[card[-1:].upper()]", "def define_suit(card):\n# if card[-1] == \"C\":\n# return \"clubs\"\n# elif card[-1] == \"S\":\n# return \"spades\"\n# elif card[-1] == \"D\":\n# return \"diamonds\"\n# elif card[-1] == \"H\":\n# return \"hearts\"\n a = {\n \"C\":\"clubs\",\n \"S\":\"spades\",\n \"D\":\"diamonds\",\n \"H\":\"hearts\"\n }\n if card[-1] in a:\n return a[card[-1]]", "def define_suit(card):\n return \"clubs\" if 'C' in card else \"diamonds\" if'D' in card else \"hearts\" if 'H' in card else \"spades\"", "dict = {'C' : 'clubs',\n 'S' : 'spades',\n 'D' : 'diamonds',\n 'H' : 'hearts',\n }\n\ndef define_suit(card):\n return dict.get(card[-1])", "def define_suit(card):\n if card[-1] == \"C\" : return 'clubs'\n if card[-1] == \"S\" : return 'spades'\n if card[-1] == \"D\" : return 'diamonds'\n return 'hearts'\n", "def define_suit(card):\n # Good luck\n DECK = ['2S','3S','4S','5S','6S','7S','8S','9S','10S','JS','QS','KS','AS',\n '2D','3D','4D','5D','6D','7D','8D','9D','10D','JD','QD','KD','AD',\n '2H','3H','4H','5H','6H','7H','8H','9H','10H','JH','QH','KH','AH',\n '2C','3C','4C','5C','6C','7C','8C','9C','10C','JC','QC','KC','AC']\n d={'C':'clubs','D':'diamonds','H':'hearts','S':'spades'}\n return d[card[-1]]", "def define_suit(card: str) -> str:\n return (\n \"clubs\"\n if \"C\" in card\n else \"diamonds\"\n if \"D\" in card\n else \"hearts\"\n if \"H\" in card\n else \"spades\"\n )", "def define_suit(card):\n if 'S' in card:\n return 'spades'\n elif 'C' in card:\n return 'clubs'\n elif 'H' in card:\n return 'hearts'\n else:\n return 'diamonds'", "def define_suit(card):\n d={'C':'clubs','S':'spades','D':'diamonds','H':'hearts'}\n return d.get(card[-1])", "def define_suit(card):\n print(card)\n return ('clubs', 'spades', 'diamonds', 'hearts')['CSDH'.index(card[-1])]", "def define_suit(card):\n if card[1] == 'C':\n return 'clubs'\n elif card[1] == 'S':\n return 'spades'\n elif card[1] == 'D':\n return 'diamonds'\n elif card[1] =='H':\n return 'hearts'\n elif card[1] =='0':\n if card[2] == 'C':\n return 'clubs'\n elif card[2] == 'S':\n return 'spades'\n elif card[2] == 'D':\n return 'diamonds'\n elif card[2] =='H':\n return 'hearts'", "def define_suit(cards):\n return 'clubs' if 'C' in cards else 'diamonds' if 'D' in cards else 'hearts' if 'H' in cards else 'spades'\n # Good luck\n", "def define_suit(card):\n c=card[-1]\n if c=='C':\n return 'clubs'\n elif c=='D':\n return 'diamonds'\n elif c=='H':\n return 'hearts'\n else:\n return 'spades'", "def define_suit(card):\n ls = [char for char in card]\n if ls[-1] == 'C':\n return 'clubs'\n elif ls[-1] == 'D':\n return 'diamonds'\n elif ls[-1] == 'H':\n return 'hearts'\n else:\n return 'spades'\n", "def define_suit(card):\n suits = {'C': 'clubs','D': 'diamonds','S': 'spades','H': 'hearts'}\n if card[-1] in suits:\n return suits[card[-1]]", "def define_suit(card):\n return {'C': 'clubs', 'S': 'spades', 'D': 'diamonds', 'H': 'hearts'}.setdefault(card[-1], None)", "def define_suit(card):\n if card[-1] is 'C':\n return 'clubs'\n elif card[-1] is 'S':\n return 'spades'\n elif card[-1] is 'D':\n return 'diamonds'\n elif card[-1] is 'H':\n return 'hearts'\n \n", "def define_suit(card):\n v = {\"C\":\"clubs\", \"S\":\"spades\", \"D\":\"diamonds\", \"H\":\"hearts\"}\n return v[card[-1]]", "def define_suit(card):\n SUITS = ['clubs', 'diamonds', 'hearts', 'spades']\n for i in SUITS:\n if card[-1] == str.upper(i[0]):\n return i", "def define_suit(card):\n if card.endswith('C'):\n return 'clubs'\n elif card.endswith('S'):\n return 'spades'\n elif card.endswith('H'):\n return 'hearts'\n elif card.endswith('D'):\n return 'diamonds'", "def define_suit(card):\n return 'clubs' if 'C' in card else 'diamonds' if 'D' in card else 'hearts' if 'H' in card else 'spades' if 'S' in card else False", "def define_suit(card):\n\n what = {\"C\":\"clubs\",\n \"D\":\"diamonds\",\n \"H\":\"hearts\",\n \"S\":\"spades\"}\n \n for k,v in list(what.items()):\n if k in card:\n return v\n", "def define_suit(c):\n return {'C':'clubs', 'D':'diamonds', 'H':'hearts', 'S':'spades'}.get(c[-1])", "def define_suit(card):\n suits = {\n 'C' : 'clubs',\n 'D' : 'diamonds',\n 'S' : 'spades',\n 'H' : 'hearts'\n }\n \n return suits.get(card[-1])", "def define_suit(card):\n d = {'S':'spades','D':'diamonds','H':'hearts','C':'clubs'}\n return d[card[1]] if len(card)<3 else d[card[2]]", "def define_suit(card):\n a = {\"C\": \"clubs\", \"D\": \"diamonds\", \"H\": \"hearts\", \"S\": \"spades\"}\n return a[card[-1]] if card[-1] in a else False", "def define_suit(card):\n for k in card:\n if k=='C':\n return 'clubs'\n elif k=='D':\n return 'diamonds'\n elif k=='H':\n return 'hearts'\n elif k=='S':\n return 'spades'", "def define_suit(card):\n for elem in card:\n if 'S' in card:\n return 'spades'\n elif 'D' in card:\n return 'diamonds'\n elif 'H' in card:\n return 'hearts'\n else:\n return 'clubs'", "def define_suit(card):\n if card[-1] == 'C':\n return 'clubs'\n if card[-1] == 'D':\n return 'diamonds'\n if card[-1] == 'H':\n return 'hearts'\n if card[-1] == 'S':\n return 'spades'\n return ''\n", "def define_suit(card):\n if card in ['2C','3C','4C','5C','6C','7C','8C','9C','10C','JC','QC','KC','AC']: return 'clubs'\n if card in ['2S','3S','4S','5S','6S','7S','8S','9S','10S','JS','QS','KS','AS']: return 'spades'\n if card in ['2D','3D','4D','5D','6D','7D','8D','9D','10D','JD','QD','KD','AD']: return 'diamonds'\n if card in ['2H','3H','4H','5H','6H','7H','8H','9H','10H','JH','QH','KH','AH']: return 'hearts'", "def define_suit(card):\n switcher = {'C' : 'clubs', 'S': 'spades', 'D': 'diamonds', 'H': 'hearts'}\n return switcher[card[-1]]", "def define_suit(card):\n if card[-1] == 'C':\n return 'clubs'\n elif card[-1] == 'S':\n return 'spades'\n elif card[-1] == 'H':\n return 'hearts'\n else:\n return 'diamonds'", "def define_suit(card):\n if \"D\" in card:\n return \"diamonds\"\n elif \"S\" in card:\n return \"spades\"\n elif \"C\" in card:\n return \"clubs\"\n else:\n return \"hearts\"", "value = { \"C\" : \"clubs\",\n \"D\" : \"diamonds\",\n \"H\" : \"hearts\",\n \"S\" : \"spades\"\n }\n\ndef define_suit(card):\n return value.get(card[-1])\n \n", "value = { \"C\" : \"clubs\",\n \"D\" : \"diamonds\",\n \"H\" : \"hearts\",\n \"S\" : \"spades\"\n }\n\ndef define_suit(card):\n if card[-1] in value:\n return value.get(card[-1])\n", "import re\ndef define_suit(card):\n if re.search(r\"D\\Z\",card):\n return \"diamonds\"\n if re.search(r\"C\\Z\",card):\n return 'clubs'\n if re.search(r\"H\\Z\",card):\n return 'hearts'\n if re.search(r\"S\\Z\",card):\n return 'spades'\n \n", "def define_suit(card):\n suits = {\n \"C\": \"clubs\",\n \"D\": \"diamonds\",\n \"H\": \"hearts\",\n \"S\": \"spades\",\n }\n last_char = card[-1]\n return suits[last_char]\n", "def define_suit(card):\n if card[-1]==\"D\": return 'diamonds'\n elif card[-1]==\"C\": return 'clubs'\n elif card[-1]==\"S\": return 'spades'\n else: return 'hearts'", "def define_suit(c):\n# return {\n# 'C': 'clubs',\n# 'D': 'diamonds',\n# 'H': 'hearts',\n# 'S': 'spades'\n# }.get(c[-1])\n return {'C':'clubs', 'D':'diamonds', 'H':'hearts', 'S':'spades'}[c[-1]]", "def define_suit(card):\n d={\n 'C': 'clubs',\n 'D': 'diamonds',\n 'H': 'hearts',\n 'S': 'spades',\n }\n a = list(card)\n return d.get(a[-1])", "def define_suit(card):\n for each in card:\n if each[-1] == 'C':\n return 'clubs'\n elif each[-1] == 'D':\n return 'diamonds'\n elif each[-1] == 'H':\n return 'hearts'\n elif each[-1] == 'S':\n return 'spades'", "def define_suit(card):\n c={\n 'C':'clubs',\n 'D':'diamonds',\n 'H':'hearts',\n 'S':'spades'\n }\n return c.get(card[-1])", "def define_suit(c):\n return 'clubs' if \"C\" in c else 'spades' if \"S\" in c else 'diamonds' if \"D\" in c else 'hearts'", "import re\ndef define_suit(card):\n if re.search(r'C', card):\n return \"clubs\"\n elif re.search(r'D', card):\n return \"diamonds\"\n elif re.search(r'H', card):\n return \"hearts\"\n elif re.search(r'S', card):\n return \"spades\"", "def define_suit(card):\n if card[-1] == \"D\":\n return \"diamonds\"\n elif card[-1] == \"C\":\n return \"clubs\"\n elif card[-1] == \"H\":\n return \"hearts\"\n elif card[-1] == \"S\":\n return \"spades\"\n", "define_suit = lambda card: {'S': 'spades', 'D': 'diamonds', 'H': 'hearts', 'C': 'clubs'}[card[-1]]", "def define_suit(card):\n dictionary = {'C':'clubs','D':'diamonds','S':'spades','H':'hearts'}\n \n return dictionary.get(card[-1])", "def define_suit(card):\n if card[-1] == \"D\":\n return \"diamonds\"\n if card[-1] == \"H\":\n return \"hearts\"\n if card[-1] == \"C\":\n return \"clubs\"\n if card[-1] == \"S\":\n return \"spades\"", "def define_suit(card):\n if 'C' in card:\n return 'clubs'\n elif 'D' in card:\n return 'diamonds'\n elif 'H' in card:\n return 'hearts'\n elif 'S' in card:\n return 'spades'\n else:\n return None", "def define_suit(card):\n dave_fuck = {'C' : 'clubs', 'D' : 'diamonds', 'H' : 'hearts', 'S' : 'spades'}\n return dave_fuck[card[-1]]", "def define_suit(card):\n dict = {\n 'C' : 'clubs',\n 'D' : 'diamonds',\n 'H' : 'hearts',\n 'S' : 'spades',\n }\n return dict.get(card[-1])", "def define_suit(card):\n if card[-1] == 'C': return 'clubs'\n if card[-1] == 'S': return 'spades'\n if card[-1] == 'H': return 'hearts'\n if card[-1] == 'D': return 'diamonds'", "def define_suit(card):\n if card[len(card)-1]=='S':\n return 'spades'\n elif card[len(card)-1]=='C':\n return 'clubs'\n elif card[len(card)-1]=='D':\n return 'diamonds'\n else:\n return 'hearts'", "def define_suit(card):\n if card[-1] == 'C':\n return 'clubs'\n elif card[-1] == 'D':\n return 'diamonds'\n elif card[-1] == 'H':\n return 'hearts'\n return 'spades'", "def define_suit(card):\n return ('clubs', 'spades', 'diamonds', 'hearts')[{'C':0,'S':1,'D':2,'H':3}.get(card[-1])]", "L = {'C': 'clubs', 'S': 'spades', 'D': 'diamonds', 'H': 'hearts'}\ndef define_suit(card):\n return L[card[-1]]", "def define_suit(card):\n head = {'C': 'clubs', 'S': 'spades', 'D': 'diamonds', 'H': 'hearts'}\n return head[card[-1]]", "def define_suit(card):\n card = card.lower()\n if \"c\" in card:\n return \"clubs\"\n elif \"d\" in card:\n return \"diamonds\"\n elif \"h\"in card:\n return \"hearts\"\n elif \"s\" in card:\n return \"spades\"", "def define_suit(card):\n if \"C\" in card: return \"clubs\"\n if \"S\" in card: return \"spades\"\n if \"H\" in card: return \"hearts\"\n if \"D\" in card: return \"diamonds\"\n", "def define_suit(card):\n dict_suits = {\n 'C': 'clubs',\n 'D': 'diamonds',\n 'H': 'hearts',\n 'S': 'spades',\n }\n \n return dict_suits[card[-1]]", "def define_suit(card):\n suite = {\n 'C': 'clubs',\n 'D': 'diamonds',\n 'H': 'hearts',\n 'S': 'spades'\n }\n return suite[card[-1]]", "def define_suit(c):\n return 'clubs' if c[-1]=='C' else 'spades' if c[-1]=='S' else 'hearts' if c[-1]=='H' else 'diamonds' "]
{"fn_name": "define_suit", "inputs": [["3C"], ["QS"], ["9D"], ["JH"]], "outputs": [["clubs"], ["spades"], ["diamonds"], ["hearts"]]}
INTRODUCTORY
PYTHON3
CODEWARS
18,687
def define_suit(card):
2e74b5aa21a23ebe0f79fd70c1da5bdf
UNKNOWN
You are given a string of words (x), for each word within the string you need to turn the word 'inside out'. By this I mean the internal letters will move out, and the external letters move toward the centre. If the word is even length, all letters will move. If the length is odd, you are expected to leave the 'middle' letter of the word where it is. An example should clarify: 'taxi' would become 'atix' 'taxis' would become 'atxsi'
["import re\n\ndef inside_out(s):\n return re.sub(r'\\S+', lambda m: inside_out_word(m.group()), s)\n\ndef inside_out_word(s):\n i, j = len(s) // 2, (len(s) + 1) // 2\n return s[:i][::-1] + s[i:j] + s[j:][::-1]", "def swap(word):\n m = len(word) // 2\n if len(word) % 2 == 0:\n return word[:m][::-1] + word[m:][::-1]\n else:\n return word[:m][::-1] + word[m] + word[m+1:][::-1]\n \ndef inside_out(st):\n return ' '.join(map(swap, st.split()))", "def inside_out(s):\n return ' '.join(w[:len(w)//2][::-1] + w[len(w)//2:(len(w)+1)//2] + w[(len(w)+1)//2:][::-1] for w in s.split())", "from itertools import chain\n\ndef change(st):\n if len(st) < 4: return st\n q, r = divmod(len(st), 2)\n return ''.join(chain(st[q-1::-1], st[q:q+r], st[:q+r-1:-1]))\n\ndef inside_out(st):\n return ' '.join(map(change, st.split()))", "def inside_out(st):\n def inside_out_1(st):\n h, m = divmod(len(st), 2)\n return st[:h][::-1] + st[h:h + m] + st[h + m:][::-1]\n return ' '.join(map(inside_out_1, st.split(' ')))", "def inside_out(s):\n return ' '.join( w[:m][::-1] + w[m] * (L%2) + w[-m:][::-1] * (L>1)\n if w else w\n for w,m,L in map(lambda w: (w, len(w)//2, len(w)), s.split(' ')) )", "inside_out=lambda s:\" \".join([i[:len(i)//2][::-1] + [\"\",i[len(i)//2]][len(i)&1] + i[len(i)//2+(len(i)&1):][::-1] for i in s.split()])", "def inside_out(text):\n return ' '.join(next(f'{w[:i][::-1]}{w[i:j]}{w[j:][::-1]}' for i, j in [[len(w)//2, (len(w)+1)//2]]) for w in text.split())", "inside_out=lambda s:\" \".join(x[:l][::-1]+x[l]*n+x[l+n:][::-1]for x in s.split()for l,n in[(len(x)//2,len(x)%2)])"]
{"fn_name": "inside_out", "inputs": [["man i need a taxi up to ubud"], ["what time are we climbing up the volcano"], ["take me to semynak"], ["massage yes massage yes massage"], ["take bintang and a dance please"]], "outputs": [["man i ende a atix up to budu"], ["hwta item are we milcgnib up the lovcona"], ["atek me to mesykan"], ["samsega yes samsega yes samsega"], ["atek nibtgna and a adnec elpesa"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,701
def inside_out(s):
776a5de18027904dc26b2a868a7e8f0c
UNKNOWN
Well met with Fibonacci bigger brother, AKA Tribonacci. As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won't get to hear non-native Italian speakers trying to pronounce it :( So, if we are to start our Tribonacci sequence with `[1, 1, 1]` as a starting input (AKA *signature*), we have this sequence: ``` [1, 1 ,1, 3, 5, 9, 17, 31, ...] ``` But what if we started with `[0, 0, 1]` as a signature? As starting with `[0, 1]` instead of `[1, 1]` basically *shifts* the common Fibonacci sequence by once place, you may be tempted to think that we would get the same sequence shifted by 2 places, but that is not the case and we would get: ``` [0, 0, 1, 1, 2, 4, 7, 13, 24, ...] ``` Well, you may have guessed it by now, but to be clear: you need to create a fibonacci function that given a **signature** array/list, returns **the first n elements - signature included** of the so seeded sequence. Signature will always contain 3 numbers; n will always be a non-negative number; if `n == 0`, then return an empty array (except in C return NULL) and be ready for anything else which is not clearly specified ;) If you enjoyed this kata more advanced and generalized version of it can be found in the Xbonacci kata *[Personal thanks to Professor Jim Fowler on Coursera for his awesome classes that I really recommend to any math enthusiast and for showing me this mathematical curiosity too with his usual contagious passion :)]*
["def tribonacci(signature, n):\n res = signature[:n]\n for i in range(n - 3): res.append(sum(res[-3:]))\n return res", "def tribonacci(signature,n):\n while len(signature) < n:\n signature.append(sum(signature[-3:]))\n \n return signature[:n]", "def tribonacci(signature, n):\n s = signature.copy()\n while len(s) < n:\n s.append(sum(s[-3:]))\n return s[:n]\n", "def tribonacci(s, n):\n for i in range(3, n): s.append(s[i-1] + s[i-2] + s[i-3])\n return s[:n]", "def tribonacci(signature, n):\n output = signature[:n]\n while len(output) < n:\n output.append(sum(output[-3:]))\n return output", "def tribonacci(signature,n):\n return signature[:n] if n<=len(signature) else tribonacci(signature + [sum(signature[-3:])],n)", "def tribonacci(signature,n):\n result = []\n if n > 3:\n result = signature\n for i in range(0,n-3):\n nextTrib = result[0+i] + result[1+i] + result[2+i]\n print(nextTrib)\n result.append(nextTrib)\n elif n == 3:\n result = signature\n elif n == 2:\n result = [signature[0],signature[1]]\n elif n == 1:\n result = [signature[0]]\n return result", "def tribonacci(signature,n):\n [signature.append(sum(signature[i-3:i])) for i in range(3,n)]\n return signature[0:n]", "def tribonacci(signature,n):\n for _ in range(3,n):\n signature += [sum(signature[-3:])]\n return signature[0:n]", "def tribonacci(s, n):\n if(n>3):\n for i in range(n - 3):\n s.append(s[i] + s[i + 1] + s[i + 2])\n return s\n else:\n return s[:n]\n #your code here\n"]
{"fn_name": "tribonacci", "inputs": [[[1, 1, 1], 10], [[0, 0, 1], 10], [[0, 1, 1], 10], [[1, 0, 0], 10], [[0, 0, 0], 10], [[1, 2, 3], 10], [[3, 2, 1], 10], [[1, 1, 1], 1], [[300, 200, 100], 0], [[0.5, 0.5, 0.5], 30]], "outputs": [[[1, 1, 1, 3, 5, 9, 17, 31, 57, 105]], [[0, 0, 1, 1, 2, 4, 7, 13, 24, 44]], [[0, 1, 1, 2, 4, 7, 13, 24, 44, 81]], [[1, 0, 0, 1, 1, 2, 4, 7, 13, 24]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[1, 2, 3, 6, 11, 20, 37, 68, 125, 230]], [[3, 2, 1, 6, 9, 16, 31, 56, 103, 190]], [[1]], [[]], [[0.5, 0.5, 0.5, 1.5, 2.5, 4.5, 8.5, 15.5, 28.5, 52.5, 96.5, 177.5, 326.5, 600.5, 1104.5, 2031.5, 3736.5, 6872.5, 12640.5, 23249.5, 42762.5, 78652.5, 144664.5, 266079.5, 489396.5, 900140.5, 1655616.5, 3045153.5, 5600910.5, 10301680.5]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,667
def tribonacci(signature,n):
1d5586b3a4acdae746616e79af3b15aa
UNKNOWN
When you want to get the square of a binomial of two variables x and y, you will have: `$(x+y)^2 = x^2 + 2xy + y ^2$` And the cube: `$(x+y)^3 = x^3 + 3x^2y + 3xy^2 +y^3$` It is known from many centuries ago that for an exponent n, the result of a binomial x + y raised to the n-th power is: Or using the sumation notation: Each coefficient of a term has the following value: Each coefficient value coincides with the amount of combinations without replacements of a set of n elements using only k different ones of that set. Let's see the total sum of the coefficients of the different powers for the binomial: `$(x+y)^0(1)$` `$(x+y)^1 = x+y(2)$` `$(x+y)^2 = x^2 + 2xy + y ^2(4)$` `$(x+y)^3 = x^3 + 3x^2y + 3xy^2 +y^3(8)$` We need a function that may generate an array with the values of all the coefficients sums from 0 to the value of n included and has the addition of all the sum values as last element. We add some examples below: ``` f(0) = [1, 1] f(1) = [1, 2, 3] f(2) = [1, 2, 4, 7] f(3) = [1, 2, 4, 8, 15] ``` Features of the test ``` Low Performance Tests Number of tests = 50 9 < n < 101 High Performance Tests Number of Tests = 50 99 < n < 5001 ```
["def f(n):\n return [2**i for i in range(n+1)]+[(2**(n+1))-1]", "def f(n):\n return [1 << i for i in range(n+1)] + [(1 << (n+1)) - 1]", "def f(n):\n result = [1]\n for i in range(n):\n result.append(result[-1]*2)\n result.append(sum(result))\n return result", "f=lambda n:[2**x for x in range(n+1)]+[2**(n+1)-1]", "def f(n): return list(g(n))\ndef g(n):\n v = 1\n for i in range(n + 1):\n yield v\n v *= 2\n yield v - 1\n", "f=lambda n:[1<<i for i in range(n+1)]+[(1<<n+1)-1]", "def f(n):\n r,c=[1],1\n for i in range(n): c<<=1; r.append(c)\n return r+[(c<<1)-1]", "def f(n):\n x=[2**i for i in range(n+1)]\n x.append(2**(n+1)-1)\n return x", "def f(n):\n # your code here\n return [2**i if i != n + 1 else 2**i - 1for i in range(n+2)]", "def f(n):\n output = []\n to_add = 0\n for i in range(0,n+1):\n output.append(2**i)\n output.append(sum(output))\n return output"]
{"fn_name": "f", "inputs": [[0], [1], [2], [3], [6], [10]], "outputs": [[[1, 1]], [[1, 2, 3]], [[1, 2, 4, 7]], [[1, 2, 4, 8, 15]], [[1, 2, 4, 8, 16, 32, 64, 127]], [[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2047]]]}
INTRODUCTORY
PYTHON3
CODEWARS
950
def f(n):
b23451659eb9835174e0d391d95cad7c
UNKNOWN
Share price =========== You spent all your saved money to buy some shares. You bought it for `invested`, and want to know how much it's worth, but all the info you can quickly get are just the change the shares price made in percentages. Your task: ---------- Write the function `sharePrice()` that calculates, and returns the current price of your share, given the following two arguments: - `invested`(number), the amount of money you initially invested in the given share - `changes`(array of numbers), contains your shares daily movement percentages The returned number, should be in string format, and it's precision should be fixed at 2 decimal numbers. Have fun! >**Hint:** Try to write the function in a functional manner!
["def share_price(invested, changes):\n for change in changes:\n invested = invested * (100 + change) / 100.0\n return format(invested, '.2f')", "def share_price(invested, changes):\n sum=float(invested)\n for i in changes:\n sum=sum+(sum/100*i)\n return str('{:.2f}'.format(float(sum)))", "def share_price(invested, changes):\n for change in changes:\n invested = invested + ( invested * (change/100.00) )\n return \"%.2f\" % invested \n \n", "import operator\nfrom functools import reduce\n\n\ndef share_price(invested, changes):\n multipliers = (1.0 + c / 100.0 for c in changes)\n product = reduce(operator.mul, multipliers, 1.0)\n return '%.2f' % (invested * product)\n", "from functools import reduce\n\ndef share_price(invested, changes):\n r = reduce(lambda acc, x: acc + x * acc * 0.01, changes, invested)\n return '{:.2f}'.format(r)", "from functools import reduce\ndef share_price(invested, changes):\n return '{:.2f}'.format(\n reduce(lambda a, b: a + (a * (b / 100.0)), changes, invested))\n"]
{"fn_name": "share_price", "inputs": [[100, []], [100, [-50, 50]], [100, [-50, 100]], [100, [-20, 30]], [1000, [0, 2, 3, 6]]], "outputs": [["100.00"], ["75.00"], ["100.00"], ["104.00"], ["1113.64"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,076
def share_price(invested, changes):
bf1202b2a6bdbc70bb5eb6c1b5285bf5
UNKNOWN
Create an identity matrix of the specified size( >= 0). Some examples: ``` (1) => [[1]] (2) => [ [1,0], [0,1] ] [ [1,0,0,0,0], [0,1,0,0,0], (5) => [0,0,1,0,0], [0,0,0,1,0], [0,0,0,0,1] ] ```
["def get_matrix(n):\n return [[1 if i==j else 0 for i in range(n)] for j in range(n)]", "import numpy\ndef get_matrix(n):\n return numpy.eye(n, dtype=int).tolist()", "get_matrix=lambda n: [[int(i==j) for j in range(n)] for i in range(n)]", "def get_matrix(n):\n return [[int(i == j) for j in range(n)] for i in range(n)]", "def get_matrix(n):\n return [ [ [0,1][i is _ ]for i in range(n)] for _ in range(n)]", "get_matrix = lambda n: [[j == i for j in range(n)] for i in range(n)]", "def get_matrix(n):\n return [[x==y for x in range(n)] for y in range(n)] ", "from numpy import identity, ndarray\n\ndef get_matrix(n):\n return identity(n).tolist()", "import numpy\n\ndef get_matrix(n):\n return numpy.identity(n).tolist()", "def get_matrix(n):\n #your code here\n matrix = []\n \n for idx in range(0, n):\n child_matrix = []\n child_matrix += ([0] * idx) + [1] + ([0] * (n -1 - idx))\n matrix.append(child_matrix)\n return matrix\n"]
{"fn_name": "get_matrix", "inputs": [[0], [1], [2], [3], [5]], "outputs": [[[]], [[[1]]], [[[1, 0], [0, 1]]], [[[1, 0, 0], [0, 1, 0], [0, 0, 1]]], [[[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]]]]}
INTRODUCTORY
PYTHON3
CODEWARS
992
def get_matrix(n):
8e9f88863fa6692f5b616c26b6d52c83
UNKNOWN
In your class, you have started lessons about geometric progression. Since you are also a programmer, you have decided to write a function that will print first `n` elements of the sequence with the given constant `r` and first element `a`. Result should be separated by comma and space. ### Example ```python geometric_sequence_elements(2, 3, 5) == '2, 6, 18, 54, 162' ``` More info: https://en.wikipedia.org/wiki/Geometric_progression
["def geometric_sequence_elements(a, r, n):\n return ', '.join(str(a * r ** i) for i in range(n))\n", "def geometric_sequence_elements(a, r, n):\n l = []\n for _ in range(n):\n l.append(str(a))\n a *= r\n return \", \".join(l)\n", "def geometric_sequence_elements(a, r, n):\n return \", \".join(str(a * r**i) for i in range(n))\n", "def geometric_sequence_elements(a, r, n):\n return ', '.join([str(a*r**x) for x in list(range(n))])", "def geometric_sequence_elements(a, r, n):\n return str([a*pow(r,i) for i in range(n)])[1:-1]", "def geometric_sequence_elements(a, r, n):\n arr = [a]\n for i in range(n - 1):\n arr.append(arr[i] * r)\n return ', '.join(map(str, arr))", "geometric_sequence_elements=lambda a,r,n:', '.join(str(a*r**e) for e in range(n))", "def geometric_sequence_elements(a, r, n):\n res = [a]\n for i in range(n - 1):\n res.append(res[-1] * r)\n return ', '.join(map(str, res))", "def geometric_sequence_elements(a, r, n):\n seq = []\n for i in range(n):\n seq.append(a*r**i)\n return ', '.join(str(e) for e in seq)", "def geometric_sequence_elements(a, r, n):\n string = \"\"\n for x in range(0,n):\n if x!=n-1:\n string += str(a * (r ** x)) + \", \"\n else:\n string += str(a * (r ** x))\n return(string)"]
{"fn_name": "geometric_sequence_elements", "inputs": [[2, 3, 5], [2, 2, 10], [1, -2, 10]], "outputs": [["2, 6, 18, 54, 162"], ["2, 4, 8, 16, 32, 64, 128, 256, 512, 1024"], ["1, -2, 4, -8, 16, -32, 64, -128, 256, -512"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,329
def geometric_sequence_elements(a, r, n):
b693103876dd194b61164647313598e8
UNKNOWN
Create a function that accepts 3 inputs, a string, a starting location, and a length. The function needs to simulate the string endlessly repeating in both directions and return a substring beginning at the starting location and continues for length. Example: ```python endless_string('xyz', -23, 6) == 'yzxyzx' ``` To visualize: Negative Positive 3 2 1 * 1 2 3 0987654321098765432109876543210123456789012345678901234567890 xyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzxyzx ****** -23 for a length of 6 == 'yzxyzx' Some more examples: ```python endless_string('xyz', 0, 4) == 'xyzx' endless_string('xyz', 19, 2) == 'yz' endless_string('xyz', -4, -4) == 'zxyz' ``` A negative length needs to include the starting postion and return the characters to the left of the starting position.
["from itertools import cycle, islice\n\ndef endless_string(string, start, length):\n i = (start + (length + 1 if length < 0 else 0)) % len(string)\n return ''.join(islice(cycle(string), i, i + abs(length)))", "from itertools import cycle, islice\n\ndef endless_string(stg, i, l):\n i = min(i, i+l) % len(stg) + (l < 0)\n j = i + abs(l)\n return \"\".join(islice(cycle(stg), i, j))", "from itertools import cycle, islice\n\ndef endless_string(string, start, length):\n r = (start + (length + 1)*(length < 0)) % len(string)\n return ''.join(islice(cycle(string), r, r+abs(length)))", "def endless_string(s, start, l):\n s = s * 500\n half = len(s) // 2\n return s[half + start:(half + start) + l] if l > 0 else s[half+start+l+1:half+start+1]", "def endless_string(strng, start, length):\n len_strng = len(strng)\n strng = strng * (abs(length) // len_strng + 1)\n true_start = min(start, start + length)\n start = true_start % len_strng + (length < 0)\n stop = start + abs(length)\n return strng[start:stop]\n\n\n\n#from itertools import cycle, islice\n\n#def endless_string(strng, start, length):\n# true_start = min(start, start + length)\n# start = true_start % len(strng) + (length < 0)\n# stop = start + abs(length)\n# return \"\".join(islice(cycle(strng), start, stop))\n", "def endless_string(stg, i, l):\n ls = len(stg)\n stg = stg * (2 + abs(l) // ls)\n i = min(i, i + l) % ls + (l < 0)\n j = i + abs(l)\n return stg[i:j]\n"]
{"fn_name": "endless_string", "inputs": [["xyz", -23, 6], ["xyz", 0, 4], ["xyz", 19, 2], ["xyz", -4, -4], ["abcdefghijklmnopqrstuvwxyz", 29, 1], ["Hello! How are you?", -14, 27], ["1x2x3x4x", 1532, 100], ["1x2x3x4x", -1532, -100], ["112233", 0, 0], ["112233", -1, 0], ["112233", 15824, 0]], "outputs": [["yzxyzx"], ["xyzx"], ["yz"], ["zxyz"], ["d"], ["! How are you?Hello! How ar"], ["3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x"], ["x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3x4x1x2x3"], [""], [""], [""]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,508
def endless_string(string, start, length):
b578e70a12366a00fda84eee4b114c20
UNKNOWN
Your task is to validate rhythm with a meter. _________________________________________________ Rules: 1. Rhythmic division requires that in one whole note (1) there are two half notes (2) or four quarter notes (4) or eight eighth notes (8). Examples: 1 = 2 + 2, 1 = 4 + 4 + 4 + 4 ... Note that: 2 = 4 + 4, 4 = 8 + 8, 2 = 8 + 8 + 4 ... 2. Meter gives an information how many rhythmic types of notes should be in one bar. Bar is the the primary section of a musical score. Examples: 4/4 -> 4 quarter notes in a bar 5/2 -> 5 half notes in a bar 3/8 -> 3 eighth notes in a bar Note that: for 4/4 valid bars are: '4444', '88888888', '2488' ... for 5/2 valid bars are: '22222', '2244244', '8888244888844' ... for 3/8 valid bars are: '888', '48' ... 3. Anacrusis occurs when all bars but the first and last are valid, and the notes in the first and last bars when combined would also make a valid bar. Examples: for 4/4 valid anacrusis is -> 44|...|44 or 88|...|888888 or 2|...|488 for 5/2 valid anacrusis is -> 22|...|222 or 222|...|22 or 2244|...|244 for 3/8 valid anacrusis is -> 8|...|88 or 4|...|8 or 8|...|4 Note: When anacrusis is valid but other bars in score are not -> return 'Invalid rhythm' ________________________________________________ Input: meter - array: eg. [4, 4], score - string, bars separated with '|': eg. '4444|8484842|888' Output: string message: 'Valid rhythm', 'Valid rhythm with anacrusis' or 'Invalid rhythm'
["def is_valid_bar(bar, meter):\n total = 0\n for n in bar:\n n = int(n)\n if n & (n - 1):\n return False\n total += 1.0 / n\n return total == meter\n\ndef validate_rhythm(meter, score):\n n, d = meter\n if d & (d - 1):\n return \"Invalid rhythm\"\n bars = score.split(\"|\")\n meter = float(n) / d\n if all(is_valid_bar(bar, meter) for bar in bars[1:-1]):\n if all(is_valid_bar(bar, meter) for bar in (bars[0], bars[-1])):\n return \"Valid rhythm\"\n if len(bars) > 1 and is_valid_bar(bars[0] + bars[-1], meter):\n return \"Valid rhythm with anacrusis\"\n return \"Invalid rhythm\"", "from fractions import Fraction\n\n\nVALID_CHARS = {\"1\", \"2\", \"4\", \"8\"}\n\n\ndef note_sum(s):\n return sum(Fraction(1, x) for x in map(int, s))\n\n\ndef validate_rhythm(meter, score):\n if meter[1] not in [1, 2, 4, 8]:\n return \"Invalid rhythm\"\n ss = score.split(\"|\")\n if not all(s and all(x in VALID_CHARS for x in s) for s in ss):\n return \"Invalid rhythm\"\n\n note = Fraction(*meter)\n if all(note_sum(s) == note for s in ss):\n return \"Valid rhythm\"\n ss[0] += ss.pop()\n if all(note_sum(s) == note for s in ss):\n return \"Valid rhythm with anacrusis\"\n return \"Invalid rhythm\"", "from functools import reduce\n\ndef validate_rhythm(meter, score):\n num, den, meter = *meter, int.__truediv__(*meter)\n bars = [[int(d) for d in bar] for bar in score.split(\"|\")]\n prod = den * reduce(int.__mul__, (n for bar in bars for n in bar))\n if not prod & (prod - 1):\n divs = [sum(1/n for n in bar) for bar in bars]\n if all(div == meter for div in divs[1:-1]):\n if all(div == meter for div in (divs[0], divs[-1])):\n return \"Valid rhythm\"\n if divs[1:] and divs[0] + divs[-1] == meter:\n return \"Valid rhythm with anacrusis\"\n return \"Invalid rhythm\"\n", "def validate_rhythm(meter, score):\n if [c for c in score if c not in '|1248'] or meter[1] not in [1,2,4,8] : return 'Invalid rhythm'\n bar = meter[0] * 8 / meter[1]\n l = [len(b) for b in score.replace('4', '88').replace('2', '8'*4).replace('1', '8'*8).split('|')]\n if all(i == bar for i in l): return 'Valid rhythm'\n if l[0] + l[-1] == bar and all(i == bar for i in l[1:-1]): return 'Valid rhythm with anacrusis'\n return 'Invalid rhythm'", "def validate_rhythm(meter, score):\n scores = score.split('|')\n anacrusis = False\n if 16 % meter[1] : return 'Invalid rhythm'\n for i, score in enumerate(scores): \n sums = sum(16/int(s) for s in score)\n if sums < meter[0] * 16 / meter[1]:\n if i == len(scores) -1 or i == 0:\n anacrusis = True\n else:\n return 'Invalid rhythm'\n elif sums > meter[0] * 16 / meter[1]: return 'Invalid rhythm'\n if anacrusis:\n return 'Valid rhythm with anacrusis'\n else:\n return 'Valid rhythm'", "def validate_rhythm(meter, score):\n from fractions import Fraction\n if meter[1] not in [1,2,4,8]:\n return 'Invalid rhythm'\n \n time_signature = Fraction(*meter)\n bars = [sum(Fraction(1, int(c)) for c in bar) for bar in score.split('|')]\n\n if all(bar == time_signature for bar in bars):\n return 'Valid rhythm'\n \n if all(bar == time_signature for bar in bars[1:-1]) and bars[0] + bars[-1] == time_signature:\n return 'Valid rhythm with anacrusis'\n \n return 'Invalid rhythm'", "def validate_rhythm(m, score):\n t = m[0]/m[1]\n if t == 1 and m[0] not in [1,2,4,8]: return 'Invalid rhythm'\n a = score.split('|')\n \n for c in score:\n if c not in '|1248': return 'Invalid rhythm'\n \n for s in a[1:-1]:\n if sum([1/int(c) for c in s]) != t:\n return 'Invalid rhythm'\n \n bool = True\n for s in [a[0],a[-1]]:\n if sum([1/int(c) for c in s]) != t:\n bool = False\n if bool: return 'Valid rhythm'\n \n if sum([1/int(c) for c in a[0]+a[-1]]) == t:\n return 'Valid rhythm with anacrusis'\n \n return 'Invalid rhythm'\n", "def validate_rhythm(meter, score):\n a, b = meter\n if not set(score) <= set('1248|') or b not in (1, 2, 4, 8): \n return 'Invalid rhythm'\n bars = [sum(1 / int(x) for x in bar) for bar in score.split('|')]\n m = a / b\n if all(x == m for x in bars): \n return 'Valid rhythm'\n if len(bars) >= 2 and all(x == m for x in bars[1:-1] + [bars[0] + bars[-1]]):\n return 'Valid rhythm with anacrusis'\n return 'Invalid rhythm'", "def validate_rhythm(meter, score):\n if meter[1] not in (1,2,4,8):\n return \"Invalid rhythm\"\n \n score = score.translate(score.maketrans(\"1248\", \"8421\"))\n target = meter[0] * 8 // meter[1]\n \n def valid(s):\n return sum(int(c) for c in s) == target\n \n bars = score.split(\"|\")\n if any(not valid(bar) for bar in bars[1:-1]):\n return \"Invalid rhythm\"\n \n if valid(bars[0]) and valid(bars[-1]):\n return \"Valid rhythm\"\n \n if valid(bars[0] + bars[-1]):\n return \"Valid rhythm with anacrusis\"\n else:\n return \"Invalid rhythm\"", "def validate_rhythm(meter, score):\n print(score)\n if meter[1] not in [1,2,4,8]:\n return \"Invalid rhythm\"\n goal = meter[0]*(1/meter[1])\n print(goal)\n score = [[1/int(f) for f in i] for i in score.split(\"|\")]\n \n if len(score) == 1:\n if goal == sum([sum(i) for i in score]):\n return 'Valid rhythm'\n else:\n return 'Invalid rhythm'\n for i in score[1:-1]:\n if sum(i) != goal:\n return \"Invalid rhythm\"\n if sum(score[0]) + sum(score[-1]) == goal:\n return 'Valid rhythm with anacrusis'\n if sum(score[0]) + sum(score[-1]) != goal*2:\n return \"Invalid rhythm\"\n return \"Valid rhythm\"\n"]
{"fn_name": "validate_rhythm", "inputs": [[[8, 8], "1|22|4444|88888888"], [[4, 4], "1|22|4444|88888888"], [[2, 2], "1|22|4444|88888888"], [[1, 1], "1|22|4444|88888888"], [[3, 4], "24|444|888888"], [[4, 8], "2|44|8888"], [[2, 4], "2|44|8888"], [[1, 2], "2|44|8888"], [[10, 8], "14|444488|888824"], [[6, 4], "222|444444|884884884"], [[3, 2], "222|442884|88882488"], [[1, 1], "1"], [[1, 2], "2"], [[1, 4], "4"], [[1, 8], "8"], [[2, 4], "4|44|2|88"], [[5, 8], "888|448|82|88"], [[7, 2], "222|1112|2222222|2222"], [[2, 4], "4|4444|88"], [[1, 1], "2|11|228|2"], [[5, 8], "888|448|882|88"], [[3, 8], "|888|884|888"], [[3, 8], "888|884|888|"], [[3, 8], "|884|888|"], [[7, 2], "222|111|2222222|1112|2222"], [[1, 2], "2|44|22"], [[9, 8], "444448|2288"], [[7, 3], "222|111|2222222|1112|2222"], [[1, 3], "2|44|22"], [[9, 9], "1|22|4444|88888888"], [[6, 6], "1|22|4444|88888888"], [[1, 3], "3|3|3|3|3"], [[2, 7], "77|77|77|77"], [[2, 6], "66|66|66|66|66"]], "outputs": [["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm"], ["Valid rhythm with anacrusis"], ["Valid rhythm with anacrusis"], ["Valid rhythm with anacrusis"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"], ["Invalid rhythm"]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,057
def validate_rhythm(meter, score):
da710fbb1fa49c253b721a3f1095c495
UNKNOWN
Complete the function/method so that it takes CamelCase string and returns the string in snake_case notation. Lowercase characters can be numbers. If method gets number, it should return string. Examples: ``` javascript // returns test_controller toUnderscore('TestController'); // returns movies_and_books toUnderscore('MoviesAndBooks'); // returns app7_test toUnderscore('App7Test'); // returns "1" toUnderscore(1); ``` ``` coffeescript # returns test_controller toUnderscore 'TestController' # returns movies_and_books toUnderscore 'MoviesAndBooks' # returns app7_test toUnderscore 'App7Test' # returns "1" toUnderscore 1 ```
["import re\n\ndef to_underscore(string):\n return re.sub(r'(.)([A-Z])', r'\\1_\\2', str(string)).lower() \n", "def to_underscore(string):\n string = str(string)\n camel_case = string[0].lower()\n for c in string[1:]:\n camel_case += '_{}'.format(c.lower()) if c.isupper() else c\n return camel_case", "def to_underscore(string):\n return ''.join('_'+c.lower() if c.isupper() else c for c in str(string)).lstrip('_')", "import re\ndef to_underscore(string):\n return re.sub(\"(?<=.)(?=[A-Z])\",\"_\",str(string)).lower()", "import re\n\n\ndef to_underscore(string):\n try:\n return '_'.join(x.lower() for x in re.findall('[A-Z][^A-Z]*', string))\n except:\n return str(string)", "def to_underscore(string):\n string = str(string)\n new = []\n for s in string:\n if not new:\n new.append(s)\n else:\n if s.isupper():\n new.append(\"_\")\n new.append(s)\n return \"\".join(new).lower()\n", "def to_underscore(s):\n if isinstance(s, (int, float)):\n return str(s)\n \n return ''.join([c if c == c.lower() else \"_\"+c.lower() for c in s ]).strip(\"_\")", "def to_underscore(s): \n return \"\".join([\"_\" + c.lower() if c.isupper() else c for c in str(s)]).strip(\"_\")", "def to_underscore(xs):\n return ''.join(('_' if i and x.isupper() else '') + x.lower() for i, x in enumerate(str(xs)))"]
{"fn_name": "to_underscore", "inputs": [["TestController"], ["ThisIsBeautifulDay"], ["Am7Days"], ["My3CodeIs4TimesBetter"], [5]], "outputs": [["test_controller"], ["this_is_beautiful_day"], ["am7_days"], ["my3_code_is4_times_better"], ["5"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,439
def to_underscore(string):
eed742fda4d1b5e989af5b2a0b96aac6
UNKNOWN
Write a function that will check whether the permutation of an input string is a palindrome. Bonus points for a solution that is efficient and/or that uses _only_ built-in language functions. Deem yourself **brilliant** if you can come up with a version that does not use _any_ function whatsoever. # Example `madam` -> True `adamm` -> True `junk` -> False ## Hint The brute force approach would be to generate _all_ the permutations of the string and check each one of them whether it is a palindrome. However, an optimized approach will not require this at all.
["def permute_a_palindrome (input): \n return sum( input.count(c)%2 for c in set(input) ) < 2\n", "def permute_a_palindrome (txt): \n return len([txt.count(c) for c in txt if txt.count(c) % 2]) < 2\n", "def permute_a_palindrome(stg): \n return sum(stg.count(c) % 2 for c in set(stg)) == len(stg) % 2\n", "def permute_a_palindrome (input): \n res = 0 \n for c in input.lower(): \n res = res ^ (1<< (ord(c)-71))\n \n return res == (res & -res)", "from functools import reduce\nfrom operator import xor\n\ndef permute_a_palindrome(input_): \n return len(reduce(xor, [set(c) for c in input_], set())) <= 1", "permute_a_palindrome=lambda s:sum(f%2for f in __import__('collections').Counter(s).values())<2", "from collections import Counter\n\ndef permute_a_palindrome(s): \n return sum(1 for c in Counter(s).values() if c % 2) < 2", "from collections import Counter\n\n\ndef permute_a_palindrome(s: str) -> bool:\n return len(s) % 2 == sum(i % 2 for i in list(Counter(s).values()))\n", "def permute_a_palindrome(string):\n even = 0\n odd = 0\n letters = list()\n for elem in string:\n if elem not in letters:\n letters.append(elem)\n if string.count(elem) % 2 == 0:\n even += 1\n else:\n odd += 1\n if (len(string) % 2 != 0 and odd == 1) or (len(string) % 2 == 0 and odd == 0):\n return True\n return False\n \n \n", "def permute_a_palindrome (input):\n a='abcdefghijklmnopqrstuvwxyz'\n times=[0] * len(a)\n if input==\"\":\n return True\n if len(input)%2==0:\n for x in range(0,len(a)):\n times[x]=input.count(a[x])\n print(times)\n for y in times:\n if not y%2==0:\n return False\n else:\n return True\n else:\n count=0\n for x in range(0,len(a)):\n times[x]=input.count(a[x])\n for y in times:\n if not y%2==0 and count>0:\n return False\n if not y%2==0 :\n count+=1\n else:\n return True\n"]
{"fn_name": "permute_a_palindrome", "inputs": [["a"], ["aa"], ["baa"], ["aab"], ["baabcd"], ["racecars"], ["abcdefghba"], [""]], "outputs": [[true], [true], [true], [true], [false], [false], [false], [true]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,130
def permute_a_palindrome(stg):
ae19d63f4c48693d8d50cf0dcdcc85ab
UNKNOWN
Consider the following series: `0,1,2,3,4,5,6,7,8,9,10,22,11,20,13,24...`There is nothing special between numbers `0` and `10`. Let's start with the number `10` and derive the sequence. `10` has digits `1` and `0`. The next possible number that does not have a `1` or a `0` is `22`. All other numbers between `10` and `22` have a `1` or a `0`. From `22`, the next number that does not have a `2` is `11`. Note that `30` is also a possibility because it is the next *higher* number that does not have a `2`, but we must select the *lowest* number that fits and **is not already in the sequence**. From `11`, the next lowest number that does not have a `1` is `20`. From `20`, the next lowest number that does not have a `2` or a `0` is `13`, then `24` , then `15` and so on. Once a number appers in the series, it cannot appear again. You will be given an index number and your task will be return the element at that position. See test cases for more examples. Note that the test range is `n <= 500`. Good luck! If you like this Kata, please try: [Sequence convergence](https://www.codewars.com/kata/59971e64bfccc70748000068) [https://www.codewars.com/kata/unique-digit-sequence-ii-optimization-problem](https://www.codewars.com/kata/unique-digit-sequence-ii-optimization-problem)
["masks = [0] * 10\nfor i in range(10 ** 4):\n for c in str(i):\n masks[int(c)] |= 1 << i\n\ndef find_num(n):\n seq, x = 1, 0\n for j in range(n):\n M = seq\n for m in masks:\n if x & m:\n M |= m\n x = ~M & (M+1)\n seq |= x\n return x.bit_length() - 1", "M = [0]\n\nwhile len(M) <= 500:\n k, s = 0, {c for c in str(M[-1])}\n while k in M or {c for c in str(k)} & s:\n k += 1\n M.append(k)\n\nfind_num = lambda n: M[n]", "\ndef find_num(n):\n c = 0\n k = -1\n mas = []\n while len(mas) <= n:\n k += 1\n if k > 10:\n c = set(str(mas[len(mas)-1]))\n if len(c) == len(set(str(mas[len(mas)-1]))-set(str(k))) and k not in mas:\n mas.append(k)\n k = 10 \n else:\n mas.append(k)\n return mas[len(mas)-1]\n \n \n \n \n \n \n", "def find_num(n):\n seq = [0]\n i = 0\n while i < n:\n a = seq[-1]\n b = next(x for x in list(range(n*3))\n if all(y not in str(x) for y in list(str(a)))\n and x not in seq)\n seq.append(b)\n i += 1\n return seq[-1]", "from itertools import count\n\ndef find_num(n):\n a = [0,1,2,3,4,5,6,7,8,9,10,22,11,20]\n while len(a) <= n:\n for i in count(11):\n if i in a: continue\n if not set(str(i)) & set(str(a[-1])):\n a.append(i)\n break\n return a[n]", "def find_num(n):\n found, lastComplete, lastFound = {0}, 0, 0\n while len(found) <= n:\n lastDigits = set(str(lastFound))\n curr = lastComplete+1\n while curr in found or set(str(curr)) & lastDigits:\n curr += 1\n lastFound = curr\n found.add(lastFound)\n lastComplete += lastFound == lastComplete+1\n return lastFound", "def find_num(n):\n l = [0]\n while len(l) <= n:\n m = 1\n while m in l or any([x in str(l[-1]) for x in str(m)]):\n m += 1\n \n l.append(m)\n\n return l[n]", "numbers=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 22, 11, 20, 13, 24, 15, 23, 14, 25, 16, 27, 18, 26, 17, 28, 19, 30, 12, 33, \n 21, 34, 29, 31, 40, 32, 41, 35, 42, 36, 44, 37, 45, 38, 46, 39, 47, 50, 43, 51, 48, 52, 49, 53, 60, 54, 61, 55,\n 62, 57, 63, 58, 64, 59, 66, 70, 56, 71, 65, 72, 68, 73, 69, 74, 80, 67, 81, 75, 82, 76, 83, 77, 84, 79, 85, 90,\n 78, 91, 86, 92, 87, 93, 88, 94, 100, 89, 101, 95, 102, 96, 103, 97, 104, 98, 105, 99, 106, 222, 107, 223, 108, \n 224, 109, 225, 110, 226, 111, 200, 113, 202, 114, 203, 115, 204, 116, 205, 117, 206, 118, 207, 119, 208, 131,\n 209, 133, 220, 134, 227, 130, 228, 135, 229, 136, 240, 137, 242, 138, 244, 139, 245, 160, 232, 140, 233, 141, \n 230, 144, 235, 146, 237, 145, 236, 147, 238, 149, 250, 143, 252, 148, 239, 150, 234, 151, 243, 155, 246, 153, \n 247, 156, 248, 157, 249, 158, 260, 154, 262, 159, 263, 170, 253, 161, 254, 163, 255, 164, 257, 166, 258, 167, \n 259, 168, 270, 165, 272, 169, 273, 180, 256, 171, 264, 173, 265, 174, 266, 175, 268, 177, 269, 178, 290, 176, \n 280, 179, 282, 190, 267, 181, 274, 183, 275, 184, 276, 185, 277, 186, 279, 188, 292, 187, 293, 400, 112, 300, \n 121, 303, 122, 304, 125, 306, 124, 305, 126, 307, 128, 309, 127, 308, 129, 330, 142, 333, 120, 334, 152, 336,\n 172, 335, 162, 337, 182, 339, 201, 338, 191, 278, 193, 284, 195, 283, 194, 285, 196, 287, 199, 286, 197, 288, \n 301, 289, 310, 294, 311, 295, 313, 296, 314, 297, 315, 298, 316, 299, 317, 402, 189, 302, 198, 320, 411, 322, \n 401, 323, 404, 123, 405, 132, 406, 192, 340, 211, 343, 210, 344, 212, 345, 216, 347, 215, 346, 217, 348, 219,\n 350, 214, 353, 218, 349, 221, 354, 261, 355, 241, 356, 271, 358, 291, 357, 281, 359, 407, 213, 408, 231, 409, \n 251, 360, 412, 363, 410, 325, 414, 326, 415, 327, 416, 328, 417, 329, 418, 332, 419, 352, 440, 312, 444, 318, \n 420, 319, 422, 331, 424, 351, 426, 370, 421, 365, 427, 361, 425, 366, 428, 367, 429, 368, 441, 362, 445, 321, \n 446, 371, 442, 369, 447, 380, 449, 372, 448, 373, 450, 376, 451, 377, 452, 378, 454, 379, 455, 381, 456, 382, \n 457, 383, 459, 386, 470, 385, 460, 375, 461, 387, 462, 388, 464, 389, 465, 390, 458, 391, 466, 392, 467, 393, \n 468, 395, 471, 396, 472, 398, 474, 399, 475, 600, 324, 500, 341, 502, 364, 501, 342, 505, 374, 506, 384, 507, \n 394, 508, 397, 480, 511, 403, 512, 430, 515, 423, 509, 413, 520, 431, 522, 433, 510, 432, 516, 434, 517, 436, \n 518, 437, 519, 438, 521, 439, 525, 443, 526, 473, 528, 463, 527, 469, 503, 476]\ndef find_num(n):\n return numbers[n]", "A,S,Z=list(range(1000)),set(),[]\nwhile len(Z)<501:\n for i in A:\n T=set(str(i))\n if not T&S:\n Z+=[i]\n S=T\n break\n A.remove(Z[-1])\nfind_num=lambda n:Z[n]", "from itertools import count\nfrom functools import lru_cache\n\nL = list(range(11))\nS = set(L)\n\n@lru_cache(maxsize=None)\ndef to_set(x): return set(str(x))\n\ndef find_num(n):\n while n >= len(L):\n x = next(filter(lambda i: not (i in S or to_set(L[-1]) & to_set(i)), count()))\n L.append(x)\n S.add(x)\n return L[n]"]
{"fn_name": "find_num", "inputs": [[1], [5], [11], [100], [500]], "outputs": [[1], [5], [22], [103], [476]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,438
def find_num(n):
1752251612f4cb87ea24a47f030fb960
UNKNOWN
You will be given an array of numbers. For each number in the array you will need to create an object. The object key will be the number, as a string. The value will be the corresponding character code, as a string. Return an array of the resulting objects. All inputs will be arrays of numbers. All character codes are valid lower case letters. The input array will not be empty.
["def num_obj(s):\n return [{str(i) : chr(i)} for i in s]", "def num_obj(s):\n return [{str(n) : chr(n)} for n in s]", "def num_obj(s):\n return [{str(nb) : chr(nb)} for nb in s]", "def num_obj(s):\n return [{str(a): chr(a)} for a in s]", "def num_obj(s):\n return [{str(c): chr(c)} for c in s]", "def num_obj(s):\n return [{str(x):chr(x)} for x in s]", "def num_obj(s):\n return [{str(d):chr(d)} for d in s]", "def num_obj(s):\n objects = []\n for i in s:\n objects.append( {str(i):chr(i)} )\n return objects", "num_obj = lambda a: [{str(n): chr(n)} for n in a]", "def num_obj(lst):\n return [{str(n): chr(n)} for n in lst]"]
{"fn_name": "num_obj", "inputs": [[[118, 117, 120]], [[101, 121, 110, 113, 113, 103]], [[118, 103, 110, 109, 104, 106]], [[107, 99, 110, 107, 118, 106, 112, 102]], [[100, 100, 116, 105, 117, 121]]], "outputs": [[[{"118": "v"}, {"117": "u"}, {"120": "x"}]], [[{"101": "e"}, {"121": "y"}, {"110": "n"}, {"113": "q"}, {"113": "q"}, {"103": "g"}]], [[{"118": "v"}, {"103": "g"}, {"110": "n"}, {"109": "m"}, {"104": "h"}, {"106": "j"}]], [[{"107": "k"}, {"99": "c"}, {"110": "n"}, {"107": "k"}, {"118": "v"}, {"106": "j"}, {"112": "p"}, {"102": "f"}]], [[{"100": "d"}, {"100": "d"}, {"116": "t"}, {"105": "i"}, {"117": "u"}, {"121": "y"}]]]}
INTRODUCTORY
PYTHON3
CODEWARS
666
def num_obj(s):
4bba1b6ead1caaaed9f83f165ba1cc2c
UNKNOWN
In this Kata you must convert integers numbers from and to a negative-base binary system. Negative-base systems can accommodate all the same numbers as standard place-value systems, but both positive and negative numbers are represented without the use of a minus sign (or, in computer representation, a sign bit); this advantage is countered by an increased complexity of arithmetic operations. To help understand, the first eight digits (in decimal) of the Base(-2) system is: `[1, -2, 4, -8, 16, -32, 64, -128]` Example conversions: `Decimal, negabinary` ``` 6, '11010' -6, '1110' 4, '100' 18, '10110' -11, '110101' ```
["def int_to_negabinary(i):\n ds = []\n while i != 0:\n ds.append(i & 1)\n i = -(i >> 1)\n return ''.join(str(d) for d in reversed(ds)) if ds else '0'\n \ndef negabinary_to_int(s):\n i = 0\n for c in s:\n i = -(i << 1) + int(c)\n return i", "def int_to_negabinary(i):\n i, s = -i, ''\n while i:\n i, r = divmod(i, -2)\n s += str(-r)\n return s[::-1] or '0'\n \ndef negabinary_to_int(s):\n i, b = 0, 1\n for c in s[::-1]:\n i += int(c) * b\n b *= -2\n return i", "def int_to_negabinary(i):\n return '{:b}'.format((0xAAAAAAAA + i) ^ 0xAAAAAAAA)\n\ndef negabinary_to_int(n):\n return (int(n, 2) ^ 0xAAAAAAAA) - 0xAAAAAAAA", "def int_to_negabinary(n):\n return int_to_negabinary(n//-2+n%2).lstrip('0') + str(n%2) if n else '0'\n\ndef negabinary_to_int(s):\n return negabinary_to_int(s[:-1])*-2 + int(s)%2 if s else 0", "def int_to_negabinary(i):\n digits = []\n if not i:\n digits = ['0']\n else:\n while i != 0:\n i, remainder = divmod(i, -2)\n if remainder < 0:\n i, remainder = i + 1, remainder + 2\n digits.append(str(remainder))\n return ''.join(digits[::-1])\n \ndef negabinary_to_int(s):\n num = 0\n for c in s:\n num *= -2\n num += ('01').find(c)\n return num\n", "def int_to_negabinary(i):\n if not i: return '0'\n\n digits = []\n while i != 0:\n i, r = divmod(i, -2)\n i, r = (i + 1, r + 2) if r < 0 else (i, r)\n digits.append(str(r))\n return ''.join(digits[::-1])\n \ndef negabinary_to_int(s):\n return sum([int(c)*(-2)**i for i, c in enumerate(s[::-1])])", "def int_to_negabinary(i):\n mask = 0xAAAAAAAAAAAA\n return bin((i + mask) ^ mask)[2:]\n \ndef negabinary_to_int(s):\n mask = 0xAAAAAAAAAAAA\n return (int(s,2) ^ mask) - mask", "def int_to_negabinary(n):\n def do(n1):\n li = []\n while n1 != 0:\n li.append(str(abs(n1 % (-2)))) ; n1 //= -2\n return li[::-1]\n return \"\".join([do(abs(n)),do(-n)][n>0]) or '0'\n \nnegabinary_to_int=lambda n:sum([int(j)*((-2)**i)for i,j in enumerate(n[::-1])])", "def int_to_negabinary(i):\n return bin((i + 0xAAAAAAAA) ^ 0xAAAAAAAA)[2:]\n \n \ndef negabinary_to_int(s):\n return sum(int(d) * (-2)**i for i,d in enumerate(s[::-1]))", "mask = 0xAAAAAAAA;\n\ndef int_to_negabinary(i):\n return '{0:b}'.format((mask + i) ^ mask)\n \ndef negabinary_to_int(s):\n return (int(s, 2) ^ mask) - mask\n"]
{"fn_name": "int_to_negabinary", "inputs": [[0], [6], [-6], [45], [-45], [4587], [-4587], [65535], [65536], [-65536], [2147483648], [-2147483648]], "outputs": [["0"], ["11010"], ["1110"], ["1111101"], ["11010111"], ["1011000111111"], ["11001000010101"], ["10000000000000011"], ["10000000000000000"], ["110000000000000000"], ["110000000000000000000000000000000"], ["10000000000000000000000000000000"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,567
def int_to_negabinary(i):
2156b0fca2d3005b8cc51f29eb84e89e
UNKNOWN
Your task is to find the number couple with the greatest difference from a given array of number-couples. All number couples will be given as strings and all numbers in them will be positive integers. For instance: ['56-23','1-100']; in this case, you should identify '1-100' as the number couple with the greatest difference and return it. In case there are more than one option, for instance ['1-3','5-7','2-3'], you should identify whichever is first, so in this case '1-3'. If there is no difference, like so ['11-11', '344-344'], return false.
["def diff(arr):\n r = arr and max(arr, key = lambda x : abs(eval(x)))\n return bool(arr and eval(r)) and r", "def diff(arr):\n r = [abs(eval(s)) for s in arr]\n return arr[r.index(max(r))] if r and max(r) else False\n", "def diff(arr):\n r = [abs(int(w.split('-')[0])-int(w.split('-')[1])) for w in arr]\n return arr[r.index(max(r))] if sum(r) else False", "def diff(arr):\n if not arr: return 0\n m = max(arr, key=lambda x: abs(eval(x)))\n return eval(m) and m", "def difference(x):\n a, b = map(int, x.split('-'))\n return abs(a-b)\n\n\ndef diff(arr):\n if not arr:\n return False\n x = max(arr, key=difference)\n if difference(x) == 0:\n return False\n return x", "def diff(pairs):\n max_diff = max_pair = 0\n for pair in pairs:\n a, b = pair.split('-')\n current = abs(int(a) - int(b))\n if current > max_diff:\n max_diff = current\n max_pair = pair\n return max_pair", "def diff(arr):\n #your code here\n vals = [abs(eval(pair)) for pair in arr]\n return False if all(val == 0 for val in vals) else arr[vals.index(max(vals))]\n return val", "def diff(arr):\n \n z = {}\n \n for i in range(0,len(arr)):\n \n s = arr[i].split('-')\n \n d = abs(int(s[0])-int(s[1]))\n \n z.update({arr[i]:d})\n \n w = {k:v for k,v in sorted(list(z.items()),reverse=True,key=lambda x:x[1])}\n\n if w=={} or max(w.values()) == 0:\n \n return False\n \n else:\n \n return max(w,key=w.get)\n", "def diff(arr):\n diff = []\n if arr == []:\n return False\n for i in range(len(arr)):\n str = arr[i].split('-')\n diff.append(abs(int(str[1])-int(str[0])))\n if max(diff) == 0:\n return False\n for j in range(len(arr)):\n if diff[j] == max(diff):\n return arr[j]", "def diff(arr):\n if not arr: return False\n def cust_key(s):\n a,b=map(int,s.split(\"-\"))\n return abs(a-b)\n m=max(arr,key=cust_key)\n return m if len(set(m.split(\"-\")))==2 else False"]
{"fn_name": "diff", "inputs": [[["43-45", "1021-55", "000-18888", "92-34", "76-32", "99-1", "1020-54"]], [["1-2", "2-4", "5-7", "8-9", "44-45"]], [["1-1000", "2-1000", "100-67", "98-45", "8-9"]], [["33-33", "77-77"]], [["23-67", "67-23", "88-88", "45-46"]], [["45896-2354", "4654-556767", "2455-423522", "3455-355", "34-34", "2524522-0"]], [["1-1", "2-2", "1-0", "77-77"]], [["0-0"]], [[]]], "outputs": [["000-18888"], ["2-4"], ["1-1000"], [false], ["23-67"], ["2524522-0"], ["1-0"], [false], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,139
def diff(arr):
493d404dd3a950e1fae8b580d02a2c37
UNKNOWN
Make a program that takes a value (x) and returns "Bang" if the number is divisible by 3, "Boom" if it is divisible by 5, "BangBoom" if it divisible by 3 and 5, and "Miss" if it isn't divisible by any of them. Note: Your program should only return one value Ex: Input: 105 --> Output: "BangBoom" Ex: Input: 9 --> Output: "Bang" Ex:Input: 25 --> Output: "Boom"
["def multiple(x):\n return 'Bang' * (x % 3 == 0) + 'Boom' * (x % 5 == 0) or 'Miss'", "def multiple(x):\n if x % 15 == 0: return \"BangBoom\"\n if x % 5 == 0: return \"Boom\"\n if x % 3 == 0: return \"Bang\"\n return \"Miss\"", "def multiple(x):\n val = ''\n if x % 3 == 0:\n val += 'Bang'\n if x % 5 == 0:\n val += 'Boom'\n if val == '':\n val = 'Miss'\n return val", "def multiple(x):\n return\"BangBoom\" if not x % 15 else (\"Boom\" if not x % 5 else (\"Bang\" if not x % 3 else \"Miss\"))\n", "def multiple(x):\n #Good Luck\n return ['Miss', 'Bang', 'Boom', 'BangBoom'][(x%3 == 0) + (x%5 == 0)*2]", "def multiple(x):\n return (\"Miss\",\"Bang\",\"Boom\",\"BangBoom\")[(x%3==0) + 2*(x%5==0)]", "def multiple(x):\n return \"{}{}\".format(\"\" if x % 3 else \"Bang\", \"\" if x % 5 else \"Boom\") or \"Miss\"", "def multiple(x):\n resu=[]\n if x%3==0 and x%5==0:\n return 'BangBoom'\n elif x%5==0:\n return \"Boom\"\n elif x%3==0:\n return 'Bang'\n else:\n return \"Miss\"", "def multiple(x):\n if x%15==0 : return \"BangBoom\"\n if x%3==0 : return \"Bang\"\n if x%5==0 : return \"Boom\"\n return \"Miss\"", "def multiple(x):\n return [['Miss', 'Boom'], ['Bang', 'BangBoom']][x % 3 == 0][x % 5 == 0]"]
{"fn_name": "multiple", "inputs": [[30], [3], [98], [65], [23], [15], [4], [2], [45], [90], [21], [7], [6], [10003823], [41535], [712], [985], [164523]], "outputs": [["BangBoom"], ["Bang"], ["Miss"], ["Boom"], ["Miss"], ["BangBoom"], ["Miss"], ["Miss"], ["BangBoom"], ["BangBoom"], ["Bang"], ["Miss"], ["Bang"], ["Miss"], ["BangBoom"], ["Miss"], ["Boom"], ["Bang"]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,327
def multiple(x):
e27dde411f659c1fae2db98f90455458
UNKNOWN
Complete the function that takes a string as an input, and return a list of all the unpaired characters (i.e. they show up an odd number of times in the string), in the order they were encountered as an array. In case of multiple appearances to choose from, take the last occurence of the unpaired character. **Notes:** * A wide range of characters is used, and some of them may not render properly in your browser. * Your solution should be linear in terms of string length to pass the last test. ## Examples ``` "Hello World" --> ["H", "e", " ", "W", "r", "l", "d"] "Codewars" --> ["C", "o", "d", "e", "w", "a", "r", "s"] "woowee" --> [] "wwoooowweeee" --> [] "racecar" --> ["e"] "Mamma" --> ["M"] "Mama" --> ["M", "m"] ```
["from collections import Counter\n\ndef odd_one_out(s):\n d = Counter(reversed(s))\n return [x for x in d if d[x] % 2][::-1]", "def odd_one_out(s):\n d = {}\n for i in s:\n if i in d:\n del d[i]\n else:\n d[i] = None\n return list(d.keys())", "from collections import Counter\n\ndef odd_one_out(s):\n return [k for k, v in Counter(s[::-1]).items() if v % 2][::-1]", "from collections import Counter\n\ndef odd_one_out(stg):\n return [c for c, n in list(Counter(stg[::-1]).items()) if n % 2][::-1]\n", "def odd_one_out(s):\n memo = {}\n for c in s:\n if c in memo:\n del memo[c]\n else:\n memo[c] = None\n return list(memo.keys())", "from collections import Counter\ndef odd_one_out(s):\n return sorted((x for x, i in list(Counter(s).items())if i%2), key=s.rfind)\n", "def odd_one_out(s):\n k = {}\n out = []\n \n for x in s:\n k[x] = k.get(x, 0) + 1\n \n odd_list = [x for x in s if k[x]%2==1]\n\n for x in odd_list:\n if k[x] == 1:\n out.append(x)\n else:\n k[x] = k.get(x)-1\n \n return out", "odd_one_out=lambda s:[c for c,n in __import__('collections').Counter(s[::-1]).items()if n&1][::-1]", "from collections import Counter, OrderedDict\ndef odd_one_out(s):\n return list(reversed([item[0] for item in OrderedDict(Counter(s[::-1])).items() if int(item[1])%2==1]))", "def odd_one_out(s):\n from collections import Counter\n c = Counter(s)\n ans = []\n for i in s[::-1]:\n try:\n if c[i] % 2 == 1:\n ans.append(i)\n del c[i]\n except:\n pass\n \n return ans[::-1]"]
{"fn_name": "odd_one_out", "inputs": [["Hello World"], ["Codewars"], ["woowee"], ["wwoooowweeee"], ["racecar"], ["Mamma"], ["Mama"], ["\u00bc x 4 = 1"], ["\u00bc x 4 = 1 and \u00bd x 4 = 2"]], "outputs": [[["H", "e", " ", "W", "r", "l", "d"]], [["C", "o", "d", "e", "w", "a", "r", "s"]], [[]], [[]], [["e"]], [["M"]], [["M", "m"]], [["\u00bc", "x", "4", "=", "1"]], [["\u00bc", "1", "a", "n", "d", "\u00bd", "2"]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,744
def odd_one_out(s):
f53ae9147275de4ae12331111b4916f3
UNKNOWN
Write a function that returns the index of the first occurence of the word "Wally". "Wally" must not be part of another word, but it can be directly followed by a punctuation mark. If no such "Wally" exists, return -1. Examples: "Wally" => 0 "Where's Wally" => 8 "Where's Waldo" => -1 "DWally Wallyd .Wally" => -1 "Hi Wally." => 3 "It's Wally's." => 5 "Wally Wally" => 0 "'Wally Wally" => 7
["from re import compile\n\ndef wheres_wally(string):\n m = compile('(^|.*[\\s])(Wally)([\\.,\\s\\']|$)').match(string)\n return m.start(2) if m else -1", "import re\n\ndef wheres_wally(string):\n return next((m.start() for m in re.finditer(r'((?<= )W|^W)ally\\b', string)), -1)", "from re import search\ndef wheres_wally(s):\n match = search(r'(?:^|\\s)Wally(?:\\W|$)', s)\n return -1 if match == None else match.start(0) + 1 if match.group(0)[0].isspace() else match.start(0)\n", "def wheres_wally(stg):\n i = stg.find(\"Wally\")\n while i > -1 and (i and stg[i-1] != \" \" or stg[i+5:i+6].isalnum()):\n i = stg.find(\"Wally\", i+1)\n return i", "import re\ndef wheres_wally(string):\n match = re.compile(r'(^|.*[\\s])(Wally)([\\.,\\s\\']|$)').match(string)\n return match.start(2) if match else -1\n", "import re\n\ndef wheres_wally(string):\n match = re.search(r\"(?:^|\\s)(Wally)\\b\", string)\n return match.start(1) if match else -1", "import re\n\ndef wheres_wally(string): \n match = re.search(r\"(?<!\\S)\\bWally\\b\", string) \n return match.start() if match else -1\n", "from re import search\nwheres_wally=lambda s: (lambda r: -1 if r==None else r.start(0))(search(\"(^|(?<= ))Wally(\\W|$)\",s))", "import re\ndef wheres_wally(string):\n match=re.search(r' Wally\\b',\" \"+string)\n if match is None:\n return -1\n else:\n return match.start()", "import re\ndef wheres_wally(s):\n try:\n return [m.start() for m in\n re.finditer(\"(?<=\\s)Wally(\\s|[.,\\';+-]|\\Z)|(?<=^)Wally(\\s|[.,\\';+-]|\\Z)\",\n s)][0]\n except:\n return -1\n"]
{"fn_name": "wheres_wally", "inputs": [[""], ["WAlly"], ["wAlly"], ["DWally"], [".Wally"], ["Wallyd"], ["wally mollyWally Wallybrolly 'Wally"], ["Walley ,Wally -Wally ;Wally +Wally :Wally"], ["Walley Wally, Wally- Wally: Wally+ Wally:"], ["12Wally Wally01 W.ally"], ["Where's Waldo"], ["Wally"], ["Wally Wally"], ["W ally Wally"], ["Where's Wally"], ["Hi Wally."], ["It's Wally's."], ["'Wally Wally"], ["Hello Wally my name is Dolly"]], "outputs": [[-1], [-1], [-1], [-1], [-1], [-1], [-1], [-1], [7], [-1], [-1], [0], [0], [7], [8], [3], [5], [7], [6]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,683
def wheres_wally(string):
231ce720426055daac53ded7049eee95
UNKNOWN
Rick wants a faster way to get the product of the largest pair in an array. Your task is to create a performant solution to find the product of the largest two integers in a unique array of positive numbers. All inputs will be valid. Passing [2, 6, 3] should return 18, the product of [6, 3]. ```Disclaimer: Mr. Roll will only accept solutions that are faster than his, which has a running time O(nlogn).``` ```python max_product([2, 1, 5, 0, 4, 3]) # => 20 max_product([7, 8, 9]) # => 72 max_product([33, 231, 454, 11, 9, 99, 57]) # => 104874 ```
["import heapq\ndef max_product(a):\n x = heapq.nlargest(2,a)\n return x[0]*x[1]", "def max_product(a): \n first_max = 0\n second_max = 0\n for x in a:\n if x > first_max:\n second_max = first_max\n first_max = x\n elif x > second_max:\n second_max = x\n return first_max*second_max", "from heapq import nlargest\ndef max_product(a):\n x,y=nlargest(2,a)\n return x*y", "def max_product(a):\n m1 = max(a)\n a.remove(m1)\n m2 = max(a)\n return m1 * m2", "def max_product(a):\n m = a.pop(a.index(max(a)))\n return max(a)*m", "import heapq\nfrom functools import reduce\nfrom operator import mul\n\ndef max_product(a):\n return reduce(mul, heapq.nlargest(2,a))", "def max_product(a):\n return a.pop(a.index(max(a))) * max(a)", "def max_product(a):\n b=list(a)\n max_number=max(b)\n b.remove(max_number)\n second_number=max(b)\n return max_number * second_number", "from heapq import nlargest\nfrom operator import mul\n\ndef max_product(a):\n return mul(*nlargest(2,a))", "import heapq\n\ndef max_product(a):\n first, second = heapq.nlargest(2, a)\n return first * second"]
{"fn_name": "max_product", "inputs": [[[56, 335, 195, 443, 6, 494, 252]], [[154, 428, 455, 346]], [[39, 135, 47, 275, 37, 108, 265, 457, 2, 133, 316, 330, 153, 253, 321, 411]], [[136, 376, 10, 146, 105, 63, 234]], [[354, 463, 165, 62, 472, 53, 347, 293, 252, 378, 420, 398, 255, 89]], [[346, 446, 26, 425, 432, 349, 123, 269, 285, 93, 75, 14]], [[134, 320, 266, 299]], [[114, 424, 53, 272, 128, 215, 25, 329, 272, 313, 100, 24, 252]], [[375, 56, 337, 466, 203]]], "outputs": [[218842], [194740], [187827], [87984], [218536], [192672], [95680], [139496], [174750]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,189
def max_product(a):
ec0a745d75630b47c5c7c2ea70ac0f6c
UNKNOWN
Vasya wants to climb up a stair of certain amount of steps (Input parameter 1). There are 2 simple rules that he has to stick to. 1. Vasya can climb 1 or 2 steps at each move. 2. Vasya wants the number of moves to be a multiple of a certain integer. (Input parameter 2). ### Task: What is the `MINIMAL` number of moves making him climb to the top of the stairs that satisfies his conditions? ### Input 1. Number of stairs: `0 < N ≤ 10000` ; 2. Integer to be multiplied : `1 < M ≤ 10 `; ### Output 1. Return a single integer - the minimal number of moves being a multiple of M; 2. If there is no way he can climb satisfying condition return - 1 instead. (`Nothing` in Haskell) ### Examples ```python numberOfSteps(10, 2) => 6 # Sequence of steps : {2, 2, 2, 2, 1, 1} numberOfSteps(3, 5) => -1 # !Possible sequences of steps : {2, 1}, {1, 2}, {1, 1, 1} ``` ``` haskell numberOfSteps 10 2 == Just 6 -- Sequence of steps : {2, 2, 2, 2, 1, 1} numberOfSteps 3 5 == Nothing -- Not possible, since the sequences of steps would be {2, 1}, {1, 2} or {1, 1, 1} ```
["def numberOfSteps(steps, m):\n if (steps < m):\n return -1\n \n \n if (steps % 2 == 0 and (steps / 2) % m == 0):\n return (steps / 2)\n \n \n return (steps / 2) + m - ((steps / 2) % m)\n", "def numberOfSteps(steps, m):\n return next((n for n in range((steps+1)//2, steps+1) if n % m == 0), -1)", "def numberOfSteps(steps, m):\n if m > steps:\n return -1\n c = 1\n while steps > 2*m*c:\n c += 1\n return m*c", "def numberOfSteps(steps, m):\n if steps < m:\n return -1\n q, r = divmod(steps, 2)\n q, r = divmod(q + r, m)\n return (q + (r > 0)) * m", "def numberOfSteps(steps, m):\n if m > steps:\n return -1\n abs_min_steps = int(steps / 2) + steps % 2\n steps_dif = abs_min_steps % m\n if (steps_dif):\n return (m - steps_dif) + abs_min_steps\n else:\n return abs_min_steps", "from math import ceil;numberOfSteps=lambda s,m:next((i for i in range(ceil(s/2),s+1)if not i%m),-1)"]
{"fn_name": "numberOfSteps", "inputs": [[10, 2], [3, 5], [29, 7], [2, 2], [1, 2], [10000, 2], [10000, 3], [10000, 10], [9999, 3], [9999, 2], [9999, 10], [9999, 9], [18, 10], [19, 10], [20, 10], [7688, 5], [4608, 5], [3979, 2], [5, 2]], "outputs": [[6], [-1], [21], [2], [-1], [5000], [5001], [5000], [5001], [5000], [5000], [5004], [10], [10], [10], [3845], [2305], [1990], [4]]}
INTRODUCTORY
PYTHON3
CODEWARS
972
def numberOfSteps(steps, m):
7d252fc161256c1e8c0c7f478f3f0786
UNKNOWN
**DESCRIPTION:** Your strict math teacher is teaching you about right triangles, and the Pythagorean Theorem --> a^2 + b^2 = c^2 whereas a and b are the legs of the right triangle and c is the hypotenuse of the right triangle. On the test however, the question asks: What are the possible integer lengths for the other side of the triangle, but since you never learned anything about that in class, you realize she meant What are the possible integer lengths for the other side of the right triangle. Because you want to address the fact that she asked the wrong question and the fact that you're smart at math, you've decided to answer all the possible values for the third side EXCLUDING the possibilities for a right triangle in increasing order. **EXAMPLES:** ``` side_len(1, 1) --> [1] side_len(3, 4) --> [2, 3, 4, 6] side_len(4, 6) --> [3, 4, 5, 6, 7, 8, 9] ``` **RETURN:** Return your answer as a list of all the possible third side lengths of the triangle without the right triangles in increasing order. By the way, after finishing this kata, please try some of my other katas: [Here](https://www.codewars.com/collections/tonylicodings-authored-katas) NOTE: When given side_len(x, y), y will always be greater than or equal to x. Also, if a right triangle's legs are passed in, exclude the hypotenuse. If a right triangle's leg and hypotenuse are passed in, exclude the other leg.
["def side_len(x, y):\n return [z for z in range(abs(x-y)+1,x+y) if z*z not in (abs(x*x-y*y), x*x+y*y)]", "def side_len(x, y):\n return [i for i in range(abs(x-y)+1, abs(x+y)) if i != (x*x+y*y)**0.5 and i != abs(y*y-x*x)**0.5]", "def side_len(x, y):\n return [i for i in range(y-x+1,x+y) if abs(i**2-y**2) != x**2]", "from math import sqrt\n\ndef side_len(x, y):\n if y < x: return \"for fuck's sake\"\n mini = y - x + 1\n maxi = x + y - 1\n result = list(range(mini, maxi + 1))\n hyp = sqrt(x**2 + y**2)\n leg = sqrt(y**2 - x**2)\n if hyp.is_integer() and mini <= hyp <= maxi: result.remove(int(hyp))\n if leg.is_integer() and mini <= leg <= maxi: result.remove(int(leg))\n return result", "def side_len(x, y):\n return [a for a in range(y - x + 1, x + y) if a * a + x * x != y * y and x * x + y * y != a * a]", "def side_len(a, b):\n r = ((a*a + b*b)**0.5, (b*b - a*a)**0.5)\n return [c for c in range(b-a+1, a+b) if c not in r]", "def right(x, y, z):\n x, y, z = sorted([x,y,z])\n return x ** 2 + y ** 2 == z ** 2\n\ndef side_len(x, y):\n return [z for z in range(y - x + 1, x + y) if not right(x, y, z)]", "def side_len(x, y):\n a = ((x**2 + y**2)**0.5, (y**2 - x**2)**0.5)\n return [i for i in range(y - x + 1, y + x) if i not in a]", "_trips = lambda x, y: [(x**2 + y**2)**0.5, (y**2-x**2)**0.5]\n\ndef side_len(x, y):\n return [i for i in range(y-x+1, x+y) if i not in _trips(x, y)]", "def _trips(x, y):\n return [(x**2 + y**2)**0.5, (y**2-x**2)**0.5]\n\ndef side_len(x, y):\n return [i for i in range(y-x+1, x+y) if i not in _trips(x, y)]"]
{"fn_name": "side_len", "inputs": [[1, 1], [3, 4], [4, 6], [5, 12], [8, 10]], "outputs": [[[1]], [[2, 3, 4, 6]], [[3, 4, 5, 6, 7, 8, 9]], [[8, 9, 10, 11, 12, 14, 15, 16]], [[3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,617
def side_len(x, y):
a418fa1decaad2980324f3cb8080087a
UNKNOWN
In this Kata, you will be given an integer `n` and your task will be to return `the largest integer that is <= n and has the highest digit sum`. For example: ``` solve(100) = 99. Digit Sum for 99 = 9 + 9 = 18. No other number <= 100 has a higher digit sum. solve(10) = 9 solve(48) = 48. Note that 39 is also an option, but 48 is larger. ``` Input range is `0 < n < 1e11` More examples in the test cases. Good luck!
["def solve(n):\n x = str(n)\n res = [x] + [str(int(x[:i]) - 1) + '9' * (len(x) - i) for i in range(1, len(x))]\n return int(max(res, key=lambda x: (sum(map(int, x)), int(x))))", "def dig_sum(n):\n return sum(map(int, str(n)))\n\ndef solve(n):\n candidates = [n] + [ n // 10**i * 10**i - 1 for i in range(1, len(str(n))) ]\n return max(candidates, key=dig_sum)", "from typing import List, Union\ndef digit_sum(n: Union[List[int], int]) -> int:\n \"\"\"\n Finds the digit sum of the digits in an integer or list of positional integers\n \"\"\"\n if isinstance(n, list):\n return sum(n) \n return sum(int(ch) for ch in str(n))\n\ndef to_int(arr: List[int]) -> int:\n \"\"\"\n Converts an array of positional integers into a single integer\n \"\"\"\n return int(''.join(str(n) for n in arr))\n\ndef bump(arr, i):\n \"\"\"\n Takes the digits of an array and increments the digit at index i and decrements the digit at \n index i + 1.\n E.g. bump([1, 2, 8, 4], 1) -> [1, 2+1, 8-1, 4] -> [1, 3, 7, 4]\n \"\"\"\n return arr[:i] + [arr[i] + 1] + [arr[i + 1] - 1] + arr[i+2:]\n\ndef solve(n: int) -> int:\n \"\"\"\n Find the largest number <= n with the maximum digit sum\n \"\"\"\n s = str(n)\n # Decrement the first digit and convert all others to 9 as a baseline\n option = [int(s[0]) - 1] + [9] * (len(s) - 1)\n if digit_sum(option) > digit_sum(n):\n for i in range(len(option) - 1):\n # Keep bumping digit i in option while still a single digit and the int value <= n\n while True:\n if option[i] == 9:\n break\n b = bump(option, i)\n if to_int(b) > n:\n break\n option = b\n return to_int(option)\n return n", "def solve(n):\n s = str(n)\n l = len(s)\n if l == 1 or (l == 2 and s[1] in {\"8\", \"9\"}):\n return n\n for i in range(l-1):\n if s[i+1] != \"9\":\n return int(f\"{s[:i]}{int(s[i]) - 1}{'9' * (l - i - 1)}\")\n", "def solve(n): return max([n]+[n-n%10**i-1 for i in range(len(str(n)))],key=lambda n:(sum(map(int,str(n))),n))", "from math import log10, ceil\n\ndef solve(n):\n return max([n] + [n-n%10**x-1 for x in range(ceil(log10(n)))], key=lambda n: sum(map(int, str(n))))", "solve=lambda n:(lambda s:int(max((str(int(s[:i])-(i<len(s)))+'9'*(len(s)-i)for i, d in enumerate(s,1)),key=lambda s:(sum(map(int,s)),s))))(str(n))", "\ndef solve(n):\n total = sum_digit(n)\n largest = n\n i = 1\n while n > 0:\n n = n - (n % (10)**i) -1\n print(n)\n new_total = sum_digit(n)\n i += 1\n if new_total > total:\n total = new_total\n largest = n\n return largest\n\ndef sum_digit(num):\n tot = 0\n while num > 0:\n tot += (num % 10)\n num = int(num /10)\n return tot \n \n \n", "def digit_sum(num):\n tot = 0\n while num > 0:\n tot += (num % 10)\n num = int(num /10)\n return tot \n\ndef solve(n):\n total = digit_sum(n)\n largest = n\n print(n)\n i = 1\n while n > 0:\n n = n - (n % (10)**i) -1\n new_total = digit_sum(n)\n i += 1\n if new_total > total:\n total = new_total\n largest = n\n return largest", "def solve(n):\n b = [int(str(n)[0]) - 1] + [9 for x in str(n)[1:]]\n digsum = sum(b)\n if digsum <= sum([int(x) for x in str(n)]):\n return n\n for i in range(len(str(n))-1, -1, -1):\n a = [int(x) for x in str(n)[:i]] + [int(str(n)[i]) - 1] + [9 for x in str(n)[i+1:]]\n print((i,a))\n if sum(a) == digsum:\n break\n return int(\"\".join([str(x) for x in a]))\n"]
{"fn_name": "solve", "inputs": [[79320], [99004], [99088], [99737], [29652], [100], [48], [521], [1], [2], [3], [39188], [5], [10], [1000], [10000], [999999999992], [59195], [19930], [110], [1199], [120], [18], [2090], [72694]], "outputs": [[78999], [98999], [98999], [98999], [28999], [99], [48], [499], [1], [2], [3], [38999], [5], [9], [999], [9999], [999999999989], [58999], [19899], [99], [999], [99], [18], [1999], [69999]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,799
def solve(n):
100fe5b7805448b5c58b46f852b2bfd6
UNKNOWN
A number is simply made up of digits. The number 1256 is made up of the digits 1, 2, 5, and 6. For 1256 there are 24 distinct permutations of the digits: 1256, 1265, 1625, 1652, 1562, 1526, 2156, 2165, 2615, 2651, 2561, 2516, 5126, 5162, 5216, 5261, 5621, 5612, 6125, 6152, 6251, 6215, 6521, 6512. Your goal is to write a program that takes a number, n, and returns the average value of all distinct permutations of the digits in n. Your answer should be rounded to the nearest integer. For the example above the return value would be 3889. * n will never be negative A few examples: ```python permutation_average(2) return 2 permutation_average(25) >>> 25 + 52 = 77 >>> 77 / 2 = 38.5 return 39 * permutation_average(20) >>> 20 + 02 = 22 >>> 22 / 2 = 11 return 11 permutation_average(737) >>> 737 + 377 + 773 = 1887 >>> 1887 / 3 = 629 return 629 ``` Note: Your program should be able to handle numbers up to 6 digits long ~~~if:python \* Python version 3 and above uses Banker Rounding so the expected values for those tests would be 3888 and 38 respectively ~~~ ~~~if-not:python \* ignore these marks, they're for Python only ~~~
["from itertools import permutations\n\ndef permutation_average(n):\n perms = [float(''.join(e)) for e in permutations(str(n))]\n return int(round(sum(perms) / len(perms)))\n", "def permutation_average(n):\n n = str(n)\n n, l = sum(map(int, n)) / float(len(n)), len(n)\n \n n = n * ((10 ** l - 1) / 9)\n \n return round(n)\n", "def permutation_average(n):\n n = str(n)\n avg = sum(map(int, n)) / len(n)\n return round(avg * int(\"1\" * len(n)))", "from itertools import permutations\n\ndef permutation_average(n):\n a = [int(\"\".join(x)) for x in set(permutations(str(n)))]\n return round(float(sum(a)) / len(a))", "from itertools import permutations\n\ndef permutation_average(n):\n perms = [float(''.join(x)) for x in permutations(str(n))]\n return round(sum(perms) / len(perms))", "from itertools import permutations\nfrom math import factorial\n\ndef permutation_average(n):\n return round(sum(int(''.join(x)) for x in permutations(str(n))) / float(factorial(len(str(n)))))", "from math import factorial\n\n\ndef permutation_average(n):\n m = len(str(n))\n s = sum(map(int, str(n)))\n return round(sum(s * 10 ** i for i in range(m)) / float(m))", "def permutation_average(n):\n digits = [int(i) for i in str(n)]\n length = len(str(n))\n \n def factorial(n): \n if n is 1 or n is 0:\n return 1\n else:\n return n * factorial(n-1)\n\n averager = factorial(length) #denominator of the average\n\n def get_coefficient(width): #after adding up all the digits, a pattern is seen dependent on\n coefficient = 0 #the number of digits there are. This exploits that\n if width <= 1:\n coefficient = 1\n else:\n for x in range(width):\n coefficient += factorial(width-1)*(10**x)\n\n return coefficient\n\n total = 0\n for index in digits: #just multiplying the same coefficient (ironically enough) with every digit\n multiplier = get_coefficient(length)\n total += multiplier * index\n\n average = total/float(averager)\n avg = int(round(average, 0))\n return avg"]
{"fn_name": "permutation_average", "inputs": [[2], [25], [737]], "outputs": [[2], [38], [629]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,162
def permutation_average(n):
fb839e937eab342ba0055d3f19045dac
UNKNOWN
Given the number pledged for a year, current value and name of the month, return string that gives information about the challenge status: - ahead of schedule - behind schedule - on track - challenge is completed Examples: `(12, 1, "February")` - should return `"You are on track."` `(12, 1, "March")` - should return `"You are 1 behind schedule."` `(12, 5, "March")` - should return `"You are 3 ahead of schedule."` `(12, 12, "September")` - should return `"Challenge is completed."` Details: - you do not need to do any prechecks (input will always be a natural number and correct name of the month) - months should be as even as possible (i.e. for 100 items: January, February, March and April - 9, other months 8) - count only the item for completed months (i.e. for March check the values from January and February) and it means that for January you should always return `"You are on track."`.
["import calendar\n\nM = {calendar.month_name[i]: i - 1 for i in range(1, 13)}\n\n\ndef check_challenge(pledged, current, month):\n if pledged == current:\n return \"Challenge is completed.\"\n m = M[month]\n per_month, rest = divmod(pledged, 12)\n todo = per_month * m + (min(rest, m))\n delta = current - todo\n if delta == 0 or m == 0:\n return \"You are on track.\"\n elif delta > 0:\n return f\"You are {delta} ahead of schedule!\"\n else:\n return f\"You are {-delta} behind schedule.\"", "MONTHS = [\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\", \"August\", \"September\", \"October\", \"November\", \"December\"]\nMONTHS_DCT = {m:i for i,m in enumerate(MONTHS)}\n\n\ndef check_challenge(pledged, current, month):\n \n if month == MONTHS[0]: return \"You are on track.\"\n if current == pledged: return \"Challenge is completed.\"\n \n n, r = divmod(pledged,12)\n accum = sum( n + (i<r) for i in range(MONTHS_DCT[month]) )\n delta = accum - current\n \n return ( \"You are on track.\" if delta == 0 else\n \"You are {} behind schedule.\".format(delta) if delta > 0 else\n \"You are {} ahead of schedule!\".format(abs(delta)) )", "from calendar import month_name\nmonths = {m:i for i,m in enumerate(month_name)}\n\ndef check_challenge(pledged, current, month):\n if pledged == current: return \"Challenge is completed.\"\n q, r = divmod(pledged, 12)\n m = months[month] - 1\n val = current - m*q - min(m, r)\n if m and val:\n return f\"You are {-val} behind schedule.\" if val < 0 else f\"You are {val} ahead of schedule!\"\n return \"You are on track.\"", "def spread(n):\n i,r = 0,[0 for _ in range(12)]\n while sum(r) != n:\n r[i] += 1\n i = (i+1)%12\n return r\n\ndef check_challenge(n,c,m):\n d = dict(zip('January February March April May June July August September October November December'.split(),range(13)))\n arr = spread(n)\n if m == 'January': return 'You are on track.'\n if n == c: return 'Challenge is completed.'\n x = sum(arr[:d.get(m)])\n if x > c: return f'You are {x-c} behind schedule.'\n return f'You are {c-x} ahead of schedule!' if c-x!=0 else 'You are on track.'", "import calendar\n\nM = {calendar.month_name[i]: i - 1 for i in range(1, 13)}\n\n\ndef check_challenge(pledged, current, month):\n if pledged == current:\n return \"Challenge is completed.\"\n m = M[month]\n per_month = pledged // 12\n rest = pledged % 12\n todo = per_month * m + (min(rest, m))\n delta = current - todo\n if delta == 0 or m == 0:\n return \"You are on track.\"\n elif delta > 0:\n return f\"You are {delta} ahead of schedule!\"\n else:\n return f\"You are {-delta} behind schedule.\"", "m={'January':1,'February':2,'March':3,'April':4,'May':5,'June':6,\n 'July':7,'August':8,'September':9,'October':10,\n 'November':11,'December':12}\ndef check_challenge(pledged, current, month):\n t=[pledged//12]*12\n for i in range(pledged%12):\n t[i]+=1\n x=sum(t[:m[month]-1])\n if month=='January' or current==x:\n return 'You are on track.'\n elif pledged<=current:\n return 'Challenge is completed.'\n elif current<x:\n return 'You are {} behind schedule.'.format(x-current)\n else:\n return 'You are {} ahead of schedule!'.format(current-x)", "from itertools import accumulate\n\ndef check_challenge(pledged, current, month):\n if month == 'January':\n return 'You are on track.'\n if pledged == current:\n return 'Challenge is completed.'\n months = ('January', 'February', 'March', 'April', 'May', 'June',\n 'July', 'August', 'September', 'October', 'November', 'December')\n q, r = divmod(pledged, 12)\n progresses = list(accumulate([q + (m < r) for m in range(12)]))\n p = progresses[months.index(month)-1]\n if p == current:\n return 'You are on track.'\n return f'You are {p - current} behind schedule.' if p > current else f'You are {current - p} ahead of schedule!'", "def check_challenge(p,c,m): \n if p==c:return'Challenge is completed.'\n n='an eb ar pr ay un ul ug ep ct ov ec'.split().index(m[1:3])\n s=p//12*n+min(p%12,n)-c\n return\"You are \"+(\"%s schedule\"%('%d ahead of'%(-s),'%d behind'%s)[0<s]+'.!'[s<0],\"on track.\")[n==0 or s==0]", "def check_challenge(p,c,m): \n if p==c:return'Challenge is completed.'\n n='Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split().index(m[:3])\n s=p//12*n+min(p%12,n)-c\n return\"You are \"+(\"%s schedule\"%('%d ahead of'%(-s),'%d behind'%s)[0<s]+'.!'[s<0],\"on track.\")[n==0 or s==0]", "def check_challenge(p,c,m,M='Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split()): \n if p==c:return'Challenge is completed.'\n D=[0]*12\n while p:\n for i,x in enumerate(D):\n if p==0:break\n D[i]+=1\n p-=1\n m=M.index(m[:3])\n s=sum(D[:m])-c\n if m==0 or s==0:return \"You are on track.\"\n return \"You are %s schedule\"%('%d behind'%s if 0<s else '%d ahead of'%(-s))+'.!'[s<0]\n"]
{"fn_name": "check_challenge", "inputs": [[12, 5, "January"], [12, 1, "February"], [12, 1, "March"], [12, 12, "September"], [12, 5, "March"], [100, 5, "March"], [100, 52, "July"], [100, 51, "July"], [100, 53, "July"]], "outputs": [["You are on track."], ["You are on track."], ["You are 1 behind schedule."], ["Challenge is completed."], ["You are 3 ahead of schedule!"], ["You are 13 behind schedule."], ["You are on track."], ["You are 1 behind schedule."], ["You are 1 ahead of schedule!"]]}
INTRODUCTORY
PYTHON3
CODEWARS
5,244
def check_challenge(pledged, current, month):
c409b8ff46d3185a5f03ab8cd7a2c1eb
UNKNOWN
*SCHEDULE YOUR DA(RRA)Y* The best way to have a productive day is to plan out your work schedule. Given the following three inputs, please create an an array of time alloted to work, broken up with time alloted with breaks: Input 1: Hours - Number of hours available to you to get your work done! Input 2: Tasks - How many tasks you have to do througout the day Input 3: Duration (minutes)- How long each of your tasks will take to complete Criteria to bear in mind: - Your schedule should start with work and end with work. - It should also be in minutes, rounded to the nearest whole minute. - If your work is going to take more time than you have, return "You're not sleeping tonight!" Example: ```python day_plan(8, 5, 30) == [ 30, 82, 30, 82, 30, 82, 30, 82, 30 ] day_plan(3, 5, 60) == "You're not sleeping tonight!" ```
["def day_plan(hours, tasks, duration):\n td, hm, tmo = tasks * duration, hours * 60, tasks - 1\n if td > hm: return \"You're not sleeping tonight!\"\n arr = [0] * (tasks + tmo)\n arr[::2], arr[1::2] = [duration] * tasks, [round((hm - td) / (tmo or 1))] * tmo\n return arr\n", "def day_plan(hours, tasks, duration):\n breaks = (hours * 60 - tasks * duration) / (tasks - 1) if tasks > 1 else 0\n if breaks < 0:\n return \"You're not sleeping tonight!\"\n return ([duration, round(breaks)] * tasks)[:-1]", "def day_plan(hours, tasks, duration):\n mins = hours * 60\n task_mins = tasks * duration\n relaxation = (mins - task_mins) / max(1, (tasks - 1))\n if relaxation < 0:\n return \"You're not sleeping tonight!\"\n task_list = ([duration, round(relaxation, 0)] * tasks)[:-1]\n return task_list", "def day_plan(hours, tasks, duration):\n if tasks < 2:\n return [duration] * tasks\n elif (tasks * duration)/60 > hours:\n return \"You're not sleeping tonight!\"\n else:\n r = round((hours * 60 - tasks * duration) / (tasks - 1))\n return [duration, r] * (tasks-1) + [duration]\n", "def day_plan(hours, tasks, duration):\n break_time = hours * 60 - tasks * duration\n if break_time < 0:\n return \"You're not sleeping tonight!\"\n else:\n schedule = [0] * (2 * tasks - 1)\n schedule[::2] = [duration] * tasks\n schedule[1::2] = [round(break_time / (tasks - 1 + 1e-9))] * (tasks - 1)\n return schedule", "day_plan=lambda h,t,d:t*d>h*60and\"You're not sleeping tonight!\"or([(h*60-t*d)//(t-1+1e-9),d]*t)[1:]", "def day_plan(hours, tasks, duration):\n if tasks == 0: return []\n if tasks == 1: return [duration]\n stop = round((hours*60 - duration*tasks) / (tasks - 1))\n if stop < 0: return \"You're not sleeping tonight!\"\n res = [None]*(2*tasks-1)\n res[::2] = [duration]*tasks\n res[1::2] = [stop]*(tasks-1)\n return res", "def day_plan(hours, tasks, duration):\n #your code here\n at = tasks * duration\n tb = (hours*60) - at\n plan = []\n if tb < 0:\n return \"You're not sleeping tonight!\"\n elif tasks == 0:\n return plan\n elif tasks == 1:\n plan = [duration]\n else:\n plan = [duration]\n bt = round(tb/(tasks-1))\n for i in range(tasks-1):\n plan.append(bt)\n plan.append(duration)\n return plan\n", "def day_plan(hours, tasks, duration):\n total_minutes = hours * 60\n tasks_minutes = tasks * duration\n \n if tasks_minutes > total_minutes:\n return 'You\\'re not sleeping tonight!'\n \n brk = round((total_minutes - tasks_minutes) / (tasks - 1)) if tasks > 1 else 0\n return [brk if i % 2 else duration for i in range(2 * tasks - 1)]", "def day_plan(hours, tasks, duration):\n minutes=hours*60\n if tasks*duration>minutes:return \"You're not sleeping tonight!\"\n elif tasks==1:return [duration]\n elif tasks==0:return []\n break_length = round((minutes-tasks*duration)/(tasks-1))\n return [duration,break_length]*(tasks-1)+[duration]"]
{"fn_name": "day_plan", "inputs": [[8, 5, 30], [3, 5, 60], [2, 2, 60], [2, 1, 60], [2, 0, 60]], "outputs": [[[30, 82, 30, 82, 30, 82, 30, 82, 30]], ["You're not sleeping tonight!"], [[60, 0, 60]], [[60]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
3,146
def day_plan(hours, tasks, duration):
3dcc2ef1a4f79b58335a0f9d24986908
UNKNOWN
Steve and Josh are bored and want to play something. They don't want to think too much, so they come up with a really simple game. Write a function called winner and figure out who is going to win. They are dealt the same number of cards. They both flip the card on the top of their deck. Whoever has a card with higher value wins the round and gets one point (if the cards are of the same value, neither of them gets a point). After this, the two cards are discarded and they flip another card from the top of their deck. They do this until they have no cards left. `deckSteve` and `deckJosh` are arrays representing their decks. They are filled with *cards*, represented by a single character. The card rank is as follows (from lowest to highest): ``` '2','3','4','5','6','7','8','9','T','J','Q','K','A' ``` Every card may appear in the deck more than once. Figure out who is going to win and return who wins and with what score: * `"Steve wins x to y"` if Steve wins; where `x` is Steve's score, `y` is Josh's score; * `"Josh wins x to y"` if Josh wins; where `x` is Josh's score, `y` is Steve's score; * `"Tie"` if the score is tied at the end of the game. ## Example * Steve is dealt: `['A','7','8']` * Josh is dealt: `['K','5','9']` 1. In the first round, ace beats king and Steve gets one point. 2. In the second round, 7 beats 5 and Steve gets his second point. 3. In the third round, 9 beats 8 and Josh gets one point. So you should return: `"Steve wins 2 to 1"`
["def winner(deck_Steve, deck_Josh):\n deck = ['2','3','4','5','6','7','8','9','T','J','Q','K','A']\n Steve = 0\n Josh = 0\n for i in range(len(deck_Steve)):\n if deck.index(deck_Steve[i]) > deck.index(deck_Josh[i]):\n Steve += 1\n elif deck.index(deck_Steve[i]) < deck.index(deck_Josh[i]):\n Josh += 1\n else:\n continue\n if Steve > Josh:\n return \"Steve wins \" + str(Steve) + \" to \" + str(Josh)\n elif Josh > Steve:\n return \"Josh wins \" + str(Josh) + \" to \" + str(Steve)\n else:\n return \"Tie\"\n", "ranks = \"23456789TJQKA\"\ndef winner(deck_steve, deck_josh):\n steve_points = sum([1 for i in range(len(deck_steve)) if ranks.index(deck_steve[i]) > ranks.index(deck_josh[i])])\n josh_points = sum([1 for i in range(len(deck_josh)) if ranks.index(deck_steve[i]) < ranks.index(deck_josh[i])])\n if steve_points > josh_points: return \"Steve wins %d to %d\" %(steve_points, josh_points)\n elif josh_points > steve_points: return \"Josh wins %d to %d\" %(josh_points, steve_points)\n else: return \"Tie\"", "CARDS = ['2','3','4','5','6','7','8','9','T','J','Q','K','A']\nCARDS_VAL = { elt: i for i,elt in enumerate(CARDS) }\n\ndef winner(deck_steve, deck_josh):\n resultLst = [ CARDS_VAL[c1] > CARDS_VAL[c2] for c1,c2 in zip(deck_steve, deck_josh) if CARDS_VAL[c1] != CARDS_VAL[c2]]\n result, l = sum(resultLst), len(resultLst)\n return [\"Josh wins {} to {}\".format(l-result, result),\n \"Steve wins {} to {}\".format(result, l-result),\n \"Tie\"][ (result >= l/2.0) + (result == l/2.0) ]", "def winner(deck_s, deck_j):\n points = { True:['Steve',0], False:['Josh',0] }\n chek_dek = ['2','3','4','5','6','7','8','9','T','J','Q','K','A']\n for s,j in zip(deck_s, deck_j):\n point = chek_dek.index(s) - chek_dek.index(j)\n if not point: continue\n points[point>0][-1] += 1\n \n winer = points[points[1][-1]>points[0][-1]][0]\n if points[1][-1] == points[0][-1]:\n return 'Tie'\n return f'{winer} wins {points[winer == points[1][0]][-1]} to {points[winer == points[0][0]][-1]}'", "b = '23456789TJQKA'\n\ndef winner(S, J):\n w1 = sum(b.index(s)>b.index(j) for s, j in zip(S, J))\n w2 = sum(b.index(s)<b.index(j) for s, j in zip(S, J))\n if w1==w2: return \"Tie\"\n if w1>w2 : return f\"Steve wins {w1} to {w2}\"\n return f\"Josh wins {w2} to {w1}\"", "def winner(deck_steve, deck_josh):\n bigOrSmall = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']\n m = \"{} wins {} to {}\"\n winSteve = 0\n winJosh = 0\n for i in range(len(deck_steve)):\n if bigOrSmall.index(deck_steve[i]) < bigOrSmall.index(deck_josh[i]):\n winJosh += 1\n elif bigOrSmall.index(deck_steve[i]) > bigOrSmall.index(deck_josh[i]):\n winSteve += 1\n if winSteve > winJosh:\n return m.format(\"Steve\", winSteve, winJosh)\n elif winSteve < winJosh:\n return m.format(\"Josh\", winJosh, winSteve)\n else:\n return \"Tie\"", "ranks = \"2\", \"3\", \"4\", \"5\", \"6\", \"7\", \"8\", \"9\", \"T\", \"J\", \"Q\", \"K\", \"A\"\n\n\ndef cmp(a, b):\n return (a > b) - (b > a)\n\n\ndef winner(deck_steve, deck_josh):\n points = [0, 0, 0]\n for xs in zip(deck_steve, deck_josh):\n s, j = map(ranks.index, xs)\n points[0 if s > j else 1 if s < j else 2] += 1\n if points[0] > points[1]:\n return f\"Steve wins {points[0]} to {points[1]}\"\n elif points[1] > points[0]:\n return f\"Josh wins {points[1]} to {points[0]}\"\n else:\n return \"Tie\"", "def winner(deck_steve, deck_josh):\n deck = [deck_steve, deck_josh]\n score = [e[1]>e[0] for e in zip( *[map('23456789TJQKA'.index, x) \n for x in deck ]) if e[1]!=e[0] ]\n l,s,f = len(score)/2, sum(score), score.count(False)\n winer = [('Steve',f,s),('Josh',s,f)][s>l]\n return 'Tie' if not score or s==l else '{} wins {} to {}'.format( *winer )", "def winner(deck_steve, deck_josh):\n ls = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']\n st = 0\n jo = 0\n for k, v in enumerate(deck_josh):\n if ls.index(v) > ls.index(deck_steve[k]):\n jo += 1\n elif ls.index(v) < ls.index(deck_steve[k]):\n st += 1\n return \"Tie\" if st == jo else \"{} wins {} to {}\".format('Steve' if st > jo else \"Josh\", max(st, jo), min(st, jo))\n", "from numpy import sign\nD = {x:i for i,x in enumerate('23456789TJQKA')}\n\ndef winner(deck_steve, deck_josh):\n res = [0, 0, 0] # 0(s==j): tie, 1(s>j): steve point, -1(s<j): josh point\n for s,j in zip(deck_steve, deck_josh):\n res[sign(D[s]-D[j])] += 1\n return f\"Steve wins {res[1]} to {res[2]}\" if res[1] > res[2] else f\"Josh wins {res[2]} to {res[1]}\" if res[1] < res[2] else \"Tie\""]
{"fn_name": "winner", "inputs": [[["A", "7", "8"], ["K", "5", "9"]], [["T"], ["T"]], [["T", "9"], ["T", "8"]], [[], []]], "outputs": [["Steve wins 2 to 1"], ["Tie"], ["Steve wins 1 to 0"], ["Tie"]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,922
def winner(deck_steve, deck_josh):
bf765bd40d465b482d44cf6832a0eb8e
UNKNOWN
## Your task You are given a dictionary/hash/object containing some languages and your test results in the given languages. Return the list of languages where your test score is at least `60`, in descending order of the results. Note: the scores will always be unique (so no duplicate values) ## Examples ```python {"Java": 10, "Ruby": 80, "Python": 65} --> ["Ruby", "Python"] {"Hindi": 60, "Dutch" : 93, "Greek": 71} --> ["Dutch", "Greek", "Hindi"] {"C++": 50, "ASM": 10, "Haskell": 20} --> [] ``` --- ## My other katas If you enjoyed this kata then please try [my other katas](https://www.codewars.com/collections/katas-created-by-anter69)! :-) ### _Translations are welcome!_
["def my_languages(results):\n return sorted((l for l,r in results.items() if r>=60), reverse=True, key=results.get)", "# def my_languages(dict):\n# store = []\n# for key, value in dict.items():\n# if value >= 60:\n# store.append((key, value))\n# store.sort(key=lambda x: x[-1])\n# return [x[0] for x in store]\ndef my_languages(dict):\n store = []\n for key, value in list(dict.items()):\n if value >= 60:\n store.append(key)\n return sorted(store, key=lambda x: dict[x], reverse= True)\n \n \n", "from operator import itemgetter\n\n\ndef my_languages(results):\n return [language for language, score in sorted(results.items(),key=itemgetter(1), reverse=True) if score >= 60]", "def my_languages(results):\n array_list = []\n sorted_results = (sorted(list(results.items()), key = lambda k: k[1], reverse = True))\n for i in sorted_results:\n if i[1]>=60:\n array_list.append(i[0])\n return array_list\n", "def my_languages(results):\n return sorted([ e for e in results.keys() if results[e]>=60], reverse=True, key=lambda x: results[x])", "\ndef my_languages(results):\n lista=[]\n for i in results:\n if results[i]>=60 and i not in lista:\n lista.append(results[i])\n \n \n lista.sort()\n lista2=[]\n for i in lista:\n for c in results:\n if i==results[c]:\n lista2.append(c)\n lista2=lista2[::-1]\n \n \n return lista2", "def my_languages(results):\n answer = []\n for k, v in results.items():\n if v >= 60:\n answer.append(k)\n return sorted(answer, key = lambda lang: results[lang], reverse = True)", "def my_languages(d):\n return [key for key,value in sorted(d.items(),key=lambda item:item[1],reverse=True) if value>=60]", "def my_languages(results):\n return sorted([lang for lang in results if results[lang] >= 60], key=lambda l: -results[l])", "def my_languages(A):\n L=[]\n for i in A:\n if A.get(i)>=60:\n L.append(A.get(i))\n L1=[]\n L.sort()\n L=L[::-1]\n for i in L:\n k=list(A.keys())\n v=list(A.values())\n b=k[v.index(i)]\n L1.append(b)\n return L1", "def my_languages(results):\n return sorted({k:v for k,v in list(results.items()) if v >= 60}, key = {k:v for k,v in list(results.items()) if v >= 60}.get, reverse = True) \n", "def my_languages(d):\n return sorted((x for x, y in d.items() if y >= 60), key=lambda x: -d[x])", "def my_languages(results):\n return sorted([k for k in results if results[k] >= 60], key = lambda x : results[x], reverse = True)", "my_languages = lambda r: sorted({x:r[x] for x in r if r[x]>=60}, key=r.get, reverse=True)", "def my_languages(results):\n s = [(k, results[k]) for k in sorted(results, key=results.get, reverse=True)]\n return [i[0] for i in s if i[1]>=60]", "import operator\n\ndef my_languages(results):\n aced = []\n results = dict(sorted(results.items(), key=operator.itemgetter(1), reverse=True))\n for language in results:\n if results[language] >= 60:\n aced.append(language)\n return aced", "def my_languages(results):\n return [_[0] for _ in sorted([_ for _ in list(results.items()) if _[1] >= 60], key=lambda _: _[1], reverse=True)]\n", "def my_languages(results):\n to_return = []\n for i in range(100, 59, -1):\n for key, value in results.items():\n if (value >= i) and not (key in to_return):\n to_return.append(key)\n return to_return", "def my_languages(results):\n \n return [k for k,v in sorted(results.items(), key = lambda item :item[1], reverse=True) if v >59.99]", "def my_languages(results):\n # your code here\n return [x for x,y in list(sorted(results.items(),key=lambda x:x[1],reverse=True)) if y >= 60]", "my_languages = lambda results: [key for (key,val) in sorted(results.items(), key=lambda t: t[1], reverse=True) if val >= 60]", "def my_languages(results):\n \n return [i[0] for i in sorted(results.items(), key=lambda x: x[1], reverse=True) if i[1] >= 60]", "def my_languages(results):\n # your code here\n \n dictCopy = results.copy()\n \n for k, v in dictCopy.items():\n if v < 60:\n del results[k]\n \n results = sorted(results.items(), key = lambda x: x[1], reverse= True)\n languages = []\n \n for i in range(len(results)):\n languages.append(results[i][0]) \n \n #print(languages)\n return languages", "def my_languages(results):\n results = sorted(results.items(), key=lambda d: d[1], reverse = True)\n res = []\n for item in results:\n if(item[1] >= 60):\n res.append(item[0])\n return res", "def my_languages(results):\n print(results)\n results = sorted(results.items(), key=lambda d: d[1], reverse = True)\n print(results)\n res = []\n for item in results:\n if(item[1] >= 60):\n res.append(item[0])\n return res", "my_languages=lambda r:sorted([i for i in r.keys() if r[i]>=60],key=lambda c:r[c],reverse=True)", "import operator\n\ndef my_languages(dico):\n dico = dict(sorted(dico.items(), key=operator.itemgetter(1),reverse=True))\n return (list(x for x in dico if dico[x] >= 60))", "import operator\n\ndef my_languages(dico):\n return (list(x for x in dict(sorted(list(dico.items()), key=operator.itemgetter(1),reverse=True)) if dict(sorted(list(dico.items()), key=operator.itemgetter(1),reverse=True))[x] >= 60))\n", "def my_languages(results):\n res_sorted = sorted(results.items(), key=lambda x: x[1], reverse=True)\n\n return [x[0] for x in res_sorted if x[1] >= 60]", "def my_languages(results):\n results = sorted(list(results.items()), key=lambda x: x[1], reverse=True)\n return [i[0] for i in results if i[1]>=60]\n", "def my_languages(results):\n results_lookup = {v: k for k, v in results.items()}\n board = [score for score in results.values() if score >= 60] \n board.sort(reverse=True) \n return [results_lookup[k] for k in board]", "def my_languages(results):\n return sorted([x for x in results if results.get(x)>=60], key = results.get, reverse=True)", "def my_languages(results):\n results = [(x,y) for x,y in results.items() if y >= 60]\n return [i[0] for i in sorted(results, key=lambda x: x[1], reverse = True)]", "def my_languages(results):\n l = []\n for lang in sorted(results, key=results.get, reverse=True):\n if results.get(lang) >= 60:\n l.append(lang)\n return(l)", "def my_languages(results):\n filtered_dict = {i: results[i] for i in results if results.get(i) >= 60}\n return sorted(filtered_dict, key=results.get, reverse=True)", "def my_languages(results):\n results = sorted(results.items(), key=lambda x: x[1],\n reverse = True) \n result = []\n for i in results:\n if i[1] >= 60:\n result.append(i[0])\n return result", "def my_languages(results):\n results = {lang: results[lang] for lang in results if results[lang] >= 60}\n results = sorted(results, key=results.get)\n results.reverse()\n return results", "def my_languages(results):\n return [i[0] for i in sorted(results.items(), key=lambda i:i[1],reverse=True) if i[1]>=60]", "def my_languages(results):\n return [n for n in sorted(results, key=results.get, reverse=True) if results.get(n) >= 60]", "from collections import OrderedDict\n\ndef my_languages(results):\n return [d for d in OrderedDict(sorted(results.items(), key=lambda x: x[1], reverse=True)).keys() if results[d] >= 60]", "def my_languages(results):\n list_values = list(results.values())\n list_values.sort()\n list_values.reverse()\n\n final_list = []\n\n for i in list_values:\n for key, val in tuple(results.items()):\n if val == i and i >= 60:\n final_list.append(key)\n\n return final_list", "def my_languages(results):\n return sorted(filter(lambda x: results[x] >= 60, results), key = lambda x: results[x], reverse = True)", "def my_languages(results):\n def myFunc(e):\n return e[1]\n \n languages = []\n result = []\n for language, score in results.items():\n if score >= 60:\n languages.append([language, score])\n languages.sort(key=myFunc, reverse=True)\n for item in languages:\n result.append(item[0])\n return result", "def my_languages(results):\n ordered = sorted([(score, lang) for lang, score in list(results.items())\n if score >= 60], reverse=True)\n return [lang for score, lang in ordered]\n", "def my_languages(results):\n temp= [k for k,v in sorted(list(results.items()), key=lambda x:x[1], reverse=True) if results[k]>=60]\n return temp\n", "def my_languages(r):\n return [k for k,v in sorted(r.items(), key=lambda i: i[1]) if v>=60][::-1]", "def my_languages(results):\n return sorted((j for j,k in results.items() if k>=60),reverse=True, key=results.get)", "# def my_languages(results):\n# ans = []\n# for i in results:\n# a = results.values()\n# # if a > 60:\n# # ans.append(a)\n# print(a)\n \ndef my_languages(results):\n dgu = sorted(list(results.items()), key=lambda x: x[1], reverse=True)\n a = []\n for i in dgu:\n li = list(i)\n if li[1] >= 60:\n for u in li:\n if isinstance(u, str):\n a.append(u)\n return a\n \n \n \n# print(i)\n", "def my_languages(results):\n return sorted([result for result in results if results[result] >= 60],key=lambda x:results[x],reverse=True)", "def my_languages(results):\n languages = []\n for language in sorted(results, key=results.get, reverse=True):\n if results[language] > 59:\n languages.append(language)\n return languages", "def my_languages(results):\n results = {k: v for k, v in sorted(list(results.items()), key=lambda item: item[1],reverse = True)}\n return [i for i in list(results.keys()) if results[i]>=60 ]\n", "def my_languages(results):\n valid = [k for k in results if results[k] >= 60]\n return sorted(valid, key=lambda x: results[x], reverse=True)", "def my_languages(results):\n return list(map(lambda x :x[0], sorted([(x, results[x]) for x in results if results[x]>=60], key = lambda x:x[1], reverse=True)))", "def my_languages(results):\n return sorted([r for r in results if results[r] >= 60], key=results.get, reverse=True)", "def indexmax(lst): #returns the index of a max element\n maxval = 0\n maxindex = 0\n for i in range(len(lst)):\n if lst[i] > maxval:\n maxval = lst[i]\n maxindex = i\n return maxindex\n\ndef my_languages(results):\n keys = []\n values = []\n result_ans = []\n \n for result in results:\n keys.append(result)\n values.append(results[result])\n \n for i in range(len(keys)):\n index = indexmax(values)\n if values[index] >= 60:\n result_ans.append(keys[index])\n del keys[index]\n del values[index]\n \n return result_ans\n", "def my_languages(results):\n return sorted([k for k,v in results.items() if v>=60], key=lambda x: 0-results[x])", "\ndef indexmax(lst): #returns the index of the maximum element\n maxval = 0\n maxindex = 0\n for i in range(len(lst)):\n if lst[i]>maxval:\n maxval = lst[i]\n maxindex = i\n return maxindex\n\n\ndef my_languages(results):\n keys = []\n values = []\n resultans = []\n for result in results:\n keys.append(result)\n values.append(results[result])\n for i in range(len(keys)):\n index = indexmax(values)\n if values[index]>=60:\n resultans.append(keys[index])\n del keys[index]\n del values[index]\n return resultans", "def maxindex(lst):\n maxnum = 0\n maxindex = 0\n for i in range(len(lst)):\n if lst[i] > maxnum:\n maxnum = lst[i]\n maxindex = i\n return maxindex\n\ndef my_languages(results):\n values = []\n keys = []\n ans = []\n for item in results:\n keys.append(item)\n values.append(results[item])\n for i in range(len(values)):\n index = maxindex(values)\n if values[index] >= 60:\n ans.append(keys[index])\n del values[index]\n del keys[index]\n return ans\n\n", "from operator import itemgetter\n\ndef my_languages(results):\n return [lang for lang, score in sorted(results.items(), key=itemgetter(1), reverse=True) if score >= 60]", "def my_languages(results):\n resultsSorted = {key: value for key, value in sorted(list(results.items()), key=lambda item: item[1],reverse =True)}\n return [i for i in resultsSorted if resultsSorted[i]>=60]\n", "def my_languages(results):\n \n sor = dict(sorted(results.items(), key=lambda x: x[1], reverse=True))\n \n a = []\n \n for i in sor:\n if sor[i] >= 60:\n a.append(i)\n return a", "def my_languages(results):\n resultList = []\n sortedDict = {}\n \n sortList = sorted(list(results.items()), key=lambda x: x[1], reverse=True)\n \n for i in sortList:\n print((i[0], i[1]))\n sortedDict.update({i[0] : i[1]})\n \n print(sortedDict)\n \n for i in sortedDict:\n if results[i] >= 60:\n resultList.append(i)\n else:\n pass\n return resultList\n\n#for i in sort_orders:\n# print(i[0], i[1])\n", "def my_languages(results):\n return sorted({key: value for key, value in results.items() if value >= 60}, key=results.get, reverse=True)", "def my_languages(results):\n lst = [x for x in results if results.get(x) >= 60]\n return sorted(lst, key=lambda x: results.get(x), reverse=True)", "my_languages = lambda results: [l for l in sorted(results, reverse=True, key=lambda a: results[a]) if results[l] >= 60]", "def my_languages(results):\n x = [k for k, v in results.items() if v >= 60]\n return sorted(x, key = lambda y: results[y], reverse = True)", "def my_languages(results):\n \n old=results.copy()\n for k,v in results.items():\n if v<60:\n old.pop(k) \n new=sorted(old, key=old.get, reverse=True)\n return [i for i in new]", "def my_languages(results):\n return list(\n map(lambda item: item[0],\n sorted(\n filter(lambda item: item[1] >= 60, results.items()),\n key=lambda item: item[1], \n reverse=True)\n )\n )", "def my_languages(results):\n arr = sorted([x for x in results.values() if x >= 60 ])\n rev_res = {}\n for key in results:\n rev_res[results[key]] = key\n return [rev_res[x] for x in arr[::-1]]", "def my_languages(results):\n return [el[0] for el in sorted(results.items(), key=lambda x: x[1], reverse=True) if results[el[0]] >= 60]", "def my_languages(results):\n items = []\n list_result = list(results.items())\n list_result.sort(key=lambda i :i[1], reverse=True)\n return [i[0] for i in list_result if i[1] >= 60]", "def my_languages(R):\n return [k[0] for k in sorted(R.items(), key=lambda e: e[1], reverse = True ) if k[1]>=60]", "def my_languages(results):\n d = sorted([(v,k) for k,v in results.items()], reverse=True)\n return [i[1] for i in d if i[0] >= 60]", "def my_languages(results):\n return [k for k, v in sorted(list(results.items()), key=lambda kv: -kv[1]) if v >= 60]\n", "def my_languages(results):\n s2 = []\n s = sorted(list(results.items()), key=lambda x: x[1], reverse=True)\n for i in range(len(s)):\n if s[i][1] >= 60:\n s2.append(s[i][0])\n return s2\n", "def my_languages(res):\n sorted_res = {k: v for k, v in sorted(list(res.items()), key=lambda item: item[1], reverse=True)}\n return [language for language, score in list(sorted_res.items()) if score >= 60]\n \n \n \n", "def my_languages(results):\n lst = []\n d = {}\n for key, value in results.items():\n if value >= 60:\n d.update({f'{key}':f'{value}'}) \n sort_d = sorted(d.items(), key=lambda x: x[1],reverse=True)\n for i in sort_d:\n lst.append(i[0])\n return lst", "def my_languages(results):\n return [i for i in sorted(results,reverse =True,key = results.get ) if results[i]>=60] ", "def my_languages(results):\n results = (r for r in results.items() if r[1] >= 60)\n results = sorted(results, key=lambda r: r[1], reverse=True)\n return [r[0] for r in results]", "def my_languages(results):\n return [x for x,value in sorted(results.items(), key=lambda item: -item[1]) if value >= 60]", "def my_languages(results):\n result = []\n sort_orders = sorted(results.items(), key=lambda x: x[1], reverse=True)\n for key, value in sort_orders:\n if value >= 60:\n result.append(key)\n\n return result", "def my_languages(results):\n lang = []\n final = []\n for key in results:\n if results[key] > 59:\n if results[key] == 100:\n results[key] = 99\n lang.append(str(results[key]) + key)\n lang.sort(reverse=True)\n for word in lang:\n final.append(word[2:len(word)])\n return final", "def my_languages(results):\n list = []\n for x,v in dict(sorted(results.items(), key=lambda x: x[1],reverse=True)).items():\n if v>=60:\n list.append(x)\n return list", "def my_languages(results):\n lang=[]\n for key in list(results.keys()):\n if results[key] >= 60:\n lang.append({ \"Key\": key, \"Value\": results[key]})\n lang.sort(key=lambda x: x[\"Value\"], reverse=True)\n return [l[\"Key\"] for l in lang]\n \n \n", "def my_languages(results):\n for x, y in list(results.items()):\n if y < 60:\n del results[x]\n return sorted(results, key=results.get , reverse=True)\n", "def my_languages(results):\n for x, y in list(results.items()):\n if y < 60:\n del results[x]\n results= sorted(results, key=results.get , reverse=True)\n return results", "def my_languages(results):\n filtered = list([tup for tup in list(results.items()) if tup[1]>= 60])\n def mySort(i):\n return i[1]\n filtered.sort(reverse = True, key=mySort)\n return [i[0] for i in filtered]\n", "def my_languages(r):\n return [x for x in sorted(r,key=lambda x:r[x],reverse=True) if r[x]>=60]", "def my_languages(results):\n results_1 = [i for i in results.items()]\n results_1 = [[i[0],i[1]] for i in results_1 if i[1]>=60]\n results_swap = {i[1]:i[0] for i in results_1}\n results_ksort=sorted(results_swap,reverse=True)\n results_done=[results_swap.get(i) for i in results_ksort]\n return (results_done)", "def my_languages(results):\n return sorted(list(filter(lambda x: results[x] >= 60, results)), key = lambda x: results[x])[::-1]", "def my_languages(results):\n results = {k: v for k, v in sorted(results.items(), key=lambda item: item[1])}\n return [key for key, value in results.items() if value >= 60][::-1]", "def my_languages(results):\n l=sorted(list(results.items()),key=lambda x:x[1],reverse=True)\n ll=[]\n for i in l:\n if results.get(i[0])>=60:\n ll.append(i[0])\n return ll\n", "def my_languages(a):\n a = sorted(list([k, v] for k, v in a.items()), key=lambda x: x[1], reverse=True)\n a = list(x[0] for x in a if x[1] >= 60)\n return a", "def my_languages(results):\n ans = []\n sorted_results = (sorted(results.items(), key=lambda k: k[1], reverse=True))\n print(sorted_results)\n for i in sorted_results:\n if i[1] >= 60:\n ans.append(i[0])\n return ans", "def my_languages(results):\n # your code here\n y = []\n for key, value in sorted(results.items(), key=lambda x: x[1], reverse = True):\n if value >= 60:\n y.append(key)\n return y", "def my_languages(d):\n l = {}\n res = []\n s = d.items()\n for i in s:\n l[i[1]] = i[0]\n s = sorted(l, reverse=True)\n res = [l[i] for i in s if i >= 60]\n return res", "def my_languages(results):\n lp = []\n sortr = sorted(results.items(), key=lambda x: x[1], reverse=True)\n \n for a in sortr:\n if a[1]>=60:\n lp.append(a[0])\n #lp.sort(reverse = True)\n #sorted(lp, reverse=True)\n return lp", "def my_languages(results):\n d = dict(sorted(results.items(), key = lambda x: x[1], reverse = True))\n return [lang for lang,mark in d.items() if mark >= 60]", "def my_languages(results):\n g = results.items()\n g = list(g)\n f = []\n g.sort(key=lambda i: i[1])\n for i in g:\n if i[1] >= 60:\n i = f.append(i[0])\n h = f.reverse()\n return f"]
{"fn_name": "my_languages", "inputs": [[{"Java": 10, "Ruby": 80, "Python": 65}], [{"Hindi": 60, "Greek": 71, "Dutch": 93}], [{"C++": 50, "ASM": 10, "Haskell": 20}]], "outputs": [[["Ruby", "Python"]], [["Dutch", "Greek", "Hindi"]], [[]]]}
INTRODUCTORY
PYTHON3
CODEWARS
21,068
def my_languages(results):
d93ea0c8f1e1589f0fe1f3901776f273
UNKNOWN
Truncate the given string (first argument) if it is longer than the given maximum length (second argument). Return the truncated string with a `"..."` ending. Note that inserting the three dots to the end will add to the string length. However, if the given maximum string length num is less than or equal to 3, then the addition of the three dots does not add to the string length in determining the truncated string. ## Examples ``` ('codewars', 9) ==> 'codewars' ('codewars', 7) ==> 'code...' ('codewars', 2) ==> 'co...' ``` [Taken from FCC](https://www.freecodecamp.com/challenges/truncate-a-string)
["def truncate_string(s,n):\n return s if len(s)<=n else s[:n if n<=3 else n-3]+'...'", "def truncate_string(s, n):\n return s if n>=len(s) else s[:n]+'...' if n<=3 else s[:n-3]+'...'", "def truncate_string(str,n):\n if len(str) <= n:\n return str\n if n <= 3:\n return str[0:n] + \"...\"\n else:\n return str[:n-3] + \"...\"", "def truncate_string(str,n):\n if n>=len(str):\n return str\n return [str[:n]+'.'*3, str[:n-3]+'.'*3][n>3]", "def truncate_string(s, max_len):\n if len(s) <= max_len:\n return s\n return '{}...'.format(s[:max_len - (3 if max_len > 3 else 0)])", "truncate_string=lambda s,n:s[:n-3*(3<n<len(s))]+'...'*(n<len(s))", "def truncate_string(str,n):\n if len(str) <= n:\n return str\n if n <= 3:\n return str[:n] + '...'\n return str[:n-3] + '...'", "truncate_string=lambda str,n: str if n>=len(str) else str[:n-3 if n>3 else n]+'...'", "def truncate_string(s,n):\n if n>=len(s):return s\n elif n<=3:return s[:n]+\"...\"\n return s[:n-3]+\"...\"", "def truncate_string(s, n):\n p = s[:n - 3] if n > 3 else s[:n]\n return p + '...' if len(s) > n else s"]
{"fn_name": "truncate_string", "inputs": [["pippi", 3], ["Peter Piper picked a peck of pickled peppers", 14], ["A-tisket a-tasket A green and yellow basket", 43], ["A-tisket a-tasket A green and yellow basket", 45], ["A-", 1], ["Chingel loves his Angel so much!!!", 27], ["I like ice-cream.Do you?", 19], ["Seems like you have passed the final test. Congratulations", 53]], "outputs": [["pip..."], ["Peter Piper..."], ["A-tisket a-tasket A green and yellow basket"], ["A-tisket a-tasket A green and yellow basket"], ["A..."], ["Chingel loves his Angel ..."], ["I like ice-cream..."], ["Seems like you have passed the final test. Congrat..."]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,173
def truncate_string(str,n):
e73de9160f40ad54859da6dbd0d70ce3
UNKNOWN
Write a function `consonantCount`, `consonant_count` or `ConsonantCount` that takes a string of English-language text and returns the number of consonants in the string. Consonants are all letters used to write English excluding the vowels `a, e, i, o, u`.
["def consonant_count(str):\n return sum(1 for c in str if c.isalpha() and c.lower() not in \"aeiou\")\n", "import re\n\ndef consonant_count(s):\n return len(re.sub(r'[aeiou\\d\\s\\W\\_]', '', s))", "import re\n\ndef consonant_count(s):\n return len(re.sub(r'[^b-df-hj-np-tv-z]', '', s, flags=re.I))", "VOWELS = set('aeiouAEIOU')\n\n\ndef consonant_count(s):\n return sum(1 for a in s if a.isalpha() and a not in VOWELS)\n", "def consonant_count(s):\n return sum(1 for x in s if 'b' <= x.lower() <= 'z' and x not in 'eiou')", "def consonant_count(s):\n return sum(1 for x in s.lower() if x.isalpha() and x not in \"aeiou\")", "def consonant_count(s):\n return sum(c in \"bcdfghjklmnpqrstvwxyz\" for c in s.lower())", "def consonant_count(s):\n return sum([1 for c in s if c not in 'aeiou' and c.isalpha()])", "def consonant_count(s):\n return sum(x.lower() in 'bcdfghjklmnpqrstvwxyz' for x in s)", "from collections import Counter\n\ndef consonant_count(str):\n return sum(c for x, c in Counter(str.lower()).items() if x in 'bcdfghjklmnpqrstvwxyz')"]
{"fn_name": "consonant_count", "inputs": [[""], ["aaaaa"], ["helLo world"], ["h^$&^#$&^elLo world"], ["0123456789"], ["012345_Cb"]], "outputs": [[0], [0], [7], [7], [0], [2]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,080
def consonant_count(s):
acbdbe433d96faffa47b5900b0222718
UNKNOWN
Convert integers to binary as simple as that. You would be given an integer as a argument and you have to return its binary form. To get an idea about how to convert a decimal number into a binary number, visit here. **Notes**: negative numbers should be handled as two's complement; assume all numbers are integers stored using 4 bytes (or 32 bits) in any language. Your output should ignore leading 0s. So, for example: ```python to_binary(3)=="11" to_binary(-3)=="11111111111111111111111111111101" ``` *Be Ready for Large Numbers. Happy Coding ^_^*
["def to_binary(n):\n return \"{:0b}\".format(n & 0xffffffff)", "def to_binary(n):\n return bin(n if n >= 0 else 2 ** 32 + n)[2:]", "def to_binary(n):\n return bin(n % 2**32)[2:]", "def to_binary(n):\n return format(n & 0xffffffff, 'b')", "def to_binary(n):\n return bin(n & (2**32 - 1))[2:]", "def to_binary(n):\n n = n & 0xFFFFFFFF\n return bin(n)[2:]", "to_binary = lambda n: bin(n + 4294967296 * (n < 0))[2:]", "import numpy\n\ndef to_binary(n):\n return numpy.binary_repr(n) if n>=0 else numpy.binary_repr(n, width=32)", "def to_binary(n):\n return '{:b}'.format(n & 4294967295)", "def to_binary(n):\n if n < 0: return (bin(n & 0b111111111111111111111111111111111)[3:])\n return bin(n)[2:]"]
{"fn_name": "to_binary", "inputs": [[2], [3], [4], [5], [7], [10], [-3], [0], [1000], [-15], [-1000], [-999999], [999999]], "outputs": [["10"], ["11"], ["100"], ["101"], ["111"], ["1010"], ["11111111111111111111111111111101"], ["0"], ["1111101000"], ["11111111111111111111111111110001"], ["11111111111111111111110000011000"], ["11111111111100001011110111000001"], ["11110100001000111111"]]}
INTRODUCTORY
PYTHON3
CODEWARS
725
def to_binary(n):
5f388f5bbed99b4b65ec9cc221b5d49d
UNKNOWN
Basic regex tasks. Write a function that takes in a numeric code of any length. The function should check if the code begins with 1, 2, or 3 and return `true` if so. Return `false` otherwise. You can assume the input will always be a number.
["def validate_code(code):\n return str(code).startswith(('1', '2', '3'))\n", "def validate_code(code):\n return str(code)[0] in '123'", "def validate_code(code):\n import re\n return bool(re.match(r\"^[123]\\d*$\",str(code)))\n", "def validate_code(code):\n import re\n return bool(re.match('[123]',str(code)))", "def validate_code(code):\n return int(str(code)[0]) < 4", "import re\n\ndef validate_code(code):\n return bool(re.match(\"^[1-3]\",str(code)))", "validate_code = lambda c: str(c)[0] in \"123\"", "def validate_code(code):\n return True if str(code)[0] in set('123') else False", "from re import match\nfrom math import log10\n\ndef validate_code(code):\n # Without bothering with string conversion\n return 0 < code // 10**int(log10(code)) < 4\n \n # Title says regex so let's write one\n return bool(match(\"\\A[1-3]\", str(code)))", "validate_code=lambda n:str(n).startswith(tuple('123'))", "def validate_code(code):\n import re\n return True if re.match('^1|^2|^3', str(code)) is not None else False", "import re\ndef validate_code(code):\n return bool(re.match(\"[123]{1}.*\",str(code)))", "def validate_code(code):\n return True if str(code)[0] in (\"1\", \"2\", \"3\") else False", "import re\nvalidate_code = lambda c: bool(re.search(\"^[1-3]\", str(c)))", "from math import ceil, log10\n\ndef validate_code(code):\n return first_digit(code) in (1, 2, 3)\n\n\ndef first_digit(num):\n num_of_digs = ceil(log10(num))\n amount_of_digs_to_remove = num_of_digs - 1\n return num // 10**(amount_of_digs_to_remove) # removes digits starting from right", "def validate_code(code):\n #your code here\n string = str(code)\n return True if string[0] in '123' else False", "import re\n\ndef validate_code(code):\n return bool(re.match(r'^[1-3]',str(code)))\n\n# easy non-regex solution would be the following\n#\n# def validate_code(code):\n# return list(str(code))[0] in list('123')\n", "import re\ndef validate_code(code):\n if re.search(r'(\\A1)|(\\A2)|(\\A3)', str(code)):\n return True\n return False", "import re\ndef validate_code(code):\n #your code here\n return bool(re.match(r'[1-3]', str(code)))", "def validate_code(code):\n return '1' <= str(code)[0] <= '3'", "def validate_code(code):\n code = list(map(int, list(str(code))))\n return True if code[0] == 1 or code[0] == 2 or code[0] == 3 else False", "def validate_code(code):\n code_str = str(code)\n if code_str[0] == '1' or code_str[0] == '2' or code_str[0] == '3':\n return True\n return False", "def validate_code(code):\n code = str(code)\n print(code)\n if str(code)[0] in ['1','2','3']:\n return True\n else:\n return False", "def validate_code(code):\n return str(code)[0] in '123'\n\n \n#\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0439. \u041d\u0430\u043f\u0438\u0448\u0438\u0442\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u0447\u0438\u0441\u043b\u043e\u0432\u043e\u0439 \u043a\u043e\u0434\n#\u043b\u044e\u0431\u043e\u0439 \u0434\u043b\u0438\u043d\u044b. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u043a\u043e\u0434 \u0441 1, 2 \u0438\u043b\u0438 3, \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c true, \u0435\u0441\u043b\u0438 \u0434\u0430. \n#\u0412 \u043f\u0440\u043e\u0442\u0438\u0432\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0435\u0440\u043d\u0438\u0442\u0435 false.\n\n#\u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c, \u0447\u0442\u043e \u0432\u0432\u043e\u0434 \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0447\u0438\u0441\u043b\u043e\u043c.\"\"\"\n", "def validate_code(code):\n return (str(code)[0]) <= '3'", "def validate_code(code):\n import re\n \n if re.match(r'^[1-3]', str(code)) is not None:\n return True\n else:\n return False", "def validate_code(code):\n wert = str(code);\n print(wert);\n \n if wert[0] == '1':\n return True;\n elif wert[0] == '2':\n return True;\n elif wert[0] == '3':\n return True;\n else:\n return False"]
{"fn_name": "validate_code", "inputs": [[123], [248], [8], [321], [9453]], "outputs": [[true], [true], [false], [true], [false]]}
INTRODUCTORY
PYTHON3
CODEWARS
4,619
def validate_code(code):
95d5a588a2698a205661bb10f825f0e7
UNKNOWN
The image shows how we can obtain the Harmonic Conjugated Point of three aligned points A, B, C. - We choose any point L, that is not in the line with A, B and C. We form the triangle ABL - Then we draw a line from point C that intersects the sides of this triangle at points M and N respectively. - We draw the diagonals of the quadrilateral ABNM; they are AN and BM and they intersect at point K - We unit, with a line L and K, and this line intersects the line of points A, B and C at point D The point D is named the Conjugated Harmonic Point of the points A, B, C. You can get more knowledge related with this point at: (https://en.wikipedia.org/wiki/Projective_harmonic_conjugate) If we apply the theorems of Ceva (https://en.wikipedia.org/wiki/Ceva%27s_theorem) and Menelaus (https://en.wikipedia.org/wiki/Menelaus%27_theorem) we will have this formula: AC, in the above formula is the length of the segment of points A to C in this direction and its value is: ```AC = xA - xC``` Transform the above formula using the coordinates ```xA, xB, xC and xD``` The task is to create a function ```harmon_pointTrip()```, that receives three arguments, the coordinates of points xA, xB and xC, with values such that : ```xA < xB < xC```, this function should output the coordinates of point D for each given triplet, such that `xA < xD < xB < xC`, or to be clearer let's see some cases: ```python harmon_pointTrip(xA, xB, xC) ------> xD # the result should be expressed up to four decimals (rounded result) harmon_pointTrip(2, 10, 20) -----> 7.1429 # (2 < 7.1429 < 10 < 20, satisfies the constraint) harmon_pointTrip(3, 9, 18) -----> 6.75 ``` Enjoy it and happy coding!!
["def harmon_pointTrip(xA, xB, xC):\n a, b, c = list(map(float, [xA, xB, xC]))\n # Yay for algebra!\n d = ((a * c) + (b * c) - (2 * a * b)) / (2 * c - a - b)\n return round(d, 4)\n", "def harmon_pointTrip(xA, xB, xC):\n return round((xA*xC + xB*xC - 2*xA*xB) / (2*xC - xA - xB), 4)", "def harmon_pointTrip(a, b, c):\n return round((a*c + b*c - 2*a*b) / (2*c - a - b), 4)", "def harmon_pointTrip(a, b, c):\n return round(float(2 * a * b - c * b - a * c) / (a - 2 * c + b), 4)", "def harmon_pointTrip(a, b, c):\n return round((2.0*a*b - b*c - a*c) / (a + b - 2*c), 4)", "harmon_pointTrip=lambda a,b,c:round(((c-a)*b+(c-b)*a)/(1.0*(c-b)+(c-a)),4)", "def harmon_pointTrip(xA, xB, xC):\n return round((xA * xC + xB * xC - 2 * xA * xB) / float(2 * xC - xA - xB), 4)", "def harmon_pointTrip(xA, xB, xC):\n n=((-1)*(xB-xC))/((xA-xC)*1.0)\n xD=((n*xA)-xB)/(n-1)\n return round(xD,4)", "harmon_pointTrip=lambda a,b,c:round(1.*(b*(c-a)+a*(c-b))/((c-a)+(c-b)),4)", "def harmon_pointTrip(xA, xB, xC): #coordinates of points A, B and C such that\n return round((2*xA*xB-xC*(xA+xB))/(xA+xB-2*xC),4)"]
{"fn_name": "harmon_pointTrip", "inputs": [[2, 10, 20], [3, 9, 18], [6, 10, 11], [4, 12, 24], [5, 17, 20]], "outputs": [[7.1429], [6.75], [9.3333], [9.0], [15.0]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,115
def harmon_pointTrip(xA, xB, xC):
d658e6dbd34fa1e2fbd6f5375d2a0f85
UNKNOWN
We have the number ```12385```. We want to know the value of the closest cube but higher than 12385. The answer will be ```13824```. Now, another case. We have the number ```1245678```. We want to know the 5th power, closest and higher than that number. The value will be ```1419857```. We need a function ```find_next_power``` ( ```findNextPower``` in JavaScript, CoffeeScript and Haskell), that receives two arguments, a value ```val```, and the exponent of the power,``` pow_```, and outputs the value that we want to find. Let'see some cases: ```python find_next_power(12385, 3) == 13824 find_next_power(1245678, 5) == 1419857 ``` The value, ```val``` will be always a positive integer. The power, ```pow_```, always higher than ```1```. Happy coding!!
["def find_next_power(val, pow_):\n return int(val ** (1.0 / pow_) + 1) ** pow_", "import math\n\ndef find_next_power(val, pow_):\n next_power_value = math.floor( 1 + val ** (1/pow_))\n return next_power_value ** pow_", "def find_next_power(val, pow_):\n return int(val ** (1 / pow_) + 1) ** pow_", "def find_next_power(val, power):\n\n return int((val ** (1.0 / power)) + 1) ** power", "def find_next_power(val, pow_):\n import math\n a=val**(1./pow_)\n b=math.ceil(a)\n return b**pow_\n", "find_next_power=lambda n,p:int(n**(1./p)+1)**p", "find_next_power=lambda v, p: (int(v**(1.0/p))+1)**p", "def find_next_power(val, pow_):\n return round((int(val ** (1.0 / pow_)) + 1) ** pow_)", "\ndef find_next_power(val, pow_):\n num, next_power_value = 1, 1\n while val > next_power_value:\n next_power_value = num ** pow_\n num += 1\n \n return next_power_value", "from math import ceil\n\ndef find_next_power(val, pow_):\n return ceil((val + 1) ** (1 / pow_)) ** pow_"]
{"fn_name": "find_next_power", "inputs": [[12385, 3], [1245678, 5], [1245678, 6]], "outputs": [[13824], [1419857], [1771561]]}
INTRODUCTORY
PYTHON3
CODEWARS
1,022
def find_next_power(val, pow_):
577b24e6bae070216293e7580d7fdf96
UNKNOWN
The goal of this Kata is to remind/show you, how Z-algorithm works and test your implementation. For a string str[0..n-1], Z array is of same length as string. An element Z[i] of Z array stores length of the longest substring starting from str[i] which is also a prefix of str[0..n-1]. The first entry of Z array is meaning less as complete string is always prefix of itself. Example: Index: 0 1 2 3 4 5 6 7 8 9 10 11 Text: "a a b c a a b x a a a z" Z values: [11, 1, 0, 0, 3, 1, 0, 0, 2, 2, 1, 0] Your task will be to implement Z algorithm in your code and return Z-array. For empty string algorithm should return []. Input: string str Output: Z array For example: print zfunc('ababcaba') [8, 0, 2, 0, 0, 3, 0, 1] Note, that an important part of this kata is that you have to use efficient way to get Z-array (O(n))
["def prefix1(a, b):\n cnt = 0\n for i, j in zip(a, b):\n if i == j:\n cnt += 1\n else:\n return cnt\n return cnt \ndef prefix2(a, b, num):\n for i in range(num, -1, -1):\n if b.startswith(a[:i]):\n return i\ndef zfunc(str_):\n z = []\n k = len(str_)\n for i in range(len(str_)):\n z.append(prefix2(str_[i:], str_[: k - i], k - i))\n #z.append(prefix1(str_[i:], str_[: k - i])) #poor timing\n return z", "def zfunc(s):\n if s == '': return []\n n, ans = len(s), [0]*len(s)\n ans[0], i, j = n, 1, 0\n while i < n:\n while i+j < n and s[j] == s[i+j]:\n j += 1\n ans[i] = j\n if j == 0:\n i += 1\n continue\n k = 1\n while i+k < n and k + ans[k] < j:\n ans[i+k] = ans[k]\n k += 1\n i += k\n j -= k\n return ans", "def zfunc(s):\n if not s: return []\n n = len(s)\n Z = [n] * n\n l = r = 0\n for i in range(1, n):\n if i > r:\n l = r = i\n while r < n and s[r - l] == s[r]:\n r += 1\n Z[i] = r - l\n r -= 1\n else:\n k = i - l\n if Z[k] < r - i + 1:\n Z[i] = Z[k]\n else:\n l = i\n while r < n and s[r - l] == s[r]:\n r += 1\n Z[i] = r - l\n r -= 1\n return Z", "def zfunc(str_):\n if not str_:\n return []\n n = len(str_)\n z = [0] * n\n left, right, z[0] = 0, 0, n\n for i in range(1, n):\n if i < right:\n k = i - left\n if z[k] < right - i:\n z[i] = z[k]\n continue\n left = i\n else:\n left = right = i\n while right < n and str_[right - left] == str_[right]:\n right += 1\n z[i] = right - left\n return z", "def zfunc(s):\n z = [len(s)] + [0] * (len(s) - 1) if s else []\n i, j = 1, 0\n while i < len(s):\n while i+j < len(s) and s[j] == s[i+j]:\n j += 1\n z[i] = j\n if j == 0:\n i += 1\n continue\n k = 1\n while i+k < len(s) and k+z[k] < j:\n z[i+k] = z[k]\n k += 1\n i += k\n j -= k\n return z", "def zfunc(str_):\n l = len(str_)\n if l == 100000:\n return []\n if l == 100:\n return list(range(100, -100, -2))\n return [next((j for j in range(l-i) if str_[j] != str_[i+j]), l-i) for i in range(l)]", "def zfunc(str_):\n if not str_:\n return []\n r=[len(str_)]\n for i in range(1,len(str_)):\n j=0\n l=len(str_)-i\n if str_[:l]==str_[i:]:\n r.append(l)\n continue\n while(i+j<len(str_) and str_[j]==str_[i+j]):\n j+=1\n r.append(j)\n return r", "def zfunc(str_): \n if not str_:\n return []\n\n N = len(str_)\n Z = [N] + ([0] * (N-1))\n right = 0\n left = 0\n for i in range(1, N):\n if i > right:\n n = 0\n while n + i < N and str_[n] == str_[n+i]:\n n += 1\n Z[i] = n\n if n > 0:\n left = i\n right = i+n-1\n else:\n p = i - left\n q = right - i + 1\n\n if Z[p] < q:\n Z[i] = Z[p]\n else:\n j = right + 1\n while j < N and str_[j] == str_[j - i]:\n j += 1\n Z[i] = j - i\n left = i\n right = j - 1\n return Z", "def getZarr(string):\n n = len(string)\n z = [0] * n\n\n # [L,R] make a window which matches \n # with prefix of s \n l, r, k = 0, 0, 0\n for i in range(1, n): \n\n # if i>R nothing matches so we will calculate. \n # Z[i] using naive way. \n if i > r: \n l, r = i, i \n\n # R-L = 0 in starting, so it will start \n # checking from 0'th index. For example, \n # for \"ababab\" and i = 1, the value of R \n # remains 0 and Z[i] becomes 0. For string \n # \"aaaaaa\" and i = 1, Z[i] and R become 5 \n while r < n and string[r - l] == string[r]: \n r += 1\n z[i] = r - l \n r -= 1\n else: \n\n # k = i-L so k corresponds to number which \n # matches in [L,R] interval. \n k = i - l \n\n # if Z[k] is less than remaining interval \n # then Z[i] will be equal to Z[k]. \n # For example, str = \"ababab\", i = 3, R = 5 \n # and L = 2 \n if z[k] < r - i + 1: \n z[i] = z[k] \n\n # For example str = \"aaaaaa\" and i = 2, \n # R is 5, L is 0 \n else: \n\n # else start from R and check manually \n l = i \n while r < n and string[r - l] == string[r]: \n r += 1\n z[i] = r - l \n r -= 1\n return z\n\ndef zfunc(str_):\n #your code goes here\n solution = getZarr(str_)\n if (len(solution) > 1):\n solution[0] = len(solution)\n return solution", "# https://www.geeksforgeeks.org/z-algorithm-linear-time-pattern-searching-algorithm/\n\n\ndef zfunc(string):\n if not string:\n return []\n\n strlen = len(string)\n Z = [0] * strlen\n\n # [L,R] make a window which matches with prefix of s\n L = R = 0\n for i in range(1, strlen):\n # if i>R nothing matches so we will calculate.\n # Z[i] using naive way.\n if i > R:\n L = R = i\n\n # R-L = 0 in starting, so it will start\n # checking from 0'th index. For example,\n # for \"ababab\" and i = 1, the value of R\n # remains 0 and Z[i] becomes 0. For string\n # \"aaaaaa\" and i = 1, Z[i] and R become 5\n while R < strlen and string[R - L] == string[R]:\n R += 1\n Z[i] = R - L\n R -= 1\n else:\n # k = i-L so k corresponds to number which\n # matches in [L,R] interval.\n k = i - L\n # if Z[k] is less than remaining interval\n # then Z[i] will be equal to Z[k].\n # For example, str = \"ababab\", i = 3, R = 5\n # and L = 2\n if Z[k] < R - i + 1:\n # For example str = \"aaaaaa\" and i = 2, R is 5,\n # L is 0\n Z[i] = Z[k]\n else:\n # else start from R and check manually\n L = i\n while R < strlen and string[R - L] == string[R]:\n R += 1\n Z[i] = R - L\n R -= 1\n Z[0] = strlen\n return Z\n"]
{"fn_name": "zfunc", "inputs": [["ababcaba"], [""], ["aaaaaaaa"], ["ababababab"], ["aaaa$aaaa"], ["abracadabra"]], "outputs": [[[8, 0, 2, 0, 0, 3, 0, 1]], [[]], [[8, 7, 6, 5, 4, 3, 2, 1]], [[10, 0, 8, 0, 6, 0, 4, 0, 2, 0]], [[9, 3, 2, 1, 0, 4, 3, 2, 1]], [[11, 0, 0, 1, 0, 1, 0, 4, 0, 0, 1]]]}
INTRODUCTORY
PYTHON3
CODEWARS
6,962
def zfunc(str_):
cf5b2c799fecf00980c789e744f1ad1c
UNKNOWN
Create a function that takes an input String and returns a String, where all the uppercase words of the input String are in front and all the lowercase words at the end. The order of the uppercase and lowercase words should be the order in which they occur. If a word starts with a number or special character, skip the word and leave it out of the result. Input String will not be empty. For an input String: "hey You, Sort me Already!" the function should return: "You, Sort Already! hey me"
["def capitals_first(string):\n return ' '.join([word for word in string.split() if word[0].isupper()] + [word for word in string.split() if word[0].islower()])\n", "def capitals_first(string):\n # biggies first...\n words = string.split()\n st1 = []\n st2 = []\n for word in words:\n if word[0].isalpha():\n if word[0].isupper():\n st1.append(word)\n else:\n st2.append(word)\n return \" \".join(st1 + st2)", "def capitals_first(string):\n return ' '.join(sorted((a for a in string.split() if a[0].isalpha()),\n key=lambda b: b[0].islower()))\n", "def capitals_first(text):\n words = [ w for w in text.split() if w[0].isalpha() and not w.isnumeric() ]\n return ' '.join(sorted(words,key=lambda w: w[0] != w[0].upper()))", "capitals_first=lambda t:(lambda x:' '.join([e for e in x if e[0].isupper()]+[e for e in x if e[0].islower()]))(t.split())", "def capitals_first(text):\n return ' '.join(sorted(filter(lambda w: w[0].isalpha(), text.split()), key=lambda w: w[0].islower()))", "def capitals_first(text):\n # one-line\n #return \" \".join(sorted((word for word in text.split(\" \") if word[0].isalpha()), key=lambda word: word[0].islower()))\n upper, lower = [], []\n for word in text.split(\" \"):\n if word[0].islower():\n lower.append(word)\n elif word[0].isupper():\n upper.append(word)\n return \" \".join(upper + lower)", "def capitals_first(text):\n words = text.split()\n lower,upper = [],[]\n for w in words:\n if w[0].islower(): lower.append(w)\n elif w[0].isupper(): upper.append(w)\n return \" \".join(upper+lower)", "from itertools import chain\ndef capitals_first(text):\n cap, low = [], []\n for w in text.split():\n if w[0].isalpha():\n (cap, low)[w[0].islower()].append(w)\n return ' '.join(chain(cap, low))", "def capitals_first(text):\n words = [word for word in text.split() if word[0].isalpha()]\n return ' '.join(sorted(words, key=lambda x: not x[0].isupper()))\n"]
{"fn_name": "capitals_first", "inputs": [["hey You, Sort me Already"], ["sense Does to That Make you?"], ["i First need Thing In coffee The Morning"], ["123 baby You and Me"], ["Life gets Sometimes pretty !Hard"]], "outputs": [["You, Sort Already hey me"], ["Does That Make sense to you?"], ["First Thing In The Morning i need coffee"], ["You Me baby and"], ["Life Sometimes gets pretty"]]}
INTRODUCTORY
PYTHON3
CODEWARS
2,116
def capitals_first(text):