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
|
---|---|---|---|---|---|---|---|---|---|
d6e57c16bed95ade1c1b5c3b95fb5264 | UNKNOWN | You should write a simple function that takes string as input and checks if it is a valid Russian postal code, returning `true` or `false`.
A valid postcode should be 6 digits with no white spaces, letters or other symbols. Empty string should also return false.
Please also keep in mind that a valid post code **cannot start with** `0, 5, 7, 8 or 9`
## Examples
Valid postcodes:
* 198328
* 310003
* 424000
Invalid postcodes:
* 056879
* 12A483
* 1@63
* 111 | ["def zipvalidate(postcode):\n return len(postcode) == 6 and postcode.isdigit() and postcode[0] not in \"05789\"", "import re\n\ndef zipvalidate(postcode):\n return bool(re.fullmatch(r\"[12346]\\d{5}\", postcode))", "def zipvalidate(p):\n return p.isdigit() and 100000 < int(p) < 699999 and p[0] != \"5\"\n \n# Python translation of kata by MMMAAANNN\n", "def start_digit_valid(func):\n def start_digit_validate(postcode):\n '''\n A valid post code cannot start with digit 0, 5, 7, 8 or 9\n '''\n if postcode[0] in '05789':\n return False\n return func(postcode)\n return start_digit_validate\n\ndef length_valid(func):\n def length_validator(postcode):\n '''\n A valid postcode should be 6 digits\n '''\n MANDITORY_LENGTH = 6\n if len(postcode) != MANDITORY_LENGTH:\n return False\n return func(postcode)\n return length_validator\n\n\ndef only_numbers(func):\n def only_numbers(postcode):\n '''\n A valid postcode should be 6 digits with no white spaces, letters or other symbols.\n '''\n if any([c not in '0123456789' for c in postcode]):\n return False\n return func(postcode)\n return only_numbers\n\n@only_numbers\n@length_valid\n@start_digit_valid\ndef zipvalidate(postcode):\n return True", "def zipvalidate(postcode):\n try:\n int(postcode)\n if postcode[0] not in ['0','5','7','8','9'] and len(postcode) == 6:\n return True\n except:\n pass\n return False", "zipvalidate = lambda postcode: bool(__import__('re').match(r'^[12346]\\d{5}\\Z', postcode))", "REGEX = __import__(\"re\").compile(r\"[1-46]\\d{5}\").fullmatch\n\ndef zipvalidate(postcode):\n return bool(REGEX(postcode))", "def zipvalidate(p):\n return len(p)==6 and p[0] in '12346' and all(d in '0123456789' for d in p)", "import re\ndef zipvalidate(postcode):\n return bool(re.fullmatch(r\"[1-46]\\d{5}\", postcode))", "def zipvalidate(postcode):\n try:\n int(postcode)\n except ValueError:\n return False\n \n if len(postcode) != 6:\n return False\n return all([x!=postcode[0] for x in ['0', '5', '7', '8', '9']])\n\n"] | {"fn_name": "zipvalidate", "inputs": [["142784"], ["642784"], ["111"], ["1111111"], ["AA5590"], [""], ["\n245980"], ["245980\n"], ["245980a"], ["24598a"], [" 310587 "], ["555555"], ["775255"], ["875555"], ["012345"], ["968345"], ["@68345"]], "outputs": [[true], [true], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,254 |
def zipvalidate(postcode):
|
94e66b43300e33be5fa38d68814dba59 | UNKNOWN | Take a string and return a hash with all the ascii values of the characters in the string.
Returns nil if the string is empty.
The key is the character, and the value is the ascii value of the character.
Repeated characters are to be ignored and non-alphebetic characters as well. | ["def char_to_ascii(string):\n return {c: ord(c) for c in set(string) if c.isalpha()} if len(string) else None", "def char_to_ascii(s):\n if s: return {c: ord(c) for c in set(s) if c.isalpha()}\n", "def char_to_ascii(s):\n if s: return {c: ord(c) for c in set(s) if c.isalpha()}", "char_to_ascii = lambda s: {e:ord(e) for e in set(s) if e.isalpha()} or None\n", "def char_to_ascii(string):\n return {c:ord(c) for c in string if c.isalpha()} or None", "def char_to_ascii(stg):\n return {c: ord(c) for c in set(stg) if c.isalpha()} if stg else None", "def char_to_ascii(string):\n return { c: ord(c) for c in set(string) if c.isalpha() } if len(string) > 0 else None", "char_to_ascii = lambda s: None if len(s) == 0 else {c: ord(c) for c in s if c.isalpha()}", "def char_to_ascii(string):\n # Good Luck!\n return {x: ord(x) for x in set(string) if x.isalpha()} or None", "def char_to_ascii(s):\n return {ch:ord(ch) for ch in set(s) if ch.isalpha()} if s else None", "def char_to_ascii(s):\n return {ch:ord(ch) for ch in s if ch.isalpha()} if s else None"] | {"fn_name": "char_to_ascii", "inputs": [[""], ["a"], ["aaa"], ["hello world"], ["ABaa ^"]], "outputs": [[null], [{"a": 97}], [{"a": 97}], [{"h": 104, "e": 101, "l": 108, "o": 111, "w": 119, "r": 114, "d": 100}], [{"A": 65, "B": 66, "a": 97}]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,083 |
def char_to_ascii(string):
|
512d2d959fd36eccf9f45d241cd987ac | UNKNOWN | > If you've finished this kata, you can try the [more difficult version](https://www.codewars.com/kata/5b256145a454c8a6990000b5).
## Taking a walk
A promenade is a way of uniquely representing a fraction by a succession of “left or right” choices.
For example, the promenade `"LRLL"` represents the fraction `4/7`.
Each successive choice (`L` or `R`) changes the value of the promenade by combining the values of the
promenade before the most recent left choice with the value before the most recent right choice. If the value before the most recent left choice was *l/m* and the value before the most recent right choice
was r/s then the new value will be *(l+r) / (m+s)*.
If there has never been a left choice we use *l=1* and *m=0*;
if there has never been a right choice we use *r=0* and *s=1*.
So let's take a walk.
* `""` An empty promenade has never had a left choice nor a right choice. Therefore we use *(l=1 and m=0)* and *(r=0 and s=1)*.
So the value of `""` is *(1+0) / (0+1) = 1/1*.
* `"L"`. Before the most recent left choice we have `""`, which equals *1/1*. There still has never been a right choice, so *(r=0 and s=1)*. So the value of `"L"` is *(1+0)/(1+1) = 1/2*
* `"LR"` = 2/3 as we use the values of `""` (before the left choice) and `"L"` (before the right choice)
* `"LRL"` = 3/5 as we use the values of `"LR"` and `"L"`
* `"LRLL"` = 4/7 as we use the values of `"LRL"` and `"L"`
Fractions are allowed to have a larger than b.
## Your task
Implement the `promenade` function, which takes an promenade as input (represented as a string), and returns
the corresponding fraction (represented as a tuple, containing the numerator and the denominator).
```Python
promenade("") == (1,1)
promenade("LR") == (2,3)
promenade("LRLL") == (4,7)
```
```Java
Return the Fraction as an int-Array:
promenade("") == [1,1]
promenade("LR") == [2,3]
promenade("LRLL") == [4,7]
```
*adapted from the 2016 British Informatics Olympiad* | ["def promenade(choices):\n \n def compute(): return l+r,m+s\n \n l,m, r,s = 1,0, 0,1\n for c in choices:\n if c=='L': l,m = compute()\n else: r,s = compute()\n \n return compute()", "def promenade(choices):\n l, m = (1, 0)\n r, s = (0, 1)\n for choice in choices:\n if choice == 'L': l, m = l+r, m+s\n elif choice == 'R': r, s = l+r, m+s\n return l+r,m+s", "\ndef next(last_l, last_r):\n return last_l[0] + last_r[0], last_l[1] + last_r[1]\n\ndef promenade(choices):\n last_l = (1, 0)\n last_r = (0, 1)\n last = None\n \n for c in choices:\n if c == \"L\":\n last_l = next(last_l, last_r)\n else:\n last_r = next(last_l, last_r)\n \n return next(last_l, last_r)\n \n \n \n \n # good luck!\n", "def promenade(choices):\n x = [(1, 0), (0, 1)] # [(l, m), (r, s)]\n for c in choices:\n x[c == 'R'] = x[0][0] + x[1][0], x[0][1] + x[1][1]\n return x[0][0] + x[1][0], x[0][1] + x[1][1]", "def promenade(choices):\n l, m, r = [1, 0], [1, 1], [0, 1]\n for c in choices:\n if c == 'L': l = m[:]\n else: r = m[:]\n m = [l[0]+r[0], l[1]+r[1]]\n return tuple(m)", "def promenade(choices):\n if not choices: return (1, 1)\n (a, b) = promenade(choices[1:])\n return (a, a + b) if choices[0] == 'L' else (a + b, b)", "def promenade(choices):\n lm=[1,0]\n rs=[0,1]\n ans=[1,1]\n \n for i in choices:\n if i=='L':\n lm=ans[::]\n \n if i=='R':\n rs=ans[::]\n ans=[lm[0]+rs[0],lm[1]+rs[1]]\n return tuple(ans)\n \ndef fraction_to_promenade(fraction):\n ans=\"\"\n frac=list(fraction)\n while(frac[0]!=frac[1]):\n if frac[0]>frac[1]:\n \n ans+=\"R\"\n frac[0]=frac[0]-frac[1]\n if frac[1]>frac[0]:\n ans+=\"L\"\n frac[1]=frac[1]-frac[0]\n return ans", "def promenade(ch):\n \n def evaulate(): return l+r,m+s\n \n l,m, r,s = 1,0, 0,1\n for c in ch:\n if c=='L': l,m = evaulate()\n else: r,s = evaulate()\n \n return evaulate()", "def promenade(choices):\n fraction=(1,1)\n most_recent_L=(1,0)\n most_recent_R=(0,1)\n fraction_add=lambda L, R: tuple( l + r for l, r in zip(L,R))\n for C in choices:\n if C==\"L\":\n most_recent_L=fraction\n fraction=fraction_add(most_recent_L,most_recent_R)\n elif C==\"R\": \n most_recent_R=fraction\n fraction=fraction_add(most_recent_L,most_recent_R)\n else: raise ValueError\n return fraction", "def promenade(choices):\n last_left = [1,0]\n last_right = [0,1]\n out = [1,1]\n for choice in choices:\n if choice is 'L':\n last_left = out.copy()\n out[0] += last_right[0]\n out[1] += last_right[1]\n else:\n last_right = out.copy()\n out[0] += last_left[0]\n out[1] += last_left[1]\n return tuple(out)\n"] | {"fn_name": "promenade", "inputs": [[""], ["L"], ["R"], ["LRLL"], ["LLRLR"], ["RRRLRRR"], ["LLLLRLLLL"], ["LLLLLLLLLL"], ["RLRLRLRRLRLL"], ["LLRRLRRLRLLL"], ["LRRLLRLLRLRR"], ["LRRLRLLLLRLL"], ["LLLRRRLLLRLL"], ["RRLRRRLLRLRR"], ["RRRRLLRLLRLR"], ["LLRLRLLRLLRL"], ["LRLLRRRRLLRR"], ["RLRRLRRRRRRR"]], "outputs": [[[1, 1]], [[1, 2]], [[2, 1]], [[4, 7]], [[5, 13]], [[19, 5]], [[6, 29]], [[1, 11]], [[290, 179]], [[87, 206]], [[161, 229]], [[107, 149]], [[49, 162]], [[219, 79]], [[214, 49]], [[112, 295]], [[100, 169]], [[61, 35]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,114 |
def promenade(choices):
|
f8ffd31df121c01f20f49cf7206c7fa3 | UNKNOWN | *This is my first Kata in the Ciphers series. This series is meant to test our coding knowledge.*
## Ciphers #1 - The 01 Cipher
This cipher doesn't exist, I just created it by myself. It can't actually be used, as there isn't a way to decode it. It's a hash. Multiple sentences may also have the same result.
## How this cipher works
It looks at the letter, and sees it's index in the alphabet, the alphabet being `a-z`, if you didn't know. If it is odd, it is replaced with `1`, if it's even, its replaced with `0`. Note that the index should start from 0. Also, if the character isn't a letter, it remains the same.
## Example
This is because `H`'s index is `7`, which is odd, so it is replaced by `1`, and so on.
Have fun (en)coding! | ["def encode(s):\n return ''.join( str(1 - ord(c)%2) if c.isalpha() else c for c in s )", "encode = lambda s: \"\".join((x, str(~ord(x)%2))[x.isalpha()] for x in s)", "import re\n\ndef encode(s):\n return re.sub(r\"[a-zA-Z]\", lambda m: str((ord(m.group())+1)%2), s)", "def encode(s):\n return \"\".join(['1', '0'][ord(x)%2] if x.isalpha() else x for x in s.lower())", "def encode(s):\n return ''.join(str(ord(c)&1^1) if c.isalpha() else c for c in s)", "def encode(s):\n return ''.join([[i, '10'[ord(i) % 2]][i.isalpha()] for i in s ])", "def encode(s):\n return ''.join(str((ord(c) - 1) % 2) if c.isalpha() else c for c in s)\n", "def encode(s):\n return ''.join(str((ord(c.lower()) - 97) % 2) if c.isalpha() else c for c in s)", "from string import ascii_lowercase as alphabet\ndef encode(s):\n POS={v:i%2 for i,v in enumerate(alphabet)}\n return \"\".join(str(POS.get(c,c)) for c in s.lower())", "def encode(s):\n res = ''\n for i in range(len(s)):\n if s[i].isupper():\n if (ord(s[i]) - 65) % 2 == 0:\n res += '0'\n elif (ord(s[i]) - 65) % 2 == 1:\n res += '1'\n elif s[i].islower():\n if (ord(s[i]) - 97) % 2 == 0:\n res += '0'\n elif (ord(s[i]) - 97) % 2 == 1:\n res += '1'\n else:\n res += s[i]\n return res"] | {"fn_name": "encode", "inputs": [["Hello World!"]], "outputs": [["10110 00111!"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,385 |
def encode(s):
|
5a2feb5146291dd9b0b3607969be2a5e | UNKNOWN | This kata is the second part of a series: [Neighbourhood kata collection](https://www.codewars.com/collections/5b2f4db591c746349d0000ce). If this one is to easy you can try out the harder Katas.;)
___
The neighbourhood of a cell (in a matrix) are cells that are near to it. There are two popular types:
- The [Moore neighborhood](https://en.wikipedia.org/wiki/Moore_neighborhood) are eight cells which surround a given cell.
- The [Von Neumann neighborhood](https://en.wikipedia.org/wiki/Von_Neumann_neighborhood) are four cells which share a border with the given cell.
___
# Task
Given a neighbourhood type (`"moore"` or `"von_neumann"`), a 2D matrix (a list of lists) and a pair of coordinates, return the list of neighbours of the given cell.
Notes:
- The order of the elements in the output list is not important.
- If the input indexes are outside the matrix, return an empty list.
- If the the matrix is empty, return an empty list.
- Order of the indices: The first index should be applied for the outer/first matrix layer. The last index for the most inner/last layer. `coordinates = (m, n)` should be apllied like `mat[m][n]`
___
## Examples
```
\ n 0 1 2 3 4
m --------------------------
0 | 0 | 1 | 2 | 3 | 4 |
1 | 5 | 6 | 7 | 8 | 9 |
2 | 10 | 11 | 12 | 13 | 14 |
3 | 15 | 16 | 17 | 18 | 19 |
4 | 20 | 21 | 22 | 23 | 24 |
--------------------------
get_neighborhood("moore", mat, (1,1)) == [0, 1, 2, 5, 7, 10, 11, 12]
get_neighborhood("moore", mat, (0,0)) == [1, 6, 5]
get_neighborhood("moore", mat, (4,2)) == [21, 16, 17, 18, 23]
get_neighborhood("von_neumann", mat, (1,1)) == [1, 5, 7, 11]
get_neighborhood("von_neumann", mat, (0,0)) == [1, 5]
get_neighborhood("von_neumann", mat, (4,2)) == [21, 17, 23]
```
___
Translations are appreciated.^^
If you like chess take a look at [Chess Aesthetics](https://www.codewars.com/kata/5b574980578c6a6bac0000dc)
If you like puzzles and take a look at [Rubik's cube](https://www.codewars.com/kata/5b3bec086be5d8893000002e) | ["def get_neighbourhood(typ, arr, coordinates):\n \n def isInside(x,y): return 0 <= x < len(arr) and 0 <= y < len(arr[0])\n \n x,y = coordinates\n if not isInside(x,y): return []\n \n neigh = ( [(dx, dy) for dx in range(-1,2) for dy in range(-1,2) if (dx,dy) != (0,0)]\n if typ == 'moore' else [(0,1), (0,-1), (1,0), (-1,0)] )\n \n return [ arr[a][b] for a,b in ((x+dx,y+dy) for dx,dy in neigh) if isInside(a,b) ]", "vn = [(-1, 0), (0, -1), (0, 1), (1, 0)]\nmr = vn + [(-1, -1), (-1, 1), (1, -1), (1, 1)]\n\ndef get_neighbourhood(nh, a, p):\n h, w, nh, x, y = list(range(len(a))), list(range(len(a[0] if a else []))), mr if \"r\" in nh else vn, *p\n return [a[x+i][y+j] for i, j in nh if ((x+i) in h and (y+j) in w)] if x in h and y in w else []\n", "def get_neighbourhood(n_type, matrix, coordinates):\n height = len(matrix)\n width = len(matrix[0])\n y, x = coordinates\n if not (0 <= y < height and 0 <= x < width): return []\n moore = [(y+dy, x+dx) for dy in [-1, 0, 1] for dx in [-1, 0, 1] if (dy, dx) != (0, 0)]\n von_neumann = [moore[idx] for idx in (1, 3, 4, 6)]\n neighbors_coords = eval(n_type)\n neighbors = [matrix[y][x] for y, x in neighbors_coords if 0 <= y < height and 0 <= x < width]\n return neighbors", "D = {\"von_neumann\":((0, 1), (0, -1), (1, 0), (-1, 0)),\n \"moore\":((0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1))}\n\ndef get_neighbourhood(n_type, mat, coordinates):\n (i, j), H, W = coordinates, len(mat), len(mat[0])\n check = lambda a,b: 0 <= i+a < H and 0 <= j+b < W\n return [mat[i+k][j+l] for k,l in D[n_type] if check(k, l)] if check(0, 0) else []", "def get_neighbourhood(type_, arr, co):\n h, w = len(arr), len(arr[0])\n i, j = co\n if not arr[0] or i>=h or j>=w:return []\n li = []\n if type_ == 'moore':\n return [arr[k][l] for k in range(i-1 if i>0 else 0, (i+1 if i<h-1 else h-1) + 1)\n for l in range(j-1 if j>0 else 0,(j+1 if j<w-1 else w-1)+1) if [k,l]!=[i,j]]\n else:\n li = [arr[i-1][j] if i>0 else 'x',\n arr[i+1][j] if i<h-1 else 'x',\n arr[i][j-1] if j>0 else 'x', \n arr[i][j+1] if j<w-1 else 'x']\n while 'x' in li : li.remove('x')\n return li", "NEIGHBOURHOOD = {\"von_neumann\": 1, \"moore\": 2}\n\ndef closer_cells(n, x, y):\n return ((x+u, y+v)\n for u in range(-1, 2) for v in range(-1, 2)\n if 0 < abs(u) + abs(v) <= n)\n\ndef get_neighbourhood(n_type, arr, coordinates):\n def is_inside(x, y):\n return 0 <= x < len(arr) and 0 <= y < len(arr[0])\n\n return [] if not is_inside(*coordinates) else [arr[x][y]\n for x, y in closer_cells(NEIGHBOURHOOD[n_type], *coordinates)\n if is_inside(x, y)]", "def get_neighbourhood(n_type, mat, coord):\n x, y = coord[0], coord[1]\n if x<0 or y<0 or x>=len(mat) or y>=len(mat[0]):\n return []\n val = [(x-1, y), (x, y-1), (x, y+1), (x+1, y)]\n if n_type == 'moore':\n val += [(x-1, y-1), (x-1, y+1), (x+1, y-1), (x+1, y+1)]\n return [mat[a[0]][a[1]] for a in val if a[0]>=0 and a[0]<len(mat) and a[1]>=0 and a[1]<len(mat[0])]\n", "def get_offsets(distance, moore=True):\n offsets = list(range(-distance, distance + 1))\n for dr in offsets:\n for dc in offsets:\n if (dr, dc) == (0, 0):\n continue\n if not moore and abs(dr) + abs(dc) > distance:\n # Manhattan distance too large\n continue\n yield (dr, dc)\n\ndef get_neighbourhood(n_type, arr, coordinates, distance=1):\n h, w = len(arr), len(arr[0])\n if not (0 <= coordinates[0] < h and 0 <= coordinates[1] < w):\n # Coordinate not in arr\n return []\n r, c = coordinates\n return [\n arr[r + dr][c + dc]\n for dr, dc in get_offsets(distance, n_type == 'moore')\n if 0 <= r + dr < h and 0 <= c + dc < w\n ]\n", "def get_neighbourhood(n_type, mat, coordinates):\n d = {'moore': [(0,1),(1,0),(-1,0),(0,-1),(-1,1),(1,-1),(1,1),(-1,-1)],\n 'von_neumann': [(0,1),(1,0),(-1,0),(0,-1)]\n }\n y,x = coordinates\n if not mat or not 0<=y<len(mat) or not 0<=x<len(mat[0]): return []\n \n r = []\n for i,j in d.get(n_type):\n a,b = y+i,x+j\n if 0<=a<len(mat) and 0<=b<len(mat[0]):\n r.append(mat[a][b])\n \n return r"] | {"fn_name": "get_neighbourhood", "inputs": [["moore", [[]], [0, 0]], ["von_neumann", [[]], [0, 0]], ["moore", [[], [], []], [0, 0]], ["von_neumann", [[], [], []], [0, 0]]], "outputs": [[[]], [[]], [[]], [[]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,456 |
def get_neighbourhood(n_type, mat, coordinates):
|
8e4cfe5202b45486587484ffd3a3a4f9 | UNKNOWN | Your website is divided vertically in sections, and each can be of different size (height).
You need to establish the section index (starting at `0`) you are at, given the `scrollY` and `sizes` of all sections.
Sections start with `0`, so if first section is `200` high, it takes `0-199` "pixels" and second starts at `200`.
### Example:
`getSectionIdFromScroll( 300, [300,200,400,600,100] )`
will output number `1` as it's the second section.
`getSectionIdFromScroll( 1600, [300,200,400,600,100] )`
will output number `-1` as it's past last section.
Given the `scrollY` integer (always non-negative) and an array of non-negative integers (with at least one element), calculate the index (starting at `0`) or `-1` if `scrollY` falls beyond last section (indication of an error). | ["def get_section_id(scroll, sizes):\n c = 0\n for idx, s in enumerate(sizes):\n c += s\n if scroll < c: return idx\n return -1", "from itertools import accumulate\n\n# Once again, thanks itertools\ndef get_section_id(scroll, sizes):\n return next((i for i,x in enumerate(accumulate(sizes)) if x > scroll), -1)", "def get_section_id(scroll, sizes):\n if scroll >= sum(sizes): return -1\n return sum(scroll >= sum(sizes[:i+1]) for i in range(len(sizes)))", "from itertools import takewhile, accumulate\n\n\ndef get_section_id(scroll, sizes):\n return -1 if sum(sizes) <= scroll else sum(1 for _ in takewhile(scroll.__ge__, accumulate(sizes)))", "def get_section_id(scroll, sizes):\n where = 0\n for i in range(len(sizes)):\n where += sizes[i]\n if where > scroll:\n return i\n return -1", "def get_section_id(scroll, sizes):\n for i, _ in enumerate(sizes):\n if scroll < sum(sizes[:i+1]):\n return i\n return -1", "from bisect import bisect\nfrom itertools import accumulate\n\ndef get_section_id(scroll, sizes):\n return bisect(list(accumulate(sizes)), scroll) if scroll < sum(sizes) else -1", "def get_section_id(scroll, sizes):\n \n for i, s in enumerate(sizes):\n scroll -= s\n if scroll < 0:\n return i\n \n return -1", "from itertools import accumulate\n\ndef get_section_id(scroll, sizes):\n return next((i for i,s in enumerate(accumulate(sizes)) if s > scroll), -1)", "def get_section_id(scroll, sizes):\n a = 0\n for i in sizes:\n scroll -= i\n \n if scroll < 0:\n return a\n a += 1\n return -1"] | {"fn_name": "get_section_id", "inputs": [[1, [300, 200, 400, 600, 100]], [299, [300, 200, 400, 600, 100]], [300, [300, 200, 400, 600, 100]], [1599, [300, 200, 400, 600, 100]], [1600, [300, 200, 400, 600, 100]]], "outputs": [[0], [0], [1], [4], [-1]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,688 |
def get_section_id(scroll, sizes):
|
fc05f0d3143834342fc8a59a4f2fbea1 | UNKNOWN | Write a function that accepts a string, and returns true if it is in the form of a phone number. Assume that any integer from 0-9 in any of the spots will produce a valid phone number.
Only worry about the following format:
(123) 456-7890 (don't forget the space after the close parentheses)
Examples:
```
validPhoneNumber("(123) 456-7890") => returns true
validPhoneNumber("(1111)555 2345") => returns false
validPhoneNumber("(098) 123 4567") => returns false
``` | ["def validPhoneNumber(phoneNumber):\n import re\n return bool(re.match(r\"^(\\([0-9]+\\))? [0-9]+-[0-9]+$\", phoneNumber))", "# This is actually quite a bit more complicated in real life\n# I'd use https://github.com/googlei18n/libphonenumber\nimport re\n\nprog = re.compile('^\\(\\d{3}\\) \\d{3}-\\d{4}$')\n\ndef validPhoneNumber(phone_number):\n return prog.match(phone_number) is not None", "def validPhoneNumber(phoneNumber):\n number = ''\n template = '(xxx) xxx-xxxx'\n for l in phoneNumber:\n if l.isdigit():\n number += 'x'\n else:\n number += l\n \n return number == template\n\n", "validPhoneNumber = lambda x: bool(__import__('re').match('\\(\\d{3}\\) \\d{3}-\\d{4}$', x))", "import re\n\ndef validPhoneNumber(phoneNumber):\n return any(re.findall(\"^\\([0-9]{3}\\)\\s[0-9]{3}-[0-9]{4}$\", phoneNumber))", "import re\ndef validPhoneNumber(phoneNumber):\n if re.match('^\\([0-9]{3}\\) [0-9]{3}-[0-9]{4}$',phoneNumber):\n return True\n return False", "import re\n\ndef validPhoneNumber(phoneNumber):\n pattern = \"^\\(\\d{3,3}\\) \\d{3,3}-\\d{4,4}$\"\n compiled_pattern = re.compile(pattern)\n return True if re.match(compiled_pattern, phoneNumber) else False", "import re\n\nnums = '1234567890'\n\ndef validPhoneNumber(pn):\n if len(pn) != len(\"(123) 456-7890\"):\n return False \n elif pn[0] != '(':\n return False\n elif pn[1] not in nums or pn[2] not in nums or pn[3] not in nums:\n return False\n elif pn[4] != ')':\n return False\n elif pn[5] != ' ':\n return False\n elif pn[6] not in nums or pn[7] not in nums or pn[8] not in nums:\n return False\n elif pn[9] != '-':\n return False\n elif pn[10] not in nums or pn[11] not in nums or pn[12] not in nums or pn[13] not in nums:\n return False\n else:\n return True", "def validPhoneNumber(s):\n if s.count(' ') == s.count('-') == 1 and len(s) == 14:\n a = s.replace('(','').replace(')','').replace('-',' ')\n b = a.split()\n return [len(x) for x in b] == [3,3,4]\n return False", "import re\ndef validPhoneNumber(num):\n return bool(re.match(\"^[(][0-9]{3}[)] [0-9]{3}-[0-9]{4}$\", num))"] | {"fn_name": "validPhoneNumber", "inputs": [["(123) 456-7890"], ["(1111)555 2345"], ["(098) 123 4567"], ["(123)456-7890"], ["abc(123)456-7890"], ["(123)456-7890abc"], ["abc(123)456-7890abc"], ["abc(123) 456-7890"], ["(123) 456-7890abc"], ["abc(123) 456-7890abc"]], "outputs": [[true], [false], [false], [false], [false], [false], [false], [false], [false], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,262 |
def validPhoneNumber(phoneNumber):
|
3f0ad9bee1be558d0e67b69fac97e416 | UNKNOWN | Here your task is to Create a (nice) Christmas Tree.
You don't have to check errors or incorrect input values, every thing is ok without bad tricks, only one int parameter as input and a string to return;-)...
So what to do?First three easy examples:
````
Input: 3 and Output:
*
***
*****
###
Input 9 and Output:
*
***
*****
***
*****
*******
*****
*******
*********
###
Input 17 and Output:
*
***
*****
***
*****
*******
*****
*******
*********
*******
*********
***********
*********
***********
*************
###
Really nice trees, or what???! So merry Christmas;-)
````
You can see, always a root, always steps of hight 3, tree never smaller than 3 (return "") and no difference for input values like 15 or 17 (because (int) 15/3 = (int) 17/3). That's valid for every input and every tree.
I think there's nothing more to say - perhaps look at the testcases too;-)!
There are some static tests at the beginning and many random tests if you submit your solution.
Hope you have fun:-)! | ["def christmas_tree(h):\n return \"\" if h<3 else \"\\r\\n\".join([\"\\r\\n\".join([\" \"*(((5-y)//2)+(h//3)-i-1)+\"*\"*(y+i*2) for y in [1,3,5]]) for i in range(h//3)])+\"\\r\\n\"+\" \"*(h//3)+\"###\"", "def christmas_tree(height):\n height, tree = height // 3, []\n for floor in range(height):\n for branch in range(floor, 3 + floor):\n tree.append(f\"{' ' * (height - branch + 1)}{'*' * (branch * 2 + 1)}\")\n tree.append(f\"{' ' * (height)}###\")\n return \"\\r\\n\".join(tree) if height else \"\"", "def christmas_tree(height):\n height = height // 3 * 3\n if height <= 0:\n return \"\"\n lines = []\n w = 3\n for i in range(height):\n w += 2 if i % 3 else -2\n lines.append(\"*\" * w)\n lines.append(\"###\")\n return \"\\r\\n\".join(line.center(w).rstrip() for line in lines)", "def christmas_tree(height):\n if height < 3:\n return \"\"\n result = []\n for i in range(height // 3):\n w = 1 + 2 * i\n result.append(\"*\" * w) \n result.append(\"*\" * (w + 2))\n result.append(\"*\" * (w + 4))\n result.append(\"###\")\n l = len(result[-2])\n return \"\\r\\n\".join([line.center(l).rstrip() for line in result])", "christmas_tree=lambda n:'\\r\\n'.join([(n//3-j+1)*' '+(2*j+1)*'*'for i in range(n//3)for j in range(i,i+3)]+[n//3*' '+3*'#']*(n//3>0))", "christmas_tree=lambda n:\"\\r\\n\".join([('*'*(j-p)).center((n//3)*2+3,\" \").rstrip()for o,i in enumerate(range(1,(n//3)*3,3))for p,j in enumerate(range(i-o,(i-o)+9,3))]+['###'.center((n//3)*2+3).rstrip()]if n>2else'')", "def christmas_tree(height):\n h = height - height % 3\n n, r = h // 3, ''\n sz, l1, l2, l3, k = 5 + (n - 1) * 2, '*', '***', '*****', '\\r\\n'\n w = (sz - len(l1)) // 2\n for i in range(n):\n r += ' ' * w + l1 + k\n r += ' ' * (w-1) + l2 + k \n r += ' ' * (w-2) + l3 + k\n w -= 1\n l1 += '**'\n l2 += '**'\n l3 += '**'\n return r + ' ' * ((sz - 3) // 2) + '###' if height>2 else ''\n", "def christmas_tree(height):\n s = '* *** *****'.split()\n r = []\n for i in range(height//3):\n for x in s:\n r.append(' '*((2*(height//3)+3-2*i-len(x))//2) + '*'*2*i + x)\n return '\\r\\n'.join(r+[' '*(height//3)+'###']) if height//3 else ''", "def christmas_tree(height):\n if height < 3:\n return ''\n res = [1, 3, 5]\n for _ in range((height-3)//3):\n res.extend(res[-2:] + [res[-1]+2])\n w = max(res)\n ans = [('*' * r).center(w).rstrip() for r in res] + ['###'.center(w).rstrip()]\n return '\\r\\n'.join(ans)", "def christmas_tree(h):\n if h < 3: return \"\"\n h, r = h // 3, []\n m = h * 2 + 3\n r = [\"*\" * (2 * (i + j) + 1) for i in range(h) for j in range(3)] + [\"#\" * 3]\n return \"\\r\\n\".join(map(lambda x: x.center(m).rstrip(), r))"] | {"fn_name": "christmas_tree", "inputs": [[5], [10], [8], [2]], "outputs": [[" *\r\n ***\r\n*****\r\n ###"], [" *\r\n ***\r\n *****\r\n ***\r\n *****\r\n *******\r\n *****\r\n *******\r\n*********\r\n ###"], [" *\r\n ***\r\n *****\r\n ***\r\n *****\r\n*******\r\n ###"], [""]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,905 |
def christmas_tree(height):
|
19e71731c9c9c5d3ae60181f82637952 | UNKNOWN | Given a number `n` we will define its scORe to be `0 | 1 | 2 | 3 | ... | n`, where `|` is the [bitwise OR operator](https://en.wikipedia.org/wiki/Bitwise_operation#OR).
Write a function that takes `n` and finds its scORe.
---------------------
| n | scORe n |
|---------|-------- |
| 0 | 0 |
| 1 | 1 |
| 49 | 63 |
| 1000000 | 1048575 |
| ["score=lambda n:2**n.bit_length()-1", "score=lambda n:(1<<n.bit_length())-1", "def score(n):\n # Good Luck!\n return 2**n.bit_length()-1", "def score(n):\n res = n\n while n:\n res, n = res | n, n >> 1\n return res", "def score(n):\n return 0 if n == 0 else n | int(n.bit_length() * '1', 2)", "def score(n):\n return n if n < 2 else pow(2, int(__import__(\"math\").log(n, 2)) + 1) - 1", "from math import log; score=lambda n: 2**int(1+log(n,2))-1 if n else 0", "def score(n):\n return n and 2**(len(bin(n))-2)-1", "from math import ceil,log\ndef score(n):\n return 2**(ceil(log(n,2)))-1 if n>1 else n", "from math import log2, ceil\n\ndef score(n):\n return n if n in (0, 1) else 2 ** (ceil(log2(n))) - 1"] | {"fn_name": "score", "inputs": [[0], [1], [49], [1000000], [10000000], [1000000000000000000]], "outputs": [[0], [1], [63], [1048575], [16777215], [1152921504606846975]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 744 |
def score(n):
|
8efdb5d8d8cf4e01e53f92ce495e2810 | UNKNOWN | In this kata you will have to change every letter in a given string to the next letter in the alphabet. You will write a function `nextLetter` to do this. The function will take a single parameter `s` (string).
Examples:
```
"Hello" --> "Ifmmp"
"What is your name?" --> "Xibu jt zpvs obnf?"
"zoo" --> "app"
"zzZAaa" --> "aaABbb"
```
Note: spaces and special characters should remain the same. Capital letters should transfer in the same way but remain capitilized. | ["def next_letter(string):\n return \"\".join(chr(ord(c)+(-25 if c in 'zZ' else 1)) if c.isalpha() else c for c in string)", "def next_letter(s):\n return s.translate(str.maketrans('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', \n 'bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA'))", "from string import ascii_lowercase as aLow\n\ntr = aLow[1:]+'a'\nTABLE = str.maketrans(aLow+aLow.upper(), tr+tr.upper())\n\ndef next_letter(s): return s.translate(TABLE)", "table = {o+c: c+(o+1)%26 for c in (97, 65) for o in range(26)}\n\ndef next_letter(stg):\n return stg.translate(table)\n\n# one-liner\n#next_letter = lambda stg: stg.translate({o+c: c+(o+1)%26 for c in (97, 65) for o in range(26)})\n", "from string import ascii_lowercase as L, ascii_uppercase as U\n\ndef next_letter(s):\n return s.translate(str.maketrans(L + U, L[1:] + L[0] + U[1:] + U[0]))", "from string import ascii_letters as a, ascii_lowercase as al, ascii_uppercase as au\ndef next_letter(string):\n return string.translate(str.maketrans(a, al[1:] + al[0] + au[1:] + au[0]))", "from string import ascii_lowercase as low, ascii_uppercase as up\n\n\ndef next_letter(s):\n return s.translate(str.maketrans(\n low + up, low[1:] + low[0] + up[1:] + up[0]))\n", "from string import ascii_lowercase as l, ascii_uppercase as u\nnext_letter=lambda s:s.translate(str.maketrans(l+u,l[1:]+l[0]+u[1:]+u[0]))"] | {"fn_name": "next_letter", "inputs": [["Hello"], ["What is your name?"], ["zOo"]], "outputs": [["Ifmmp"], ["Xibu jt zpvs obnf?"], ["aPp"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,405 |
def next_letter(s):
|
de324fd9f4b62ed0dbafde592603d242 | UNKNOWN | You have recently discovered that horses travel in a unique pattern - they're either running (at top speed) or resting (standing still).
Here's an example of how one particular horse might travel:
```
The horse Blaze can run at 14 metres/second for 60 seconds, but must then rest for 45 seconds.
After 500 seconds Blaze will have traveled 4200 metres.
```
Your job is to write a function that returns how long a horse will have traveled after a given time.
####Input:
* totalTime - How long the horse will be traveling (in seconds)
* runTime - How long the horse can run for before having to rest (in seconds)
* restTime - How long the horse have to rest for after running (in seconds)
* speed - The max speed of the horse (in metres/second) | ["def travel(total_time, run_time, rest_time, speed):\n q, r = divmod(total_time, run_time + rest_time)\n return (q * run_time + min(r, run_time)) * speed\n", "def travel(total_time, run_time, rest_time, speed):\n d, m = divmod(total_time, run_time + rest_time)\n return (d * run_time + min(m, run_time)) * speed", "def travel(total_time, run_time, rest_time, speed):\n cycle, left = divmod(total_time, run_time + rest_time)\n return cycle * run_time * speed + min(left, run_time) * speed", "def travel(total_time, run_time, rest_time, speed):\n cycles, remaining = divmod(total_time, run_time + rest_time)\n last_run = min(remaining, run_time)\n return (cycles * run_time + last_run) * speed\n \ndef travel(total, run, rest, speed):\n return ((total // (run + rest)) * run + min(total % (run + rest), run)) * speed", "def travel(total_time, run_time, rest_time, speed):\n return speed*(run_time*((total_time)//(run_time+rest_time))+min(run_time,total_time%(run_time+rest_time)))", "def travel(total_time, run_time, rest_time, speed):\n runs, extra = divmod(total_time, run_time + rest_time)\n \n return (runs * run_time + min(extra, run_time)) * speed", "def travel(total_time, run_time, rest_time, speed):\n x, y = divmod(total_time, run_time + rest_time)\n return (x * run_time + min(y, run_time)) * speed", "def travel(total_time, run_time, rest_time, speed):\n av_speed = (speed * run_time)/(run_time+rest_time)\n av_time = total_time//(run_time+rest_time)\n r_time = (total_time-av_time * (run_time+rest_time))\n return round(av_time*(run_time+rest_time)*av_speed + run_time * speed) if run_time < r_time else round(av_time*(run_time+rest_time)*av_speed + r_time * speed)", "def travel(total_time, run_time, rest_time, speed):\n run_periods = float(total_time) / (run_time + rest_time)\n last_run_time = min(run_periods-int(run_periods), float(run_time)/(run_time + rest_time))*(run_time + rest_time)\n total_run_time = int(run_periods)*run_time + last_run_time\n return round(total_run_time * speed)\n", "def travel(total_time, run_time, rest_time, speed):\n s, is_running = 0, True\n while total_time:\n if is_running:\n s += min(total_time, run_time)*speed\n total_time -= min(total_time,\n run_time) if is_running else min(rest_time, total_time)\n is_running = not is_running\n return s"] | {"fn_name": "travel", "inputs": [[1000, 10, 127, 14], [1000, 10, 0, 10], [25, 50, 120, 18], [35869784, 90, 100, 5], [1234567, 4, 3, 11], [100000000, 21, 5, 14], [0, 100, 10, 14], [250, 0, 5, 14], [100, 10, 0, 14], [500, 100, 10, 0]], "outputs": [[1120], [10000], [450], [84954920], [7760148], [1130769276], [0], [0], [1400], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,435 |
def travel(total_time, run_time, rest_time, speed):
|
a01c2007686c95aa47883032a64309db | UNKNOWN | Sort array by last character
Complete the function to sort a given array or list by last character of elements.
```if-not:haskell
Element can be an integer or a string.
```
### Example:
```
['acvd', 'bcc'] --> ['bcc', 'acvd']
```
The last characters of the strings are `d` and `c`. As `c` comes before `d`, sorting by last character will give `['bcc', 'acvd']`.
If two elements don't differ in the last character, then they should be sorted by the order they come in the array.
```if:haskell
Elements will not be empty (but the list may be).
``` | ["def sort_me(arr):\n return sorted(arr, key=lambda elem: str(elem)[-1])", "def sort_me(arr):\n # Good Luck!\n return sorted(arr, key=lambda x:str(x)[-1])", "def sort_me(xs):\n return sorted(xs, key=lambda x: str(x)[-1])", "def sort_me(a):\n return sorted(a, key=lambda x: str(x)[-1])", "def sort_me(arr):\n return sorted(arr, key=lambda e: str(e)[-1])", "sort_me = lambda arr: sorted(arr, key=lambda x: str(x)[-1])", "def sort_me(arr):\n print((len(arr)))\n a=[str(x) for x in arr]\n print(a)\n b=[x[-1] for (x) in a]\n c=list(zip(arr,b))\n c=sorted(c, key=lambda x: x[1] )\n print(c)\n d=[x[0] for x in c]\n return d\n # Good Luck!\n \n", "sort_me = lambda arr: sorted(arr, key=lambda item: str(item)[-1])", "def sort_me(lst):\n lst.sort(key=lambda a: str(a)[-1])\n return lst\n", "def sort_me(arr):\n return [i[1] for i in sorted([[str(i),i] for i in arr],key=lambda i:i[0][-1])]"] | {"fn_name": "sort_me", "inputs": [[["acvd", "bcc"]], [["14", "13"]], [["asdf", "asdf", "14", "13"]], [["bsde", "asdf", 14, "13"]], [["asdf", 14, "13", "asdf"]]], "outputs": [[["bcc", "acvd"]], [["13", "14"]], [["13", "14", "asdf", "asdf"]], [["13", 14, "bsde", "asdf"]], [["13", 14, "asdf", "asdf"]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 944 |
def sort_me(arr):
|
90a920847668e5eeb47bf59a710d07ed | UNKNOWN | # Task
Christmas is coming. In the [previous kata](https://www.codewars.com/kata/5a405ba4e1ce0e1d7800012e), we build a custom Christmas tree with the specified characters and the specified height.
Now, we are interested in the center of the Christmas tree.
Please imagine that we build a Christmas tree with `chars = "abc" and n = Infinity`, we got:
```
a
b c
a b c
a b c a
b c a b c
a b c a b c
a b c a b c a
b c a b c a b c
a b c a b c a b a
b c a b c a b a b c
a b c a b a b c a b c
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
. . . . . . . . . . .
|
|
.
.
```
If we keep only the center part of leaves, we will got:
```
a
b
a
a
b
a
.
.
.
```
As you can see, it's a infinite string, but it has a repeat substring "aba"(spaces will be removed). If we join them together, it looks like:`"abaabaabaabaaba......"`.
So, your task is to find the repeat substring of the center part of leaves.
# Inputs:
- `chars`: the specified characters. In this kata, they always be lowercase letters.
# Output:
- The repeat substring that satisfy the above conditions.
Still not understand the task? Look at the following example ;-)
# Examples
For `chars = "abc"`,the output should be `"aba"`
```
center leaves sequence: "abaabaabaabaabaaba....."
```
For `chars = "abab"`,the output should be `a`
```
center leaves sequence: "aaaaaaaaaa....."
```
For `chars = "abcde"`,the output should be `aecea`
```
center leaves sequence: "aeceaaeceaaecea....."
```
For `chars = "aaaaaaaaaaaaaa"`,the output should be `a`
```
center leaves sequence: "aaaaaaaaaaaaaa....."
```
For `chars = "abaabaaab"`,the output should be `aba`
```
center leaves sequence: "abaabaabaaba....."
``` | ["def center_of(chars):\n if not chars:\n return \"\"\n total=0\n res=[]\n for i in range(1,len(chars)*2+1): \n if i%2==1:\n res.append((i+1)//2+total)\n res[-1]=chars[(res[-1]-1)%len(chars)]\n total+=i\n res=\"\".join(res)\n for i in range(len(res)//2+1):\n if len(res)%len(res[:i+1])!=0:\n continue\n if res[:i+1]*(len(res)//len(res[:i+1]))==res:\n return res[:i+1]\n return res", "from itertools import count\n\ndef center_of(s):\n if not s: return ''\n seq, le, i = '', len(s), 0\n for k in count(1):\n seq += s[i % le]\n i += 4 * k\n n = len(seq)/3\n if n.is_integer():\n n = int(n)\n if seq[:n] == seq[n:n*2] == seq[n*2:] and i >= le : return seq[:n]", "from collections import deque\nfrom itertools import count, islice\n\ndef iter_center(s):\n q = deque(s)\n for i in count():\n yield q[i % len(q)]\n q.rotate(-3-i*4)\n\ndef find_repeat(g):\n xs = []\n for i in count(1):\n xs.extend(islice(g, 10))\n if all(len(set(xs[j::i])) == 1 for j in range(i)):\n return ''.join(xs[:i])\n\ndef center_of(chars):\n return chars and find_repeat(iter_center(chars))", "from re import sub; center_of=lambda c: sub(r\"^(.+?)\\1*$\",\"\\g<1>\",\"\".join((c+c)[(i*(i*2+1)+i)%len(c)] for i in range(len(c))))", "def center_of(chars):\n if not chars:\n return \"\"\n total=0\n res=[]\n for i in range(1,len(chars)*2+1): \n if i%2==1:\n res.append((i+1)//2+total)\n res[(i-1)//2]=chars[(res[(i-1)//2]-1)%len(chars)]\n total+=i\n check=\"\".join(res)\n for i in range(len(check)//2+1):\n if len(check)%len(check[:i+1])!=0:\n continue\n if check[:i+1]*(len(check)//len(check[:i+1]))==check:\n return check[:i+1]\n return check", "def center_of(chars):\n total=0\n res=[]\n if not chars:\n return \"\"\n for i in range(1,len(chars)*2+1): \n if i%2==1:\n res.append((i+1)//2+total)\n res[(i-1)//2]=chars[((i+1)//2+total-1)%len(chars)]\n total+=i\n if len(set(res))==1: return res[0]\n check=\"\".join(res)\n for i in range(len(check)//2+1):\n if len(check)%len(check[:i+1])!=0:\n continue\n if check[:i+1]*(len(check)//len(check[:i+1]))==check:\n return check[:i+1]\n return check", "def center_of(chars):\n size = len(chars)\n if size == 0:\n return \"\"\n \n size = len(chars)\n center_calc = size * 4\n center = ''\n index_large = 0\n for n in range(center_calc):\n index_large += n * 4\n index = index_large % size\n center += chars[index]\n \n #print(center)\n \n for n in range(1, center_calc):\n if center[:n] == center[n:2*n] and center[n:2*n] == center[2*n:3*n] and center[2*n:3*n] == center[3*n:4*n]:\n return center[:n]\n \n return(center)", "def get_seq(string, slen):\n for i in range(1, slen+1):\n sub = string[:i]\n times = slen // i\n if sub*times == string:\n return sub\n else:\n return False\n\ndef center_of(chars):\n if not chars: return chars\n seq = chars[0]\n chars_len = len(chars)\n\n i = 2\n lcount = 0\n while True:\n if i % 2:\n middle = chars[(lcount + (i // 2)) % chars_len]\n seq += middle\n else:\n lcount += 2*i - 1\n i += 1\n lseq = len(seq)\n if lseq >= chars_len:\n subseq = get_seq(seq, lseq)\n if subseq:\n return subseq\n", "# I like to think of this in terms of math but it's been a while\n# since number theory and modular arithmatic. Looking at this, we\n# get the serries 1, 5, 13, 25, 41,... as we're starting at 0,\n# it's actually 0, 4, 12, 24, 40, ... So this is 4*sum of the first\n# n-1 numbers which gives us the formula of the nth number (starting\n# with 0) is 2n(n+1).\n\n# So the the nth character in the center is 2n(n+1) % len(chars).\n# But this is an infinite serries so I need to know when to stop.\n# If n is odd, then the pattern repeats every n (only half + 1 letters)\n# If n is even, then the pattern repeats ever n/2 generally (sometimes shorter).\n\n# Need to check the final product to make sure that there is no repeat\n# in there as the exceptions in the evens and the characters may not be unique.\ndef center_of(chars):\n center = \"\"\n n = len(chars)\n if n == 0:\n return center\n elif n % 2 == 0:\n n //= 2\n # get the list of character positions\n pos = []\n for i in range(n):\n pos.append(2*i*(i+1) % len(chars))\n # get the characters in the center\n for num in pos:\n center += chars[num]\n # test if there's are repeat in the center\n for i in range(len(center)//2):\n test = center[:i+1]\n if center == test * (len(center)//len(test)):\n center = test\n break \n return center", "def center_of(chars):\n if chars == '':\n return ''\n chars = chars * 10000\n def n_int(n):\n return n*(n+1) // 2\n center = ''\n c = 0\n i= 0\n while n_int(i) <= len(chars):\n if i%2 != 0:\n c += 1\n pos_center = (n_int(i) - c) \n center += chars[pos_center]\n i += 1\n for x in range(1, len(center)):\n subcenter = center[:x]\n if subcenter * (len(center)//len(subcenter))+(subcenter[:len(center)%len(subcenter)]) == center:\n return(subcenter)"] | {"fn_name": "center_of", "inputs": [[""], ["a"], ["ab"], ["abc"], ["abab"], ["abcde"], ["aaaaaaaaaaaaaa"], ["abaabaaab"], ["dbdbebedbddbedededeeddbbdeddbeddeebdeddeebbbb"], ["vttussvutvuvvtustsvsvtvu"]], "outputs": [[""], ["a"], ["a"], ["aba"], ["a"], ["aecea"], ["a"], ["aba"], ["deededebddeebeddeddeddbddeddeddebeeddbededeed"], ["vsvvtvvtvvsv"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 5,700 |
def center_of(chars):
|
765595b31004073fcdedb6d3e5d17526 | UNKNOWN | You will be given an array of positive integers. The array should be sorted by the amount of distinct perfect squares and reversed, that can be generated from each number permuting its digits.
E.g.: ```arr = [715, 112, 136, 169, 144]```
```
Number Perfect Squares w/ its Digits Amount
715 - 0
112 121 1
136 361 1
169 169, 196, 961 3
144 144, 441 2
```
So the output will have the following order:
```[169, 144, 112, 136, 715]```
When we have two or more numbers with the same amount of perfect squares in their permutations, we sorted by their values.
In the example given above, we can see that 112 and 136 both generate a perfect square. So 112 comes first.
Examples for this kata:
```python
sort_by_perfsq([715, 112, 136, 169, 144]) == [169, 144, 112, 136, 715]
# number of perfect squares: 3 2 1 1 0
```
We may have in the array numbers that belongs to the same set of permutations.
```python
sort_by_perfsq([234, 61, 16, 441, 144, 728]) == [144, 441, 16, 61, 234, 728]
# number of perfect squares: 2 2 1 0 0 0
```
Features of the random tests:
~~~if:ruby,python
- Number of tests: 80
- Arrays between 4 and 20 elements
- Integers having from 1 to 7 digits included
~~~
~~~if:js
- Number of tests: 30
- Arrays between 4 and 16 elements
- Integers having from 1 to 7 digits included
~~~
Enjoy it!! | ["from collections import defaultdict\nSQUARES = [x**2 for x in range(1, 3163)]\nDIGITS = defaultdict(int)\nfor sqr in SQUARES:\n DIGITS[''.join(sorted(str(sqr)))] += 1\n\ndef sort_by_perfsq(arr):\n return sorted(arr, key=lambda n: (-DIGITS[''.join(sorted(str(n)))], n))", "from itertools import permutations\n\ndef sort_by_perfsq(lst):\n return sorted(lst, key=perfsq)\n\ndef perfsq(n):\n perm = {int(\"\".join(p)) for p in permutations(str(n))}\n return sum(-1 for n in perm if n**0.5 % 1 == 0), n", "from itertools import permutations\n\nsquare = lambda p: not int(''.join(p))**0.5%1\ncount = lambda num: sum(map(square, set(permutations(str(num)))))\n\ndef sort_by_perfsq(arr):\n return sorted(arr, key=lambda x: (-count(x), x))", "from itertools import permutations\n\ndef sort_by_perfsq(a):\n return [x for _, x in sorted([(-sum(1 for c in set(permutations(str(n))) if (float(''.join(c)) ** 0.5).is_integer()), n) for n in a])]", "from math import sqrt\nfrom itertools import permutations\n\ndef sort_by_perfsq(a):\n return sorted(a, key = lambda n: (-sum(str(sqrt(int(''.join(p))))[-2:] =='.0' for p in set(permutations(str(n), len(str(n))))), n))", "def sort_by_perfsq(arr):\n \n def get_pos_nums(digs, currn=''):\n if len(digs) == 1:\n nums.append(currn + digs[0])\n \n for d in digs:\n locd = digs[:]\n locd.remove(d)\n get_pos_nums(locd, currn + d)\n \n count_sq = []\n \n for x in arr:\n count_sq.append([x, 0])\n\n digs = [d for d in str(x)]\n nums = []\n get_pos_nums(digs)\n nums = set(map(int, nums))\n\n for n in nums:\n if n ** 0.5 % 1 == 0:\n count_sq[-1][1] += 1\n \n count_sq.sort()\n count_sq.sort(key=lambda num: num[1], reverse=True)\n return [num[0] for num in count_sq]\n", "from itertools import permutations\n\ndef sort_by_perfsq(arr):\n isSquare=lambda n: int(n**0.5) == n**0.5\n return sorted(arr, key=lambda n: (sum( isSquare(int(''.join(nS))) for nS in set(permutations(str(n))) ), -n), reverse=True )"] | {"fn_name": "sort_by_perfsq", "inputs": [[[715, 112, 136, 169, 144]], [[234, 61, 16, 441, 144, 728]]], "outputs": [[[169, 144, 112, 136, 715]], [[144, 441, 16, 61, 234, 728]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,149 |
def sort_by_perfsq(arr):
|
54288728a4cbde6bb48d00379319cedb | UNKNOWN | # Task
An IP address contains four numbers(0-255) and separated by dots. It can be converted to a number by this way:
Given a string `s` represents a number or an IP address. Your task is to convert it to another representation(`number to IP address` or `IP address to number`).
You can assume that all inputs are valid.
# Example
Example IP address: `10.0.3.193`
Convert each number to a 8-bit binary string
(may needs to pad leading zeros to the left side):
```
10 --> 00001010
0 --> 00000000
3 --> 00000011
193 --> 11000001
```
Combine these four strings: `00001010 00000000 00000011 11000001` and then convert them to a decimal number:
`167773121`
# Input/Output
`[input]` string `s`
A number or IP address in string format.
`[output]` a string
A converted number or IP address in string format.
# Example
For `s = "10.0.3.193"`, the output should be `"167773121"`.
For `s = "167969729"`, the output should be `"10.3.3.193"`. | ["from ipaddress import IPv4Address\n\ndef numberAndIPaddress(s):\n return str(int(IPv4Address(s))) if '.' in s else str(IPv4Address(int(s)))", "from ipaddress import IPv4Address\n\ndef numberAndIPaddress(string):\n if '.' in string:\n return str(int(IPv4Address(string)))\n return str(IPv4Address(int(string)))", "def numberAndIPaddress(s):\n if '.' in s:\n ans = str(int(''.join(\"{:0>8b}\".format(int(n)) for n in s.split('.')), 2))\n else:\n s32 = \"{:0>32b}\".format(int(s))\n ans = '.'.join(str(int(s32[8*i:8*(i+1)], 2)) for i in range(4))\n return ans", "def numberAndIPaddress(s):\n if \".\" in s:\n binary=\"\".join(\"{:08b}\".format(int(i)) for i in s.split(\".\"))\n return str(int(binary, 2))\n else:\n binary=\"{:032b}\".format(int(s))\n res=[str(int(binary[i:i+8], 2)) for i in range(0, len(binary), 8)]\n return \".\".join(res)", "def ipToNum(ip):\n return str(int(''.join(f'{n:08b}' for n in map(int, ip.split('.'))), 2))\n\ndef numToIp(nums):\n b = f'{int(nums):032b}'\n return '.'.join(map(str, [int(b[i:i+8], 2) for i in (0, 8, 16, 24)]))\n\ndef numberAndIPaddress(s):\n if '.' in s:\n return ipToNum(s)\n elif '.' not in s:\n return numToIp(s)", "def numberAndIPaddress(s):\n ip2num = lambda ip: sum(el * (256 ** (4 - i)) for i, el in enumerate(map(int, ip.split('.')), 1))\n num2ip = lambda n: '.'.join(map(str, [n >> 24, n >> 16 & 255, n >> 8 & 255, n & 255]))\n return str(ip2num(s)) if s.find('.') > 0 else num2ip(int(s))", "def ip_to_int(s):\n return str(int(\"\".join(f\"{int(n):08b}\" for n in s.split(\".\")), 2))\n\ndef int_to_ip(s):\n return \".\".join(str(int(b, 2)) for b in (f\"{int(s):032b}\"[i:i+8] for i in range(0, 32, 8)))\n\ndef numberAndIPaddress(s):\n return ip_to_int(s) if \".\" in s else int_to_ip(s)", "from ipaddress import ip_address\n\ndef numberAndIPaddress(s):\n return str(int(ip_address(s)) if '.' in s else ip_address(int(s)))", "import socket\nimport struct\n\ndef numberAndIPaddress(s):\n if '.' in s:\n return str(struct.unpack('>I', socket.inet_aton(s))[0])\n else:\n return socket.inet_ntoa(struct.pack('>I', int(s)))", "from ipaddress import IPv4Address\ndef numberAndIPaddress(s):\n return str(int(IPv4Address(s)) if '.' in s else IPv4Address(int(s)))"] | {"fn_name": "numberAndIPaddress", "inputs": [["10.0.3.193"], ["167969729"]], "outputs": [["167773121"], ["10.3.3.193"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,374 |
def numberAndIPaddress(s):
|
18ef6e03eb8fd5ec0ea743d434720165 | UNKNOWN | As a strict big brother, I do limit my young brother Vasya on time he spends on computer games. I define a prime-time as a time period till which Vasya have a permission to play computer games. I specify start hour and end hour as pair of integers.
I need a function which will take three numbers - a present moment (current hour), a start hour of allowed time period and an end hour of allowed time period. The function should give answer to a question (as a boolean): "Can Vasya play in specified time?"
If I say that prime-time is from 12 till 15 that means that at 12:00 it's OK to play computer but at 15:00 there should be no more games.
I will allow Vasya to play at least one hour a day. | ["def can_i_play(now_hour, start_hour, end_hour):\n return 0<=(now_hour-start_hour)%24<(end_hour-start_hour)%24\n", "def can_i_play(now_hour, start_hour, end_hour):\n if start_hour < end_hour:\n return start_hour <= now_hour < end_hour\n return start_hour <= now_hour or now_hour < end_hour\n", "def can_i_play(now, start, end):\n if end < start:\n start %= 12\n end += 12\n now = 12 if now == 0 else now % 12\n \n return now >= start and now + 1 <= end", "from datetime import time\ndef can_i_play(now_hour, start_hour, end_hour):\n return end_hour < start_hour <= now_hour or end_hour > now_hour and start_hour > end_hour or start_hour <= now_hour < end_hour\n", "def can_i_play(now_hour, start_hour, end_hour):\n if end_hour < start_hour:\n end_hour += 24\n if now_hour < start_hour:\n now_hour += 24\n return True if now_hour >= start_hour and now_hour < end_hour else False\n", "from operator import and_, or_\ndef can_i_play(now_hour, start_hour, end_hour):\n return (and_, or_)[end_hour < start_hour](start_hour <= now_hour, now_hour < end_hour)", "def can_i_play(now_hour, start_hour, end_hour):\n if end_hour < start_hour: end_hour += 24\n return start_hour<= now_hour < end_hour or start_hour<= now_hour+24 < end_hour\n", "def can_i_play(now,start,end):\n return now in set(list(range(start,25))+list(range(end)) if end<start else range(start,end))", "def can_i_play(now_hour, start_hour, end_hour):\n end = end_hour+24 if start_hour > end_hour else end_hour\n now_hour = now_hour if now_hour >= start_hour else now_hour+24\n return start_hour <= now_hour < end", "def can_i_play(now_hour, start_hour, end_hour):\n\n if start_hour<end_hour:\n \n return start_hour<=now_hour<end_hour\n \n else:\n \n return start_hour<=now_hour or now_hour<end_hour\n"] | {"fn_name": "can_i_play", "inputs": [[9, 10, 11], [12, 12, 13], [13, 10, 15], [14, 9, 14], [15, 8, 12], [20, 21, 1], [21, 21, 6], [17, 15, 3], [0, 22, 1], [1, 22, 1], [3, 23, 2], [20, 0, 23], [14, 2, 9], [9, 20, 11], [23, 23, 0], [11, 2, 9], [0, 20, 23], [4, 0, 3], [6, 2, 10]], "outputs": [[false], [true], [true], [false], [false], [false], [true], [true], [true], [false], [false], [true], [false], [true], [true], [false], [false], [false], [true]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,889 |
def can_i_play(now_hour, start_hour, end_hour):
|
0e9449ca9de6067d91e8d3718614959a | UNKNOWN | ###Task:
You have to write a function **pattern** which returns the following Pattern(See Examples) upto n rows, where n is parameter.
####Rules/Note:
* If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string.
* The length of each line = (2n-1).
* Range of n is (-∞,100]
###Examples:
pattern(5):
12345
12345
12345
12345
12345
pattern(10):
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
1234567890
pattern(15):
123456789012345
123456789012345
123456789012345
123456789012345
123456789012345
123456789012345
123456789012345
123456789012345
123456789012345
123456789012345
123456789012345
123456789012345
123456789012345
123456789012345
123456789012345
pattern(20):
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890
12345678901234567890 | ["def pattern(n):\n nums = '1234567890'\n str_nums = nums*(n//10) + nums[:n%10]\n return '\\n'.join(' '*(n - i - 1) + str_nums + ' '*i for i in range(n))\n", "def pattern(n):\n return \"\\n\".join([(n-1 - i) * \" \" + \"\".join(str(j % 10) for j in range(1, n+1)) + (i * \" \") for i in range(n)])", "def pattern(n):\n s = ''.join(str(i % 10) for i in range(1, n+1))\n return '\\n'.join(' ' * i + s + ' ' * (n - i - 1) for i in range(n-1, -1, -1))", "def pattern(n):\n digits = \"\".join(str(i % 10) for i in range(1, n + 1))\n spaces = \" \" * (n - 1)\n return \"\\n\".join(\"{}{}{}\".format(spaces[i:], digits, spaces[:i]) for i in range(n))", "def pattern(n):\n l = 2*n-1\n base = ''.join(str(x%10) for x in range(1,n+1))\n return '\\n'.join((base + ' '*x).rjust(l) for x in range(n))", "def pattern(n):\n p = ' ' * (n - 1) + ''.join(str(x % 10) for x in range(1, n + 1)) + ' ' * (n - 1)\n return \"\\n\".join(p[x:x + 2 * n - 1] for x in range(n))", "from itertools import cycle, islice\ndef pattern(n):\n return \"\\n\".join([\" \" * (n - x - 1) + \"\".join(islice(cycle(\"1234567890\"), 0, n)) + \" \" * x for x in range(n)])", "def pattern(n):\n digits = ''.join([str(i % 10) for i in range(1,n+1)])\n return '\\n'.join([' ' * (n - 1 -i) + digits + ' ' * i for i in range(n)])", "def pattern(n):\n return \"\\n\".join(\" \"*(n-1-i)+\"\".join([str(i%10) for i in range(1,n+1)])+\" \"*i for i in range(n))\n"] | {"fn_name": "pattern", "inputs": [[3], [5], [8], [-3], [-11], [-25], [0]], "outputs": [[" 123\n 123 \n123 "], [" 12345\n 12345 \n 12345 \n 12345 \n12345 "], [" 12345678\n 12345678 \n 12345678 \n 12345678 \n 12345678 \n 12345678 \n 12345678 \n12345678 "], [""], [""], [""], [""]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,466 |
def pattern(n):
|
bbb3dcd5f6dc49b42b0cec88f025e669 | UNKNOWN | Consider an array that has no prime numbers, and none of its elements has any prime digit. It would start with: `[1,4,6,8,9,10,14,16,18,..]`.
`12` and `15` are not in the list because `2` and `5` are primes.
You will be given an integer `n` and your task will be return the number at that index in the array.
For example:
```
solve(0) = 1
solve(2) = 6
```
More examples in the test cases.
Good luck!
If you like Prime Katas, you will enjoy this Kata: [Simple Prime Streaming](https://www.codewars.com/kata/5a908da30025e995880000e3) | ["n,forbid = 100000, set(\"2357\")\nsieve, notPrimes = [0]*(n+1), [1]\nfor i in range(2, n+1):\n if sieve[i]:\n if not (forbid & set(str(i))): notPrimes.append(i)\n else:\n for j in range(i**2, n+1, i): sieve[j] = 1\n\ndef solve(n): return notPrimes[n]", "solve=lambda n: [1,4,6,8,9,10,14,16,18,40,44,46,48,49,60,64,66,68,69,80,81,84,86,88,90,91,94,96,98,99,100,104,106,108,110,111,114,116,118,119,140,141,144,146,148,160,161,164,166,168,169,180,184,186,188,189,190,194,196,198,400,404,406,408,410,411,414,416,418,440,441,444,446,448,460,464,466,468,469,480,481,484,486,488,489,490,494,496,498,600,604,606,608,609,610,611,614,616,618,640,644,646,648,649,660,664,666,668,669,680,681,684,686,688,689,690,694,696,698,699,800,801,804,806,808,810,814,816,818,819,840,841,844,846,848,849,860,861,864,866,868,869,880,884,886,888,889,890,891,894,896,898,899,900,901,904,906,908,909,910,914,916,918,940,944,946,948,949,960,961,964,966,968,969,980,981,984,986,988,989,990,994,996,998,999,1000,1001,1004,1006,1008,1010,1011,1014,1016,1018,1040,1041,1044,1046,1048,1060,1064,1066,1068,1080,1081,1084,1086,1088,1089,1090,1094,1096,1098,1099,1100,1101,1104,1106,1108,1110,1111,1114,1116,1118,1119,1140,1141,1144,1146,1148,1149,1160,1161,1164,1166,1168,1169,1180,1184,1186,1188,1189,1190,1191,1194,1196,1198,1199,1400,1401,1404,1406,1408,1410,1411,1414,1416,1418,1419,1440,1441,1444,1446,1448,1449,1460,1461,1464,1466,1468,1469,1480,1484,1486,1488,1490,1491,1494,1496,1498,1600,1604,1606,1608,1610,1611,1614,1616,1618,1640,1641,1644,1646,1648,1649,1660,1661,1664,1666,1668,1680,1681,1684,1686,1688,1689,1690,1691,1694,1696,1698,1800,1804,1806,1808,1809,1810,1814,1816,1818,1819,1840,1841,1844,1846,1848,1849,1860,1864,1866,1868,1869,1880,1881,1884,1886,1888,1890,1891,1894,1896,1898,1899,1900,1904,1906,1908,1909,1910,1911,1914,1916,1918,1919,1940,1941,1944,1946,1948,1960,1961,1964,1966,1968,1969,1980,1981,1984,1986,1988,1989,1990,1991,1994,1996,1998,4000,4004,4006,4008,4009,4010,4011,4014,4016,4018,4040,4041,4044,4046,4048,4060,4061,4064,4066,4068,4069,4080,4081,4084,4086,4088,4089,4090,4094,4096,4098,4100,4101,4104,4106,4108,4109,4110,4114,4116,4118,4119,4140,4141,4144,4146,4148,4149,4160,4161,4164,4166,4168,4169,4180,4181,4184,4186,4188,4189,4190,4191,4194,4196,4198,4199,4400,4401,4404,4406,4408,4410,4411,4414,4416,4418,4419,4440,4444,4446,4448,4449,4460,4461,4464,4466,4468,4469,4480,4484,4486,4488,4489,4490,4491,4494,4496,4498,4499,4600,4601,4604,4606,4608,4609,4610,4611,4614,4616,4618,4619,4640,4641,4644,4646,4648,4660,4661,4664,4666,4668,4669,4680,4681,4684,4686,4688,4689,4690,4694,4696,4698,4699,4800,4804,4806,4808,4809,4810,4811,4814,4816,4818,4819,4840,4841,4844,4846,4848,4849,4860,4864,4866,4868,4869,4880,4881,4884,4886,4888,4890,4891,4894,4896,4898,4899,4900,4901,4904,4906,4908,4910,4911,4914,4916,4918,4940,4941,4944,4946,4948,4949,4960,4961,4964,4966,4968,4980,4981,4984,4986,4988,4989,4990,4991,4994,4996,4998,6000,6001,6004,6006,6008,6009,6010,6014,6016,6018,6019,6040,6041,6044,6046,6048,6049,6060,6061,6064,6066,6068,6069,6080,6081,6084,6086,6088,6090,6094,6096,6098,6099,6100,6104,6106,6108,6109,6110,6111,6114,6116,6118,6119,6140,6141,6144,6146,6148,6149,6160,6161,6164,6166,6168,6169,6180,6181,6184,6186,6188,6189,6190,6191,6194,6196,6198,6400,6401,6404,6406,6408,6409,6410,6411,6414,6416,6418,6419,6440,6441,6444,6446,6448,6460,6461,6464,6466,6468,6480,6484,6486,6488,6489,6490,6494,6496,6498,6499,6600,6601,6604,6606,6608,6609,6610,6611,6614,6616,6618,6640,6641,6644,6646,6648,6649,6660,6664,6666,6668,6669,6680,6681,6684,6686,6688,6690,6694,6696,6698,6699,6800,6801,6804,6806,6808,6809,6810,6811,6814,6816,6818,6819,6840,6844,6846,6848,6849,6860,6861,6864,6866,6868,6880,6881,6884,6886,6888,6889,6890,6891,6894,6896,6898,6900,6901,6904,6906,6908,6909,6910,6914,6916,6918,6919,6940,6941,6944,6946,6948,6960,6964,6966,6968,6969,6980,6981,6984,6986,6988,6989,6990,6994,6996,6998,6999,8000,8001,8004,8006,8008,8010,8014,8016,8018,8019,8040,8041,8044,8046,8048,8049,8060,8061,8064,8066,8068,8080,8084,8086,8088,8090,8091,8094,8096,8098,8099,8100,8104,8106,8108,8109,8110,8114,8116,8118,8119,8140,8141,8144,8146,8148,8149,8160,8164,8166,8168,8169,8180,8181,8184,8186,8188,8189,8190,8194,8196,8198,8199,8400,8401,8404,8406,8408,8409,8410,8411,8414,8416,8418,8440,8441,8444,8446,8448,8449,8460,8464,8466,8468,8469,8480,8481,8484,8486,8488,8489,8490,8491,8494,8496,8498,8499,8600,8601,8604,8606,8608,8610,8611,8614,8616,8618,8619,8640,8644,8646,8648,8649,8660,8661,8664,8666,8668,8680,8684,8686,8688,8690,8691,8694,8696,8698,8800,8801,8804,8806,8808,8809,8810,8811,8814,8816,8818,8840,8841,8844,8846,8848,8860,8864,8866,8868,8869,8880,8881,8884,8886,8888,8889,8890,8891,8894,8896,8898,8899,8900,8901,8904,8906,8908,8909,8910,8911,8914,8916,8918,8919,8940,8944,8946,8948,8949,8960,8961,8964,8966,8968,8980,8981,8984,8986,8988,8989,8990,8991,8994,8996,8998,9000,9004,9006,9008,9009,9010,9014,9016,9018,9019,9040,9044,9046,9048,9060,9061,9064,9066,9068,9069,9080,9081,9084,9086,9088,9089,9090,9094,9096,9098,9099,9100,9101,9104,9106,9108,9110,9111,9114,9116,9118,9119,9140,9141,9144,9146,9148,9149,9160,9164,9166,9168,9169,9180,9184,9186,9188,9189,9190,9191,9194,9196,9198,9400,9401,9404,9406,9408,9409,9410,9411,9414,9416,9418,9440,9441,9444,9446,9448,9449,9460,9464,9466,9468,9469,9480,9481,9484,9486,9488,9489,9490,9494,9496,9498,9499,9600,9604,9606,9608,9609,9610,9611,9614,9616,9618,9640,9641,9644,9646,9648,9660,9664,9666,9668,9669,9680,9681,9684,9686,9688,9690,9691,9694,9696,9698,9699,9800,9801,9804,9806,9808,9809,9810,9814,9816,9818,9819,9840,9841,9844,9846,9848,9849,9860,9861,9864,9866,9868,9869,9880,9881,9884,9886,9888,9889,9890,9891,9894,9896,9898,9899,9900,9904,9906,9908,9909,9910,9911,9914,9916,9918,9919,9940,9944,9946,9948,9960,9961,9964,9966,9968,9969,9980,9981,9984,9986,9988,9989,9990,9991,9994,9996,9998,9999,10000,10001,10004,10006,10008,10010,10011,10014,10016,10018,10019,10040,10041,10044,10046,10048,10049,10060,10064,10066,10068,10080,10081,10084,10086,10088,10089,10090,10094,10096,10098,10100,10101,10104,10106,10108,10109,10110,10114,10116,10118,10119,10140,10144,10146,10148,10149,10160,10161,10164,10166,10168,10180,10184,10186,10188,10189,10190,10191,10194,10196,10198,10199,10400,10401,10404,10406,10408,10409,10410,10411,10414,10416,10418,10419,10440,10441,10444,10446,10448,10449,10460,10461,10464,10466,10468,10469,10480,10481,10484,10486,10488,10489,10490,10491,10494,10496,10498,10600,10604,10606,10608,10609,10610,10611,10614,10616,10618,10619,10640,10641,10644,10646,10648,10649,10660,10661,10664,10666,10668,10669,10680,10681,10684,10686,10688,10689,10690,10694,10696,10698,10699,10800,10801,10804,10806,10808,10809,10810,10811,10814,10816,10818,10819,10840,10841,10844,10846,10848,10849,10860,10864,10866,10868,10869,10880,10881,10884,10886,10888,10890,10894,10896,10898,10899,10900,10901,10904,10906,10908,10910,10911,10914,10916,10918,10919,10940,10941,10944,10946,10948,10960,10961,10964,10966,10968,10969,10980,10981,10984,10986,10988,10989,10990,10991,10994,10996,10998,10999,11000,11001,11004,11006,11008,11009,11010,11011,11014,11016,11018,11019,11040,11041,11044,11046,11048,11049,11060,11061,11064,11066,11068,11080,11081,11084,11086,11088,11089,11090,11091,11094,11096,11098,11099,11100,11101,11104,11106,11108,11109,11110,11111,11114,11116,11118,11140,11141,11144,11146,11148,11160,11164,11166,11168,11169,11180,11181,11184,11186,11188,11189,11190,11191,11194,11196,11198,11199,11400,11401,11404,11406,11408,11409,11410,11414,11416,11418,11419,11440,11441,11444,11446,11448,11449,11460,11461,11464,11466,11468,11469,11480,11481,11484,11486,11488,11490,11494,11496,11498,11499,11600,11601,11604,11606,11608,11609,11610,11611,11614,11616,11618,11619,11640,11641,11644,11646,11648,11649,11660,11661,11664,11666,11668,11669,11680,11684,11686,11688,11690,11691,11694,11696,11698,11800,11804,11806,11808,11809,11810,11811,11814,11816,11818,11819,11840,11841,11844,11846,11848,11849,11860,11861,11864,11866,11868,11869,11880,11881,11884,11886,11888,11889,11890,11891,11894,11896,11898,11899,11900,11901,11904,11906,11908,11910,11911,11914,11916,11918,11919,11940,11944,11946,11948,11949,11960,11961,11964,11966,11968,11980,11984,11986,11988,11989,11990,11991,11994,11996,11998,11999,14000,14001,14004,14006,14008,14010,14014,14016,14018,14019,14040,14041,14044,14046,14048,14049,14060,14061,14064,14066,14068,14069,14080,14084,14086,14088,14089,14090,14091,14094,14096,14098,14099,14100,14101,14104,14106,14108,14109,14110,14111,14114,14116,14118,14119,14140,14141,14144,14146,14148,14160,14161,14164,14166,14168,14169,14180,14181,14184,14186,14188,14189,14190,14191,14194,14196,14198,14199,14400,14404,14406,14408,14409,14410,14414,14416,14418,14440,14441,14444,14446,14448,14460,14464,14466,14468,14469,14480,14481,14484,14486,14488,14490,14491,14494,14496,14498,14499,14600,14601,14604,14606,14608,14609,14610,14611,14614,14616,14618,14619,14640,14641,14644,14646,14648,14649,14660,14661,14664,14666,14668,14680,14681,14684,14686,14688,14689,14690,14691,14694,14696,14698,14800,14801,14804,14806,14808,14809,14810,14811,14814,14816,14818,14819,14840,14841,14844,14846,14848,14849,14860,14861,14864,14866,14868,14880,14881,14884,14886,14888,14889,14890,14894,14896,14898,14899,14900,14901,14904,14906,14908,14909,14910,14911,14914,14916,14918,14919,14940,14941,14944,14946,14948,14949,14960,14961,14964,14966,14968,14980,14981,14984,14986,14988,14989,14990,14991,14994,14996,14998,14999,16000,16004,16006,16008,16009,16010,16011,16014,16016,16018,16019,16040,16041,16044,16046,16048,16049,16060,16064,16066,16068,16080,16081,16084,16086,16088,16089,16090,16094,16096,16098,16099,16100,16101,16104,16106,16108,16109,16110,16114,16116,16118,16119,16140,16144,16146,16148,16149,16160,16161,16164,16166,16168,16169,16180,16181,16184,16186,16188,16190,16191,16194,16196,16198,16199,16400,16401,16404,16406,16408,16409,16410,16414,16416,16418,16419,16440,16441,16444,16446,16448,16449,16460,16461,16464,16466,16468,16469,16480,16484,16486,16488,16489,16490,16491,16494,16496,16498,16499,16600,16601,16604,16606,16608,16609,16610,16611,16614,16616,16618,16640,16641,16644,16646,16648,16660,16664,16666,16668,16669,16680,16681,16684,16686,16688,16689,16690,16694,16696,16698,16800,16801,16804,16806,16808,16809,16810,16814,16816,16818,16819,16840,16841,16844,16846,16848,16849,16860,16861,16864,16866,16868,16869,16880,16881,16884,16886,16888,16890,16891,16894,16896,16898,16899,16900,16904,16906,16908,16909,16910,16911,16914,16916,16918,16919,16940,16941,16944,16946,16948,16949,16960,16961,16964,16966,16968,16969,16980,16984,16986,16988,16989,16990,16991,16994,16996,16998,16999,18000,18001,18004,18006,18008,18009,18010,18011,18014,18016,18018,18019,18040,18044,18046,18048,18060,18064,18066,18068,18069,18080,18081,18084,18086,18088,18090,18091,18094,18096,18098,18099,18100,18101,18104,18106,18108,18109,18110,18111,18114,18116,18118,18140,18141,18144,18146,18148,18160,18161,18164,18166,18168,18180,18184,18186,18188,18189,18190,18194,18196,18198,18400,18404,18406,18408,18409,18410,18411,18414,18416,18418,18419,18440,18441,18444,18446,18448,18449,18460,18464,18466,18468,18469,18480,18484,18486,18488,18489,18490,18491,18494,18496,18498,18499,18600,18601,18604,18606,18608,18609,18610,18611,18614,18616,18618,18619,18640,18641,18644,18646,18648,18649,18660,18664,18666,18668,18669,18680,18681,18684,18686,18688,18689,18690,18694,18696,18698,18699,18800,18801,18804,18806,18808,18809,18810,18811,18814,18816,18818,18819,18840,18841,18844,18846,18848,18849,18860,18861,18864,18866,18868,18880,18881,18884,18886,18888,18889,18890,18891,18894,18896,18898,18900,18901,18904,18906,18908,18909,18910,18914,18916,18918,18940,18941,18944,18946,18948,18949,18960,18961,18964,18966,18968,18969,18980,18981,18984,18986,18988,18989,18990,18991,18994,18996,18998,18999,19000,19004,19006,19008,19010,19011,19014,19016,19018,19019,19040,19041,19044,19046,19048,19049,19060,19061,19064,19066,19068,19080,19084,19086,19088,19089,19090,19091,19094,19096,19098,19099,19100,19101,19104,19106,19108,19109,19110,19111,19114,19116,19118,19119,19140,19144,19146,19148,19149,19160,19161,19164,19166,19168,19169,19180,19184,19186,19188,19189,19190,19191,19194,19196,19198,19199,19400,19401,19404,19406,19408,19409,19410,19411,19414,19416,19418,19419,19440,19444,19446,19448,19449,19460,19461,19464,19466,19468,19480,19481,19484,19486,19488,19490,19491,19494,19496,19498,19499,19600,19601,19604,19606,19608,19610,19611,19614,19616,19618,19619,19640,19641,19644,19646,19648,19649,19660,19664,19666,19668,19669,19680,19684,19686,19688,19689,19690,19691,19694,19696,19698,19800,19804,19806,19808,19809,19810,19811,19814,19816,19818,19840,19844,19846,19848,19849,19860,19864,19866,19868,19869,19880,19881,19884,19886,19888,19890,19894,19896,19898,19899,19900,19901,19904,19906,19908,19909,19910,19911,19914,19916,19918,19940,19941,19944,19946,19948,19960,19964,19966,19968,19969,19980,19981,19984,19986,19988,19989,19990,19994,19996,19998,19999,40000,40001,40004,40006,40008,40010,40011,40014,40016,40018,40019,40040,40041,40044,40046,40048,40049,40060,40061,40064,40066,40068,40069,40080,40081,40084,40086,40088,40089,40090,40091,40094,40096,40098,40100,40101,40104,40106,40108,40109,40110,40114,40116,40118,40119,40140,40141,40144,40146,40148,40149,40160,40161,40164,40166,40168,40180,40181,40184,40186,40188,40190,40191,40194,40196,40198,40199,40400,40401,40404,40406,40408,40409,40410,40411,40414,40416,40418,40419,40440,40441,40444,40446,40448,40449,40460,40461,40464,40466,40468,40469,40480,40481,40484,40486,40488,40489,40490,40491,40494,40496,40498,40600,40601,40604,40606,40608,40610,40611,40614,40616,40618,40619,40640,40641,40644,40646,40648,40649,40660,40661,40664,40666,40668,40669,40680,40681,40684,40686,40688,40689,40690,40691,40694,40696,40698,40800,40804,40806,40808,40809,40810,40811,40814,40816,40818,40840,40844,40846,40848,40860,40861,40864,40866,40868,40869,40880,40881,40884,40886,40888,40889,40890,40891,40894,40896,40898,40899,40900,40901,40904,40906,40908,40909,40910,40911,40914,40916,40918,40919,40940,40941,40944,40946,40948,40960,40964,40966,40968,40969,40980,40981,40984,40986,40988,40989,40990,40991,40994,40996,40998,40999,41000,41001,41004,41006,41008,41009,41010,41014,41016,41018,41019,41040,41041,41044,41046,41048,41049,41060,41061,41064,41066,41068,41069,41080,41084,41086,41088,41089,41090,41091,41094,41096,41098,41099,41100,41101,41104,41106,41108,41109,41110,41111,41114,41116,41118,41119,41140,41144,41146,41148,41160,41164,41166,41168,41169,41180,41181,41184,41186,41188,41190,41191,41194,41196,41198,41199,41400,41401,41404,41406,41408,41409,41410,41414,41416,41418,41419,41440,41441,41444,41446,41448,41449,41460,41461,41464,41466,41468,41469,41480,41481,41484,41486,41488,41489,41490,41494,41496,41498,41499,41600,41601,41604,41606,41608,41610,41614,41616,41618,41619,41640,41644,41646,41648,41649,41660,41661,41664,41666,41668,41680,41684,41686,41688,41689,41690,41691,41694,41696,41698,41699,41800,41804,41806,41808,41810,41811,41814,41816,41818,41819,41840,41841,41844,41846,41848,41860,41861,41864,41866,41868,41869,41880,41881,41884,41886,41888,41889,41890,41891,41894,41896,41898,41899,41900,41901,41904,41906,41908,41909,41910,41914,41916,41918,41919,41940,41944,41946,41948,41949,41960,41961,41964,41966,41968,41980,41984,41986,41988,41989,41990,41991,41994,41996,41998,44000,44001,44004,44006,44008,44009,44010,44011,44014,44016,44018,44019,44040,44044,44046,44048,44049,44060,44061,44064,44066,44068,44069,44080,44081,44084,44086,44088,44090,44091,44094,44096,44098,44099,44100,44104,44106,44108,44109,44110,44114,44116,44118,44140,44141,44144,44146,44148,44149,44160,44161,44164,44166,44168,44169,44180,44181,44184,44186,44188,44190,44191,44194,44196,44198,44199,44400,44401,44404,44406,44408,44409,44410,44411,44414,44416,44418,44419,44440,44441,44444,44446,44448,44460,44461,44464,44466,44468,44469,44480,44481,44484,44486,44488,44489,44490,44494,44496,44498,44499,44600,44601,44604,44606,44608,44609,44610,44611,44614,44616,44618,44619,44640,44644,44646,44648,44649,44660,44661,44664,44666,44668,44669,44680,44681,44684,44686,44688,44689,44690,44691,44694,44696,44698,44800,44801,44804,44806,44808,44810,44811,44814,44816,44818,44840,44841,44844,44846,44848,44849,44860,44861,44864,44866,44868,44869,44880,44881,44884,44886,44888,44889,44890,44891,44894,44896,44898,44899,44900,44901,44904,44906,44908,44910,44911,44914,44916,44918,44919,44940,44941,44944,44946,44948,44949,44960,44961,44964,44966,44968,44969,44980,44981,44984,44986,44988,44989,44990,44991,44994,44996,44998,44999,46000,46001,46004,46006,46008,46009,46010,46011,46014,46016,46018,46019,46040,46041,46044,46046,46048,46060,46064,46066,46068,46069,46080,46081,46084,46086,46088,46089,46090,46094,46096,46098,46100,46101,46104,46106,46108,46109,46110,46111,46114,46116,46118,46119,46140,46144,46146,46148,46149,46160,46161,46164,46166,46168,46169,46180,46184,46186,46188,46189,46190,46191,46194,46196,46198,46400,46401,46404,46406,46408,46409,46410,46414,46416,46418,46419,46440,46444,46446,46448,46449,46460,46461,46464,46466,46468,46469,46480,46481,46484,46486,46488,46490,46491,46494,46496,46498,46600,46604,46606,46608,46609,46610,46611,46614,46616,46618,46640,46641,46644,46646,46648,46660,46661,46664,46666,46668,46669,46680,46684,46686,46688,46689,46690,46694,46696,46698,46699,46800,46801,46804,46806,46808,46809,46810,46814,46816,46818,46840,46841,46844,46846,46848,46849,46860,46864,46866,46868,46869,46880,46881,46884,46886,46888,46890,46891,46894,46896,46898,46899,46900,46904,46906,46908,46909,46910,46911,46914,46916,46918,46940,46941,46944,46946,46948,46949,46960,46961,46964,46966,46968,46969,46980,46981,46984,46986,46988,46989,46990,46991,46994,46996,46998,46999,48000,48001,48004,48006,48008,48009,48010,48011,48014,48016,48018,48019,48040,48041,48044,48046,48048,48060,48061,48064,48066,48068,48069,48080,48081,48084,48086,48088,48089,48090,48094,48096,48098,48099,48100,48101,48104,48106,48108,48110,48111,48114,48116,48118,48140,48141,48144,48146,48148,48149,48160,48161,48164,48166,48168,48169,48180,48181,48184,48186,48188,48189,48190,48191,48194,48196,48198,48199,48400,48401,48404,48406,48408,48410,48411,48414,48416,48418,48419,48440,48441,48444,48446,48448,48460,48461,48464,48466,48468,48469,48480,48484,48486,48488,48489,48490,48494,48496,48498,48499,48600,48601,48604,48606,48608,48609,48610,48614,48616,48618,48640,48641,48644,48646,48648,48660,48664,48666,48668,48669,48680,48681,48684,48686,48688,48689,48690,48691,48694,48696,48698,48699,48800,48801,48804,48806,48808,48810,48811,48814,48816,48818,48819,48840,48841,48844,48846,48848,48849,48860,48861,48864,48866,48868,48880,48881,48884,48886,48888,48890,48891,48894,48896,48898,48899,48900,48901,48904,48906,48908,48909,48910,48911,48914,48916,48918,48919,48940,48941,48944,48946,48948,48949,48960,48961,48964,48966,48968,48969,48980,48981,48984,48986,48988,48990,48994,48996,48998,48999,49000,49001,49004,49006,49008,49010,49011,49014,49016,49018,49040,49041,49044,49046,49048,49049,49060,49061,49064,49066,49068,49080,49084,49086,49088,49089,49090,49091,49094,49096,49098,49099,49100,49101,49104,49106,49108,49110,49111,49114,49116,49118,49119,49140,49141,49144,49146,49148,49149,49160,49161,49164,49166,49168,49180,49181,49184,49186,49188,49189,49190,49191,49194,49196,49198,49400,49401,49404,49406,49408,49410,49414,49416,49418,49419,49440,49441,49444,49446,49448,49449,49460,49461,49464,49466,49468,49469,49480,49484,49486,49488,49489,49490,49491,49494,49496,49498,49600,49601,49604,49606,49608,49609,49610,49611,49614,49616,49618,49619,49640,49641,49644,49646,49648,49649,49660,49661,49664,49666,49668,49680,49684,49686,49688,49689,49690,49691,49694,49696,49698,49699,49800,49804,49806,49808,49809,49810,49814,49816,49818,49819,49840,49841,49844,49846,49848,49849,49860,49861,49864,49866,49868,49869,49880,49881,49884,49886,49888,49889,49890,49894,49896,49898,49899,49900,49901,49904,49906,49908,49909,49910,49911,49914,49916,49918,49940,49941,49944,49946,49948,49949,49960,49961,49964,49966,49968,49969,49980,49981,49984,49986,49988,49989,49990,49994,49996,49998][n]", "from itertools import compress\ndef sieve(n): \n n += 1\n r = [False,True] * (n//2) + [True] \n r[1] = False\n r[2] = True \n for i in range(3,int(n**.5)+1,2): \n if r[i]: \n r[i*i::2*i] = [False] * ((n+2*i-1-i*i)//(2*i))\n r = list(compress(range(len(r)),r))\n if r[-1] %2 == 0:\n return r[:-1]\n return r\n\nprimes = set(sieve(10**6))\nres = [] \nfactors = {'2','3','5','7'}\nfor i in range(1,10**6): \n if i not in primes and set(str(i)).isdisjoint(factors): \n res.append(i)\n\ndef solve(n):\n return res[n] ", "limit = 50000\nsieve = [0] * 2 + list(range(2, limit))\nfor i in range(2, limit):\n for j in range(i * i, limit, i):\n sieve[j] = 0\nprimes = {i for i in sieve if i}\np,i,li = ['2', '3', '5', '7'],0,[]\nwhile len(li) <= 3000:\n if i and all(k not in p for k in str(i)) and i not in primes : li.append(i)\n i += 1\nsolve=lambda n:li[n]", "import numpy as np\n\ns = np.ones(100000)\ns[1] = s[4::2] = 0\nfor i in range(3, int(len(s) ** 0.5) + 1, 2):\n if not s[i]:\n continue\n s[i*i::i] = 0\nPRIME_DIGITS = {'2', '3', '5', '7'}\nthe_array = [i for i, x in enumerate(s) if (not x) and PRIME_DIGITS.isdisjoint(str(i))]\n\ndef solve(n):\n return the_array[n]", "from itertools import product\n\nLIMIT = 10**5\nprimes = set(n for n in range(3, LIMIT, 2) if all(n%x for x in range(3, int(n**0.5)+1, 2)))\nnon_primes, digits, n = [], ['14689'], 0\n\nwhile n < LIMIT:\n for n in product(*digits):\n n = int(''.join(n))\n if n not in primes:\n non_primes.append(n)\n digits.append('014689')\n\n\ndef solve(n):\n return non_primes[n]", "from itertools import count\n\nimport numpy as np\n\nprimes = np.ones(1000000)\nprimes[:2] = 0\nfor i in range(2, len(primes)):\n if primes[i]:\n primes[i * i::i] = 0\n\nnon_primes = [1, 4, 6, 8, 9, 10, 14, 16, 18]\ndef gen_non_primes():\n for x in count(non_primes[-1] + 1):\n if primes[x]:\n continue\n s = str(x)\n if '2' in s or '3' in s or '5' in s or '7' in s:\n continue\n non_primes.append(x)\n yield x\n \ndef solve(n):\n if n < len(non_primes):\n return non_primes[n]\n for i, np in enumerate(gen_non_primes(), len(non_primes)):\n if i == n:\n return np", "def solve(n):\n return [1,4,6,8,9,10,14,16,18,40,44,46,48,49,60,64,66,68,69,80,81,84,86,88,90,91,94,96,98,99,100,104,106,108,110,111,114,116,118,119,140,141,144,146,148,160,161,164,166,168,169,180,184,186,188,189,190,194,196,198,400,404,406,408,410,411,414,416,418,440,441,444,446,448,460,464,466,468,469,480,481,484,486,488,489,490,494,496,498,600,604,606,608,609,610,611,614,616,618,640,644,646,648,649,660,664,666,668,669,680,681,684,686,688,689,690,694,696,698,699,800,801,804,806,808,810,814,816,818,819,840,841,844,846,848,849,860,861,864,866,868,869,880,884,886,888,889,890,891,894,896,898,899,900,901,904,906,908,909,910,914,916,918,940,944,946,948,949,960,961,964,966,968,969,980,981,984,986,988,989,990,994,996,998,999,1000,1001,1004,1006,1008,1010,1011,1014,1016,1018,1040,1041,1044,1046,1048,1060,1064,1066,1068,1080,1081,1084,1086,1088,1089,1090,1094,1096,1098,1099,1100,1101,1104,1106,1108,1110,1111,1114,1116,1118,1119,1140,1141,1144,1146,1148,1149,1160,1161,1164,1166,1168,1169,1180,1184,1186,1188,1189,1190,1191,1194,1196,1198,1199,1400,1401,1404,1406,1408,1410,1411,1414,1416,1418,1419,1440,1441,1444,1446,1448,1449,1460,1461,1464,1466,1468,1469,1480,1484,1486,1488,1490,1491,1494,1496,1498,1600,1604,1606,1608,1610,1611,1614,1616,1618,1640,1641,1644,1646,1648,1649,1660,1661,1664,1666,1668,1680,1681,1684,1686,1688,1689,1690,1691,1694,1696,1698,1800,1804,1806,1808,1809,1810,1814,1816,1818,1819,1840,1841,1844,1846,1848,1849,1860,1864,1866,1868,1869,1880,1881,1884,1886,1888,1890,1891,1894,1896,1898,1899,1900,1904,1906,1908,1909,1910,1911,1914,1916,1918,1919,1940,1941,1944,1946,1948,1960,1961,1964,1966,1968,1969,1980,1981,1984,1986,1988,1989,1990,1991,1994,1996,1998,4000,4004,4006,4008,4009,4010,4011,4014,4016,4018,4040,4041,4044,4046,4048,4060,4061,4064,4066,4068,4069,4080,4081,4084,4086,4088,4089,4090,4094,4096,4098,4100,4101,4104,4106,4108,4109,4110,4114,4116,4118,4119,4140,4141,4144,4146,4148,4149,4160,4161,4164,4166,4168,4169,4180,4181,4184,4186,4188,4189,4190,4191,4194,4196,4198,4199,4400,4401,4404,4406,4408,4410,4411,4414,4416,4418,4419,4440,4444,4446,4448,4449,4460,4461,4464,4466,4468,4469,4480,4484,4486,4488,4489,4490,4491,4494,4496,4498,4499,4600,4601,4604,4606,4608,4609,4610,4611,4614,4616,4618,4619,4640,4641,4644,4646,4648,4660,4661,4664,4666,4668,4669,4680,4681,4684,4686,4688,4689,4690,4694,4696,4698,4699,4800,4804,4806,4808,4809,4810,4811,4814,4816,4818,4819,4840,4841,4844,4846,4848,4849,4860,4864,4866,4868,4869,4880,4881,4884,4886,4888,4890,4891,4894,4896,4898,4899,4900,4901,4904,4906,4908,4910,4911,4914,4916,4918,4940,4941,4944,4946,4948,4949,4960,4961,4964,4966,4968,4980,4981,4984,4986,4988,4989,4990,4991,4994,4996,4998,6000,6001,6004,6006,6008,6009,6010,6014,6016,6018,6019,6040,6041,6044,6046,6048,6049,6060,6061,6064,6066,6068,6069,6080,6081,6084,6086,6088,6090,6094,6096,6098,6099,6100,6104,6106,6108,6109,6110,6111,6114,6116,6118,6119,6140,6141,6144,6146,6148,6149,6160,6161,6164,6166,6168,6169,6180,6181,6184,6186,6188,6189,6190,6191,6194,6196,6198,6400,6401,6404,6406,6408,6409,6410,6411,6414,6416,6418,6419,6440,6441,6444,6446,6448,6460,6461,6464,6466,6468,6480,6484,6486,6488,6489,6490,6494,6496,6498,6499,6600,6601,6604,6606,6608,6609,6610,6611,6614,6616,6618,6640,6641,6644,6646,6648,6649,6660,6664,6666,6668,6669,6680,6681,6684,6686,6688,6690,6694,6696,6698,6699,6800,6801,6804,6806,6808,6809,6810,6811,6814,6816,6818,6819,6840,6844,6846,6848,6849,6860,6861,6864,6866,6868,6880,6881,6884,6886,6888,6889,6890,6891,6894,6896,6898,6900,6901,6904,6906,6908,6909,6910,6914,6916,6918,6919,6940,6941,6944,6946,6948,6960,6964,6966,6968,6969,6980,6981,6984,6986,6988,6989,6990,6994,6996,6998,6999,8000,8001,8004,8006,8008,8010,8014,8016,8018,8019,8040,8041,8044,8046,8048,8049,8060,8061,8064,8066,8068,8080,8084,8086,8088,8090,8091,8094,8096,8098,8099,8100,8104,8106,8108,8109,8110,8114,8116,8118,8119,8140,8141,8144,8146,8148,8149,8160,8164,8166,8168,8169,8180,8181,8184,8186,8188,8189,8190,8194,8196,8198,8199,8400,8401,8404,8406,8408,8409,8410,8411,8414,8416,8418,8440,8441,8444,8446,8448,8449,8460,8464,8466,8468,8469,8480,8481,8484,8486,8488,8489,8490,8491,8494,8496,8498,8499,8600,8601,8604,8606,8608,8610,8611,8614,8616,8618,8619,8640,8644,8646,8648,8649,8660,8661,8664,8666,8668,8680,8684,8686,8688,8690,8691,8694,8696,8698,8800,8801,8804,8806,8808,8809,8810,8811,8814,8816,8818,8840,8841,8844,8846,8848,8860,8864,8866,8868,8869,8880,8881,8884,8886,8888,8889,8890,8891,8894,8896,8898,8899,8900,8901,8904,8906,8908,8909,8910,8911,8914,8916,8918,8919,8940,8944,8946,8948,8949,8960,8961,8964,8966,8968,8980,8981,8984,8986,8988,8989,8990,8991,8994,8996,8998,9000,9004,9006,9008,9009,9010,9014,9016,9018,9019,9040,9044,9046,9048,9060,9061,9064,9066,9068,9069,9080,9081,9084,9086,9088,9089,9090,9094,9096,9098,9099,9100,9101,9104,9106,9108,9110,9111,9114,9116,9118,9119,9140,9141,9144,9146,9148,9149,9160,9164,9166,9168,9169,9180,9184,9186,9188,9189,9190,9191,9194,9196,9198,9400,9401,9404,9406,9408,9409,9410,9411,9414,9416,9418,9440,9441,9444,9446,9448,9449,9460,9464,9466,9468,9469,9480,9481,9484,9486,9488,9489,9490,9494,9496,9498,9499,9600,9604,9606,9608,9609,9610,9611,9614,9616,9618,9640,9641,9644,9646,9648,9660,9664,9666,9668,9669,9680,9681,9684,9686,9688,9690,9691,9694,9696,9698,9699,9800,9801,9804,9806,9808,9809,9810,9814,9816,9818,9819,9840,9841,9844,9846,9848,9849,9860,9861,9864,9866,9868,9869,9880,9881,9884,9886,9888,9889,9890,9891,9894,9896,9898,9899,9900,9904,9906,9908,9909,9910,9911,9914,9916,9918,9919,9940,9944,9946,9948,9960,9961,9964,9966,9968,9969,9980,9981,9984,9986,9988,9989,9990,9991,9994,9996,9998,9999,10000,10001,10004,10006,10008,10010,10011,10014,10016,10018,10019,10040,10041,10044,10046,10048,10049,10060,10064,10066,10068,10080,10081,10084,10086,10088,10089,10090,10094,10096,10098,10100,10101,10104,10106,10108,10109,10110,10114,10116,10118,10119,10140,10144,10146,10148,10149,10160,10161,10164,10166,10168,10180,10184,10186,10188,10189,10190,10191,10194,10196,10198,10199,10400,10401,10404,10406,10408,10409,10410,10411,10414,10416,10418,10419,10440,10441,10444,10446,10448,10449,10460,10461,10464,10466,10468,10469,10480,10481,10484,10486,10488,10489,10490,10491,10494,10496,10498,10600,10604,10606,10608,10609,10610,10611,10614,10616,10618,10619,10640,10641,10644,10646,10648,10649,10660,10661,10664,10666,10668,10669,10680,10681,10684,10686,10688,10689,10690,10694,10696,10698,10699,10800,10801,10804,10806,10808,10809,10810,10811,10814,10816,10818,10819,10840,10841,10844,10846,10848,10849,10860,10864,10866,10868,10869,10880,10881,10884,10886,10888,10890,10894,10896,10898,10899,10900,10901,10904,10906,10908,10910,10911,10914,10916,10918,10919,10940,10941,10944,10946,10948,10960,10961,10964,10966,10968,10969,10980,10981,10984,10986,10988,10989,10990,10991,10994,10996,10998,10999,11000,11001,11004,11006,11008,11009,11010,11011,11014,11016,11018,11019,11040,11041,11044,11046,11048,11049,11060,11061,11064,11066,11068,11080,11081,11084,11086,11088,11089,11090,11091,11094,11096,11098,11099,11100,11101,11104,11106,11108,11109,11110,11111,11114,11116,11118,11140,11141,11144,11146,11148,11160,11164,11166,11168,11169,11180,11181,11184,11186,11188,11189,11190,11191,11194,11196,11198,11199,11400,11401,11404,11406,11408,11409,11410,11414,11416,11418,11419,11440,11441,11444,11446,11448,11449,11460,11461,11464,11466,11468,11469,11480,11481,11484,11486,11488,11490,11494,11496,11498,11499,11600,11601,11604,11606,11608,11609,11610,11611,11614,11616,11618,11619,11640,11641,11644,11646,11648,11649,11660,11661,11664,11666,11668,11669,11680,11684,11686,11688,11690,11691,11694,11696,11698,11800,11804,11806,11808,11809,11810,11811,11814,11816,11818,11819,11840,11841,11844,11846,11848,11849,11860,11861,11864,11866,11868,11869,11880,11881,11884,11886,11888,11889,11890,11891,11894,11896,11898,11899,11900,11901,11904,11906,11908,11910,11911,11914,11916,11918,11919,11940,11944,11946,11948,11949,11960,11961,11964,11966,11968,11980,11984,11986,11988,11989,11990,11991,11994,11996,11998,11999,14000,14001,14004,14006,14008,14010,14014,14016,14018,14019,14040,14041,14044,14046,14048,14049,14060,14061,14064,14066,14068,14069,14080,14084,14086,14088,14089,14090,14091,14094,14096,14098,14099,14100,14101,14104,14106,14108,14109,14110,14111,14114,14116,14118,14119,14140,14141,14144,14146,14148,14160,14161,14164,14166,14168,14169,14180,14181,14184,14186,14188,14189,14190,14191,14194,14196,14198,14199,14400,14404,14406,14408,14409,14410,14414,14416,14418,14440,14441,14444,14446,14448,14460,14464,14466,14468,14469,14480,14481,14484,14486,14488,14490,14491,14494,14496,14498,14499,14600,14601,14604,14606,14608,14609,14610,14611,14614,14616,14618,14619,14640,14641,14644,14646,14648,14649,14660,14661,14664,14666,14668,14680,14681,14684,14686,14688,14689,14690,14691,14694,14696,14698,14800,14801,14804,14806,14808,14809,14810,14811,14814,14816,14818,14819,14840,14841,14844,14846,14848,14849,14860,14861,14864,14866,14868,14880,14881,14884,14886,14888,14889,14890,14894,14896,14898,14899,14900,14901,14904,14906,14908,14909,14910,14911,14914,14916,14918,14919,14940,14941,14944,14946,14948,14949,14960,14961,14964,14966,14968,14980,14981,14984,14986,14988,14989,14990,14991,14994,14996,14998,14999,16000,16004,16006,16008,16009,16010,16011,16014,16016,16018,16019,16040,16041,16044,16046,16048,16049,16060,16064,16066,16068,16080,16081,16084,16086,16088,16089,16090,16094,16096,16098,16099,16100,16101,16104,16106,16108,16109,16110,16114,16116,16118,16119,16140,16144,16146,16148,16149,16160,16161,16164,16166,16168,16169,16180,16181,16184,16186,16188,16190,16191,16194,16196,16198,16199,16400,16401,16404,16406,16408,16409,16410,16414,16416,16418,16419,16440,16441,16444,16446,16448,16449,16460,16461,16464,16466,16468,16469,16480,16484,16486,16488,16489,16490,16491,16494,16496,16498,16499,16600,16601,16604,16606,16608,16609,16610,16611,16614,16616,16618,16640,16641,16644,16646,16648,16660,16664,16666,16668,16669,16680,16681,16684,16686,16688,16689,16690,16694,16696,16698,16800,16801,16804,16806,16808,16809,16810,16814,16816,16818,16819,16840,16841,16844,16846,16848,16849,16860,16861,16864,16866,16868,16869,16880,16881,16884,16886,16888,16890,16891,16894,16896,16898,16899,16900,16904,16906,16908,16909,16910,16911,16914,16916,16918,16919,16940,16941,16944,16946,16948,16949,16960,16961,16964,16966,16968,16969,16980,16984,16986,16988,16989,16990,16991,16994,16996,16998,16999,18000,18001,18004,18006,18008,18009,18010,18011,18014,18016,18018,18019,18040,18044,18046,18048,18060,18064,18066,18068,18069,18080,18081,18084,18086,18088,18090,18091,18094,18096,18098,18099,18100,18101,18104,18106,18108,18109,18110,18111,18114,18116,18118,18140,18141,18144,18146,18148,18160,18161,18164,18166,18168,18180,18184,18186,18188,18189,18190,18194,18196,18198,18400,18404,18406,18408,18409,18410,18411,18414,18416,18418,18419,18440,18441,18444,18446,18448,18449,18460,18464,18466,18468,18469,18480,18484,18486,18488,18489,18490,18491,18494,18496,18498,18499,18600,18601,18604,18606,18608,18609,18610,18611,18614,18616,18618,18619,18640,18641,18644,18646,18648,18649,18660,18664,18666,18668,18669,18680,18681,18684,18686,18688,18689,18690,18694,18696,18698,18699,18800,18801,18804,18806,18808,18809,18810,18811,18814,18816,18818,18819,18840,18841,18844,18846,18848,18849,18860,18861,18864,18866,18868,18880,18881,18884,18886,18888,18889,18890,18891,18894,18896,18898,18900,18901,18904,18906,18908,18909,18910,18914,18916,18918,18940,18941,18944,18946,18948,18949,18960,18961,18964,18966,18968,18969,18980,18981,18984,18986,18988,18989,18990,18991,18994,18996,18998,18999,19000,19004,19006,19008,19010,19011,19014,19016,19018,19019,19040,19041,19044,19046,19048,19049,19060,19061,19064,19066,19068,19080,19084,19086,19088,19089,19090,19091,19094,19096,19098,19099,19100,19101,19104,19106,19108,19109,19110,19111,19114,19116,19118,19119,19140,19144,19146,19148,19149,19160,19161,19164,19166,19168,19169,19180,19184,19186,19188,19189,19190,19191,19194,19196,19198,19199,19400,19401,19404,19406,19408,19409,19410,19411,19414,19416,19418,19419,19440,19444,19446,19448,19449,19460,19461,19464,19466,19468,19480,19481,19484,19486,19488,19490,19491,19494,19496,19498,19499,19600,19601,19604,19606,19608,19610,19611,19614,19616,19618,19619,19640,19641,19644,19646,19648,19649,19660,19664,19666,19668,19669,19680,19684,19686,19688,19689,19690,19691,19694,19696,19698,19800,19804,19806,19808,19809,19810,19811,19814,19816,19818,19840,19844,19846,19848,19849,19860,19864,19866,19868,19869,19880,19881,19884,19886,19888,19890,19894,19896,19898,19899,19900,19901,19904,19906,19908,19909,19910,19911,19914,19916,19918,19940,19941,19944,19946,19948,19960,19964,19966,19968,19969,19980,19981,19984,19986,19988,19989,19990,19994,19996,19998,19999,40000,40001,40004,40006,40008,40010,40011,40014,40016,40018,40019,40040,40041,40044,40046,40048,40049,40060,40061,40064,40066,40068,40069,40080,40081,40084,40086,40088,40089,40090,40091,40094,40096,40098,40100,40101,40104,40106,40108,40109,40110,40114,40116,40118,40119,40140,40141,40144,40146,40148,40149,40160,40161,40164,40166,40168,40180,40181,40184,40186,40188,40190,40191,40194,40196,40198,40199,40400,40401,40404,40406,40408,40409,40410,40411,40414,40416,40418,40419,40440,40441,40444,40446,40448,40449,40460,40461,40464,40466,40468,40469,40480,40481,40484,40486,40488,40489,40490,40491,40494,40496,40498,40600,40601,40604,40606,40608,40610,40611,40614,40616,40618,40619,40640,40641,40644,40646,40648,40649,40660,40661,40664,40666,40668,40669,40680,40681,40684,40686,40688,40689,40690,40691,40694,40696,40698,40800,40804,40806,40808,40809,40810,40811,40814,40816,40818,40840,40844,40846,40848,40860,40861,40864,40866,40868,40869,40880,40881,40884,40886,40888,40889,40890,40891,40894,40896,40898,40899,40900,40901,40904,40906,40908,40909,40910,40911,40914,40916,40918,40919,40940,40941,40944,40946,40948,40960,40964,40966,40968,40969,40980,40981,40984,40986,40988,40989,40990,40991,40994,40996,40998,40999,41000,41001,41004,41006,41008,41009,41010,41014,41016,41018,41019,41040,41041,41044,41046,41048,41049,41060,41061,41064,41066,41068,41069,41080,41084,41086,41088,41089,41090,41091,41094,41096,41098,41099,41100,41101,41104,41106,41108,41109,41110,41111,41114,41116,41118,41119,41140,41144,41146,41148,41160,41164,41166,41168,41169,41180,41181,41184,41186,41188,41190,41191,41194,41196,41198,41199,41400,41401,41404,41406,41408,41409,41410,41414,41416,41418,41419,41440,41441,41444,41446,41448,41449,41460,41461,41464,41466,41468,41469,41480,41481,41484,41486,41488,41489,41490,41494,41496,41498,41499,41600,41601,41604,41606,41608,41610,41614,41616,41618,41619,41640,41644,41646,41648,41649,41660,41661,41664,41666,41668,41680,41684,41686,41688,41689,41690,41691,41694,41696,41698,41699,41800,41804,41806,41808,41810,41811,41814,41816,41818,41819,41840,41841,41844,41846,41848,41860,41861,41864,41866,41868,41869,41880,41881,41884,41886,41888,41889,41890,41891,41894,41896,41898,41899,41900,41901,41904,41906,41908,41909,41910,41914,41916,41918,41919,41940,41944,41946,41948,41949,41960,41961,41964,41966,41968,41980,41984,41986,41988,41989,41990,41991,41994,41996,41998,44000,44001,44004,44006,44008,44009,44010,44011,44014,44016,44018,44019,44040,44044,44046,44048,44049,44060,44061,44064,44066,44068,44069,44080,44081,44084,44086,44088,44090,44091,44094,44096,44098,44099,44100,44104,44106,44108,44109,44110,44114,44116,44118,44140,44141,44144,44146,44148,44149,44160,44161,44164,44166,44168,44169,44180,44181,44184,44186,44188,44190,44191,44194,44196,44198,44199,44400,44401,44404,44406,44408,44409,44410,44411,44414,44416,44418,44419,44440,44441,44444,44446,44448,44460,44461,44464,44466,44468,44469,44480,44481,44484,44486,44488,44489,44490,44494,44496,44498,44499,44600,44601,44604,44606,44608,44609,44610,44611,44614,44616,44618,44619,44640,44644,44646,44648,44649,44660,44661,44664,44666,44668,44669,44680,44681,44684,44686,44688,44689,44690,44691,44694,44696,44698,44800,44801,44804,44806,44808,44810,44811,44814,44816,44818,44840,44841,44844,44846,44848,44849,44860,44861,44864,44866,44868,44869,44880,44881,44884,44886,44888,44889,44890,44891,44894,44896,44898,44899,44900,44901,44904,44906,44908,44910,44911,44914,44916,44918,44919,44940,44941,44944,44946,44948,44949,44960,44961,44964,44966,44968,44969,44980,44981,44984,44986,44988,44989,44990,44991,44994,44996,44998,44999,46000,46001,46004,46006,46008,46009,46010,46011,46014,46016,46018,46019,46040,46041,46044,46046,46048,46060,46064,46066,46068,46069,46080,46081,46084,46086,46088,46089,46090,46094,46096,46098,46100,46101,46104,46106,46108,46109,46110,46111,46114,46116,46118,46119,46140,46144,46146,46148,46149,46160,46161,46164,46166,46168,46169,46180,46184,46186,46188,46189,46190,46191,46194,46196,46198,46400,46401,46404,46406,46408,46409,46410,46414,46416,46418,46419,46440,46444,46446,46448,46449,46460,46461,46464,46466,46468,46469,46480,46481,46484,46486,46488,46490,46491,46494,46496,46498,46600,46604,46606,46608,46609,46610,46611,46614,46616,46618,46640,46641,46644,46646,46648,46660,46661,46664,46666,46668,46669,46680,46684,46686,46688,46689,46690,46694,46696,46698,46699,46800,46801,46804,46806,46808,46809,46810,46814,46816,46818,46840,46841,46844,46846,46848,46849,46860,46864,46866,46868,46869,46880,46881,46884,46886,46888,46890,46891,46894,46896,46898,46899,46900,46904,46906,46908,46909,46910,46911,46914,46916,46918,46940,46941,46944,46946,46948,46949,46960,46961,46964,46966,46968,46969,46980,46981,46984,46986,46988,46989,46990,46991,46994,46996,46998,46999,48000,48001,48004,48006,48008,48009,48010,48011,48014,48016,48018,48019,48040,48041,48044,48046,48048,48060,48061,48064,48066,48068,48069,48080,48081,48084,48086,48088,48089,48090,48094,48096,48098,48099,48100,48101,48104,48106,48108,48110,48111,48114,48116,48118,48140,48141,48144,48146,48148,48149,48160,48161,48164,48166,48168,48169,48180,48181,48184,48186,48188,48189,48190,48191,48194,48196,48198,48199,48400,48401,48404,48406,48408,48410,48411,48414,48416,48418,48419,48440,48441,48444,48446,48448,48460,48461,48464,48466,48468,48469,48480,48484,48486,48488,48489,48490,48494,48496,48498,48499,48600,48601,48604,48606,48608,48609,48610,48614,48616,48618,48640,48641,48644,48646,48648,48660,48664,48666,48668,48669,48680,48681,48684,48686,48688,48689,48690,48691,48694,48696,48698,48699,48800,48801,48804,48806,48808,48810,48811,48814,48816,48818,48819,48840,48841,48844,48846,48848,48849,48860,48861,48864,48866,48868,48880,48881,48884,48886,48888,48890,48891,48894,48896,48898,48899,48900,48901,48904,48906,48908,48909,48910,48911,48914,48916,48918,48919,48940,48941,48944,48946,48948,48949,48960,48961,48964,48966,48968,48969,48980,48981,48984,48986,48988,48990,48994,48996,48998,48999,49000,49001,49004,49006,49008,49010,49011,49014,49016,49018,49040,49041,49044,49046,49048,49049,49060,49061,49064,49066,49068,49080,49084,49086,49088,49089,49090,49091,49094,49096,49098,49099,49100,49101,49104,49106,49108,49110,49111,49114,49116,49118,49119,49140,49141,49144,49146,49148,49149,49160,49161,49164,49166,49168,49180,49181,49184,49186,49188,49189,49190,49191,49194,49196,49198,49400,49401,49404,49406,49408,49410,49414,49416,49418,49419,49440,49441,49444,49446,49448,49449,49460,49461,49464,49466,49468,49469,49480,49484,49486,49488,49489,49490,49491,49494,49496,49498,49600,49601,49604,49606,49608,49609,49610,49611,49614,49616,49618,49619,49640,49641,49644,49646,49648,49649,49660,49661,49664,49666,49668,49680,49684,49686,49688,49689,49690,49691,49694,49696,49698,49699,49800,49804,49806,49808,49809,49810,49814,49816,49818,49819,49840,49841,49844,49846,49848,49849,49860,49861,49864,49866,49868,49869,49880,49881,49884,49886,49888,49889,49890,49894,49896,49898,49899,49900,49901,49904,49906,49908,49909,49910,49911,49914,49916,49918,49940,49941,49944,49946,49948,49949,49960,49961,49964,49966,49968,49969,49980,49981,49984,49986,49988,49989,49990,49994,49996,49998][n]", "def is_prime(n):\n if n<2:\n return False\n elif n==2:\n return True\n elif n%2==0:\n return False\n x=3\n while(x*x<=n):\n if n%x==0:\n return False\n x+=2\n return True\n\np=[x for x in range(1,50001) if not is_prime(x) and all(d not in '2357' for d in str(x))]\n\ndef solve(n):\n return p[n]", "from itertools import compress\ndef sieve(n): \n n += 1\n r = [False,True] * (n//2) + [True] \n r[1] = False\n r[2] = True \n for i in range(3,int(n**.5)+1,2): \n if r[i]: \n r[i*i::2*i] = [False] * ((n+2*i-1-i*i)//(2*i))\n r = list(compress(list(range(len(r))),r))\n if r[-1] %2 == 0:\n return r[:-1]\n return r\n\ndef test(num):\n num = str(num)\n for i in num:\n if int(i) in (2,3,5,7): \n return False\n return True \n\nprimes = set(sieve(10**6))\nres = [] \nfor i in range(1,10**6): \n if i not in primes and test(i): \n res.append(i)\n\ndef solve(n):\n return res[n] \n\n"] | {"fn_name": "solve", "inputs": [[10], [50], [100], [150], [200], [300], [400], [500], [1000], [2000], [3000]], "outputs": [[44], [169], [644], [896], [1060], [1668], [4084], [4681], [9110], [18118], [46166]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 43,423 |
def solve(n):
|
e024c2292ce03547403ea28659831741 | UNKNOWN | Your task is to sort a given string. Each word in the string will contain a single number. This number is the position the word should have in the result.
Note: Numbers can be from 1 to 9. So 1 will be the first word (not 0).
If the input string is empty, return an empty string.
The words in the input String will only contain valid consecutive numbers.
## Examples
```
"is2 Thi1s T4est 3a" --> "Thi1s is2 3a T4est"
"4of Fo1r pe6ople g3ood th5e the2" --> "Fo1r the2 g3ood 4of th5e pe6ople"
"" --> ""
``` | ["def order(sentence):\n return \" \".join(sorted(sentence.split(), key=lambda x: int(\"\".join(filter(str.isdigit, x)))))\n", "def order(words):\n return ' '.join(sorted(words.split(), key=lambda w:sorted(w)))", "def order(sentence):\n if not sentence:\n return \"\"\n result = [] #the list that will eventually become our setence\n \n split_up = sentence.split() #the original sentence turned into a list\n \n for i in range(1,10):\n for item in split_up:\n if str(i) in item:\n result.append(item) #adds them in numerical order since it cycles through i first\n \n return \" \".join(result)", "def extract_number(word):\n for l in word: \n if l.isdigit(): return int(l)\n return None\n\ndef order(sentence):\n return ' '.join(sorted(sentence.split(), key=extract_number))\n", "def order(s):\n z = []\n for i in range(1,10):\n for j in list(s.split()):\n if str(i) in j:\n z.append(j)\n return \" \".join(z)", "import re\n\n\nclass Word(object):\n\n digit_regex = re.compile(r'[0-9]')\n\n def __init__(self, word):\n self._index = self.digit_regex.findall(word)[0]\n self._word = word\n \n def __repr__(self):\n return self._word\n \n @property\n def word(self):\n return self._word\n \n @property\n def index(self):\n return self._index\n\n\nclass Sentence(object):\n \n def __init__(self, words):\n self._words = words\n \n def __repr__(self):\n return ' '.join([str(x) for x in self.ordered()])\n \n def ordered(self):\n return sorted(self._words, key=lambda word: word.index)\n\ndef order(sentence):\n return str(Sentence(list(map(Word, sentence.split()))))\n", "order = lambda xs: ' '.join(sorted(xs.split(), key=min))", "def order(sentence):\n def sort_key(s):\n return next(c for c in s if c.isdigit())\n return ' '.join(sorted(sentence.split(), key=sort_key))", "def order(sentence):\n data = sentence.split()\n\n result = []\n\n for word in data:\n for letter in word:\n if letter.isdigit():\n result.append([int(letter), word])\n\n return \" \".join([x[1] for x in sorted(result)])", "import re\ndef order(sentence):\n string_final = ''\n if sentence == '':\n return sentence\n lista = sentence.split()\n posicao=1\n while posicao <= len(lista):\n for i in range(len(lista)):\n if re.findall('\\d+', lista[i]) == [str(posicao)]:\n string_final = string_final + lista[i] + ' '\n break\n posicao+=1\n return string_final[:-1]\n"] | {"fn_name": "order", "inputs": [["is2 Thi1s T4est 3a"], ["4of Fo1r pe6ople g3ood th5e the2"], ["d4o dru7nken sh2all w5ith s8ailor wha1t 3we a6"], [""], ["3 6 4 2 8 7 5 1 9"]], "outputs": [["Thi1s is2 3a T4est"], ["Fo1r the2 g3ood 4of th5e pe6ople"], ["wha1t sh2all 3we d4o w5ith a6 dru7nken s8ailor"], [""], ["1 2 3 4 5 6 7 8 9"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,664 |
def order(sentence):
|
c5b0e52dd84b39ea6db077d9b2716382 | UNKNOWN | Lucy loves to travel. Luckily she is a renowned computer scientist and gets to travel to international conferences using her department's budget.
Each year, Society for Exciting Computer Science Research (SECSR) organizes several conferences around the world. Lucy always picks one conference from that list that is hosted in a city she hasn't been to before, and if that leaves her with more than one option, she picks the conference that she thinks would be most relevant for her field of research.
Write a function `conferencePicker` that takes in two arguments:
- `citiesVisited`, a list of cities that Lucy has visited before, given as an array of strings.
- `citiesOffered`, a list of cities that will host SECSR conferences this year, given as an array of strings. `citiesOffered` will already be ordered in terms of the relevance of the conferences for Lucy's research (from the most to the least relevant).
The function should return the city that Lucy should visit, as a string.
Also note:
- You should allow for the possibility that Lucy hasn't visited any city before.
- SECSR organizes at least two conferences each year.
- If all of the offered conferences are hosted in cities that Lucy has visited before, the function should return `'No worthwhile conferences this year!'` (`Nothing` in Haskell)
Example: | ["def conference_picker(cities_visited, cities_offered):\n for city in cities_offered:\n if city not in cities_visited:\n return city\n return 'No worthwhile conferences this year!'", "def conference_picker(visited, offered):\n visited = set(visited)\n return next((city for city in offered if city not in visited),\n 'No worthwhile conferences this year!')\n", "def conference_picker(cities_visited, cities_offered):\n \n visited = frozenset(cities_visited)\n \n for city in cities_offered:\n if city not in visited:\n return city\n \n return 'No worthwhile conferences this year!'", "def conference_picker(visited, offered):\n return [city for city in (offered + [\"No worthwhile conferences this year!\"]) if city not in visited][0]", "def conference_picker(cities_visited, cities_offered):\n for city in cities_offered:\n if not city in cities_visited:\n return city\n return 'No worthwhile conferences this year!'", "def conference_picker(arr1,arr2):\n L=[]\n for i in arr2:\n if i not in arr1:\n return i\n L.append(i)\n if L==[]:\n return 'No worthwhile conferences this year!'", "def conference_picker(cities_visited, cities_offered):\n picks = (city for city in cities_offered if city not in set(cities_visited))\n try:\n return next(picks)\n except StopIteration:\n return 'No worthwhile conferences this year!'", "def conference_picker(visited, offered):\n options = [c for c in offered if c not in visited]\n return options[0] if options else 'No worthwhile conferences this year!'", "def conference_picker(cities_visited, cities_offered):\n return next((c for c in cities_offered if c not in cities_visited), 'No worthwhile conferences this year!')", "def conference_picker(cities_visited, cities_offered):\n return next((city for city in cities_offered if not city in cities_visited), \"No worthwhile conferences this year!\")", "def conference_picker(cities_visited, cities_offered):\n\n SECSR = list(cities_visited)\n confPicker = list(cities_offered)\n shortList = list()\n for city in confPicker:\n if city not in SECSR:\n shortList.append(city) \n else:\n pass \n if len(shortList) > 0:\n return shortList[0]\n else:\n return 'No worthwhile conferences this year!'", "def conference_picker(cities_visited, cities_offered):\n for i in cities_offered:\n if i not in cities_visited:\n return i \n return \"No worthwhile conferences this year!\"", "def conference_picker(cities_visited, cities_offered):\n return [city for city in (cities_offered + ['No worthwhile conferences this year!']) if city not in cities_visited][0]", "def conference_picker(cities_visited, cities_offered):\n worthwile = set(cities_offered) - set(cities_visited)\n if worthwile:\n return min(worthwile, key=cities_offered.index)\n return 'No worthwhile conferences this year!'", "conference_picker=lambda v, o: o[0] if len(v)==0 else (lambda res: 'No worthwhile conferences this year!' if len(res)==0 else res[0])([c for c in o if c not in v])", "def conference_picker(cv, co):\n return [[i for i in co if not i in cv]+['No worthwhile conferences this year!']][0][0]", "def conference_picker(cities_visited, cities_offered):\n t=[i for i in cities_offered if i not in cities_visited]\n return t[0] if len(t)>0 else 'No worthwhile conferences this year!'", "def conference_picker(cities_visited, cities_offered):\n for city in cities_offered:\n if city not in cities_visited: return city\n return 'No worthwhile conferences this year!' if len(cities_visited) > 0 else cities_offered[0]", "def conference_picker(cities_visited, cities_offered):\n city=[]\n for i in cities_offered:\n if i not in cities_visited:\n city.append(i)\n if len(city)==0:\n return 'No worthwhile conferences this year!'\n else:\n return city[0]\n", "def conference_picker(cities_visited, cities_offered):\n if len(cities_visited) == 0:\n return cities_offered[0]\n for city in cities_offered:\n if city in cities_visited:\n pass\n else:\n return city\n return 'No worthwhile conferences this year!'"] | {"fn_name": "conference_picker", "inputs": [[[], ["Philadelphia", "Osaka", "Tokyo", "Melbourne"]], [[], ["Brussels", "Madrid", "London"]], [[], ["Sydney", "Tokyo"]], [["London", "Berlin", "Mexico City", "Melbourne", "Buenos Aires", "Hong Kong", "Madrid", "Paris"], ["Berlin", "Melbourne"]], [["Beijing", "Johannesburg", "Sydney", "Philadelphia", "Hong Kong", "Stockholm", "Chicago", "Seoul", "Mexico City", "Berlin"], ["Stockholm", "Berlin", "Chicago"]], [["Rome"], ["Rome"]], [["Milan"], ["London"]], [["Mexico City", "Dubai", "Philadelphia", "Madrid", "Houston", "Chicago", "Delhi", "Seoul", "Mumbai", "Lisbon", "Hong Kong", "Brisbane", "Stockholm", "Tokyo", "San Francisco", "Rio De Janeiro"], ["Lisbon", "Mexico City"]], [["Gatlantis", "Baldur's Gate", "Gotham City", "Mystara", "Washinkyo", "Central City"], ["Mystara", "Gatlantis", "MegaTokyo", "Genosha", "Central City", "Washinkyo", "Gotham City", "King's Landing", "Waterdeep"]], [["Thay", "Camelot"], ["Waterdeep", "Washinkyo"]]], "outputs": [["Philadelphia"], ["Brussels"], ["Sydney"], ["No worthwhile conferences this year!"], ["No worthwhile conferences this year!"], ["No worthwhile conferences this year!"], ["London"], ["No worthwhile conferences this year!"], ["MegaTokyo"], ["Waterdeep"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,382 |
def conference_picker(cities_visited, cities_offered):
|
318b9c7f1401c1075078c21c40a75d0e | UNKNOWN | Because my other two parts of the serie were pretty well received I decided to do another part.
Puzzle Tiles
You will get two Integer n (width) and m (height) and your task is to draw following pattern. Each line is seperated with '\n'.
Both integers are equal or greater than 1. No need to check for invalid parameters.
There are no whitespaces at the end of each line.
e.g.:
\_( )\_\_ \_( )\_\_ \_( )\_\_ \_( )\_\_
\_| \_| \_| \_| \_|
(\_ \_ (\_ \_ (\_ \_ (\_ \_ (\_
|\_\_( )\_|\_\_( )\_|\_\_( )\_|\_\_( )\_|
|\_ |\_ |\_ |\_ |\_
puzzleTiles(4,3)=> \_) \_ \_) \_ \_) \_ \_) \_ \_)
|\_\_( )\_|\_\_( )\_|\_\_( )\_|\_\_( )\_|
\_| \_| \_| \_| \_|
(\_ \_ (\_ \_ (\_ \_ (\_ \_ (\_
|\_\_( )\_|\_\_( )\_|\_\_( )\_|\_\_( )\_|
For more informations take a look in the test cases!
Serie: ASCII Fun
ASCII Fun #1: X-Shape
ASCII Fun #2: Funny Dots
ASCII Fun #3: Puzzle Tiles
ASCII Fun #4: Build a pyramid | ["def puzzle_tiles(width, height):\n def f():\n yield ' ' + ' _( )__' * width\n for i in range(height):\n if i % 2 == 0:\n yield ' _|' + ' _|' * width\n yield '(_' + ' _ (_' * width\n yield ' |' + '__( )_|' * width\n else: \n yield ' |_' + ' |_' * width\n yield ' _)' + ' _ _)' * width\n yield ' |' + '__( )_|' * width\n return '\\n'.join(f())", "def puzzle_tiles(width, height):\n def line(i):\n if i == 0:\n return ' ' + ' _( )__' * width\n if i % 3 == 0:\n return ' ' + '__( )_'.join('|' for _ in range(width + 1))\n if i % 6 == 1:\n return ' ' + ' '.join('_|' for _ in range(width + 1))\n if i % 6 == 2:\n return ' _ '.join('(_' for _ in range(width + 1))\n if i % 6 == 4:\n return ' ' + ' '.join('|_' for _ in range(width + 1))\n if i % 6 == 5:\n return ' _ '.join(' _)' for _ in range(width + 1))\n\n return '\\n'.join(line(i) for i in range(3 * height + 1))", "def puzzle_tiles(w, h):\n puzzle = [' ' + ''.join([' _( )__'] * w)]\n for i in range(h):\n if i % 2:\n puzzle.append(''.join([' |_ '] * (w+1)))\n puzzle.append(''.join([' _) _ '] * (w+1))[:-2])\n else:\n puzzle.append(''.join([' _| '] * (w+1)))\n puzzle.append(''.join(['(_ _ '] * (w+1))[:-2])\n puzzle.append(' ' + ''.join(['|__( )_'] * (w+1))[:-6])\n return '\\n'.join(l.rstrip() for l in puzzle)", "LINES = [\"__( )_\", \" _|\", \" _ {0}_\"]\n\ndef puzzle_tiles(width, height):\n s = [''] * (height*3 + 1)\n for i in range(len(s)):\n line = LINES[i%3]\n \n if not i: s[i] = ' '.join([' '] + [line[1:]+'_'] * width)\n \n elif not i%3: s[i] = '|'.join([' '] + [line] * width + [''])\n \n elif i%3 == 1: s[i] = ' ' + ('_|' + line * width)[::(-1)**(not i%2)]\n \n elif i%3 == 2: s[i] = ' '*(i%2) + ('{0}_' + line*width).format(\"()\"[i%2])[::(-1)**(i%2)]\n \n return '\\n'.join(s)", "def puzzle_tiles(width, height): \n temp1=(\" \"*3+\"_( )__ \"*width).rstrip()\n temp2=\" _\"+\" _\".join([\"|\"]*(width+1))\n temp3=\" _ \".join([\"(_\"]*(width+1))\n temp4=\" \"+\"__( )_\".join([\"|\"]*(width+1))\n temp5=\" \"+temp2[::-1].rstrip()\n temp6=\" _\"+\" _ _\".join([\")\"]*(width+1))\n res=[temp1]\n for i in range(height):\n if i%2==0:\n res.append(temp2)\n res.append(temp3)\n res.append(temp4)\n else:\n res.append(temp5)\n res.append(temp6)\n res.append(temp4)\n return \"\\n\".join(res)", "def puzzle_tiles(width, height):\n r=[]\n r.append(' '+' _( )__'*width)\n for i in range(height):\n if i%2==0:\n r.append(' _'+'| _'*width+'|')\n r.append('(_ _ '*width+'(_')\n else:\n r.append(' '+'|_ '*width+'|_')\n r.append(' _)'+' _ _)'*width)\n r.append(' '+'|__( )_'*width+'|')\n return '\\n'.join(r)", "from itertools import cycle\none = \" _( )__\\n _| _|\\n(_ _ (_\\n |__( )_|\".splitlines()\nrev = ' |_ |_\\n _) _ _)\\n |__( )_|'.splitlines()\ndef puzzle_tiles(n,m):\n build, it = one.copy(), [2,3,2,2]\n for i in range(n - 1):\n for j in range(len(build)) : build[j] += one[j][it[j]:]\n build_rev, it = rev.copy(), [3,4,2]\n for i in range(n - 1):\n for j in range(len(build_rev)) : build_rev[j] += rev[j][it[j]:]\n nex = cycle([build[1:], build_rev])\n return '\\n'.join([build[0]] + sum([next(nex) for i in range(m)],[]))", "from itertools import cycle\ndef puzzle_tiles(width, height):\n up_puzzle = ''.join([' ', ' _( )__'*width, '\\n'])\n puzzle = cycle(\n [\n ['', ' _| '*width, ' _|'],\n ['', '(_ _ '*width, '(_'],\n [' ', '|__( )_'*width, '|'],\n [' ','|_ '*width, '|_'],\n [' ',' _) _ '*width, ' _)'],\n [' ','|__( )_'*width, '|']\n ])\n return up_puzzle + '\\n'.join('{}{}{}'.format(*next(puzzle)) for i in range(height*3))", "def puzzle_tiles(width, height):\n \n top = ' ' + ' '.join(['_( )__'] * width)\n bottom = ' |' + '|'.join(['__( )_'] * width) + '|'\n rows = [top]\n \n for i in range(height): \n if i % 2: \n line1 = ' |_' + '|_'.join([' '] * width) + '|_'\n line2 = ' _)' + '_)'.join([' _ '] * width) + '_)'\n else: \n line1 = ' _|' + '_|'.join([' '] * width) + '_|'\n line2 = '(_' + '(_'.join([' _ '] * width) + '(_'\n \n rows.append('\\n'.join([line1, line2, bottom]))\n \n return '\\n'.join(rows)"] | {"fn_name": "puzzle_tiles", "inputs": [[1, 1], [3, 2]], "outputs": [[" _( )__\n _| _|\n(_ _ (_\n |__( )_|"], [" _( )__ _( )__ _( )__\n _| _| _| _|\n(_ _ (_ _ (_ _ (_\n |__( )_|__( )_|__( )_|\n |_ |_ |_ |_\n _) _ _) _ _) _ _)\n |__( )_|__( )_|__( )_|"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,881 |
def puzzle_tiles(width, height):
|
03c7fe804da5a4c32e8439531bae56a9 | UNKNOWN | I'm new to coding and now I want to get the sum of two arrays...actually the sum of all their elements. I'll appreciate for your help.
P.S. Each array includes only integer numbers. Output is a number too. | ["def array_plus_array(arr1,arr2):\n return sum(arr1+arr2)\n", "def array_plus_array(arr1,arr2):\n return sum(arr1) + sum(arr2)", "def array_plus_array(*args):\n return sum(map(sum, args))\n", "def array_plus_array(a, b):\n return sum(a+b)", "def array_plus_array(arr1,arr2):\n counter = 0\n for i in arr1:\n counter += i\n for i in arr2:\n counter += i\n return counter", "from itertools import chain\ndef array_plus_array(arr1,arr2):\n return sum(chain(arr1, arr2))", "def array_plus_array(arr1,arr2):\n result=0\n for ar1,ar2 in zip(arr1,arr2):\n result = result + (ar1+ar2)\n return result", "def array_plus_array(*args):\n return sum(map(sum, args))", "def array_plus_array(A1,A2): return sum( A2 + A1 )", "from functools import reduce\n\n\ndef array_plus_array(arr1,arr2):\n arr0 = arr1 + arr2\n return reduce(lambda a, b: a + b, arr0)", "from functools import reduce\n\n\ndef array_plus_array(arr1, arr2):\n # arr3 = arr1 + arr2\n arr3 = [*arr1, *arr2]\n return reduce(lambda a, b: a + b, arr3)\n", "def array_plus_array(arr1,arr2):\n counter = 0\n for i in range(len(arr1)):\n counter += arr1[i]\n for i in range(len(arr2)):\n counter += arr2[i]\n return counter", "from itertools import chain\n\ndef array_plus_array(*arrays):\n return sum(chain.from_iterable(arrays))", "array_plus_array=lambda a,b: sum(a+b)", "def array_plus_array(arr1,arr2):\n sum1 = 0\n sum2= 0\n for num1 in arr1:\n sum1 += num1\n for num2 in arr2:\n sum2 += num2\n return sum1 + sum2", "from typing import List\n\ndef array_plus_array(arr1: List[int], arr2: List[int]) -> int:\n \"\"\" Get the sum of two arrays. \"\"\"\n return sum(arr1 + arr2)", "def array_plus_array(arr1,arr2):\n arr1.extend(arr2)\n sum = 0\n for i in arr1:\n sum = sum+i\n return sum \n", "def array_plus_array(arr1,arr2):\n total1 = 0\n total2 = 0\n for a in arr1:\n total1 += a\n \n for b in arr2:\n total2 += b\n \n total = total1 + total2\n return total\n", "def array_plus_array(arr1,arr2):\n arr =arr1+arr2 \n total = sum(arr)\n return total", "def array_plus_array(arr1,arr2):\n sum1 = 0\n sum2 = 0\n for i in arr1:\n sum1 = sum1 + i\n for j in arr2:\n sum2 = sum2 + j\n return sum1 + sum2\n", "def array_plus_array(arr1,arr2):\n list = arr1 + arr2\n sum = 0\n for n in list:\n sum += n\n \n return sum\n", "array_plus_array=lambda x,y: sum(x)+sum(y)", "def array_plus_array(x,y):\n sum= 0\n for i in x + y:\n sum += i \n return sum", "def array_plus_array(arr1,arr2):\n counter_one = 0\n counter_two = 0\n for integers in arr1:\n counter_one = counter_one + integers\n for integers in arr2:\n counter_two = counter_two + integers\n output = counter_one + counter_two\n return output", "def array_plus_array(arr1,arr2): \n return sum(arr1[:]) + sum(arr2[:]) ", "def array_plus_array(arr1,arr2):\n return sum(i for a in [arr1, arr2] for i in a)", "def array_plus_array(arr1,arr2):\n sum = 0\n for i in range (max(len(arr1), len(arr2))):\n sum = sum + arr1[i] + arr2[i]\n return sum", "array_plus_array = lambda arr1,arr2: sum(arr1+arr2)", "def array_plus_array(arr1,arr2):\n sum = 0\n for elm in arr1:\n sum += elm\n \n for elm in arr2:\n sum += elm\n \n return sum\n \n \n", "def array_plus_array(arr1,arr2):\n total1 = 0\n total2 = 0\n for i in arr1:\n total1 += i\n for i in arr2:\n total2 += i\n return total1 + total2", "def array_plus_array(arr1,arr2):\n result = 0\n for value in arr1:\n result = result + value\n \n for value in arr2:\n result = result + value\n \n \n return result", "def array_plus_array(arr1,arr2):\n sol = 0\n for a in arr1:\n sol = sol + a\n for b in arr2:\n sol = sol + b\n return sol", "def array_plus_array(arr1,arr2):\n sum_list = []\n for (i1, i2) in zip(arr1, arr2):\n sum_list.append(i1+i2)\n\n return sum(sum_list)", "def array_plus_array(arr1,arr2):\n ans1 = sum(arr1) \n ans2 = sum(arr2)\n ans3 = ans1 + ans2\n return ans3", "def array_plus_array(arr1,arr2):\n for i in arr1:\n return sum(arr1)+sum(arr2)", "\ndef array_plus_array(arr1,arr2):\n \n s=[]\n t=0\n s=arr1+arr2\n print (s)\n for i in s:\n t+=i\n return t\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", "def array_plus_array(arr1,arr2):\n b = arr1 + arr2\n return sum(b)\n", "def array_plus_array(arr1,arr2):\n total_sum = 0\n for number in arr1:\n total_sum += number\n for num in arr2:\n total_sum += num\n \n return total_sum", "def array_plus_array(arr1,arr2):\n z = 0\n y = 0\n for k in arr1:\n z += k\n for j in arr2:\n y += j\n x = z + y\n return x", "def array_plus_array(arr1,arr2):\n soma = 0\n for i in range(len(arr1)):\n soma += arr1[i]\n for i in range(len(arr2)):\n soma += arr2[i]\n return soma\n", "from functools import *\ndef array_plus_array(arr1,arr2):\n return int(reduce(lambda x,y : x+y, list(map(lambda x,y : x+y ,arr1,arr2))))", "def array_plus_array(x,y):\n return sum(x) + sum(y)", "def array_plus_array(arr1,arr2):\n sum = 0\n sum1 = 0\n result = 0\n for i in arr1:\n sum += i\n for x in arr2:\n sum1 += x\n result += sum + sum1\n return result ", "def array_plus_array(arr1,arr2):\n arr1_sum = 0\n arr2_sum = 0\n for i in arr1:\n arr1_sum = arr1_sum + i\n for j in arr2:\n arr2_sum = arr2_sum + j\n total_sum = arr1_sum + arr2_sum\n return total_sum\n \n", "def array_plus_array(arr1,arr2):\n \n total1 = 0\n total2 = 0\n for i in arr1:\n total1 += i\n \n for j in arr2:\n total2 += j\n \n return total1 + total2", "array_plus_array = lambda *a:sum(sum(a,[]))", "def array_plus_array(arr1,arr2):\n a = 0\n b = 0\n for x in arr1:\n a += x\n for y in arr2:\n b += y\n sum = a + b\n return sum", "def array_plus_array(arr1,arr2):\n arr = arr1+arr2\n c = 0\n for i in arr:\n c += i\n return c", "def array_plus_array(arr1,arr2):\n result1 = 0\n result2 = 0\n result = 0\n for number in arr1:\n result1 += number\n for number in arr2:\n result2 += number\n result = result1 + result2\n return result\n pass", "def array_plus_array(arr1,arr2):\n sum1 = 0\n sum2 = 0\n for i in arr1:\n sum1 = i + sum1\n for i in arr2:\n sum2 = i + sum2\n sum = sum1 + sum2\n return sum", "def array_plus_array(arr1,arr2):\n sum = 0\n for i in arr1:\n sum += i\n for u in arr2:\n sum += u\n return sum", "def array_plus_array(arr1,arr2):\n arr1sum = 0\n arr2sum = 0\n for i in arr1:\n arr1sum += i\n for i in arr2:\n arr2sum += i\n return arr1sum + arr2sum", "def array_plus_array(arr1,arr2):\n l=[]\n for i in range(0,len(arr1)):\n l.append(arr1[i]+arr2[i])\n return sum(l)\n", "def array_plus_array(arr1,arr2):\n list = [x + y for x, y in zip(arr1,arr2)]\n return sum(list)", "def array_plus_array(arr1,arr2):\n return sum(num for num in arr1 + arr2)", "def array_plus_array(arr1,arr2):\n sum1 = 0\n sum2 = 0\n for x in arr1:\n sum1 += x\n for y in arr2:\n sum2 += y\n return sum1 + sum2", "def array_plus_array(arr1,arr2):\n sum1 = 0\n sum2 = 0\n for i in range(len(arr1)):\n sum1 += arr1[i]\n for x in range(len(arr2)):\n sum2 += arr2[x]\n return sum1 + sum2", "def array_plus_array(arr1,arr2):\n sum = 0\n for el in arr1:\n sum += el\n for el_2 in arr2:\n sum+=el_2\n return sum \n", "def array_plus_array(arr1, arr2):\n total = 0\n full_list = arr1 + arr2\n for num in range(0, len(full_list)):\n total = total + full_list[num]\n \n return total", "def array_plus_array(arr1,\n arr2):\n\n return sum(arr1) + sum(arr2)\n", "def array_plus_array(arr1,arr2):\n sum = arr1+arr2\n num = 0\n for i in sum:\n num = num+i\n \n return num", "array_plus_array = lambda x,y : sum([x[i] + y[i] for i in range(len(x))])", "def array_plus_array(arr1,arr2,sum=0):\n for i in arr1:\n sum+=i\n for i in arr2:\n sum+=i\n return sum\n", "def array_plus_array(arr1,arr2):\n Liste=list()\n for index in range(len(arr1)):\n sum1=arr1[index] + arr2[index]\n Liste.append(sum1)\n return sum(Liste)\n", "import numpy as np\n\ndef array_plus_array(arr1,arr2):\n numpy_add = np.add(arr1,arr2)\n return sum(numpy_add)", "def array_plus_array(arr1,arr2):\n \"\"\"(^-__-^)\"\"\"\n return(sum(arr1)+sum(arr2))", "def array_plus_array(arr1,arr2):\n return sum([i for i in arr1 + arr2])", "def array_plus_array(arr1,arr2):\n x = arr1 + arr2\n total = 0\n for i in range(len(x)):\n total += x[i]\n \n return total", "def array_plus_array(a1,a2):\n return sum(a1[0:] + a2[0:])", "def array_plus_array(arr1,arr2):\n zipped = list(zip(arr1, arr2))\n return sum([x + y for x, y in zipped])\n", "def array_plus_array(arr1,arr2):\n v = 0\n z = 0\n for x in arr1:\n v = v + x\n for x in arr2:\n z = z + x\n return(v + z)", "def array_plus_array(arr1,arr2):\n \n import numpy as np\n \n s1 = np.sum(arr1)\n s2 = np.sum(arr2)\n \n return s1+s2", "def array_plus_array(arr1,arr2):\n v = sum(arr1)\n w = sum(arr2)\n return (v + w)\n\nend = array_plus_array([0, 0, 0], [4, 5, 6])\nprint(end)", "def array_plus_array(arr1,arr2):\n i = 0\n res = 0\n arr = arr1 + arr2\n while i < len(arr):\n res += arr[i]\n i += 1\n \n return(res)", "def array_plus_array(arr1,arr2):\n x = 0\n for i in range(len(arr1)):\n x = arr1[i] + x\n for j in range(len(arr2)):\n x = arr2[j] + x\n return x", "def array_plus_array(a,b):\n nl = a + b \n sum = 0\n for n in nl:\n sum += n\n return sum\n\n", "def array_plus_array(a,b):\n newl, sum = a+b, 0\n for n in newl:\n sum += n\n return sum\n\n# or just sum(a+b)\n", "def array_plus_array(a,b):\n newl, sum = a+b, 0\n for n in newl:\n sum += n\n return sum\n \n", "def array_plus_array(arr1,arr2):\n total1 = 0\n for num in arr1:\n total1 += num\n \n for num in arr2:\n total1 += num\n \n return total1", "def array_plus_array(arr1,arr2):\n numbers = (arr1) + (arr2)\n return sum(numbers)", "def array_plus_array(arr1,arr2):\n x = 0\n for n in arr1:\n x+=n\n for m in arr2:\n x+=m\n return x", "def array_plus_array(arr1,arr2):\n return sum(i for i in arr1) + sum(x for x in arr2)", "def array_plus_array(arr1,arr2):\n resultado=0\n for i in range(len(arr1)):\n resultado=resultado+arr1[i]\n for i in range(len(arr2)):\n resultado=resultado+arr2[i]\n return resultado", "def array_plus_array(arr1,arr2):\n list1 = arr1 + arr2\n count = 0\n for x in list1:\n count += x\n return count \n", "def array_plus_array(arr1,arr2):\n x = arr1 + arr2\n result = 0\n for i in x:\n result += i\n return(result)", "def array_plus_array(arr1, arr2):\n ans = 0\n for x in arr1: ans += x\n for x in arr2: ans += x\n return ans", "def array_plus_array(arr1,arr2):\n if not arr1: return None\n sum = 0\n \n for i in range(len(arr1)):\n sum += arr1[i] + arr2[i]\n return sum", "def array_plus_array(arr1,arr2):\n return sum((*arr1, *arr2))", "def array_plus_array(arr1,arr2):\n s = 0\n for i in arr1:\n s = s+i\n for j in arr2:\n s = s+j\n return s", "def array_plus_array(arr1,arr2):\n sarr1 = sum(arr1)\n sarr2 = sum(arr2)\n return sarr1+sarr2", "def array_plus_array(arr1,arr2):\n lst = arr1 + arr2\n sum = 0\n for item in lst:\n \n sum+= item\n \n return sum", "def array_plus_array(arr1,arr2):\n a = sum(i for i in arr1)\n b = sum(i for i in arr2)\n c = a+b\n return c\n", "def array_plus_array(arr1,arr2):\n total = 0\n arr1.extend(arr2)\n for num in arr1:\n total += num\n return total", "def array_plus_array(arr1,arr2):\n return sum([i for i in arr1] + [i for i in arr2])", "def array_plus_array(arr1,arr2):\n c =sum(arr1) + sum(arr2)\n return c\n", "def array_plus_array(arr1,arr2):\n arr11 = sum(arr1)\n arr22 = sum(arr2)\n return arr11 + arr22", "def array_plus_array(arr1,arr2):\n i = 0\n l = 0\n o = 0\n \n while i < len(arr1):\n l = l + arr1[i]\n i+=1\n \n i=0\n \n while i < len(arr2):\n o = o + arr2[i]\n i+=1\n \n l = l+o\n return l\n \n", "def array_plus_array(arr1,arr2):\n res1 = 0\n res2 = 0 \n for i in arr1:\n res1 += i\n for j in arr2:\n res2 += j\n return res1 + res2", "def array_plus_array(arr1,arr2):\n sum1 = 0\n for i in arr1:\n sum1 = sum1 + i\n sum2 = 0 \n for i in arr2:\n sum2 = sum2 + i\n return sum1 + sum2\n", "def array_plus_array(arr1,arr2):\n combined = arr1 + arr2\n res = 0\n for num in combined:\n res += num\n return res", "def array_plus_array(arr1, arr2):\n d = 0\n for a1 ,a2 in zip(arr1,arr2):\n x=a1+a2\n d+=x\n return d"] | {"fn_name": "array_plus_array", "inputs": [[[1, 2, 3], [4, 5, 6]], [[-1, -2, -3], [-4, -5, -6]], [[0, 0, 0], [4, 5, 6]], [[100, 200, 300], [400, 500, 600]]], "outputs": [[21], [-21], [15], [2100]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 14,039 |
def array_plus_array(arr1,arr2):
|
2b465f2265587e11a83ec25d3f02f9de | UNKNOWN | # Story
Well, here I am stuck in another traffic jam.
*Damn all those courteous people!*
Cars are trying to enter the main road from side-streets somewhere ahead of me and people keep letting them cut in.
Each time somebody is let in the effect ripples back down the road, so pretty soon I am not moving at all.
(Sigh... late again...)
## Visually
The diagram below shows lots of cars all attempting to go North.
* the `a`,`b`,`c`... cars are on the main road with me (`X`)
* the `B` cars and `C` cars are merging from side streets
| a |
| b | ↑
--------+ c |
BBBBBB d |
--------+ e |
| f | ↑
| g |
--------+ h |
CCCCC i |
--------+ j | ↑
| k |
| l |
| m |
| X |
This can be represented as
* `mainRoad` = `"abcdefghijklmX"`
* `sideStreets` = `["","","","BBBBBB","","","","","CCCCC"]`
# Kata Task
Assume every car on the main road will "give way" to 1 car entering from each side street.
Return a string representing the cars (up to and including me) in the order they exit off the top of the diagram.
## Notes
* My car is the only `X`, and I am always on the main road
* Other cars may be any alpha-numeric character (except `X` of course)
* There are no "gaps" between cars
* Assume side streets are always on the left (as in the diagram)
* The `sideStreets` array length may vary but is never more than the length of the main road
* A pre-loaded `Util.display(mainRoad,sideStreets)` method is provided which may help to visualise the data
* (Util.Display for C#)
## Example
Here are the first few iterations of my example, showing that I am hardly moving at all...
InitialIter 1Iter 2Iter 3Iter 4Iter 5Iter 6Iter 7
a
b
c
BBBBBBd
e
f
g
h
CCCCCi
j
k
l
m
X
b
c
d
BBBBBB
e
f
g
h
CCCCCi
j
k
l
m
X
c
d
B
BBBBBe
f
g
h
i
CCCCC
j
k
l
m
X
d
B
e
BBBBB
f
g
h
i
CCCCC
j
k
l
m
X
B
e
B
BBBBf
g
h
i
C
CCCCj
k
l
m
X
e
B
f
BBBB
g
h
i
C
CCCCj
k
l
m
X
B
f
B
BBBg
h
i
C
j
CCCC
k
l
m
X
f
B
g
BBB
h
i
C
j
CCCC
k
l
m
X
:-)
DM | ["def traffic_jam(road, sides):\n X = road.index(\"X\")\n main = list(road[:X+1])\n \n for i in reversed(range( min(X,len(sides)) )):\n tmp = []\n for j in range(1, min(len(main)-i-1, len(sides[i]))+1 ):\n tmp.append(sides[i][-j])\n tmp.append(main[i+j])\n main[i+1:i+len(tmp)//2+1] = tmp\n \n return ''.join(main)", "def traffic_jam(main_road, side_streets):\n answer = main_road\n for i in range(len(side_streets) - 1, -1, -1):\n ss = list(side_streets[i])[::-1]\n j = i + 1\n while ss:\n answer = answer[:j] + ss.pop(0) + answer[j:]\n j += 2\n return answer[:answer.find(\"X\") + 1]", "def traffic_jam(main_road, side_streets):\n if side_streets == ['', '', '', 'abcdef', '', '', '', '', 'abcde']:\n return 'abcdfeefdgchbiaejdkclbmaX'\n else:\n for pos in range(len(side_streets)-1,-1,-1):\n if side_streets[pos] != \"\":\n main_road = main_road[:pos] + side_streets[pos][0].join(main_road[pos:][i:i+1] for i in range(0, len(main_road[pos:pos+len(side_streets[pos])+1]), 1)) + main_road[pos+1+len(side_streets[pos]):]\n return main_road[:main_road.index('X')+1] \n", "def traffic_jam(main_road, side_streets):\n \n road = list(main_road)\n indice = road.index('X')\n road = road[:indice+1]\n \n side = [list(e) for e in side_streets]\n if not side : return ''.join(road)\n \n if len(side)<len(road):\n side += [[] for k in range(len(road)-len(side)) ]\n\n final = []\n def conduit(voiture, position):\n while position>0:\n if side[position-1]:\n v = side[position-1].pop()\n conduit(v, position-1)\n position -=1\n final.append(voiture)\n \n for i, voiture in enumerate(road):\n conduit(voiture, i)\n \n return ''.join(final)", "def traffic_jam(main_road, side_streets):\n #display(main_road, side_streets)\n \n result = ''\n \n while True:\n for i in range(len(main_road) - 1, -1, -1):\n if len(side_streets) > i and len(side_streets[i])> 0:\n main_road = main_road[:i+1] + side_streets[i][-1] + main_road[i+1:]\n side_streets[i] = side_streets[i][:-1]\n side_streets = side_streets[:i] + [''] + side_streets[i:]\n result += main_road[0]\n if main_road[0] == 'X':\n return result\n main_road = main_road[1:]\n", "def traffic_jam(estrada, rua_lateral):\n X = estrada.index(\"X\")\n principal = list(estrada[:X + 1])\n\n for i in reversed(range(min(X, len(rua_lateral)))):\n tmp = []\n for j in range(1, min(len(principal) - i - 1, len(rua_lateral[i])) + 1):\n tmp.append(rua_lateral[i][-j])\n tmp.append(principal[i + j])\n principal[i + 1:i + len(tmp) // 2 + 1] = tmp\n\n return ''.join(principal)", "def traffic_jam(main, ss):\n ret = list(main)\n for i,s in reversed(list(enumerate(ss))):\n for j,c in enumerate(s[::-1]): \n ret.insert(i+j*2+1,c)\n return ''.join(ret[:ret.index('X')+1])\n \n \n", "def traffic_jam(m,S):\n M=list(m)\n for i in range(len(S))[::-1]:\n R=sum(zip(M[i:],S[i][::-1]),())\n M[i:]=list(R)+M[i+len(R)//2:]\n return''.join(M)[:M.index('X')+1]", "def traffic_jam(m, S):\n M=list(m)\n for i in range(len(S))[::-1]:\n R=sum([list(r)for r in zip(M[i:],S[i][::-1])],[])\n M[i:]=R+M[i+len(R)//2:]\n return ''.join(M)[:M.index('X')+1]"] | {"fn_name": "traffic_jam", "inputs": [["abcdeXghi", ["", "", "CCCCC", "", "EEEEEEEEEE", "FFFFFF", "", "", "IIIIII"]], ["abcdefX", []], ["abcXdef", []], ["Xabcdef", []], ["abcdefghijklmX", ["", "", "", "BBBBBB", "", "", "", "", "CCCCC"]], ["abcdefghijkX", ["", "AAAAAAAAAA", "", "BBBBBBBB", "", "CCCC"]], ["abcdefghijkX", ["", "AAAAAAAAAA", "BBBBBBBB", "CCCC"]], ["abcdeX", ["AAAAA", "BBBB", "CCC", "DD", "E"]], ["abcdefghijklmnopqrstuvwX", ["AAA", "BBB", "CCC", "DDD", "EEE", "FFF", "GGG", "HHH", "III", "JJJ", "KKK", "LLL", "MMM", "NNN", "OOO", "PPP", "QQQ", "RRR", "SSS", "TTT", "UUU", "VVV", "WWW"]], ["ZZZZZZZZX", ["", "", "", "ZZZZ"]], ["AAAAAAX", []], ["000X000", []], ["AAAAAAAAAAAAAX", ["", "", "", "AAAAAA", "", "", "", "", "AAAAA"]], ["abcdefghijklmX", ["", "", "", "abcdef", "", "", "", "", "abcde"]]], "outputs": [["abcCdCeCECX"], ["abcdefX"], ["abcX"], ["X"], ["abcdBeBfBgBhBiBCjCkClCmCX"], ["abAcAdABAeABAfABACABAgBCBhBCBiCjkX"], ["abAcABAdABACABAeABACABfBCBgBChijkX"], ["aAbABAcABACBdBCDCeDEX"], ["aAbABAcBCBdCDCeDEDfEFEgFGFhGHGiHIHjIJIkJKJlKLKmLMLnMNMoNONpOPOqPQPrQRQsRSRtSTSuTUTvUVUwVWVX"], ["ZZZZZZZZZZZZX"], ["AAAAAAX"], ["000X"], ["AAAAAAAAAAAAAAAAAAAAAAAAX"], ["abcdfeefdgchbiaejdkclbmaX"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,598 |
def traffic_jam(main_road, side_streets):
|
94cecca389dfdfbb32957a672fccaf6e | UNKNOWN | # Task
A masked number is a string that consists of digits and one asterisk (`*`) that should be replaced by exactly one digit. Given a masked number `s`, find all the possible options to replace the asterisk with a digit to produce an integer divisible by 6.
# Input/Output
`[input]` string `s`
A masked number.
`1 ≤ inputString.length ≤ 10000.`
`[output]` a string array
Sorted array of strings representing all non-negative integers that correspond to the given mask and are divisible by 6.
# Example
For `s = "1*0"`, the output should be `["120", "150", "180"].`
For `s = "*1"`, the output should be `[].`
For `s = "1234567890123456789012345678*0"`,
the output should be
```
[
"123456789012345678901234567800",
"123456789012345678901234567830",
"123456789012345678901234567860",
"123456789012345678901234567890"]```
As you can see, the masked number may be very large ;-) | ["def is_divisible_by_6(s):\n all_numbers = [ int(s.replace('*', str(n))) for n in range(10) ]\n return [ str(n) for n in all_numbers if n % 6 == 0 ]", "def is_divisible_by_6(s):\n return [str(n) for n in [int(s.replace('*', str(i))) for i in range(10)] if n % 6 == 0]", "def is_divisible_by_6(stg):\n result = []\n for d in \"0123456789\":\n r = int(d.join(stg.split(\"*\")))\n if r % 6 == 0:\n result.append(str(r))\n return result\n\n# one-liner\n# return [str(int(stg.replace(\"*\", d))) for d in \"0123456789\" if int(stg.replace(\"*\", d)) % 6 == 0]\n", "def is_divisible_by_6(s):\n if s[-1] != \"*\":\n if int(s[-1]) % 2 == 1:\n return []\n else:\n lst = []\n for i in range(10):\n if int(s.replace(\"*\", str(i))) % 3 == 0:\n lst.append(int(s.replace(\"*\", str(i))))\n for x in range(len(lst)):\n lst[x] = str(lst[x])\n return lst\n\n else:\n lst = []\n for i in [0,2,4,6,8]:\n lst.append(s[:-1] + str(i))\n lst2 = []\n for x in range(len(lst)):\n if int(lst[x]) % 3 == 0:\n lst2.append(lst[x])\n return lst2", "def is_divisible_by_6(s):\n xs = [s.replace('*', str(i)) for i in range(10)]\n return [x.lstrip('0') or '0' for x in xs if int(x) % 6 == 0]", "def is_divisible_by_6(s):\n out=[]\n for digit in \"0123456789\":\n div=int(s.replace(\"*\",digit))\n if div%6==0:out.append(str(div))\n return out", "def is_divisible_by_6(s):\n x = [s.replace('*', str(i)) for i in range(10)]\n x = [i for i in x if int(i) % 6 == 0]\n x = [i[1:] if i[0] == '0' and len(i) > 1 else i for i in x]\n return x", "from functools import reduce\n\ndef is_divisible_by_6(s):\n \n digits = list(range(0,10))\n perm = [s.replace('*', str(d)) for d in digits]\n res = [s for s in perm if isDiv2(s) and isDiv3(s)]\n \n return [x.lstrip('0') if len(x) > 1 else x for x in res]\n \ndef isDiv2(n):\n return int(n[-1]) % 2 == 0\n\ndef isDiv3(n):\n d = [int(x) for x in list(n) if x != '*']\n sum = reduce(lambda a,b: a+b, d)\n return sum % 3 == 0\n", "def is_divisible_by_6(s):\n ls = []\n for x in range(10):\n if int(s.replace(\"*\", str(x)))%6 == 0:\n ls.append(s.replace(\"*\", str(x))) \n for x in ls:\n if len(x)>1 and x[0] == \"0\":\n ls.insert(ls.index(x), x[1:])\n ls.remove(x)\n return ls", "def is_divisible_by_6(s):\n if s==\"*\":\n return [\"0\", \"6\"]\n elif s[-1].isdigit() and int(s[-1])%2:\n return []\n check=s.index(\"*\")\n res=[]\n digit_sum=sum(int(i) for i in s[:check]+s[check+1:])\n for i in range(10):\n if (check==len(s)-1 and i%2==0 and (i+digit_sum)%3==0) or (check!=len(s)-1 and (i+digit_sum)%3==0):\n res.append(str(int(s[:check]+str(i)+s[check+1:])))\n return res"] | {"fn_name": "is_divisible_by_6", "inputs": [["1*0"], ["*"], ["*1"], ["*2"], ["81234567890*"], ["41*"], ["*6"], ["2345*345729"], ["34234*2"], ["1234567890123456789012345678*0"]], "outputs": [[["120", "150", "180"]], [["0", "6"]], [[]], [["12", "42", "72"]], [["812345678904"]], [["414"]], [["6", "36", "66", "96"]], [[]], [["3423402", "3423432", "3423462", "3423492"]], [["123456789012345678901234567800", "123456789012345678901234567830", "123456789012345678901234567860", "123456789012345678901234567890"]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,005 |
def is_divisible_by_6(s):
|
d50b19d2e50461c87fc4558871b3a0d5 | UNKNOWN | Born a misinterpretation of [this kata](https://www.codewars.com/kata/simple-fun-number-334-two-beggars-and-gold/), your task here is pretty simple: given an array of values and an amount of beggars, you are supposed to return an array with the sum of what each beggar brings home, assuming they all take regular turns, from the first to the last.
For example: `[1,2,3,4,5]` for `2` beggars will return a result of `[9,6]`, as the first one takes `[1,3,5]`, the second collects `[2,4]`.
The same array with `3` beggars would have in turn have produced a better out come for the second beggar: `[5,7,3]`, as they will respectively take `[1,4]`, `[2,5]` and `[3]`.
Also note that not all beggars have to take the same amount of "offers", meaning that the length of the array is not necessarily a multiple of `n`; length can be even shorter, in which case the last beggars will of course take nothing (`0`).
***Note:*** in case you don't get why this kata is about *English* beggars, then you are not familiar on how religiously queues are taken in the kingdom ;) | ["def beggars(values, n):\n return [sum(values[i::n]) for i in range(n)]", "def beggars(a, n): \n return [sum(a[i::n]) for i in range(n)]", "def beggars(values, n):\n if n == 0:\n return []\n i=0\n take=[]\n for x in range(n):\n take.append(0)\n for val in values:\n take[i%n]=take[i%n]+val\n i= i + 1\n return take ", "def beggars(values: list, n: int):\n if n < 1: return []\n\n beggars = [0] * n\n for i, v in enumerate(values):\n beggars[i % n] += v\n\n return beggars", "def beggars(values, n):\n if n<1: return []\n k = [0]*n\n for i in range(len(values)):\n k[i%n]+=values[i]\n return k", "def beggars(values, n):\n return [sum(values[k::n]) for k in range(n)]", "def beggars(values, n):\n #your code here\n if n == 0:\n return []\n newe = list(0 for i in range(n)) \n count = 0\n for i in values:\n newe[(count % n)] += i\n count += 1\n return newe ", "def beggars(values, n):\n return [sum(values[i] for i in range(j, len(values), n)) for j in range(n)]", "beggars=lambda values,n:[sum(values[i::n]) for i in range(n)]", "def beggars(values, n):\n retList = [0]*n\n if not n:\n return []\n for idx,i in enumerate(values):\n retList[idx%n] += i\n return retList\n"] | {"fn_name": "beggars", "inputs": [[[1, 2, 3, 4, 5], 1], [[1, 2, 3, 4, 5], 2], [[1, 2, 3, 4, 5], 3], [[1, 2, 3, 4, 5], 6], [[1, 2, 3, 4, 5], 0]], "outputs": [[[15]], [[9, 6]], [[5, 7, 3]], [[1, 2, 3, 4, 5, 0]], [[]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,342 |
def beggars(values, n):
|
052515368ed4e48ed078cdf25ba75d6d | UNKNOWN | In graph theory, a graph is a collection of nodes with connections between them.
Any node can be connected to any other node exactly once, and can be connected to no nodes, to some nodes, or to every other node.
Nodes cannot be connected to themselves
A path through a graph is a sequence of nodes, with every node connected to the node following and preceding it.
A closed path is a path which starts and ends at the same node.
An open path:
```
1 -> 2 -> 3
```
a closed path:
```
1 -> 2 -> 3 -> 1
```
A graph is connected if there is a path from every node to every other node.
A graph is a tree if it is connected and there are no closed paths.
Your job is to write a function 'isTree', which returns true if a graph is a tree, and false if it is not a tree.
Graphs will be given as an array with each item being an array of integers which are the nodes that node is connected to.
For example, this graph:
```
0--1
| |
2--3--4
```
has array:
```
[[1,2], [0,3], [0,3], [1,2,4], [3]]
```
Note that it is also not a tree, because it contains closed path:
```
0->1->3->2->0
```
A node with no connections is an empty array
Note that if node 0 is connected to node 1, node 1 is also connected to node 0. This will always be true.
The order in which each connection is listed for each node also does not matter.
Good luck! | ["def isTree(matrix):\n visited_nodes = set([0])\n crossed_edges = set()\n agenda = [0]\n\n while agenda:\n node = agenda.pop()\n for i in matrix[node]:\n if (node, i) in crossed_edges: continue \n if i in visited_nodes: return False\n agenda.append(i)\n crossed_edges.add( (i, node) )\n visited_nodes.add(i)\n \n return len(visited_nodes) == len(matrix)", "def isTree(matrix):\n seen, stack = set(), [0]\n while stack:\n node = stack.pop()\n if node in seen:\n return False\n seen.add(node)\n stack += list(set(matrix[node]) - seen)\n return len(seen) == len(matrix)", "def isTree(matrix):\n visited = [False] * len(matrix)\n\n def traverse(origin, transit):\n if not visited[transit]:\n visited[transit] = True\n return all(traverse(transit, destination) for destination in matrix[transit] if destination != origin)\n \n return traverse(None, 0) and all(visited)", "def isTree(matrix):\n '''depth first search; tree on n vertices has exactly n-1 edges'''\n vertices = set(range(len(matrix)))\n stack = [vertices.pop()]\n while stack:\n children = {y for y in matrix[stack.pop()] if y in vertices}\n vertices.difference_update(children)\n stack.extend(children)\n return not vertices and sum(map(len,matrix)) == 2 * len(matrix) - 2", "def isTree(Q) :\n if not len(Q) : return False\n H = [0] * len(Q)\n U = [[-1,0]]\n while len(U) :\n F,T = U.pop()\n if H[T] : return False\n H[T] = 1\n U += [[T,V] for V in Q[T] if V != F]\n return len(Q) == sum(H)", "def visit(ad_lst, i, fth=-1, path=[], visited=0):\n if i in path:\n return [], -1\n visited += 1\n path.append(i)\n for v in range(0, len(ad_lst[i])):\n if fth == ad_lst[i][v]:\n continue\n path2, v2 = visit(ad_lst, ad_lst[i][v], i, path)\n if len(path2) == 0:\n return [], -1\n path = path2\n visited += v2\n return path, visited\n \ndef isTree(ad_lst):\n for v in range(0, len(ad_lst)):\n path, visited = visit(ad_lst, v, -1, [], 0)\n if len(path) == 0:\n return False\n if visited == len(ad_lst):\n return True\n return False", "def isTree(matrix):\n seen = [False] * len(matrix)\n\n def traverse(from_node, to_node):\n if not seen[to_node]:\n seen[to_node] = True\n for next_node in matrix[to_node]:\n if next_node != from_node:\n if not traverse(to_node, next_node):\n return False\n return True\n \n return traverse(None, 0) and all(seen)", "from collections import defaultdict\n\ndef isTree(matrix):\n graph = defaultdict(set)\n for node, connections in enumerate(matrix):\n if not connections:\n return False\n for connection in connections:\n graph[connection].add(node)\n graph[node].add(connection)\n \n N = len(matrix)\n for node in graph.keys():\n stack, seen = [node], set()\n while stack:\n cur_node = stack.pop()\n if cur_node in seen:\n return False\n seen.add(cur_node)\n for next_node in graph[cur_node]:\n if next_node not in seen:\n stack.append(next_node)\n if len(seen) < N:\n return False\n return True", "def isTree(m):\n status = [(e, 0) for e in m[0]]\n seen = set([0]) if status else set()\n while status:\n t, f = status.pop()\n seen.add(t)\n for e in m[t]:\n if e != f:\n if e in seen:\n return False\n seen.add(e)\n status.append((e, t))\n return len(seen) == len(m)", "def s(m, b, e, v):\n v[b] += 1\n if v[b] > 1:\n return v\n for i in range(len(m[b])):\n if m[b][i] != e:\n v = s(m,m[b][i],b,v)\n return v\n\ndef isTree(m):\n v = [0]*len(m)\n v = s(m, 0, -1, v)\n return v == [1]*len(v)"] | {"fn_name": "isTree", "inputs": [[[[], []]], [[[1], [0]]], [[[1, 2], [0, 2], [0, 1]]], [[[1, 2, 3], [0, 2], [1, 2], [0]]], [[[1, 2, 3], [0], [0], [0, 4], [3]]], [[[1, 2, 3], [0], [0], [0, 4], [3], []]], [[[1], [0, 2], [1, 3, 5], [2, 4], [3, 5], [4, 2]]], [[[1], [0, 2, 3, 4], [1], [1], [1]]], [[[1], [0, 2, 3], [1], [1], [5], [4, 6, 7], [5], [5]]], [[[1, 2], [0, 3], [0, 3], [1, 2, 4], [3]]], [[[1, 2], [0, 2], [0, 1], []]], [[[1, 2], [0, 2], [0, 1], [4], [3]]]], "outputs": [[false], [true], [false], [false], [true], [false], [false], [true], [false], [false], [false], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,235 |
def isTree(matrix):
|
09e352621407309636189b2ee427e42f | UNKNOWN | In this Kata, you will create a function that converts a string with letters and numbers to the inverse of that string (with regards to Alpha and Numeric characters). So, e.g. the letter `a` will become `1` and number `1` will become `a`; `z` will become `26` and `26` will become `z`.
Example: `"a25bz"` would become `"1y226"`
Numbers representing letters (`n <= 26`) will always be separated by letters, for all test cases:
* `"a26b"` may be tested, but not `"a262b"`
* `"cjw9k"` may be tested, but not `"cjw99k"`
A list named `alphabet` is preloaded for you: `['a', 'b', 'c', ...]`
A dictionary of letters and their number equivalent is also preloaded for you called `alphabetnums = {'a': '1', 'b': '2', 'c': '3', ...}` | ["import re\ndef AlphaNum_NumAlpha(string):\n return re.sub( r'[0-9]{1,2}|[a-z]', lambda x:str(ord(x.group() )-96) if x.group().isalpha() else chr(int(x.group())+96) , string)\n \n #\\w\n", "import re\nfrom string import ascii_lowercase\n\ndef repl(m):\n x = m.group()\n if x.isdigit():\n return ascii_lowercase[int(x)-1]\n else:\n return str(ascii_lowercase.find(x) + 1)\n\ndef AlphaNum_NumAlpha(string):\n return re.sub(r'[a-z]|\\d+', repl, string)", "import re\n\ndef AlphaNum_NumAlpha(string):\n return ''.join(chr(int(e)+96) if e.isdigit() else str(ord(e)-96) for e in re.split('([a-z])', string) if e)", "import re\ndef AlphaNum_NumAlpha(string):\n f = lambda x: str(ord(x)-ord('a')+1) if x.isalpha() else chr(ord('a')+int(x)-1)\n return ''.join([f(x) for x in re.findall(r'\\d{1,2}|[a-z]', string)])"] | {"fn_name": "AlphaNum_NumAlpha", "inputs": [["25abcd26"], ["18zyz14"], ["a1b2c3d4"], ["5a8p17"], ["w6aa4ct24m5"], ["17dh"], ["25gj8sk6r17"], ["18zzz14"], ["y17kg5et11"], ["abcdefghijklmnopqrstuvwxyz"], ["1a2b3c4d5e6f7g8h9i10j11k12l13m14n15o16p17q18r19s20t21u22v23w24x25y26z"], ["h15q4pc6yw23nmx19y"], ["p16k11o25x7m6m20ct9"], ["nv15u19d5fq8"], ["4n3fk22en17ekve"], ["iwantamemewar"], ["7h15cc9s23l11k10sd5"], ["hd2gd14gf2sg5lm8wfv9bb13"], ["13"], ["7k7k7sg3jvh16d"], ["6h19r21a8b"], ["youaredonegoodforyou"]], "outputs": [["y1234z"], ["r262526n"], ["1a2b3c4d"], ["e1h16q"], ["23f11d320x13e"], ["q48"], ["y710h1911f18q"], ["r262626n"], ["25q117e520k"], ["1234567891011121314151617181920212223242526"], ["a1b2c3d4e5f6g7h8i9j10k11l12m13n14o15p16q17r18s19t20u21v22w23x24y25z26"], ["8o17d163f2523w141324s25"], ["16p11k15y24g13f13t320i"], ["1422o21s4e617h"], ["d14c611v514q511225"], ["92311420113513523118"], ["g8o33i19w12k11j194e"], ["84b74n76b197e1213h23622i22m"], ["m"], ["g11g11g197c10228p4"], ["f8s18u1h2"], ["251521118541514571515461518251521"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 853 |
def AlphaNum_NumAlpha(string):
|
41e3cd5fe671b115b2971762f3e82f5a | UNKNOWN | Convert a hash into an array. Nothing more, Nothing less.
```
{name: 'Jeremy', age: 24, role: 'Software Engineer'}
```
should be converted into
```
[["name", "Jeremy"], ["age", 24], ["role", "Software Engineer"]]
```
```if:python,javascript,crystal
**Note**: The output array should be sorted alphabetically.
```
Good Luck! | ["def convert_hash_to_array(hash):\n return sorted(map(list, hash.items()))", "def convert_hash_to_array(hash):\n return [[k, hash[k]] for k in sorted(hash)]", "def convert_hash_to_array(d):\n return [ [k,v] for k,v in sorted(d.items()) ] ", "def convert_hash_to_array(dct):\n return sorted(list(item) for item in dct.items())", "def convert_hash_to_array(hash):\n return sorted(list(x) for x in hash.items())", "# From slowest to fastest.\n\ndef convert_hash_to_array(hash):\n return sorted(map(list, hash.items()))\n \ndef convert_hash_to_array(hash):\n return sorted([k, v] for k, v in hash.items())\n\ndef convert_hash_to_array(hash):\n return [[k, hash[k]] for k in sorted(hash)]", "def convert_hash_to_array(hash):\n dictlist = []\n for key, value in hash.items():\n temp = [key,value]\n dictlist.append(temp)\n return sorted(dictlist)", "convert_hash_to_array = lambda l: [[a,l[a]] for a in sorted(l)]", "def convert_hash_to_array(hash):\n my_list = []\n for k in sorted(hash.items()):\n temp = [k[0], k[1]]\n my_list.append(temp)\n return my_list", "def convert_hash_to_array(hash):\n return sorted([[att, hash[att]] for att in hash])"] | {"fn_name": "convert_hash_to_array", "inputs": [[{"name": "Jeremy"}], [{"name": "Jeremy", "age": 24}], [{"name": "Jeremy", "age": 24, "role": "Software Engineer"}], [{"product": "CodeWars", "power_level_over": 9000}], [{}]], "outputs": [[[["name", "Jeremy"]]], [[["age", 24], ["name", "Jeremy"]]], [[["age", 24], ["name", "Jeremy"], ["role", "Software Engineer"]]], [[["power_level_over", 9000], ["product", "CodeWars"]]], [[]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,220 |
def convert_hash_to_array(hash):
|
88bc4e7b2df87f17821c588198806714 | UNKNOWN | To participate in a prize draw each one gives his/her firstname.
Each letter of a firstname
has a value which is its rank in the English alphabet. `A` and `a` have rank `1`, `B` and `b` rank `2` and so on.
The *length* of the firstname is added to the *sum* of these ranks hence a number `som`.
An array of random weights is linked to the firstnames and each `som` is multiplied by
its corresponding weight to get what they call a `winning number`.
Example:
```
names: "COLIN,AMANDBA,AMANDAB,CAROL,PauL,JOSEPH"
weights: [1, 4, 4, 5, 2, 1]
PauL -> som = length of firstname + 16 + 1 + 21 + 12 = 4 + 50 -> 54
The *weight* associated with PauL is 2 so PauL's *winning number* is 54 * 2 = 108.
```
Now one can sort the firstnames in decreasing order of the `winning numbers`. When two
people have the same `winning number` sort them *alphabetically* by their firstnames.
### Task:
- parameters: `st` a string of firstnames, `we` an array of weights, `n` a rank
- return: the firstname of the participant whose rank is `n`
(ranks are numbered from 1)
### Example:
```
names: "COLIN,AMANDBA,AMANDAB,CAROL,PauL,JOSEPH"
weights: [1, 4, 4, 5, 2, 1]
n: 4
The function should return: "PauL"
```
# Notes:
- The weight array is at least as long as the number of names, it can be longer.
- If `st` is empty return "No participants".
- If n is greater than the number of participants then return "Not enough participants".
- See Examples Test Cases for more examples. | ["def rank(st, we, n):\n if not st:\n return \"No participants\"\n \n if n>len(we):\n return \"Not enough participants\"\n\n name_score = lambda name,w: w*(len(name)+sum([ord(c.lower())-96for c in name]))\n \n scores= [name_score(s,we[i]) for i,s in enumerate(st.split(','))]\n \n scores = list(zip(st.split(','),scores)) \n \n scores.sort(key=lambda x: (-x[1],x[0]))\n \n return scores[n-1][0]", "def win_num(name, weight):\n return (len(name) + sum(ord(c)-96 for c in name.lower())) * weight\n\ndef rank(st, we, n):\n if not st: return \"No participants\"\n elif n>len(we): return \"Not enough participants\"\n else: return sorted((-win_num(s,w),s) for s,w in zip(st.split(\",\"), we))[n-1][1]\n", "DELTA = ord(\"a\")-1\n\ndef sumName(name):\n return sum( ord(c)-DELTA for c in name) + len(name)\n\ndef rank(st, we, n):\n return (\"No participants\" if st == \"\" else\n \"Not enough participants\" if n > st.count(\",\")+1 else \n sorted( (-sumName(name.lower())*w, name) for name,w in zip(st.split(','), we) )[n-1][1] )", "def rank(st, we, n):\n if not st: return \"No participants\"\n st = st.split(',')\n calc = lambda x: we[x[0]] * (len(x[1]) + sum(ord(m) - ord('a') + 1 for m in x[1].lower()))\n return sorted(sorted([m for m in enumerate(st)], key=lambda x: x[1]), key=lambda m: calc(m), reverse=True)[n - 1][1] if len(st) >= n else \"Not enough participants\"", "from string import ascii_lowercase\n\ndef rank(st, we, n): \n names = st.split(\",\")\n ranks = {}\n \n if st == \"\":\n return \"No participants\"\n \n if n > len(names):\n return \"Not enough participants\"\n \n for index, name in enumerate(names):\n som = len(name) + sum([ascii_lowercase.index(letter) + 1 for letter in name.lower()])\n ranks[name] = we[index] * som\n \n sort = sorted(list(ranks.items()), key=lambda x: (-x[1], x[0]))\n return [name for name, som in sort][n - 1]\n", "from typing import List\n\n\ndef rank(st: str, we: List[int], n: int):\n if not st:\n return \"No participants\"\n\n names = st.split(',')\n if n > len(names):\n return \"Not enough participants\"\n\n return sorted(((-w * (len(s) + sum(ord(c) - 96 for c in s.lower())), s) for s, w in zip(names, we)))[n - 1][1]\n", "def weight_words(nam):\n sum = 0\n for x in nam:\n sum += ord(x) - 96\n return sum + len(nam)\n\n\ndef rank(st, we, n):\n index = 0\n if len(st) == 0:\n return \"No participants\"\n lst_st = st.split(',')\n if n > len(lst_st):\n return \"Not enough participants\"\n res = []\n for name, w in zip(lst_st,we):\n res.append((weight_words(name.lower())*w, name))\n res = sorted(res, reverse=True)\n while index < len(res) - 1:\n tmp = res[index]\n tmp_next = res[index + 1]\n if tmp[0] == tmp_next[0]:\n if tmp[1] > tmp_next[1]:\n res[index],res[index + 1] = res[index + 1],res[index]\n else:\n index = index + 1\n else:\n index = index + 1\n return res[n - 1][1]", "def rank(st, we, n):\n if not st:\n return \"No participants\"\n names = st.split(\",\")\n if len(names) < n:\n return \"Not enough participants\"\n result = {names[i]: (sum(ord(l.lower()) - ord('a') + 1 for l in names[i]) + len(names[i])) * we[i] for i in range(len(names))}\n result = {k: v for k, v in sorted(result.items(), key=lambda item: item[0])}\n result = sorted(result.items(), key=lambda item: item[1], reverse=True)\n return result[n-1][0]", "from string import ascii_lowercase\n\n\ndef rank(st, we, n):\n if not st:\n return \"No participants\"\n if n > len(st.split(',')):\n return \"Not enough participants\"\n x = ascii_lowercase\n s = 0\n winning_num = []\n names = []\n group = sorted(list(zip(st.split(','), we)))\n for name, weight in group:\n names.append(name)\n for letter in name.lower():\n s += (x.index(letter)) + 1\n s += len(name)\n winning_num.append(s * weight)\n s = 0\n final = list(zip(winning_num, names))\n final.sort(reverse=True)\n z = []\n final_names = []\n for V, N in final:\n final_names.append(N)\n if V == final[n - 1][0]:\n z.append(N)\n z.sort()\n ind = []\n for p in z:\n ind.append(final_names.index(p))\n new_list = final_names[:min(ind)] + z + final_names[max(ind) + 1:]\n return new_list[n - 1]", "def rank(st: str, we: list, n: int):\n if not st:\n return 'No participants'\n elif n > len(st.split(',')):\n return \"Not enough participants\"\n \n def to_number(word):\n return (sum(ord(c.lower())-96 for c in word) + len(word))\n \n d = {}\n for w, wt in zip(st.split(','), we):\n d[w] = to_number(w) * wt\n \n sorted_d = sorted(d.items(), key=lambda kv: (-kv[1], kv[0]))\n print(sorted_d)\n return sorted_d[n-1][0]"] | {"fn_name": "rank", "inputs": [["Addison,Jayden,Sofia,Michael,Andrew,Lily,Benjamin", [4, 2, 1, 4, 3, 1, 2], 4], ["Elijah,Chloe,Elizabeth,Matthew,Natalie,Jayden", [1, 3, 5, 5, 3, 6], 2], ["Aubrey,Olivai,Abigail,Chloe,Andrew,Elizabeth", [3, 1, 4, 4, 3, 2], 4], ["Lagon,Lily", [1, 5], 2], ["Elijah,Michael,Avery,Sophia,Samantha", [2, 1, 5, 2, 2], 3], ["William,Willaim,Olivia,Olivai,Lily,Lyli", [1, 1, 1, 1, 1, 1], 1], ["Addison,Jayden,Sofia,Michael,Andrew,Lily,Benjamin", [4, 2, 1, 4, 3, 1, 2], 8], ["", [4, 2, 1, 4, 3, 1, 2], 6], ["Addison,William,Jayden", [3, 5, 6], 1], ["Joshua,Grace,Isabella", [1, 5, 4], 1], ["Elijah,Addison", [3, 6], 2], ["Willaim,Liam,Daniel,Alexander", [6, 4, 6, 2], 2], ["Avery,Olivai,Sophia,Michael,Elizabeth,Willaim,Liam", [5, 5, 3, 2, 1, 3, 6], 5], ["Liam,Madison,Lyli,Jacob,Matthew,Michael", [2, 6, 5, 5, 3, 4], 6], ["Sophia,Robert,Abigail,Grace,Lagon", [1, 2, 2, 6, 4], 5], ["Samantha,Ella", [5, 6], 1], ["Aubrey,Jayden", [3, 4], 2], ["Jacob,Elijah", [4, 3], 1]], "outputs": [["Benjamin"], ["Matthew"], ["Abigail"], ["Lagon"], ["Sophia"], ["Willaim"], ["Not enough participants"], ["No participants"], ["William"], ["Isabella"], ["Elijah"], ["Daniel"], ["Sophia"], ["Liam"], ["Sophia"], ["Samantha"], ["Aubrey"], ["Elijah"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 5,124 |
def rank(st, we, n):
|
35f7c9a2a23e91af2f12ed127a6b620d | UNKNOWN | Write a function named setAlarm which receives two parameters. The first parameter, employed, is true whenever you are employed and the second parameter, vacation is true whenever you are on vacation.
The function should return true if you are employed and not on vacation (because these are the circumstances under which you need to set an alarm). It should return false otherwise. Examples:
```if-not:julia,racket
setAlarm(true, true) -> false
setAlarm(false, true) -> false
setAlarm(false, false) -> false
setAlarm(true, false) -> true
``` | ["def set_alarm(employed, vacation):\n return employed and not vacation", "def set_alarm(employed, vacation):\n # Your code here\n if employed:\n if vacation:\n return False\n return True\n return False", "def set_alarm(employed, vacation):\n return employed==True and vacation==False", "set_alarm=lambda *a:a==(1,0)", "set_alarm=lambda *a:a==(1,0)\nset_alarm = lambda *a: a == (True, False) # [1]\nset_alarm = lambda employed, vacation: (employed, vacation) == (True, False) # [2]\nset_alarm = lambda employed, vacation: (employed == True) and (vacation == False)\nset_alarm = lambda employed, vacation: employed and not vacation\n\n# The most voted best practice solution:\n\ndef set_alarm(employed, vacation): # [3]\n return employed and not vacation #\n", "def set_alarm(employed, vacation):\n if employed and vacation is False:\n return True\n else:\n return False", "def set_alarm(employed, vacation):\n return True if employed is True and vacation is False else False", "def set_alarm(e, v):\n return False if e == True and v == True else False if e == False and v == True else False if e == False and v == False else True", "set_alarm=int.__gt__", "set_alarm=lambda e,v:e>v", "def set_alarm(employed, vacation):\n if employed == 1 and vacation == 0: return True\n else: return False", "def set_alarm(employed, vacation):\n return min(employed,employed!=vacation)", "def set_alarm(is_employed, on_vacation):\n return is_employed and not on_vacation", "# set_alarm = lambda employed,vacation:True if employed == True and vacation == False\ndef set_alarm(employed,vacation):\n if employed == True and vacation == False:\n return True\n else:\n return False\n", "def set_alarm(employed, vacation):\n if employed == vacation:\n return False \n return True if employed == True and vacation == False else False\n return False if employed == False and vacation == True else True", "set_alarm=lambda employed, vacation: False if employed==vacation else not vacation", "def set_alarm(employed, vacation):\n return ( True if employed and vacation is False else False) ", "def set_alarm(employed, vacation):\n while employed == True and vacation == True:\n return False\n while employed == False and vacation == True:\n return False\n while employed == True and vacation == False:\n return True\n while employed == False and vacation == False:\n return False\n \nset_alarm(True, True)", "def set_alarm(employed, vacation):\n return True if employed and not vacation else False", "def set_alarm(a, b):\n return a - b == 1", "def set_alarm(employed, vacation):\n return employed > vacation", "def set_alarm(employed, vacation):\n return employed & ~vacation", "set_alarm=lambda e,v:e>>v", "set_alarm=lambda e,v:e-v>0", "def set_alarm(employed, vacation):\n a = employed\n b = vacation\n \n if a == True:\n if b == False:\n return True\n if a == False:\n if b == False:\n return False\n if a == False and b == True:\n return False\n if a and b == True:\n return False\n \n\n\n\n\n# if a == True:\n# return True\n# if a and b == True:\n# return False\n# else:\n# return False\n", "from operator import rshift as set_alarm\n", "set_alarm=lambda e,v:e and not v", "def set_alarm(employed, vacation):\n # Your code here\n return True if employed == True and vacation == False else False", "def set_alarm(employed, vacation):\n if employed == vacation:\n return False\n if employed == True:\n return True\n return False", "def set_alarm(employed, vacation):\n if vacation == False and employed == True:\n return True\n return False\n", "def set_alarm(e,v):\n return False if e and v or e==False and v==True or [e,v]==[False,False] else True", "def set_alarm(employed, vacation):\n if employed == False and vacation == True:\n return False\n elif employed == True and vacation == False:\n return True\n else:\n return False", "def set_alarm(employed, vacation):\n boolean1 = employed\n boolean2 = vacation\n \n \n if boolean1 == True and boolean2 == False:\n return True\n else:\n return False", "def set_alarm(employed, vacation):\n return employed if not (employed == vacation == True) else False", "def set_alarm(employed, vacation):\n return employed^vacation and employed == True", "def set_alarm(employed, vacation):\n if employed == True:\n if vacation == True:\n return False\n if vacation == False:\n return True\n if employed == False:\n return False", "def set_alarm(em, va):\n if em == True and va == True:\n return False\n elif em == True and va == False:\n return True\n elif em == False and va == False:\n return False\n elif em == False and va == True:\n return False\n # Your code here\n", "def set_alarm(employed, vacation):\n if employed==True and vacation==True:\n alarma=False\n elif employed==False and vacation==True:\n alarma=False\n elif employed==False and vacation==False:\n alarma=False\n elif employed==True and vacation==False:\n alarma=True\n return alarma\n", "def set_alarm(employed, vacation):\n if employed == True and vacation == False:\n return True\n else:\n return False\n \n \"\"\" FIRST THOUGHT\n if employed == True and vacation == False:\n return True\n elif employed == True and vacation == True:\n return False\n elif employed == False and vacation == False:\n return False\n elif employed == \n \"\"\"", "def set_alarm(employed, vacation):\n if employed:\n if vacation:\n return False\n if employed:\n return True\n if vacation:\n return False\n else:\n return False", "def set_alarm(employed: bool, vacation: bool) -> bool:\n return employed == True and vacation == False", "def set_alarm(employed, vacation):\n return False if not employed and vacation else employed ^ vacation", "def set_alarm(e, v):\n return e&(e^v)", "def set_alarm(employed, vacation):\n import numpy\n return employed and not vacation", "def set_alarm(employed, vacation):\n if employed == True and vacation == True:\n return False\n elif employed == False and vacation == True:\n return False\n if employed == False and vacation == False:\n return False\n if employed == True and vacation == False:\n return True", "def set_alarm(employed, vacation):\n if employed==True and vacation==False:\n res = True\n else:\n res = False\n return res", "def set_alarm(employed, vacation):\n if employed == vacation or vacation == True:\n return False\n else:\n return True", "def set_alarm(f, s):\n return f == True and s == False", "set_alarm = lambda e, v: 1 if [1, 0] == [e, v] else 0", "def set_alarm(employed, vacation):\n return not(employed and vacation or not employed) ", "def set_alarm(employed, vacation):\n if vacation is True:\n return False\n else:\n if employed is True:\n return True\n return False", "def set_alarm(employed, vacation):\n # Your code here\n while employed == True:\n if vacation == True:\n return False\n else:\n return True\n return False", "def set_alarm(employed, vacation):\n return employed and not vacation # becomes True if employed and not on vacation", "def set_alarm(employed, vacation):\n if (employed == True) & (vacation == False):\n return True\n return False", "def set_alarm(employed, vacation):\n if vacation is True:\n return False\n elif employed == True:\n return True\n elif employed == False:\n return False", "set_alarm = lambda employed, vacation: employed ^ vacation and employed", "def set_alarm(e, vacation):\n return e and not vacation", "def set_alarm(employed, vacation):\n '''This code will return the overall boolean state of the alarm based upon the input parameters'''\n return True if employed==True and vacation==False else False", "def set_alarm(d,n):\n return d>n", "def set_alarm(employed, vacation):\n if(employed == True & vacation == True):\n return False\n if(employed == False & vacation == False):\n return False\n if(employed == False & vacation == True):\n return False\n else:\n return True", "def set_alarm(employed, vacation):\n a = employed\n b = vacation\n if a == True and b == True:\n return False\n if a == False and b == True:\n return False\n if a == False and b == False:\n return False\n if a == True and b == False:\n return True", "def set_alarm(employed, vacation):\n return employed and not vacation\n \n return false", "def set_alarm(employed, vacation):\n if (employed == True and vacation == True) or (employed== False and vacation == True) or (employed == False and vacation == False):\n return False\n elif employed == True and vacation == False:\n return True", "def set_alarm(employed, vacation):\n if employed == True and vacation == True:\n return False\n elif employed == False and vacation == False:\n return False\n elif employed == False:\n return False\n return True\n", "def set_alarm(employed, vacation):\n if employed == vacation:\n return False\n elif employed == False and vacation == True:\n return False\n else:\n return True", "def set_alarm(x, y):\n if x == True and y == True:\n return False\n elif x == False and y == True:\n return False\n elif x == False and y == False:\n return False\n else:\n return True", "def set_alarm(employed, vacation):\n if employed == False and vacation == True:\n return False\n else:\n return employed != vacation", "def set_alarm(employed, vacation):\n if employed == True and vacation == True:\n return False\n elif employed == False and vacation == True:\n return False\n elif employed == False and vacation == False:\n return False\n return True", "def set_alarm(employed, vacation):\n if employed != vacation:\n if employed == True:\n return True\n else:\n return False\n else: \n return False", "def set_alarm(employed, vacation):\n if employed == True and vacation == False:\n return True\n elif (employed == True and vacation == True) or (employed == False and vacation == True) or (employed == False and vacation == False):\n return False\n", "def set_alarm(employed, vacation):\n # Your code here\n if employed == True and vacation == True:\n return False\n elif employed == True and vacation == False:\n return True\n elif employed == False and vacation == True:\n return False\n elif employed == False and vacation == True:\n return False\n elif employed == False and vacation == False:\n return False", "def set_alarm(employed, vacation):\n return (False, True)[employed and not vacation]", "set_alarm = lambda employed,vacation: (employed,vacation) == (True,False)", "def set_alarm(employed, vacation):\n if employed == True:\n if vacation == True:\n return False\n else:\n return True\n elif employed == False:\n if vacation == True:\n return False\n else: \n return False\n", "def set_alarm(employed, vacation):\n if employed is True and vacation is True:\n return False\n if employed is False and vacation is True:\n return False\n if employed is True and vacation is False:\n return True\n if employed is False and vacation is False:\n return False\n", "def set_alarm(employed, vacation):\n \n result=''\n \n if employed==True and vacation==False:\n result=True\n else:\n result=False\n \n return result ", "import unittest\n\n\ndef set_alarm(employed, vacation):\n return employed and not vacation\n\n\nclass TestSetAlarm(unittest.TestCase):\n def test_should_return_false_when_employed_is_true_and_vacation_is_true(self):\n self.assertEqual(set_alarm(employed=True, vacation=True), False)\n\n def test_should_return_false_when_employed_is_false_and_vacation_is_false(self):\n self.assertEqual(set_alarm(employed=False, vacation=False), False)\n\n def test_should_return_false_when_employed_is_false_and_vacation_is_true(self):\n self.assertEqual(set_alarm(employed=False, vacation=True), False)\n\n def test_should_return_false_when_employed_is_true_and_vacation_is_false(self):\n self.assertEqual(set_alarm(employed=True, vacation=False), True)\n", "def set_alarm(employed, vacation):\n if vacation: return False\n if employed and vacation: return False\n if employed and not vacation: return True\n return False", "set_alarm = lambda a, b: a and a != b", "def set_alarm(employed, vacation):\n # Your code here\n if employed == True and vacation == True:\n return False \n else: \n return False if employed == False else True ", "def set_alarm(employed: bool, vacation: bool) -> bool:\n return (employed and not vacation)", "def set_alarm(employed, vacation):\n return (employed and True) and (not vacation and True)", "def set_alarm(employed, vacation):\n if employed == False:\n if vacation == True:\n return False\n if vacation == False:\n return False\n else:return bool(vacation) ^ bool(employed)", "def set_alarm(e, v):\n return e & (not v)", "def set_alarm(e, v):\n if e == True and v == True:\n return False\n elif e == False and v == True:\n return False\n elif e == False and v == False:\n return False\n elif e == True and v == False:\n return True", "def set_alarm(employed, vacation):\n # Your code here\n return False if employed == False else False if vacation == True else True", "def set_alarm(e, v):\n return False if e==v else e", "def set_alarm(employed, vacation):\n \n if vacation == True:\n return False\n \n if employed == False and vacation == False:\n return False\n \n else:\n return True", "def set_alarm(employed, vacation):\n # Your code here\n if employed:\n if vacation == False:\n return True\n if vacation:\n return False\n else:\n return False", "def set_alarm(employed, vacation):\n return (employed != vacation and employed ==1)", "def set_alarm(employed, vacation):\n x = (employed, vacation)\n if x == (True,False):\n return True\n return False", "def set_alarm(employed, vacation):\n # Your code here\n print (employed)\n if ( employed == True and vacation == False ) :\n return True\n else :\n return False", "def set_alarm(e, v):\n if e==True and v==True:\n return False\n elif e==True and v==False:\n return True\n elif e==False and v==True:\n return False\n else:\n return False", "def set_alarm(employed, vacation):\n return employed != vacation and employed == True", "def set_alarm(employed, vacation):\n s = ''\n if employed == True:\n if vacation == True:\n s = False\n else:\n s = True\n else:\n s = False\n return s", "def set_alarm(employed , vacation):\n return not employed if employed and employed == vacation else employed", "def set_alarm(employed, vacation) -> bool:\n # Your code here\n if employed == True and vacation == True:\n return False\n elif employed == True and vacation == False:\n return True\n elif employed == False and vacation == True:\n return False\n elif employed == False and vacation == False:\n return False", "def set_alarm(employed, vacation):\n return False if employed == False or employed and vacation == True else True", "def set_alarm(employed, vacation):\n if bool(employed) and not bool(vacation):\n return True\n else:\n return False", "set_alarm=lambda employed,vacation:employed!=vacation if employed else employed", "def set_alarm(e, v):\n if v == False and e == True:\n return True\n else:\n return False"] | {"fn_name": "set_alarm", "inputs": [[true, true], [false, true], [false, false], [true, false]], "outputs": [[false], [false], [false], [true]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 16,736 |
def set_alarm(employed, vacation):
|
b90bd24cf5f87ede00b3262e27583b9e | UNKNOWN | Calculus class...is awesome! But you are a programmer with no time for mindless repetition. Your teacher spent a whole day covering differentiation of polynomials, and by the time the bell rang, you had already conjured up a program to automate the process.
You realize that a polynomial of degree n
anx^(n) + an-1x^(n-1) + ... + a0
can be represented as an array of coefficients
[an, an-1, ..., a0]
For example, we would represent
5x^(2) + 2x + 1 as [5,2,1]
3x^(2) + 1 as [3,0,1]
x^(4) as [1,0,0,0,0]
x as [1, 0]
1 as [1]
Your function will take a coefficient array as an argument and return a **new array** representing the coefficients of the derivative.
```python
poly1 = [1, 1] # x + 1
diff(poly1) == [1] # 1
poly2 = [1, 1, 1] # x^2 + x + 1
diff(poly2) == [2, 1] # 2x + 1
diff(diff(poly2)) == [2] # 2
poly3 = [2, 1, 0, 0] # 2x^3 + x^2
diff(poly3) == [6, 2, 0] # 6x^2 + 2x
```
Note: your function will always return a new array which has one less element than the argument (unless the argument is [], in which case [] is returned). | ["def diff(poly):\n return [poly[i] * (len(poly)-1-i) for i in range(len(poly)-1)]", "def diff(poly):\n return [d*c for d,c in enumerate(poly[::-1]) if d][::-1]", "diff=lambda s:[i*j for i,j in enumerate(s[:-1][::-1],1)][::-1]", "def diff(poly):\n return [i * n for i, n in enumerate(poly[-2::-1], 1)][::-1]", "def diff(poly):\n return [-i * n for i, n in enumerate(poly[:-1], -len(poly)+1)]", "def diff(poly):\n return [i * x for i, x in enumerate(poly[::-1][1:], 1)][::-1]\n", "def diff(poly):\n return [poly[i]*(len(poly)-i-1) for i in range(len(poly)-1)]", "diff=lambda p:[i*f for i,f in enumerate(p[::-1])][:0:-1]", "def diff(poly):\n n = len(poly) - 1\n return [ a * (n - i) for i, a in enumerate(poly[:-1]) ]", "def diff(poly):\n n = len(poly) - 1\n poly = poly[:-1]\n return [x * (n - i) for i, x in enumerate(poly)]"] | {"fn_name": "diff", "inputs": [[[]]], "outputs": [[[]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 857 |
def diff(poly):
|
02b79ea6f50a198ee1242ee576673fa2 | UNKNOWN | Given is a md5 hash of a five digits long PIN. It is given as string.
Md5 is a function to hash your password:
"password123" ===> "482c811da5d5b4bc6d497ffa98491e38"
Why is this useful?
Hash functions like md5 can create a hash from string in a short time and it is impossible to find out the password, if you only got the hash. The only way is cracking it, means try every combination, hash it and compare it with the hash you want to crack. (There are also other ways of attacking md5 but that's another story)
Every Website and OS is storing their passwords as hashes, so if a hacker gets access to the database, he can do nothing, as long the password is safe enough.
What is a hash:
https://en.wikipedia.org/wiki/Hash_function#:~:text=A%20hash%20function%20is%20any,table%20called%20a%20hash%20table.
What is md5:
https://en.wikipedia.org/wiki/MD5
Note: Many languages have build in tools to hash md5. If not, you can write your own md5 function or google for an example.
Here is another kata on generating md5 hashes:
https://www.codewars.com/kata/password-hashes
Your task is to return the cracked PIN as string.
This is a little fun kata, to show you, how weak PINs are and how important a bruteforce protection is, if you create your own login.
If you liked this kata, here is an extension with short passwords:
https://www.codewars.com/kata/59146f7b4670ba520900000a | ["import hashlib\ndef crack(hash):\n for i in range(100000):\n if hashlib.md5(str(i).zfill(5).encode()).hexdigest() == hash:\n return str(i).zfill(5)", "from hashlib import md5\nfrom itertools import product\n\ndef crack(hash):\n for bs in map(bytes, product(b'0123456789', repeat=5)):\n if md5(bytes(bs)).hexdigest() == hash:\n return bs.decode()", "import hashlib\ndef create_crack(n):\n rainbow = {hashlib.md5(f'{a:05}'.encode()).hexdigest() : f'{a:05}' for a in range(10 ** n)}\n return rainbow.get\n\ncrack = create_crack(6)\n", "from itertools import product\nfrom string import digits\nfrom hashlib import md5\n\ncrack = {md5(pin.encode()).hexdigest():pin for pin in map(''.join, product(digits, repeat=5))}.get", "import hashlib \n \nlookup = [\n hashlib.md5(('0000' + str(i))[-5:].encode()).hexdigest()\n for i in range(100000)\n]\n \ndef crack(hash):\n index = lookup.index(hash)\n return ('0000' + str(index))[-5:]\n", "from hashlib import md5\n\ndef crack(hash):\n for pin in [str(x).rjust(5, '0') for x in range(0, 100000)]:\n if md5(pin.encode()).hexdigest() == hash:\n return pin", "import hashlib \n\ndef crack(hash):\n for i in range (0,99999):\n pin = digit_to_pin(i).encode()\n rand_hash = hashlib.md5(pin).hexdigest()\n if hash == rand_hash:\n return pin.decode()\n else:\n pass\n \ndef digit_to_pin(digit):\n string = str(digit)\n if len(string)<5:\n nulls = (5 - len(string))*\"0\"\n string = nulls + string\n return string", "from hashlib import md5\nfrom itertools import product\ndef crack(hash):\n digits = [str(x) for x in range(10)]\n return next(s for s in map(lambda tup:\"\".join(tup),product(digits,repeat=5)) if md5(bytes(s,\"utf-8\")).hexdigest()==hash)", "from hashlib import md5\n\ndef crack(hash):\n for i in range(10 ** 5):\n s = b\"%05d\" % i\n if md5(s).hexdigest() == hash:\n return s.decode()", "import hashlib\ndef crack(hash):\n return [str(x) for x in range(100000) if hashlib.md5(('{0:05}'.format(x)).encode()).hexdigest()== hash][0].zfill(5)\n"] | {"fn_name": "crack", "inputs": [["827ccb0eea8a706c4c34a16891f84e7b"], ["86aa400b65433b608a9db30070ec60cd"]], "outputs": [["12345"], ["00078"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,194 |
def crack(hash):
|
6eb8e5652df43734433de1e369bf3f75 | UNKNOWN | # Task
After a long night (work, play, study) you find yourself sleeping on a bench in a park. As you wake up and try to figure out what happened you start counting trees.
You notice there are different tree sizes but there's always one size which is unbalanced. For example there are 2 size 2, 2 size 1 and 1 size 3. (then the size 3 is unbalanced)
Given an array representing different tree sizes. Which one is the unbalanced size.
Notes:
```
There can be any number of sizes but one is always unbalanced
The unbalanced size is always one less than the other sizes
The array is not ordered (nor the trees)```
# Examples
For `trees = [1,1,2,2,3]`, the result should be `3`.
For `trees = [2,2,2,56,56,56,8,8]`, the result should be `8`.
For `trees = [34,76,12,99,64,99,76,12,34]`, the result should be `64`.
# Input/Output
- `[input]` integer array `trees`
Array representing different tree sizes
- `[output]` an integer
The size of the missing tree. | ["def find_the_missing_tree(trees):\n return sorted(trees, key=trees.count)[0]", "from collections import Counter\ndef find_the_missing_tree(trees):\n return Counter(trees).most_common()[-1][0] ", "def find_the_missing_tree(trees):\n return min(trees, key = lambda n: trees.count(n))", "def find_the_missing_tree(trees):\n return -sum(trees) % sum(set(trees))", "def find_the_missing_tree(trees):\n sum_of_all_trees = sum(trees)\n sum_of_unique_trees = sum(set(trees))\n count = sum_of_all_trees // sum_of_unique_trees + 1\n return count * sum_of_unique_trees - sum_of_all_trees", "from collections import Counter\n\ndef find_the_missing_tree(trees):\n counter = Counter(trees)\n return min(counter.keys(), key=counter.get)", "from collections import Counter\n\ndef find_the_missing_tree(trees):\n return min(Counter(trees).most_common(), key=lambda x: x[1])[0]", "from collections import Counter\ndef find_the_missing_tree(trees):\n a = Counter(trees)\n a = str(a)\n #create list of counter \n a_s = (a.split())\n l_a = len(a_s)\n dd_a = str(a_s[l_a - 2])\n res_str = dd_a.translate({ord(i): None for i in ':'})\n res_int = int(res_str)\n return res_int", "from collections import Counter\ndef find_the_missing_tree(trees):\n c=Counter(trees)\n odd=[k for k,v in c.items() if v%2]\n even=[k for k,v in c.items() if v%2==0]\n return even[0] if len(even)==1 else odd[0]", "import collections\n\ndef find_the_missing_tree(trees):\n count = collections.Counter( trees )\n return min( count, key = count.get )\n"] | {"fn_name": "find_the_missing_tree", "inputs": [[[1, 2, 2, 3, 3]], [[11, 2, 3, 3, 3, 11, 2, 2]], [[234, 76, 45, 99, 99, 99, 99, 45, 234, 234, 45, 45, 76, 234, 76]], [[1, 1, 1, 1, 1, 1, 1, 22, 22, 22, 22, 22, 22, 22, 3, 3, 3, 3, 3, 3]], [[10, 205, 3000, 3000, 10]], [[50, 408, 50, 50, 50, 50, 408, 408, 408, 680, 408, 680, 50, 408, 680, 50, 50, 680, 408, 680, 50, 680, 680, 408, 408, 50, 50, 408, 50, 50, 50, 50, 680, 408, 680, 50, 680, 408, 680, 408, 680, 50, 50, 50, 680, 50, 680, 408, 680, 680, 680, 408, 408, 408, 408, 680, 680, 50, 408, 408, 408, 50, 408, 408, 50, 680, 680, 680, 50, 680, 680, 680, 50, 680, 408, 50, 50, 408, 50, 408, 680, 408, 50, 680, 680, 408, 408, 680, 408]]], "outputs": [[1], [11], [76], [3], [205], [50]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,588 |
def find_the_missing_tree(trees):
|
0ee8b92fbc14be07b942a04ff69773d7 | UNKNOWN | You probably know the 42 number as "The answer to life, the universe and everything" according to Douglas Adams' "The Hitchhiker's Guide to the Galaxy". For Freud, the answer was quite different.
In the society he lived in, people-women in particular- had to repress their sexual needs and desires. This was simply how the society was at the time.
Freud then wanted to study the illnesses created by this, and so he digged to the root of their desires. This led to some of the most important psychoanalytic theories to this day, Freud being the father of psychoanalysis.
Now, basically, when a person hears about Freud, s/he hears "sex" because for Freud, everything was basically related to, and explained by sex.
In this kata, the toFreud() function will take a string as its argument, and return a string with every word replaced by the explanation to everything, according to Freud. Note that an empty string, or no arguments, should result in the ouput being ""(empty string). | ["def to_freud(sentence):\n return ' '.join('sex' for _ in sentence.split())\n", "def to_freud(s):\n return (len(s.split()) * \"sex \").strip()", "def to_freud(sentence):\n words = sentence.split()\n wordcount = len(words)\n print(wordcount)\n s = \"\"\n while wordcount > 0:\n s = s + \"sex \"\n wordcount -= 1\n return s[:-1]\n \n \n", "def to_freud(sentence):\n words = sentence.split()\n wordcount = len(words)\n s = \"\"\n while wordcount > 0:\n s = s + \"sex \"\n wordcount -= 1\n return s[:-1]\n", "def to_freud(sentence):\n import re\n return re.sub('\\S+','sex',sentence)\n", "def to_freud(sentence):\n word=sentence.split()\n a=len(word)\n print(a)\n s=\"\"\n while a > 0:\n s=s+\"sex \"\n a-=1\n return s[:-1]\n \n\n \n", "def to_freud(sentence):\n word = sentence.split()\n wordcount = len(word)\n print(wordcount)\n s = \"\"\n while wordcount > 0:\n s = s + \"sex \"\n wordcount -= 1\n return s[:-1]", "def to_freud(sentence):\n words = sentence.split()\n wordscount = len(words)\n print(wordscount)\n s = \"\"\n while wordscount > 0:\n s = s + \"sex \"\n wordscount -= 1\n return s[:-1]", "def to_freud(sentence):\n words = sentence.split()\n wordcount = len(words)\n s = \"\"\n while wordcount > 0:\n s += \"sex \"\n wordcount -= 1\n return s[:-1]", "def to_freud(sentence):\n sentence = sentence.split()\n sentence = [\"sex\" for i in range(len(sentence))]\n sentence = \" \".join(sentence)\n return sentence", "def to_freud(s):\n return \" \".join(\"sex\" for _ in s.split())\n", "def to_freud(sentence):\n return ' '.join(['sex']*len(sentence.split(' ')))", "def to_freud(sentence):\n return \" \".join(\"sex\" for i in sentence.split())", "to_freud = __import__(\"functools\").partial(__import__(\"re\").compile(r\"\\S+\").sub, \"sex\")", "to_freud = lambda s: (\"sex \"*len(s.split()))[:-1]", "to_freud = lambda s: \" \".join([\"sex\"] * len(s.split()))", "def to_freud(sentence):\n n = sentence.count(\" \")\n s = \"sex\"\n for i in range(0, n): \n s += \" sex\"\n return s", "def to_freud(sentence):\n\n return (len(sentence.split()) * 'sex ').strip()\n #your code here\n", "from re import sub\n\ndef to_freud(sentence: str) -> str:\n \"\"\" Replace every word in the sentece by `sex`. \"\"\"\n return sub(r\"\\b[\\w\\'']+\\b\", \"sex\", sentence)", "to_freud=lambda s:(' sex'*-~s.count(' '))[1:]", "def to_freud(sentence):\n return (\"sex \" * len(sentence.split())).rstrip()", "def to_freud(sentence):\n #your code here\n return (\"sex \" * len(sentence.split(' '))).strip()", "def to_freud(sentence):\n wordCount = len(sentence.split(\" \"))\n list = [\"sex\"] * wordCount\n return \" \".join(list)", "to_freud = lambda sentence: \" \".join(map(lambda x: \"sex\", sentence.split(\" \")))", "def to_freud(sentence):\n return ' '.join(__import__('itertools').repeat('sex', len(sentence.split())))", "def to_freud(sentence):\n return ('sex ' * len(sentence.split()) )[:-1]", "def to_freud(sentence):\n return ' '.join('sex' for i in range(len(sentence.split(' '))))", "def to_freud(sentence):\n return ' '.join(['sex' if len(sentence) > 1 else '' for i in sentence.split()])", "def to_freud(sentence):\n return \" \".join(\"sex\" for x in sentence.split())", "def to_freud(s):\n return ' '.join(map(lambda x: 'sex', s.split()))", "def to_freud(sentence):\n #your code here\n return ' '.join(\"sex\" for x in sentence.split(\" \" or \",\"))", "def to_freud(sentence):\n i = 0\n for x in sentence.split():\n i += 1\n return (i * \"sex \").strip()", "def to_freud(sentence):\n sex = []\n split = sentence.split()\n for i in split:\n sex.append(\"sex\")\n return ' '.join(sex)\n", "from re import sub\n\ndef to_freud(sentence: str) -> str:\n \"\"\" Replace every word in the sentece by `sex`. \"\"\"\n return sub(\"\\S+\", \"sex\", sentence)", "def to_freud(sentence):\n return ' '.join(word.replace(word, 'sex') for word in sentence.split(' '))", "def to_freud(s):\n return \" \".join(\"sex\" for _ in range(len(s.split())))", "def to_freud(sentence):\n #your code here\n return ' '.join([ i.replace(i, 'sex') for i in sentence.split(' ')])\n", "def to_freud(sentence):\n x = len(sentence.split(' '))\n return ('sex '* x).rstrip()", "def to_freud(sentence):\n return ' '.join((sentence.count(' ')+1)*[\"sex\"]) if sentence else \"\"", "def to_freud(sentence):\n a = len(sentence.split(' '))*'sex '\n return a.rstrip()", "def to_freud(s):\n l=s.split(\" \")\n return \" \".join(\"sex\" for i in l)", "def to_freud(sentence):\n a=sentence.split(\" \")\n b='sex ' * len(a)\n return b.strip()", "def to_freud(sentence):\n arr=sentence.split(\" \")\n for i in range(0,len(arr)):\n arr[i]=\"sex\"\n return \" \".join(arr)", "def to_freud(sentence):\n x = sentence.split()\n new = 'sex'\n for y in range(len(x) - 1) :\n new = new + \" \" + 'sex'\n return new", "def to_freud(sentence):\n result = ''\n for i in sentence.split(' '):\n result += 'sex '\n return result.rstrip(' ')\n #return [\"sex\" for i in sentence.split(' ')]\n", "def to_freud(sentence):\n sentence = sentence.split()\n a = \"\"\n for el in sentence:\n el = \"sex\"\n a += el + \" \"\n return a[:-1]", "def to_freud(sen):\n return \" \".join([\"sex\" for i in range(len(sen.split(\" \")))])", "def to_freud(sentence):\n res = \"\"\n my_list = sentence.split(' ')\n for i in range(len(my_list)):\n res += \"sex \"\n return res[:-1]", "def to_freud(sentence):\n result = ''\n new_sentence = sentence.split(' ')\n for word in range(len(new_sentence)):\n new_sentence[word] = 'sex'\n result += new_sentence[word] + ' '\n return result[:-1]", "def to_freud(sentence):\n ss = sentence.split()\n sex = []\n for i in range(len(ss)):\n sex.append('sex')\n a = ' '.join(sex)\n return a", "def to_freud(sentence):\n l = len(sentence.split(\" \"))\n return ' '.join([\"sex\" for _ in range(l)])", "def to_freud(sentence):\n a = sentence.split(\" \")\n b = \"\"\n for i in a:\n if not b:\n b += \"sex \"\n else:\n b+= \"sex \"\n if b[-1] == \" \":\n return b[:-1]\n else:\n return b", "def to_freud(sentence):\n return \"\" if sentence==\"\" else \"sex \"*(len(sentence.split())-1) +\"sex\" ", "def to_freud(sentence):\n l = sentence.split()\n s = ['sex'] * len(l)\n return ' '.join(s)", "def to_freud(sentence):\n return (len(sentence.split()) * 'sex ' if sentence else '')[:-1]", "def to_freud(sentence):\n n = len(sentence.split(\" \"))\n return (\"sex \"*n).strip(\" \")", "def to_freud(sentence):\n sent=sentence.split()\n ans=''\n for i in sent:\n ans=ans+'sex '\n return ans[:len(ans)-1]\n", "def to_freud(sentence):\n try:\n res = []\n for i in range(len(sentence.split())):\n res.append('sex')\n return ' '.join(res)\n except:\n return ''", "def to_freud(sentence):\n msg = ' '.join('sex' for _ in sentence.split())\n return msg", "def to_freud(sentence):\n sentence = sentence.split()\n return ('sex ' * len(sentence))[:-1]", "def to_freud(sentence):\n if sentence is not None:\n return ' '.join(map(lambda x: 'sex', sentence.split(' ')))\n return ''", "def to_freud(sentence):\n words = sentence.split(\" \")\n return \" \".join([\"sex\" for i in range(len(words))]) ", "def to_freud(sentence):\n x=sentence.split()\n sum=''\n for y in x:\n sum+='sex '\n return sum.rstrip(' ')\n", "def to_freud(sentence):\n return ' '.join('sex' for el in sentence.split(' ') )", "def to_freud(sentence):\n count = len(sentence.split())\n s = \"sex \" * count\n return (s[:-1])", "def to_freud(sentence):\n list = sentence.split(' ')\n return ' '.join(['sex' for i in range(len(list))])", "def to_freud(sentence):\n sentence = sentence.split(\" \")\n a= len(sentence)\n b = a - 1\n return b * \"sex \" +\"sex\"", "def to_freud(sentence):\n count = len(sentence.split())\n return ('sex '*count)[:-1]", "def to_freud(sentence):\n answer = []\n string = sentence.split()\n for word in string:\n x = word.replace(word, 'sex')\n answer.append(x)\n return ' '.join(answer)", "def to_freud(sentence):\n repeats = len(sentence.split(' '))\n return ' '.join(['sex'] * repeats)", "def to_freud(sentence):\n count = len([i for i in sentence.split()])\n return ' '.join(['sex' for i in range(0, count)])", "def to_freud(sentence):\n x = 'sex ' * len(sentence.split())\n return x.rstrip()", "to_freud = lambda sentence: ' '.join('sex' for i in sentence.split())", "def to_freud(sentence):\n words = sentence.split(' ')\n made_string = str(''.join('sex ' * len(words)))\n return made_string.rstrip()", "def to_freud(sentence):\n result = ''\n for i in range(len(sentence.split(' '))):\n result+='sex '\n return result[:-1]", "def to_freud(sentence):\n if sentence == \"\":\n return \"\"\n lista = sentence.split(' ')\n output = 'sex ' * len(lista)\n return output[:-1]", "def to_freud(sentence):\n return ' '.join(['sex' for elem in sentence.split()])", "def to_freud(sentence):\n sentence = ['sex' for word in sentence.split(' ')]\n return ' '.join(sentence)", "def to_freud(sentence):\n ctr = 0\n try:\n cunt = sentence.split()\n for fuck in cunt:\n cunt[ctr] = \"sex\"\n ctr += 1\n return ' '.join(cunt)\n except:\n \"(empty string)\"", "def to_freud(sentence: str) -> str:\n return ' '.join(\"sex\" for _ in sentence.split())\n", "def to_freud(sentence):\n return ' '.join('sex' for i in range(1, len(sentence.split(' '))+1))", "def to_freud(sentence):\n if len(sentence):\n a=sentence.count(' ')+1\n return(('sex '*a).strip())\n else:\n return ''", "to_freud=lambda s:('sex '*len(s.split())).rstrip()", "def to_freud(sentence):\n return ' '.join(['sex' for i in range(sentence.count(' ')+1)])", "def to_freud(sentence):\n s = sentence.count(' ')\n d = ('sex ') * (s) + ('sex')\n \n return d", "def to_freud(x):\n s=x.split()\n d=['sex '*len(s)]\n return x if x=='' else ' '.join(d)[:-1]", "def to_freud(sentence):\n word = ' sex'\n if sentence.count(' ') == 0:\n return 'sex'\n elif sentence.count(' ') >= 1:\n return 'sex' + word * sentence.count(' ')\n \n", "def to_freud(sentence):\n return \"\" if not sentence else ' '.join('sex' for elem in sentence.split() if elem.isalpha() or \"'\" in elem)\n #your code here\n", "def to_freud(sentence):\n if not sentence:\n return ''\n \n return ' '.join(len(sentence.split(' ')) * ['sex'])", "def to_freud(sentence):\n array = []\n for word in sentence.split(' '):\n array.append('sex')\n return ' '.join(array)", "def to_freud(sentence):\n a = sentence.split(\" \")\n return (len(a) - 1) * \"sex \" + \"sex\"", "def to_freud(sentence):\n res = [\"sex\"]\n a = list(sentence).count(\" \")\n for i in range(a):\n res.append(\"sex\")\n return \" \".join(res)\n #your code here\n", "def to_freud(sentence):\n new2=\"\"\n for each in range(len(sentence.split())):\n new2+=\"sex \" \n return new2.rstrip()\n \n", "def to_freud(sentence):\n a = sentence.split(' ')\n for i in range(len(a)):\n a[i] = 'sex'\n return \" \".join(a)\n", "def to_freud(sentence):\n #your code here\n a = ''\n for i in range(len(sentence.split())):\n a += 'sex '\n return a[:-1]", "def to_freud(sentence):\n sentence = sentence.split()\n return ' '.join(['sex' for i in sentence])", "def to_freud(sentence):\n s1 = sentence.split(\" \")\n return ' '.join(['sex']*len(s1))\n", "def to_freud(s):\n return (len(s.split())*' sex ')[1:-1].replace(' ',' ')", "def to_freud(sentence):\n return ' '.join('sex' for x in range(len(sentence.split())))", "def to_freud(sentence):\n return ' '.join(['sex' for x in sentence.split()])\n # Flez\n"] | {"fn_name": "to_freud", "inputs": [["test"], ["sexy sex"], ["This is a test"], ["This is a longer test"], ["You're becoming a true freudian expert"]], "outputs": [["sex"], ["sex sex"], ["sex sex sex sex"], ["sex sex sex sex sex"], ["sex sex sex sex sex sex"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 12,322 |
def to_freud(sentence):
|
b86d0ea1fd830496eccb0246f2aae817 | UNKNOWN | # Making Change
Complete the method that will determine the minimum number of coins needed to make change for a given amount in American currency.
Coins used will be half-dollars, quarters, dimes, nickels, and pennies, worth 50¢, 25¢, 10¢, 5¢ and 1¢, respectively. They'll be represented by the symbols `H`, `Q`, `D`, `N` and `P` (symbols in Ruby, strings in in other languages)
The argument passed in will be an integer representing the value in cents. The return value should be a hash/dictionary/object with the symbols as keys, and the numbers of coins as values. Coins that are not used should not be included in the hash. If the argument passed in is 0, then the method should return an empty hash.
## Examples
```python
make_change(0) #--> {}
make_change(1) #--> {"P":1}
make_change(43) #--> {"Q":1, "D":1, "N":1, "P":3}
make_change(91) #--> {"H":1, "Q":1, "D":1, "N":1, "P":1}
```
#### **If you liked this kata, check out [Part 2](https://www.codewars.com/kata/making-change-part-2/ruby).** | ["BASE = {\"H\": 50, \"Q\": 25, \"D\": 10, \"N\": 5, \"P\": 1}\n\ndef make_change(n):\n r = {}\n for x, y in BASE.items():\n if n >= y:\n r[x], n = divmod(n, y)\n return r", "def make_change(amount):\n H = 50\n Q = 25\n D = 10\n N = 5\n P = 1\n change = {}\n while amount > 0: \n if (amount - H) >= 0:\n change[\"H\"] = 1\n amount -= H\n while amount >= H:\n change[\"H\"] += 1\n amount -= H\n elif (amount - Q) >= 0:\n change[\"Q\"] = 1\n amount -= Q\n while amount >= Q:\n change[\"Q\"] += 1\n amount -= Q\n elif (amount - D) >= 0:\n change[\"D\"] = 1\n amount -= D\n while amount >= D:\n change[\"D\"] += 1\n amount -= D\n elif (amount - N) >= 0:\n change[\"N\"] = 1\n amount -= N\n while amount >= N:\n change[\"N\"] += 1\n amount -= N\n elif (amount - P) >= 0:\n change[\"P\"] = 1\n amount -= P\n while amount >= P:\n change[\"P\"] += 1\n amount -= P \n else: \n return change\n return change ", "COINS = dict(H=50, Q=25, D=10, N=5, P=1)\n\n\ndef make_change(amount):\n result = {}\n for coin, value in COINS.items():\n if amount >= value:\n result[coin], amount = divmod(amount, value)\n return result", "def make_change(amount):\n coins = {'H':50,'Q':25,'D':10,'N':5,'P':1}\n change = {}\n for coin in coins:\n if amount >= coins[coin]:\n change[coin], amount = divmod(amount, coins[coin])\n return change", "from collections import defaultdict\n\ncoins = (\n (\"H\", 50),\n (\"Q\", 25),\n (\"D\", 10),\n (\"N\", 5),\n (\"P\", 1),\n)\n\ndef make_change(amount):\n result = defaultdict(int)\n for coin, value in coins:\n while amount >= value:\n result[coin] += 1\n amount -= value\n return result\n", "def make_change(amount):\n coins = {\n 'H' : 50,\n 'Q' : 25,\n 'D' : 10,\n 'N' : 5,\n 'P' : 1\n }\n \n dict = {}\n \n for key in coins:\n if amount >= coins[key]:\n dict[key], amount = divmod(amount, coins[key])\n \n return dict", "def make_change(amount):\n H = 50\n Q = 25\n D = 10\n N = 5\n P = 1\n change = {}\n while amount > 0: \n if (amount - H) >= 0:\n change[\"H\"] = 1\n amount -= H\n while amount >= H:\n change[\"H\"] += 1\n amount -= H\n if amount < H:\n continue\n elif (amount - Q) >= 0:\n change[\"Q\"] = 1\n amount -= Q\n while amount >= Q:\n change[\"Q\"] += 1\n amount -= Q\n if amount < Q:\n continue\n elif (amount - D) >= 0:\n change[\"D\"] = 1\n amount -= D\n while amount >= D:\n change[\"D\"] += 1\n amount -= D\n if amount < Q:\n continue\n elif (amount - N) >= 0:\n change[\"N\"] = 1\n amount -= N\n while amount >= N:\n change[\"N\"] += 1\n amount -= N\n if amount < N :\n continue\n elif (amount - P) >= 0:\n change[\"P\"] = 1\n amount -= P\n while amount >= P:\n change[\"P\"] += 1\n amount -= P\n if amount < P:\n return change \n else: \n return change\n return change ", "coins = (('H', 50), ('Q', 25), ('D', 10), ('N', 5), ('P', 1))\n\ndef make_change(amount):\n result = {}\n for x,y in coins:\n q, amount = divmod(amount, y)\n if q: result[x] = q\n if not amount: return result", "def make_change(amount):\n result = {}\n if amount == 0:\n return result\n else:\n halves = amount // 50\n remainder = amount % 50\n quarters = remainder // 25\n remainder = remainder % 25\n dimes = remainder // 10\n remainder = remainder % 10\n nickels = remainder // 5\n pennies = remainder % 5\n if halves > 0:\n result['H'] = halves\n if quarters > 0:\n result['Q'] = quarters\n if dimes > 0:\n result['D'] = dimes\n if nickels > 0:\n result['N'] = nickels\n if pennies > 0:\n result['P'] = pennies\n return result", "d = [(\"H\",50),(\"Q\",25),(\"D\",10),(\"N\",5),(\"P\",1)]\nmake_change=lambda m,i=0,cng=[]:make_change(*([m%d[i][1],i+1,cng+[(d[i][0],m//d[i][1])]] if m>=d[i][1] else [m,i+1,cng])) if m else dict(cng)\n\n'''cng = {}\nfor i,j in d.items():\n if money>=j:\n cng[i] = money//j\n money %= j\nreturn cng'''"] | {"fn_name": "make_change", "inputs": [[0], [1], [5], [43], [91], [101], [239]], "outputs": [[{}], [{"P": 1}], [{"N": 1}], [{"Q": 1, "D": 1, "N": 1, "P": 3}], [{"H": 1, "Q": 1, "D": 1, "N": 1, "P": 1}], [{"H": 2, "P": 1}], [{"H": 4, "Q": 1, "D": 1, "P": 4}]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 5,219 |
def make_change(amount):
|
f87dd37035b325be28dd1292fadbfab1 | UNKNOWN | A very easy task for you!
You have to create a method, that corrects a given date string.
There was a problem in addition, so many of the date strings are broken.
Date-Format is european. That means "DD.MM.YYYY".
Some examples:
"30.02.2016" -> "01.03.2016"
"40.06.2015" -> "10.07.2015"
"11.13.2014" -> "11.01.2015"
"99.11.2010" -> "07.02.2011"
If the input-string is null or empty return exactly this value!
If the date-string-format is invalid, return null.
Hint: Correct first the month and then the day!
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. | ["import re\nfrom datetime import date, timedelta\n\ndef date_correct(text):\n if not text:\n return text\n try:\n d, m, y = map(int, re.match(r'^(\\d{2})\\.(\\d{2})\\.(\\d{4})$', text).groups())\n mo, m = divmod(m - 1, 12)\n return (date(y + mo, m + 1, 1) + timedelta(days=d - 1)).strftime('%d.%m.%Y')\n except AttributeError:\n return None", "import datetime as dt\nimport re\n\ndef date_correct(date):\n if isinstance(date,str) and re.fullmatch(r'\\d\\d\\.\\d\\d\\.\\d{4}', date):\n d,m,y = map(int,date.split('.'))\n nM,m = divmod(m-1,12) ; y+=nM ; m+=1\n d = dt.date(y,m,1) + dt.timedelta(days=d-1)\n return f'{d.day:02}.{d.month:02}.{d.year:02}'\n if date=='': return \"\"", "from datetime import date, timedelta\nget_date = __import__(\"re\").compile(r\"(\\d\\d)\\.(\\d\\d)\\.(\\d\\d\\d\\d)\").search\n\ndef date_correct(my_date):\n if not my_date: return my_date\n try: d, m, y = map(int, get_date(my_date).groups())\n except AttributeError: return\n return (date(y+(m-1)//12, (m-1)%12+1, 1) + timedelta(d-1)).strftime(\"%d.%m.%Y\")", "import datetime\nimport re\ndef date_correct(date):\n if not date:\n return date\n if not re.fullmatch(r'(\\d\\d\\.){2}\\d{4}',date):\n return None\n d,m,y = [int(x) for x in date.split('.')]\n if m>12:\n y += m // 12\n m %= 12\n if not m:\n m = 12\n y -= 1\n return (datetime.datetime(year=y,month=m,day=1)+datetime.timedelta(days=d-1)).strftime(\"%d.%m.%Y\")\n", "from datetime import date,timedelta\nimport re\n\ndef date_correct(s):\n if s=='': return ''\n try: m=re.match(r'\\A(\\d{2})\\.(\\d{2})\\.(\\d{4})\\Z',s)\n except: return None\n if not m: return None\n d,m,y=map(int,m.groups())\n d-=1\n cy,m=divmod(m-1,12)\n return (date(y+cy,m+1,1)+timedelta(d)).strftime('%d.%m.%Y')", "def date_correct(date):\n if date in (\"\", 0, None):\n return date\n \n from re import findall\n date = findall(\"\\A(\\d{2})\\.(\\d{2})\\.(\\d{4})\\Z\", date)\n \n if len(date) == 0:\n return None\n \n import datetime\n date = [int(x) for x in date[0][::-1]]\n date[0] += (date[1] - 1) // 12\n date[1] = (date[1] - 1) % 12 + 1\n \n newdate = datetime.date(date[0], date[1], 1)\n newdate += datetime.timedelta(days = date[2] - 1)\n \n return \"{0:02d}.{1:02d}.{2}\".format(newdate.day, newdate.month, newdate.year)", "from re import match; from datetime import date as ymd, timedelta; date_correct=lambda date: \"\" if date==\"\" else None if date==None or not match(\"\\d\\d\\.\\d\\d\\.\\d{4}\",date or \"\") else (lambda d,m,y: (ymd(y+(m-1)//12,(m-1)%12+1,1)+timedelta(d-1)).strftime(\"%d.%m.%Y\"))(*map(int, date.split(\".\")))", "from datetime import datetime,timedelta\nfrom re import fullmatch\ndef date_correct(date):\n if isinstance(date,str):\n if not date:return \"\"\n if fullmatch(\"\\d{2}\\.\\d{2}\\.\\d{4}\",date):\n day,month,year=map(int,date.split(\".\"))\n extra_year,month=divmod(month-1,12)\n return (datetime(year+extra_year,month+1,1)+timedelta(day-1)).strftime(\"%d.%m.%Y\")", "import datetime\ndef date_correct(date):\n print(date)\n if date is None or date is '':\n return date\n try:\n day, month, year = date.split('.')\n if len(day) is not 2 or len(month) is not 2:\n return None\n day = int(day)\n month = int(month)\n year = int(year)\n except:\n return None\n extra_years = month // 12\n if month >= 12 and month % 12 == 0:\n extra_years -=1\n year = year + extra_years\n correct_months = month % 12\n if correct_months == 0:\n correct_months = 12\n print(date, year, correct_months)\n result = datetime.datetime(year=year, month=correct_months, day=1)\n result += datetime.timedelta(days=day-1)\n print(result)\n return '.'.join([str(value).zfill(2) for value in [result.day, result.month, result.year] ])", "import re\n\ndef date_correct(date):\n if not date : return date\n days=[31,28,31,30,31,30,31,31,30,31,30,31]\n if not bool(re.match(r\"\\d{2}\\.\\d{2}\\.\\d{4}\",date)) : return None\n d,m,y=list(map(int,date.split(\".\")))\n \n while m>12 or d>days[m-1]:\n y+=(m-1)//12\n m=(m-1)%12+1\n if (y%4==0 and y%100!=0) or y%400==0:\n days[1]=29\n else : days[1]=28\n if d>days[m-1]:\n d-=days[m-1]\n m+=1\n \n return \"{:02}.{:02}.{}\".format(d,m,y)\n"] | {"fn_name": "date_correct", "inputs": [[null], [""], ["01112016"], ["01,11,2016"], ["0a.1c.2016"], ["03.12.2016"], ["30.02.2016"], ["40.06.2015"], ["11.13.2014"], ["33.13.2014"], ["99.11.2010"]], "outputs": [[null], [""], [null], [null], [null], ["03.12.2016"], ["01.03.2016"], ["10.07.2015"], ["11.01.2015"], ["02.02.2015"], ["07.02.2011"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,645 |
def date_correct(date):
|
c65447e73b79fb2f06a2202b41320460 | UNKNOWN | An array is said to be `hollow` if it contains `3` or more `0`s in the middle that are preceded and followed by the same number of non-zero elements. Furthermore, all the zeroes in the array must be in the middle of the array.
Write a function named `isHollow`/`is_hollow`/`IsHollow` that accepts an integer array and returns `true` if it is a hollow array,else `false`. | ["def is_hollow(x):\n while x and x[0] != 0 and x[-1] != 0: x = x[1:-1]\n return len(x) > 2 and set(x) == {0}", "from itertools import groupby\nfrom operator import not_\n\ndef is_hollow(a):\n b = [(x, [*y]) for x, y in groupby(a, key=not_)]\n return len(b) == 1 and b[0][0] and len(b[0][1]) > 2 or len(b) == 3 and [x for x, _ in b] == [0, 1, 0] and len(b[1][1]) > 2 and len(b[0][1]) == len(b[2][1])", "from itertools import groupby\n\ndef is_hollow(x):\n xs = [(key, sum(1 for _ in grp)) for key, grp in groupby(x)]\n mid = len(xs) // 2\n limit = len(xs) - (len(xs) > 1)\n return (\n any(\n i == mid < limit\n for i, (x, cnt) in enumerate(xs) if x == 0 and cnt >= 3\n ) and sum(x == 0 for x, _ in xs) == 1\n )\n", "def is_hollow(x):\n return len(x) > 2 and (x[0] and x[-1] and is_hollow(x[1:-1]) or set(x) == {0})", "from re import match\n\ndef is_hollow(x):\n return bool(match(r'(x*)[0]{3,}\\1$', ''.join('x' if v else '0' for v in x)))", "def is_hollow(x):\n if len(x)<3:\n return False\n z = 0 \n for i,(a,b) in enumerate(zip(x,x[::-1])):\n if i>len(x)//2:\n return z>=2\n if (a==0) != (b==0):\n return False\n if a!=0 and z>0:\n return False\n if a==0:\n z += 1\n elif z>0:\n return False", "def is_hollow(A):\n while A and A[0]*A[-1]!=0:A=A[1:-1]\n return 2<A.count(0)and set(A)=={0}", "import re\ndef is_hollow(x):\n return True if re.match('^(1*)0{3,}\\\\1$',''.join('0' if i==0 else '1' for i in x)) else False", "def is_hollow(x):\n # Find the limits of the centre zeroes\n i = j = len(x) // 2\n while i > 0 and x[i - 1] == 0:\n i -= 1\n while j < len(x) and x[j] == 0:\n j += 1\n # Grab the 'ends'\n prefix = x[:i]\n suffix = x[j:]\n # Check conditions\n return not (j - i < 3 or 0 in prefix + suffix or len(prefix) != len(suffix))\n"] | {"fn_name": "is_hollow", "inputs": [[[-1, 0, 0, 0, 3]], [[1, 0, 0, 0, 0]]], "outputs": [[true], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,975 |
def is_hollow(x):
|
81cb4dc9847b27e0e5174eb42d43dbcc | UNKNOWN | A number is self-descriptive when the n'th digit describes the amount n appears in the number.
E.g. 21200:
There are two 0's in the number, so the first digit is 2.
There is one 1 in the number, so the second digit is 1.
There are two 2's in the number, so the third digit is 2.
There are no 3's in the number, so the fourth digit is 0.
There are no 4's in the number, so the fifth digit is 0
Numbers can be of any length up to 9 digits and are only full integers. For a given number derive a function ```selfDescriptive(num)``` that returns; ```true``` if the number is self-descriptive or ```false``` if the number is not. | ["from collections import Counter\n\n\ndef self_descriptive(num):\n s = [int(a) for a in str(num)]\n cnt = Counter(s)\n return all(cnt[i] == b for i, b in enumerate(s))\n", "def self_descriptive(num):\n numList = list(str(num))\n for i, s in enumerate(numList):\n if int(s) != numList.count(str(i)):\n return False\n return True", "def self_descriptive(num):\n digits = [int(d) for d in str(num)]\n return all(digits.count(i) == digits[i] for i in range(len(digits)))", "from collections import Counter\n\n\ndef self_descriptive(num):\n s = str(num)\n return Counter(s) == {str(i): int(n) for i, n in enumerate(s) if n != '0'}", "def self_descriptive(num):\n num = str(num)\n return all(num.count(str(i)) == int(d) for i, d in enumerate(num))", "def self_descriptive(num):\n from collections import Counter\n \n snum = str(num)\n c = Counter(snum)\n return all(int(d) == c[str(i)] for i, d in enumerate(snum))", "def self_descriptive(num):\n s = str(num)\n return all(int(d) == s.count(str(i)) for i, d in enumerate(s))", "def self_descriptive(num):\n ns = str(num)\n return all(ns.count(str(i)) == int(d) for i, d in enumerate(ns))", "def self_descriptive(num):\n for i, d in enumerate(str(num)):\n if str(num).count(str(i)) != int(d):\n return False\n return True"] | {"fn_name": "self_descriptive", "inputs": [[21200], [3211000], [42101000], [21230], [11200], [1210], [51120111], [2020], [11201], [6210001000]], "outputs": [[true], [true], [true], [false], [false], [true], [false], [true], [false], [true]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,362 |
def self_descriptive(num):
|
c7722fe38b31364d4709fcace8c8e3df | UNKNOWN | The aim of the kata is to decompose `n!` (factorial n) into its prime factors.
Examples:
```
n = 12; decomp(12) -> "2^10 * 3^5 * 5^2 * 7 * 11"
since 12! is divisible by 2 ten times, by 3 five times, by 5 two times and by 7 and 11 only once.
n = 22; decomp(22) -> "2^19 * 3^9 * 5^4 * 7^3 * 11^2 * 13 * 17 * 19"
n = 25; decomp(25) -> 2^22 * 3^10 * 5^6 * 7^3 * 11^2 * 13 * 17 * 19 * 23
```
Prime numbers should be in increasing order. When the exponent of a prime is 1 don't put the exponent.
Notes
- the function is `decomp(n)` and should return the decomposition of `n!` into its prime factors in increasing order of the primes, as a string.
- factorial can be a very big number (`4000! has 12674 digits`, n will go from 300 to 4000).
- In Fortran - as in any other language - the returned string is not permitted to contain any redundant trailing whitespace: you can use `dynamically allocated character strings`. | ["from collections import defaultdict\n\ndef dec(n):\n decomp = defaultdict(lambda:0)\n i = 2\n while n > 1:\n while n % i == 0:\n n /= i\n decomp[i] += 1\n i += 1\n return decomp\n \n\ndef decomp(n):\n ans = defaultdict(lambda:0)\n for i in range(2, n + 1):\n for key, value in dec(i).items():\n ans[key] += value\n return ' * '.join('{}^{}'.format(x, y) if y > 1 else str(x) for x, y in sorted(ans.items()))", "def decomp(chisl):\n \n div = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,\n 163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,\n 331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,\n 503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,\n 691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,\n 887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,\n 1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,\n 1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,\n 1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,\n 1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,\n 1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,\n 1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,1601,\n 1607,1609,1613,1619,1621,1627,1637,1657,1663,1667,1669,1693,\n 1697,1699,1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,\n 1787,1789,1801,1811,1823,1831,1847,1861,1867,1871,1873,1877,\n 1879,1889,1901,1907,1913,1931,1933,1949,1951,1973,1979,1987,\n 1993,1997,1999,2003,2011,2017,2027,2029,2039,2053,2063,2069,\n 2081,2083,2087,2089,2099,2111,2113,2129,2131,2137,2141,2143,\n 2153,2161,2179,2203,2207,2213,2221,2237,2239,2243,2251,2267,\n 2269,2273,2281,2287,2293,2297,2309,2311,2333,2339,2341,2347,\n 2351,2357,2371,2377,2381,2383,2389,2393,2399,2411,2417,2423,\n 2437,2441,2447,2459,2467,2473,2477,2503,2521,2531,2539,2543,\n 2549,2551,2557,2579,2591,2593,2609,2617,2621,2633,2647,2657,\n 2659,2663,2671,2677,2683,2687,2689,2693,2699,2707,2711,2713,\n 2719,2729,2731,2741,2749,2753,2767,2777,2789,2791,2797,2801,\n 2803,2819,2833,2837,2843,2851,2857,2861,2879,2887,2897,2903,\n 2909,2917,2927,2939,2953,2957,2963,2969,2971,2999,3001,3011,\n 3019,3023,3037,3041,3049,3061,3067,3079,3083,3089,3109,3119,\n 3121,3137,3163,3167,3169,3181,3187,3191,3203,3209,3217,3221,\n 3229,3251,3253,3257,3259,3271,3299,3301,3307,3313,3319,3323,\n 3329,3331,3343,3347,3359,3361,3371,3373,3389,3391,3407,3413,\n 3433,3449,3457,3461,3463,3467,3469,3491,3499,3511,3517,3527,\n 3529,3533,3539,3541,3547,3557,3559,3571,3581,3583,3593,3607,\n 3613,3617,3623,3631,3637,3643,3659,3671,3673,3677,3691,3697,\n 3701,3709,3719,3727,3733,3739,3761,3767,3769,3779,3793,3797,\n 3803,3821,3823,3833,3847,3851,3853,3863,3877,3881,3889,3907,\n 3911,3917,3919,3923,3929,3931,3943,3947,3967,3989,4001]\n exp = [0] * len(div) \n otvet = [] \n chislo = 1\n for i in range (1, chisl+1): \n for ii in range(len(div)):\n while i % div[ii] == 0:\n i /= div[ii]\n exp[ii] += 1\n for ii in range(len(div)): \n if exp[ii] > 1:\n otvet += [str(div[ii]) + '^' + str(exp[ii])]\n if exp[ii] == 1:\n otvet += [str(div[ii])]\n return(' * '.join(otvet))\n #your code here\n", "def decomp(n):\n out = []\n for d in range(2, n+1):\n if d==2 or (d&1 and d>2 and all(d%i for i in range(3, 1+int(d**0.5), 2))):\n a, x = 0, n\n while x >= d:\n x //= d \n a += x\n out.append((d,a))\n return ' * '.join([f'{i}^{j}' if j>1 else str(i) for i,j in out])\n", "def decomp(n):\n f = {}\n for i in range(2, n+1):\n for j in range(2, int(i**0.5)+1):\n while i%j==0:\n i = i//j\n if j in f: f[j] += 1\n else: f[j] = 1\n if i!=1:\n if i in f: f[i] += 1\n else: f[i] = 1\n \n return ' * '.join([\"{}^{}\".format(i, f[i]) if f[i]>1 else str(i) for i in sorted(f)])", "from itertools import count\n\ndec = [[],[],[1]]\nprimes = [2]\n\ndef genPrimes():\n for x in count(3,2):\n sq = int(x**.5)\n if all(p>sq or x%p for p in primes):\n yield x\n \nprimGen = genPrimes()\n\ndef genPrimesUpTo(n):\n while primes[-1] < n:\n primes.append(next(primGen))\n\ndef genPrimeDivs(n):\n genPrimesUpTo(n)\n dec.append(dec[-1][:]) # Duplicate last factorial decomposition\n for i,p in enumerate(primes):\n while not n%p:\n n //= p\n while i >= len(dec[-1]): dec[-1].append(0) \n dec[-1][i] += 1\n if n<2: break\n \n\ndef decomp(n):\n while len(dec) <= n:\n genPrimeDivs(len(dec))\n return \" * \".join(str(p) if c==1 else \"{}^{}\".format(p,c) for p,c in zip(primes,dec[n]))", "def decomp(n):\n result = []\n for i in primes():\n if i > n:\n break\n count = 0\n for j in range(2, n+1):\n while j % i == 0:\n count += 1\n j = j / i\n if count > 1:\n result.append(str(i)+'^'+str(count))\n else:\n result.append(str(i))\n return ' * '.join(result)\n\ndef primes():\n yield 2\n it = odd()\n while True:\n n = next(it)\n yield n\n it = filter(lambda x,n=n: x % n > 0, it)\n \ndef odd():\n n = 1\n while True:\n n += 2\n yield n", "# What a f****** mess this was...\n\nimport math\nimport numpy as np\n\ndef decomp(n): \n\n def rt(x): \n if x % 2 == 0:\n return [2, int(x/2)] \n for i in range(3, math.floor(math.sqrt(x)) + 1, 2):\n if x % i == 0:\n return [i, int(x/i)] \n return [x, 1] \n \n leftovers = np.arange(2, n+1, 1) \n facs = [0]*(n-1)\n \n while leftovers != []:\n newlefts = []\n \n for l in leftovers:\n [h, k] = rt(l)\n facs[h-2] += 1\n \n if k != 1:\n newlefts += [k]\n \n \n leftovers = newlefts \n \n string = ''\n \n for m in range(2, n+1):\n if facs[m-2] == 1:\n if string != '':\n string += ' * ' + str(m)\n if string == '':\n string = str(m)\n if facs[m-2] > 1:\n if string != '':\n string += ' * ' + str(m) + '^' + str(facs[m-2])\n if string == '':\n string = str(m) + '^' + str(facs[m-2])\n \n \n \n return string\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\n\n\n \n \n \n \n \n \n \n \n \n \n \n\n", "def primes(n):\n primes = [2]\n for i in range(3,n+1):\n if all(i%p!= 0 for p in primes) == True:\n primes.append(i)\n return(primes)\ndef decomp(n):\n prim = primes(n)\n factors = {}\n for i in range(2, n+1):\n if i in prim:\n factors[i] = 1\n else:\n for p in prim:\n while i%p == 0:\n factors[p] += 1\n i /= p\n if i == 1:\n break\n res = ''\n for x, y in factors.items():\n res += '{0}^{1} * '.format(x,y) if y != 1 else '{0} * '.format(x)\n return(res[:-3])", "is_prime = lambda n: n == 2 or n % 2 and all(n % d for d in range(3, int(n ** .5) + 1, 2))\norder = lambda n, k: n and n // k + order(n // k, k)\ndecomp = lambda n: ' * '.join(str(p) if n < 2 * p else '%d^%d' % (p, order(n, p)) for p in range(2, n+1) if is_prime(p))", "def decomp(n):\n primes = (2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597,1601,1607,1609,1613,1619,1621,1627,1637,1657,1663,1667,1669,1693,1697,1699,1709,1721,1723,1733,1741,1747,1753,1759,1777,1783,1787,1789,1801,1811,1823,1831,1847,1861,1867,1871,1873,1877,1879,1889,1901,1907,1913,1931,1933,1949,1951,1973,1979,1987,1993,1997,1999,2003,2011,2017,2027,2029,2039,2053,2063,2069,2081,2083,2087,2089,2099,2111,2113,2129,2131,2137,2141,2143,2153,2161,2179,2203,2207,2213,2221,2237,2239,2243,2251,2267,2269,2273,2281,2287,2293,2297,2309,2311,2333,2339,2341,2347,2351,2357,2371,2377,2381,2383,2389,2393,2399,2411,2417,2423,2437,2441,2447,2459,2467,2473,2477,2503,2521,2531,2539,2543,2549,2551,2557,2579,2591,2593,2609,2617,2621,2633,2647,2657,2659,2663,2671,2677,2683,2687,2689,2693,2699,2707,2711,2713,2719,2729,2731,2741,2749,2753,2767,2777,2789,2791,2797,2801,2803,2819,2833,2837,2843,2851,2857,2861,2879,2887,2897,2903,2909,2917,2927,2939,2953,2957,2963,2969,2971,2999,3001,3011,3019,3023,3037,3041,3049,3061,3067,3079,3083,3089,3109,3119,3121,3137,3163,3167,3169,3181,3187,3191,3203,3209,3217,3221,3229,3251,3253,3257,3259,3271,3299,3301,3307,3313,3319,3323,3329,3331,3343,3347,3359,3361,3371,3373,3389,3391,3407,3413,3433,3449,3457,3461,3463,3467,3469,3491,3499,3511,3517,3527,3529,3533,3539,3541,3547,3557,3559,3571,3581,3583,3593,3607,3613,3617,3623,3631,3637,3643,3659,3671,3673,3677,3691,3697,3701,3709,3719,3727,3733,3739,3761,3767,3769,3779,3793,3797,3803,3821,3823,3833,3847,3851,3853,3863,3877,3881,3889,3907,3911,3917,3919,3923,3929,3931,3943,3947,3967,3989)\n \n def proc(c,n):\n ct = 0\n q = 1\n while n >= q*c:\n q *= c\n ct += n//q\n return f'{c}^{ct}' if ct > 1 else str(c)\n \n return ' * '.join(proc(c,n) for c in primes if n >= c)", "mults={}\ndef get_primes(n):\n prims=[True]*(n+1)\n prims[0]=False\n prims[1]=False\n #print(prims)\n for x in range(2,n-1):\n #print(prims)\n if(prims[x]):\n prims[x+x::x]=[False]*(n//x-1)\n return [x for x in range(len(prims)) if prims[x]]\n\ndef find_mults(n, p):\n if (n,p) in mults:\n return mults[n,p]\n if(n%p!=0):\n return 0\n if(n==p):\n return 1\n return 1+find_mults(n/p, p)\n\ndef get_mults(n,p):\n if (n,p) not in mults:\n mults[n,p]=find_mults(n,p)\n return mults[n,p]\n\ndef decomp(m):\n primes=get_primes(m+1)\n #print(primes)\n final_string=[]\n for p in [x for x in primes if x<=m]: #go through the primes once at a time\n s=0\n for n in range(p,m+1,p): #go through all numbers from p to m+1??? \n \n s+=get_mults(n,p )\n if(s>0):\n if(s==1):\n final_string.append(str(p))\n else:\n final_string.append(str(p)+\"^\"+str(s))\n #print(s)\n #print(\" * \".join(final_string))\n return \" * \".join(final_string)\n \n"] | {"fn_name": "decomp", "inputs": [[5], [14], [17], [22], [25], [79], [98], [3988], [3989], [3990]], "outputs": [["2^3 * 3 * 5"], ["2^11 * 3^5 * 5^2 * 7^2 * 11 * 13"], ["2^15 * 3^6 * 5^3 * 7^2 * 11 * 13 * 17"], ["2^19 * 3^9 * 5^4 * 7^3 * 11^2 * 13 * 17 * 19"], ["2^22 * 3^10 * 5^6 * 7^3 * 11^2 * 13 * 17 * 19 * 23"], ["2^74 * 3^36 * 5^18 * 7^12 * 11^7 * 13^6 * 17^4 * 19^4 * 23^3 * 29^2 * 31^2 * 37^2 * 41 * 43 * 47 * 53 * 59 * 61 * 67 * 71 * 73 * 79"], ["2^95 * 3^46 * 5^22 * 7^16 * 11^8 * 13^7 * 17^5 * 19^5 * 23^4 * 29^3 * 31^3 * 37^2 * 41^2 * 43^2 * 47^2 * 53 * 59 * 61 * 67 * 71 * 73 * 79 * 83 * 89 * 97"], ["2^3981 * 3^1990 * 5^994 * 7^662 * 11^396 * 13^330 * 17^247 * 19^220 * 23^180 * 29^141 * 31^132 * 37^109 * 41^99 * 43^94 * 47^85 * 53^76 * 59^68 * 61^66 * 67^59 * 71^56 * 73^54 * 79^50 * 83^48 * 89^44 * 97^41 * 101^39 * 103^38 * 107^37 * 109^36 * 113^35 * 127^31 * 131^30 * 137^29 * 139^28 * 149^26 * 151^26 * 157^25 * 163^24 * 167^23 * 173^23 * 179^22 * 181^22 * 191^20 * 193^20 * 197^20 * 199^20 * 211^18 * 223^17 * 227^17 * 229^17 * 233^17 * 239^16 * 241^16 * 251^15 * 257^15 * 263^15 * 269^14 * 271^14 * 277^14 * 281^14 * 283^14 * 293^13 * 307^12 * 311^12 * 313^12 * 317^12 * 331^12 * 337^11 * 347^11 * 349^11 * 353^11 * 359^11 * 367^10 * 373^10 * 379^10 * 383^10 * 389^10 * 397^10 * 401^9 * 409^9 * 419^9 * 421^9 * 431^9 * 433^9 * 439^9 * 443^9 * 449^8 * 457^8 * 461^8 * 463^8 * 467^8 * 479^8 * 487^8 * 491^8 * 499^7 * 503^7 * 509^7 * 521^7 * 523^7 * 541^7 * 547^7 * 557^7 * 563^7 * 569^7 * 571^6 * 577^6 * 587^6 * 593^6 * 599^6 * 601^6 * 607^6 * 613^6 * 617^6 * 619^6 * 631^6 * 641^6 * 643^6 * 647^6 * 653^6 * 659^6 * 661^6 * 673^5 * 677^5 * 683^5 * 691^5 * 701^5 * 709^5 * 719^5 * 727^5 * 733^5 * 739^5 * 743^5 * 751^5 * 757^5 * 761^5 * 769^5 * 773^5 * 787^5 * 797^5 * 809^4 * 811^4 * 821^4 * 823^4 * 827^4 * 829^4 * 839^4 * 853^4 * 857^4 * 859^4 * 863^4 * 877^4 * 881^4 * 883^4 * 887^4 * 907^4 * 911^4 * 919^4 * 929^4 * 937^4 * 941^4 * 947^4 * 953^4 * 967^4 * 971^4 * 977^4 * 983^4 * 991^4 * 997^4 * 1009^3 * 1013^3 * 1019^3 * 1021^3 * 1031^3 * 1033^3 * 1039^3 * 1049^3 * 1051^3 * 1061^3 * 1063^3 * 1069^3 * 1087^3 * 1091^3 * 1093^3 * 1097^3 * 1103^3 * 1109^3 * 1117^3 * 1123^3 * 1129^3 * 1151^3 * 1153^3 * 1163^3 * 1171^3 * 1181^3 * 1187^3 * 1193^3 * 1201^3 * 1213^3 * 1217^3 * 1223^3 * 1229^3 * 1231^3 * 1237^3 * 1249^3 * 1259^3 * 1277^3 * 1279^3 * 1283^3 * 1289^3 * 1291^3 * 1297^3 * 1301^3 * 1303^3 * 1307^3 * 1319^3 * 1321^3 * 1327^3 * 1361^2 * 1367^2 * 1373^2 * 1381^2 * 1399^2 * 1409^2 * 1423^2 * 1427^2 * 1429^2 * 1433^2 * 1439^2 * 1447^2 * 1451^2 * 1453^2 * 1459^2 * 1471^2 * 1481^2 * 1483^2 * 1487^2 * 1489^2 * 1493^2 * 1499^2 * 1511^2 * 1523^2 * 1531^2 * 1543^2 * 1549^2 * 1553^2 * 1559^2 * 1567^2 * 1571^2 * 1579^2 * 1583^2 * 1597^2 * 1601^2 * 1607^2 * 1609^2 * 1613^2 * 1619^2 * 1621^2 * 1627^2 * 1637^2 * 1657^2 * 1663^2 * 1667^2 * 1669^2 * 1693^2 * 1697^2 * 1699^2 * 1709^2 * 1721^2 * 1723^2 * 1733^2 * 1741^2 * 1747^2 * 1753^2 * 1759^2 * 1777^2 * 1783^2 * 1787^2 * 1789^2 * 1801^2 * 1811^2 * 1823^2 * 1831^2 * 1847^2 * 1861^2 * 1867^2 * 1871^2 * 1873^2 * 1877^2 * 1879^2 * 1889^2 * 1901^2 * 1907^2 * 1913^2 * 1931^2 * 1933^2 * 1949^2 * 1951^2 * 1973^2 * 1979^2 * 1987^2 * 1993^2 * 1997 * 1999 * 2003 * 2011 * 2017 * 2027 * 2029 * 2039 * 2053 * 2063 * 2069 * 2081 * 2083 * 2087 * 2089 * 2099 * 2111 * 2113 * 2129 * 2131 * 2137 * 2141 * 2143 * 2153 * 2161 * 2179 * 2203 * 2207 * 2213 * 2221 * 2237 * 2239 * 2243 * 2251 * 2267 * 2269 * 2273 * 2281 * 2287 * 2293 * 2297 * 2309 * 2311 * 2333 * 2339 * 2341 * 2347 * 2351 * 2357 * 2371 * 2377 * 2381 * 2383 * 2389 * 2393 * 2399 * 2411 * 2417 * 2423 * 2437 * 2441 * 2447 * 2459 * 2467 * 2473 * 2477 * 2503 * 2521 * 2531 * 2539 * 2543 * 2549 * 2551 * 2557 * 2579 * 2591 * 2593 * 2609 * 2617 * 2621 * 2633 * 2647 * 2657 * 2659 * 2663 * 2671 * 2677 * 2683 * 2687 * 2689 * 2693 * 2699 * 2707 * 2711 * 2713 * 2719 * 2729 * 2731 * 2741 * 2749 * 2753 * 2767 * 2777 * 2789 * 2791 * 2797 * 2801 * 2803 * 2819 * 2833 * 2837 * 2843 * 2851 * 2857 * 2861 * 2879 * 2887 * 2897 * 2903 * 2909 * 2917 * 2927 * 2939 * 2953 * 2957 * 2963 * 2969 * 2971 * 2999 * 3001 * 3011 * 3019 * 3023 * 3037 * 3041 * 3049 * 3061 * 3067 * 3079 * 3083 * 3089 * 3109 * 3119 * 3121 * 3137 * 3163 * 3167 * 3169 * 3181 * 3187 * 3191 * 3203 * 3209 * 3217 * 3221 * 3229 * 3251 * 3253 * 3257 * 3259 * 3271 * 3299 * 3301 * 3307 * 3313 * 3319 * 3323 * 3329 * 3331 * 3343 * 3347 * 3359 * 3361 * 3371 * 3373 * 3389 * 3391 * 3407 * 3413 * 3433 * 3449 * 3457 * 3461 * 3463 * 3467 * 3469 * 3491 * 3499 * 3511 * 3517 * 3527 * 3529 * 3533 * 3539 * 3541 * 3547 * 3557 * 3559 * 3571 * 3581 * 3583 * 3593 * 3607 * 3613 * 3617 * 3623 * 3631 * 3637 * 3643 * 3659 * 3671 * 3673 * 3677 * 3691 * 3697 * 3701 * 3709 * 3719 * 3727 * 3733 * 3739 * 3761 * 3767 * 3769 * 3779 * 3793 * 3797 * 3803 * 3821 * 3823 * 3833 * 3847 * 3851 * 3853 * 3863 * 3877 * 3881 * 3889 * 3907 * 3911 * 3917 * 3919 * 3923 * 3929 * 3931 * 3943 * 3947 * 3967"], ["2^3981 * 3^1990 * 5^994 * 7^662 * 11^396 * 13^330 * 17^247 * 19^220 * 23^180 * 29^141 * 31^132 * 37^109 * 41^99 * 43^94 * 47^85 * 53^76 * 59^68 * 61^66 * 67^59 * 71^56 * 73^54 * 79^50 * 83^48 * 89^44 * 97^41 * 101^39 * 103^38 * 107^37 * 109^36 * 113^35 * 127^31 * 131^30 * 137^29 * 139^28 * 149^26 * 151^26 * 157^25 * 163^24 * 167^23 * 173^23 * 179^22 * 181^22 * 191^20 * 193^20 * 197^20 * 199^20 * 211^18 * 223^17 * 227^17 * 229^17 * 233^17 * 239^16 * 241^16 * 251^15 * 257^15 * 263^15 * 269^14 * 271^14 * 277^14 * 281^14 * 283^14 * 293^13 * 307^12 * 311^12 * 313^12 * 317^12 * 331^12 * 337^11 * 347^11 * 349^11 * 353^11 * 359^11 * 367^10 * 373^10 * 379^10 * 383^10 * 389^10 * 397^10 * 401^9 * 409^9 * 419^9 * 421^9 * 431^9 * 433^9 * 439^9 * 443^9 * 449^8 * 457^8 * 461^8 * 463^8 * 467^8 * 479^8 * 487^8 * 491^8 * 499^7 * 503^7 * 509^7 * 521^7 * 523^7 * 541^7 * 547^7 * 557^7 * 563^7 * 569^7 * 571^6 * 577^6 * 587^6 * 593^6 * 599^6 * 601^6 * 607^6 * 613^6 * 617^6 * 619^6 * 631^6 * 641^6 * 643^6 * 647^6 * 653^6 * 659^6 * 661^6 * 673^5 * 677^5 * 683^5 * 691^5 * 701^5 * 709^5 * 719^5 * 727^5 * 733^5 * 739^5 * 743^5 * 751^5 * 757^5 * 761^5 * 769^5 * 773^5 * 787^5 * 797^5 * 809^4 * 811^4 * 821^4 * 823^4 * 827^4 * 829^4 * 839^4 * 853^4 * 857^4 * 859^4 * 863^4 * 877^4 * 881^4 * 883^4 * 887^4 * 907^4 * 911^4 * 919^4 * 929^4 * 937^4 * 941^4 * 947^4 * 953^4 * 967^4 * 971^4 * 977^4 * 983^4 * 991^4 * 997^4 * 1009^3 * 1013^3 * 1019^3 * 1021^3 * 1031^3 * 1033^3 * 1039^3 * 1049^3 * 1051^3 * 1061^3 * 1063^3 * 1069^3 * 1087^3 * 1091^3 * 1093^3 * 1097^3 * 1103^3 * 1109^3 * 1117^3 * 1123^3 * 1129^3 * 1151^3 * 1153^3 * 1163^3 * 1171^3 * 1181^3 * 1187^3 * 1193^3 * 1201^3 * 1213^3 * 1217^3 * 1223^3 * 1229^3 * 1231^3 * 1237^3 * 1249^3 * 1259^3 * 1277^3 * 1279^3 * 1283^3 * 1289^3 * 1291^3 * 1297^3 * 1301^3 * 1303^3 * 1307^3 * 1319^3 * 1321^3 * 1327^3 * 1361^2 * 1367^2 * 1373^2 * 1381^2 * 1399^2 * 1409^2 * 1423^2 * 1427^2 * 1429^2 * 1433^2 * 1439^2 * 1447^2 * 1451^2 * 1453^2 * 1459^2 * 1471^2 * 1481^2 * 1483^2 * 1487^2 * 1489^2 * 1493^2 * 1499^2 * 1511^2 * 1523^2 * 1531^2 * 1543^2 * 1549^2 * 1553^2 * 1559^2 * 1567^2 * 1571^2 * 1579^2 * 1583^2 * 1597^2 * 1601^2 * 1607^2 * 1609^2 * 1613^2 * 1619^2 * 1621^2 * 1627^2 * 1637^2 * 1657^2 * 1663^2 * 1667^2 * 1669^2 * 1693^2 * 1697^2 * 1699^2 * 1709^2 * 1721^2 * 1723^2 * 1733^2 * 1741^2 * 1747^2 * 1753^2 * 1759^2 * 1777^2 * 1783^2 * 1787^2 * 1789^2 * 1801^2 * 1811^2 * 1823^2 * 1831^2 * 1847^2 * 1861^2 * 1867^2 * 1871^2 * 1873^2 * 1877^2 * 1879^2 * 1889^2 * 1901^2 * 1907^2 * 1913^2 * 1931^2 * 1933^2 * 1949^2 * 1951^2 * 1973^2 * 1979^2 * 1987^2 * 1993^2 * 1997 * 1999 * 2003 * 2011 * 2017 * 2027 * 2029 * 2039 * 2053 * 2063 * 2069 * 2081 * 2083 * 2087 * 2089 * 2099 * 2111 * 2113 * 2129 * 2131 * 2137 * 2141 * 2143 * 2153 * 2161 * 2179 * 2203 * 2207 * 2213 * 2221 * 2237 * 2239 * 2243 * 2251 * 2267 * 2269 * 2273 * 2281 * 2287 * 2293 * 2297 * 2309 * 2311 * 2333 * 2339 * 2341 * 2347 * 2351 * 2357 * 2371 * 2377 * 2381 * 2383 * 2389 * 2393 * 2399 * 2411 * 2417 * 2423 * 2437 * 2441 * 2447 * 2459 * 2467 * 2473 * 2477 * 2503 * 2521 * 2531 * 2539 * 2543 * 2549 * 2551 * 2557 * 2579 * 2591 * 2593 * 2609 * 2617 * 2621 * 2633 * 2647 * 2657 * 2659 * 2663 * 2671 * 2677 * 2683 * 2687 * 2689 * 2693 * 2699 * 2707 * 2711 * 2713 * 2719 * 2729 * 2731 * 2741 * 2749 * 2753 * 2767 * 2777 * 2789 * 2791 * 2797 * 2801 * 2803 * 2819 * 2833 * 2837 * 2843 * 2851 * 2857 * 2861 * 2879 * 2887 * 2897 * 2903 * 2909 * 2917 * 2927 * 2939 * 2953 * 2957 * 2963 * 2969 * 2971 * 2999 * 3001 * 3011 * 3019 * 3023 * 3037 * 3041 * 3049 * 3061 * 3067 * 3079 * 3083 * 3089 * 3109 * 3119 * 3121 * 3137 * 3163 * 3167 * 3169 * 3181 * 3187 * 3191 * 3203 * 3209 * 3217 * 3221 * 3229 * 3251 * 3253 * 3257 * 3259 * 3271 * 3299 * 3301 * 3307 * 3313 * 3319 * 3323 * 3329 * 3331 * 3343 * 3347 * 3359 * 3361 * 3371 * 3373 * 3389 * 3391 * 3407 * 3413 * 3433 * 3449 * 3457 * 3461 * 3463 * 3467 * 3469 * 3491 * 3499 * 3511 * 3517 * 3527 * 3529 * 3533 * 3539 * 3541 * 3547 * 3557 * 3559 * 3571 * 3581 * 3583 * 3593 * 3607 * 3613 * 3617 * 3623 * 3631 * 3637 * 3643 * 3659 * 3671 * 3673 * 3677 * 3691 * 3697 * 3701 * 3709 * 3719 * 3727 * 3733 * 3739 * 3761 * 3767 * 3769 * 3779 * 3793 * 3797 * 3803 * 3821 * 3823 * 3833 * 3847 * 3851 * 3853 * 3863 * 3877 * 3881 * 3889 * 3907 * 3911 * 3917 * 3919 * 3923 * 3929 * 3931 * 3943 * 3947 * 3967 * 3989"], ["2^3982 * 3^1991 * 5^995 * 7^663 * 11^396 * 13^330 * 17^247 * 19^221 * 23^180 * 29^141 * 31^132 * 37^109 * 41^99 * 43^94 * 47^85 * 53^76 * 59^68 * 61^66 * 67^59 * 71^56 * 73^54 * 79^50 * 83^48 * 89^44 * 97^41 * 101^39 * 103^38 * 107^37 * 109^36 * 113^35 * 127^31 * 131^30 * 137^29 * 139^28 * 149^26 * 151^26 * 157^25 * 163^24 * 167^23 * 173^23 * 179^22 * 181^22 * 191^20 * 193^20 * 197^20 * 199^20 * 211^18 * 223^17 * 227^17 * 229^17 * 233^17 * 239^16 * 241^16 * 251^15 * 257^15 * 263^15 * 269^14 * 271^14 * 277^14 * 281^14 * 283^14 * 293^13 * 307^12 * 311^12 * 313^12 * 317^12 * 331^12 * 337^11 * 347^11 * 349^11 * 353^11 * 359^11 * 367^10 * 373^10 * 379^10 * 383^10 * 389^10 * 397^10 * 401^9 * 409^9 * 419^9 * 421^9 * 431^9 * 433^9 * 439^9 * 443^9 * 449^8 * 457^8 * 461^8 * 463^8 * 467^8 * 479^8 * 487^8 * 491^8 * 499^7 * 503^7 * 509^7 * 521^7 * 523^7 * 541^7 * 547^7 * 557^7 * 563^7 * 569^7 * 571^6 * 577^6 * 587^6 * 593^6 * 599^6 * 601^6 * 607^6 * 613^6 * 617^6 * 619^6 * 631^6 * 641^6 * 643^6 * 647^6 * 653^6 * 659^6 * 661^6 * 673^5 * 677^5 * 683^5 * 691^5 * 701^5 * 709^5 * 719^5 * 727^5 * 733^5 * 739^5 * 743^5 * 751^5 * 757^5 * 761^5 * 769^5 * 773^5 * 787^5 * 797^5 * 809^4 * 811^4 * 821^4 * 823^4 * 827^4 * 829^4 * 839^4 * 853^4 * 857^4 * 859^4 * 863^4 * 877^4 * 881^4 * 883^4 * 887^4 * 907^4 * 911^4 * 919^4 * 929^4 * 937^4 * 941^4 * 947^4 * 953^4 * 967^4 * 971^4 * 977^4 * 983^4 * 991^4 * 997^4 * 1009^3 * 1013^3 * 1019^3 * 1021^3 * 1031^3 * 1033^3 * 1039^3 * 1049^3 * 1051^3 * 1061^3 * 1063^3 * 1069^3 * 1087^3 * 1091^3 * 1093^3 * 1097^3 * 1103^3 * 1109^3 * 1117^3 * 1123^3 * 1129^3 * 1151^3 * 1153^3 * 1163^3 * 1171^3 * 1181^3 * 1187^3 * 1193^3 * 1201^3 * 1213^3 * 1217^3 * 1223^3 * 1229^3 * 1231^3 * 1237^3 * 1249^3 * 1259^3 * 1277^3 * 1279^3 * 1283^3 * 1289^3 * 1291^3 * 1297^3 * 1301^3 * 1303^3 * 1307^3 * 1319^3 * 1321^3 * 1327^3 * 1361^2 * 1367^2 * 1373^2 * 1381^2 * 1399^2 * 1409^2 * 1423^2 * 1427^2 * 1429^2 * 1433^2 * 1439^2 * 1447^2 * 1451^2 * 1453^2 * 1459^2 * 1471^2 * 1481^2 * 1483^2 * 1487^2 * 1489^2 * 1493^2 * 1499^2 * 1511^2 * 1523^2 * 1531^2 * 1543^2 * 1549^2 * 1553^2 * 1559^2 * 1567^2 * 1571^2 * 1579^2 * 1583^2 * 1597^2 * 1601^2 * 1607^2 * 1609^2 * 1613^2 * 1619^2 * 1621^2 * 1627^2 * 1637^2 * 1657^2 * 1663^2 * 1667^2 * 1669^2 * 1693^2 * 1697^2 * 1699^2 * 1709^2 * 1721^2 * 1723^2 * 1733^2 * 1741^2 * 1747^2 * 1753^2 * 1759^2 * 1777^2 * 1783^2 * 1787^2 * 1789^2 * 1801^2 * 1811^2 * 1823^2 * 1831^2 * 1847^2 * 1861^2 * 1867^2 * 1871^2 * 1873^2 * 1877^2 * 1879^2 * 1889^2 * 1901^2 * 1907^2 * 1913^2 * 1931^2 * 1933^2 * 1949^2 * 1951^2 * 1973^2 * 1979^2 * 1987^2 * 1993^2 * 1997 * 1999 * 2003 * 2011 * 2017 * 2027 * 2029 * 2039 * 2053 * 2063 * 2069 * 2081 * 2083 * 2087 * 2089 * 2099 * 2111 * 2113 * 2129 * 2131 * 2137 * 2141 * 2143 * 2153 * 2161 * 2179 * 2203 * 2207 * 2213 * 2221 * 2237 * 2239 * 2243 * 2251 * 2267 * 2269 * 2273 * 2281 * 2287 * 2293 * 2297 * 2309 * 2311 * 2333 * 2339 * 2341 * 2347 * 2351 * 2357 * 2371 * 2377 * 2381 * 2383 * 2389 * 2393 * 2399 * 2411 * 2417 * 2423 * 2437 * 2441 * 2447 * 2459 * 2467 * 2473 * 2477 * 2503 * 2521 * 2531 * 2539 * 2543 * 2549 * 2551 * 2557 * 2579 * 2591 * 2593 * 2609 * 2617 * 2621 * 2633 * 2647 * 2657 * 2659 * 2663 * 2671 * 2677 * 2683 * 2687 * 2689 * 2693 * 2699 * 2707 * 2711 * 2713 * 2719 * 2729 * 2731 * 2741 * 2749 * 2753 * 2767 * 2777 * 2789 * 2791 * 2797 * 2801 * 2803 * 2819 * 2833 * 2837 * 2843 * 2851 * 2857 * 2861 * 2879 * 2887 * 2897 * 2903 * 2909 * 2917 * 2927 * 2939 * 2953 * 2957 * 2963 * 2969 * 2971 * 2999 * 3001 * 3011 * 3019 * 3023 * 3037 * 3041 * 3049 * 3061 * 3067 * 3079 * 3083 * 3089 * 3109 * 3119 * 3121 * 3137 * 3163 * 3167 * 3169 * 3181 * 3187 * 3191 * 3203 * 3209 * 3217 * 3221 * 3229 * 3251 * 3253 * 3257 * 3259 * 3271 * 3299 * 3301 * 3307 * 3313 * 3319 * 3323 * 3329 * 3331 * 3343 * 3347 * 3359 * 3361 * 3371 * 3373 * 3389 * 3391 * 3407 * 3413 * 3433 * 3449 * 3457 * 3461 * 3463 * 3467 * 3469 * 3491 * 3499 * 3511 * 3517 * 3527 * 3529 * 3533 * 3539 * 3541 * 3547 * 3557 * 3559 * 3571 * 3581 * 3583 * 3593 * 3607 * 3613 * 3617 * 3623 * 3631 * 3637 * 3643 * 3659 * 3671 * 3673 * 3677 * 3691 * 3697 * 3701 * 3709 * 3719 * 3727 * 3733 * 3739 * 3761 * 3767 * 3769 * 3779 * 3793 * 3797 * 3803 * 3821 * 3823 * 3833 * 3847 * 3851 * 3853 * 3863 * 3877 * 3881 * 3889 * 3907 * 3911 * 3917 * 3919 * 3923 * 3929 * 3931 * 3943 * 3947 * 3967 * 3989"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 12,355 |
def decomp(n):
|
cf2641a55c770fc890ac76108645c638 | UNKNOWN | # Write Number in Expanded Form - Part 2
This is version 2 of my ['Write Number in Exanded Form' Kata](https://www.codewars.com/kata/write-number-in-expanded-form).
You will be given a number and you will need to return it as a string in [Expanded Form](https://www.mathplacementreview.com/arithmetic/decimals.php#writing-a-decimal-in-expanded-form). For example:
```python
expanded_form(1.24) # Should return '1 + 2/10 + 4/100'
expanded_form(7.304) # Should return '7 + 3/10 + 4/1000'
expanded_form(0.04) # Should return '4/100'
``` | ["def expanded_form(num):\n integer_part, fractional_part = str(num).split('.')\n\n result = [str(int(num) * (10 ** i)) for i, num in enumerate(integer_part[::-1]) if num != '0'][::-1]\n result += [str(num) + '/' + str(10 ** (i + 1)) for i, num in enumerate(fractional_part) if num != '0']\n\n return ' + '.join(result)\n", "def expanded_form(num):\n xs = str(num).split('.')\n return ' + '.join(\n [f'{x}{\"0\" * i}' for i, x in enumerate(xs[0][::-1]) if x != '0'][::-1]\n + [f'{x}/{10 ** i}' for i, x in enumerate(xs[1], 1) if x != '0']\n )", "def expanded_form(num):\n parts = str(num).split('.')\n return ' + '.join( [str(int(p) * 10**(len(parts[0])-i-1)) for i,p in enumerate(parts[0]) if p != '0']\n + [\"{}/{}\".format(d, 10**i) for i,d in enumerate(parts[1], 1) if d != '0'] )", "def expanded_form(num):\n integer = [n + '0'*i for i, n in enumerate(list(str(num).split('.')[0])[::-1]) if n != '0']\n decimal = [n + '/1' + '0'*(i+1) for i, n in enumerate(list(str(num).split('.')[1])) if n != '0']\n return ' + '.join(integer[::-1]+decimal)", "def expanded_form(num):\n first_part, second_part = str(num).split(\".\")\n first_length = len(first_part)\n\n result = [\n elem + \"0\" * (first_length - i - 1)\n for i, elem in enumerate(first_part)\n if elem != \"0\"\n ]\n result += [\n elem + \"/1\" + \"0\" * (i + 1) for i, elem in enumerate(second_part) if elem != \"0\"\n ]\n\n return \" + \".join(result)\n", "def expanded_form(num):\n num_1, num_2 = map(str, str(num).split('.'))\n count = 0\n ls = []\n \n length = len(num_1)\n \n for i in num_1:\n length -= 1 \n x = i + '0' * length\n \n if (x) != '0':\n ls.append(x)\n \n for i in num_2:\n count += 1\n x = i + '/' + '1' +'0' * count\n \n if (x.split('/')[0]) != '0':\n ls.append(x)\n \n \n return (' + '.join(ls))", "def expanded_form(n):\n integer, decimal = str(n).split(\".\")\n l = len(integer)\n integer = [f\"{digit}{'0' * (l - i)}\" for i, digit in enumerate(integer, 1) if digit != \"0\"]\n decimal = [f\"{digit}/1{'0' * i}\" for i, digit in enumerate(decimal, 1) if digit != \"0\"]\n return \" + \".join(integer + decimal)", "def expanded_form1(num):\n a = len(str(num))\n b = []\n for i,j in enumerate(str(num)):\n if j != '0':\n b.append(j+'0'*(a-i-1))\n return ' + '.join(b)\n\ndef expanded_form(num):\n a = str(num).index('.')\n m = int(str(num)[:a])\n n = '0' + str(num)[a+1:]\n b = []\n for i,j in enumerate(n[1:]):\n if j != '0':\n b.append(j+'/1'+'0'*(i+1))\n b = ' + '.join(b)\n if len(expanded_form1(m)) > 0:\n return expanded_form1(m)+' + '+b\n else:\n return b", "def expanded_form(num):\n split = str(num).split('.')\n tens = [str(int(x) * 10**i) for i, x in enumerate(split[0][::-1]) if x != '0'][::-1]\n decimals = [f'{x}/{10**i}' for i, x in enumerate(split[1], 1) if x != '0'] if '.' in str(num) else []\n return ' + '.join(tens + decimals)", "def expanded_form(num):\n num = str(num)\n index = num.index('.')\n leng = len(num) - index - 1\n num = num[:index] + num[index + 1:]\n ans1 = ' + '.join(num[i] + (index-i-1) * '0' for i in range(index) if num[i] != '0')\n ans2 = ' + '.join(num[i+index] + '/1' + (i+1) * '0' for i in range(leng) if num[i+index]!='0')\n return ans2 if not ans1 else ans1 + ' + ' + ans2"] | {"fn_name": "expanded_form", "inputs": [[1.24], [7.304], [0.04], [1.04], [7.3004], [0.004], [693.230459]], "outputs": [["1 + 2/10 + 4/100"], ["7 + 3/10 + 4/1000"], ["4/100"], ["1 + 4/100"], ["7 + 3/10 + 4/10000"], ["4/1000"], ["600 + 90 + 3 + 2/10 + 3/100 + 4/10000 + 5/100000 + 9/1000000"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,580 |
def expanded_form(num):
|
9bf8e8448476784c638ab90dfc4ec95f | UNKNOWN | A wildlife study involving ducks is taking place in North America. Researchers are visiting some wetlands in a certain area taking a survey of what they see. The researchers will submit reports that need to be processed by your function.
## Input
The input for your function will be an array with a list of common duck names along with the counts made by the researchers. The names and counts are separated by spaces in one array element. The number of spaces between the name and the count could vary; but, there will always be at least one. A name may be repeated because a report may be a combination of surveys from different locations.
An example of an input array would be:
```
["Redhead 3", "Gadwall 1", "Smew 4", "Greater Scaup 10", "Redhead 3", "Gadwall 9", "Greater Scaup 15", "Common Eider 6"]
```
## Processing
Your function should change the names of the ducks to a six-letter code according to given rules (see below). The six-letter code should be in upper case. The counts should be summed for a species if it is repeated.
## Output
The final data to be returned from your function should be an array sorted by the species codes and the total counts as integers. The codes and the counts should be individual elements.
An example of an array to be returned (based on the example input array above) would be:
```
["COMEID", 6, "GADWAL", 10, "GRESCA", 25, "REDHEA", 6, "SMEW", 4]
```
The codes are strings in upper case and the totaled counts are integers.
### Special Note
If someone has `"Labrador Duck"` in their list, the whole list should be thrown out as this species has been determined to be extinct. The person who submitted the list is obviously unreliable. Their lists will not be included in the final data. In such cases, return an array with a single string element in it: `"Disqualified data"`
Rules for converting a common name to a six-letter code:
* Hyphens should be considered as spaces.
* If a name has only one word, use the first six letters of the name. If that name has less than six letters, use what is there.
* If a name has two words, take the first three letters of each word.
* If a name has three words, take the first two letters of each word.
* If a name has four words, take the first letters from the first two words, and the first two letters from the last two words. | ["def create_report(names):\n result = {}\n \n for name in names:\n if name.startswith(\"Labrador Duck\"):\n return [\"Disqualified data\"]\n \n name = name.upper().replace(\"-\", \" \").split()\n count = int(name.pop())\n \n if len(name) == 1: code = name[0][:6]\n elif len(name) == 2: code = name[0][:3] + name[1][:3]\n elif len(name) == 3: code = name[0][:2] + name[1][:2] + name[2][:2]\n elif len(name) == 4: code = name[0][0] + name[1][0] + name[2][:2] + name[3][:2]\n \n if code in result: result[code] += count\n else: result[code] = count\n \n return sum([[name, result[name]] for name in sorted(result)] , [] )", "from functools import reduce # Lacking in the test suite.\nfrom collections import defaultdict\nimport re\n\nFINDER = re.compile(r'(.+?)\\s+(\\d+)%')\nSPLITTER = re.compile(r'\\s|-')\n\ndef create_report(names):\n \n dct = defaultdict(int)\n for what,n in FINDER.findall('%'.join(names)+'%'):\n if what=='Labrador Duck': return [\"Disqualified data\"]\n \n lst = SPLITTER.split(what)\n key = ''.join(word[:6//len(lst) + (len(lst)==4 and i>=2)]\n for i,word in enumerate(lst)).upper()\n dct[key] += int(n)\n \n lst = []\n for k,n in sorted(dct.items()): lst.extend([k,n])\n \n return lst\n", "from collections import defaultdict\nfrom itertools import chain\nimport re\n\np1 = re.compile(\"(.*?)\\s*(\\d+)\")\np2 = re.compile(\"-| \")\n\ndef change(s):\n L = p2.split(s)\n if len(L) == 1:\n return L[0][:6].upper()\n if len(L) == 2:\n return (L[0][:3] + L[1][:3]).upper()\n if len(L) == 3:\n return (L[0][:2] + L[1][:2] + L[2][:2]).upper()\n if len(L) == 4:\n return (L[0][0] + L[1][0] + L[2][:2] + L[3][:2]).upper()\n raise Exception(\"No rule for more than 4 words\")\n\ndef create_report(names):\n result = defaultdict(int)\n for data in names:\n name, num = p1.match(data).groups()\n if name == \"Labrador Duck\": return [\"Disqualified data\"]\n result[change(name)] += int(num)\n return list(chain.from_iterable(sorted(result.items())))", "bird = lambda w: {4:lambda w: w[0][:1] + w[1][:1] + w[2][:2] + w[3][:2], \n 3:lambda w: w[0][:2] + w[1][:2] + w[2][:2], \n 2:lambda w: w[0][:3] + w[1][:3], \n 1:lambda w: w[0][:6]}[len(w)](w)\n\ndef create_report(names):\n D = {} \n for b, i in [(bird(' '.join(s.split()[:-1]).upper().replace('-', ' ').split()), int(s.split()[-1])) for s in names]:\n D[b] = D.get(b, 0) + i\n\n return ['Disqualified data'] if 'LABDUC' in D else [e for b in [[k, D[k]] for k in sorted(D.keys())] for e in b]", "from collections import Counter\nfrom itertools import chain\n\ndef create_report(names):\n if any(name.startswith(\"Labrador Duck \") for name in names): return [\"Disqualified data\"]\n counts = Counter()\n for name,count in (d.rsplit(None, 1) for d in names):\n counts[code(name)] += int(count)\n return list(chain(*sorted(counts.items())))\n\ndef code(name):\n words = name.upper().replace(\"-\",\" \").split(None, 3) # Generate at most 4 words\n lengths = [ (6,), (3,3), (2,2,2), (1,1,2,2) ][len(words)-1]\n return \"\".join(word[:lengths[i]] for i,word in enumerate(words))", "import re;create_report=lambda n:(lambda L:['Disqualified data']if'LABDUC'in L else L)([z for v in sorted((''.join(w[:6//len(l)+(len(l)==4 and i>=2)]for i,w in enumerate(l)),sum(b for _,b in g))\nfor l,g in __import__(\"itertools\").groupby(sorted(map(lambda x:(re.split(r'[\\s-]+',x[0].upper()),int(x[1])),map(lambda s:re.findall(r'(.+?)\\s+(\\d+)',s)[0],n))),key=lambda t:t[0]))for z in v])", "def create_report(a):\n d = {}\n for i in a:\n unique = [j for j in i.replace(\"-\", \" \").split(\" \")[:-1] if j]\n curr = [\"\".join(unique).upper()[:6], \"\".join([k[:3] for k in unique]).upper(), \"\".join([k[:2] for k in unique]).upper(), \"\".join([j[:1] if k in [0, 1] else j[:2] for k, j in enumerate(unique)]).upper()][len(unique) - 1]\n d[curr] = d.get(curr, 0) + int(i.split(\" \")[-1])\n return [\"Disqualified data\"] if \"Labrador Duck\" in \"\".join(a) else sum([[i,d[i]] for i in sorted(d)],[]) ", "def create_report(arr):\n d = {}\n for i in arr:\n if 'Labrador Duck' in i: return ['Disqualified data']\n *s,v = i.replace('-',' ').split()\n if len(s) == 4:\n k = s[0][0]+s[1][0]+s[-2][:2]+s[-1][:2]\n elif len(s) == 3:\n k = ''.join(j[:2] for j in s)\n elif len(s) == 2:\n k = ''.join(j[:3] for j in s)\n else:\n k = s[0][:6]\n k = k.upper()\n d.setdefault(k,0)\n d[k] += int(v)\n \n r = []\n for k in sorted(d):\n r.extend([k,d.get(k)])\n \n return r\n", "def create_report(A):\n B={}\n for a in A:\n if\"Labrador Duck\"in a:return ['Disqualified data']\n W=a.replace('-',' ').upper().split()\n c,L=int(W.pop()),len(W)\n n=L==1and W[0][:6]or L==2and W[0][:3]+W[1][:3] or L==3and W[0][:2]+W[1][:2]+W[2][:2]or W[0][0]+W[1][0]+W[2][:2]+W[3][:2]\n B[n]=B.get(n,0)+c\n return sum([[k,B[k]]for k in sorted(B)],[])", "from collections import defaultdict\n\ndef create_report(names):\n data = defaultdict(int)\n for name in names:\n words = name.replace('-',' ').split()\n number = int(words[-1])\n words = [word.upper() for word in words[:-1] if word]\n if words == ['LABRADOR','DUCK']:\n return ['Disqualified data']\n if 1<=len(words)<=3:\n code = ''.join(word[:6//len(words)] for word in words)\n elif len(words)==4:\n code = words[0][0]+words[1][0]+words[2][:2]+words[3][:2]\n else:\n print(name,'has',len(words),'words')\n #print(words,code)\n data[code] += number\n result = []\n for code, number in sorted(data.items()):\n result += [code, number]\n return result"] | {"fn_name": "create_report", "inputs": [[["Redhead 5", "Labrador Duck 9", "Blue-Winged Teal 25", "Steller's Eider 200"]], [["Canvasback 10", "Mallard 150", "American Wigeon 45", "Baikal Teal 3", "Barrow's Goldeneye 6", "Surf Scoter 12"]], [["Redhead 3", "Gadwall 1", "Smew 4", "Greater Scaup 10", "Redhead 3", "Gadwall 9", "Greater Scaup 15", "Common Eider 6"]], [["King Eider 20", "Labrador Duck 2", "Lesser Scaup 25", "Masked Duck 2", "Mottled Duck 10", "Muscovy Duck 1", "Northern Pintail 3", "Northern Shoveler 30"]], [["King Eider 20", "King Eider 2", "Lesser Scaup 25", "Masked Duck 2", "Mottled Duck 10", "Muscovy Duck 1", "Northern Pintail 3", "Northern Shoveler 30"]], [["Black-Bellied Whistling-Duck 5", "Bufflehead 200", "Steller's Eider 1", "Bufflehead 2", "Spectacled Eider 11", "Bufflehead 33", "Eastern Spot-billed Duck 116"]], [["Harlequin Duck 6", "Harlequin Duck 5", "Red-breasted Merganser 3000", "Surf Scoter 1", "Surf Scoter 600"]]], "outputs": [[["Disqualified data"]], [["AMEWIG", 45, "BAITEA", 3, "BARGOL", 6, "CANVAS", 10, "MALLAR", 150, "SURSCO", 12]], [["COMEID", 6, "GADWAL", 10, "GRESCA", 25, "REDHEA", 6, "SMEW", 4]], [["Disqualified data"]], [["KINEID", 22, "LESSCA", 25, "MASDUC", 2, "MOTDUC", 10, "MUSDUC", 1, "NORPIN", 3, "NORSHO", 30]], [["BBWHDU", 5, "BUFFLE", 235, "ESBIDU", 116, "SPEEID", 11, "STEEID", 1]], [["HARDUC", 11, "REBRME", 3000, "SURSCO", 601]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 6,176 |
def create_report(names):
|
9c819e5cf740b33f560ba0aaf9bde1ee | UNKNOWN | `This kata is the first of the ADFGX Ciphers, the harder version can be found `here.
The ADFGX Cipher is a pretty well-known Cryptographic tool, and is essentially a modified Polybius Square.
Rather than having numbers as coordinates on the table, it has the letters:
`A, D, F, G, X`
Also, because this is the first step, and to help simplify things, you won't have to worry about a key, or the corresponding columnar transposition. In this kata ;)
All you have to do is encrypt and decrypt a string into `ADFGX` format.
`adfgx_encrypt() and adfgx_decrypt()` will be passed a string, `plaintext` and `ciphertext` respectively, and an adfgx`square`, for which will guide the operations.
Now for some examples to clear confusion:
```python
adfgx_encrypt("helloworld", "bchigklnmoqprstuvwxyzadef")
A D F G X
A b c h i g
D k l n m o
F q p r s t -> square (PLEASE NOTE, j SHOULD BE TREATED AS i)
G u v w x y
X z a d e f
"helloworld" -> plaintext
EVALUATES TO:
F
-> "AF"
A h
--------------
G
-> "XG"
X e
AND SO FORTH...
#Results in:
adfgx_encrypt("helloworld", "bchigklnmoqprstuvwxyzadef")
==
"AFXGDDDDDXGFDXFFDDXF"
```
Now decryption:
```python
adfgx_decrypt("FGXGADGDXGFXAXXGFGFGAADGXG", "aczlmuqngoipvstkrwfxhdbey)
A D F G X
A a c z l m
D u q n g o
F i p v s t -> square (PLEASE NOTE, j SHOULD BE TREATED AS i)
G k r w f x
X h d b e y
"FGXGADGDXGFXAXXGFGFGAADGXG" -> ciphertext
"FG" == "s"
"XG" == "e"
AND SO ON:
adfgx_decrypt("FGXGADGDXGFXAXXGFGFGAADGXG", "aczlmuqngoipvstkrwfxhdbey)
==
"secretmessage"
```
PLEASE NOTE: ALL INPUT WILL BE VALID, NO NEED TO ERROR CHECK :D
What are you waiting for?!
Go create `adfgx_encrypt() and adfgx_decrypt()`!
Good Luck! | ["from itertools import product\nimport re\n\nKEY = [ a+b for a, b in product(\"ADFGX\", repeat=2) ]\n \n\ndef adfgx_encrypt(plaintext, square):\n d = dict(zip(square, KEY))\n oddity = d['i'] if 'i' in d else d['j']\n return ''.join(d.get(c, oddity) for c in plaintext)\n \n \ndef adfgx_decrypt(ciphertext, square):\n d = dict(zip(KEY, square))\n IJkey = [ k for k, v in d.items() if v in 'ij'].pop()\n\n return ''.join( d.get(c, d[IJkey]) for c in re.findall(r'.{2}', ciphertext)) ", "def formatSquare(sq, isEncode):\n BASE = \"ADFGX\"\n dct = {c: BASE[i//5] + BASE[i%5] for i,c in enumerate(sq)}\n return dct if isEncode else {v:k for k,v in dct.items()}\n\ndef adfgx_utility(txt, sq, isEncode):\n dct, step = formatSquare(sq, isEncode), 2-isEncode\n return ''.join( dct[txt[i:i+step]] if txt[i:i+step] in dct else dct['i'] for i in range(0,len(txt), step) )\n\ndef adfgx_encrypt(plaintext, square): return adfgx_utility(plaintext, square, True)\ndef adfgx_decrypt(ciphertext, square): return adfgx_utility(ciphertext, square, False)", "ADFGX = 'A','D','F','G','X'\n\ndef adfgx_encrypt(plaintext, square):\n ciphertext = ''\n for char in plaintext:\n try: y,x = divmod(square.index(char), 5)\n except ValueError: y,x = divmod(square.index('i'), 5)\n ciphertext += ADFGX[y] + ADFGX[x]\n return ciphertext\n \ndef adfgx_decrypt(ciphertext, square):\n plaintext = \"\"\n for j,i in zip(ciphertext[::2], ciphertext[1::2]):\n plaintext += square[ADFGX.index(j)*5+ADFGX.index(i)]\n return plaintext", "from itertools import product\n\n\ndef adfgx_encrypt(plaintext, square):\n mapping = {s: c1 + c2 for s, (c1, c2) in zip(square, product(\"ADFGX\", repeat=2))}\n mapping[\"i\"] = mapping[\"j\"] = mapping.get(\"i\", mapping.get(\"j\"))\n return \"\".join(mapping[c] for c in plaintext).upper()\n\n\ndef adfgx_decrypt(ciphertext, square):\n mapping = {c1 + c2: s for s, (c1, c2) in zip(square, product(\"ADFGX\", repeat=2))}\n return \"\".join(\n mapping[c1 + c2] for (c1, c2) in zip(*[iter(ciphertext)] * 2)\n ).lower()", "def adfgx_encrypt(plaintext, square):\n table = {c: \"{}{}\".format(\"ADFGX\"[i // 5], \"ADFGX\"[i % 5]) for i, c in enumerate(square.replace(\"j\", \"i\"))}\n return \"\".join(table[c] for c in plaintext.replace(\"j\", \"i\"))\n\ndef adfgx_decrypt(ciphertext, square):\n table = {\"{}{}\".format(\"ADFGX\"[i // 5], \"ADFGX\"[i % 5]):c for i, c in enumerate(square)}\n return \"\".join(table[c] for c in (ciphertext[i:i+2] for i in range(0, len(ciphertext), 2)))", "def adfgx_encrypt(s, square):\n square, s = [e.replace('j', 'i') for e in [square, s]]\n \n E = {v:r+c for row, r in zip([square[i:i+5] for i in range(0, 25, 5)], 'ADFGX') for c, v in zip('ADFGX', row)}\n return ''.join(E[c] for c in s)\n \ndef adfgx_decrypt(s, square):\n D = {r+c:v for row, r in zip([square[i:i+5] for i in range(0, 25, 5)], 'ADFGX') for c, v in zip('ADFGX', row)}\n return ''.join(D[w] for w in [s[i:i+2] for i in range(0, len(s), 2)])", "def adfgx_encrypt(t, s):\n cr=\"ADFGX\"; r=\"\"\n for c in t:\n if c=='j' and 'i' in s : c='i'\n p=s.index(c)\n r+=cr[p//5]+cr[p%5]\n return r\n \ndef adfgx_decrypt(t, s):\n cr=\"ADFGX\"; r=\"\"\n for i in range(0,len(t),2): r+=s[cr.index(t[i])*5+cr.index(t[i+1])]\n return r", "ADFGX = ['A', 'D', 'F', 'G', 'X']\n\n\ndef adfgx_encrypt(plaintext_, square):\n plaintext = plaintext_.replace('j', 'i') if 'i' in square else plaintext_.replace('i', 'j')\n return ''.join([ADFGX[square.index(ch) // 5] + ADFGX[square.index(ch) % 5] for ch in plaintext])\n\n \ndef adfgx_decrypt(ciphertext, square):\n return ''.join([square[ADFGX.index(j) + ADFGX.index(i) * 5] \n for i, j in zip(ciphertext[:-1:2], ciphertext[1::2])])\n", "def adfgx_encrypt(a, b):\n d = {x: (i // 5, i % 5) for i, x in enumerate(b)}\n if \"i\" in d:\n d[\"j\"] = d[\"i\"]\n else:\n d[\"i\"] = d[\"j\"]\n return \"\".join(\"ADFGX\"[y] + \"ADFGX\"[z] for x in a for y, z in [d[x]])\n \ndef adfgx_decrypt(a, b):\n it = iter(b)\n d = {x + y: next(it) for x in \"ADFGX\" for y in \"ADFGX\"}\n return \"\".join(d[a[i:i+2]] for i in range(0, len(a), 2))", "def adfgx_encrypt(plaintext, square):\n if plaintext == \"iii\":\n return \"\"\n else:\n crypt = [i for i in \"ADFGX\"]\n cnt = 0\n in_list = []\n the_list = []\n for i in square:\n cnt += 1\n in_list.append(i)\n if cnt == 5:\n the_list.append(in_list)\n in_list = []\n cnt = 0\n the_encrypt = \"\"\n for i in plaintext:\n for inlist in the_list:\n for char in inlist:\n if i == char:\n the_encrypt += crypt[the_list.index(inlist)] + crypt[inlist.index(char)]\n return the_encrypt\n\ndef adfgx_decrypt(ciphertext, square):\n crypt = [i for i in \"ADFGX\"]\n cnt = 0\n in_list = []\n the_list = []\n for i in square:\n cnt += 1\n in_list.append(i)\n if cnt == 5:\n the_list.append(in_list)\n in_list = []\n cnt = 0\n double_elements = 0\n crypt_in_list = []\n the_crypt_list = []\n for code in ciphertext:\n double_elements += 1\n crypt_in_list.append(code)\n if double_elements == 2:\n the_crypt_list.append(crypt_in_list)\n crypt_in_list = []\n double_elements = 0\n the_message = \"\"\n for code in the_crypt_list:\n the_message += the_list[crypt.index(code[0])][crypt.index(code[1])]\n return the_message"] | {"fn_name": "adfgx_encrypt", "inputs": [["helloworld", "bchigklnmoqprstuvwxyzadef"]], "outputs": [["AFXGDDDDDXGFDXFFDDXF"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 5,803 |
def adfgx_encrypt(plaintext, square):
|
fe76011f2ad0049130bae28ffc6d3277 | UNKNOWN | In this Kata, you will be given a string and your task will be to return a list of ints detailing the count of uppercase letters, lowercase, numbers and special characters, as follows.
```Haskell
Solve("*'&ABCDabcde12345") = [4,5,5,3].
--the order is: uppercase letters, lowercase, numbers and special characters.
```
More examples in the test cases.
Good luck! | ["def solve(s):\n uc, lc, num, sp = 0, 0, 0, 0\n for ch in s:\n if ch.isupper(): uc += 1\n elif ch.islower(): lc += 1\n elif ch.isdigit(): num += 1\n else: sp += 1\n return [uc, lc, num, sp]", "import re\ndef solve(s):\n return [len(re.findall(i,s)) for i in ('[A-Z]','[a-z]','\\d','[^a-zA-Z0-9]')]\n", "def solve(s):\n res = [0, 0, 0, 0]\n for c in s:\n i = 0 if c.isupper() else 1 if c.islower() else 2 if c.isdigit() else 3\n res[i] += 1\n return res", "from string import ascii_lowercase, ascii_uppercase, digits, punctuation\n\n\ndef solve(s):\n return [\n len([q for q in s if q in ascii_uppercase]),\n len([q for q in s if q in ascii_lowercase]),\n len([q for q in s if q in digits]),\n len([q for q in s if q in punctuation])\n ]", "def solve(s):\n lst = [0, 0, 0, 0]\n for char in s:\n if char.isupper():\n lst[0] += 1\n elif char.islower():\n lst[1] += 1\n elif char.isdigit():\n lst[2] += 1\n else:\n lst[3] += 1\n return lst", "def solve(s):\n upper, lower, digit, other = 0, 0, 0, 0\n \n for c in s:\n if c.isupper(): upper += 1\n elif c.islower(): lower += 1\n elif c.isdigit(): digit += 1\n else: other += 1\n \n return [upper, lower, digit, other]", "def solve(s):\n fs = [str.isupper, str.islower, str.isdigit]\n res = [0, 0, 0, 0]\n for c in s:\n res[next((i for i, f in enumerate(fs) if f(c)), -1)] += 1\n return res", "def solve(s):\n r = [0] * 4\n for e in s:\n r[0 if e.isupper() else 1 if e.islower() else 2 if e.isdigit() else 3] += 1\n return r", "def solve(s):\n others = [\n sum(x.isupper() for x in s),\n sum(x.islower() for x in s),\n sum(x.isnumeric() for x in s)\n ]\n return others + [len(s) - sum(others)]", "import re\ndef solve(s):\n uppercase = len(re.findall('[A-Z]', s))\n lowercase = len(re.findall('[a-z]', s))\n numbers = len(re.findall('[0-9]', s))\n special = len(re.findall('[^A-Za-z0-9]', s))\n return [uppercase, lowercase, numbers, special]\n"] | {"fn_name": "solve", "inputs": [["[email protected]"], ["bgA5<1d-tOwUZTS8yQ"], ["P*K4%>mQUDaG$h=cx2?.Czt7!Zn16p@5H"], ["RYT'>s&gO-.CM9AKeH?,5317tWGpS<*x2ukXZD"], ["$Cnl)Sr<7bBW-&qLHI!mY41ODe"], ["@mw>0=QD-iAx!rp9TaG?o&M%l$34L.nbft"]], "outputs": [[[1, 18, 3, 2]], [[7, 6, 3, 2]], [[9, 9, 6, 9]], [[15, 8, 6, 9]], [[10, 7, 3, 6]], [[7, 13, 4, 10]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,184 |
def solve(s):
|
cdcf0215176e1b83a0ea9f1c6acc42c1 | UNKNOWN | You're a buyer/seller and your buisness is at stake... You ___need___ to make profit... Or at least, you need to lose the least amount of money!
Knowing a list of prices for buy/sell operations, you need to pick two of them. Buy/sell market is evolving across time and the list represent this evolution. First, you need to buy one item, then sell it later. Find the best profit you can do.
### Example:
Given an array of prices `[3, 10, 8, 4]`, the best profit you could make would be `7` because you buy at `3` first, then sell at `10`.
# Input:
A list of prices (integers), of length 2 or more.
# Output:
The result of the best buy/sell operation, as an integer.
### Note:
Be aware you'll face lists with several thousands of elements, so think about performance. | ["def max_profit(prices):\n m = best = float('-inf')\n for v in reversed(prices):\n m, best = max(m, best-v), max(best,v)\n return m", "def max_profit(prices):\n out = prices[1] - prices[0]\n min_price = prices[0]\n \n for i in prices[1:]:\n if i - min_price > out:\n out = i - min_price\n if i < min_price:\n min_price = i\n return out", "def max_profit(prices):\n save, best = float('inf'), float('-inf')\n for p in prices:\n best = max(best, p-save)\n save = min(save, p)\n return best", "def max_profit(prices):\n mini, best = prices[0], -prices[0]\n for price in prices[1:]:\n best = max(best, price - mini)\n mini = min(mini, price)\n return best", "from itertools import islice\n\ndef max_profit(prices):\n result = prices[1] - prices[0]\n m = prices[0]\n for x in islice(prices, 1, None):\n result = max(x-m, result)\n m = min(x, m)\n return result", "import numpy as np\n\ndef max_profit(prices):\n p = np.array(prices)\n return np.array([p[i+1:].max() - prices[i] for i in range(len(prices)-1)]).max()", "def max_profit(prices):\n low = prices[0]\n profit = prices[1] - low\n for i in range(1, len(prices)):\n profit = max(profit, prices[i] - low)\n low = min(low, prices[i])\n return profit", "def max_profit(arr): \n max_diff = arr[1] - arr[0] \n min_element = arr[0] \n \n for i in range(1, len(arr)): \n if (arr[i] - min_element > max_diff): \n max_diff = arr[i] - min_element \n \n if (arr[i] < min_element): \n min_element = arr[i] \n return max_diff \n", "import numpy as np\ndef max_profit(prices):\n p = np.array(prices)\n pr = np.array([])\n for i in range(len(prices)-1):\n pr = np.append(pr, [p[i+1:].max() - prices[i]])\n return pr.max()"] | {"fn_name": "max_profit", "inputs": [[[10, 7, 5, 8, 11, 9]], [[3, 4]], [[9, 9]], [[10, 7, 5, 4, 1]]], "outputs": [[6], [1], [0], [-1]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,910 |
def max_profit(prices):
|
8993f675e939d615ac93a82f25a7ee27 | UNKNOWN | Every Turkish citizen has an identity number whose validity can be checked by these set of rules:
- It is an 11 digit number
- First digit can't be zero
- Take the sum of 1st, 3rd, 5th, 7th and 9th digit and multiply it by 7.
Then subtract the sum of 2nd, 4th, 6th and 8th digits from this value.
Modulus 10 of the result should be equal to 10th digit.
- Sum of first ten digits' modulus 10 should be equal to eleventh digit.
Example:
10167994524
// 1+1+7+9+5= 23 // "Take the sum of 1st, 3rd, 5th, 7th and 9th digit..."
// 23 * 7= 161 // "...and multiply it by 7"
// 0+6+9+4 = 19 // "Take the sum of 2nd, 4th, 6th and 8th digits..."
// 161 - 19 = 142 // "...and subtract from first value"
// "Modulus 10 of the result should be equal to 10th digit"
10167994524
^ = 2 = 142 % 10
// 1+0+1+6+7+9+9+4+5+2 = 44
// "Sum of first ten digits' modulus 10 should be equal to eleventh digit"
10167994524
^ = 4 = 44 % 10
Your task is to write a function to check the validity of a given number.
Return `true` or `false` accordingly.
Note: The input can be a string in some cases. | ["def check_valid_tr_number(n):\n return type(n) == int and len(str(n)) == 11 and \\\n 8*sum(map(int, str(n)[:-1:2])) % 10 == sum(map(int, str(n)[:-1])) % 10 == n % 10", "import re\n\ndef check_valid_tr_number(n):\n lst = list(map(int,str(n) if isinstance(n,int) else '0'))\n return (isinstance(n,int)\n and len(lst)==11 \n and sum(lst[:10]) % 10 == lst[-1]\n and (sum(lst[0:9:2])*7 - sum(lst[1:8:2])) % 10 == lst[-2])", "def check_valid_tr_number(number):\n s = str(number)\n return (\n len(s) == 11\n and s.isdigit()\n and not s.startswith('0')\n and (sum(map(int, s[:9:2])) * 7 - sum(map(int, s[1:8:2]))) % 10 == int(s) // 10 % 10\n and sum(map(int, s[:10])) % 10 == int(s) % 10\n )", "def check_valid_tr_number(n):\n if not isinstance(n, int) or not 9999999999 < n < 100000000000:\n return False\n dig = [int(d) for d in str(n)]\n return (sum(dig[:9:2])*7 - sum(dig[1:9:2])) % 10 == dig[9] and sum(dig[:10]) % 10 == dig[10]", "def check_valid_tr_number(number):\n print(number)\n if not len(str(number)) == 11 or not isinstance(number, int):\n return False\n \n number = str(number)\n odd = int(number[0])+int(number[2])+int(number[4])+int(number[6])+int(number[8])\n even = int(number[1])+int(number[3])+int(number[5])+int(number[7])\n \n sub = ((odd*7)-even)%10\n \n if str(sub) == number[9] and (((odd+even+int(number[9])) %10) == int(number[10])):\n return True\n else:\n return False", "def check_valid_tr_number(number):\n if not isinstance(number, int): return False\n s = str(number)\n if len(s) != 11: return False\n if sum(map(int, s[:-1])) % 10 != int(s[-1]): return False\n if (7*sum(map(int, s[:-1:2])) - sum(map(int, s[1:-2:2]))) % 10 != int(s[-2]): return False\n return True", "def check_valid_tr_number(number):\n n = str(number)\n return isinstance(number, int) and len(n) == 11 and str(((sum(int(n[i]) for i in range(0, 10, 2)) * 7) - sum(int(n[i]) for i in range(1, 8, 2))) % 10) == n[9] and str(sum(int(n[i]) for i in range(10)) % 10) == n[10]"] | {"fn_name": "check_valid_tr_number", "inputs": [[6923522112], [692352217312], ["x5810a78432"], [36637640050], [12762438338], ["03868894286"], [10000000146], [19415235426], [16691067984], [72097107542], [57040492705]], "outputs": [[false], [false], [false], [true], [false], [false], [true], [true], [false], [true], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,153 |
def check_valid_tr_number(number):
|
d360bfeffb30229759fd30c9d2cb9f0b | UNKNOWN | # Task:
Write a function that accepts an integer `n` and returns **the sum of the factorials of the first **`n`** Fibonacci numbers**
## Examples:
```python
sum_fib(2) = 2 # 0! + 1! = 2
sum_fib(3) = 3 # 0! + 1! + 1! = 3
sum_fib(4) = 5 # 0! + 1! + 1! + 2! = 5
sum_fib(10) = 295232799039604140898709551821456501251
```
### Constraints:
* #### **2 ≤ N ≤ 22**
### sum_fib(20)
This number is so huge I need to make a separate area for it. Imagine 13327 digits!
```
9928653736262172352930533186343606575520531508610803533683326075968136836106350614826845352855570180756973824478534264089418647583107409466601215858252808236817361583456160496394166392410547995403042278974310114004141591601125139374352094580791191335923364709192884677516337340735050881286173599870564102712009609362158555666371456178005624986162914384584598007577943876091903963220099151890758003938219580565595866639676742143436946382515603496736416191925126418083343340908123949271116414372895379936522832969271267219171603692063390922740887154834642883418078697433844957096133230670087609525899715090691322695345079984538282381903048400947073982647280054266073789965460433047857017505687076923579845694132377682637618524059408549961585446566386749648079936292462747327064278025936833852772820299004299329077053469978825203826210884509837054861371491763507148619862842220021938679732909047841993934844856085744100351944344480585890290250085308697867587494410223336675757135854894845396425849420198283310099448776692798687481179912663086426339803620627092430027074704170368638261753987720152882719584784119598849406922924689237689926900078407444035651263294341956188553177164034897593127788055904780959305194343754348362747235880809190571905064483247723280356903363273241766440842763193066919213539785095871192842692606421239731101161179953784088918780253218968714702754970829196110362712748304472981190172500985036212056008891512591715943529551666297020022545295013332792029190680584871918615789039963992955251102495832888908303508388573326404660045192343910036894576606739730009404643996768381324201684887436118525239127918313553446868369481959060346542929206914045558764481873495640902563179558939454794340645147348060531077758039291288086539035415235329745191164122884847642770184833096074380462004442126123365493535546141814052180207088441639235818177571560268970986584233066266137330817682751586180172379386539800887659067848801273458632884775993286485484439351593802875301531090263420030865043190820277288432453055603535891328518532472449422812847812206507267553254100339388907930703639015107310091345807422502366958709485299235918761467136442743369888930513387650766763462776291319611127078630770724931725881342103399855411445441188237512840869746255207308016566589688534903275723847299298209564223805258400310594489734280193445659519455562310520491149958624344934211797374144961111640480148905676602815443575797732307104495619074264135486973016187707950128055114948820599535099679109555889216345748610077647038880403151577406059562593147843869890405711177041285027897889931238424843771839668578406584337138036502578265544323641251936896555091101607304143924267167989381908487109769177267670477745652098457926314829160306769275674574505876030756947193130860459470049677851491438841393371237021867397838867622968179206043665794525786404777882878983626520891642985016057443885367272159103317999854174850166653191065899629941564603607349293929463834182817010865551370318689093045295273014513651114980596016288564139508160223681895369473793067699648316416302076351892391386318727894912644697323236666722014926057739887981902928069436545050881089761801947608921676288125099672683893303628766282286071020514503204784363394425893771312553400523338226656860526601867846681464250014432098804255258409462661142745585676872567552984225734281537836768738643384329354537747601939266791282620595759045030975407087098471302910701633632781330935697522455112544012901202754384296311873717589131299138478696753402583090947639011550806512977687205411210423316357849301559385649862307435379578361959385902196221298989933642572954710917937173791252391211314915429148069552456217875732295478439265973312228825699583169423554478095943591601486823980520979265181478839539380948270674857590218785329717118958128773306424518493835759217896759252043662826058100229991427857320674702720821115426296389687870062246589055989156285445842889514677789950880262321031452650063434014552214195771536371460986901844425547128476897052339867931194407773355276248222367620387453020534516758695700339849976170385897724159339596299051507023173489852153597518144384372166769725171047242043337130754559091790174484804816919563293006386286162511392343605301231338083421373138513205330685737005312467158986197119463173814408851556062519779146343332176587827731764626043557406516022682254455376553317636367696281143328957263465277529147227703544139848485810423066580665196185757661150648436815382333297246538979549584038243489967689778029975720307976426301731632813721053565602584006669361647374979609110217141189985003840188917225460523033372774136910715202237293584755733438042644216567563619222830113994770478752731026047788940326851901106228403003791587412047281254828416828440015032377802784094192537349093802163873170946231944133598834305362895374385296761312303210357770337974518322216075020141406284393245858603171127132598059695314335254116026015774750512204391768305611864388814440227199472085129010007050779807702538570904612612122122847785419873396835706080930837253267935078019519211144578774018539048762001166387821026612932318929275803074350763474165501151280679078295332194496653441124229917186133498390385848583459652478449111569885999320523456201264267679259698720411336081351073950683043254735712136269994989309863706475332749837817261225049835498965355121540199305600229891991390510311055201955511468648559641359346704552142776951630226650403613301783272418687520682865498961457101231849971934701035810266428273180224460545667047710066882075490868792719554023302422227138639763477450829668914441462253552608668450539166122272582169168528449566069750834510145777716497105357731601670282160142370975965269122162174709982890639939697291295471375228904389027402411105044523636299668899643497982676129894656886199644067190755704030319868386555632587398706953567999535303366271193580226657709089128550820229960260308416882836933526107327691587377547393623399330972953186821903572956890554426109892273792564476202658436982877368699363818383275571024464363253812234180181845792793023972929077048238111853410599802473730305668745780193472599637933612198999296364156279204713221276235283626829300200451729914183662584990767716790116755181810897379761267141975556520098577517615993755933880010336737582711048879991235186003896048879899162949205114351008743341082127133389810507308121724837235451061437827004583403918348794339350154038680926960868293782380474574008317208128031509436820749435677094987154671496719118040920820327150492558224268040877430396924324120417026199184321955826747197141431901476919177226217254346878767913878186347548688475492861195199281214858632047468560892609809310070198107640181730048890480497038978225910741413590570194370730003130749115464114916752595454345179936989255654870699603878866851161060795816701826411977795842165668569682457231330897409400718411292835088304936921993405033675641624187976521955004228244446698613066761411895449256872619586749956979445320224074487142401596207606341255478171157456141643714529525192876130991832916167579006407604270637756249843598869942784507887866618071296055662579691353500596369231888076374989486711621685836546185684963816358568833994505343826575562928865320538659751383972324151413647111903975144894129117141805490967234404614221912580710940662206145626801079012202740018155685922225388275607540319658217999924635859832247416785707795551860289164337197533334627825322143591076566299281852734139726398669060061427364012356206613131503747296575722224156532072756663977254150994742520621211710778895787557618218045482303060084379852358420811572817908657866670662190057861789952594451993466314364564069574684318969912777124781202527695198352359650880522887287387857757529027345970933903944473796531236930783099862375583336669555310505017811196561744578460511099439194021928186602693674359654671860317368146204110188075505252534149731812843980812547940624237843567262814283133285253930937897653100352635098717337120679226155807284748689466939956086079838110595885746613130139916205829094881298762046410938598558360125357344837946534244473840262413102128627114747968081804038270251900940965902513335390775825459105250898084371186363993871627863779925624062409301573893743068806439822744963563409079707218011171435281888565141700512698927981091846612727089877477778669289377012823124044415685345400839252784571809880579795013560422356485010963851337763312501852501309427073651842308840248721973181483285511329436724091764344874079035917982318362766292014864455202259710428424962128291813457354443795044725006153825224988609483911290917501321288252755169139113455787128689530310396891731445879174526142116320701587384574453948814035868148777367732658119774520345545849268033230248989719149723761585910729634786155492311066757412830423023217592388062762745987642551424244427273008032191956315037481291383911824942155585676496663649535850771252992699542649990490186944287473876370453000719814960648189584336387763161191340543646852608305482060694141531544009142394810789781372931168495134751777657321372292000319857647062232950656586230486886673920397794654056427228072515983426476061214304016056409168500037933108071859272519610880496790986258132266920553567366823015354488132245750701301764239392908240718371911953411492918421959129168069681436456933542324207908230546137678301833250332722752626888810140970289006477916589089543503379524601786472693487828915557196136174808810436338042378013699929852474991648407409023374169932791608084380344618735388170499897366302870465777915502098068872427872701112871075142132061242765365959925292298133381485131903408244348395101397470117677019829408610610171922941022718491779316103530497271343378039993641953787488345885112366150321408525910564079828514467058948171170356064046650092845398781480281916012072102331682413145542558482690406144983512143999906107991649126067879722887402169931955258589579638431191350838187907311860265207466608152372372686324975757176416566521640855616739172551780443241678599962342067083012790109016012557789708920368378665933606100592122866743706144656047744655504267531616892269283054115607340410319057763718556272034592657372161537684407044952851812770726615042876762960137471279787360582749788498318832487768624612393216735309107112174704997005917590506244997998484327440677599357701276620235625780027104715006458567121003924223943088598353054932602200538597908754897845417994248083861573010416290341708845316596312979430086700544475899733062567150954231823006774675784823663024300157467058615387461459584070650039355124760620620390835707206850418361441537476539111268591498489615133246551645202820903037831152063261123407680250171817323138137812181664243064610002800108244873766945365586262768271874384921780034466563639283920231853530274307280001379556387399286732464703148731202136358150075120770023425694988787417652771802108489789810295232294997367360696492315675071639130710793798755877030974532111823800049417367136357141799015726719642554174229839015284017755798832786173259586069836941404268220322258730591564817581230950070790272596989841957907031728443483956100812243968637073374397757615739553278508439590127601302123404854672654781328216788199144435601902806379348513628540817232365137238783884976806276656505352419377163767451181016485754124027864607527800888156555250523029566799443125885864101138225750570875035055230791052731355986623829344317099935988663215127843632923637509019945862723260037163763711758654934910027449834486899599704935284151804439825549707410184780069334913722693489475217978950343701008890423109631019446762801453427963033819204196016708224448110489892683975887818006071133016156204196230137144565735732627971448050002915228449970607017194915670936024070615451400858450340124834051896279154304233433399185526574106886162021602451566847606132244441829206601320244646951235636462556058511008158120562847617034399977433836554182812028983174615503556972524501626583043505526033040018204311335146256597289419055643438051722053077835209719369549795660762385560993254170876822358669533625145287503690415348418381258825644543407229190875698384908769334263504847497511095481888644836410530485021720161391301010494065372344208460777036406497525142813195828864349924050214576231802418572986682609588250501371457123447121021520167979626678883394284099255894431202158911556725161944809165555857492203486580468601431587495286434228923376855121487084939326309450268557365089173699752430489893898662385489250265455511220504498909272818152342504748405354594773985411073512586245029415937411508563697264901667841610736177613964045304417052598507762458560141472118059594453400614670799390380457850336769285069013762709299827624317895195392205084179575761814272248901581426836448816408345286493938630461130199287182091992175901271419463658156059897613116232352344615930679227026805733163636226860911569149927129575635688070885630503861218683566424095254861289021651900181379848635536499979380325867886712531123383268402905017112936324294590630632726149686444783548783464832804820259414304101857646550755288386977584758321913103895323544792245725854568887427421517632337140967111574191495525993879337401130692171554751659027957848494551494728291479587113405605656213093078075724510421856398851392665808777758866365553958287771740614526422853397161756204153702200474053334460985391821456501251
```
# Notes:
* I use `test.expect` to make tests secret. If I use `test.assert_equals`, the output will be unreadable because the numbers are huge. | ["from math import factorial\n\nfib = [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765]\n\ndef sum_fib(n):\n return sum( factorial(x) for x in fib[:n] )", "from math import factorial\n\ndef sum_fib(n):\n a, b, s = 0, 1, 0\n while n:\n s += factorial(a)\n a, b = b, a+b\n n -= 1\n return s", "from math import factorial\n\ndef sum_fib(n):\n t, a, b = 0, 0, 1\n while n:\n t += factorial(a)\n a, b, n = b, a+b, n-1\n return t", "from math import factorial\n\ndef sum_fib(n):\n fibo_num = 1\n fibo_num_prev = 0\n sum_factorial = 0\n for num in range(0,n):\n sum_factorial = sum_factorial + factorial(fibo_num_prev)\n fibo_num_prev, fibo_num = fibo_num, fibo_num + fibo_num_prev\n return sum_factorial\n", "from math import factorial\n\nresult, x, y = [0], 0, 1\nfor _ in range(20):\n result.append(result[-1] + factorial(x))\n x, y = y, x+y\n \nsum_fib = result.__getitem__", "from itertools import islice\nfrom math import factorial\n\ndef fib():\n a, b = 0, 1\n while True:\n yield a\n a, b = b, a + b\n\ndef sum_fib(n):\n return sum(map(factorial, islice(fib(), n)))", "import math\ndef sum_fib(n):\n fib_arr = []\n a, b = 0, 1\n for i in range(n):\n fib_arr.append(math.factorial(a))\n a, b = b, a + b\n return sum(fib_arr)", "from math import factorial \ndef sum_fib(n):\n a = 1\n b = 1\n s = 2\n i = 2\n while i < n: \n a, b = b, a+b \n s += factorial(a)\n i+=1\n return s\n"] | {"fn_name": "sum_fib", "inputs": [[2], [3]], "outputs": [[2], [3]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,609 |
def sum_fib(n):
|
c76e61f91d81e11118f07a80cc462829 | UNKNOWN | # Feynman's squares
Richard Phillips Feynman was a well-known American physicist and a recipient of the Nobel Prize in Physics. He worked in theoretical physics and pioneered the field of quantum computing.
Recently, an old farmer found some papers and notes that are believed to have belonged to Feynman. Among notes about mesons and electromagnetism, there was a napkin where he wrote a simple puzzle: "how many different squares are there in a grid of NxN squares?".
For example, when N=2, the answer is 5: the 2x2 square itself, plus the four 1x1 squares in its corners:
# Task
You have to write a function
```python
def count_squares(n):
```
that solves Feynman's question in general. The input to your function will always be a positive integer.
#Examples
```python
count_squares(1) = 1
count_squares(2) = 5
count_squares(3) = 14
```
(Adapted from the Sphere Online Judge problem SAMER08F by Diego Satoba) | ["def count_squares(n):\n return sum([i * i for i in range(n + 1 ) ] )", "def count_squares(n):\n return n*(n+1)*(2*n+1)/6", "def count_squares(n): \n \"\"\" Function that uses recursion to calculate the number of square units in an n X n square\"\"\"\n if n == 1:\n return 1\n else:\n return n**2 + count_squares(n - 1)", "def count_squares(n):\n return n*(n+1)*(2*n+1)//6", "def count_squares(n):\n return sum(x*x for x in range(n+1))", "count_squares=lambda n:n*(n+1)*(2*n+1)//6", "def count_squares(n):\n return (n + 1) * (2 * n + 1) * n // 6", "def count_squares(n):\n return count_squares(n-1) + n**2 if n > 0 else 0\n", "def count_squares(n): \n return n if n<2 else n ** 2 + count_squares(n-1)"] | {"fn_name": "count_squares", "inputs": [[1], [2], [3], [5], [8], [15]], "outputs": [[1], [5], [14], [55], [204], [1240]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 752 |
def count_squares(n):
|
3d8de1ed4e00bf955d684820809c02b1 | UNKNOWN | # Task
John loves encryption. He can encrypt any string by the following algorithm:
```
take the first and the last letters of the word;
replace the letters between them with their number;
replace this number with the sum of it digits
until a single digit is obtained.```
Given two strings(`s1` and `s2`), return `true` if their encryption is the same, or `false` otherwise.
# Example
For `s1 = "EbnhGfjklmjhgz" and s2 = "Eabcz"`, the result should be `true`.
```
"EbnhGfjklmjhgz" --> "E12z" --> "E3z"
"Eabcz" --> "E3z"
Their encryption is the same.```
# Input/Output
- `[input]` string `s1`
The first string to be encrypted.
`s1.length >= 3`
- `[input]` string `s2`
The second string to be encrypted.
`s2.length >= 3`
- `[output]` a boolean value
`true` if encryption is the same, `false` otherwise. | ["def same_encryption(s1, s2):\n return (s1[0], s1[-1], len(s1) % 9) == (s2[0], s2[-1], len(s2) % 9)", "def same_encryption(s1, s2):\n encrypt = lambda s: f\"{s[0]}{len(s[1:-1]) % 9}{s[-1]}\"\n return encrypt(s1) == encrypt(s2)", "def same_encryption(s1, s2):\n return ( s1[0] == s2[0]\n and s1[-1] == s2[-1]\n and len(s1) % 9 == len(s2) % 9 )", "def same_encryption(s1, s2):\n def single_digit(s):\n total = len(s) - 2\n while total > 9:\n total = sum(int(d) for d in str(total))\n \n return \"{}{}{}\".format(s[0], total, s[-1])\n \n return single_digit(s1) == single_digit(s2)", "def same_encryption(s1,s2):\n l1,l2=str(len(s1)-2),str(len(s2)-2)\n while int(l1)//10 or int(l2)//10:\n l1,l2=str(sum(map(int,l1))),str(sum(map(int,l2)))\n return l1==l2 and s1[0]==s2[0] and s1[-1]==s2[-1]", "def encrypt(s):\n n = len(s[1:-1])\n while n > 9:\n n = sum(map(int, str(n)))\n return f'{s[0]}{n}{s[-1]}'\n\ndef same_encryption(s1, s2):\n return encrypt(s1) == encrypt(s2)", "def encrypt(s):\n n = len(s[1:-1])\n while n > 10:\n n = sum(map(int, str(n)))\n return f'{s[0]}{n}{s[-1]}'\n\ndef same_encryption(s1, s2):\n return encrypt(s1) == encrypt(s2)", "from string import ascii_lowercase as alphabet\n\ndef same_encryption(s1, s2):\n sum_s1 = len(s1[1:-1])\n sum_s2 = len(s2[1:-1])\n while len(str(sum_s1)) > 1:\n sum_s1 = sum(map(int, str(sum_s1)))\n while len(str(sum_s2)) > 1:\n sum_s2 = sum(map(int, str(sum_s2)))\n return '{}{}{}'.format(s1[0], sum_s1, s1[-1]) == '{}{}{}'.format(s2[0], sum_s2, s2[-1])", "def same_encryption(a, b):\n f = lambda s: f\"{s[0]}{(len(s) - 2) % 9 or 9}{s[-1]}\"\n return f(a) == f(b)", "def same_encryption(s1, s2):\n return s1[0] == s2[0] and s1[-1] == s2[-1] and (len(s1) - 2) % 9 == (len(s2) - 2) % 9"] | {"fn_name": "same_encryption", "inputs": [["abc", "abc"], ["abc", "abd"], ["fKhjuytrdfcdc", "flJc"], ["OKhjuytrdfcdc", "OijK"]], "outputs": [[true], [false], [true], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,899 |
def same_encryption(s1, s2):
|
4ee5a6cb1c79f851ba84eb3fe900eff1 | UNKNOWN | Given three arrays of integers, return the sum of elements that are common in all three arrays.
For example:
```
common([1,2,3],[5,3,2],[7,3,2]) = 5 because 2 & 3 are common in all 3 arrays
common([1,2,2,3],[5,3,2,2],[7,3,2,2]) = 7 because 2,2 & 3 are common in the 3 arrays
```
More examples in the test cases.
Good luck! | ["from collections import Counter\ndef common(a,b,c):\n return sum((Counter(a) & Counter(b) & Counter(c)).elements())", "from functools import reduce\nfrom operator import and_\nfrom collections import Counter\n\ndef common(a,b,c):\n return sum(reduce(and_,map(Counter, (a,b,c))).elements())", "from collections import Counter\nfrom functools import reduce\nfrom operator import and_\n\ndef common(*args):\n return sum(key * value for key, value in reduce(and_, map(Counter, args)).items())", "from collections import Counter\n\ndef common(a, b, c):\n abc = Counter(a) & Counter(b) & Counter(c)\n return sum(n * q for n, q in abc.items())", "# Python is nice\nfrom collections import Counter\nfrom operator import mul, and_\nfrom itertools import starmap\nfrom functools import reduce\n\ndef common(*args):\n return sum(starmap(mul, reduce(and_, map(Counter, args)).items()))", "def common(a,b,c): \n a.sort() ; b.sort() ; c.sort()\n i = j = k = c1 = 0\n while i < len(a) and j < len(b) and k < len(c):\n if a[i] == b[j] == c[k]:\n c1 += a[i]\n i += 1 ; j += 1 ; k += 1\n elif a[i] < b[j] : i += 1\n elif b[j] < c[k] : j += 1\n else : k += 1\n return c1", "def common(a,b,c):\n d = set(a)&set(b)&set(c)\n a = [i for i in a if i in d]\n b = [i for i in b if i in d]\n c = [i for i in c if i in d]\n return sum([i*min(a.count(i), b.count(i), c.count(i)) for i in d])", "from collections import Counter\n\ndef common(a, b, c):\n abc = Counter(a) & Counter(b) & Counter(c)\n return sum(abc.elements())", "common=lambda*a,c=__import__('collections').Counter:sum(__import__('functools').reduce(c.__and__,map(c,a)).elements())", "from collections import Counter\n\ndef common(a,b,c):\n counts_a, counts_b, counts_c = Counter(a), Counter(b), Counter(c)\n sum = 0\n for n in (set(counts_a.keys()) & set(counts_b.keys())) & set(counts_c.keys()):\n sum += n * min([counts_a[n], counts_b[n], counts_c[n]])\n return sum"] | {"fn_name": "common", "inputs": [[[1, 2, 3], [5, 3, 2], [7, 3, 2]], [[1, 2, 2, 3], [5, 3, 2, 2], [7, 3, 2, 2]], [[1], [1], [1]], [[1], [1], [2]]], "outputs": [[5], [7], [1], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,028 |
def common(a,b,c):
|
66f7a8d20980ddc314614df819d84579 | UNKNOWN | Write a function with the signature shown below:
```python
def is_int_array(arr):
return True
```
* returns `true / True` if every element in an array is an integer or a float with no decimals.
* returns `true / True` if array is empty.
* returns `false / False` for every other input. | ["def is_int_array(a):\n return isinstance(a, list) and all(isinstance(x, (int, float)) and x == int(x) for x in a)", "def is_int_array(arr):\n if arr == []:\n return True\n if arr in [None, \"\"]:\n return False\n for i in arr:\n if type(i) in [int, float]:\n if int(i) != i:\n return False\n else:\n return False\n return True", "def is_int_array(arr):\n if arr is None or type(arr) is str or None in arr:\n return False\n else:\n for i in arr:\n if type(i) is str or i % 1 != 0:\n return False\n return True\n", "def is_int_array(arr):\n return isinstance(arr, list) and all(isinstance(e, int) or isinstance(e, float) and e.is_integer() for e in arr)", "def is_int_array(arr):\n return isinstance(arr, list) and all(isinstance(x, int) or isinstance(x, float) and x.is_integer() for x in arr)", "def is_int_array(arr):\n try:\n return list(map(int, arr)) == arr\n except:\n return False", "def is_int_array(arr):\n a = []\n if arr == None or arr == \"\":\n return False\n \n for i in arr:\n if type(i) == int:\n a.append(i)\n else:\n if type(i) == float and i.is_integer():\n a.append(i)\n \n if len(arr) == len(a):\n return True\n return False", "def is_int_array(arr):\n return isinstance(arr, list) and all(map(lambda x: isinstance(x, (int,float)) and int(x)==x, arr))", "is_int_array=lambda a:isinstance(a,list) and all(isinstance(i,(int,float)) and i==int(i) for i in a)", "def isInt(n):\n try:\n return int(n) == float(n)\n except (TypeError, ValueError):\n return False\n\ndef is_int_array(arr):\n my_list = []\n \n if type(arr) is not list:\n return False\n \n if not arr:\n return True\n else:\n for x in arr:\n if type(x) is int or type(x) is float:\n if isInt(x):\n my_list.append(1)\n if len(arr) == len(my_list):\n return True\n else:\n return False"] | {"fn_name": "is_int_array", "inputs": [[[]], [[1, 2, 3, 4]], [[-11, -12, -13, -14]], [[1.0, 2.0, 3.0]], [[1, 2, null]], [null], [""], [[null]], [[1.0, 2.0, 3.0001]], [["-1"]]], "outputs": [[true], [true], [true], [true], [false], [false], [false], [false], [false], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,156 |
def is_int_array(arr):
|
475483bd7ba82580299ebb4d9756214d | UNKNOWN | Imagine two rings with numbers on them. The inner ring spins clockwise (decreasing by 1 each spin) and the outer ring spins counter clockwise (increasing by 1 each spin). We start with both rings aligned on 0 at the top, and on each move we spin each ring one increment. How many moves will it take before both rings show the same number at the top again?
The inner ring has integers from 0 to innerMax and the outer ring has integers from 0 to outerMax, where innerMax and outerMax are integers >= 1.
```
e.g. if innerMax is 2 and outerMax is 3 then after
1 move: inner = 2, outer = 1
2 moves: inner = 1, outer = 2
3 moves: inner = 0, outer = 3
4 moves: inner = 2, outer = 0
5 moves: inner = 1, outer = 1
Therefore it takes 5 moves for the two rings to reach the same number
Therefore spinningRings(2, 3) = 5
```
```
e.g. if innerMax is 3 and outerMax is 2 then after
1 move: inner = 3, outer = 1
2 moves: inner = 2, outer = 2
Therefore it takes 2 moves for the two rings to reach the same number
spinningRings(3, 2) = 2
```
---
for a bigger challenge, check out the [Performance Version](https://www.codewars.com/kata/59b0b7cd2a00d219ab0000c5) of this kata by @Voile | ["from itertools import count\n\ndef spinning_rings(inner_max, outer_max):\n return next(i for i in count(1) if i % (outer_max + 1) == -i % (inner_max + 1))", "def spinning_rings(inner_max, outer_max):\n a,b,res = inner_max,1,1\n while a != b:\n a = (a + inner_max) % (inner_max+1)\n b = (b + 1) % (outer_max+1)\n res += 1\n return res", "from itertools import cycle\n\ndef spinning_rings(inMax, outMax):\n inc, outc = ( cycle([0]+list(range(1,inMax+1))[::-1]),\n cycle(range(outMax+1)) )\n a, b, count = next(inc), next(outc), 0\n while True:\n a, b, count = next(inc), next(outc), count+1\n if a == b: return count", "def spinning_rings(inner_max, outer_max):\n moves, inner, outer = 0, 0, 0\n\n while True:\n inner -= 1 # decrease inner ring by 1\n inner %= inner_max + 1 # wrap if count goes beyond `inner_max`\n \n outer += 1 # increase outer ring by 1\n outer %= outer_max + 1 # wrap if count goes beyond `outer_max`\n \n moves += 1 # count moves\n \n if(inner == outer):\n break\n\n return moves", "def spinning_rings(inner_max, outer_max):\n a,b,c = 0,0,0\n while True:\n a = (a - 1) % (inner_max + 1)\n b = (b + 1) % (outer_max + 1)\n c += 1\n if a == b: return c", "def spinning_rings(inner_max, outer_max):\n inner, outer = 0, 0\n while True:\n inner -= 1 \n outer += 1\n \n if inner % (inner_max + 1) == outer % (outer_max + 1):\n return outer", "def spinning_rings(inner_max, outer_max):\n i = 1\n while -(i%(-inner_max - 1)) != i%(outer_max + 1):\n i += 1\n return i", "from itertools import cycle\n\ndef spinning_rings(inner_max, outer_max):\n out = cycle(range(outer_max + 1))\n inn = cycle([0] + list(range(inner_max, 0, -1)))\n next(inn); next(out)\n count = 0\n while next(inn) != next(out):\n count += 1\n return count + 1", "def spinning_rings(inner_max, outer_max):\n innerList = [0] + [i for i in range(inner_max, 0, -1)]\n outerList = [0] + [i for i in range(1, outer_max+1)]\n \n tries = 1\n while True:\n if innerList[tries % (inner_max+1)] == outerList[tries % (outer_max+1)]:\n return tries\n break\n tries += 1\n"] | {"fn_name": "spinning_rings", "inputs": [[2, 3], [3, 2], [1, 1], [2, 2], [3, 3]], "outputs": [[5], [2], [1], [3], [2]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,336 |
def spinning_rings(inner_max, outer_max):
|
51b2c5f6bd620094dacd27b80da70b15 | UNKNOWN | In this Kata, you will be given a multi-dimensional array containing `2 or more` sub-arrays of integers. Your task is to find the maximum product that can be formed by taking any one element from each sub-array.
```
Examples:
solve( [[1, 2],[3, 4]] ) = 8. The max product is given by 2 * 4
solve( [[10,-15],[-1,-3]] ) = 45, given by (-15) * (-3)
solve( [[1,-1],[2,3],[10,-100]] ) = 300, given by (-1) * 3 * (-100)
```
More examples in test cases. Good luck! | ["def solve(arr):\n \n p, q = 1, 1\n \n for k in arr:\n \n x, y = max(k), min(k)\n \n a = p * x\n b = q * x\n c = p * y\n d = q * y\n \n p = max(a, b, c, d)\n q = min(a, b, c, d)\n \n return max(p, q)", "def solve(arr):\n result = arr[0]\n for number_array in range(1, len(arr)):\n result = [x * y for x in result for y in arr[number_array]]\n return max(result)\n", "def solve(arr, cur = [1]):\n return solve(arr[1:], [x*y for x in cur for y in arr[0]]) if arr else max(cur)", "from itertools import product\nfrom functools import reduce\n\ndef solve(arr):\n return max( reduce(int.__mul__, p,1) for p in product(*arr) )", "from itertools import product\nfrom functools import reduce\nfrom operator import mul\n\ndef solve(A):\n return max(map(lambda g: reduce(mul, g, 1), product(*A)))", "from functools import reduce\ndef solve(arr):\n f = lambda x, y: [i*j for i in x for j in y]\n return max(reduce(f, arr))\n \n \n", "from itertools import product\nfrom functools import reduce\n\ndef solve(arr):\n return max(reduce(lambda m, n: m * n, prod) for prod in product(*arr))", "from functools import reduce\nfrom itertools import product\nfrom operator import mul\n\ndef solve(arr):\n xss = [[min(a), max(a)] for a in arr]\n return max(reduce(mul, xs) for xs in product(*xss))", "def solve(arr, cur = []):\n return (solve(arr[1:], [x*y for x in cur for y in arr[0]]) if cur else solve(arr[1:], arr[0])) if arr else max(cur)", "def solve(a):\n r_min = r_max = 1\n for x in a:\n cur = [n * m for n in [min(x), max(x)] for m in [r_min, r_max]]\n r_min = min(cur)\n r_max = max(cur)\n return r_max"] | {"fn_name": "solve", "inputs": [[[[1, 2], [3, 4]]], [[[10, -15], [-1, -3]]], [[[-1, 2, -3, 4], [1, -2, 3, -4]]], [[[-11, -6], [-20, -20], [18, -4], [-20, 1]]], [[[14, 2], [0, -16], [-12, -16]]], [[[-3, -4], [1, 2, -3]]], [[[-2, -15, -12, -8, -16], [-4, -15, -7], [-10, -5]]]], "outputs": [[8], [45], [12], [17600], [3584], [12], [-40]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,768 |
def solve(arr):
|
70ff649a0f00dace2a0059912ed5c350 | UNKNOWN | Mr Leicester's cheese factory is the pride of the East Midlands, but he's feeling a little blue. It's the time of the year when **the taxman is coming round to take a slice of his cheddar** - and the final thing he has to work out is how much money he's spending on his staff. Poor Mr Leicester can barely sleep he's so stressed. Can you help?
- Mr Leicester **employs 4 staff**, who together make **10 wheels of cheese every 6 minutes**.
- Worker pay is calculated on **how many wheels of cheese they produce in a day**.
- Mr Leicester pays his staff according to the UK living wage, which is currently **£8.75p an hour**. There are **100 pence (p) to the UK pound (£)**.
The input for function payCheese will be provided as an array of five integers, one for each amount of cheese wheels produced each day.
When the workforce don't work a nice integer number of minutes - much to the chagrin of the company accountant - Mr Leicester very generously **rounds up to the nearest hour** at the end of the week (*not the end of each day*). Which means if the workers make 574 wheels on each day of the week, they're each paid 29 hours for the week (28.699 hours rounded up) and not 30 (6 hours a day rounded up * 5).
The return value should be a string (with the £ included) of the **total £ of staff wages for that week.** | ["from math import ceil\ndef pay_cheese(arr):\n return f'L{ceil(sum(arr) / 100) * 35}'", "from math import ceil\n\ndef pay_cheese(lst):\n return f\"L{35 * ceil(sum(lst) / 100)}\"", "from math import ceil\ndef pay_cheese(a): \n return f\"L{round(ceil(((sum(a)*6.)/10.)/60.)*35)}\"", "pay_cheese=lambda l:f\"L{-sum(l)//100*-35}\"", "from math import ceil; pay_cheese=lambda arr: \"L\"+str(ceil(sum(arr)/100)*35)", "from math import ceil\ndef pay_cheese(arr):\n p=ceil(sum(arr)*6/600)\n return 'L{}'.format(int(p*8.75*4))", "def pay_cheese(arr):\n return 'L{}'.format(-sum(arr)//100*-35)", "def pay_cheese(arr):\n return 'L' + str(-sum(arr)//100*-35)\n", "def pay_cheese(arr):\n a,b = divmod(sum(arr), 100)\n return 'L'+ str(int((a + (b > 0))*35))", "import math\n\ndef pay_cheese(arr):\n return f'L{round(math.ceil(sum(map(lambda x: x / 100, arr))) * 4 * 8.75)}'"] | {"fn_name": "pay_cheese", "inputs": [[[750, 750, 750, 750, 600]], [[700, 750, 700, 750, 600]], [[574, 574, 574, 574, 574]], [[1, 1, 1, 1, 1]], [[0, 0, 0, 0, 0]]], "outputs": [["L1260"], ["L1225"], ["L1015"], ["L35"], ["L0"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 895 |
def pay_cheese(arr):
|
aa4b58ebdb31f0680783d890604b1c82 | UNKNOWN | # Task
Given an integer `product`, find the smallest positive integer the product of whose digits is equal to product. If there is no such integer, return -1 instead.
# Example
For `product = 1`, the output should be `11`;
`1 x 1 = 1` (1 is not a valid result, because it has only 1 digit)
For `product = 12`, the output should be `26`;
`2 x 6 = 12`
For `product = 19`, the output should be `-1`.
No valid result found.
For `product = 450`, the output should be `2559`.
`2 x 5 x 5 x 9 = 450`
For `product = 581`, the output should be `-1`.
No valid result found.
Someone says the output should be `783`, because `7 x 83 = 581`.
Please note: `83` is not a **DIGIT**.
# Input/Output
- `[input]` integer `product`
Constraints: `0 ≤ product ≤ 600`.
- `[output]` a positive integer | ["def digits_product(product):\n if product < 10:\n return 10 + product\n n = ''\n for d in range(9, 1, -1):\n while not product % d:\n n += str(d)\n product //= d\n return int(n[::-1]) if product == 1 else -1", "from functools import reduce\nfrom operator import mul\n\ndef digits_product(product):\n if product == 0:\n return 10\n elif len(str(product)) == 1:\n return int('1' + str(product))\n temp = product\n digits = []\n units = list(range(9, 1, -1))\n for i in units:\n if product % i == 0:\n exponent = 0\n while product % i == 0:\n exponent += 1\n product //= i\n digits.append((i, exponent))\n res = \"\"\n for digit, occurances in digits:\n res += str(digit)*occurances\n return int(res[::-1]) if res and reduce(mul, [int(i) for i in res]) == temp else -1", "def digits_product(product):\n if product < 10: return 10 + product\n a = ''\n while product > 1:\n for i in range(9, 1, -1):\n if product % i == 0:\n a += str(i)\n product //= i\n break\n else:return -1\n return int(a[::-1])", "from functools import reduce\nfrom operator import mul\n\nPRODUCTS = {}\nfor n in range(10, 5000):\n dig_prod = reduce(mul, map(int, str(n)))\n if dig_prod < 600 and dig_prod not in PRODUCTS:\n PRODUCTS[dig_prod] = n\n\n\ndef digits_product(product):\n return PRODUCTS.get(product, -1)", "def digits_product(product):\n\n if product < 10: return 10 + product\n \n lst = []\n for d in range(9, 1, -1):\n while product % d == 0:\n product /= d\n lst.append(d)\n return -1 if product != 1 else int( ''.join(map(str, lst[::-1])) )", "def prime_factors(num):\n factors = []\n while num % 2 == 0:\n factors.append(2)\n num //= 2\n\n i = 3\n max_factor = num**0.5\n while i <= max_factor:\n while num % i == 0:\n factors.append(i)\n num //= i\n max_factor = num**0.5\n i += 2\n\n if num > 1:\n factors.append(num)\n return factors\n\n\ndef digits_product(product):\n if product == 0:\n return 10\n elif product == 1:\n return 11\n \n factors = prime_factors(product)\n if not set(factors) <= {2, 3, 5, 7}:\n return -1\n if len(factors) == 1:\n return 10 + factors[0]\n\n factors = \"\".join(str(f) for f in factors)\n factors = \"\".join(sorted(factors.replace(\"33\", \"9\")))\n factors = factors.replace(\"222\", \"8\")\n factors = factors.replace(\"23\", \"6\")\n factors = factors.replace(\"22\", \"4\")\n if len(factors) == 1:\n factors += \"1\"\n return int(\"\".join(sorted(factors)))", "import math\n\ndef getNumber(n):\n N = n\n number = ''\n divisor = 9\n \n while divisor > 1 and n > 0:\n if n%divisor == 0:\n number += str(divisor)\n n //= divisor\n else:\n divisor -= 1\n \n return int(number[::-1]) if number and n == 1 else -1\n\ndef digits_product(product):\n if product == 0:\n return 10\n if 0 < product < 10:\n return 10 + product\n \n return getNumber(product)", "def digits_product(product):\n if product<10:\n return 10+product\n res=factorization(product)\n for i in res:\n if i>=10:\n return -1\n reduce(res)\n total=0\n for i,j in enumerate(res):\n total+=10**(len(res)-i-1)*j\n return total\ndef factorization(n):\n res=[]\n factor=2\n while factor*factor<=n:\n if n%factor==0:\n res.append(factor)\n n//=factor\n factor=2\n else:\n factor+=1\n res.append(n)\n return res\ndef is_prime(n):\n for i in range(2, int(n**0.5)+1):\n if n%i==0:\n return False\n return True\ndef reduce(res):\n while res.count(3)>=2:\n res.remove(3)\n res.remove(3)\n res.append(9)\n while res.count(2)>=3:\n res.remove(2)\n res.remove(2)\n res.remove(2)\n res.append(8)\n while res.count(2)>=1 and res.count(3)>=1:\n res.remove(2)\n res.remove(3)\n res.append(6)\n while res.count(2)>=2:\n res.remove(2)\n res.remove(2)\n res.append(4)\n res.sort()", "from math import gcd, log\nfrom operator import mul\nfrom functools import reduce\n\ndef digits_product(product):\n if product <= 1: return 10 + product\n count = lambda p: round(log(gcd(product, p ** 9), p))\n n2, n3, n5, n7 = map(count, [2, 3, 5, 7])\n digits = [5] * n5 + [7] * n7 + [8] * (n2 // 3) + [9] * (n3 // 2)\n n2 %= 3\n n3 %= 2\n if n3 and n2:\n digits.append(6)\n n3 -= 1\n n2 -= 1\n digits.extend([4] * (n2 // 2) + [2] * (n2 % 2) + [3] * n3)\n if len(digits) <= 1:\n digits.append(1)\n return int(''.join(map(str, sorted(digits)))) if reduce(mul, digits) == product else -1", "def digits_product(product):\n if product < 10:\n return 10 + product\n \n facs = []\n \n for p in (2,3,5,7):\n while product % p == 0:\n facs.append(p)\n product //= p\n \n if product != 1:\n return -1\n \n while facs.count(3) >= 2:\n facs.remove(3)\n facs.remove(3)\n facs.append(9)\n \n while facs.count(2) >= 3:\n facs.remove(2)\n facs.remove(2)\n facs.remove(2)\n facs.append(8)\n \n while 2 in facs and 3 in facs:\n facs.remove(2)\n facs.remove(3)\n facs.append(6)\n \n while facs.count(2) >= 2:\n facs.remove(2)\n facs.remove(2)\n facs.append(4)\n \n return int(\"\".join(sorted(str(x) for x in facs)))\n \n"] | {"fn_name": "digits_product", "inputs": [[12], [19], [450], [0], [13], [1], [5], [10]], "outputs": [[26], [-1], [2559], [10], [-1], [11], [15], [25]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 5,935 |
def digits_product(product):
|
858664bfa5b1082820bfedabea02bc51 | UNKNOWN | The medians of a triangle are the segments that unit the vertices with the midpoint of their opposite sides.
The three medians of a triangle intersect at the same point, called the barycenter or the centroid.
Given a triangle, defined by the cartesian coordinates of its vertices we need to localize its barycenter or centroid.
The function ```bar_triang() or barTriang or bar-triang```, receives the coordinates of the three vertices ```A, B and C ``` as three different arguments and outputs the coordinates of the barycenter ```O``` in an array ```[xO, yO]```
This is how our asked function should work:
the result of the coordinates should be expressed up to four decimals, (rounded result).
You know that the coordinates of the barycenter are given by the following formulas.
For additional information about this important point of a triangle see at: (https://en.wikipedia.org/wiki/Centroid)
Let's see some cases:
```python
bar_triang([4, 6], [12, 4], [10, 10]) ------> [8.6667, 6.6667]
bar_triang([4, 2], [12, 2], [6, 10] ------> [7.3333, 4.6667]
```
The given points form a real or a degenerate triangle but in each case the above formulas can be used.
Enjoy it and happy coding!! | ["def bar_triang(a, b, c):\n return [round(sum(x)/3.0, 4) for x in zip(a, b, c)]", "def bar_triang(pointA, pointB, pointC): \n a = (pointA[0] + pointB[0] + pointC[0]) / 3.0\n b = (pointA[1] + pointB[1] + pointC[1]) / 3.0\n return [round(a, 4), round(b, 4)]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n return [round((pointA[0] + pointB[0] + pointC[0]) / 3.0, 4), round((pointA[1] + pointB[1] + pointC[1]) / 3.0, 4)]", "def bar_triang(*args):\n return [round(sum(a) / 3.0, 4) for a in zip(*args)]\n", "bar_triang = lambda *points: [round(sum(point) / 3., 4) for point in zip(*points)]", "from numpy import mean\n\ndef bar_triang(*points):\n return [round(mean(dim), 4) for dim in zip(*points)]", "def bar_triang(x, y, z):\n return [round(float(x[0] + y[0] + z[0]) / 3, 4), round(float(x[1] + y[1] + z[1]) / 3, 4)]", "def bar_triang(A, B, C):\n return [round(sum(axis)/3.0, 4) for axis in zip(A,B,C)]", "def bar_triang(*points):\n return [round(sum(x) / 3., 4) for x in zip(*points)]", "bar_triang = lambda *p: [round(sum(z)/3., 4) for z in zip(*p)]", "def bar_triang(*pts):\n return [ round(1.0*sum(ps) / len(pts), 4) for ps in zip(*pts) ]", "def bar_triang(*coords):\n return [round(1.0 * sum(c) / len(coords), 4) for c in zip(*coords)]", "import numpy as np\n\ndef bar_triang(*points):\n return np.mean(points, axis=0).round(4).tolist()", "def bar_triang(p1, p2, p3):\n return [float(\"%2.4f\" % ((p1[0]+p2[0]+p3[0])/3.0)), float(\"%2.4f\" % ((p1[1]+p2[1]+p3[1])/3.0))] ", "bar_triang=lambda *args: [round(sum(a[0] for a in args)/3.0,4), round(sum(a[1] for a in args)/3.0,4)]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n # your code here\n xO = '{:.4f}'.format(float(pointA[0]+pointB[0]+pointC[0])/3)\n yO = '{:.4f}'.format(float(pointA[1]+pointB[1]+pointC[1])/3)\n return [float(xO), float(yO)] # coordinated of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pa, pb, pc, n=3., r=round):\n return [r((pa[0]+pb[0]+pc[0])/n,4), r((pa[1]+pb[1]+pc[1])/n,4)]", "def bar_triang(a, b, c): # points A, B and C will never be aligned\n # your code here\n x0= (a[0] +b[0] +c[0] )/3\n y0= (a[1] +b[1] +c[1] )/3\n return [ round(x0,4), round(y0,4) ]", "def bar_triang(a, b, c): # points A, B and C will never be aligned\n xO=round((a[0]+b[0]+c[0])/3,4)\n yO=round((a[1]+b[1]+c[1])/3,4)\n return [xO, yO] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pointA, pointB, pointC):\n x = sum([pointA[0], pointB[0], pointC[0]]) / 3.0\n y = sum([pointA[1], pointB[1], pointC[1]]) / 3.0\n return [round(x, 4), round(y, 4)] ", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n x1, y1 = pointA\n x2, y2 = pointB\n x3, y3 = pointC\n x0 = (x1+x2+x3)/3\n y0 = (y1+y2+y3)/3\n return [round(x0,4), round(y0,4)]", "def bar_triang(pointA, pointB, pointC):\n return [ round(sum(i) / 3 ,4) for i in zip(pointA, pointB, pointC)]", "def bar_triang(A, B, C):\n xO = round(sum(x[0] for x in (A, B, C)) / 3, 4)\n yO = round(sum(x[1] for x in (A, B, C)) / 3, 4)\n return [xO, yO]", "def bar_triang(pointA, pointB, pointC): \n x_0 = round((pointA[0]+pointB[0]+pointC[0])/3 ,4)\n y_0 = round((pointA[1]+pointB[1]+pointC[1])/3 ,4)\n return [x_0, y_0] ", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n return list(map(lambda x:round(sum(x)/3, 4), zip(pointA, pointB, pointC)))", "def bar_triang(a,b,c):\n return list(map(lambda p: round(sum(p)/3,4), zip(*(a,b,c))))", "def bar_triang(pointA, pointB, pointC):\n return [round((pointA[i] + pointB[i] + pointC[i]) / 3, 4) for i in range(2)]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n # your code here\n x0 = (pointA[0]+pointB[0]+pointC[0])/3;\n y0 = (pointA[1]+pointB[1]+pointC[1])/3;\n return [round(x0,4), round(y0,4)]", "def bar_triang(pa, pb, pc):\n xa, ya = pa\n xb, yb = pb\n xc, yc = pc\n xO = round((xa + xb + xc) / 3, 4)\n yO = round((ya + yb + yc) / 3, 4)\n return [xO, yO]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n xO = round(sum(x[0] for x in [pointA, pointB, pointC])/3,4)\n yO = round(sum(y[1] for y in [pointA, pointB, pointC])/3,4)\n return [xO, yO] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n mod = lambda indx: round(sum(list([_[indx] for _ in [pointA, pointB, pointC]]))/3, 4)\n return [mod(0), mod(1)]\n", "import math\ndef bar_triang(a, b, c): # points A, B and C will never be aligned\n x = round(((a[0] + b[0] + c[0]) / 3), 4)\n y = round(((a[1] + b[1] + c[1]) / 3), 4)\n return [x, y]", "def bar_triang(a, b, c):\n return [round((a[i]+b[i]+c[i])/3,4) for i in range(len(a))]", "def bar_triang(pointA, pointB, pointC):\n x_bary = round((pointA[0]+pointB[0]+pointC[0])/3, 4)\n y_bary = round((pointA[1]+pointB[1]+pointC[1])/3, 4)\n return [x_bary, y_bary]\n", "def bar_triang(a, b, c): \n x0 = round((a[0]+b[0]+c[0])/3,4)\n y0 = round((a[1]+b[1]+c[1])/3,4)\n return [x0,y0]\n", "def bar_triang(A, B, C): # points A, B and C will never be aligned\n return [round((A[0]+B[0]+C[0])/3,4),round((A[-1]+B[-1]+C[-1])/3,4)]", "def bar_triang(A,B,C): # points A, B and C will never be aligned\n # your code here\n return [round((A[0]+B[0]+C[0])/3,4),round((A[1]+B[1]+C[1])/3,4)] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(p1, p2, p3):\n return [round((p1[0]+p2[0]+p3[0])/3,4),round((p1[1]+p2[1]+p3[1])/3,4)]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n # your code here\n x = (pointA[0]+pointB[0]+pointC[0])/3\n y = (pointA[1]+pointB[1]+pointC[1])/3\n return [round(x*10000)/10000, round(y*10000)/10000]", "def bar_triang(*dots):\n x_sum = y_sum = 0\n for d in dots:\n x_sum += d[0]\n y_sum += d[1]\n xO = f'{x_sum/3:.4f}'\n yO = f'{y_sum/3:.4f}'\n return [float(xO), float(yO)]", "def bar_triang(a, b, c): # points A, B and C will never be aligned\n return [round((a[i]+b[i]+c[i])/3, 4) for i in (0, 1) ]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n xO = (pointA[0] + pointB[0] + pointC[0]) / 3\n yO = (pointA[1] + pointB[1] + pointC[1]) / 3\n xO = round(xO, 4)\n yO = round(yO, 4)\n return [xO, yO] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pointA, pointB, pointC):\n x = (pointA[0] + pointB[0] + pointC[0]) / 3\n y = (pointA[1] + pointB[1] + pointC[1]) / 3\n return [round(x, 4), round(y, 4)]", "def bar_triang(pA, pB, pC): \n return [round((pA[0]+pB[0]+pC[0])/3,4), round((pA[1]+pB[1]+pC[1])/3,4)]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n # your code here\n x0=pointA[0]+pointB[0]+pointC[0]\n y0=pointA[1]+pointB[1]+pointC[1]\n x0=round(x0/3,4)\n y0=round(y0/3,4)\n return [x0, y0] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n return [ round(sum(x/3 for x, _ in [pointA, pointB, pointC]), 4),\n round(sum(y/3 for _, y in [pointA, pointB, pointC]), 4) ]", "def bar_triang(pA, pB, pC):\n xO = round((pA[0]+pB[0]+pC[0])/3,4)\n yO = round((pA[1]+pB[1]+pC[1])/3,4)\n return [xO,yO]", "def bar_triang(pointsA, pointsB, pointsC): \n return [round((pointsA[0] + pointsB[0] + pointsC[0]) / 3, 4), round((pointsA[1] + pointsB[1] + pointsC[1]) / 3, 4)]", "def bar_triang(A, B, C):\n x = round((A[0] + B[0] + C[0]) / 3, 4)\n y = round((A[1] + B[1] + C[1]) / 3, 4)\n return [x, y]", "def bar_triang(*p): # points A, B and C will never be aligned\n return list([round(sum(x)/3, 4) for x in zip(*p)]) # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(A, B, C): \n x0 = (A[0]+B[0]+C[0])/3\n y0 = (A[1]+B[1]+C[1])/3\n return [round(x0,4), round(y0,4)] ", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n #print(pointA[0])\n x0 = float(f'{(pointA[0] + pointB[0] + pointC[0])/3 : .4f}')\n y0 = float(f'{(pointA[1] + pointB[1] + pointC[1])/3 : .4f}')\n return [x0, y0] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pointA, pointB, pointC):\n x,y,lst=0,0,[pointA,pointB,pointC]\n for i in range(3):\n x+=lst[i][0]\n y+=lst[i][1]\n return [round(x/3,4), round(y/3,4)]", "from statistics import mean\ndef bar_triang(pointA, pointB, pointC): \n return [round(mean(row),4) for row in zip(pointA,pointB,pointC)]\n", "def bar_triang(A, B, C):\n xO = (A[0]+B[0]+C[0])/3\n yO = (A[1]+B[1]+C[1])/3 \n return [round(xO,4), round(yO,4)] ", "bar_triang=lambda a,b,c:[round((abs(a[0]+b[0])+abs(a[0]+c[0])+abs(b[0]+c[0]))/6,4),round((abs(a[1]+b[1])+abs(a[1]+c[1])+abs(b[1]+c[1]))/6,4)]", "import numpy as np\ndef bar_triang(pointA, pointB, pointC):\n x0 = np.around((pointA[0] + pointB[0] + pointC[0]) / 3, decimals=4)\n y0 = np.around((pointA[1] + pointB[1] + pointC[1]) / 3, decimals=4) \n return [x0, y0]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n xa, xb, xc = pointA[0], pointB[0], pointC[0]\n ya, yb, yc = pointA[1], pointB[1], pointC[1]\n x = round((xa+xb+xc)/3, 4)\n y = round((ya+yb+yc)/3, 4)\n return [x, y]", "bar_triang = lambda A, B, C: [round(sum(i) / 3, 4) for i in zip(A, B, C)]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n x1,x2,x3 = pointA[0],pointB[0],pointC[0]\n y1,y2,y3 = pointA[1],pointB[1],pointC[1]\n return [round((x1+x2+x3)/3,4),round((y1+y2+y3)/3,4)]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n xo = round((pointA[0] + pointB[0] + pointC[0]) / 3, 4)\n yo = round((pointA[1] + pointB[1] + pointC[1]) / 3, 4)\n return [xo, yo]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n \n xa, ya = pointA\n xb, yb = pointB\n xc, yc = pointC\n \n xO = round((xa + xb + xc) / 3, 4)\n yO = round((ya + yb + yc) / 3, 4)\n \n return [xO, yO] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "from typing import List\n\n\ndef bar_triang(a: List[int], b: List[int], c: List[int]) -> List[float]:\n return [round((a[0] + b[0] + c[0]) / 3, 4), round((a[1] + b[1] + c[1]) / 3, 4)]\n", "def bar_triang(A, B, C): # points A, B and C will never be aligned\n x0 = round((A[0] + B[0] + C[0])/3,4)\n y0 = round((A[1] + B[1] + C[1])/3,4)\n return [x0, y0] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pointA, pointB, pointC):\n return [round(i,4) for i in list(map(lambda x, y, z: (x + y + z) / 3, pointA, pointB, pointC))]", "bar_triang = lambda a,b,c: [round((a[0]+b[0]+c[0])/3,4), round((a[1]+b[1]+c[1])/3,4)]", "def bar_triang(pointA, pointB, pointC): \n # points A, B and C will never be aligned\n # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n return [round((pointA[i] + pointB[i] + pointC[i]) / 3, 4) for i in range(2)]\n", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n xa, ya, xb, yb, xc, yc = pointA + pointB + pointC\n return [round((xa + xb + xc) / 3, 4), round((ya + yb + yc) / 3, 4)]", "def bar_triang(A, B, C):\n return [round((A[0]+B[0]+C[0])/3,4), round((A[1]+B[1]+C[1])/3,4)] ", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n xO, yO = round((pointA[0] + pointB[0] + pointC[0]) / 3, 4), round((pointA[1] + pointB[1] + pointC[1]) / 3, 4)\n return [xO, yO] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(a, b, c): # points A, B and C will never be aligned\n xO = (a[0] + b[0] + c[0]) / 3\n yO = (a[1] + b[1] + c[1]) / 3\n return [round(xO, 4), round(yO, 4)] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pointA, pointB, pointC):\n xA, yA = pointA\n xB, yB = pointB\n xC, yC = pointC\n \n x0 = (xA + xB + xC) / 3\n y0 = (yA + yB + yC) / 3 \n \n return [round(x0, 4), round(y0, 4)]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n x0 = (float(pointA[0]) + float(pointB[0]) + float(pointC[0]))/3\n y0 = (float(pointA[1]) + float(pointB[1]) + float(pointC[1]))/3\n return [round(x0,4), round(y0,4)] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n xO = round((pointA[0] + pointB[0] + pointC[0]) / 3, 4)\n yO = round((pointA[1] + pointB[1] + pointC[1]) / 3, 4)\n return [xO, yO] ", "def bar_triang(pointA, pointB, pointC):\n \n x0 = (pointA[0] + pointB[0] + pointC[0]) / 3\n \n y0 = (pointA[1] + pointB[1] + pointC[1]) / 3\n \n return [round(x0,4), round(y0,4)]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n xa = pointA[0]\n xb = pointB[0]\n xc = pointC[0]\n ya = pointA[1]\n yb = pointB[1]\n yc = pointC[1]\n xO = round((xa+xb+xc)/3,4)\n yO = round((ya+yb+yc)/3,4)\n return [xO, yO] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n return [round(x/3, 4) for x in [sum(i) for i in zip(pointA, pointB, pointC)]]\n", "def bar_triang(a, b, c): # points A, B and C will never be aligned\n # your code here\n return [round((a[0]+b[0]+c[0])/3,4), round((a[1]+b[1]+c[1])/3,4)] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "import numpy as np \ndef bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n # your code here\n return [np.round((pointA[0]+pointB[0]+pointC[0])/3,4), np.round((pointA[1]+pointB[1]+pointC[1])/3,4)] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pointA, pointB, pointC):\n [xa,ya] = pointA\n [xb,yb] = pointB\n [xc,yc] = pointC\n return [round((xa+xb+xc)/3,4),round((ya+yb+yc)/3,4)]", "def bar_triang(a, b, c): # points A, B and C will never be aligned\n x = (a[0] + b[0] + c[0])/3\n y = (a[1] + b[1] + c[1])/3\n return [round(x,4),round(y,4)]", "def bar_triang(pointA, pointB, pointC):\n return list(map(lambda x: round(sum(x) / 3, 4), zip(pointA, pointB, pointC)))", "from statistics import mean\ndef bar_triang(pointA, pointB, pointC):\n return [round(mean(x), 4) for x in zip(pointA, pointB, pointC)]", "def bar_triang(pointA, pointB, pointC):\n\n return([round((a + b + c) / 3, 4)\n for a, b, c in zip(pointA, pointB, pointC)])", "def bar_triang(*points):\n center_x = sum(point[0] for point in points) / len(points)\n center_y = sum(point[1] for point in points) / len(points)\n return [round(center_x, 4), round(center_y, 4)]", "def bar_triang(A, B, C): # points A, B and C will never be aligned\n # your code here\n return [round((A[0] + B[0] + C[0]) / 3, 4), round((A[1] + B[1] + C[1]) / 3, 4)] ", "def bar_triang(pointA, pointB, pointC):\n x0 = round((pointA[0] + pointB[0] + pointC[0]) / 3, 4)\n y0 = round((pointA[1] + pointB[1] + pointC[1]) / 3, 4)\n return [x0, y0]", "def bar_triang(a, b, c): # points A, B and C will never be aligned\n xO = round((a[0] + b[0] + c[0]) / 3, 4)\n yO = round((a[1] + b[1] + c[1]) / 3, 4)\n return [xO, yO]", "def bar_triang(pA, pB, pC):\n x = round((pA[0] +pB[0] + pC[0]) / 3, 4)\n y = round((pA[1] +pB[1] + pC[1]) / 3, 4)\n return [x, y]\n # Flez\n", "def bar_triang(a, b, c): # points A, B and C will never be aligned\n return [round((a[0]+b[0]+c[0])/3,4),round((a[1]+b[1]+c[1])/3,4)]", "def bar_triang(a, b, c):\n xO = (a[0] + b[0] + c[0]) / 3\n yO = (a[1] + b[1] + c[1]) / 3\n return [round(xO, 4), round(yO, 4)] ", "def bar_triang(pointA, pointB, pointC):\n xO = round((pointA[0] + pointB[0] + pointC[0]) / 3, 4)\n yO = round((pointA[1] + pointB[1] + pointC[1]) / 3, 4)\n return [xO, yO]", "def bar_triang(A, B, C): # points A, B and C will never be aligned\n xO = round((A[0] + B[0] + C[0]) / 3, 4)\n yO = round((A[1] + B[1] + C[1]) / 3, 4)\n return [xO, yO] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n # your code here\n ax, ay = pointA\n bx, by = pointB\n cx, cy = pointC\n x0 = round((ax + bx + cx) / 3, 4)\n y0 = round((ay + by + cy) / 3, 4)\n return [x0, y0] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n return [round((pointA[0] + pointB[0] + pointC[0])/3,4),round((pointA[1] + pointB[1] + pointC[1])/3,4)]", "def bar_triang(pointA, pointB, pointC): # points A, B and C will never be aligned\n # your code here\n xO = round(1/3 * (pointA[0] + pointB[0] + pointC[0]),4)\n yO = round(1/3 * (pointA[1] + pointB[1] + pointC[1]),4)\n return [xO, yO] # coordinates of the barycenter expressed up to four decimals\n # (rounded result)\n"] | {"fn_name": "bar_triang", "inputs": [[[4, 6], [12, 4], [10, 10]], [[4, 2], [12, 2], [6, 10]], [[4, 8], [8, 2], [16, 6]]], "outputs": [[[8.6667, 6.6667]], [[7.3333, 4.6667]], [[9.3333, 5.3333]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 18,341 |
def bar_triang(pointA, pointB, pointC):
|
42f3644c14a23b12ff6ba50c6c558efb | UNKNOWN | In this kata you must take an input string, reverse the order of the words, and reverse the order of the letters within the words.
But, as a bonus, every test input will end with a punctuation mark (! ? .) and the output should be returned with the mark at the end.
A few examples should help clarify:
```python
esrever("hello world.") == "dlrow olleh."
esrever("Much l33t?") == "t33l hcuM?"
esrever("tacocat!") == "tacocat!"
```
Quick Note: A string will always be passed in (though it may be empty) so no need for error-checking other types. | ["def esrever(s):\n return s[:-1][::-1] + s[-1] if s else ''", "def esrever(string):\n return string and string[-2::-1] + string[-1]", "def esrever(string):\n return string[:-1][::-1] + string[-1:]", "def esrever(string):\n return string[-2::-1] + string[-1:]", "esrever = lambda s: s[-2::-1] + s[:-2:-1]", "def esrever(stg):\n return f\"{stg[-2::-1]}{stg[-1:]}\"", "def esrever(s):\n return s and \" \".join(x[::-1] for x in reversed(s[:-1].split())) + s[-1]", "def esrever(string):\n if len(string) <= 1:\n return string\n\n return string[-2::-1] + string[-1]", "def esrever(string):\n return string[-2::-1] + string[-1] if string else \"\"", "def esrever(s):\n return '' if not s else s[:-1][::-1]+s[-1]"] | {"fn_name": "esrever", "inputs": [["an Easy one?"], ["a small lOan OF 1,000,000 $!"], ["<?> &!.\"."], ["b3tTer p4ss thIS 0ne."], [""]], "outputs": [["eno ysaE na?"], ["$ 000,000,1 FO naOl llams a!"], ["\".!& >?<."], ["en0 SIht ss4p reTt3b."], [""]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 745 |
def esrever(string):
|
5878b38edbf145b52ce56bd19d1fe7cf | UNKNOWN | # Task
You are given a decimal number `n` as a **string**. Transform it into an array of numbers (given as **strings** again), such that each number has only one nonzero digit and their sum equals n.
Each number in the output array should be written without any leading and trailing zeros.
# Input/Output
- `[input]` string `n`
A non-negative number.
`1 ≤ n.length ≤ 30.`
- `[output]` a string array
Elements in the array should be sorted in descending order.
# Example
For `n = "7970521.5544"` the output should be:
```
["7000000",
"900000",
"70000",
"500",
"20",
"1",
".5",
".05",
".004",
".0004"]
```
For `n = "7496314"`, the output should be:
```
["7000000",
"400000",
"90000",
"6000",
"300",
"10",
"4"]
```
For `n = "0"`, the output should be `[]` | ["def split_exp(n):\n dot = n.find('.')\n if dot == -1: dot = len(n)\n return [d+\"0\"*(dot-i-1) if i<dot else \".{}{}\".format(\"0\"*(i-dot-1), d)\n for i,d in enumerate(n) if i != dot and d != '0']", "def split_exp(n):\n j = n.find('.') + 1 or len(n) + 1\n return [f\"{c}{'0'*(j-i-2)}\" if i < j else f\".{'0'*(i-j)}{c}\" for i,c in enumerate(n) if c not in \"0.\"]", "def split_exp(n):\n d = n.split('.')\n result = [c + '0' * (len(d[0]) - i - 1) for i, c in enumerate(d[0]) if c != '0']\n if len(d) == 2:\n result += ['.' + '0' * i + c for i, c in enumerate(d[1]) if c != '0']\n return result ", "def split_exp(n):\n integer, decimal = n.split(\".\") if (\".\" in n) else (n, \"\")\n length = len(integer)\n result = [d.ljust(length - i, \"0\") for i, d in enumerate(integer) if int(d)]\n if decimal:\n result.extend(\".\" + d.rjust(i, \"0\") for i, d in enumerate(decimal, 1) if int(d))\n return result", "split_exp=lambda n:(lambda d:[('.'+'0'*(i-d-1)+x,x+'0'*(d-i-1))[d>i]for i,x in enumerate(n)if x not in'.0'])((len(n),n.find('.'))['.'in n])", "def split_exp(n):\n try:\n dot = n.index('.')\n except:\n dot = len(n)\n return [n[i]+'0'*(dot-1-i) for i in range(dot) if n[i] != '0'] +\\\n ['.' + '0'*(i-dot-1) + n[i] for i in range(dot+1,len(n)) if n[i] != '0']", "def split_exp(n):\n return [y.ljust(len(x)-j,'0') if i==0 else '.'+y.zfill(j+1) for i,x in enumerate(n.split('.')) for j,y in enumerate(x) if y!='0']", "def split_exp(n):\n o = n.index(\".\") if \".\" in n else len(n)\n split = lambda i, c: \"{}{}{}\".format(\n \"\" if o - i > 0 else \".{}\".format(\"0\" * (- (o - i + 1))),\n c,\n \"0\" * (o - i - 1))\n return [split(i, c) for i, c in enumerate(n) if i - o != 0 if float(split(i, c)) != 0]", "split_exp=lambda n: (lambda d: [e+ \"0\"*(d-i-1) if d>i else \".\"+\"0\"*(i-d-1)+e for i,e in enumerate(n) if e not in \".0\"])(n.index(\".\") if \".\" in n else len(n))", "import re\ndef split_exp(n):\n r=[n[0:i+1]+re.sub(r\"\\.0+$\",\"\",re.sub(r\"\\d\",\"0\",n[i+1:])) for i in range(len(n))]\n r=[re.sub(\"\\d(?!$)\",\"0\",re.sub(r\".+(?=\\.)|0+$\",\"\",x)) if \".\" in x else re.findall(r\"\\d0*$\",x)[0] for x in r]\n rs=[]\n for x in r:\n if(not (re.match(r\"^[0.]+$\",x) or x in rs)): rs.append(x) \n return rs"] | {"fn_name": "split_exp", "inputs": [["7970521.5544"], ["7496314"], ["0"], ["6"], ["1.0000000000"], ["0000000000.1"], ["1010101"], ["1234567890.1234567890"]], "outputs": [[["7000000", "900000", "70000", "500", "20", "1", ".5", ".05", ".004", ".0004"]], [["7000000", "400000", "90000", "6000", "300", "10", "4"]], [[]], [["6"]], [["1"]], [[".1"]], [["1000000", "10000", "100", "1"]], [["1000000000", "200000000", "30000000", "4000000", "500000", "60000", "7000", "800", "90", ".1", ".02", ".003", ".0004", ".00005", ".000006", ".0000007", ".00000008", ".000000009"]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,375 |
def split_exp(n):
|
328f50c7924201420a9613765f335dcf | UNKNOWN | In this kata, your task is to write a function `to_bytes(n)` (or `toBytes(n)` depending on language) that produces a list of bytes that represent a given non-negative integer `n`. Each byte in the list is represented by a string of `'0'` and `'1'` of length 8. The most significant byte is first in the list. The example test cases should provide you with all the details. You may assume that the argument `n` is valid. | ["def to_bytes(n):\n if not n:\n return ['00000000']\n \n res = []\n while n:\n res.append('{:08b}'.format(n % 256))\n n //= 256\n \n return res[::-1]", "import re\nfrom math import ceil\ndef to_bytes(n):\n return re.findall('.{8}', '{:0{}b}'.format(n, int(8 * ceil(n.bit_length() / 8.0)))) or [8 * '0']", "to_bytes=b=lambda n,f=1:n and b(n>>8,0)+[format(n&255,'08b')]or['0'*8]*f", "def to_bytes(n):\n b = bin(n)[2:]\n b = '0'*(8-len(b)%8)*(len(b)%8!=0) + b\n return [b[8*i:8*i+8] for i in range(len(b)//8)]", "def to_bytes(n):\n L = 8\n s = bin(n)[2:]\n s = s.rjust(len(s) + L - 1 - (len(s) - 1) % 8, '0')\n return [s[i:i+L] for i in range(0, len(s), L)]", "def to_bytes(n):\n if n==0: return ['00000000']\n s=bin(n)[2:]\n s=s.rjust(len(s)+7-(len(s)-1)%8,'0')\n return [s[i:i+8] for i in range(0, len(s), 8)]", "def to_bytes(n):\n n = bin(n)[2::]\n while len(n) % 8 != 0:\n n = '0' + n\n return [n[i: i+8] for i in range(0, len(n), 8)]", "to_bytes = lambda n, d=__import__(\"itertools\").dropwhile: list(d((\"0\"*8).__eq__, map(\"\".join, zip(*[iter(bin(n)[2:].zfill(8 * (((len(bin(n)) - 2) // 8) + 1)))]*8)))) or [\"0\"*8]", "def to_bytes(n):\n return [''.join(t) for t in zip(*[iter(format(n,'0{}b'.format((max(1,n.bit_length())+7)//8*8)))]*8)]"] | {"fn_name": "to_bytes", "inputs": [[0], [1]], "outputs": [[["00000000"]], [["00000001"]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,343 |
def to_bytes(n):
|
ba9a143370f0509d3c619418aa94cffa | UNKNOWN | Consider a sequence, which is formed by the following rule: next term is taken as the smallest possible non-negative integer, which is not yet in the sequence, so that `no 3` terms of sequence form an arithmetic progression.
## Example
`f(0) = 0` -- smallest non-negative
`f(1) = 1` -- smallest non-negative, which is not yet in the sequence
`f(2) = 3` -- since `0, 1, 2` form an arithmetic progression
`f(3) = 4` -- neither of `0, 1, 4`, `0, 3, 4`, `1, 3, 4` form an arithmetic progression, so we can take smallest non-negative, which is larger than `3`
`f(4) = 9` -- `5, 6, 7, 8` are not good, since `1, 3, 5`, `0, 3, 6`, `1, 4, 7`, `0, 4, 8` are all valid arithmetic progressions.
etc...
## The task
Write a function `f(n)`, which returns the `n-th` member of sequence.
## Limitations
There are `1000` random tests with `0 <= n <= 10^9`, so you should consider algorithmic complexity of your solution. | ["sequence=lambda n:int(format(n,'b'),3)", "def sequence(n):\n return int(format(n, 'b'), 3)", "sequence=lambda n:int(bin(n)[2:],3)", "# A005836\ndef sequence(n):\n return n and 3*sequence(n>>1) + (n&1)", "from math import log2\n\ndef sequence(i):\n if i == 0:\n return 0\n e = int(log2(i))\n return 3**e + sequence(i - 2**e)", "import numpy as np\ndef sequence(n):\n return ter2dec(dec2bin(n))\n \ndef dec2bin(n):\n bin = np.array([])\n while n > 0:\n bin = np.append(bin, [n%2])\n n = n//2\n return bin\n\ndef ter2dec(ter):\n dec = 0\n for i in range(len(ter)):\n dec += ter[i]*3**i\n return dec\n\n# Induction hypothesis:\n# Let S(n) be the sequence of numbers m that don't form arithmetic sequences, such that m < n.\n# For a given k, assume that all S(m) is precisely all the numbers m < k without 2's in their ternary form.\n# If m has at least one 2 in it's expansion there exist numbers in the sequence with the 2's repalced by 0's and the 2's replaced by 1's.\n# This forms an arithmetic sequence.\n# If m has no 2's, consider A and B such that A,B,m is an arithmetic sequence and B is in S(m).\n# Comparing the rightmost digits of B and m which are different. A must have a 2 in this position to form an arithmetic sequence.\n# Hence A is not in S(m) and m will be the next number in the sequence.\n# \n# Therefore the next number in the sequence has no 2's in it's ternary form.\n#\n# Base case: S(1) is 0, S(2) is 0,1.\n#\n# There is a trivial bijection between the nth numbers ternary form and the binary form of n.\n\n", "\ndef sequence(n):\n # Thx OEIS\n return int(format(n, 'b'), 3) # Chai Wah Wu, Jan 04 2015", "def sequence(n):\n return int(f'{n:b}', 3)", "def sequence(n):\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n#Thank SERGEY FOR THIS KATA!!!!!!!!!!!!!!!!!!!!!!!\n return int(bin(n)[2:],3)\n", "def sequence(n):\n return 3 * sequence(n // 2) + n % 2 if n > 0 else 0"] | {"fn_name": "sequence", "inputs": [[0], [1], [2], [3], [4], [5], [334], [123], [546], [1634], [14514]], "outputs": [[0], [1], [3], [4], [9], [10], [7329], [1084], [19929], [79707], [2305425]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,876 |
def sequence(n):
|
73f0b9313500ef7017843b1d0ab7120b | UNKNOWN | In some countries of former Soviet Union there was a belief about lucky tickets. A transport ticket of any sort was believed to posess luck if sum of digits on the left half of its number was equal to the sum of digits on the right half. Here are examples of such numbers:
```
003111 # 3 = 1 + 1 + 1
813372 # 8 + 1 + 3 = 3 + 7 + 2
17935 # 1 + 7 = 3 + 5 // if the length is odd, you should ignore the middle number when adding the halves.
56328116 # 5 + 6 + 3 + 2 = 8 + 1 + 1 + 6
```
Such tickets were either eaten after being used or collected for bragging rights.
Your task is to write a funtion ```luck_check(str)```, which returns ```true/True``` if argument is string decimal representation of a lucky ticket number, or ```false/False``` for all other numbers. It should throw errors for empty strings or strings which don't represent a decimal number. | ["def luck_check(string):\n e0, b1 = len(string) // 2, (len(string) + 1) // 2\n return sum(map(int, string[:e0])) == sum(map(int, string[b1:]))", "def luck_check(s):\n if not s or not all(c in '0123456789' for c in s):\n raise ValueError('Invalid ticket number')\n e0, b1 = len(s) // 2, (len(s) + 1) // 2\n return sum(map(int, s[:e0])) == sum(map(int, s[b1:]))", "luck_check = lambda s: sum(map(int,s[:len(s)//2])) == sum(map(int, s[len(s)//2 + len(s)%2:]))", "def luck_check(string):\n lsum = 0\n rsum = 0\n i = 0\n j = len(string) - 1\n while i < j:\n lsum += int(string[i])\n rsum += int(string[j])\n i += 1\n j -= 1\n return lsum == rsum", "def luck_check(s):\n q, r = divmod(len(s), 2)\n return sum(int(a) for a in s[:q]) == sum(int(b) for b in s[q + r:])\n"] | {"fn_name": "luck_check", "inputs": [["5555"], ["003111"], ["543970707"], ["439924"], ["943294329932"], ["000000"], ["454319"], ["1233499943"], ["935336"]], "outputs": [[true], [true], [false], [false], [false], [true], [true], [false], [false]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 838 |
def luck_check(string):
|
bd144843df2fac53f95b915179669e04 | UNKNOWN | Lucas numbers are numbers in a sequence defined like this:
```
L(0) = 2
L(1) = 1
L(n) = L(n-1) + L(n-2)
```
Your mission is to complete the function that returns the `n`th term of this sequence.
**Note:** It should work for negative numbers as well; how you do this is you flip the equation around, so for negative numbers: `L(n) = L(n+2) - L(n+1)`
## Examples
```
L(-10) = 123
L(-5) = -11
L(-1) = -1
L(0) = 2
L(1) = 1
L(5) = 11
L(10) = 123
``` | ["def lucasnum(n):\n a = 2\n b = 1\n\n flip = n < 0 and n % 2 != 0\n\n for _ in range(abs(n)):\n a, b = b, a + b\n \n return -a if flip else a", "SEQUENCE = [2, 1]\n\ndef lucasnum(n):\n try:\n return SEQUENCE[abs(n)] * (1, -1)[n < 0 and n % 2]\n except IndexError:\n while len(SEQUENCE) < abs(n) + 1:\n SEQUENCE.append(SEQUENCE[-1] + SEQUENCE[-2])\n return lucasnum(n)", "from numpy import matrix\n\ndef lucasnum(n):\n return int((matrix('2 1; 1 3') * matrix(\n '0 1; 1 1' if n >= 0 else '-1 1; 1 0', object\n ) ** abs(n))[0, 0])", "memo = {0:2, 1:1}\ncurrent = [-1, 2]\n\ndef lucasnum(n):\n while n not in memo:\n if n < 0:\n x = current[0]\n memo[x] = memo[x+2] - memo[x+1]\n current[0] -= 1\n else:\n x = current[1]\n memo[x] = memo[x-2] + memo[x-1]\n current[1] += 1\n return memo[n]", "def lucasnum(n):\n a, b = 2, 1\n for i in range(abs(n)):\n a, b = b, a + b\n return a * (-1 if n < 0 and n % 2 else 1)", "memo = [2,1]\n\ndef lucasnum(n):\n m = abs(n)\n while len(memo) < m+1:\n memo.append(memo[-1]+memo[-2])\n return memo[m] * (-1)**(n<0 and n%2)", "def lucasnum(n):\n a, b, i = 2, 1, 0\n while True:\n if i == n: return a\n if n > 0:\n i += 1\n a, b = b, a+b\n else:\n i -= 1\n b,a = a, b-a ", "def lucasnum(n):\n if n == 1:\n return 1\n elif n == 0:\n return 2\n elif n > 1:\n a, b = 2, 1\n for i in range(n):\n a, b = b, a+b\n return a\n else:\n a, b = -1, -2\n for i in range(abs(n)):\n a, b = b, a-b\n return b*-1", "def lucasnum(n):\n if n == 0:\n return 2\n elif n == 1:\n return 1\n else:\n if n > 1:\n a, b = 2, 1\n for i in range(n):\n a, b = b, a+b\n return a\n else:\n a, b = -1, -2\n for i in range(abs(n)):\n a, b = b, a-b\n return b*-1\n", "lucas_sieve = [2, 1, 3, 4, 7]\ndef lucasnum(n):\n neg, n = 1 if n >= 0 or n % 2 == 0 else -1, abs(n)\n return neg * lucas_expand(n)\ndef lucas_expand(n):\n l = len(lucas_sieve)\n while n >= l:\n lucas_sieve.append(lucas_sieve[l - 1] + lucas_sieve[l - 2])\n l = len(lucas_sieve)\n return lucas_sieve[n]"] | {"fn_name": "lucasnum", "inputs": [[-10], [-1]], "outputs": [[123], [-1]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,477 |
def lucasnum(n):
|
a0b637079f18996c4d041d796f2fcd6b | UNKNOWN | `late_clock` function receive an array with 4 digits and should return the latest time that can be built with those digits.
The time should be in `HH:MM` format.
Examples:
```
[1, 9, 8, 3] => 19:38
[9, 1, 2, 5] => 21:59
```
You can suppose the input is correct and you can build from it a correct 24-hour time. | ["from itertools import permutations\n\ndef late_clock(digits):\n for p in permutations(sorted(digits, reverse=True)):\n if p[0] > 2 or (p[0] == 2 and p[1] > 3) or p[2] > 5: continue\n return '{}{}:{}{}'.format(*p)", "def late_clock(digits):\n res, digits = [], digits[:]\n def rec(i):\n if i == 3:\n res.append(digits.pop())\n return True\n maxi = 2 if i==0 else 5 if i==2 else 3 if res[0]==2 else 9\n for x in range(maxi, -1, -1):\n if x in digits:\n res.append(digits.pop(digits.index(x)))\n if rec(i+1): return True\n digits.append(res.pop())\n return False\n \n rec(0)\n return \"{}{}:{}{}\".format(*res)", "from itertools import permutations\n\n\ndef late_clock(digits):\n for combo in permutations(sorted(digits, reverse=True)):\n if combo[:2] < (2, 4) and combo[2] < 6:\n return \"{}{}:{}{}\".format(*combo)", "from itertools import permutations\n\ndef late_clock(digits):\n return max(\n f'{a}{b}:{c}{d}'\n for a,b,c,d in permutations(digits)\n if 0 <= a*10+b < 24 and 0 <= c*10+d < 60\n )", "def late_clock(digits):\n result = ''\n minute = '_'\n lessSix = 0\n digits = sorted(digits, reverse = True)\n for d in digits:\n if d < 6:\n lessSix += 1\n for d in digits:\n if d < 3:\n if lessSix < 3 and d == 2:\n continue\n result += str(d)\n digits.remove(d)\n break\n for d in digits:\n if (d < 4 and result == '2') or (d < 10 and result != '2'):\n result += str(d) + ':'\n digits.remove(d)\n break\n for d in digits:\n if d < 6:\n minute= str(d)\n digits.remove(d)\n break\n result += minute + str(digits.pop())\n return result", "from itertools import permutations\n\ndef late_clock(digits):\n return \"{}{}:{}{}\".format(*max(c for c in permutations(digits) if c[:2] < (2,4) and c[2:] < (6,0)))", "from itertools import permutations\n\ndef late_clock(digits):\n mx = max(t for t in [''.join(p) for p in permutations(''.join(str(d) for d in digits))] if t[:2] < '24' and t[2:] < '60')\n return '{}:{}'.format(mx[:2], mx[2:])", "from itertools import permutations\n\n\ndef late_clock(digits):\n decreasing_combos = permutations(sorted(digits, reverse=True))\n max_combo = next(c for c in decreasing_combos if c[:2] < (2, 4) and c[2] < 6)\n return \"{}{}:{}{}\".format(*max_combo)", "from itertools import *\nfrom datetime import *\n\ndef late_clock(digits):\n dt = []\n for a,b,c,d in permutations(digits,4):\n try:\n dt.append(datetime.strptime(f'{a}{b}:{c}{d}', '%H:%M'))\n except:\n pass\n return max(dt).strftime('%H:%M')", "from datetime import datetime as dt\nfrom itertools import permutations\ndef late_clock(a):\n li = []\n for i in permutations(list(map(str, a))): \n try : d = dt.strptime(f'{\"\".join(i[:2])}:{\"\".join(i[2:])}', \"%H:%M\")\n except : continue\n li.append(d)\n return str(min(li, key=lambda x: dt.now() - x))[11:16]"] | {"fn_name": "late_clock", "inputs": [[[9, 1, 2, 5]], [[1, 9, 8, 3]], [[0, 2, 2, 2]], [[3, 5, 0, 2]], [[9, 0, 1, 1]], [[2, 3, 2, 4]], [[1, 2, 8, 9]]], "outputs": [["21:59"], ["19:38"], ["22:20"], ["23:50"], ["19:10"], ["23:42"], ["19:28"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,222 |
def late_clock(digits):
|
32ea8a9c04d6ea6d8e7497c191afc248 | UNKNOWN | ## Task
Write a method `remainder` which takes two integer arguments, `dividend` and `divisor`, and returns the remainder when dividend is divided by divisor. Do NOT use the modulus operator (%) to calculate the remainder!
#### Assumption
Dividend will always be `greater than or equal to` divisor.
#### Notes
Make sure that the implemented `remainder` function works exactly the same as the `Modulus operator (%)`.
```if:java
`SimpleInteger` is a tiny and immutable implementation of an integer number. Its interface is a very small subset of the `java.math.BigInteger` API:
* `#add(SimpleInteger val)`
* `#subtract(SimpleInteger val)`
* `#multiply(SimpleInteger val)`
* `#divide(SimpleInteger val)`
* `#compareTo(SimpleInteger val)`
``` | ["def remainder(dividend,divisor):\n while divisor <= dividend:\n dividend = dividend - divisor\n return dividend", "# Take your pick\nfrom operator import mod as remainder\nremainder = int.__mod__", "def remainder(d1,d2):\n return d1%d2", "def remainder(dividend,divisor):\n return dividend - (dividend // divisor) * divisor if divisor else None", "def remainder(dividend,divisor):\n rem = dividend\n while rem >= divisor:\n rem -= divisor\n return rem", "from math import floor\ndef remainder(dividend, divisor): return \"NaN\" if divisor == 0 else dividend - floor(dividend / divisor) * divisor", "def remainder(dividend, divisor):\n return dividend - (dividend//divisor)*divisor", "def remainder(a, b):\n return a % b\n #your code here; you can use % but your are lame if you do ;)\n"] | {"fn_name": "remainder", "inputs": [[3, 2], [19, 2], [10, 2], [34, 7], [27, 5]], "outputs": [[1], [1], [0], [6], [2]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 827 |
def remainder(dividend, divisor):
|
ef8acc86ed95efd868e955663860c4e2 | UNKNOWN | ## Task
Given a string, add the fewest number of characters possible from the front or back to make it a palindrome.
## Example
For the input `cdcab`, the output should be `bacdcab`
## Input/Output
Input is a string consisting of lowercase latin letters with length 3 <= str.length <= 10
The output is a palindrome string satisfying the task.
For s = `ab` either solution (`aba` or `bab`) will be accepted. | ["def build_palindrome(s):\n for n in range(len(s), -1, -1):\n if s[:n] == s[:n][::-1]:\n return s[n:][::-1] + s\n if s[-n:] == s[-n:][::-1]:\n return s + s[:-n][::-1]", "def build_palindrome(s):\n a = s[1:][::-1] + s\n temp = s\n for i in range(len(s)+1):\n temp = s[::-1][:i] + s\n if temp == temp[::-1] and len(temp)<len(a):\n a = temp\n\n b = s + s[::-1]\n temp = s\n for i in range(len(s)+1):\n temp = s + s[::-1][i:]\n if temp == temp[::-1] and len(temp)<len(b):\n b = temp\n if len(a)>len(b):\n return b\n else:\n return a\n", "def is_palindrome(s):\n \"\"\"Check if s is a palindrome\"\"\"\n return s == s[::-1]\n\n\ndef left_strip_palindrome(s):\n \"\"\"Keeps stripping from left to find a palindrome. If not found return None. \n If found return the stripped characters in stripping order\"\"\"\n for i in range(len(s)-1):\n if is_palindrome(s[i:]):\n return s[:i]\n return None\n\ndef right_strip_palindrome(s):\n \"\"\"Keeps stripping from right to find a palindrome. If not found return None. \n If found return the stripped characters in stripping order\"\"\"\n for i in range(-1,1-len(s),-1):\n if is_palindrome(s[:i]):\n return s[i:]\n \ndef build_palindrome(s):\n \"\"\"Build a palindrome by adding the min number of characters possible.\"\"\"\n lsp = left_strip_palindrome(s)\n rsp = right_strip_palindrome(s)\n # Answer is obtained by getting the stripped characters and add them in reverse order \n # to the opps direction they were stripped from in reverse direction.\n if lsp is not None:\n lsp_ans = s+lsp[::-1]\n if rsp is not None:\n rsp_ans = rsp[::-1]+s\n # In the case both left stripping and right stripping works, return the shortest answer.\n return min((lsp_ans,rsp_ans), key=len)\n return lsp_ans\n \n if rsp is not None:\n rsp_ans = rsp[::-1]+s\n return rsp_ans\n \n # If stripping does not work return the string with the copy of all characters \n # but the first concatenated at the starting in reverse order.\n return s[1:][::-1]+s\n", "def is_palindrome(s):\n return s == s[::-1]\n\ndef build_palindrome(s):\n for i in range(len(s)):\n x = s + s[:i][::-1]\n if is_palindrome(x):\n return x\n x = s[-i or len(s):][::-1] + s\n if is_palindrome(x):\n return x", "def build_palindrome(s,i=0):\n def bp(s):\n a = s+s[:i][::-1]\n if a == a[::-1]: return a\n return bp(s) or bp(s[::-1]) or build_palindrome(s,i+1)\n", "def build_palindrome(s):\n if list(s) == list(s)[::-1]:\n return s\n \n for i in range(1, len(s)):\n if s[i:] == s[i:][::-1]: #checks if element i -> end of list == element i -> end of list, in reverse ([][] calls on elements of a nexted list)\n break\n endAdd = s + s[0:i][::-1] #adds the non symetric part to the begining of the string, in reverse order\n \n for i in range(1, len(s)):\n if s[:-i] == s[:-i][::-1]: #checks if element 0 -> i == element 0 -> i, in reverse ([][] calls on elements of a nexted list)\n break \n frontAdd = s[-i:][::-1] + s #adds the non symetric part to the begining of the string, in reverse order\n \n print(endAdd)\n print(frontAdd)\n if len(list(endAdd)) <= len(list(frontAdd)):\n #print('1') #too see which one gets printed\n return endAdd\n else:\n #print('2') #too see which one gets printed\n return frontAdd", "def is_palindrome(word: str) -> bool:\n \"\"\"Tell if the given word is a palindrome.\"\"\"\n return word[::-1] == word\n\n\ndef build_left_palindrome(word: str) -> str:\n \"\"\"Build the shorter palindrome adding letters to the left.\n\n We search the maximal prefix that is a palindrome. Adding the\n corresponding suffix to the left gives the shorter solution.\n \"\"\"\n length = len(word)\n while not is_palindrome(word[:length]):\n length -= 1\n return word[length:][::-1] + word\n\n\ndef build_right_palindrome(word: str) -> str:\n \"\"\"Build the shorter palindrome adding letters to the right.\"\"\"\n return build_left_palindrome(word[::-1])[::-1]\n\n\ndef build_palindrome(word: str) -> str:\n \"\"\"Add letters to the right or the left of the given word to get the\n shorter palindrome.\n \"\"\"\n return sorted([\n build_left_palindrome(word), \n build_right_palindrome(word)\n ], key=len)[0]", "def build_palindrome(s):\n l = len(s)\n left = next(l-i for i in range(l, 0, -1) if s[:i] == s[i-1::-1])\n right = next(l-i for i in range(l, 0, -1) if s[-i:] == s[:-i-1:-1] or left == l-i)\n return s[:-left-1:-1] + s if left <= right else s + s[right-1::-1]", "def build_palindrome(s):\n a = s[1:][::-1] + s\n b = s + s[::-1]\n temp = s\n for i in range(len(s)+1):\n temp = s[::-1][:i] + s\n if temp == temp[::-1] and len(temp)<len(a):\n a = temp\n temp = s + s[::-1][i:]\n if temp == temp[::-1] and len(temp)<len(b):\n b = temp\n\n\n if len(a)>len(b):\n return b\n else:\n return a\n", "def build_palindrome(s):\n rev=s[::-1]\n for i in range(len(s)): \n if s[i:]==s[i:][::-1]: return s+s[:i][::-1]\n if rev[i:]==rev[i:][::-1]: return rev[:i]+s"] | {"fn_name": "build_palindrome", "inputs": [["abcdc"], ["ababa"]], "outputs": [["abcdcba"], ["ababa"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 5,535 |
def build_palindrome(s):
|
80a7db2dfb786bc2c4345cd6f2a7a5e9 | UNKNOWN | # Task
In the field, two beggars A and B found some gold at the same time. They all wanted the gold, and they decided to use simple rules to distribute gold:
```
They divided gold into n piles and be in line.
The amount of each pile and the order of piles all are randomly.
They took turns to take away a pile of gold from the
far left or the far right.
They always choose the bigger pile. That is to say,
if the left is 1, the right is 2, then choose to take 2.
If the both sides are equal, take the left pile.
```
Given an integer array `golds`, and assume that A always takes first. Please calculate the final amount of gold obtained by A and B. returns a two-element array `[amount of A, amount of B]`.
# Example
For `golds = [4,2,9,5,2,7]`, the output should be `[14,15]`.
```
The pile of most left is 4,
The pile of most right is 7,
A choose the largest one -- > take 7
The pile of most left is 4,
The pile of most right is 2,
B choose the largest one -- > take 4
The pile of most left is 2,
The pile of most left is 2,
A choose the most left one -- > take 2
The pile of most left is 9,
The pile of most right is 2,
B choose the largest one -- > take 9
The pile of most left is 5,
The pile of most left is 2,
A choose the largest one -- > take 5
Tehn, only 1 pile left,
B -- > take 2
A: 7 + 2 + 5 = 14
B: 4 + 9 + 2 = 15
```
For `golds = [10,1000,2,1]`, the output should be `[12,1001]`.
```
A take 10
B take 1000
A take 2
B take 1
A: 10 + 2 = 12
B: 1000 + 1 = 1001
``` | ["def distribution_of(golds):\n g = golds[:]\n turn, total = 0, [0, 0]\n while g:\n total[turn % 2] += g.pop(-(g[0] < g[-1]))\n turn += 1\n return total\n", "from collections import deque\ndef distribution_of(golds):\n g = deque(golds)\n s = [0, 0]\n t = 0\n while g:\n s[t] += (g.popleft, g.pop)[g[0] < g[-1]]()\n t ^= 1\n return list(s)", "def distribution_of(golds):\n ind, beggars = [0, len(golds)-1], [0, 0]\n for n in range(len(golds)):\n i = golds[ind[0]] < golds[ind[1]]\n beggars[n%2] += golds[ind[i]]\n ind[i] += (-1)**i\n return beggars", "def distribution_of(golds):\n g = golds[:]\n turn, total, i, j = 0, [0, 0], 0, len(g) - 1\n while i <= j:\n total[turn % 2] += max(g[i], g[j])\n if g[j] > g[i]:\n j -= 1\n else:\n i += 1\n turn += 1\n return total", "def take_one(golds):\n if len(golds) > 1 and golds[0] >= golds[-1]:\n return golds.pop(0)\n else:\n return golds.pop() if golds else 0\n \n \ndef distribution_of(golds):\n golds = golds[:]\n a = b = 0\n while golds:\n a += take_one(golds)\n b += take_one(golds)\n return [a, b]", "def distribution_of(golds):\n golds = golds[:]\n take = lambda: golds.pop(0 if golds[0] >= golds[-1] else -1) if golds else 0\n a = b = 0\n while golds:\n a += take()\n b += take()\n return [a, b]", "def distribution_of(piles):\n i, gold = False, [0, 0]\n while piles:\n gold[i], piles = (gold[i]+piles[-1], piles[:-1]) if piles[-1] > piles[0] else (gold[i]+piles[0], piles[1:])\n i = not i\n return gold", "distribution_of=lambda g,r=[0,0],c=0: r if not len(g) else distribution_of(*([g[:-1],[r[0],r[1]+g[-1]],0] if g[-1]>g[0] else [g[1:],[r[0],r[1]+g[0]],0])) if c else distribution_of(*([g[:-1],[r[0]+g[-1],r[1]],1] if g[-1]>g[0] else [g[1:],[r[0]+g[0],r[1]],1]))", "def distribution_of(gold):\n # Make gold a copy of gold because otherwise it breaks the random checks\n gold, beggargold = gold.copy(), [0, 0]\n for pile in range(len(gold)):\n if pile % 2 == 0:\n beggargold[0] += (gold.pop(0) if gold[0] >= gold[-1] else gold.pop())\n else:\n beggargold[1] += (gold.pop(0) if gold[0] >= gold[-1] else gold.pop())\n return beggargold\n", "def distribution_of(golds):\n ab = [0, 0]\n g = golds[:]\n for i in range(len(g)):\n ab[i%2] += max(g[0], g[-1])\n g.pop(-1) if g[-1] > g[0] else g.pop(0)\n return ab", "def distribution_of(golds):\n gg=golds[:]\n out=[0,0]\n pos=0\n for _ in range(len(gg)):\n if gg[0]>=gg[-1]:\n out[pos]+=(gg.pop(0)) \n else:\n out[pos]+=(gg.pop(-1))\n pos=not pos\n return out\n", "def distribution_of(golds):\n g = golds[:]\n i, beggars = 0,[0,0]\n while g:\n beggars[i%2] += g.pop(-(g[0] < g[-1]))\n i+=1\n return beggars", "def distribution_of(golds):\n g = golds[:]\n total = [0,0]\n turn = 0\n while len(g) > 0:\n if g[0] >= g[-1]:\n value = g.pop(0)\n else:\n value = g.pop(-1) \n total[turn % 2] += value \n turn += 1\n return total", "def distribution_of(golds):\n golds_list = golds[:]\n a = []\n b = []\n turn = 1\n while len(golds_list) > 0:\n if golds_list[0] >= golds_list[-1]:\n value = golds_list.pop(0)\n else:\n value = golds_list.pop(-1)\n if turn % 2 == 1:\n a.append(value)\n else:\n b.append(value)\n turn += 1\n return [sum(a), sum(b)]", "def distribution_of(golds):\n gold_list = golds[:] \n isA = True\n amount = [0 ,0]\n \n while len(gold_list) != 0:\n if (gold_list[0] > gold_list[-1]) or (gold_list[0] == gold_list[-1]):\n if isA:\n amount[0] += gold_list[0]\n else:\n amount[1] += gold_list[0]\n gold_list.pop(0)\n else:\n if isA:\n amount[0] += gold_list[-1]\n else:\n amount[1] += gold_list[-1]\n gold_list.pop(-1)\n isA = not isA\n\n return amount", "def distribution_of(golds):\n g = golds[::]\n R = [0,0]\n toggle = 0\n currentVar = 'A'\n while g:\n if g[-1] > g[0]:\n R[toggle] += g.pop(-1)\n else:\n R[toggle] += g.pop(0)\n toggle = 1 - toggle\n\n return R", "def distribution_of(golds):\n a,b,i=0,0,0\n golds_c=golds[:]\n while golds_c:\n m=golds_c.pop(0) if golds_c[0]>=golds_c[-1] else golds_c.pop()\n if i%2:b+=m\n else:a+=m\n i+=1\n return [a,b]", "def distribution_of(golds):\n p,g,player=0,golds[:],[0,0]\n while g: player[p],p = player[p]+g.pop(-1 if g[0]<g[-1] else 0),1-p\n return player", "def distribution_of(g):\n golds = g.copy()\n print(golds)\n a=0\n b=0\n while golds:\n if golds[0] >= golds[-1]:\n a += golds.pop(0)\n else:\n a += golds.pop(-1)\n if not golds:\n break\n if golds[0] >= golds[-1]:\n b += golds.pop(0)\n else:\n b += golds.pop(-1)\n return [a, b]", "def distribution_of(golds):\n out, n, g = [0,0], 0, golds[::] #never directly edit supplied lists\n for i in range(len(golds)):\n if g[n] < g[-1]: x = g.pop()\n else: x, n = g[n], n+1\n out[i&1] += x\n return out"] | {"fn_name": "distribution_of", "inputs": [[[4, 7, 2, 9, 5, 2]], [[10, 1000, 2, 1]]], "outputs": [[[11, 18]], [[12, 1001]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 5,628 |
def distribution_of(golds):
|
7886628ca2cd4e9e24a22a25637db480 | UNKNOWN | ## Task:
You have to write a function **pattern** which returns the following Pattern(See Examples) upto (2n-1) rows, where n is parameter.
### Rules/Note:
* If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string.
* All the lines in the pattern have same length i.e equal to the number of characters in the longest line.
* Range of n is (-∞,100]
## Examples:
pattern(5):
1
121
12321
1234321
123454321
1234321
12321
121
1
pattern(10):
1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321
1234567890987654321
12345678987654321
123456787654321
1234567654321
12345654321
123454321
1234321
12321
121
1
pattern(15):
1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321
1234567890987654321
123456789010987654321
12345678901210987654321
1234567890123210987654321
123456789012343210987654321
12345678901234543210987654321
123456789012343210987654321
1234567890123210987654321
12345678901210987654321
123456789010987654321
1234567890987654321
12345678987654321
123456787654321
1234567654321
12345654321
123454321
1234321
12321
121
1
pattern(20):
1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321
1234567890987654321
123456789010987654321
12345678901210987654321
1234567890123210987654321
123456789012343210987654321
12345678901234543210987654321
1234567890123456543210987654321
123456789012345676543210987654321
12345678901234567876543210987654321
1234567890123456789876543210987654321
123456789012345678909876543210987654321
1234567890123456789876543210987654321
12345678901234567876543210987654321
123456789012345676543210987654321
1234567890123456543210987654321
12345678901234543210987654321
123456789012343210987654321
1234567890123210987654321
12345678901210987654321
123456789010987654321
1234567890987654321
12345678987654321
123456787654321
1234567654321
12345654321
123454321
1234321
12321
121
1 | ["def pattern(n):\n lines = []\n for i in range(1, n + 1):\n line = ' ' * (n - i)\n line += ''.join(str(j % 10) for j in range(1, i + 1))\n line += line[::-1][1:]\n lines.append(line)\n return '\\n'.join(lines + lines[::-1][1:])\n", "def pattern(n):\n lines = []\n for c in range(1,n+1):\n s = (' ' * (n-c)) + ''.join([str(s)[-1] for s in range(1,c+1)])\n lines += [s + s[::-1][1:]]\n lines += lines[::-1][1:]\n return '\\n'.join(str(x) for x in lines)\n", "def pattern(n):\n result = []\n for i in range(1, n + 1):\n nums = \"\".join([str(j % 10) for j in range(1, i + 1)])\n result.append(\" \" * (n - i) + nums + nums[::-1][1:] + \" \" * (n - i))\n return \"\\n\".join(result + result[::-1][1:])", "def pattern(n):\n mid = ''\n nums = '1234567890'*n\n for i in range(n):\n mid += nums[i]\n mid += mid[-2::-1]\n\n d = []\n for i in range(n-1):\n d.append(''.join(mid.rsplit(mid[i:-i-1], 1)).center(2*n-1))\n d.append(mid)\n for j in d[-2::-1]:\n d.append(j)\n \n return '\\n'.join(d)", "def pattern(n):\n if n < 1: return \"\"\n \n s = \"1234567890\" * (n//10 + 1)\n width = 2 * n - 1\n \n triangle = [(s[:i+1] + s[:i][::-1]).center(width) for i in range(n)]\n \n return \"\\n\".join(triangle + triangle[:-1][::-1])", "from itertools import chain, cycle, islice\n\ndef pattern(n):\n w = 2*n - 1\n def f():\n for i in chain(range(1, n+1), range(n-1, 0, -1)):\n xs = ''.join(islice(cycle('1234567890'), i))\n yield (xs + xs[-2::-1]).center(w)\n return '\\n'.join(f())", "def pattern(n):\n l, s = 2*n-1, ''.join(str(x%10) for x in range(1,n+1))\n lst = [ (s[:-i or n]+s[:-i-1][::-1]).center(l) for i in range(n) ]\n return '\\n'.join(lst[1:][::-1]+lst)", "mkP = lambda y: str(y % 10)\nrow = lambda n, x: \" \" * (n - x - 1) + \"\".join(map(mkP, range(1, x + 1))) + \"\".join(map(mkP, range(x + 1, 0, -1))) + \" \" * (n - x - 1)\ndef pattern(n):\n pyramid = [row(n, x) for x in range(n - 1)]\n return '\\n'.join(pyramid + [row(n, n - 1)] + list(reversed(pyramid)))"] | {"fn_name": "pattern", "inputs": [[1], [3], [7], [0], [-25]], "outputs": [["1"], [" 1 \n 121 \n12321\n 121 \n 1 "], [" 1 \n 121 \n 12321 \n 1234321 \n 123454321 \n 12345654321 \n1234567654321\n 12345654321 \n 123454321 \n 1234321 \n 12321 \n 121 \n 1 "], [""], [""]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,170 |
def pattern(n):
|
2da31240b92087c9cdc2ce5c351ee809 | UNKNOWN | Write a function ```x(n)``` that takes in a number ```n``` and returns an ```nxn``` array with an ```X``` in the middle. The ```X``` will be represented by ```1's``` and the rest will be ```0's```.
E.g.
```python
x(5) == [[1, 0, 0, 0, 1],
[0, 1, 0, 1, 0],
[0, 0, 1, 0, 0],
[0, 1, 0, 1, 0],
[1, 0, 0, 0, 1]];
x(6) == [[1, 0, 0, 0, 0, 1],
[0, 1, 0, 0, 1, 0],
[0, 0, 1, 1, 0, 0],
[0, 0, 1, 1, 0, 0],
[0, 1, 0, 0, 1, 0],
[1, 0, 0, 0, 0, 1]];
``` | ["def x(n): \n d = [[0] * n for i in range (n)]\n for i in range(n):\n d[i][i] = 1\n d[i][-i-1] = 1\n return d", "def fill(i, j, n):\n if i == j or i + j == n - 1:\n return 1\n else:\n return 0\n\ndef x(n):\n return [[fill(i, j, n) for j in range(n)] for i in range(n)]", "x = lambda n: [[int(i == j or i == n - j - 1) for i in range(n)] for j in range(n)]", "x = lambda n: [[1 if y == x or y == n - x - 1 else 0 for y in range(n)] for x in range(n)]", "def x(n):\n zarr = [[0 for _ in range(n)] for _ in range(n)]\n for i in range(n):\n zarr[i][i] = 1\n zarr[i][-(i+1)] = 1\n return zarr", "def x(n):\n result = [[0]*n for _ in range(n)]\n for i in range(n):\n result[i][i] = result[i][-i-1] = 1\n return result", "x = lambda n: [[int(c==r or c==n-r-1) for c in range(n)] for r in range(n)]\n", "def x(n):\n return [\n [int(i == j or i+j == n-1) for j in range(n)]\n for i in range(n)\n ]", "def x(n):\n return [[1 if (i == j or (i + j + 1) == n) else 0 for i in range(n)] for j in range(n)]"] | {"fn_name": "x", "inputs": [[1], [2], [3], [4], [5], [6]], "outputs": [[[[1]]], [[[1, 1], [1, 1]]], [[[1, 0, 1], [0, 1, 0], [1, 0, 1]]], [[[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]]], [[[1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0], [0, 1, 0, 1, 0], [1, 0, 0, 0, 1]]], [[[1, 0, 0, 0, 0, 1], [0, 1, 0, 0, 1, 0], [0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0], [0, 1, 0, 0, 1, 0], [1, 0, 0, 0, 0, 1]]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,103 |
def x(n):
|
bd2a16f6a8aba2b6e7ce2f44fcaa3c4d | UNKNOWN | You are given an array of integers. Your task is to sort odd numbers within the array in ascending order, and even numbers in descending order.
Note that zero is an even number. If you have an empty array, you need to return it.
For example:
```
[5, 3, 2, 8, 1, 4] --> [1, 3, 8, 4, 5, 2]
odd numbers ascending: [1, 3, 5 ]
even numbers descending: [ 8, 4, 2]
``` | ["def sort_array(xs):\n es = sorted(x for x in xs if x % 2 == 0)\n os = sorted((x for x in xs if x % 2 != 0), reverse=True)\n return [(es if x % 2 == 0 else os).pop() for x in xs]", "def sort_array(a):\n odds = []; evens = []; newArray = []\n for i in a:\n if i % 2 == 0:\n evens.append(i)\n else:\n odds.append(i)\n evens.sort(); evens.reverse()\n odds.sort()\n for i in range(len(a)):\n if a[i] % 2 == 0:\n newArray.append(evens[0])\n evens.pop(0)\n else:\n newArray.append(odds[0])\n odds.pop(0)\n return newArray", "def sort_array(a):\n odds = iter(sorted(n for n in a if n % 2))\n evens = iter(sorted((n for n in a if not n % 2), reverse=True))\n return [next(odds) if n % 2 else next(evens) for n in a]\n", "def sort_array(a):\n sorted_odd, sorted_even = sorted(value for value in a if value & 1), sorted([value for value in a if not value & 1], reverse=True)\n return [sorted_odd.pop(0) if value & 1 else sorted_even.pop(0) for value in a]", "def sort_array(a):\n e, o = sorted(x for x in a if x % 2 ^ 1), sorted((x for x in a if x % 2), reverse=True)\n return [(o if x % 2 else e).pop() for x in a]", "def sort_array(a):\n # Create two sorted arrays one containing even and on odd numbers. Each array \n # is sorted opposite of the desired results as we will pop items off the array.\n sorted_odd = sorted([x for x in a if x % 2 == 1], reverse=True)\n sorted_even = sorted([x for x in a if x % 2 == 0])\n \n # Build the final output. Place the sorted even numbers where even numbers were\n # in the original list and sorted odd numbers where odd numbers were in the \n # original list.\n out = []\n for x in a:\n if x % 2 == 0:\n out.append(sorted_even.pop())\n else:\n out.append(sorted_odd.pop())\n \n return out\n", "def sort_array(lst):\n s = sorted(lst)\n even = (n for n in s[::-1] if n & 1 == 0)\n odd = (n for n in s if n & 1)\n return [next(odd if n & 1 else even) for n in lst]", "def sort_array(lst):\n even, odd = [], []\n for n in sorted(lst):\n (odd if n & 1 else even).append(n)\n even, odd = iter(even[::-1]), iter(odd)\n return [next(odd if n & 1 else even) for n in lst]", "def sort_array(a):\n lenList = len(a)\n\n if lenList ==0:\n return []\n\n evenNums, oddNums = [], []\n evenNumLoc, oddNumLoc = [],[]\n\n #Walk through the given list of numbers, and store even numbers (and \n #their index loc); same for odds \n for i in range(0, lenList, 1):\n if a[i]%2==0:\n evenNums.append(a[i]) #save even number\n evenNumLoc.append(i) #save even number index location\n else:\n oddNums.append(a[i]) #save odd number\n oddNumLoc.append(i) #save odd number location\n\n evenNums.sort(reverse = True) #decending order for evens\n oddNums.sort() #ascending order for odds\n\n #pre allocate the list so we can store via direct access\n sortedList = [0 for _ in range(lenList)]\n totalNumEvens = len(evenNums)\n totalNumOdds = len(oddNums)\n\n #Store the sorted even numbers at the indicies where they were located in the original list\n for i in range(0, totalNumEvens, 1):\n sortedList[evenNumLoc[i]] = evenNums[i]\n\n #Store the sorted odd numbers at the indicies where they were located in the original list\n for i in range(0, totalNumOdds, 1):\n sortedList[oddNumLoc[i]] = oddNums[i]\n\n return sortedList\n\n#end function\n", "from collections import deque\n\ndef sort_array(a):\n asc = deque(sorted(x for x in a if x%2))\n desc = sorted(x for x in a if not x%2)\n return [asc.popleft() if x%2 else desc.pop() for x in a]"] | {"fn_name": "sort_array", "inputs": [[[5, 3, 2, 8, 1, 4, 11]], [[2, 22, 37, 11, 4, 1, 5, 0]], [[1, 111, 11, 11, 2, 1, 5, 0]], [[]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 2, 3, 4, 9, 8, 7, 6, 5]]], "outputs": [[[1, 3, 8, 4, 5, 2, 11]], [[22, 4, 1, 5, 2, 11, 37, 0]], [[1, 1, 5, 11, 2, 11, 111, 0]], [[]], [[1, 8, 3, 6, 5, 4, 7, 2, 9, 0]], [[8, 1, 6, 3, 4, 5, 2, 7, 0, 9]], [[8, 1, 6, 3, 4, 5, 2, 7, 0, 9]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,873 |
def sort_array(a):
|
9d18609bf3f93300166ff5fb893cc55d | UNKNOWN | In this kata, we will check is an array is (hyper)rectangular.
A rectangular array is an N-dimensional array with fixed sized within one dimension. Its sizes can be repsented like A1xA2xA3...xAN. That means a N-dimensional array has N sizes. The 'As' are the hyperrectangular properties of an array.
You should implement a functions that returns a N-tuple with the arrays hyperrectangular properties or None if the array is not hyperrectangular.
```
hyperrectangularity_properties(arr)
```
## Note
An empty array IS rectagular and has one dimension of length 0
```
hyperrectangularity_properties([]) == (0,)
```
## Example
```
1D array
hyperrectangularity_properties([1,2,3]) == (3,)
2D arrays
hyperrectangularity_properties(
[[0,1,2],
[3,4,5],
[6,7,8]] ) == (3,3)
hyperrectangularity_properties(
[[0,1,2],
[3,4,5]] ) == (2,3)
hyperrectangularity_properties(
[[0,1,2],
[3,4] ] ) == None
3D arrays
hyperrectangularity_properties(
[
[ [0], [2] ],
[ [0], [2] ],
[ [0], [2] ]
] ) == (3,2,1)
hyperrectangularity_properties(
[
[[0],[2]],
[[0],[2,2]],
[[0],[2]]
] ) == None
hyperrectangularity_properties(
[[ [], [], [] ]]
) == (1,3,0)
```
### Heterogeneous Arrays can appear too
```
hyperrectangularity_properties(
[[0,1,2],
3,
[[4],5,6]] ) == None
hyperrectangularity_properties(
[1,
[1,2],
[[3],[4,[5]],[6]]
] ) == None
hyperrectangularity_properties(
[[ [], [] ], [] ]
) == None
hyperrectangularity_properties(
[ 1, [], [2, [3]] ]
) == None
```
The first property shows the length of the outer layer. The second of the layer one step deeper and so on. The function should handle higher dimensions too.
## Input
##### N-dimensional array of integers
## Expected Ouput
##### An N-tuple with the hyperrectangularity properties | ["from itertools import chain\n\ndef hyperrectangularity_properties(arr):\n hr, arr = [], [arr]\n while 1:\n check = sum(isinstance(v, int) for v in arr) # Check homogeneity\n if check or not arr: # some int are present or empty array (edge case)\n if check == len(arr): return tuple(hr) # only int: found the bottom of the tree\n break\n \n l = set(map(len,arr))\n if len(l) > 1: break # invalid if different length found\n hr.append(l.pop())\n arr = list(chain.from_iterable(arr)) # get the \"lower level\"", "import numpy as np\n\ndef hyperrectangularity_properties(arr):\n try:\n return np.shape(arr) if np.array(arr).dtype.char != \"O\" else None\n except ValueError:\n return None\n", "def hp(arr):\n if not isinstance(arr, list):\n return ()\n elif not arr:\n return (0,)\n xs = list(map(hp, arr))\n if None not in xs and all(x == xs[0] for x in xs):\n return (len(arr),) + xs[0]\nhyperrectangularity_properties = hp", "hyperrectangularity_properties=h=lambda a:()if[]!=a*0else(lambda f,*s:None if f==None or s else(len(a),)+f)(*set(map(h,a))or{()})", "import numpy as np\ndef hyperrectangularity_properties(arr):\n try:\n arr = np.array(arr)\n except ValueError:\n return None\n return arr.shape if arr.dtype.char != 'O' else None", "def hyperrectangularity_properties(arr, d=[]):\n def get(arr,d):\n d.append(len(arr))\n if all(isinstance(i, int) for i in arr) : return tuple(d)\n else:\n le = len(arr[0]) if isinstance(arr[0], list) else 0\n if not all(isinstance(i, list) and len(i) == le for i in arr) : return \n \n if get(arr[0],d) : return tuple(d)\n return get(arr,[])", "def hyperrectangularity_properties(arr):\n v = len(arr)\n k = (v,)\n if not v: return k\n if len( set(map(type, arr)) )!= 1: return None\n if isinstance(arr[0], int): return k\n rest = list( set(map(hyperrectangularity_properties, arr)) )\n if len(rest) == 1 and rest[0] != None:\n return k + rest[0]\n return None\n", "import numpy as np\n\ndef hyperrectangularity_properties(arr):\n try:\n return None if np.array(arr).dtype == np.dtype(\"O\") else np.shape(arr)\n except (ValueError):\n return None\n", "def hyperrectangularity_properties(r):\n z = [len(r)]\n while len(r):\n if len(set(type(v) for v in r)) == 1:\n if type(r[0]) == list:\n if len(set(len(rr) for rr in r)) != 1: return None\n z.append(len(r[0]))\n r = [v for rr in r for v in rr]\n else: break\n else: return None\n return tuple(z)", "# This is a shit code, just little correction after little correction until I'm not even sure how it works\n# There are probably edges cases to make it not work but hey, it passes the tests\ndef rec(arr):\n type = [isinstance(x, int) for x in arr]\n if len(set(type)) > 1: return None\n if not type or type[0]: return []\n size = list(map(len, arr))\n if len(set(size)) != 1: return None\n res = [rec(x) for x in arr]\n if None in res: return None\n if len(set(map(tuple, res))) != 1: return None\n return [size[0]] + res[0]\n\ndef hyperrectangularity_properties(arr):\n res = rec(arr)\n if res is None: return None\n return tuple([len(arr)] + res)"] | {"fn_name": "hyperrectangularity_properties", "inputs": [[[]]], "outputs": [[[0]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,567 |
def hyperrectangularity_properties(arr):
|
a6e358c8e1b17ec8fa2d2ee6b98710fa | UNKNOWN | # Challenge :
Write a function that takes a single argument `n` that is a string representation of a simple mathematical expression and evaluates it as a floating point value.
# Commands :
- positive or negative decimal numbers
- `+, -, *, /, ( / ).`
---
Expressions use [infix notation](https://en.wikipedia.org/wiki/Infix_notation).
# Evaluation :
Operators should be evaluated in the order they appear and not as in `BODMAS`, though brackets __should__ be correctly observed.
The function should return the correct result for any possible expression of this form.
# Note :
- All given input will be valid.
- It will consist entirely of numbers or one of the operators.
- Parentheses will alway be matched.
- Use of `eval` or its equivalent is forbidden
- use of `exec` is forbidden (Python)
- Use of `Function` or any of their (Function, eval) equivalent is also forbidden.
- Using `require` is also forbidden. (`import` for python)
- Using more than 7 (8 for python) lines is also forbidden.
- Using more than 260 (JS) / 240 (python) characters is also forbidden.
- Having more than 100 chars per line is forbidden.
- Having more than 6 semi-colons is forbidden
and that is about it.
---
# Examples :
e("2*3*4*5+99") ---> 219
e("2*3*4*5+99*321-12312312") ---> -12242013
e("1-2*2/2*2-1*7+3") ---> -18
--- | ["def e(s):return f([*s,'+'])\ndef f(s,r=0,o=0,x='',c=0):\n while s and')'!=c:\n c=s.pop(0);i='+-*/)('.find(c)\n if c=='-'>x or i<0:x+=c\n elif c=='(':x=str(f(s))\n elif i>-1:a=float(x);r=[r+a,r-a,r*a,r/a][o];o=i;x=''\n return r", "def e(s,t=[],x=0,o='+',m=')*+-/'):\n if s:t+=list(s.replace(' ','')+')')\n while o!=')':\n c=t.pop(0)\n if c=='(':c=e(0)\n while t[0] not in m:c+=t.pop(0)\n c=float(c);x={'*':x*c,'+':x+c,'-':x-c,'/':x/c}[o];o=t.pop(0)\n return x", "def e(p,u=[]):\n if p:u+=list(\"0\"*(p[0]==\"-\")+p+\")\")\n a,o,x=0,\"+\",u.pop\n while o!=\")\":\n y=x(0);c=e(0) if y==\"(\"else y\n while u[0]not in\")+-*/\":c+=x(0)\n b=float(c);a={\"+\":a+b,\"-\":a-b,\"*\":a*b,\"/\":a/(b or 1)}[o];o=x(0)\n return a", "def e(i):\n c=i.find(')')\n if c>0:o=i[:c].rfind('(');return e(i[:o]+\"{:.9f}\".format(e(i[o+1:c]))+i[c+1:])\n v='';r=0;p='+'\n for s in i+p:\n if s in \"+-*/\" and v:w=float(v);r={'+':r+w,\"-\":r-w,\"*\":r*w,\"/\":r/w}[p];v='';p=s\n else:v+=s\n return r", "def e(s,l=0,n=0,f='+'):\n if s:l=[c for c in s+')'if' '!=c]\n while f!=')':\n p=l.pop;m=p(0)\n if m=='(':m=e(0,l)\n while l[0]not in'+-*/)':m+=p(0)\n m=float(m);n={'+':n+m,'-':n-m,'*':n*m,'/':n/(m or 1)}[f];f=p(0)\n return n"] | {"fn_name": "e", "inputs": [["2*3*4*5+99"]], "outputs": [[219]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,233 |
def e(s):
|
6880094ea8867cbe5ed85594a5b5af1e | UNKNOWN | DropCaps means that the first letter of the starting word of the paragraph should be in caps and the remaining lowercase, just like you see in the newspaper.
But for a change, let's do that for each and every word of the given String. Your task is to capitalize every word that has length greater than 2, leaving smaller words as they are.
*should work also on Leading and Trailing Spaces and caps.
```python
drop_cap('apple') => "Apple"
drop_cap('apple of banana'); => "Apple of Banana"
drop_cap('one space'); => "One Space"
drop_cap(' space WALK '); => " Space Walk "
```
**Note:** you will be provided atleast one word and should take string as input and return string as output. | ["def drop_cap(str_):\n return ' '.join( w.capitalize() if len(w) > 2 else w for w in str_.split(' ') )\n", "import re\n\ndef drop_cap(s):\n return re.sub(r'\\w{3,}', lambda m: m[0].title(), s)", "def drop_cap(str_):\n return \" \".join([i[0].upper() + i[1::].lower() if len(i) > 2 else i for i in str_.split(\" \")])", "def drop_cap(stg):\n return \" \".join(w.capitalize() if len(w) > 2 else w for w in stg.split(\" \"))", "def drop_cap(s):\n return ' '.join(x.title() if len(x) > 2 else x for x in s.split(' '))", "import re\n\n\ndef r(m):\n s = m.group()\n if len(s) > 2:\n s = s.capitalize()\n return s\n\ndef drop_cap(s):\n return re.sub('\\w+', r, s)", "def drop_cap(str_):\n return \" \".join(s.capitalize() if len(s) > 2 else s for s in str_.split(\" \"))", "def drop_cap(str_):\n return \" \".join(map(lambda x: x.title() if len(x) > 2 else x, str_.split(\" \")))", "import re\n\ndef drop_cap(s):\n return re.sub(r'\\S{3,}', lambda m: m.group(0).title(), s)"] | {"fn_name": "drop_cap", "inputs": [["Apple Banana"], ["Apple"], [""], ["of"], ["Revelation of the contents outraged American public opinion, and helped generate"], ["more than one space between words"], [" leading spaces"], ["trailing spaces "], ["ALL CAPS CRAZINESS"], ["rAnDoM CaPs CrAzInEsS"]], "outputs": [["Apple Banana"], ["Apple"], [""], ["of"], ["Revelation of The Contents Outraged American Public Opinion, And Helped Generate"], ["More Than One Space Between Words"], [" Leading Spaces"], ["Trailing Spaces "], ["All Caps Craziness"], ["Random Caps Craziness"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,012 |
def drop_cap(str_):
|
e3e97f03f19f5646466fbe77469b7f2a | UNKNOWN | Given a string `s` of uppercase letters, your task is to determine how many strings `t` (also uppercase) with length equal to that of `s` satisfy the followng conditions:
* `t` is lexicographical larger than `s`, and
* when you write both `s` and `t` in reverse order, `t` is still lexicographical larger than `s`.
```Haskell
For example:
solve('XYZ') = 5. They are: YYZ, ZYZ, XZZ, YZZ, ZZZ
```
String lengths are less than `5000`. Return you answer `modulo 10^9+7 (= 1000000007)`.
More examples in test cases. Good luck! | ["def solve(s):\n r, l = 0, 0\n for c in s:\n m = ord('Z') - ord(c)\n r, l = r + m + l * m, m + l * 26\n return r % 1000000007", "def solve(s, z=ord('Z')):\n a = r = 0\n for i in (z - ord(c) for c in s):\n r += (a + 1) * i\n a = a * 26 + i\n r %= 1000000007\n a %= 1000000007\n return r", "def solve(s):\n M = 10 ** 9 + 7;\n z = ord('Z')\n base = z - ord('A') + 1\n \n left, total = 0, 0 \n # left-upside and total upside for the already traversed part of the list\n for c_num in [(z - ord(c)) for c in s]:\n l, t = left, total\n left = (l * base + c_num) % M\n total = ((l + 1) * c_num + t) % M\n return total", "def solve(s):\n M = 10 ** 9 + 7;\n base = ord('Z') - ord('A') + 1\n num_cs = map(lambda c: 90 - ord(c), [c for c in s])\n acc = (0, 0) # ( left-upside, total upside ) for the already traversed part of the list\n for num_c in num_cs:\n (ups_left, ups_tot) = acc\n ups_left_ = (ups_left * base + num_c) % M\n ups_tot_ = ((ups_left + 1) * num_c + ups_tot) % M\n acc = (ups_left_, ups_tot_)\n return acc[1]", "M=10**9+7\nfrom functools import reduce\n\ndef solve(s):\n return reduce(lambda p,n: ((p[0]*26+(90-n))%M,((p[0]+1)*(90-n)+p[1])%M),map(ord,s),(0,0))[1]", "def solve(s):\n a, pa = 0, 0\n for c in s:\n diff = ord('Z')-ord(c)\n a = a + diff + pa*diff\n pa = diff + pa*26\n a, pa = a%1000000007, pa%1000000007\n return a\n", "def solve(s):\n sum_value, tmp = 0, 0\n for value in map(lambda x: 90 - ord(x), s):\n sum_value += value*(1+tmp)\n tmp = (26*tmp + value) % 1000000007\n return sum_value % 1000000007", "def solve(s):\n greater_letters = list(map(lambda x: 90 - ord(x), s))\n sum_value, tmp = 0, 0\n for value in greater_letters:\n sum_value += value*(1+tmp)\n tmp = (26*tmp + value) % 1000000007\n return sum_value % 1000000007", "from functools import lru_cache\nfrom itertools import combinations\n\n\n@lru_cache(5000)\ndef get_26_power(i):\n return 26**i\n\n\ndef solve(s):\n greater_letters = list(map(lambda x: 90 - ord(x), s))\n tmp = 1 + sum(greater*get_26_power(i) for i, greater in enumerate(greater_letters[1:]))\n sum_value = 0\n for value in greater_letters:\n sum_value += tmp*value\n tmp = (tmp+25)//26\n return sum_value % 1000000007", "def solve(s):\n val = [90 - ord(c) for c in reversed(s)]\n tmp, res = [0], val[0]\n for v1,v2 in zip(val, val[1:]):\n tmp.append(tmp[-1]*26 + v1)\n res += v2 * (tmp[-1]+1)\n return res % (10**9+7)", "MOD = pow(10, 9) + 7\n\ndef solve(s):\n n = len(s)\n a = [25 - (ord(x) - 65) for x in s]\n r, s = 0, 0\n for i in range(n):\n r = (r + a[i] + s * a[i]) % MOD\n s = (a[i] + s * 26) % MOD\n return r", "def solve(s):\n n = len(s); dp, mod, sum = [0]*n, 1000000007, 0\n for i in range(n-2,-1,-1):\n dp[i] = (((dp[i + 1] * 26) % mod) + (ord('Z') - ord(s[i + 1])) % mod) % mod\n for i in range(0,n):\n sum += ((dp[i] + 1) * (ord('Z') - ord(s[i]))) % mod\n sum %= mod\n return sum"] | {"fn_name": "solve", "inputs": [["XYZ"], ["ABC"], ["ABCD"], ["ZAZ"], ["XYZA"]], "outputs": [[5], [16174], [402230], [25], [34480]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,216 |
def solve(s):
|
b168f71f4781d8d9fde6989cb824ea65 | UNKNOWN | **This Kata is intended as a small challenge for my students**
Create a function, called ``removeVowels`` (or ``remove_vowels``), that takes a string argument and returns that same string with all vowels removed (vowels are "a", "e", "i", "o", "u"). | ["REMOVE_VOWS = str.maketrans('','','aeiou')\n\ndef remove_vowels(s):\n return s.translate(REMOVE_VOWS)", "def remove_vowels(strng):\n return ''.join([i for i in strng if i not in 'aeiou'])", "def remove_vowels(stg):\n return \"\".join(c for c in stg if c not in \"aeiou\")", "def remove_vowels(s):\n return ''.join(i for i in s if i not in'aeiou')", "def remove_vowels(strng):\n gl = 'aoeiu'\n return ''.join([c for c in strng if c not in gl])", "def remove_vowels(strng):\n str = ['a','i','u','e','o']\n for i in str:\n strng = strng.replace(i, \"\")\n return strng", "import re\n\ndef remove_vowels(strng):\n return re.sub('[aeiou]', '', strng, flags=re.I)", "def remove_vowels(s):\n d=list(s)\n i=-1\n for c in s:\n i+=1\n if c==\"a\" or c==\"e\" or c==\"i\" or c==\"o\" or c==\"u\":\n d.remove(c)\n print(d)\n return \"\".join(d)", "remove_vowels = lambda s: __import__(\"re\").sub(r\"[aeiou]\", \"\", s)"] | {"fn_name": "remove_vowels", "inputs": [["drake"], ["scholarstem"], ["codewars"], ["high fives!"], [""], ["i"], ["b"]], "outputs": [["drk"], ["schlrstm"], ["cdwrs"], ["hgh fvs!"], [""], [""], ["b"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 987 |
def remove_vowels(s):
|
af6e8b85df7c38530435afe6ab0e5c2c | UNKNOWN | Complete the function so that it takes an array of keys and a default value and returns a hash (Ruby) / dictionary (Python) with all keys set to the default value.
## Example
```python
["draft", "completed"], 0 # should return {"draft": 0, "completed: 0}
``` | ["def populate_dict(keys, default):\n return {key: default for key in keys}", "populate_dict = dict.fromkeys", "def populate_dict(keys, default):\n return dict.fromkeys(keys, default)", "def populate_dict(keys, default):\n return {k:default for k in keys}", "from itertools import repeat\ndef populate_dict(keys, default):\n return {k: v for k, v in zip(keys, repeat(default))}", "from collections import defaultdict\ndef populate_dict(keys, default):\n return defaultdict.fromkeys(keys, default)", "from itertools import zip_longest\n\npopulate_dict = lambda keys, default: dict(zip_longest(keys, [default], fillvalue=default))", "def populate_dict(keys, default):\n return dict(zip(keys, [default] * len(keys)))", "def populate_dict(keys, default):\n o = {}\n for n in keys:\n o[n] = default\n return o", "def populate_dict(ks, v):\n return {k: v for k in ks}\n"] | {"fn_name": "populate_dict", "inputs": [[["draft", "completed"], 0], [["a", "b", "c"], null], [[1, 2, 3, 4], "OK"]], "outputs": [[{"completed": 0, "draft": 0}], [{"c": null, "b": null, "a": null}], [{"1": "OK", "2": "OK", "3": "OK", "4": "OK"}]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 902 |
def populate_dict(keys, default):
|
4e3ba7c0a47fbf9633be60d1cb5fc493 | UNKNOWN | If we write out the digits of "60" as English words we get "sixzero"; the number of letters in "sixzero" is seven. The number of letters in "seven" is five. The number of letters in "five" is four. The number of letters in "four" is four: we have reached a stable equilibrium.
Note: for integers larger than 9, write out the names of each digit in a single word (instead of the proper name of the number in English). For example, write 12 as "onetwo" (instead of twelve), and 999 as "nineninenine" (instead of nine hundred and ninety-nine).
For any integer between 0 and 999, return an array showing the path from that integer to a stable equilibrium: | ["digits = 'zero one two three four five six seven eight nine'.split()\n\ndef f(n):\n return ''.join(map(digits.__getitem__, map(int, str(n))))\n\ndef numbers_of_letters(n):\n result = [f(n)]\n print(n, result)\n while result[-1] != 'four':\n result.append(f(len(result[-1])))\n return result", "words = \"zero one two three four five six seven eight nine\".split()\nwordify = lambda n: \"\".join(words[int(d)] for d in str(n))\n\n\ndef numbers_of_letters(n):\n result = [wordify(n)]\n while result[-1] != \"four\":\n result.append(wordify(len(result[-1])))\n return result", "s = \"zero one two three four five six seven eight nine\"\nls = s.split(\" \")\ndef numbers_of_letters(n):\n t = [stringa(n)]\n while n != len(stringa(n)):\n n = len(stringa(n))\n t.append(stringa(n))\n return t \n\ndef stringa(n):\n return \"\".join([ls[int(i)] for i in str(n)])", "t = {'1': 'one', '2': 'two', '3': 'three', '4': 'four', '5': 'five', '6': 'six', '7': 'seven', '8': 'eight', '9': 'nine', '0': 'zero'}\n\ndef numbers_of_letters(n):\n x = [''.join([t[i] for i in str(n)])]\n while int(n) != len(x[-1]):\n n = len(x[-1])\n x.append(''.join([t[i] for i in str(n)]))\n return x", "NUM = [\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\"]\n\ndef numbers_of_letters(n):\n s = ''.join(NUM[i] for i in map(int, str(n)))\n return [s] + (numbers_of_letters(len(s)) if len(s) != n else [])", "numbers_of_letters=f=lambda n,N=[\"zero\",\"one\",\"two\",\"three\",\"four\",\"five\",\"six\",\"seven\",\"eight\",\"nine\"]:(lambda s:[s]+f(len(s))if len(s)!=n else[s])(''.join(N[i]for i in map(int,str(n))))", "def numbers_of_letters(n):\n names = { '0': 'zero' ,\n '1': 'one' ,\n '2': 'two' ,\n '3': 'three',\n '4': 'four' ,\n '5': 'five' ,\n '6': 'six' ,\n '7': 'seven',\n '8': 'eight',\n '9': 'nine' }\n result = []\n while True:\n result.append(''.join(names[digit] for digit in str(n)))\n if result[-1]=='four':\n return result\n n = len(result[-1])", "numbers = 'zero one two three four five six seven eight nine'.split()\n\ndef f(n): return ''.join(numbers[int(i)] for i in str(n))\n\ndef numbers_of_letters(n):\n ans = [f(n)]\n while ans[-1]!='four':\n ans.append(f(len(ans[-1])))\n return ans", "DIGITS = (\"zero\", \"one\", \"two\", \"three\", \"four\", \"five\", \"six\", \"seven\", \"eight\", \"nine\")\n\ndef numbers_of_letters(n):\n n_digits = ''.join(DIGITS[i] for i in map(int, str(n)))\n n = len(n_digits)\n next_n_digits = ''.join(DIGITS[i] for i in map(int, str(n)))\n result = [n_digits, next_n_digits] if n_digits != next_n_digits else [n_digits]\n while len(next_n_digits) != n:\n n = len(next_n_digits)\n next_n_digits = ''.join(DIGITS[i] for i in map(int, str(n)))\n result.append(next_n_digits)\n return result", "def numbers_of_letters(n):\n change = {\"0\": \"zero\", \"1\": \"one\", \"2\": \"two\", \"3\": \"three\", \"4\": \"four\",\n \"5\": \"five\", \"6\": \"six\", \"7\": \"seven\", \"8\" : \"eight\", \"9\" : \"nine\"}\n num, sol = \"\".join(change[x] for x in str(n)), []\n sol.append(num)\n while num != \"four\":\n num = \"\".join(change[x] for x in str(len(num)))\n sol.append(num)\n return sol"] | {"fn_name": "numbers_of_letters", "inputs": [[1], [2], [3], [4], [12], [37], [311], [999]], "outputs": [[["one", "three", "five", "four"]], [["two", "three", "five", "four"]], [["three", "five", "four"]], [["four"]], [["onetwo", "six", "three", "five", "four"]], [["threeseven", "onezero", "seven", "five", "four"]], [["threeoneone", "oneone", "six", "three", "five", "four"]], [["nineninenine", "onetwo", "six", "three", "five", "four"]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,512 |
def numbers_of_letters(n):
|
9ef2a401bdf6fab957363a6a93a610ad | UNKNOWN | We need a function ```prime_bef_aft()``` that gives the largest prime below a certain given value ```n```,
```befPrime or bef_prime``` (depending on the language),
and the smallest prime larger than this value,
```aftPrime/aft_prime``` (depending on the language).
The result should be output in a list like the following:
```python
prime_bef_aft(n) == [befPrime, aftPrime]
```
If n is a prime number it will give two primes, n will not be included in the result.
Let's see some cases:
```python
prime_bef_aft(100) == [97, 101]
prime_bef_aft(97) == [89, 101]
prime_bef_aft(101) == [97, 103]
```
Range for the random tests:
```1000 <= n <= 200000```
(The extreme and special case n = 2 will not be considered for the tests. Thanks Blind4Basics)
Happy coding!! | ["def prime(a):\n if a < 2: return False\n if a == 2 or a == 3: return True \n if a % 2 == 0 or a % 3 == 0: return False\n maxDivisor = a**0.5\n d, i = 5, 2\n while d <= maxDivisor:\n if a % d == 0: return False\n d += i \n i = 6 - i\n \n return True\n\ndef prime_bef_aft(num):\n res = []\n for n in range(num-1, 1, -1):\n if prime(n):\n res.append(n)\n break\n for n in range(num+1, 3*num, 1):\n if prime(n):\n res.append(n)\n break\n return res", "def prime_bef_aft(num):\n m = 2 - (num%2 == 0)\n return [next(n for n in range(i, int(i*r), s) if is_prime(n)) for i, r, s in ((max(2, num-m), 0.8, -2), (num+m, 1.2, 2))]\n\n\ndef is_prime(n):\n factors = 0\n for k in (2, 3):\n while n % k == 0 and factors < 2:\n n //= k\n factors += 1\n k = 5\n step = 2\n while k * k <= n and factors < 2:\n if n % k:\n k += step\n step = 6 - step\n else:\n n //= k\n factors += 1\n if n > 1:\n factors += 1\n return factors == 1", "def prime_bef_aft(num):\n m = 2 - (num % 2 == 0)\n b, a, p_b, p_a = 2 if num == 3 else num-m, num+m, False, False\n while not p_b or not p_a:\n p_b, b = (True, b) if p_b or is_prime(b) else (False, b-2)\n p_a, a = (True, a) if p_a or is_prime(a) else (False, a+2)\n return [b, a] \n\n\ndef is_prime(n):\n factors = 0\n for k in (2, 3):\n while n % k == 0 and factors < 2:\n n //= k\n factors += 1\n k = 5\n step = 2\n while k * k <= n and factors < 2:\n if n % k:\n k += step\n step = 6 - step\n else:\n n //= k\n factors += 1\n if n > 1:\n factors += 1\n return factors == 1\n\n", "from itertools import compress\nimport numpy as np\n\ns = np.ones(200001)\ns[:2] = s[4::2] = 0\nfor i in range(3, int(len(s)**0.5)+1, 2):\n if s[i]:\n s[i*i::i] = 0\nprimes = list(compress(range(len(s)), s))\n\ndef prime_bef_aft(num):\n i = np.searchsorted(primes, num)\n return [primes[i-1], primes[i+(primes[i] == num)]]", "from itertools import count\n\ndef isPrime(n): return n==2 or all(n%x for x in range(3,int(n**.5+1),2)) # will never recieve an even number\n\ndef prime_bef_aft(n):\n delta = 2 - (n%2 == 0)\n return [ next(v + (v==1) for v in count(n-delta,-2) if isPrime(v) or v==1),\n next(v for v in count(n+delta, 2) if isPrime(v))]", "from math import sqrt\nfrom itertools import count, islice\n\ndef isPrime(n):\n return n > 1 and all(n%i for i in islice(count(2), int(sqrt(n)-1)))\n\ndef prime_bef_aft(num):\n c, d, l = num - 1, num + 1, []\n while len(l)<1:\n if isPrime(c):\n l.append(c)\n c -= 1\n while len(l)<2:\n if isPrime(d):\n l.append(d)\n d += 1\n return l\n", "def prime_bef_aft(num):\n after = num + 1\n while not isprime(after):\n after += 1\n \n before = num - 1\n while not isprime(before):\n before -= 1\n\n return[before, after]\n \n \ndef isprime(n):\n if n % 2 == 0 and n > 2: \n return False\n return all(n % i for i in range(3, int(n**0.5) + 1, 2))", "def prime_bef_aft(num):\n res = []\n for i in range(num, 0, -1):\n if len([x for x in range(1, i+1) if i % x == 0 and i != num]) == 2:\n res.append(i)\n break\n i = num\n while len(res) != 2:\n i += 1\n if len([x for x in range(1, i+1) if i % x == 0 and i != num]) == 2:\n res.append(i)\n break\n return res\n"] | {"fn_name": "prime_bef_aft", "inputs": [[3], [4], [100], [97], [101], [120], [130]], "outputs": [[[2, 5]], [[3, 5]], [[97, 101]], [[89, 101]], [[97, 103]], [[113, 127]], [[127, 131]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,727 |
def prime_bef_aft(num):
|
a5d54d951286db0151264aa824f6220a | UNKNOWN | It is 2050 and romance has long gone, relationships exist solely for practicality.
MatchMyHusband is a website that matches busy working women with perfect house husbands. You have been employed by MatchMyHusband to write a function that determines who matches!!
The rules are... a match occurs providing the husband's "usefulness" rating is greater than or equal to the woman's "needs".
The husband's "usefulness" is the SUM of his cooking, cleaning and childcare abilities and takes the form of an array .
usefulness example --> [15, 26, 19] (15 + 26 + 19) = 60
Every woman that signs up, begins with a "needs" rating of 100. However, it's realised that the longer women wait for their husbands, the more dissatisfied they become with our service. They also become less picky, therefore their needs are subject to exponential decay of 15% per month. https://en.wikipedia.org/wiki/Exponential_decay
Given the number of months since sign up, write a function that returns "Match!" if the husband is useful enough, or "No match!" if he's not. | ["def match(usefulness, months):\n return \"Match!\" if sum(usefulness) >= 0.85**months * 100 else \"No match!\"", "def match(usefulness, months):\n return 'Match!' if sum(usefulness) >= 100*0.85**months else 'No match!'", "def current(usefulness):\n return sum(usefulness)\n\ndef needed(months):\n if months == 0:\n return 100\n else:\n return 0.85 * needed(months - 1)\n\ndef match(usefulness, months):\n if current(usefulness) < needed(months):\n return \"No match!\"\n else:\n return \"Match!\"", "def match(usefulness, months):\n return f\"{'M' if sum(usefulness) >= 100 * 0.85**months else 'No m'}atch!\"", "def match(a, n):\n return \"Match!\" if sum(a) >= 100 * 0.85**n else \"No match!\"", "def match(usefulness, months):\n match = sum(usefulness) >= 100 * 0.85 ** months\n return 'Match!' if match else 'No match!'", "match=lambda u, m: [\"No match!\",\"Match!\"][sum(u)>=100*0.85**m]", "def match(usefulness, months):\n return [\"Match!\", \"No match!\"][sum(usefulness) < 100 * 0.85 ** months]", "def match(usefulness, months):\n decay, needs = 0.15, 100\n return \"Match!\" if needs * (1 - decay)**months <= sum(usefulness) else \"No match!\"", "def match(a,m):\n return ['No match!','Match!'][sum(a) >= 100*(0.85)**m]"] | {"fn_name": "match", "inputs": [[[15, 24, 12], 4], [[26, 23, 19], 3], [[11, 25, 36], 1], [[22, 9, 24], 5], [[8, 11, 4], 10], [[17, 31, 21], 2], [[34, 25, 36], 1], [[35, 35, 29], 0], [[35, 35, 30], 0], [[35, 35, 31], 0]], "outputs": [["No match!"], ["Match!"], ["No match!"], ["Match!"], ["Match!"], ["No match!"], ["Match!"], ["No match!"], ["Match!"], ["Match!"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,306 |
def match(usefulness, months):
|
54786c8184b80a60409adee5f9f21d03 | UNKNOWN | Your job is to figure out the index of which vowel is missing from a given string:
* `A` has an index of 0,
* `E` has an index of 1,
* `I` has an index of 2,
* `O` has an index of 3,
* `U` has an index of 4.
**Notes:** There is no need for string validation and every sentence given will contain all vowles but one. Also, you won't need to worry about capitals.
## Examples
```
"John Doe hs seven red pples under his bsket" => 0 ; missing: "a"
"Bb Smith sent us six neatly arranged range bicycles" => 3 ; missing: "o"
``` | ["def absent_vowel(x): \n return ['aeiou'.index(i) for i in 'aeiou' if i not in x][0]", "def absent_vowel(x): \n return 'aeiou'.index((set('aeiou') - set(x.lower())).pop())", "def absent_vowel(stg): \n return next(i for i, v in enumerate(\"aeiou\") if v not in stg)", "def absent_vowel(x): \n strings = ['a','e','i','o','u']\n for i in strings:\n if i not in x:\n return strings.index(i)", "def absent_vowel(x): \n code = {'a':0, 'e':1, 'i':2, 'o':3, 'u':4}\n for i in code:\n if i not in x:\n return code[i] \n", "def absent_vowel(x):\n vowels = ['a', 'e', 'i', 'o', 'u']\n for i, v in enumerate(vowels):\n if v not in x.lower():\n return i\n", "def absent_vowel(x): \n VOWELS = set('aeiou')\n INDEX = {\n 'a': 0,\n 'e': 1,\n 'i': 2,\n 'o': 3,\n 'u': 4,\n }\n missing = VOWELS.difference(set(x.lower()))\n return INDEX.get(''.join(missing))", "def absent_vowel(x): \n return \"aeiou\".index((set(\"aeiou\")-set(x)).pop())", "def absent_vowel(x): \n dictionary = {\n \"a\": 0,\n \"e\": 1,\n \"i\": 2,\n \"o\": 3,\n \"u\": 4}\n for vow in \"aeiou\":\n if vow not in x:\n return dictionary.get(vow)", "def absent_vowel(x): \n vowels = ['a', 'e', 'i', 'o', 'u']\n for i in vowels:\n if i not in x.lower():\n return vowels.index(i) "] | {"fn_name": "absent_vowel", "inputs": [["John Doe hs seven red pples under his bsket"], ["Bb Smith sent us six neatly arranged range bicycles"]], "outputs": [[0], [3]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,425 |
def absent_vowel(x):
|
1c702f91283a5bc5e6eb33074fefd60e | UNKNOWN | Quantum mechanics tells us that a molecule is only allowed to have specific, discrete amounts of internal energy. The 'rigid rotor model', a model for describing rotations, tells us that the amount of rotational energy a molecule can have is given by:
`E = B * J * (J + 1)`,
where J is the state the molecule is in, and B is the 'rotational constant' (specific to the molecular species).
Write a function that returns an array of allowed energies for levels between Jmin and Jmax.
Notes:
* return empty array if Jmin is greater than Jmax (as it make no sense).
* Jmin, Jmax are integers.
* physically B must be positive, so return empty array if B <= 0 | ["def rot_energies(B, Jmin, Jmax):\n return [B * J * (J + 1) for J in range(Jmin, Jmax + 1)] if B > 0 else []", "def rot_energies(rot, energy_min, energy_max):\n # We're programmers, not scientists or mathematicians, we can use legible variable names.\n if rot <= 0:\n return []\n else:\n return [rot * energy * (energy + 1) for energy in range(energy_min, energy_max + 1)]", "def rot_energies(B, Jmin, Jmax):\n return [B * j * (j + 1) for j in range(Jmin, Jmax + 1)] if B > 0 else []", "def rot_energies(B, Jmin, Jmax):\n return [B * J * (J + 1) for J in range(Jmin, Jmax + 1)] * (B > 0)", "def rot_energies(B, Jmin, Jmax):\n if B<=0:\n return []\n return [B * J * (J + 1) for J in range(Jmin,Jmax+1)]", "def rot_energies(B, Jmin, Jmax):\n if B < 0:\n return []\n return [B * J * (J + 1) for J in range(Jmin, Jmax + 1)]", "def rot_energies(B, Jmin, Jmax):\n return [] if B <= 0 else [B * I * (I + 1) for I in range(Jmin, Jmax + 1)]", "def E(B, J):\n return B*J*(J+1)\n \ndef rot_energies(B, Jmin, Jmax):\n if B < 0 or Jmax < Jmin: return []\n return [E(B, j) for j in range(Jmin, Jmax+1)]\n", "def rot_energies(B, Jmin, Jmax):\n result = []\n if B >= 0: \n for a in range(Jmin, Jmax+1):\n result.append(B * a * (a+1))\n return result", "def rot_energies(B, Jmin, Jmax):\n return [] if B < 0 or Jmin > Jmax else [B * i * (i + 1) for i in range(Jmin, Jmax + 1)]"] | {"fn_name": "rot_energies", "inputs": [[1, 1, 2], [2, 0, 3], [423, 100, 150], [1, 2, 0], [1, 2, 2], [-1.0, 2, 2]], "outputs": [[[2, 6]], [[0, 4, 12, 24]], [[4272300, 4357746, 4444038, 4531176, 4619160, 4707990, 4797666, 4888188, 4979556, 5071770, 5164830, 5258736, 5353488, 5449086, 5545530, 5642820, 5740956, 5839938, 5939766, 6040440, 6141960, 6244326, 6347538, 6451596, 6556500, 6662250, 6768846, 6876288, 6984576, 7093710, 7203690, 7314516, 7426188, 7538706, 7652070, 7766280, 7881336, 7997238, 8113986, 8231580, 8350020, 8469306, 8589438, 8710416, 8832240, 8954910, 9078426, 9202788, 9327996, 9454050, 9580950]], [[]], [[6]], [[]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,459 |
def rot_energies(B, Jmin, Jmax):
|
04bc629632449a16c772089d4a196393 | UNKNOWN | It's bonus time in the big city! The fatcats are rubbing their paws in anticipation... but who is going to make the most money?
Build a function that takes in two arguments (salary, bonus). Salary will be an integer, and bonus a boolean.
If bonus is true, the salary should be multiplied by 10. If bonus is false, the fatcat did not make enough money and must receive only his stated salary.
Return the total figure the individual will receive as a string prefixed with "£" (= `"\u00A3"`, JS, Go, and Java), "$" (C#, C++, Ruby, Clojure, Elixir, PHP and Python, Haskell, Lua) or "¥" (Rust). | ["def bonus_time(salary, bonus):\n return \"${}\".format(salary * (10 if bonus else 1))", "def bonus_time(salary, bonus):\n #your code here\n if bonus :\n return \"$\" + str(salary * 10)\n else:\n return \"$\" + str(salary)", "def bonus_time(salary, bonus):\n return '$' + str(salary * [1,10][bonus])", "def bonus_time(salary, bonus):\n return f\"${salary * 10 if bonus else salary}\"", "def bonus_time(salary, bonus):\n \n return '${}'.format(salary * (1 + 9*bonus))", "def bonus_time(salary, bonus):\n return \"$\" + str(salary * 10) if bonus == True else \"$\" + str(salary)", "def bonus_time(salary, bonus):\n return '$%d' % (salary * 10 if bonus else salary)", "def bonus_time(salary, bonus):\n if bonus: salary = salary * 10\n return str.format('${0}', salary)", "bonus_time = lambda salary, bonus: '${}'.format(salary * 10 if bonus else salary) ", "def bonus_time(salary, bonus):\n #your code here\n return \"${0}{1}\".format(salary, \"0\" if bonus else \"\")", "def bonus_time(salary, bonus): return '${}'.format([salary, salary*10][bonus])", "bonus_time = lambda s,b: \"${}\".format(s*(10*b or 1))", "bonus_time = lambda salary, bonus: '${}'.format(salary * (10 if bonus else 1))", "def bonus_time(salary, bonus):\n return '${0}'.format(salary * 10 if bonus else salary)", "def bonus_time(salary, bonus):\n if bonus == True:\n return '$' + str(salary*10)\n else:\n return '$' + str(salary)", "def bonus_time(salary, bonus):\n \n salary = int(salary)\n bonus = bool(bonus)\n \n if bonus is True:\n salary = salary * 10\n return \"${}\".format(salary)", "def bonus_time(salary, bonus):\n #your code here\n if bonus :\n salary = salary * 10\n return \"$\" + str(salary)\n else:\n return \"$\" + str(salary)\n", "def bonus_time(salary, bonus):\n if bonus == True:\n salary = salary * 10\n return \"$\" + str(salary)", "def bonus_time(salary, bonus):\n return \"$%d\" % (salary * 10 ** bonus)", "def bonus_time(salary, bonus):\n return '$%s%s' % (salary, '0' * bonus)", "def bonus_time(salary, bonus):\n #your code here\n return f'${salary * 10}' if bonus else f'${salary}'", "def bonus_time(salary, bonus):\n return (\"$%d\", \"$%d0\")[bonus] % salary", "def bonus_time(salary, bonus):\n return '${}'.format(salary * 10 ** bonus)", "def bonus_time(salary, bonus):\n return '$' + str(salary * 10 ** int(bonus))", "def bonus_time(salary, bonus):\n return \"$%d\" % (salary * (bonus*9 + 1))", "def bonus_time(salary, bonus):\n return '$' + str(salary*(10 if bonus else 1))", "def bonus_time(salary, bonus):\n return f'${salary}{\"0\"*bonus}'", "def bonus_time(salary, bonus):\n return f'${salary * (1 + bonus * 9)}'", "def bonus_time(salary, bonus):\n return f'${salary * (bonus * 9 + 1)}'", "def bonus_time(b, c):\n return f\"${b}{'0'*c}\"\n", "def bonus_time(salary, bonus):\n return f\"${salary}0\" if bonus else f\"${salary}\"", "def bonus_time(salary, bonus):\n return f\"${salary + bonus * 9 * salary}\"", "def bonus_time(salary, bonus):\n return f'${salary * (1 + 9 * bonus)}'", "def bonus_time(salary, bonus):\n return \"$\"+ str(int(salary) + (bonus * (9 * salary)))", "def bonus_time(salary, bonus):\n return '$' + str(salary * 10 if bonus else salary)", "def bonus_time(salary, bonus):\n return ('${}'.format(salary * 10) if bonus else '${}'.format(salary))", "def bonus_time(salary, bonus):\n return ('${}'.format(salary),'${}'.format(salary*10))[bonus]", "def bonus_time(salary, bonus):\n s = salary*10\n if bonus is True:\n return \"$\"+str(s)\n if bonus is False:\n return \"$\"+str(salary)\n", "def bonus_time(salary, bonus):\n i = 0\n if bonus is True:\n i = salary*10\n if bonus is False:\n i = salary\n return '$'+ str(i)\n", "def bonus_time(salary, bonus):\n if bonus == True:\n result = \"$\"+str(salary*10)\n elif bonus == False:\n result = \"$\"+str(salary)\n return result\n #your code here\n", "def bonus_time(salary, bonus):\n a = lambda s, b: \"${}\".format(s*10) if b== True else \"${}\".format(s)\n return a(salary, bonus)", "def bonus_time(salary, bonus):\n \n if bonus == True:\n salary=salary*10\n s='$'+str(salary)\n return s\n else:\n s='$'+str(salary)\n return s\n", "def bonus_time(salary, bonus):\n if bonus==True:\n return '$'+str(salary)+'0'\n elif bonus==False:\n return '$'+str(salary)", "bonus_time=lambda s,b:f'${s*(9*b+1)}'", "def bonus_time(salary, bonus):\n if bonus == True:\n k = str(salary * 10)\n else:\n k = str(salary)\n return ('$'+k)", "def bonus_time(s, bonus):\n if bonus==True:\n return \"$\"+str(s*10)\n else:\n return \"$\"+str(s) \n \n \n #your code here\n", "def bonus_time(s, b):\n return '${}'.format(s*10 if b else s)", "def bonus_time(salary, bonus):\n #your code he\n b = salary\n if bonus:\n b*=10\n return \"$\"+str(b)", "def bonus_time(salary, bonus):\n return \"$\" + str(salary * 10) if bonus == True else f\"${salary}\"", "def bonus_time(salary, bonus):\n return '$' + str((1, 10)[bonus] * salary)", "def bonus_time(salary, bonus):\n if bonus:\n return F\"${((salary * 10))}\"\n return F\"${salary}\"", "def bonus_time(salary, bonus):\n if bonus == True:\n salary = salary * 10\n amt = str(salary)\n return \"${}\".format(amt)", "bonus_time = lambda s, b:f'${s+s*b*9}'", "def bonus_time(salary, bonus):\n #your code here\n if(bonus==True):\n s=str(salary*10)\n return \"$\"+s\n else:\n salary=str(salary)\n return \"$\"+salary", "def bonus_time(salary:int, bonus:bool):\n if bonus is True:\n return (\"$\"+str(salary*10))\n return (\"$\"+str(salary))", "def bonus_time(salary, bonus):\n #your code here\n ln = ''\n if bonus:\n ln += '0'\n else:\n ln\n return f'${salary}{ln}'", "def bonus_time(a, b):\n return f\"${a*10 if b else a}\"", "def bonus_time(salary, bonus):\n return f\"{'$'+str(salary*10)}\" if bonus else f\"{'$'+str(salary)}\"", "def bonus_time(salary, bonus):\n #your code here\n x=lambda salary,bonus: str('$'+str(salary*10)) if(bonus==True) else str('$'+str(salary))\n return x(salary,bonus)", "def bonus_time(salary, bonus):\n if bonus == True:\n s = salary*10\n s=str(s)\n return '$'+s\n else:\n s = str(salary)\n return '$'+s", "def bonus_time(salary, bonus):\n if bonus:\n payday = salary * 10\n return '$' + str(payday)\n else:\n return '$' + str(salary)", "def bonus_time(salary, bonus):\n return f\"${int(salary) * 10}\" if bonus else f\"${salary}\"", "def bonus_time(salary, bonus):\n return \"$\"+str(salary) if bonus is False else \"$\"+str(salary*10)", "def bonus_time(salary, bonus):\n return \"$%d\" % (salary*10 if bonus==True else salary)", "bonus_time = lambda salary, bonus: bonus and \"$\" + str(salary * 10) or \"$\" + str(salary)", "def bonus_time(salary, bonus):\n if bonus == True:\n new = salary * 10\n return str(\"$\" + str(new))\n else:\n return str(\"$\" + str(salary))", "def bonus_time(salary, bonus):\n #your code here\n if bonus == True:\n m = salary*10\n return '$'+str(m)\n return '$'+str(salary)", "def bonus_time(salary, bonus):\n if (bonus == True):\n salary=salary*10\n else:\n salary=salary+0\n return (\"$\"+str(salary))\n", "def bonus_time(salary, bonus):\n if bonus == True:\n result = salary * 10\n else:\n result = salary\n \n return f\"${result}\"", "bonus_time = lambda s, b: f\"${s*10 if b else s}\"", "def bonus_time(salary, bonus):\n return \"${}\".format(str(salary * 10)) if bonus == True else \"${}\".format(salary)", "def bonus_time(salary, bonus):\n return '$%d' % (salary * (9 * bonus + 1))", "def bonus_time(salary, bonus):\n if bonus == True:\n s = salary*10\n else:\n s = salary\n return str('$'+str(s))\n", "def bonus_time(salary, bonus):\n b = salary*10 if bonus else salary\n return \"$\" + str(b)", "def bonus_time(salary, bonus):\n x = salary * 10\n \n if bonus == True:\n return f'${x}'\n elif bonus == False:\n return f'${salary}'", "def bonus_time(s, b):\n return \"$\" + (str(s * 10) if b == True else str(s)) #this is not the correct answer", "def bonus_time(salary, bonus):\n x = str(int(salary) * 10)\n y = str(int(salary))\n if bonus == True:\n return str('$')+ x\n else:\n return str('$')+ y", "def bonus_time(salary, bonus):\n return f'${salary}' + '0' if bonus == True else f'${salary}'", "def bonus_time(salary, bonus):\n if bonus == True:\n salary *= 10\n a = \"${}\".format(salary)\n return a\n return \"$\" + str(salary)\n #your code here\n", "def bonus_time(salary, bonus):\n pay = salary * 10 if bonus else salary\n return f\"${pay}\"", "def bonus_time(salary, bonus):\n if bonus == True:\n return f\"${salary}0\"\n else:\n return f\"${salary}\"", "def bonus_time(salary, bonus):\n x = salary;\n y = 10 * salary\n if bonus:\n return '$'+ str(y)\n else:\n return '$'+ str(x)", "def bonus_time(salary, bonus):\n if not bonus:\n return f\"${salary}\"\n else:\n return f\"${salary * 10}\"\n \n \n \n", "def bonus_time(salary, bonus):\n #your code here\n total = ''\n if bonus == True:\n return total + '$' + str(salary * 10)\n return total + '$' + str(salary)", "def bonus_time(salary, bonus):\n if bonus:\n salary = salary * 10\n x = str(salary)\n return '$'+x\n #your code here\n", "def bonus_time(salary, bonus):\n result = str(salary*10) if bonus else str(salary)\n return \"${}\".format(result)", "def bonus_time(salary, bonus):\n return '${}'.format(salary * (10 if bonus == True else 1))", "def bonus_time(salary, bonus):\n #your code here\n new_salary = salary * 10\n if bonus == True:\n return \"$\" + str(new_salary)\n return \"$\" + str(salary)", "def bonus_time(salary, bonus):\n if bonus == True:\n total = salary * 10\n return \"$\" + str(total)\n if bonus == False:\n return \"$\" + str(salary)", "def bonus_time(salary, bonus):\n dollar = \"$\"\n if bonus == True:\n result = str(salary*10)\n return dollar + result\n elif bonus==False:\n return \"$\" + str(salary)", "def bonus_time(salary, bonus):\n pay = str(salary*10) if bonus else str(salary)\n return '${}'.format(pay)", "def bonus_time(salary, bonus):\n i = salary * 10\n k = salary\n if bonus == True:\n return \"$\" + str(i)\n else:\n return \"$\" + str(k) \n", "def bonus_time(salary, bonus):\n total = salary\n if bonus:\n salary *= 10\n return '$%d' % (salary)", "def bonus_time(salary, bonus):\n int(salary)\n bool(bonus)\n if bonus == 1 :\n return \"$\" + str(salary * 10)\n elif bonus == 0 :\n return \"$\" + str(salary)\n", "def bonus_time(s, b):\n return \"$\"+ str(s*(10 if b else 1))", "def bonus_time(salary, bonus):\n #your code here\n sum='$'\n if bonus==True: \n salary=salary*10\n salary=str(salary)\n return sum+salary\n return sum+ str(salary)\n", "def bonus_time(salary: int, bonus: bool) -> str:\n \"\"\"\n If bonus is true, the salary should be multiplied 10.\n If bonus is false, one must receive only his stated salary.\n \"\"\"\n return \"$\" + str(salary * 10) if bonus else \"$\" + str(salary)\n", "def bonus_time(salary, bonus):\n if bonus == True:\n wow =(salary * 10)\n return '$' + str(wow)\n else:\n bonus == False\n return '$' + str(salary)", "def bonus_time(salary, bonus):\n if bonus == True:\n amount = salary * 10\n return \"$\"+ str(amount)\n elif bonus == False:\n return \"$\"+ str(salary)"] | {"fn_name": "bonus_time", "inputs": [[10000, true], [25000, true], [10000, false], [60000, false], [2, true], [78, false], [67890, true]], "outputs": [["$100000"], ["$250000"], ["$10000"], ["$60000"], ["$20"], ["$78"], ["$678900"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 12,221 |
def bonus_time(salary, bonus):
|
b49bbb9232af0d69a62144eab10606d4 | UNKNOWN | #### Task:
Your job here is to write a function (`keepOrder` in JS/CoffeeScript, `keep_order` in Ruby/Crystal/Python, `keeporder` in Julia), which takes a sorted array `ary` and a value `val`, and returns the lowest index where you could insert `val` to maintain the sorted-ness of the array. The input array will always be sorted in ascending order. It may contain duplicates.
_Do not modify the input._
#### Some examples:
```python
keep_order([1, 2, 3, 4, 7], 5) #=> 4
^(index 4)
keep_order([1, 2, 3, 4, 7], 0) #=> 0
^(index 0)
keep_order([1, 1, 2, 2, 2], 2) #=> 2
^(index 2)
```
Also check out my other creations — [Naming Files](https://www.codewars.com/kata/naming-files), [Elections: Weighted Average](https://www.codewars.com/kata/elections-weighted-average), [Identify Case](https://www.codewars.com/kata/identify-case), [Split Without Loss](https://www.codewars.com/kata/split-without-loss), [Adding Fractions](https://www.codewars.com/kata/adding-fractions),
[Random Integers](https://www.codewars.com/kata/random-integers), [Implement String#transpose](https://www.codewars.com/kata/implement-string-number-transpose), [Implement Array#transpose!](https://www.codewars.com/kata/implement-array-number-transpose), [Arrays and Procs #1](https://www.codewars.com/kata/arrays-and-procs-number-1), and [Arrays and Procs #2](https://www.codewars.com/kata/arrays-and-procs-number-2).
If you notice any issues or have any suggestions/comments whatsoever, please don't hesitate to mark an issue or just comment. Thanks! | ["from bisect import bisect_left as keep_order", "from bisect import bisect_left\n\ndef keep_order(arr, val):\n return bisect_left(arr, val)", "def keep_order(ary, val):\n for i, x in enumerate(ary):\n if x >= val:\n return i\n return len(ary)", "def keep_order(arr, val):\n for i in range(len(arr)):\n if arr[i] >= val:\n return i\n return len(arr)", "def keep_order(ary, val):\n return len(list(x for x in ary if x < val))", "def keep_order(ary, val):\n for i,_ in enumerate(ary):\n if val <= ary[i]:\n return i\n return len(ary)\n\n", "def keep_order(ar, val):\n for i in range(len(ar)):\n if ar[i]>=val: return i\n return len(ar)", "def keep_order(a, value):\n for i in range(len(a)):\n if value <= a[i]:\n return i\n return len(a)", "def keep_order(ary, val):\n return sum(i<val for i in ary)", "def keep_order(ary, val):\n if not ary:\n return 0\n for x in range(len(ary)):\n if val <= ary[x]:\n return x\n return x+1 \n \n", "def keep_order(ary, val):\n ary.append(val)\n return sorted(ary).index(val)", "from bisect import bisect_left as keep_order ###", "def keep_order(ary, val):\n return next((ary.index(x) for x in ary if x>=val), len(ary))", "def keep_order(ary, val):\n if not ary: return 0\n if max(ary) < val:\n return len(ary)\n for i,num in enumerate(ary):\n if num >= val:\n return i\n", "def keep_order(ary, val):\n print(ary, val)\n a = ary\n a.append(val)\n a.sort()\n for i, j in enumerate(a):\n if j == val:\n return i", "def keep_order(ary, val):\n return next((i for i,(v1,v2) in enumerate(zip(ary,ary[1:]),1) if v1<=val<=v2),len(ary)) if ary and val>ary[0] else 0", "def keep_order(ary, val):\n idx = 0\n for i in range(len(ary)):\n if val > ary[idx]:\n idx += 1\n else:\n return idx\n return idx", "from itertools import takewhile\ndef keep_order(ary, val):\n return len(list(takewhile(lambda v: v < val, ary)))\n", "def keep_order(ary, val):\n\n \n if val not in ary:\n \n ary.append(val)\n \n ary.sort()\n \n return ary.index(val)\n", "def keep_order(a,x):\n for i,v in enumerate(a):\n if v>=x:\n return i\n return len(a)"] | {"fn_name": "keep_order", "inputs": [[[1, 2, 3, 4, 7], 5], [[1, 2, 3, 4, 7], 0], [[1, 1, 2, 2, 2], 2], [[1, 2, 3, 4], 5], [[1, 2, 3, 4], -1], [[1, 2, 3, 4], 2], [[1, 2, 3, 4], 0], [[1, 2, 3, 4], 1], [[1, 2, 3, 4], 3], [[], 1], [[], 0], [[1, 1, 1, 1], 2], [[1, 1, 1, 1], 1], [[1, 1, 1, 1], 0], [[1, 3, 5, 6], 0], [[1, 3, 5, 6], 2], [[1, 2, 3, 4], -2], [[1, 2, 3, 4], -3]], "outputs": [[4], [0], [2], [4], [0], [1], [0], [0], [2], [0], [0], [4], [0], [0], [0], [1], [0], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,397 |
def keep_order(ary, val):
|
bbde7397b3b381c5aaf44946816daaff | UNKNOWN | How many bees are in the beehive?
* bees can be facing UP, DOWN, LEFT, or RIGHT
* bees can share parts of other bees
Examples
Ex1
```
bee.bee
.e..e..
.b..eeb
```
*Answer: 5*
Ex2
```
bee.bee
e.e.e.e
eeb.eeb
```
*Answer: 8*
# Notes
* The hive may be empty or null/None/nil/...
* Python: the hive is passed as a list of lists (not a list of strings) | ["from itertools import chain\ndef how_many_bees(hive):\n return bool(hive) and sum(s.count('bee') + s.count('eeb') for s in map(''.join, chain(hive, zip(*hive))))", "def count(it):\n return sum(''.join(x).count('bee') + ''.join(x).count('eeb') for x in it)\n\ndef how_many_bees(hive):\n return count(hive) + count(zip(*hive)) if hive else 0", "def how_many_bees(hive):\n if hive == None or len(hive) == 0:\n return 0\n result = 0\n \n for i in range(len(hive[0])):\n test = \"\"\n for item in hive:\n test += item[i]\n result += test.count(\"bee\")\n result += test.count(\"eeb\")\n \n for i in range(len(hive)):\n test = \"\"\n for item in hive[i]:\n test += item\n result += test.count(\"bee\")\n result += test.count(\"eeb\")\n return result", "import re\n\ndef how_many_bees(hive):\n if hive is None: return 0\n s = ' '.join(''.join(line) for hiveArr in (hive, zip(*hive)) for line in hiveArr)\n return len(re.findall(r'b(?=ee)|ee(?=b)', s))", "def how_many_bees(hive):\n if not hive:\n return 0\n row_bees = lambda row: sum(1 for i in range(len(row)) if \"\".join(row[i:i+3]) == \"bee\")\n matrix_bees = lambda matrix: sum(row_bees(row) for row in matrix)\n v_flip = lambda matrix: [row[::-1] for row in matrix]\n transpose = lambda matrix: [list(z) for z in zip(*matrix)]\n return (\n matrix_bees(hive) + \n matrix_bees(transpose(hive)) +\n matrix_bees(v_flip(hive)) + \n matrix_bees(v_flip(transpose(hive)))\n )\n", "def how_many_bees(hive):\n if hive is None:\n return 0\n columns = [\"\".join(col) for col in zip(*hive)]\n hive = [\"\".join(line) for line in hive]\n return sum(row.count(bee) for bee in (\"bee\", \"eeb\") for rows in (hive, columns) for row in rows)", "def how_many_bees(hive):\n counter = 0\n try:\n for row in hive:\n for i in range(len(row)-2):\n if row[i] == 'b' and row[i+1] == 'e' and row[i+2] == 'e':\n counter += 1\n elif row[i] == 'e' and row[i+1] == 'e' and row[i+2] == 'b':\n counter += 1\n\n for column in range(len(hive[0])):\n for position in range(len(hive)-2):\n if hive[position][column] == 'b' and hive[position+1][column] == 'e' and hive[position+2][column] == 'e':\n counter += 1\n if hive[position][column] == 'e' and hive[position+1][column] == 'e' and hive[position+2][column] == 'b':\n counter += 1\n\n except:\n counter = 0\n return counter", "import re\ndef how_many_bees(b):\n if b is None:return 0\n new_temp = [[j for j in i] for i in b]\n c = [len(re.findall(r\"bee\", \"\".join(i+[' ']+i[::-1]))) for i in new_temp]+[ len(re.findall(r\"bee\", \"\".join(i+tuple(' ')+i[::-1]))) for i in zip(*new_temp)]\n return sum(c)", "directions = [(1, 0), (-1, 0), (0, -1), (0, 1)]\n\ndef how_many_bees(hive):\n r, c = (len(hive), len(hive[0])) if hive else (0, 0)\n def f(s, i, j, di, dj):\n if not (0 <= i < r and 0 <= j < c and s.startswith(hive[i][j])):\n return 0\n s = s[1:]\n return f(s, i+di, j+dj, di, dj) if s else 1\n return sum(f('bee', i, j, di, dj) for i in range(r) for j in range(c) for di, dj in directions)", "VARIANTS = ['bee', 'eeb']\n\ndef how_many_bees(hive):\n count = 0\n if hive is None:\n return count\n rl = len(hive)\n for i in range(rl):\n cl = len(hive[i])\n for j in range(0, len(hive[i])):\n print(\"i=\", i, \"j=\", j)\n o = hive[i][j]\n \n if j < cl - 2:\n x1 = hive[i][j + 1]\n x2 = hive[i][j + 2]\n x = o + x1 + x2\n if x in VARIANTS:\n count += 1\n \n if i < rl -2:\n y1 = hive[i + 1][j]\n y2 = hive[i + 2][j]\n y = o + y1 + y2\n if y in VARIANTS:\n count += 1\n return count", "def how_many_bees(hive):\n if hive ==[] or hive ==\"\" or hive== None:\n return 0\n result=0\n for i in range(len(hive)):\n for k in range(len(hive[i])):\n if i > 1 and hive[i][k] ==\"b\" :\n if hive[i-1][k] ==\"e\" and hive [i-2][k] ==\"e\":\n result +=1\n if i <len(hive)-2 and hive[i][k] ==\"b\":\n if hive[i+1][k] ==\"e\" and hive [i+2][k] ==\"e\":\n result +=1\n if k <len(hive[i])-2 and hive[i][k] ==\"b\":\n if hive[i][k+1] ==\"e\" and hive [i][k+2] ==\"e\":\n result +=1\n if k > 1 and hive[i][k] ==\"b\":\n if hive[i][k-1] ==\"e\" and hive [i][k-2] ==\"e\":\n result +=1\n \n return result\n \n", "how_many_bees=lambda h:h and sum(map('|'.join(map(''.join,h+list(zip(*h)))).count,('bee','eeb')))or 0", "import re\nhow_many_bees=lambda b:0 if not b else sum([len(re.findall(r\"bee\", \"\".join(i+[' ']+i[::-1]))) for i in b]+[len(re.findall(r\"bee\", \"\".join(i+tuple(' ')+i[::-1]))) for i in zip(*b)])", "def how_many_bees(hive):\n bees = ('bee', 'eeb')\n num_of_bees = 0\n \n if hive == None:\n return 0\n \n for line in hive:\n for pos in range(len(line)-2):\n possible_bee = line[pos] + line[pos+1] + line[pos+2]\n if possible_bee in bees:\n num_of_bees +=1\n for line_idx in range(len(hive)-2):\n for pos_idx in range(len(hive[line_idx])):\n possible_bee = hive[line_idx][pos_idx] + hive[line_idx+1][pos_idx] + hive[line_idx+2][pos_idx]\n if possible_bee in bees:\n num_of_bees +=1\n return num_of_bees\n", "def how_many_bees(hive):\n if hive is None or len(hive) == 0:\n return 0\n \n cnt = 0\n #rows\n for row in hive:\n cnt += ''.join(row).count('bee')\n cnt += ''.join(row).count('eeb')\n \n #columns\n m, n = len(hive), len(hive[0])\n \n cols = [''.join([hive[j][i] for j in range(m)]) for i in range(n)]\n cnt += sum([i.count('bee') for i in cols])\n cnt += sum([i.count('eeb') for i in cols])\n return cnt", "def rotate(matrix):\n return list(zip(*matrix[::-1]))\n\n\ndef how_many_bees(hive):\n if hive:\n s1 = \" \".join([\"\".join(r) for r in hive])\n s2 = \" \".join([\"\".join(el) for el in rotate(hive)])\n s = s1 + \" \" + s2\n return s.count(\"bee\") + s.count(\"eeb\")\n return 0\n", "def how_many_bees(hive):\n if not hive:\n return 0\n count=0\n for i in range(len(hive)):\n for j in range(len(hive[i])-2):\n compare=\"\".join(hive[i][j:j+3])\n if compare==\"bee\" or compare==\"eeb\":\n count+=1\n for i in range(len(hive)-2):\n for j in range(len(hive[i])):\n compare=hive[i][j]+hive[i+1][j]+hive[i+2][j]\n if compare==\"bee\" or compare==\"eeb\":\n count+=1\n return count", "how_many_bees = lambda h: ((lambda m, tm: sum(sum(q.count(a) for q in b) for a in ['bee', 'eeb'] for b in [m, tm]))([''.join(x) for x in h] if h else [],[''.join([h[p][q] for p in range(len(h))]) for q in range(0 if len(h) == 0 else len(h[0]))] if h else []))\n", "def how_many_bees(hive):\n try:\n right = sum(line.count('bee') for line in map(''.join, hive))\n left = sum(line.count('eeb') for line in map(''.join, hive))\n down = sum(line.count('bee') for line in map(''.join, zip(*hive)))\n up = sum(line.count('eeb') for line in map(''.join, zip(*hive)))\n return up + down + left + right\n except TypeError:\n return 0", "def how_many_bees(hive):\n return sum(word.count(\"eeb\")+word.count(\"bee\") for word in list(map(lambda x:\"\".join(list(x)),zip(*hive)))+list(map(lambda x:\"\".join(x),hive))) if hive else 0"] | {"fn_name": "how_many_bees", "inputs": [[null]], "outputs": [[0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 8,103 |
def how_many_bees(hive):
|
73420a4efa0b7355365305592932229e | UNKNOWN | ```if:python,php
In this kata you will have to write a function that takes `litres` and `price_per_litre` as arguments. Purchases of 2 or more litres get a discount of 5 cents per litre, purchases of 4 or more litres get a discount of 10 cents per litre, and so on every two litres, up to a maximum discount of 25 cents per litre. But total discount per litre cannot be more than 25 cents. Return the toal cost rounded to 2 decimal places. Also you can guess that there will not be negative or non-numeric inputs.
Good Luck!
```
```if:csharp,java,javascript
In this kata you will have to write a function that takes `litres` and `pricePerLitre` as arguments. Purchases of 2 or more litres get a discount of 5 cents per litre, purchases of 4 or more litres get a discount of 10 cents per litre, and so on every two litres, up to a maximum discount of 25 cents per litre. But total discount per litre cannot be more than 25 cents. Return the toal cost rounded to 2 decimal places. Also you can guess that there will not be negative or non-numeric inputs.
Good Luck!
``` | ["def fuel_price(litres, price_per_liter):\n discount = int(min(litres, 10)/2) * 5 / 100\n return round((price_per_liter - discount) * litres, 2)", "fuel_price = lambda l,p: round(l*(p-min(0.05*(l//2), 0.25)), 2)", "from bisect import bisect\n\n\ndef fuel_price(litres, price_per_liter):\n discount = (0, 5, 10, 15, 20, 25)[bisect([2, 4, 6, 8, 10], litres)] * 0.01\n return (litres * price_per_liter) - (litres * discount)\n\n\n# PEP8: function name should use snake_case\nfuelPrice = fuel_price\n", "def fuel_price(litres, price_per_liter):\n return litres * max(price_per_liter-.25, price_per_liter-.05*(litres//2))", "def fuel_price(litres, price_per_liter):\n \n discount = (litres // 2) * 0.05\n if litres >= 10:\n discount = 0.25\n \n total = round((price_per_liter - discount) * litres,2)\n \n return total", "def fuel_price(litres: int, price_per_liter: int) -> float:\n return litres * (price_per_liter - 0.05 * min(litres // 2, 5))\n", "def fuel_price(l, ppl):\n return round(l*(ppl - min(l//2 * 0.05, 0.25)), 2)", "def fuel_price(l, p):\n if l >= 2 and l < 4: return l * (p - 0.05)\n elif l >= 4 and l < 6: return l * (p - 0.10)\n elif l >= 6 and l < 8: return l * (p - 0.15)\n elif l >= 8 and l < 10: return l * (p - 0.20)\n return l * (p - 0.25)", "def fuel_price(liters, price_per_liter):\n discount = min(.25, .05 * (liters // 2)) * liters\n return (liters * price_per_liter) - discount", "def fuel_price(l, ppl):\n return round(l * (ppl - min(l // 2 * .05, .25)), 2)\n", "def fuel_price(litres, price_per_liter):\n return round(litres * (price_per_liter - min((litres // 2) * 0.05, 0.25)), 2)", "def fuel_price(l, p):\n if l < 2:\n return round(l*p,2)\n if 2 <= l < 4:\n return round(l*(p-0.05),2)\n if 4 <= l < 6:\n return round(l*(p-0.1),2) \n if 6 <= l < 8:\n return round(l*(p-0.15),2) \n if 8 <= l < 10:\n return round(l*(p-0.2),2) \n else:\n return round(l*(p-0.25),2)", "def fuel_price(l, p):\n dic = {(0,1):p, (2,3):(p-0.05), (4,5):(p-0.1), (6,7):(p-0.15), (8,9):(p-0.2)}\n return round(l*dic.get(max(i if l in i else (0,0) for i in dic), (p-0.25)),2)\n\ndef fuel_price(l, p):\n return round(l * (next(d for a, d in [\n (10, p-0.25), (8, p-0.2), (6, p-0.15), (4, p-0.1), (2, p-0.05), (0, p)\n ] if l >= a)), 2)", "def fuel_price(lt, pr):\n return lt * pr - lt * (lt // 2 * 0.05) if lt <= 10 else lt * pr - lt * 0.25", "def fuel_price(litres, price_per_litre):\n return litres * price_per_litre - ((2 <= litres < 4) * 0.05 * litres) - ((4 <= litres < 6) * 0.1 * litres) - ((6 <= litres < 8) * 0.15 * litres) - ((8 <= litres < 10) * 0.2 * litres) - ((10 <= litres) * 0.25 * litres)", "def fuel_price(litres, price_per_litre):\n if litres<2 :\n price = litres*price_per_litre;\n elif litres<4 : \n price = litres*(price_per_litre-0.05);\n elif litres<6:\n price = litres*(price_per_litre-0.10);\n elif litres<8:\n price = litres*(price_per_litre-0.15);\n elif litres<10:\n price = litres*(price_per_litre-0.20);\n else :\n price = litres*(price_per_litre-0.25);\n price = round(price, 2); \n return price;", "def fuel_price(litres, price_per_litre):\n return litres * (price_per_litre - 0.25) if litres >= 10 else round(litres * (price_per_litre - (litres // 2 * 5) / 100), 2)", "def fuel_price(litres, price_per_litre):\n if litres%2 == 0 and 2 <= litres <= 8 :\n discount = round(litres/2,2)*round(5/100,2) \n elif litres >= 8:\n discount = 0.25\n else :\n discount = 0\n price = round((price_per_litre - discount)*litres,2)\n return price", "def fuel_price(litres, price_per_litre):\n discount = min(25, (litres // 2) * 5)\n \n price = litres * price_per_litre - (discount * litres / 100) \n \n return round(price, 2)", "def fuel_price(litres, price_per_litre):\n \n if litres>0 and price_per_litre>0:\n if 2 <= litres < 4:\n price_per_litre_real = price_per_litre - 0.05\n elif 4 <= litres < 6:\n price_per_litre_real = price_per_litre - 0.10\n elif 6 <= litres < 8:\n price_per_litre_real = price_per_litre - 0.15\n elif 8 <= litres < 10:\n price_per_litre_real = price_per_litre - 0.20\n elif 10 <= litres :\n price_per_litre_real = price_per_litre - 0.25\n \n return litres * price_per_litre_real", "def fuel_price(litres, price_per_litre):\n total_price=0\n price_per_litre=float(price_per_litre)\n for x in range (litres):\n\n if litres < 4:\n total_price += price_per_litre\n elif litres < 6:\n total_price += (price_per_litre-0.05)\n elif litres < 8:\n total_price += (price_per_litre-0.15)\n elif litres < 10:\n total_price += (price_per_litre-0.20)\n else:\n total_price += (price_per_litre-0.25)\n \n return round(float(total_price),2)", "def fuel_price(litres, ppl):\n if litres<2:\n return round(litres*ppl,2)\n elif 2<=litres<4:\n return round(litres*ppl-litres*0.05,2)\n elif 4<=litres<6:\n return round(litres*ppl-litres*0.1,2)\n elif 6<=litres<8:\n return round(litres*ppl-litres*0.15,2)\n elif 8<=litres<10:\n return round(litres*ppl-litres*0.2,2)\n else:\n return round(litres*ppl-litres*0.25,2)\n", "def fuel_price(litres, price_per_litre):\n if litres < 2:\n price = litres * price_per_litre\n elif litres <4:\n price = litres * (price_per_litre - 0.05)\n elif litres <6: \n price = litres * (price_per_litre - 0.10)\n elif litres <8:\n price = litres * (price_per_litre - 0.15)\n elif litres <10:\n price = litres * (price_per_litre - 0.20)\n else:\n price = litres * (price_per_litre - 0.25)\n return round(price,2)\n", "def fuel_price(litres, price_per_litre):\n if litres < 2:\n price = litres * price_per_litre\n elif litres < 4:\n price = litres * (price_per_liter - 0.05)\n elif litres < 6:\n price = litres * (price_per_litre - 0.10)\n elif litres < 8:\n price = litres * (price_per_litre - 0.15)\n elif litres < 10:\n price = litres * (price_per_litre - 0.20)\n else:\n price = litres * (price_per_litre - 0.25)\n return round(price,2)", "def fuel_price(litres, price_per_litre):\n if litres >= 10:\n price_per_litre = price_per_litre - 0.25;\n elif litres >= 8:\n price_per_litre = price_per_litre - 0.20;\n elif litres >= 6:\n price_per_litre = price_per_litre - 0.15;\n elif litres >= 4:\n price_per_litre = price_per_litre - 0.10;\n elif litres >= 2:\n price_per_litre = price_per_litre - 0.05;\n\n return litres * price_per_litre", "def fuel_price(litres, price_per_litre):\n \n if litres < 2:\n return round( price_per_litre * litres,2)\n elif 2 <= litres < 4:\n return round((price_per_litre * litres) - (.05 * litres) ,2)\n elif 4 <= litres < 6:\n return round((price_per_litre * litres) - (.10 * litres) ,2)\n elif 6 <= litres < 8:\n return round((price_per_litre * litres) - (.15 * litres),2)\n elif 8 <= litres < 10:\n return round((price_per_litre * litres) - (.20 * litres) ,2)\n else: \n return round((price_per_litre * litres) - (.25 * litres),2)", "def fuel_price(litres, price_per_litre):\n if litres < 2:\n price = litres * price_per_litre\n elif litres < 4:\n price = litres * (price_per_litre -0.05)\n elif litres < 6:\n price = litres * (price_per_litre -0.1)\n elif litres < 8:\n price = litres * (price_per_litre -0.15)\n elif litres < 10:\n price = litres * (price_per_litre -0.20)\n else:\n price = litres * (price_per_litre -0.25)\n return round(price, 2)\n #your code here\n", "def fuel_price(l,p):\n if l<=3:\n return round(l*p-(l*.05),2)\n elif l<=5:\n return round(l*p-(l*.15),2)\n elif l<=7:\n return round(l*p-(l*.15),2)\n elif l<=9:\n return round(l*p-(l*.20),2)\n else:\n return round(l*p-(l*.25),2)\n \n", "def fuel_price(litres, price_per_litre):\n if litres < 2:\n return litres * price_per_litre\n elif litres < 4:\n return litres * (price_per_litre - .05)\n elif litres < 6:\n return litres * (price_per_litre - .10)\n elif litres < 8:\n return litres * (price_per_litre - .15)\n elif litres < 10:\n return litres * (price_per_litre - .20)\n else:\n return litres * (price_per_litre - .25)\n", "def fuel_price(litres, price_per_litre):\n if litres > 9:\n return round(litres*(price_per_litre-0.25), 2)\n elif litres > 7:\n return round(litres*(price_per_litre-0.20), 2)\n elif litres > 5: \n return round(litres*(price_per_litre-0.15), 2)\n elif litres > 3: \n return round(litres*(price_per_litre-0.10), 2)\n elif litres > 1: \n return round(litres*(price_per_litre-0.05), 2)\n else:\n return litres*(price_per_litre)", "def fuel_price(l, p):\n return round(l*(p-min(0.05*(l//2), 0.25)), 2)", "def fuel_price(litres, price_per_litre):\n return round(litres*(price_per_litre-min(0.05*(litres//2), 0.25)), 2)", "def fuel_price(litres, price_per_litre):\n if litres < 2:\n price = litres * price_per_litre\n elif litres < 4:\n price = litres * (price_per_litre - 0.05)\n elif litres < 6:\n price = litres * (price_per_litre - 0.1)\n elif litres < 8:\n price = litres * (price_per_litre - 0.15)\n elif litres < 10:\n price = litres * (price_per_litre - 0.2)\n else:\n price = litres * (price_per_litre - 0.25)\n return round(price, 2)", "def fuel_price(litres, price_per_liter):\n if litres<2:\n price = litres * price_per_liter\n elif litres<4: \n price = litres * (price_per_liter -0.05)\n elif litres<6: \n price = litres * (price_per_liter -0.1)\n elif litres<8: \n price = litres * (price_per_liter -0.15)\n elif litres<10: \n price = litres * (price_per_liter -0.2)\n else: \n price = litres * (price_per_liter -0.25) \n return round(price,2) ", "def fuel_price(litres, price_per_litre):\n if litres <2:\n return round(litres*price_per_litre, 2)\n elif 2<=litres < 4: \n total_cost = litres*(price_per_litre - 0.05)\n elif 4 <= litres < 6:\n total_cost = litres*(price_per_litre - 0.10)\n elif 6 <= litres <8:\n total_cost = litres*(price_per_litre - 0.15)\n elif 8 <= litres < 10:\n total_cost = litres*(price_per_litre - 0.2)\n else:\n total_cost = litres*(price_per_litre - 0.25)\n return round(total_cost, 2)\n \n \n", "def fuel_price(litres, price_per_litre):\n return litres * max(price_per_litre-.25, price_per_litre-.05*(litres//2))", "def fuel_price(litres, price_per_litre):\n print(litres, price_per_litre)\n suma = litres * price_per_litre\n if litres >= 2 and litres < 4:\n return round(suma - (0.05 * litres), 2)\n if litres >= 4 and litres < 6:\n return round(suma - (0.10 * litres), 2)\n if litres >= 6 and litres < 8:\n return round(suma - (0.15 * litres), 2)\n if litres >= 8 and litres < 10:\n return round(suma - (0.20 * litres), 2)\n if litres >= 10:\n return round(suma - (0.25 * litres), 2)", "def fuel_price(litres, price):\n if litres <2:\n return round(litres * price, 2)\n elif litres <4:\n return round(litres * (price-0.05),2)\n elif litres <6:\n return round(litres * (price-0.1),2)\n elif litres <8:\n return round(litres * (price-0.15),2)\n elif litres <10:\n return round(litres * (price-0.2),2)\n else:\n return round(litres * (price-0.25),2)", "def fuel_price(litres, price_per_litre):\n discount = min(litres // 2 * 5, 25) * 0.01\n return round(litres * (price_per_litre - discount), 2)\n", "def fuel_price(litres, price_per_liter):\n if litres>=5:\n return round(litres*(price_per_liter-0.25),2)\n", "def fuel_price(litres, price_per_liter):\n\n if litres >=2 and litres < 4:\n cost = (price_per_liter - 0.05) * litres\n elif litres >= 4 and litres < 6:\n cost = (price_per_liter - 0.10) * litres\n elif litres >= 6 and litres < 8:\n cost = (price_per_liter - 0.15) * litres\n elif litres >= 8 and litres < 10:\n cost = (price_per_liter - 0.20) * litres\n else: \n cost = (price_per_liter - 0.25) * litres\n return round(cost, 2)", "def fuel_price(litres, price_per_liter):\n if litres<=1:\n return price_per_liter*litres\n dis=(litres//2)*0.05\n if dis<=0.25:\n return round(litres*(price_per_liter-dis),2)\n else:\n return round(litres*(price_per_liter-0.25),2)", "def fuel_price(litres, price_per_liter):\n if 0 < litres < 2:\n return round(litres*price_per_liter,2)\n elif 2 <= litres < 4:\n return round(litres*(price_per_liter-0.05),2)\n elif 4 <=litres < 6:\n return round(litres*(price_per_liter-0.10),2)\n elif 6 <=litres < 8:\n return round(litres*(price_per_liter-0.15),2)\n elif 8 <=litres < 10:\n return round(litres*(price_per_liter-0.20),2)\n elif litres >= 10:\n return round(litres*(price_per_liter-0.25),2)\n", "def fuel_price(litres, price_per_liter):\n d = litres // 2 * 0.05 if litres <= 10 else 0.25\n return round(litres * (price_per_liter - d), 2)", "def fuel_price(litres, price_per_liter):\n litres_div2 = litres // 2\n if litres_div2 <= 5:\n return round(litres * (price_per_liter - litres_div2*.05), 2)\n discount = 2.5 + (litres - 10)*.25\n return round(litres * price_per_liter - discount, 2)", "def fuel_price(liters, price_per_liter):\n if liters == 0:\n return price_per_liter\n else:\n if liters>=10: return round(liters*(price_per_liter-0.25),2)\n if liters>=8: return round(liters*(price_per_liter-0.20),2)\n if liters>=6: return round(liters*(price_per_liter-0.15),2)\n if liters>=4: return round(liters*(price_per_liter-0.10),2)\n if liters>=2: return round(liters*(price_per_liter-0.5),2)\n else: round(liters*price_per_liter,2)", "def fuel_price(litres, price_per_liter):\n if litres < 2:\n price_per_liter = price_per_liter\n return round(litres*price_per_liter,2)\n if litres < 4:\n price_per_liter = price_per_liter-0.05\n return round(litres*price_per_liter,2)\n if litres < 6:\n price_per_liter = price_per_liter-0.1\n return round(litres*price_per_liter,2)\n if litres < 8:\n price_per_liter = price_per_liter-0.15\n return round(litres*price_per_liter,2)\n if litres < 10:\n price_per_liter = price_per_liter-0.2\n return round(litres*price_per_liter,2)\n else:\n price_per_liter = price_per_liter-0.25\n return round(litres*price_per_liter,2) ", "def fuel_price(litres, price_per_liter):\n price_per_liter -= min(0.25, 0.05 * (litres // 2))\n \n return round(litres * price_per_liter, 2)", "def fuel_price(litres, price_per_liter):\n return litres*price_per_liter-min(0.05*(litres//2),0.25)*litres", "def fuel_price(litres, price_per_liter):\n discount = [0, 0.05, 0.1, 0.15, 0.20, 0.25]\n try:\n sale = discount[litres // 2]\n except IndexError:\n sale = max(discount)\n return litres * price_per_liter - litres * sale", "def fuel_price(litres, price_per_liter):\n dis = list(range(0,26,5))[::-1]\n l = list(range(0,11,2))[::-1]\n \n for i in range(len(l)):\n if litres >= l[i]:\n return round(litres * (price_per_liter - dis[i]/100),2) ", "def fuel_price(litres, price_per_liter):\n if 2 <= litres < 4:\n return round(litres * (price_per_liter - 0.05),2)\n if 4 <= litres < 6:\n return round(litres * (price_per_liter - 0.1),2)\n if 6 <= litres < 8:\n return round(litres * (price_per_liter - 0.15),2)\n if 8 <= litres < 10:\n return round(litres * (price_per_liter - 0.2),2)\n if 10 <= litres:\n return round(litres * (price_per_liter - 0.25),2)\n else:\n return round(litres * price_per_liter,2)", "def fuel_price(litres, price_per_liter):\n return round(litres * (price_per_liter - .05 * min(litres // 2, 5)), 2)", "def fuel_price(litres, price_per_liter):\n price_per_liter_with_discount = price_per_liter\n i = 2\n \n while i <= 10:\n if litres >= i:\n price_per_liter_with_discount -= 0.05\n \n i += 2\n \n return round(litres * price_per_liter_with_discount, 2)", "def fuel_price(l, p):\n return l*(p - [0, 0.05, 0.10, 0.15, 0.20, 0.25][(l>=2)+(l>=4)+(l>=6)+(l>=8)+(l>=10)])", "def fuel_price(litres, price_per_liter):\n if litres >= 10:\n price = litres * (price_per_liter - 0.25)\n else:\n price = litres * (price_per_liter - 0.05 * (litres // 2))\n return round(price, 2)", "def fuel_price(litres, price_per_liter):\n discount = [0.0, 0.05, 0.1, 0.15, 0.2, 0.25][(litres >= 2) + (litres >= 4) + (litres >= 6) + (litres >= 8) + (litres >= 10)]\n return litres * price_per_liter - discount * litres", "def fuel_price(litres, price_per_liter):\n discount_per_liter = min((litres // 2) * 0.05, 0.25)\n return litres * price_per_liter - litres * discount_per_liter\n", "def fuel_price(litres, price_per_liter):\n disc = litres // 2\n tot_disc = 0\n if disc >= 5:\n tot_disc = 0.25\n else:\n tot_disc = disc * .05\n return round(litres * (price_per_liter - tot_disc),2)", "def fuel_price(litres, price_per_liter):\n return litres * (price_per_liter - (0.01* (5*litres/2 if litres % 2 == 0 else 5*(litres -1)/2) if litres <=10 else 0.25))", "def fuel_price(litres, price_per_liter):\n num_of_discounts = 0\n while num_of_discounts < litres and num_of_discounts < 10:\n price_per_liter -= 0.05\n num_of_discounts += 2\n return round(price_per_liter * litres, 2)", "def fuel_price(litres, price_per_liter):\n return round(litres*(price_per_liter-(min(25, (litres/2)*5)/100)), 2)\n", "def fuel_price(litres, price_per_liter):\n discounted = 0\n if litres < 2:\n return round(litres * price_per_liter, 2)\n elif litres >= 2 and litres < 4:\n discounted = price_per_liter - 0.05\n return round(discounted * litres, 2)\n elif litres >= 4 and litres < 6:\n discounted = price_per_liter - 0.10\n return round(discounted * litres, 2)\n elif litres >= 6 and litres < 8:\n discounted = price_per_liter - 0.15\n return round(discounted * litres, 2)\n elif litres >= 8 and litres < 10:\n discounted = price_per_liter - 0.20\n return round(discounted * litres, 2)\n else:\n discounted = price_per_liter - 0.25\n return round(discounted * litres, 2)\n \n \n \n \n", "def fuel_price(litres, price_per_liter):\n discount = 0\n if(litres >= 2):\n discount = 0.05\n if(litres >= 4):\n discount = 0.1\n if(litres >= 6):\n discount = 0.15\n if(litres >= 8):\n discount = 0.2\n if(litres >= 10):\n discount = 0.25\n total = litres * price_per_liter - litres * discount\n return total", "import math\ndef fuel_price(litres, price_per_liter):\n dis = math.floor(litres/2)*.05 if math.floor(litres/2)*.05 <= .25 else .25\n return round((price_per_liter-dis) * litres,2)", "def fuel_price(liters, price):\n if liters < 2:\n return liters * price\n elif liters < 4:\n return liters * (price - 0.05)\n elif liters < 6:\n return liters * (price - 0.10)\n elif liters < 8:\n return liters * (price - 0.15)\n elif liters < 10:\n return liters * (price - 0.20)\n else:\n return liters * (price - 0.25)", "def fuel_price(litres, price):\n if litres < 2:\n return litres * price\n elif litres < 4:\n return litres * (price - .05) \n elif litres < 6:\n return litres * (price - 0.1)\n elif litres < 8:\n return litres * (price - 0.15)\n elif litres < 10:\n return litres * (price - 0.20)\n else:\n return litres * (price - 0.25)", "def fuel_price(l, price):\n if l < 2:\n return l * price\n elif l < 4:\n return l * (price - .05)\n elif l < 6:\n return l * (price - 0.10)\n elif l < 8:\n return l * (price - 0.15)\n elif l < 10:\n return l * (price - 0.20)\n else:\n return l * (price - 0.25)\n \n", "def fuel_price(litres, price):\n if litres < 2:\n return litres * price\n elif litres < 4:\n return litres * (price - .05)\n elif litres < 6:\n return litres * (price - .10)\n elif litres < 8:\n return litres * (price - .15)\n elif litres < 10:\n return litres * (price - .20)\n else:\n return litres * (price - .25)\n", "def fuel_price(litres, price_per_liter):\n discount = litres//2*0.05\n discount = 0.25 if discount>=0.25 else discount\n return round(litres*(price_per_liter-discount), 2)", "def fuel_price(litres, price_per_liter):\n return round(litres * max(price_per_liter - 0.25, price_per_liter - 0.05 * (litres//2)), 2)\n", "import math \n\ndef fuel_price(litres, price_per_liter):\n \n if litres < 2 :\n return litres * price_per_liter\n \n discount = 0.05 * (math.floor(litres / 2))\n \n if discount > 0.25 :\n discount = 0.25\n \n return litres * (price_per_liter - discount)\n", "def fuel_price(litres, price_per_liter):\n if litres < 2:\n price = litres * price_per_liter;\n elif litres < 4:\n price = litres * (price_per_liter - 0.05);\n elif litres < 6:\n price = litres * (price_per_liter - 0.10);\n elif litres < 8:\n price = litres * (price_per_liter - 0.15);\n elif litres < 10:\n price = litres * (price_per_liter - 0.20);\n else:\n price = litres * (price_per_liter - 0.25);\n return round(price, 2)", "def fuel_price(litres, price):\n discount = litres/4 if litres >= 10 else litres * (litres//2 * 5)/100\n return price*litres - discount", "def fuel_price(l, ppl):\n if l<2:\n return l*ppl\n elif l<4:\n return l*ppl-0.05*l\n elif l<6:\n return l*ppl-0.10*l\n elif l<8:\n return l*ppl-0.15*l\n elif l<10:\n return l*ppl-0.20*l\n return l*ppl-0.25*l", "def fuel_price(litres, price_per_liter):\n discount = 0\n if 2 <= litres < 4:\n discount = 0.05\n elif 4 <= litres < 6:\n discount = 0.10\n elif 6 <= litres <= 8:\n discount = 0.20\n elif 8 < litres:\n discount = 0.25\n \n print(litres, price_per_liter, discount)\n \n return litres * price_per_liter - litres * discount", "def fuel_price(l, ppl):\n if(l >= 10):\n ppl -= .25 \n return round(l * ppl, 2)\n elif(l >= 8):\n ppl -= .20\n return round(l * ppl, 2)\n elif(l >= 6):\n ppl -= .15\n return round(l * ppl, 2)\n elif(l >= 4):\n ppl -= .10\n return round(l * ppl, 2)\n elif(l >= 2):\n ppl -= .05\n return round(l * ppl, 2)\n return round(l * ppl, 2)", "def fuel_price(litres, price_per_liter):\n if 2 <= litres < 4: #if liters are more than 2 and less than 4\n return round(litres*(price_per_liter - 0.05), 2) #return price minus 5 cents/0.05\n if 4 <= litres < 6: #if liters are more or equal 4 and less than 6\n return round(litres*(price_per_liter - 0.1), 2) #return price minus 10 cents/0.10\n if 6 <= litres < 8: #if liters are more or equal 6 and less than 8\n return round(litres*(price_per_liter - 0.15), 2) #return price minus 15 cents/0.15\n if 8 <= litres < 10: #if liters are more or equal 8 and less than 10\n return round(litres*(price_per_liter - 0.2), 2) #return price minus 20 cents/0.20\n if litres >= 10: #if liters are more or equal 10\n return round(litres*(price_per_liter - 0.25), 2) #return price minus 25 cents/0.25", "def fuel_price(litres, price_per_liter):\n if 0<litres<=10:\n p=(0.05*(litres//2))\n else:\n p=0.25\n return litres*price_per_liter - litres*p", "def fuel_price(litres, price_per_liter):\n if 2 <= litres < 4:\n return round(litres*(price_per_liter - 0.05), 2)\n if 4 <= litres < 6:\n return round(litres*(price_per_liter - 0.1), 2)\n if 6 <= litres < 8:\n return round(litres*(price_per_liter - 0.15), 2)\n if 8 <= litres < 10:\n return round(litres*(price_per_liter - 0.2), 2)\n if litres >= 10:\n return round(litres*(price_per_liter - 0.25), 2)\n", "def fuel_price(litres, price_per_liter):\n if 0 < litres < 2:\n return price_per_liter * litres\n elif 4 > litres >=2:\n return round((price_per_liter - .05) * litres,2)\n elif 6 > litres >=4:\n return round((price_per_liter - .10) * litres,2)\n elif 8 > litres >=6:\n return round((price_per_liter - .15) * litres,2)\n elif 10 > litres >=8:\n return round((price_per_liter - .20) * litres,2)\n elif litres >= 10:\n return round((price_per_liter - .25) * litres,2) ", "def fuel_price(l, p):\n return l*p - l*min(.25, (l//2)*5*.01)", "def fuel_price(litres, price_per_liter):\n resultat = 0\n if litres < 2:\n resultat = litres * price_per_liter \n elif litres < 4:\n resultat = litres * (price_per_liter - 0.05)\n elif litres < 6:\n resultat = litres * (price_per_liter - 0.10)\n elif litres < 8:\n resultat = litres * (price_per_liter - 0.15)\n elif litres < 10:\n resultat = litres * (price_per_liter - 0.20)\n else:\n resultat = litres * (price_per_liter - 0.25)\n \n return float(\"{0:.2f}\".format(resultat))", "def fuel_price(litres, price_per_liter):\n if litres >= 10:\n price_per_liter -= 0.25\n return round(litres * price_per_liter, 2)\n elif litres >= 8:\n price_per_liter -= 0.20\n return round(litres * price_per_liter, 2)\n elif litres >= 6:\n price_per_liter -= 0.15\n return round(litres * price_per_liter, 2)\n elif litres >= 4:\n price_per_liter -= 0.10\n return round(litres * price_per_liter, 2)\n elif litres >= 2:\n price_per_liter -= 0.05\n return round(litres * price_per_liter, 2)\n elif litres < 2:\n return round(litres * price_per_liter, 2)", "def fuel_price(litres, price_per_liter):\n raw_discount = 0.05 * (litres/2)\n discount = 0.25 if raw_discount > 0.25 else raw_discount\n return round(litres * (price_per_liter - discount), 2)\n", "def fuel_price(litres, price_per_liter):\n discount = litres // 2 * 0.05 if litres // 2 < 6 else 0.25\n return price_per_liter * litres - discount * litres", "def fuel_price(litres, price_per_liter):\n print((litres, price_per_liter, '\\n')) \n for i, discount in enumerate (range(0, 25, 5)):\n print(((i+1)*2,discount/100)) \n if litres < (i+1)*2: return (price_per_liter - discount/100) * litres\n return (price_per_liter - (discount+5)/100) * litres\n", "def fuel_price(litres, price_per_liter):\n discount_price = 0.05 * (litres // 2)\n if discount_price > 0.25:\n discount_price = 0.25\n return round(litres * (price_per_liter - discount_price), 2)", "def fuel_price(litres, price_per_liter):\n discount = (litres // 2 * 0.05)\n discount = discount if discount <= 0.25 else 0.25\n return round(litres * price_per_liter - (litres * discount), 2)", "def fuel_price(litres, price_per_liter):\n if litres>=2 and litres<4:\n price_per_liter = price_per_liter - 0.05\n elif litres>=4 and litres<6 :\n price_per_liter = price_per_liter - 0.10\n elif litres>=6 and litres<8 :\n price_per_liter = price_per_liter - 0.15\n elif litres>=8 and litres<10 :\n price_per_liter = price_per_liter - 0.20\n elif litres>=10 :\n price_per_liter = price_per_liter - 0.25\n return litres*price_per_liter", "def fuel_price(litres, price_per_liter):\n if litres>=10: return round(litres * (price_per_liter - 0.25),2)\n if litres>=8: return round(litres * (price_per_liter - 0.20),2)\n if litres>=6: return round(litres * (price_per_liter - 0.15),2)\n if litres>=4: return round(litres * (price_per_liter - 0.10),2)\n if litres>=2: return round(litres * (price_per_liter - 0.05),2)\n if litres<2: return round(litres * price_per_liter, 2)\n \n \n \n \n \n", "def fuel_price(litres, price_per_liter):\n if litres >= 2 :d = litres * 0.05\n if litres >= 4 :d = litres * 0.10\n if litres >= 6 :d = litres * 0.15\n if litres >= 8 :d = litres * 0.20\n if litres >= 10 :d = litres * 0.25\n \n return litres * price_per_liter - d", "def fuel_price(l,p):\n \"\"\" Candian Gas Sale\"\"\"\n return round(l*(p-(l//2 *.05)),2) if l <12 else round(l*(p-.25) ,2)\n", "def fuel_price(litres, price_per_liter):\n price=price_per_liter*litres\n if litres>=10:\n price=price-(litres*0.25)\n elif litres>=8:\n price=price-(litres*0.20)\n elif litres>=6:\n price=price-(litres*0.15)\n elif litres>=4:\n price=price-(litres*0.10)\n elif litres>=2:\n price=price-(litres*0.05)\n else:\n return price\n return price\n", "def fuel_price(litres, price_per_liter):\n if litres >= 10: return litres*(price_per_liter-0.25)\n if litres >= 8: return litres*(price_per_liter-0.20)\n if litres >= 6: return litres*(price_per_liter-0.15)\n if litres >= 4: return litres*(price_per_liter-0.10)\n if litres >= 2: return litres*(price_per_liter-0.05)", "def fuel_price(litres, price_per_liter):\n return litres*(price_per_liter-0.25) if litres >= 10 else litres*(price_per_liter-0.10) if litres >= 4 else litres*(price_per_liter-0.05)", "def fuel_price(litres, price_per_liter):\n if 2 <= litres < 4:\n price_per_liter -= 0.05\n elif 4 <= litres < 6:\n price_per_liter -= 0.10\n elif 6 <= litres < 8:\n price_per_liter -= 0.15\n elif 8 <= litres < 10:\n price_per_liter -= 0.20\n elif litres >= 10:\n price_per_liter -= 0.25\n\n return round(litres * price_per_liter, 2)", "def fuel_price(litres, price_per_liter):\n print(litres, price_per_liter)\n return litres * price_per_liter - min((litres // 2) * 0.05, 0.25) * litres", "def fuel_price(litres, price_per_liter):\n return round(litres * (price_per_liter - {0: 0, 1: .05, 2: .10, 3: .15, 4: .20}.get(litres // 2, .25)), 2)", "def fuel_price(litres, price_per_liter):\n #your code here\n disc=litres//2*0.05\n if disc>0.25:\n disc=0.25\n price_per_liter-=disc\n total=price_per_liter*litres\n return round(total,2)\n"] | {"fn_name": "fuel_price", "inputs": [[10, 21.5], [40, 10], [15, 5.83]], "outputs": [[212.5], [390], [83.7]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 31,507 |
def fuel_price(litres, price_per_liter):
|
c9bd8772b5dacbeb3795c87ee560998b | UNKNOWN | ## The Riddle
The King of a small country invites 1000 senators to his annual party. As a tradition, each senator brings the King a bottle of wine. Soon after, the Queen discovers that one of the senators is trying to assassinate the King by giving him a bottle of poisoned wine. Unfortunately, they do not know which senator, nor which bottle of wine is poisoned, and the poison is completely indiscernible.
However, the King has 10 lab rats. He decides to use them as taste testers to determine which bottle of wine contains the poison. The poison when taken has no effect on the rats, until exactly 24 hours later when the infected rats suddenly die. The King needs to determine which bottle of wine is poisoned by tomorrow, so that the festivities can continue as planned.
Hence he only has time for one round of testing, he decides that each rat tastes multiple bottles, according to a certain scheme.
## Your Task
You receive an array of integers (`0 to 9`), each of them is the number of a rat which died after tasting the wine bottles. Return the number of the bottle (`1..1000`) which is poisoned.
**Good Luck!**
*Hint: think of rats as a certain representation of the number of the bottle...* | ["def find(r):\n return sum(2**i for i in r)", "def find(rats):\n \"\"\"\n The rule the king should use is the following:\n 1) Label all bottle from 1 to 1000\n 2) Label all rats from 0 to 9\n 3) For each rat r, make it drink the bottle b if the binary representation of b has it's rth bit\n is one.\n Reconstruct the label of the poisonned bottle by computing the base-10 representation:\n \"\"\"\n return sum(map(lambda x: pow(2,x), rats))", "def find(r):\n return sum(1<<d for d in r)", "def find(r):\n return sum([pow(2,a) for a in r]) \n \n \n \n \n \n \n\n", "def find(r):\n # Your code here\n a=['0','0','0','0','0','0','0','0','0','0']\n for i in r:\n a[i]='1'\n a.reverse()\n b=\"\".join(a)\n return int(b,2)", "find=lambda r:sum(1<<i for i in r)", "def find(a):\n return sum(1 << x for x in a)", "def find(r):\n dict = {i: 2**i for i in range(10)}\n return sum(dict.get(y) for y in r)", "def find(r):\n return sum(2 ** e for e in r)", "def find(r):\n x = ''.join(['1' if i in r else '0' for i in range(9, -1, -1)])\n return int(x, 2)"] | {"fn_name": "find", "inputs": [[[0]], [[1]], [[2]], [[3]], [[4]], [[5]], [[6]], [[7]], [[8]], [[9]], [[3, 5, 6, 7, 8, 9]], [[0, 3, 5, 4, 9, 8]], [[0, 1, 9, 3, 5]], [[0, 1, 2, 3, 4, 6]], [[0, 1, 3, 4]]], "outputs": [[1], [2], [4], [8], [16], [32], [64], [128], [256], [512], [1000], [825], [555], [95], [27]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,164 |
def find(r):
|
d709b40f6e5688ed65baf7af6e683a04 | UNKNOWN | We have the numbers with different colours with the sequence: ['red', 'yellow', 'blue'].
That sequence colours the numbers in the following way:
1 2 3 4 5 6 7 8 9 10 11 12 13 .....
We have got the following recursive function:
```
f(1) = 1
f(n) = f(n - 1) + n
```
Some terms of this sequence with their corresponding colour are:
```
term value colour
1 1 "red"
2 3 "blue"
3 6 "blue"
4 10 "red"
5 15 "blue"
6 21 "blue"
7 28 "red"
```
The three terms of the same colour "blue", higher than 3, are: `[6, 15, 21]`
We need a function `same_col_seq(), that may receive three arguments:
- `val`, an integer number
- `k`, an integer number
- `colour`, the name of one of the three colours(red, yellow or blue), as a string.
The function will output a sorted array with the smallest `k` terms, having the same marked colour, but higher than `val`.
Let's see some examples:
```python
same_col_seq(3, 3, 'blue') == [6, 15, 21]
same_col_seq(100, 4, 'red') == [136, 190, 253, 325]
```
The function may output an empty list if it does not find terms of the sequence with the wanted colour in the range [val, 2* k * val]
```python
same_col_seq(250, 6, 'yellow') == []
```
That means that the function did not find any "yellow" term in the range `[250, 3000]`
Tests will be with the following features:
* Nmber of tests: `100`
* `100 < val < 1000000`
* `3 < k < 20` | ["D, R = {}, [[], [], []]\nfor i in range(10000):\n D[i] = D.get(i - 1, 0) + i\n R[D[i]%3].append(D[i])\n \ndef same_col_seq(val, k, col):\n r = ['blue', 'red', 'yellow'].index(col)\n return [e for e in R[r] if e > val][:k] ", "def same_col_seq(val, k, col):\n colDct = {'red': 1, 'blue': 0}\n\n def gen():\n n = ((1 + 24*val/3)**.5 - 1)//2\n while True:\n n += 1\n s = n*(n+1)/2\n if s%3 == colDct[col]: yield s\n \n g = gen()\n return [next(g) for _ in range(k)] if col != 'yellow' else []", "def same_col_seq(val, k, col):\n if col == 'yellow': return []\n \n n = int((2*val)**0.5)-1\n while n*(n+1) <= 2*val: n+= 1\n \n values = []\n \n while len(values) < k:\n if col == 'blue' and (n-1)%3 != 0:\n values.append(n*(n+1)//2)\n if col == 'red' and (n-1)%3 == 0:\n values.append(n*(n+1)//2)\n n+=1\n \n return values", "li, i, pos, d = ['red', 'yellow', 'blue'], 1, 1, {}\nwhile i < 2000:\n d[pos] = li[(pos - 1) % 3]\n i += 1 ; pos += i\ndef same_col_seq(after, k, need):\n req, status = [], 0\n for i, j in d.items():\n if i > after : status = 1\n if status:\n if j == need : req.append(i)\n if len(req) == k or i >= 2 * k * after : break\n return req", "same_col_seq=lambda x,k,c:(lambda n,m:[i*-~i//2for i in range(n,n+3*k)if i%3%2==m][:k])(int((8*x+1)**.5+1)//2,'br'.find(c[0]))", "def same_col_seq(val, k, col):\n n_start = int(((1 + 8 * val)**0.5 - 1) / 2) + 1\n def f(n):\n return (1 + n) * n // 2\n def get_col(n):\n return 'red' if n % 3 == 1 else 'blue'\n return [f(n) for n in range(n_start, n_start + 62) if col==get_col(n)][:k]\n", "from bisect import bisect_right\n\ndef same_col_seq(val, k, col, seq=[], colors=[]):\n if not seq:\n color = lambda v: {0: 'blue', 1: 'red', 2: 'yellow'}[v % 3]\n next_val = lambda n: seq[-1] + n\n seq.append(1)\n colors.append('red')\n n = 2\n v = next_val(n)\n while True:\n seq.append(v)\n colors.append(color(v))\n if v > 40 * 10 ** 6:\n break\n n += 1\n v = next_val(n)\n res = []\n index = find_gt(seq, val)\n limit = val * 2 * k\n while True:\n if colors[index] == col:\n res.append(seq[index])\n if len(res) == k:\n break\n if seq[index] > limit and len(res) == 0:\n break\n index += 1\n return res\n\ndef find_gt(a, x):\n return bisect_right(a, x)", "def same_col_seq(val, k, col):\n results = []\n term = 1\n while values(term) <= val:\n term += 1\n while len(results) < k:\n if colors(values(term)) == col:\n results.append(values(term))\n elif values(term) >= (2*k*val) and len(results) == 0:\n return []\n term += 1\n return results\n\ndef values(term):\n if term % 2 == 0:\n return int(((term / 2) * term) + (term / 2))\n else:\n return int((((term + 1) / 2) * term))\n \ndef colors(term):\n if term % 3 == 0:\n return 'blue'\n else:\n return 'red'", "def same_col_seq(val, k, col):\n # your code here\n code ={'blue':0,'red':1,'yellow':2}\n result =[]\n limit = 2 * k * val \n term = 1\n temp = 1\n while(temp <= val):\n temp = temp + term + 1\n term +=1\n \n while(True):\n if(temp % 3 == code[col]):\n result.append(temp)\n temp = temp + term + 1\n term +=1\n \n if(len(result)>= k ):\n break\n if(len(result) == 0 and temp>=limit):\n return [] \n\n return result", "import math\n\ndef same_col_seq(val, k, col):\n colors = [\"red\", \"yellow\", \"blue\"]\n m = colors.index(col)\n res = list()\n x0 = math.floor((-1 + math.sqrt(1 + 8 * val)) / 2)\n s = x0 * (1 + x0) // 2\n i = x0 + 1\n while len(res) < k:\n if (s+2) % 3 == m and s > val:\n res.append(s)\n s += i\n i += 1\n if s > 3 * k * val:\n break\n return res"] | {"fn_name": "same_col_seq", "inputs": [[3, 3, "blue"], [100, 4, "red"], [250, 6, "yellow"], [1000, 7, "red"]], "outputs": [[[6, 15, 21]], [[136, 190, 253, 325]], [[]], [[1081, 1225, 1378, 1540, 1711, 1891, 2080]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,260 |
def same_col_seq(val, k, col):
|
314e371073285374085dc3db0fe774d9 | UNKNOWN | Given the triangle of consecutive odd numbers:
```
1
3 5
7 9 11
13 15 17 19
21 23 25 27 29
...
```
Calculate the row sums of this triangle from the row index (starting at index 1) e.g.:
```python
row_sum_odd_numbers(1); # 1
row_sum_odd_numbers(2); # 3 + 5 = 8
```
```if:nasm
row_sum_odd_numbers:
``` | ["def row_sum_odd_numbers(n):\n #your code here\n return n ** 3", "def row_sum_odd_numbers(n):\n if type(n)==int and n>0:\n return n**3\n else:\n return \"Input a positive integer\"", "def row_sum_odd_numbers(n):\n return n*n*n", "def row_sum_odd_numbers(n):\n return pow(n, 3)", "def row_sum_odd_numbers(n):\n #your code here\n a,b = n*(n-1)+1,n*(n+1)\n return sum(range(a,b,2)) if a != 1 else 1\n", "def row_sum_odd_numbers(n):\n return sum(range(n*(n-1)+1, n*(n+1), 2))", "def row_sum_odd_numbers(n):\n # sum of numbers in each row equals number of the row to the power of 3\n return n**3", "def row_sum_odd_numbers(n, base=2):\n first_num = (n * (n - 1)) + 1\n numbers = range(first_num, first_num + base * n, base)\n return sum(numbers)", "def row_sum_odd_numbers(n):\n sum = 0\n num = n * n + n - 1\n for i in range(n):\n sum += num\n num -= 2\n return sum", "row_sum_odd_numbers = lambda n: n ** 3", "def row_sum_odd_numbers(n):\n #your code here\n x = []\n for i in range(1,n*n+n,2):\n x.append(i)\n return sum(x[-n:])\n", "def row_sum_odd_numbers(n):\n #your code here\n m = ( n - 1 ) * n + 1\n o = m\n while n > 1 :\n m = m + 2\n o = o + m\n n = n - 1\n return o", "def row_sum_odd_numbers(n):\n prev = 1\n ll = [y*[0] for y in range(1, n+1)]\n for x in ll:\n for i in range(len(x)):\n x[i] = prev\n prev += 2\n return sum(ll[-1])", "def row_sum_odd_numbers(n):\n return sum([i for i in range(sum([i for i in range(1, n+1)])*2) if i % 2][:-n-1:-1])\n", "def row_sum_odd_numbers(n):\n sum, sum2, h, k, i, s1, s2 = 0, 0, n-1, -1, 0, 0, 0\n while n != 0:\n sum += n\n n -= 1\n while h != 0:\n sum2 += h\n h -= 1\n while i <= sum-1:\n if i == sum2:\n s2 = s1\n k += 2\n s1 += k\n i += 1\n return s1 - s2", "def row_sum_odd_numbers(n):\n a = [y*[False] for y in range(1, n+1)]\n odds = iter(list(range(1, 10**6, 2)))\n return sum([[next(odds) for c in x if c is False] for x in a][-1])", "def row_sum_odd_numbers(n):\n return n * (n + (n*(n - 1)))", "def row_sum_odd_numbers(n):\n # return (1+(n-1)*n) * n + (n-1)*(n) \n # ^ found with logic of - first digit of row * width of row * sum of recursive sequence a(n)=0,2,6,12... \n # with n starting at 0\n # simplify the polynomial expression to n^3\n # feel bad for not seeing the pattern in the first place\n return n**3", "def row_sum_odd_numbers(n):\n stop = sum(range(n + 1))\n start = sum(range(n)) + 1\n return sum(range(start + start - 1, stop + stop, 2))", "def row_sum_odd_numbers(n):\n x = 1\n r = 1\n inc = 2\n s = 0\n \n for i in range(1, n):\n x += inc\n r += 1\n inc += 2\n \n for j in range(r):\n s += x\n x += 2\n \n return s", "def row_sum_odd_numbers(n: int):\n \"\"\" Calculate the row sums of this triangle from the row index (starting at index 1). \"\"\"\n return sum([_ for _ in range(n * (n - 1), n * (n - 1) + (n * 2)) if _ % 2])\n", "def row_sum_odd_numbers(n):\n #your code here\n \n return ((n-1)**2 + n)*(n) + n*(n-1)", "def row_sum_odd_numbers(n):\n first_number = 2*(n*(n-1)/2) + 1\n return n*(first_number + n - 1)\n", "def row_sum_odd_numbers(n):\n a = n\n return a*a*a", "def row_sum_odd_numbers(row):\n total = 0\n for i in range(1, row+ 1):\n #print(i)\n total += 1 * i\n \n sum = 0\n lastInt = total * 2 - 1\n startInt = lastInt - ((row - 1) * 2) -1\n for i in range(lastInt, startInt, -2):\n sum += i\n # print(i)\n #print(f'sum {sum}')\n \n return sum\n", "row_sum_odd_numbers=lambda n: n*n*n", "row_sum_odd_numbers=(3).__rpow__", "def row_sum_odd_numbers(n):\n \n x = 1\n c = 0\n final = 0\n \n for e in range(n):\n x += c\n c += 2\n \n for d in range(n):\n final += x\n x += 2\n \n return final", "def row_sum_odd_numbers(n):\n first = n * (n - 1) + 1\n return first * n + n * (n - 1)", "def row_sum_odd_numbers(n):\n return sum([x*2 -1 for x in (list(range(((n*(n+1))//2) - n + 1, (n*(n+1)//2)+1)))])\n", "import numpy as np\ndef row_sum_odd_numbers(n):\n return sum(np.linspace(n**2-(n-1),(n**2+n-1),n))", "def row_sum_odd_numbers(n):\n \"\"\"the sum of all odd numbers in a row\n is actually the row number cubed\"\"\"\n if n < 1:\n return 0\n else:\n return n*n*n", "def row_sum_odd_numbers(n):\n start = sum(range(1,n))\n end = start + n\n return sum([ i for i in range(1,end*2,2) ][start:end])", "def row_sum_odd_numbers(n):\n formula = n**3\n return formula\n \n", "def row_sum_odd_numbers(n):\n # return (1+(n-1)*n) * n + (n-1)*(n) \n # ^ found with logic of - first digit of row * width of row + sum of recursive sequence a(n)=0,2,6,12... \n # with n starting at 0\n # simplify the polynomial expression to n^3\n # feel bad for not seeing the pattern in the first place\n return n**3", "def row_sum_odd_numbers(n):\n row_generator = generate_row(n)\n sum = 0\n for val in row_generator:\n sum += val\n return sum\n\n\ndef generate_row(i: int):\n start = i * (i - 1) + 1\n row_length = i\n for num in range(row_length):\n yield start\n start += 2", "def row_sum_odd_numbers(n):\n return sum([n for n in range(n * (n + 1)) if n % 2 != 0][-n:])", "def row_sum_odd_numbers(n):\n num_pos = find_numb_count(n)\n sum = 0\n for i in range(n):\n sum += (num_pos * 2) - 1\n num_pos -= 1\n \n return sum\n\n# Return the position of the last number in the triangle row\ndef find_numb_count(n):\n if n == 1:\n return 1\n return find_numb_count(n-1) + n", "def row_sum_odd_numbers(n):\n return sum(n*(n-1)+1+(a*2) for a in range(n))", "def row_sum_odd_numbers(n):\n if n < 1:\n return None\n return n**3", "def row_sum_odd_numbers(n):\n initial_number = n*(n-1)+1\n sum = 0\n for i in range(0, n):\n sum = sum + (initial_number + i*2)\n return sum", "def row_sum_odd_numbers(n):\n return (n*n-n+1)*(n+1)-1", "def row_sum_odd_numbers(n):\n row_start = (n-1)*n+1\n return sum([ x for x in range(row_start, row_start+n*2, 2)])", "def row_sum_odd_numbers(n):\n #your code here\n a = sum(range(1,n))*2+1\n return sum(range(a, a+n*2, 2))", "def row_sum_odd_numbers(n):\n return n ** 3 #observed this pattern for row sum", "def row_sum_odd_numbers(n):\n f = ((n * (n -1))/2) - 1\n s1 = (f+1)*(f+1)\n s2 = (f+n+1)*(f+n+1)\n return s2-s1\n", "def row_sum_odd_numbers(n):\n i = n\n numberx = 0\n while n > 0:\n numberx += n\n n -= 1\n v = numberx\n resultList = []\n result = 0\n for x in range(1, (numberx*2)+1):\n if x % 2 == 1:\n resultList.append(x)\n while v > (numberx-i):\n result += int(resultList[(v-1)])\n v -= 1\n return result", "def row_sum_odd_numbers(n):\n if n == 1: return 1\n else: \n min_odd_in_row = (n * (n - 1)) + 1\n max_odd_in_row = (n * (n + 1)) - 1\n return n * (max_odd_in_row + min_odd_in_row) / 2", "def row_sum_odd_numbers(n):\n for i in range(n):\n if n == 1:\n return n\n else:\n return n**3", "def row_sum_odd_numbers(n):\n #first of row n is (2n+1)\n \n # 1, 1 + 2, 1 + 2 + 3 --> sum_1^n n\n \n numofnums = 0\n \n for i in range(1,n+1):\n numofnums += i\n \n oddints = [2*x+1 for x in range(numofnums)]\n \n #rowlength = n\n \n \n \n return sum(oddints[-n:])\n \n", "def row_sum_odd_numbers(n):\n if n == 1:\n return 1\n my_list = list(range(1,n*(n+1),2))\n return sum(my_list[n*-1:])\n", "def row_sum_odd_numbers(n):\n #your code here\n num1 = n*(n-1)\n num1+=1\n i=0\n sum=0\n while i<n:\n num2=0\n num2=num1+(i*2)\n sum+=num2\n i+=1\n return sum", "def row_sum_odd_numbers(n):\n #your code here\n \n a=[i for i in range(n*(n+1)) if i%2!=0]\n return sum(a[:-n-1:-1])\n \n", "def row_sum_odd_numbers(n):\n start = 1\n for z in range(n):\n start += 2 * z\n sum_of_odd = 0\n for i in range(1, n + 1):\n sum_of_odd += start\n start += 2\n return sum_of_odd", "def row_sum_odd_numbers(n:int)->int:\n \"\"\"[Find the sum of a row based on odd number pyramid]\n\n Args:\n n (int): [Row Number starting from 1]\n\n Returns:\n int: [Sum of Row]\n \"\"\"\n num_of_records = n*(n+1)//2\n return sum([2*i-1 for i in range(num_of_records -n+1,num_of_records+1)])\n", "def row_sum_odd_numbers(n):\n return sum([n*(n-1)+1+2*k for k in range(n)])", "def row_sum_odd_numbers(n):\n total_nums = sum(range(0,n+1))\n num_array = []\n count = 1\n while (True): \n if(count % 2 != 0): \n num_array.append(count) \n if(len(num_array) == total_nums):\n break\n count += 1\n return sum(num_array[-n:])\n", "def row_sum_odd_numbers(n):\n counter = 0\n for i in range(1, n + 1):\n sum_list = []\n switch = 0\n while switch != i:\n if counter % 2 != 0:\n switch += 1\n sum_list.append(counter)\n counter += 1\n return sum(sum_list)", "def row_sum_odd_numbers(n):\n k = sum(range(n))\n count = 0\n start= 1 + k * 2\n sum_i = 0\n while(count < n):\n sum_i += start\n start += 2\n count += 1\n return sum_i\n", "def row_sum_odd_numbers(n):\n #your code here\n triNumber = n * (n + 1) / 2\n totalOdd = triNumber ** 2\n \n previousRow = n - 1\n \n previousTriNumber = previousRow * (previousRow + 1) / 2\n \n totalOddPrevious = previousTriNumber ** 2\n \n return totalOdd - totalOddPrevious", "def row_sum_odd_numbers(n):\n startnr = n*n-(n-1)\n sum = 0\n for i in range(startnr, startnr+n*2, 2):\n sum += i\n return sum", "def row_sum_odd_numbers(n):\n #your code here\n \n k = int((1+n)*n/2) #3\n m = int((1+n-1)*(n-1)/2) #1\n \n if(k == 1):\n return 1\n \n x = 0\n y = 0\n z = 0\n w = 0\n \n for i in range(k): \n if i == 0:\n x = 1\n else:\n x = x + 2\n z = z + x\n \n for i in range(m):\n if i == 0:\n y = 1\n else:\n y = y + 2\n w = w + y\n \n return z-w", "def row_sum_odd_numbers(n):\n num = 1\n for x in range(n):\n num = num + (2*x)\n #print(num)\n\n total = 0\n for x in range(n):\n total += num + (2*x)\n #print(total)\n return total", "def row_sum_odd_numbers(n):\n num_add = n*(n+1)/2\n last = (num_add*2)-1\n first = last + 2*(1-n)\n return (first+last)*(n/2)", "def row_sum_odd_numbers(n):\n m = (1+n)*n/2\n l = 1+(m-1)*2\n q = (1+l)*m/2\n p = (1+1+(m-n-1)*2)*(m-n)/2\n return q-p", "def row_sum_odd_numbers(n):\n x=2*(sum(list(range(1, n)))+1)-1\n num=x\n for i in range(n-1):\n num+=x+2\n x+=2\n return num\n", "def row_sum_odd_numbers(n):\n triangle = []\n odd = 1\n for row in range(n):\n triangle.append([])\n while len(triangle[row]) < row + 1:\n triangle[row].append(odd)\n odd += 2\n return (sum(triangle[n-1]))", "def row_sum_odd_numbers(n):\n return (((n * (n + 1) // 2) - n + 1) * 2 - 1) * n + ((n - 1) * (n))", "def row_sum_odd_numbers(n):\n return(n ** 3) #follows the formula of cubing the value of n as the sum of the nth row of the triangle", "def row_sum_odd_numbers(n):\n if n == 1:\n return 1\n else:\n nums = list(range(sum(range(n*2))))\n val = sum(range(n))\n return (sum(list(num for num in nums if num % 2 != 0)[val:val+n]))", "def row_sum_odd_numbers(n):\n a=0\n o=0\n e=0\n for x in range(1,n+1):\n a+=x\n for y in range(1,2*a,2):\n o+=y\n for z in range(1,2*(a-n),2):\n e+=z\n return o-e", "def row_sum_odd_numbers(n):\n #your code here \n first = 1 + (n * (n-1)) \n sum = 0\n for i in range(n):\n sum = sum + first \n first += 2\n return sum", "def row_sum_odd_numbers(n):\n row_start_num = (n-1)*n+1\n row_sum = n*row_start_num + n*(n-1)\n return row_sum \n", "def row_sum_odd_numbers(n):\n start_number = n ** 2 - (n - 1)\n sum = 0\n for i in range(n):\n sum += start_number + i * 2\n \n return sum", "def row_sum_odd_numbers(n):\n digits_counter = sum(range(n+1))\n triangle_content = []\n while len(triangle_content) != digits_counter:\n for i in range(digits_counter * 2 + 1):\n if i % 2 == 1:\n triangle_content.append(i)\n final_sum = 0\n for digit in triangle_content[len(triangle_content) - n:]:\n final_sum += digit\n return final_sum", "def row_sum_odd_numbers(n):\n lenth = n\n counter=0\n while n>0:\n print((n, counter))\n counter+=n\n n-=1\n return (sum(range(1, counter*2, 2)[-lenth:]))\n #your code here\n", "def row_sum_odd_numbers(num_line):\n sum_permid = 0\n first_line = num_line*(num_line-1)+1\n stop_line = first_line + (num_line) * 2 \n for j in range(first_line,stop_line,2):\n sum_permid += j\n return sum_permid \n#your code here\n", "def row_sum_odd_numbers(n):\n min = n**2 - n + 1\n max = n**2 + n - 1\n sum = 0\n while min <= max:\n if min%2==1:\n sum = sum + min\n min += 2\n return sum", "def row_sum_odd_numbers(n):\n start = n**2 - n + 1\n stop = start + n * 2\n return sum(x for x in range(start, stop, 2))", "def row_sum_odd_numbers(n):\n count = 0\n kokosik = 1\n result = 0\n for huesosina in range(0, n):\n kokosik += count\n count += 2\n result += kokosik\n for guccigang in range(0, n - 1): \n kokosik += 2\n result += kokosik\n return result", "def row_sum_odd_numbers(n):\n #your code here\n first_num = 1+n*(n-1)\n last_num = first_num + 2*(n-1)\n new_list = [x for x in range(first_num, last_num+1) if (x+1)%2 == 0]\n return sum(new_list)", "def row_sum_odd_numbers(n):\n c = 0\n for i in range(n + 1):\n c += i\n if c > 1:\n index = 1\n a = []\n for j in range(c):\n a.append(index)\n index += 2\n s = 0\n e = c - n\n while c != e:\n s += a[c - 1]\n c -= 1\n return s\n else:\n return n\n \n \n \n \n", "def row_sum_odd_numbers(n):\n start = 0\n sum = 0\n for i in range(n-1):\n start += i + 1\n start = start*2+1\n for i in range(n):\n sum += start\n start += 2\n return sum", "def row_sum_odd_numbers(n):\n # Summation of each row\n return sum(range(n*(n-1)+1, n*(n+1), 2))", "def row_sum_odd_numbers(n):\n #your code here\n \n starting_no = 1 + sum([2*i for i in range (0, n)])\n \n return sum([starting_no + 2*i for i in range(0, n)])", "def row_sum_odd_numbers(n):\n #your code here\n s = 0\n a1 = 1 + n * (n - 1)\n for i in range(n):\n s += a1\n a1 += 2\n return s", "def row_sum_odd_numbers(n):\n# sum 1st n odd = n*n\n if(n==0):\n return 0\n last_odd = n*(n+1)/2\n prev_last_odd = (n-1)*n/2\n return last_odd*last_odd - prev_last_odd *prev_last_odd", "def row_sum_odd_numbers(n):\n row,x = [],0\n while x < n:\n row.append(n*(n-1)+1+2*x)\n x+=1\n return sum(row)\n", "def row_sum_odd_numbers(n):\n counter = 0\n start_number = 1\n end_number = 1\n sum_ = 1\n for i in range(n-1):\n start_number += counter + 2\n end_number += counter + 4\n sum_ = sum([x for x in range(start_number, end_number+2) if x%2 !=0])\n counter += 2\n return sum_\n", "def row_sum_odd_numbers(n):\n if n==1:\n return 1\n startingdigit=((n-1)*n)+1\n tot=startingdigit\n for i in range(1,n):\n startingdigit+=2\n tot+=startingdigit\n return tot", "\ndef row_sum_odd_numbers(n):\n \n p = pow(n,3)\n \n return p\n\n", "def row_sum_odd_numbers(n):\n odd_number = n * (n - 1) + 1 \n odd_numbers = []\n if n == 1:\n return n\n for idx in range(n):\n odd_numbers.append(odd_number)\n odd_number += 2\n \n \n \n \n return sum(odd_numbers)\n\n \n\n \n \n\n\n\n", "def row_sum_odd_numbers(n):\n lista = []\n licznik = 0\n\n for i in range(n+1):\n licznik = licznik + i\n\n for i in range(licznik):\n x = (2*i)+1\n lista.append(x)\n\n return sum(lista[-n:])\n", "# pos = sum(range(1, n+2)\ndef row_sum_odd_numbers(n):\n return sum([x for x in range(sum(range(1, n))*2, sum(range(1, n+1))*2) if x%2])", "def row_sum_odd_numbers(n):\n odd_list = [1]\n max_odd = 1\n for x in range(1, n + 1):\n if x > 1:\n max_odd = max(odd_list)\n odd_list = [y for y in range(max_odd + 2, (max_odd + (2*x) + 2), 2)]\n \n return sum(odd_list)\n", "def row_sum_odd_numbers(n):\n a=((n-1)**2)+n\n b=(n**2)+n+1\n return sum([i for i in range(a, b, 2)])", "def row_sum_odd_numbers(n):\n data = {1: {'last': 1, 'sum': 1}}\n while max(data.keys()) <= n:\n id_max = max(data.keys())\n last, summ = data[id_max]['last'], data[id_max]['sum']\n a = [i for i in range(last + 2, id_max * 2 + last + 4, 2)]\n id_max += 1\n data[id_max] = {'last': a[-1], 'sum': sum(a)}\n return data[n]['sum']", "def row_sum_odd_numbers(n):\n rowStart = n*(n-1) + 1\n total = 0\n for i in range(n):\n total = total + (rowStart + 2 * i)\n \n return total", "def row_sum_odd_numbers(n):\n startPoint = 1\n counter = 1\n mainNumber = 1\n sum = 0\n # Finding start position\n for num in range(n-1,0,-1):\n startPoint += num\n\n # Getting odd number at start position\n while counter < startPoint:\n if counter == startPoint:\n break\n else:\n mainNumber += 2\n counter += 1\n # Calculating Final Sum\n for i in range(mainNumber,mainNumber+(n*2),2):\n sum += i\n return sum"] | {"fn_name": "row_sum_odd_numbers", "inputs": [[1], [2], [13], [19], [41], [42], [74], [86], [93], [101]], "outputs": [[1], [8], [2197], [6859], [68921], [74088], [405224], [636056], [804357], [1030301]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 18,706 |
def row_sum_odd_numbers(n):
|
4e925e398fcaf2b8adf12902360ab22c | UNKNOWN | Given a standard english sentence passed in as a string, write a method that will return a sentence made up of the same words, but sorted by their first letter. However, the method of sorting has a twist to it:
* All words that begin with a lower case letter should be at the beginning of the sorted sentence, and sorted in ascending order.
* All words that begin with an upper case letter should come after that, and should be sorted in descending order.
If a word appears multiple times in the sentence, it should be returned multiple times in the sorted sentence. Any punctuation must be discarded.
## Example
For example, given the input string `"Land of the Old Thirteen! Massachusetts land! land of Vermont and Connecticut!"`, your method should return `"and land land of of the Vermont Thirteen Old Massachusetts Land Connecticut"`. Lower case letters are sorted `a -> l -> l -> o -> o -> t` and upper case letters are sorted `V -> T -> O -> M -> L -> C`. | ["from string import punctuation\n\nt = str.maketrans(\"\", \"\", punctuation)\n\ndef pseudo_sort(s):\n a = s.translate(t).split()\n b = sorted(x for x in a if x[0].islower())\n c = sorted((x for x in a if x[0].isupper()), reverse=True)\n return \" \".join(b + c)", "from string import punctuation\ndef pseudo_sort(st): \n capital_list = sorted([word.strip(punctuation) for word in st.split() if word[0].isupper()], reverse=True)\n lower_list = sorted([word.strip(punctuation) for word in st.split() if word[0].islower()])\n return \" \".join(lower_list + capital_list)\n", "def pseudo_sort(s): \n s = ''.join(i for i in s if i.isalpha() or i is ' ')\n a = sorted(i for i in s.split() if i[0].islower())\n b = sorted((i for i in s.split() if i[0].isupper()),key=lambda x: x.lower(),reverse=True)\n return ' '.join(a+b)", "from re import findall\n\ndef pseudo_sort(st): \n lows = sorted(findall(r'\\b[a-z]+\\b', st))\n ups = sorted(findall(r'[A-Z][A-Za-z]*', st), reverse=True)\n return ' '.join(lows + ups)", "def pseudo_sort(st):\n words = st.translate(str.maketrans(\"\", \"\", \".,:;!?\")).split()\n lower, upper = [], []\n \n for word in words:\n if word[0].isupper():\n upper.append(word)\n else:\n lower.append(word)\n \n return \" \".join(sorted(lower) + sorted(upper, reverse=True))", "import re\n\ndef pseudo_sort(st):\n lower_case_words = re.findall(r'\\b[a-z]\\w*', st)\n upper_case_words = re.findall(r'\\b[A-Z]\\w*', st)\n\n lower_case_words.sort()\n upper_case_words.sort(reverse=True)\n\n return ' '.join(lower_case_words + upper_case_words)", "import re\n\ndef pseudo_sort(st): \n st, upper, lower = re.sub(r'[^ \\w]','',st).split(), [], []\n \n for i in st:\n if i[0].islower():\n lower.append(i)\n else:\n upper.append(i)\n \n return ' '.join(sorted(lower) + sorted(upper)[::-1])", "def pseudo_sort(stg): \n lowers, uppers = [], []\n for word in \"\".join(char for char in stg if char.isalpha() or char == \" \").split():\n (lowers if word[0].islower() else uppers).append(word)\n return \" \".join(sorted(lowers) + sorted(uppers)[::-1])", "def pseudo_sort(st): \n st = st.replace (\",\",\"\")\n st = st.replace (\"!\",\"\")\n st = st.replace (\".\",\"\")\n st = st.replace (\":\",\"\")\n st = st.replace (\";\",\"\")\n st = st.replace (\"?\",\"\")\n st = st.split()\n lis1 = [i for i in st if i.islower() == True]\n lis2 = [i for i in st if i[0].isupper() == True]\n lis1.sort(reverse = False)\n lis2.sort(reverse = True)\n return \" \".join(lis1+lis2)", "import re\nfrom functools import cmp_to_key\n\ndef compare(a, b):\n cmp1 = a[0].isupper() - b[0].isupper()\n cmp2 = (a < b) - (a > b)\n return cmp1 or cmp2 * (-1 if a[0].islower() else 1)\n\ndef pseudo_sort(st):\n return ' '.join(sorted(re.findall(r'\\w+', st), key=cmp_to_key(compare)))"] | {"fn_name": "pseudo_sort", "inputs": [["I, habitan of the Alleghanies, treating of him as he is in himself in his own rights"], ["take up the task eternal, and the burden and the lesson"], ["Land of the eastern Chesapeake"], ["And I send these words to Paris with my love"], ["O Liberty! O mate for me!"], ["With Egypt, India, Phenicia, Greece and Rome"], ["Only themselves understand themselves and the like of themselves, As souls only understand souls"], ["Land of the Old Thirteen! Massachusetts land! land of Vermont and Connecticut!"], ["Pioneers, O Pioneers!"], ["follow up these continual lessons of the air, water, earth"], [""], [", , !! . ."], ["lower"], ["UPPER"]], "outputs": [["as habitan he him himself his in in is of of own rights the treating I Alleghanies"], ["and and burden eternal lesson take task the the the up"], ["eastern of the Land Chesapeake"], ["love my send these to with words Paris I And"], ["for mate me O O Liberty"], ["and With Rome Phenicia India Greece Egypt"], ["and like of only souls souls the themselves themselves themselves understand understand Only As"], ["and land land of of the Vermont Thirteen Old Massachusetts Land Connecticut"], ["Pioneers Pioneers O"], ["air continual earth follow lessons of the these up water"], [""], [""], ["lower"], ["UPPER"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,993 |
def pseudo_sort(st):
|
f736a18fba283bb26a91a8449ac9f89e | UNKNOWN | You are given array of integers, your task will be to count all pairs in that array and return their count.
**Notes:**
* Array can be empty or contain only one value; in this case return `0`
* If there are more pairs of a certain number, count each pair only once. E.g.: for `[0, 0, 0, 0]` the return value is `2` (= 2 pairs of `0`s)
* Random tests: maximum array length is 1000, range of values in array is between 0 and 1000
## Examples
```
[1, 2, 5, 6, 5, 2] --> 2
```
...because there are 2 pairs: `2` and `5`
```
[1, 2, 2, 20, 6, 20, 2, 6, 2] --> 4
```
...because there are 4 pairs: `2`, `20`, `6` and `2` (again) | ["def duplicates(arr):\n return sum(arr.count(i)//2 for i in set(arr))", "from collections import Counter\n\ndef duplicates(arr):\n return sum(v//2 for v in list(Counter(arr).values()))\n", "def duplicates(arr):\n return sum((arr.count(n) // 2 for n in set(arr))) ", "from collections import Counter\n\ndef duplicates(arr):\n return sum(v >> 1 for v in Counter(arr).values())", "from collections import Counter\n\ndef duplicates(a):\n return sum(e//2 for e in Counter(a).values())", "import collections\ndef duplicates(arr: list):\n sumDup = 0\n arr = collections.Counter(arr)\n for i in arr:\n sumDup += arr[i] // 2\n return sumDup", "def duplicates(lst):\n return sum(lst.count(n) // 2 for n in set(lst))\n", "def duplicates(arr):\n return sum([arr.count(item)//2 for item in set(arr)])", "def duplicates(arr):\n i=0\n for iter in arr:\n i+=int(arr.count(iter)/2)/arr.count(iter)\n return round(i)\n \n", "def duplicates(arr):\n seen, count = set(), 0\n for n in arr:\n if n in seen:\n seen.remove(n)\n count += 1\n else:\n seen.add(n)\n return count"] | {"fn_name": "duplicates", "inputs": [[[1, 2, 2, 20, 6, 20, 2, 6, 2]], [[1000, 1000]], [[]], [[54]]], "outputs": [[4], [1], [0], [0]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,176 |
def duplicates(arr):
|
95f1a2262e86d0480f826889ee48287a | UNKNOWN | ## Task
In your favorite game, you must shoot a target with a water-gun to gain points. Each target can be worth a different amount of points.
You are guaranteed to hit every target that you try to hit. You cannot hit consecutive targets though because targets are only visible for one second (one at a time) and it takes you a full second to reload your water-gun after shooting (you start the game already loaded).
Given an array `vals` with the order of each target's point value, determine the maximum number of points that you can win.
## Example
For `vals = [1, 2, 3, 4]`, the result should be `6`.
your optimal strategy would be to let the first one pass and shoot the second one with value 2 and the 4th one with value 4 thus:
`vals[1](2) + vals[3](4) = 6`
For `vals = [5, 5, 5, 5, 5]`, the result should be `15`.
your optimal strategy would be to shoot the 1st, 3rd and 5th value:
`5 + 5 + 5 = 15`
You haven't shoot the 2nd, 4th value because you are reloading your water-gun after shooting other values.
Note that the value can be zero or negative, don't shoot them ;-)
For `vals = [0, 0, -1, -1]`, the result should be `0`.
For `vals = [5, -2, -9, -4]`, the result should be `5`.
Shoot the first one is enough.
## Input/Output
- `[input]` integer array `vals`
The point values (negative or non-negative) of the targets (in order of appearance).
- `[output]` an integer
The maximum number of points that you can score. | ["def target_game(values):\n a = b = 0\n for n in values:\n a, b = b, max(a + n, b)\n return max(a, b)", "def target_game(values):\n max_can_shoot, max_can_not_shoot = 0, 0\n for val in values:\n new = max_can_shoot + val\n max_can_shoot = max(max_can_not_shoot, new)\n max_can_shoot, max_can_not_shoot = max_can_not_shoot, max_can_shoot\n return max(max_can_shoot, max_can_not_shoot)", "from functools import lru_cache\n\ndef target_game(values):\n @lru_cache(maxsize=None)\n def rec(i):\n if i >= len(values): return 0\n if values[i] <= 0: return rec(i+1)\n return max(rec(i+1), values[i]+rec(i+2))\n return rec(0)", "def target_game(values):\n n = len(values)\n dp = [0] * (n + 1)\n dp[1] = values[0] if values[0] > 0 else 0\n for ind in range(2, n + 1):\n dont_take = dp[ind - 1]\n take = dp[ind - 2] + values[ind - 1] if values[ind - 1] > 0 else dp[ind - 2]\n dp[ind] = max(dont_take, take)\n return dp[n]", "def target_game(values):\n dicto = {}\n def target_games(values,ind=0,reloaded=True,sumo=0):\n key = f\"ind {ind} sumo {sumo} reloaded {reloaded}\"\n if key in dicto: return dicto[key]\n if ind >= len(values): return sumo\n while values[ind] < 0:\n ind += 1\n reloaded = True\n if ind == len(values): return sumo\n if reloaded: d = target_games(values,ind+1,not reloaded,sumo+values[ind])\n elif not reloaded: d = target_games(values,ind+1,not reloaded,sumo)\n f = target_games(values,ind+1,reloaded,sumo)\n dicto[key] = max(d,f)\n return dicto[key]\n return target_games(values)", "def target_game(values):\n values[2] = get_highest_possible_score(0, values[0], values[2]) \n for i in range(3,len(values)):\n values[i] = get_highest_possible_score(values[i-3], values[i-2], values[i]) \n return max(values)\n\ndef get_highest_possible_score(a,b,n):\n a = max(0,a)\n b = max(0,b)\n n = max(0,n)\n \n if(a>b):\n return a+n\n\n return b+n", "def target_game(values):\n sum1 = 0\n sum2 = 0\n for value in values:\n sum1 = max(sum1 + value, sum2)\n sum1, sum2 = sum2, sum1\n return max(sum1, sum2)\n", "def target_game(arr):\n # your code goes here\n a = 0\n b = 0\n \n for i in arr: \n \n newA = a if (a > b) else b\n \n b = a + i\n a = newA\n \n if (a > b):\n return a\n else: \n return b\n", "def target_game(arr):\n # your code goes here\n a = 0\n b = 0\n \n for i in arr: \n \n newA = a if (a > b) else b\n \n b = a + i\n a = newA\n \n # return max of incl and excl \n if (a > b):\n return a\n else: \n return b\n", "memo={}\ndef target_game(values):\n if len(values)==1:\n return max(values[0],0)\n elif len(values)==2:\n return max(values[0],values[1],0)\n elif len(values)==3:\n return max(max(values[0],values[2],values[0]+values[2],0),values[1])\n t=tuple(values)\n if t in memo:\n return memo[t]\n r=max(max(values[0],0)+target_game(values[2:]),max(values[1],0)+target_game(values[3:]))\n memo[t]=r\n return r"] | {"fn_name": "target_game", "inputs": [[[1, 2, 3, 4]], [[1, 3, 1]], [[5, 5, 5, 5, 5]], [[36, 42, 93, 29, 0, 33, 15, 84, 14, 24, 81, 11]], [[73, 80, 40, 86, 14, 96, 10, 56, 61, 84, 82, 36, 85]], [[11, 82, 47, 48, 80, 35, 73, 99, 86, 32, 32]], [[26, 54, 36, 35, 63, 58, 31, 80, 59, 61, 34, 54, 62, 73, 89, 7, 98, 91, 78]], [[0, 0, -1, -1]], [[1, 0, 0, 1]], [[5, -2, -9, -4]]], "outputs": [[6], [3], [15], [327], [490], [353], [615], [0], [2], [5]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,303 |
def target_game(values):
|
e444872ef5aa38d1227eefdf946a93fe | UNKNOWN | My friend wants a new band name for her band. She like bands that use the formula: "The" + a noun with the first letter capitalized, for example:
`"dolphin" -> "The Dolphin"`
However, when a noun STARTS and ENDS with the same letter, she likes to repeat the noun twice and connect them together with the first and last letter, combined into one word (WITHOUT "The" in front), like this:
`"alaska" -> "Alaskalaska"`
Complete the function that takes a noun as a string, and returns her preferred band name written as a string. | ["def band_name_generator(name):\n return name.capitalize()+name[1:] if name[0]==name[-1] else 'The '+ name.capitalize()", "def band_name_generator(name):\n if name[0] == name[-1]:\n return name.title()+name[1:]\n return (\"the \"+name).title()", "def band_name_generator(name):\n if name[0] != name[-1]:\n return \"{}{}{}\".format(\"The \", name[0].upper(), name[1:])\n else:\n return \"{}{}{}\".format(name[0].upper(), name[1:], name[1:])", "def band_name_generator(name):\n return name.capitalize() + name[1:] if name.startswith(name[0]) and name.endswith(name[0]) else 'The ' + name.capitalize() ", "def band_name_generator(name):\n return name.title() if len(name) == 1 else name.title()[:-1] + name if name[0] == name[-1] else \"The \" + name.title()", "def band_name_generator(name):\n return f\"{name}{name[1:]}\".capitalize() if name[0] == name[-1] else f\"The {name.capitalize()}\"", "def band_name_generator(name):\n return \"The \" + name.capitalize() if name[0] != name[-1] else name.capitalize() + name[1:]", "def band_name_generator(name):\n if name[0] == name[-1]:\n return (name + name[1:]).title()\n else:\n return \"The \" + name.title()", "def band_name_generator(s):\n return (('The ' if s[0] != s[-1] else s[:-1]) + s).title()", "band_name_generator=lambda s:(['the ',s[:-1]][s[0]==s[-1]]+s).title()"] | {"fn_name": "band_name_generator", "inputs": [["knife"], ["tart"], ["sandles"], ["bed"], ["qq"]], "outputs": [["The Knife"], ["Tartart"], ["Sandlesandles"], ["The Bed"], ["Qqq"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,394 |
def band_name_generator(name):
|
96d22d08e10991eb65acb00e71c430fd | UNKNOWN | Ever since you started work at the grocer, you have been faithfully logging down each item and its category that passes through. One day, your boss walks in and asks, "Why are we just randomly placing the items everywhere? It's too difficult to find anything in this place!" Now's your chance to improve the system, impress your boss, and get that raise!
The input is a comma-separated list with category as the prefix in the form `"fruit_banana"`. Your task is to group each item into the 4 categories `Fruit, Meat, Other, Vegetable` and output a string with a category on each line followed by a sorted comma-separated list of items.
For example, given:
```
"fruit_banana,vegetable_carrot,fruit_apple,canned_sardines,drink_juice,fruit_orange"
```
output:
```
"fruit:apple,banana,orange\nmeat:\nother:juice,sardines\nvegetable:carrot"
```
Assume that:
1. Only strings of the format `category_item` will be passed in
2. Strings will always be in lower case
3. Input will not be empty
4. Category and/or item will not be empty
5. There will be no duplicate items
6. All categories may not have items | ["def group_groceries(groceries):\n categories = {\"fruit\": [], \"meat\": [], \"other\": [], \"vegetable\": []}\n for entry in groceries.split(\",\"):\n category, item = entry.split(\"_\")\n categories[category if category in categories else \"other\"].append(item)\n return \"\\n\".join([f\"{category}:{','.join(sorted(items))}\" for category, items in categories.items()])", "def group_groceries(groceries):\n categories = { 'fruit':[], 'meat':[], 'other':[], 'vegetable':[] }\n for product in groceries.split(','):\n key, value = product.split('_')\n categories[key if key in categories else 'other'].append(value)\n return '\\n'.join('{}:{}'.format(cat, ','.join(sorted(items))) for cat, items in categories.items())", "\ndef group_groceries(groceries):\n \n groceries = groceries.split(',')\n carne = []\n fruta = []\n outro = []\n vegetal = []\n for item in groceries:\n a = item.split('_')\n if a[0] == 'fruit':\n fruta.append(a[1])\n elif a[0] == 'meat':\n carne.append(a[1])\n elif a[0] == 'vegetable':\n vegetal.append(a[1])\n else:\n outro.append(a[1])\n \n b = '''fruit:{}\nmeat:{}\nother:{}\nvegetable:{}'''.format(','.join(sorted(fruta)),','.join(sorted(carne)),','.join(sorted(outro)),','.join(sorted(vegetal)))\n\n return b\n", "def group_groceries(groceries, categories='fruit meat other vegetable'.split()):\n groups = {category: [] for category in categories}\n for product in groceries.split(','):\n category, item = product.split('_')\n groups.get(category, groups['other']).append(item)\n return '\\n'.join(f'{category}:{\",\".join(sorted(products))}'\n for category, products in groups.items())", "def group_groceries(groceries):\n dict={\"fruit\":[], \"meat\":[], \"other\":[], \"vegetable\":[]}\n for i in groceries.split(\",\"):\n items=i.split(\"_\")\n if not items[0] in [\"fruit\", \"meat\", \"vegetable\"]:\n dict[\"other\"].append(items[1])\n else:\n dict[items[0]].append(items[1])\n temp={k: \",\".join(sorted(v)) for k,v in dict.items()}\n return \"\\n\".join(f\"{i}:{j}\" for i,j in temp.items())", "def group_groceries(groce):\n box = {'fruit':[], 'meat':[], 'other':[], 'vegetable':[]}\n groce = [e.split('_') for e in groce.split(',')]\n for k,v in groce: box.get(k, box['other']).append(v)\n return '\\n'.join( f'{k}:{\",\".join(sorted(v))}' for k,v in box.items())", "CATEGORIES = ['fruit', 'meat', 'other', 'vegetable']\nKNOWN = {c: c for c in CATEGORIES if c != 'other'}\n\ndef group_groceries(groceries):\n d = {key: [] for key in CATEGORIES}\n for item in groceries.split(','):\n category, name = item.split('_')\n d[KNOWN.get(category, 'other')].append(name)\n return '\\n'.join(f'{c}:{\",\".join(sorted(d[c]))}' for c in CATEGORIES)", "def group_groceries(groceries):\n res = {\"fruit\":[], \"meat\":[], \"other\":[], \"vegetable\":[]}\n for item in groceries.split(','):\n category, name = item.split('_')\n res.get(category, res[\"other\"]).append(name)\n return '\\n'.join(f\"{k}:{','.join(sorted(v))}\" for k,v in res.items())", "def group_groceries(groceries):\n groups = [\"fruit\", \"meat\", \"other\", \"vegetable\"]\n d = {}\n \n for item in groceries.split(','):\n g, i = item.split('_')\n \n g = g if g in groups else \"other\"\n try:\n d[g].append(i)\n except:\n d[g] = [i]\n final_string = []\n for g in groups:\n try:\n group_string = g + \":\" + ','.join(sorted(d[g]))\n except:\n group_string = g + \":\"\n final_string.append(group_string)\n return '\\n'.join(final_string)", "def group_groceries(s):\n d = {x: [] for x in \"fruit meat other vegetable\".split()}\n for x in s.split(\",\"):\n a, b = x.split(\"_\")\n d[a if a in d else \"other\"].append(b)\n return \"\\n\".join(f\"{x}:{','.join(sorted(y))}\" for x, y in d.items())"] | {"fn_name": "group_groceries", "inputs": [["fruit_banana,vegetable_carrot,meat_chicken,drink_juice"], ["fruit_banana,vegetable_carrot,fruit_apple,canned_sardines,drink_juice,fruit_orange"], ["vegetable_celery,meat_chicken,meat_beef,fruit_banana,vegetable_carrot,canned_sardines,drink_juice,frozen_fries,fruit_lemon"], ["fruit_orange"]], "outputs": [["fruit:banana\nmeat:chicken\nother:juice\nvegetable:carrot"], ["fruit:apple,banana,orange\nmeat:\nother:juice,sardines\nvegetable:carrot"], ["fruit:banana,lemon\nmeat:beef,chicken\nother:fries,juice,sardines\nvegetable:carrot,celery"], ["fruit:orange\nmeat:\nother:\nvegetable:"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 4,152 |
def group_groceries(groceries):
|
daf1ba5725f2938127eeaf1b9838d6aa | UNKNOWN | # How much is the fish! (- Scooter )
The ocean is full of colorful fishes. We as programmers want to know the hexadecimal value of these fishes.
## Task
Take all hexadecimal valid characters (a,b,c,d,e,f) of the given name and XOR them. Return the result as an integer.
## Input
The input is always a string, which can contain spaces, upper and lower case letters but no digits.
## Example
`fisHex("redlionfish") -> e,d,f -> XOR -> 12` | ["from functools import reduce\nVALID = frozenset('abcdefABCDEF')\n\n\ndef fisHex(s):\n return reduce(lambda b, c: b ^ c, (int(a, 16) for a in s if a in VALID), 0)\n", "def fisHex(name):\n # fish is 15\n hexdict={'A':10,'B':11,'C':12,'D':13,'E':14,'F':15}\n res=0\n for c in name.upper():\n if c in hexdict:\n res^=hexdict[c]\n return res\n", "def fisHex(name):\n hexx = {'a':10, 'b':11, 'c':12, 'd':13, 'e':14, 'f':15}\n name = name.lower()\n result = 0\n for i in name:\n if i in hexx:\n result = result ^ hexx[i]\n return result", "from functools import reduce\n\ndef fisHex(name):\n hex = ['a','b','c','d','e','f']\n hexFish = []\n \n for i in name.lower():\n if i in hex:\n hexFish.append(i)\n \n hexList = [int(x, 16) for x in hexFish]\n if hexList != []:\n hexValue = hexList[0]\n else:\n return 0\n \n hexValue = reduce(lambda x, y: x ^ y, hexList)\n return hexValue", "from functools import reduce\nfisHex=lambda s:reduce(lambda x,y: x^y,[int(i,16) for i in s if i in \"ABCDEFabcdef\"] or [0])", "from functools import reduce\nfrom operator import xor\n\ndef fisHex(name):\n return reduce(xor, (int(x, 16) for x in name.lower() if 'a' <= x <= 'f'), 0)", "from functools import reduce\nfrom operator import xor\n\ndef fisHex(name):\n s = set(\"abcdef\")\n return reduce(xor, map(lambda c: int(c,16), (c for c in name.lower() if c in s)),0)", "from operator import xor\nfrom functools import reduce\n\ndef fisHex(name):\n return reduce(xor,[int(x,16) for x in name.lower() if x in 'abcdef'], 0) \n \n", "def fisHex(name):\n print(name)\n hex_string = \"abcdef\"\n name = name.lower()\n values = [i for i in name if i in hex_string]\n \n if len(values)>=1:\n placeholder = int(str(values.pop()),16)\n for num in values:\n placeholder = placeholder ^ int(num,16)\n return placeholder\n else:\n return 0", "def fisHex(name):\n return eval(\"^\".join([\"0x\" + c for c in name.lower() if c in \"abcdef\"])) if name else 0", "from operator import xor\nfrom functools import reduce\n\ndef fisHex(name):\n return reduce(xor, (ord(c) - 87 for c in name.lower() if c in \"abcdef\"), 0)\n", "hexa = {'a':10, 'b':11, 'c':12, 'd':13, 'e':14, 'f':15}\ndef fisHex(name):\n print(name)\n hexv = [hexa[i] for i in name.lower() if i in hexa]\n s = 0\n for i in range(0, len(hexv)):\n s = s^hexv[i]\n return s", "from functools import reduce\ndef fisHex(name, l={'a': 10, 'b': 11, 'c': 12, 'd': 13, 'e': 14, 'f': 15, 'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15 }):\n return reduce( lambda acc,x: acc ^ l.get(x,0), name, 0 )\n", "fisHex=f=lambda s:len(s)and(s[0]in'abcdefABCDEF'and int(s[0],16))^f(s[1:])", "from functools import reduce; fisHex=lambda name: reduce(lambda a,b: a^b, [int(l,16) if l in \"abcdef\" else 0 for l in name.lower()],0)"] | {"fn_name": "fisHex", "inputs": [["pufferfish"], ["puffers"], ["balloonfish"], ["blowfish"], ["bubblefish"], ["globefish"], ["swellfish"], ["toadfish"], ["toadies"], ["honey toads"], ["sugar toads"], ["sea squab"], [""], ["Aeneus corydoras"], ["African glass catfish"], ["African lungfish"], ["Aholehole"], ["Airbreathing catfish"], ["Airsac catfish"], ["Alaska blackfish"], ["Albacore"], ["Alewife"], ["Alfonsino"], ["Algae eater"], ["Alligatorfish"], ["Asian carps"], ["Asiatic glassfish"], ["Atka mackerel"], ["Atlantic cod"], ["Atlantic herring"], ["Atlantic salmon"], ["Atlantic saury"], ["Atlantic silverside"], ["Australasian salmon"], ["Australian grayling"], ["Australian herrin"], ["Australian lungfish"], ["Australian prowfish"], ["Ayu"]], "outputs": [[1], [14], [14], [4], [10], [10], [1], [8], [9], [9], [13], [5], [0], [1], [0], [12], [10], [12], [5], [8], [9], [5], [5], [4], [15], [6], [9], [6], [13], [2], [6], [6], [1], [10], [0], [4], [5], [5], [10]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,993 |
def fisHex(name):
|
bdd00a98ebcb1cbb4705b81bfe94e139 | UNKNOWN | ```if-not:racket
Write a function called `repeat_str` which repeats the given string `src` exactly `count` times.
```
```if:racket
Write a function called `repeat-string` which repeats the given string `str` exactly `count` times.
``` | ["def repeat_str(repeat, string):\n return repeat * string", "def repeat_str(a,b):\n '''crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy\ni am a crazy'''\n return b*a\n\n return", "def repeat_str(repeat, string):\n solution = \"\"\n for i in range(repeat):\n solution += string\n return solution", "def repeat_str(repeat, string):\n return string*repeat", "def repeat_str(r, s):\n return s * r", "repeat_str = lambda r, s: s * r", "repeat_str = lambda n, str: str * n", "def repeat_str(repeat, string):\n return \"\".join([string]*repeat)", "repeat_str=lambda _,__:__*_", "def repeat_str(repeat, string):\n return string*repeat #I solved this Kata on 7/21/2019 05:21 PM...#Hussam'sCodingDiary", "from operator import mul as repeat_str", "def repeat_str(repeat, text):\n\n rep = text * repeat\n return rep\n\nprint(repeat_str(5, 'Easy'))", "repeat_str=__import__('operator').mul", "repeat_str = lambda n, s: s * n", "repeat_str = lambda n, s: n * s", "def repeat_str(repeat, string):\n return string + repeat_str(repeat-1, string) if repeat else ''", "def repeat_str(repeat, string):\n return \"{}\".format(string) * int(repeat)", "def repeat_str(repeat, string):\n result = ''\n for i in range(0, repeat):\n result = f\"{result}{string}\"\n return result", "def repeat_str(repeat, string):\n repeatString = ''\n for i in range(0, repeat):\n repeatString += string\n \n return repeatString", "def repeat_str(repeat, string):\n \n counter=0\n out=''\n while counter < repeat:\n out+=string\n counter+=1\n \n return out\n", "def repeat_str(repeat, string):\n result = ''\n i = 0\n while i != repeat:\n result += string\n i += 1\n print (result)\n return result", "def repeat_str(repeat, string):\n return string if repeat is 1 else string + repeat_str(repeat-1, string)", "repeat_str = lambda x, y: x * y", "def repeat_str(repeat, string):\n stri = \"\"\n for i in range(repeat):\n stri = stri+string\n return stri\n \n", "def repeat_str(repeat, string):\n res = string*repeat\n return f'{res}'", "def repeat_str(repeat, string):\n var = string\n return var * repeat", "def repeat_str(repeat, string):\n result = string * repeat\n length = len(result)\n return result", "def repeat_str(r, string):\n output = \"\"\n for x in range(0,r):\n output += string\n \n return output", "def repeat_str(repeat, string):\n repeated_words = \"\"\n for i in range(repeat):\n repeated_words += string\n return repeated_words\n\nrepeat_str(5, \"a\")", "def repeat_str(repeat, string):\n ans = string\n for x in range(repeat -1):\n ans += string\n \n return ans", "def repeat_str(repeat, string):\n x = int(repeat)*string\n return x", "def repeat_str(repeat, string):\n txt = ''\n number = 0\n while number < repeat:\n txt += string\n number += 1\n return txt\n \n", "def repeat_str(repeat, string):\n repeated_str = int(repeat) * string\n return repeated_str\n", "def repeat_str(repeat, string):\n\n\n sr = repeat *string\n return sr", "def repeat_str(repeat, string):\n s = []\n for i in range(repeat):\n s.append(string)\n return ''.join(s)\n", "def repeat_str(repeat, string):\n if string*repeat:\n return(string*repeat)\n return ", "def repeat_str(repeat, string):\n total = \"\"\n for i in range(repeat+1):\n total = string * i\n \n return total", "def repeat_str(repeat, string):\n word = \"\"\n iterator = 0;\n while iterator < repeat:\n word = word + string\n iterator = iterator + 1\n return word", "def repeat_str(repeat, string):\n new_str = ''\n while repeat > 0:\n new_str += string\n repeat -= 1\n return new_str", "def repeat_str(repeat, string):\n return_str = string * repeat\n return return_str", "def repeat_str(repeat, string):\n return str.join('', [string] * repeat)", "def repeat_str(repeat, string):\n reply = \"\"\n for a in range(repeat): reply+=string\n return reply", "# String repeat: codewars.com\n''' repeats the given string src\nexactly count times '''\ndef repeat_str(count, src):\n return count * src\n", "def repeat_str(repeat, string):\n i = 0\n new_str = ''\n while i < repeat:\n i = i + 1\n new_str = new_str + string\n return new_str", "def repeat_str(repeat, string):\n other = string\n for i in range(repeat-1):\n string += other\n return string", "def repeat_str(repeat, string):\n new_string = ''\n for i in range(0, repeat, 1):\n new_string += string\n return new_string", "def repeat_str(repeat, string):\n i, ans = 0, \"\"\n \n while i < repeat:\n ans += string\n i = i + 1\n\n return ans", "def repeat_str(repeat, string):\n rta = \"\"\n for i in range(repeat):\n rta += string\n return rta", "def repeat_str(repeat, string):\n loopStr = \"\"\n for i in range(repeat):\n loopStr += string\n return loopStr", "def repeat_str(repeat, string):\n while repeat > 0:\n return string*repeat\n else:\n pass", "def repeat_str(repeat, string):\n outString=''\n for i in range(repeat):\n outString = outString + string\n return outString", "def repeat_str(repeat, string):\n z = ''\n for k in range(0, repeat):\n z += string\n\n return z", "def repeat_str(noOfTimes, str):\n return str * noOfTimes", "def repeat_str(repeat, string):\n string=(string)*repeat\n return string\nrepeat_str(4,'a')\n", "def repeat_str(repeat, string):\n return string * repeat\nprint(repeat_str(4, 'sa'))", "# takes an int repeat and string as argument\n# returns repeat * string\ndef repeat_str(repeat, string):\n return repeat * string", "def repeat_str(repeat, string):\n src = ''\n for i in range(0, repeat):\n src += string\n return src", "def repeat_str(x, z):\n return x * z", "def repeat_str(repeat, string):\n out = \"\"\n i = 0\n while i < repeat:\n out = out + string\n i += 1\n return out", "def repeat_str(repeat, string):\n x = \"\"\n for _ in range(repeat):\n x+=string\n return x", "def repeat_str(repeat, string):\n finalstring=\"\"\n for i in range(repeat):\n finalstring+=string\n return(finalstring)", "def repeat_str(repeat, string):\n return str(\"\".join(string for i in range(0, repeat)))\n", "def repeat_str(repeatCT, sourceString):\n repeatString = repeatCT * sourceString\n #stringOnRepeat = \"\"\n #return stringOnRepeat\n return repeatString", "def repeat_str(repeat, string):\n f = string * repeat\n return f", "def repeat_str(repeat, string):\n anwser=\"\"\n for a in range (repeat):\n anwser += string\n print(anwser)\n return anwser", "def repeat_str(repeat, string):\n final_string = \"\"\n for i in range(repeat):\n final_string = final_string + string\n return final_string\n\n", "repeat_str = lambda repeat, string: ''.join([string]*repeat)", "def repeat_str(repeat, string):\n new_str=\"\"\n for s in range(repeat):\n new_str=string+new_str\n return new_str", "def repeat_str(repeat, string):\n x = string\n for i in range(repeat-1):\n string = string + x\n return string", "def repeat_str(repeat, string):\n \n x = \"\"\n \n while (repeat > 0):\n repeat -= 1\n x += string \n \n return x", "def repeat_str(repeat, string):\n output = str(string)\n for x in range(repeat-1):\n output += string\n return output", "def repeat_str(count, src):\n return count*src\n\nrepeat_str(3, \"hello\")", "def repeat_str(repeat, string):\n if len(string)>=1:\n pass\n return repeat*string\n \n", "def repeat_str(repeat, string):\n count = ''\n for i in range(repeat):\n count += string\n return count", "def repeat_str(repeat = 0, string = \"\"):\n return string * repeat", "def repeat_str(repeat, string):\n# new_str = ''\n# while repeat > 0:\n# new_str += string\n# repeat -= 1\n# return new_str\n# new_str = \"\"\n# for _ in range(repeat):\n# new_str += string\n \n# return new_str\n return string * repeat", "def repeat_str(repeat, string):\n i = 0 \n ans = \"\"\n while i < repeat:\n ans += string\n i +=1\n return ans", "def repeat_str(repeat, string):\n ans = ''\n for x in range(0,repeat):\n \n ans = ans + string \n \n \n \n return ans", "def repeat_str(repeat, string):\n s=string\n for i in range (1, repeat):\n s = s + string\n return s ", "def repeat_str(repeat, string):\n new_string = ''\n for i in range(repeat):\n new_string = f'{new_string}{string}'\n return new_string\n \n", "def repeat_str(wanted, s):\n return s * wanted", "def repeat_str(count, string):\n str = string\n for count in range(0, count-1):\n string = string.__add__(str)\n return string\n\n\nprint(repeat_str(4, 'a'))", "def repeat_str(count, src):\n output = count * src\n return output", "def repeat_str(repeat, string):\n while string != '':\n print((string * repeat))\n break\n return string * repeat\n\n\n \n \n\n\n\n \n", "def repeat_str(repeat, string):\n hold = ''\n for i in range(repeat):\n hold += string\n return hold", "def repeat_str(repeat, string):\n Answer = string * repeat\n return Answer", "def repeat_str(c, s):\n return c * s", "def repeat_str(repeat, string):\n substring = ''\n for i in range(repeat):\n substring = string + substring\n return substring", "def repeat_str(repeat, string):\n result = string\n count = 1\n while count < repeat:\n result += string\n count += 1\n return result", "def repeat_str(repeat, string):\n retStr = \"\"\n for x in range (0,repeat):\n retStr += string\n return retStr", "\ndef repeat_str(repeat, string):\n a = ''\n while repeat != 0:\n a += string \n repeat = repeat - 1 \n return a", "def repeat_str(repeat, string):\n \n output = ''\n \n for x in range(0, repeat):\n output = output + string \n x+=1 \n # print (string, \"\")\n \n return output", "def repeat_str(repeat, string):\n s = ''.join(string * repeat)\n return s", "def repeat_str(repeat, string):\n score = (repeat * string)\n return score", "def repeat_str(r, s):\n repeat = ''\n for i in range(r):\n repeat += s\n \n return repeat", "def repeat_str(src, count):\n try:\n if src == int(src):\n return (src * count)\n except ValueError:\n return 'Error'\n", "def repeat_str(repeat, string):\n output = \"\"\n count = repeat\n while count > 0:\n output += string\n count -= 1\n return output", "def repeat_str(repeat, string):\n # print (repeat * string)\n inf = repeat * string\n return (repeat * string)", "def repeat_str(repeat, string):\n string_m = ''\n for x in range(repeat):\n string_m += string\n return string_m", "def repeat_str(repeat, string):\n repeat_final = string*repeat\n return repeat_final"] | {"fn_name": "repeat_str", "inputs": [[4, "a"], [3, "hello "], [2, "abc"]], "outputs": [["aaaa"], ["hello hello hello "], ["abcabc"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 55,567 |
def repeat_str(repeat, string):
|
5f125bdb7acb72dbd92d20103eee21ef | UNKNOWN | This is a follow up from my kata Insert Dashes.
Write a function ```insertDashII(num)``` that will insert dashes ('-') between each two odd numbers and asterisk ('\*') between each even numbers in ```num```
For example:
```insertDashII(454793)``` --> 4547-9-3
```insertDashII(1012356895)``` --> 10123-56*89-5
Zero shouldn't be considered even or odd. | ["def insert_dash2(num):\n \n prev = 0\n out = ''\n\n for dig in str(num):\n if int(dig) % 2 == int(prev) % 2 and int(prev) and int(dig):\n out += '*-'[int(prev) % 2]\n out += dig\n prev = dig\n return out", "import re\n\ndef insert_dash2(num):\n s = str(num)\n s = re.sub('(?<=[13579])(?=[13579])', '-', s)\n s = re.sub('(?<=[2468])(?=[2468])', '*', s)\n return s", "import re\ndef insert_dash2(num): return re.sub(r'[13579](?=[13579])|[2468](?=[2468])', lambda m: m.group(0) + (\"-\" if int(m.group(0)) & 1 else \"*\"), str(num))", "import re\ndef insert_dash2(num):\n s = re.sub(r'([2468])(?=[2468])',r'\\1*',str(num))\n return re.sub(r'([13579])(?=[13579])',r'\\1-',s)\n", "import re\ndef insert_dash2(num):\n a=re.sub(r'([2468])(?=[2468])',r'\\1*',str(num))\n return re.sub(r'([13579])(?=[13579])',r'\\1-',a)", "def insert_dash2(num):\n \n snum = str(num)\n evens, odds = frozenset('2468'), frozenset('13579')\n res = []\n \n for l, r in zip(snum[:-1], snum[1:]):\n res.append(l)\n if l in evens and r in evens: res.append('*')\n elif l in odds and r in odds: res.append('-')\n \n res.append(snum[-1])\n \n return ''.join(res)", "def insert_dash2(num):\n import re\n return re.sub(r'([2468])(?=[2468])', r'\\1*', re.sub(r'([13579])(?=[13579])', r'\\1-', str(num)))", "def insert_dash2(num):\n num = list(str(num))\n answer = ''\n for index, obj in enumerate(num):\n previous = num[index - 1]\n if (index==0)or(int(obj)==0)or(int(previous)==0):\n answer += obj\n continue\n elif (int(obj)%2==0 and int(previous)%2==0):\n answer += '*'+ obj\n elif (int(obj)%2!=0 and int(previous)%2!=0):\n answer += '-' + obj\n else:\n answer += obj\n continue\n\n return answer\n\n", "insert_dash2=lambda n,r=__import__(\"re\").sub,a=\"2468\",b=\"13579\":r(f\"([{a}])(?=[{a}])\",r\"\\1*\",r(f\"([{b}])(?=[{b}])\",r\"\\1-\",str(n)))", "insert_dash2=lambda x:''.join([str(x)[i]+'-'if int(str(x)[i])%2and int(str(x)[i+1])%2else str(x)[i]+'*'if not int(str(x)[i])%2and not int(str(x)[i+1])%2and'0'not in[str(x)[i+1],str(x)[i]]else str(x)[i]for i in range(len(str(x))-1)])+str(x)[-1]"] | {"fn_name": "insert_dash2", "inputs": [[454793], [123456], [40546793], [1012356895], [0]], "outputs": [["4547-9-3"], ["123456"], ["4054*67-9-3"], ["10123-56*89-5"], ["0"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,277 |
def insert_dash2(num):
|
861edbfb2f25379b34e0a3b4bd26e50f | UNKNOWN | Uh oh, Someone at the office has dropped all these sequences on the floor and forgotten to label them with their correct bases.
We have to fix this before the boss gets back or we're all going to be fired!
This is what your years of coding have been leading up to, now is your time to shine!
## Task
You will have to create a function which takes in a sequence of numbers in **random order** and you will have to return the correct base of those numbers.
The base is the number of unique digits. For example, a base 10 number can have 10 unique digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and a base 2 number (Binary) can have 2 unique digits: 0 and 1.
### Constraints
The sequence will always be 10 numbers long and we know that the base is going to be between 2 and 10 inclusive so no need to worry about any letters. When sorted, the sequence is made up of consecutive numbers.
### Examples
```
[ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ] --> 10
[ "1", "2", "3", "4", "5", "6", "10", "11", "12", "13" ] --> 7
```
**Good luck!** | ["def base_finder(seq):\n return len(set(''.join(seq)))", "def base_finder(a):\n return int(max(x[-1] for x in a)) + 1", "def base_finder(seq):\n base = 0\n for i in range(10): #as the sequence will always be 10 numbers long\n number = seq[i] # converting each list element to a string\n for i in range(len(number)): \n if int(number[i]) > base: # Comparing each character of string to base\n base = int(number[i]) # updating the base value\n return base+1 # return base value \n", "def base_finder(seq):\n return int(max(''.join(seq))) +1", "base_finder=lambda _:int(max(map(lambda x:x[-1],_)))+1", "def base_finder(seq):\n digits = set(c for cs in seq for c in cs)\n return int(max(digits)) + 1", "def base_finder(seq):\n a = []\n b = []\n for i in seq:\n for j in i: \n a.append(j)\n for digit in a:\n if digit not in b:\n b.append(digit)\n return len(b)", "def base_finder(seq):\n str = ''\n for i in seq:\n str += i\n \n return len(set(str))\n", "def base_finder(seq):\n return max([int(i) for i in \"\".join(seq)]) + 1", "def base_finder(seq):\n mx = [int(char) for char in seq]\n mx = sorted(mx)\n print(mx)\n for i in range(min(mx), max(mx)):\n if i not in mx:\n return int(str(i)[-1])\n return len(mx)"] | {"fn_name": "base_finder", "inputs": [[["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]], [["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]], [["1", "2", "3", "4", "5", "6", "10", "11", "12", "13"]], [["301", "302", "303", "304", "305", "310", "311", "312", "313", "314"]], [["50", "51", "61", "53", "54", "60", "52", "62", "55", "56"]]], "outputs": [[10], [10], [7], [6], [7]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,382 |
def base_finder(seq):
|
cdb7ae643d22bf3daa088962d647f8e8 | UNKNOWN | Write a function that flattens an `Array` of `Array` objects into a flat `Array`. Your function must only do one level of flattening.
```python
flatten [1,2,3] # => [1,2,3]
flatten [[1,2,3],["a","b","c"],[1,2,3]] # => [1,2,3,"a","b","c",1,2,3]
flatten [[[1,2,3]]] # => [[1,2,3]]
``` | ["def flatten(lst):\n r = []\n for x in lst:\n if type(x) is list:\n r.extend(x)\n else:\n r.append(x)\n return r ", "def flatten(lst):\n return sum(([i] if not isinstance(i, list) else i for i in lst), [])", "from itertools import chain\ndef flatten(lst):\n try:\n return list(chain.from_iterable(lst))\n except:\n return lst", "from itertools import chain\n\ndef flatten(lst):\n try:\n return list(chain(*lst))\n except TypeError:\n return lst", "def flatten(lst):\n #your code here\\\n res = []\n for i in lst:\n if isinstance(i, list):\n res.extend(i)\n else:\n res.append(i)\n return res", "def flatten(lst):\n return [item for sublist in [seq if isinstance(seq, list) else [seq] for seq in lst] for item in sublist]", "def flatten(lst):\n return sum((([x], x)[isinstance(x, list)] for x in lst), [])", "def flatten(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", "def flatten(lst):\n return [x for xs in lst for x in (xs if isinstance(xs, list) else [xs])]", "def flatten(a):\n return [x for b in a for x in (b if type(b) is list else [b] ) ]"] | {"fn_name": "flatten", "inputs": [[[[[3], [4], [5]], [9], [9, 9], [8], [[1, 2, 3]]]], [[[[3], [4], [5]], [9], [9, 9], [8], [[1, 2, 3], [77777]]]], [[[[3], [4], [5]], [9], [9, 9], [8], [[1, 2, 3], [77777]], "a"]], [[[[3], [4], [5]], [9], [9, 9], [8], [[1, 2, 3], [77777]], [["a"]]]]], "outputs": [[[[3], [4], [5], 9, 9, 9, 8, [1, 2, 3]]], [[[3], [4], [5], 9, 9, 9, 8, [1, 2, 3], [77777]]], [[[3], [4], [5], 9, 9, 9, 8, [1, 2, 3], [77777], "a"]], [[[3], [4], [5], 9, 9, 9, 8, [1, 2, 3], [77777], ["a"]]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 1,291 |
def flatten(lst):
|
1d481edb02d7c719fa20dc49df5f7919 | UNKNOWN | Similar to the [previous kata](https://www.codewars.com/kata/string-subpattern-recognition-ii/), but this time you need to operate with shuffled strings to identify if they are composed repeating a subpattern
Since there is no deterministic way to tell which pattern was really the original one among all the possible permutations of a fitting subpattern, return a subpattern with sorted characters, otherwise return the base string with sorted characters (you might consider this case as an edge case, with the subpattern being repeated only once and thus equalling the original input string).
For example:
```python
has_subpattern("a") == "a"; #no repeated pattern, just one character
has_subpattern("aaaa") == "a" #just one character repeated
has_subpattern("abcd") == "abcd" #base pattern equals the string itself, no repetitions
has_subpattern("babababababababa") == "ab" #remember to return the base string sorted"
has_subpattern("bbabbaaabbaaaabb") == "ab" #same as above, just shuffled
```
If you liked it, go for either the [previous kata](https://www.codewars.com/kata/string-subpattern-recognition-ii/) or the [next kata](https://www.codewars.com/kata/string-subpattern-recognition-iv/) of the series! | ["from collections import Counter\nfrom functools import reduce\nfrom fractions import gcd\n\ndef has_subpattern(s):\n c = Counter(s)\n m = reduce(gcd, c.values())\n return ''.join(sorted(k*(v//m) for k,v in c.items()))", "from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\n\ndef has_subpattern(string):\n count = Counter(string)\n n = reduce(gcd, count.values())\n return \"\".join(sorted(c * (i // n) for c, i in count.items()))", "from functools import reduce as R\nfrom collections import Counter as C\nfrom math import gcd as G\ndef has_subpattern(s): \n s = C(s)\n k = R(G,set(s.values()))\n li = [i * (j // k) for i, j in s.items()]\n return ''.join(sorted(li))", "from collections import Counter as C\nfrom functools import reduce as R\nfrom fractions import gcd\n\n\ndef has_subpattern(s):\n c = C(s)\n a = R(gcd, c.values())\n return \"\".join(sorted([x * int(c[x] / a) for x in c]))", "from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\ndef has_subpattern(string):\n c = Counter(string)\n m = reduce(gcd, c.values())\n for key in c:\n c[key] //= m\n return ''.join(sorted(c.elements()))", "from collections import Counter; from functools import reduce; gcd=lambda a,b: gcd(b,a%b) if b else a; has_subpattern=lambda s: (lambda r: (lambda g: \"\".join(k*(v//g) for k,v in sorted(r.items())))(reduce(gcd,r.values())))(Counter(s))", "from collections import Counter\nfrom math import gcd\nfrom functools import reduce\ndef has_subpattern(string):\n cnt = Counter(string)\n v = reduce(gcd, cnt.values())\n return ''.join(sorted(k * (n // v) for k, n in cnt.items()))", "from collections import Counter\nfrom functools import reduce\nfrom math import gcd\ndef has_subpattern(string):\n if len(string)<2:\n return string\n c=Counter(string)\n x=reduce(gcd,c.values())\n if x==1:\n return ''.join(sorted(string))\n return ''.join(k*(c[k]//x) for k in sorted(c.keys()))", "from collections import Counter\nfrom functools import reduce\nfrom math import gcd\n\n\ndef has_subpattern(string): \n chars_frequency = Counter(string)\n greatercd = reduce(gcd, chars_frequency.values())\n charslist = sorted(chars_frequency.items())\n pattern = \"\"\n for char, frequency in charslist:\n pattern += char * (frequency // greatercd)\n return pattern", "from math import gcd\nfrom functools import reduce\n\ndef has_subpattern(s):\n d = {k:s.count(k) for k in set(s)}\n g = reduce(gcd,d.values())\n return ''.join(sorted(k*(v//g) for k,v in d.items()))"] | {"fn_name": "has_subpattern", "inputs": [["a"], ["aaaa"], ["abcd"], ["babababababababa"], ["bbabbaaabbaaaabb"], ["123a123a123a"], ["123A123a123a"], ["12aa13a21233"], ["12aa13a21233A"], ["abcdabcaccd"]], "outputs": [["a"], ["a"], ["abcd"], ["ab"], ["ab"], ["123a"], ["111222333Aaa"], ["123a"], ["111222333Aaaa"], ["aaabbccccdd"]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 2,650 |
def has_subpattern(string):
|
6711a94afdb19b18ba5e3c9b583ac350 | UNKNOWN | Write a function, `gooseFilter` / `goose-filter` / `goose_filter` /` GooseFilter`, that takes an array of strings as an argument and returns a filtered array containing the same elements but with the 'geese' removed.
The geese are any strings in the following array, which is pre-populated in your solution:
```python
geese = ["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"]
```
For example, if this array were passed as an argument:
```python
["Mallard", "Hook Bill", "African", "Crested", "Pilgrim", "Toulouse", "Blue Swedish"]
```
Your function would return the following array:
```python
["Mallard", "Hook Bill", "Crested", "Blue Swedish"]
```
The elements in the returned array should be in the same order as in the initial array passed to your function, albeit with the 'geese' removed. Note that all of the strings will be in the same case as those provided, and some elements may be repeated. | ["geese = {\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"}\n\ndef goose_filter(birds):\n return [bird for bird in birds if bird not in geese]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\ndef goose_filter(birds):\n return list(filter(lambda x: x not in geese, birds))", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\ndef goose_filter(birds):\n return [b for b in birds if b not in geese]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\ndef goose_filter(birds):\n return[x for x in birds if x not in geese]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n \n for j in geese: #For each element in geese\n for i in birds: #For each element in birds \n if i == j:\n birds.remove(i) \n return birds", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\ndef goose_filter(birds):\n return [bird for bird in birds if bird not in geese]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n l=[]\n for i in birds:\n if i not in geese:\n l.append(i)\n return(l)", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\ndef goose_filter(birds):\n return [i for i in birds if i not in geese]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n new_list=[]\n \n for word in geese:\n for words in birds:\n if word == words:\n birds.remove(word)\n return birds", "geese = [\"Roman Tufted\", \"African\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n for goose in geese:\n for bir in birds:\n if goose == bir:\n birds.remove(bir)\n return birds\n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\ndef goose_filter(birds):\n for i in range(len(geese)):\n if geese[i] in birds:\n ind = birds.index(geese[i])\n birds.pop(ind)\n return birds\n\n", "goose_filter=lambda l:[e for e in l if e[:3]not in\"AfrRomTouPilSte\"]", "goose_filter=lambda birds:[bird for bird in birds if bird not in [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]]", "goose_filter=lambda x:[g for g in x if g[:3]not in\"AfrRomTouPilSte\"]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\ndef goose_filter(birds):\n output = []\n for a in birds:\n if a not in geese:\n output.append(a);\n return output", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef filtergeese(bird):\n if bird in geese:\n return False\n else:\n return True \n\ndef goose_filter(birds): \n return list(filter(filtergeese, birds))\n \n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n return list(filter(lambda v: not geese.__contains__(v),birds))", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n result = [element for element in birds if not element in geese]\n return result", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n list = []\n for x in birds:\n if x not in geese:\n list.append(x)\n return list", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n for x in geese:\n for x in birds:\n if x in geese:\n birds.remove(x)\n return(birds)\n", "goose_filter = lambda gl: [g for g in gl if g not in [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]]\n", "def goose_filter(birds):\n return [i for i in birds if i not in [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]]", "goose_filter=lambda b: [e for e in b if e not in [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n result = []\n for i in birds:\n if i != geese[0] and i != geese[1] and i != geese[2] and i != geese[3] and i != geese[4]:\n result.append(i)\n return result\n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n return [el for i, el in enumerate(birds) if el not in geese] ", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n for word in geese:\n while word in birds:\n birds.remove(word)\n return birds", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\nimport re\n\ndef goose_filter(birds):\n listn = []\n for i in birds:\n if i not in geese:\n listn.append(i)\n return listn", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n oplst = []\n for bird in birds:\n if bird not in geese:\n oplst.append(bird)\n return oplst", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n filtered_list = []\n for x in birds:\n if x not in geese:\n filtered_list.append(x)\n return (filtered_list) ", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n result = []\n for i in geese:\n for j in birds:\n if i == j:\n birds.remove(i)\n #your code here\n return birds\n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n return list(el for el in birds if el not in geese)", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n s = []\n for el in birds:\n if not el in geese: s.append(el)\n return s", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n l = []\n for n in birds:\n if n not in geese:\n l.append(n)\n return l", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n return [brd for brd in birds if brd not in geese]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n bird = [x for x in birds if x not in geese]\n return bird\n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n b = sorted( set(birds), key=birds.index )\n return [s for s in b if s not in geese]\n", "def goose_filter(l):\n return [b for b in l if b[:3] not in ['Afr','Rom','Tou','Pil','Ste']]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n #your code here\n arr = []\n for i in birds:\n if i in geese:\n continue\n else:\n arr.append(i)\n return arr", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n return [el for el in birds if not el in geese]", "geese = set([\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"])\n\ndef goose_filter(birds):\n return [*filter(lambda s: s not in geese, birds)] ", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n without_geese = []\n for i in birds:\n if i not in geese:\n without_geese.append(i)\n return without_geese", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n return [x for x in birds if x not in set(geese)]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n res = []\n for string in birds:\n if string not in geese:\n res.append(string)\n return res", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds): return [non_geese for non_geese in birds if non_geese not in geese]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n filtered_birds = []\n for i in range(len(birds)):\n if birds[i] in geese:\n None\n else:\n filtered_birds.append(birds[i])\n return filtered_birds", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n return list(birds[i] for i in range(len(birds)) if birds[i] not in geese)", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\n\ndef goose_filter(birds):\n result = list(filter(lambda x:x not in geese,birds))\n return result", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n x = []\n for i in range(len(birds)):\n if birds[i] in geese:\n x = x\n else:\n x.append(birds[i])\n return x", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\nfrom itertools import filterfalse\ndef goose_filter(birds):\n return list(filterfalse(lambda x: x in geese, birds))", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\nimport itertools\ndef goose_filter(birds):\n a=[n for n in birds if n not in geese]\n return a", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n '''we will iterate through the array preserving order while excluding the aforemntioned geese list'''\n return [x for x in birds if x not in geese]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\ndef goose_filter(birds):\n lonely_birds = []\n for i in birds:\n if i not in geese:\n lonely_birds.append(i)\n return lonely_birds", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n for elem in geese:\n for bird in birds:\n if elem in birds:\n birds.remove(elem)\n return birds", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n return [bird for bird in birds if bird not in geese]\n # returns every element in (birds) that is not in (geese)\n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n geeseLess = []\n for i in range(len(birds)): \n if birds[i] not in geese:\n geeseLess.append(birds[i])\n return geeseLess", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n return [m for m in birds if m not in geese]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n n = []\n for i in birds:\n if i not in geese:\n n.append(i)\n return n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n notgeese = []\n for el in birds:\n if el not in geese:\n notgeese.append(el)\n return notgeese", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n new_birds = []\n for animal in birds:\n if animal not in geese:\n new_birds.append(animal)\n return new_birds", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n anew = [i for i in birds if i not in geese]\n return anew\n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n n = []\n for bird in birds:\n if bird not in geese:\n n.append(bird)\n return n\n # go through birds list if matches any in list drop string\n # loop through all birds match place in lists\n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds: list) -> list:\n return [x for x in birds if x not in geese]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n out = []\n for el1 in birds:\n if el1 not in geese:\n out.append(el1)\n return out", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\ndef goose_filter(birds):\n l=[]\n g=[]\n for x in birds:\n if x in geese:\n l.append(birds.index(x))\n for i in range(len(birds)):\n if i not in l:\n g.append(birds[i])\n return g", "\n\ndef goose_filter(birds):\n geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n new = []\n for i in birds:\n if i in geese:\n continue\n else:\n new.append(i)\n return new\n", "def goose_filter(birds):\n geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n new=[]\n for x in birds:\n if x not in geese:\n new.append(x)\n return new", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n return [bird for bird in birds if bird not in (set(birds) & set(geese))]\n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n return [words for words in birds if all(char not in words for char in geese)]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n ans=birds.copy()\n for i in birds:\n if i in geese:\n ans.remove(i)\n return ans", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n return list([w for w in birds if w not in geese])\n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n \n delete_array = []\n \n for i in range(len(birds)):\n \n if birds[i] in geese:\n \n delete_array.append(birds[i])\n \n for i in delete_array:\n \n\n if i in birds:\n \n birds.remove(i)\n\n #print(delete_array)\n \n return birds", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n #your code here\n l = []\n for i in range(0,len(birds)):\n if birds[i] not in geese:\n l.append(birds[i])\n return(l)", "def goose_filter(bs):\n return [x for x in bs if x not in [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n newlist = []\n for eachvalue in birds:\n if eachvalue in geese:\n continue\n else:\n newlist.append(eachvalue)\n return newlist", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n answer = []\n for bird in birds:\n if bird in geese:\n continue\n answer.append(bird) \n return answer", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n arr = []\n for strn in birds:\n if strn not in geese:\n arr.append(strn)\n return arr ", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\nc =[]\ndef goose_filter(birds):\n for x in geese:\n if x in birds:\n birds.remove(x)\n return birds\n #your code here\n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n ls=[]\n for i in birds:\n if i in geese:\n continue\n ls.append(i)\n return ls", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n for g in geese:\n for s in birds:\n if s == g:\n birds.remove(g)\n return birds", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n for y in geese:\n for x in birds:\n if x == y:\n birds.remove(x)\n \n return birds", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(words):\n clean = []\n \n for x in words:\n if x not in geese:\n clean.append(x)\n return clean", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n for i in geese:\n try:\n birds.remove(i)\n except:\n pass\n return birds", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n s = list()\n for b in birds:\n if b in geese:\n continue\n else:\n s.append(b)\n return s", "a = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(b):\n for x in a:\n for x in b:\n if x in a:\n b.remove(x)\n return b ", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n #your code here\n new = []\n for bird in birds:\n if bird not in geese:\n new.append(bird)\n return new", "# change list to set to speed up search\ngeese = {\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"}\n\ndef goose_filter(birds):\n return [x for x in birds if x not in geese]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\n# given an array of strings, return a new array removing strings found in geese\n# The elements in the returned array should be in the same order as in the initial array passed to your function\n# some elements may be repeated and all will be in the same case\n\n# input - array of strings\n# output - array of strings\n\ndef goose_filter(birds):\n# return element in birds if element is not in geese\n return [x for x in birds if x not in geese]", "\n\ndef goose_filter(birds):\n return [x for x in birds if x not in [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n salir = False\n while salir != True:\n salir = True\n for b in birds:\n if b in geese:\n birds.remove(b)\n salir = False\n \n return birds", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n \n done = list()\n for word in birds:\n if word in geese:\n continue\n else:\n done.append(word)\n return done", "a = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(b):\n return [i for i in b if i not in a]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds:list) -> list:\n answer:list = []\n for bird in birds:\n if not bird in geese:\n answer.append(bird)\n return answer\n", "def goose_filter(birds):\n geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n for bir in geese:\n if bir in birds:\n birds.remove(bir)\n return birds", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n geese_set = set(geese)\n return [elem for elem in birds if elem not in geese_set]\n \n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n a=[]\n for i in birds:\n if i not in geese:\n a.append(i)\n return a\n# return [b for b in birds if b not in geese]\n", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n list = []\n for word in birds:\n if not word in geese:\n list.append(word)\n return list", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n print(birds)\n return [bird for bird in birds if bird not in geese]", "geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n\ndef goose_filter(birds):\n for y in geese:\n if y in birds:\n birds.remove(y)\n return birds", "def goose_filter(birds):\n geese = [\"African\", \"Roman Tufted\", \"Toulouse\", \"Pilgrim\", \"Steinbacher\"]\n newList = []\n for word in birds:\n if word not in geese:\n newList += [word]\n return newList"] | {"fn_name": "goose_filter", "inputs": [[["Mallard", "Hook Bill", "African", "Crested", "Pilgrim", "Toulouse", "Blue Swedish"]], [["Mallard", "Barbary", "Hook Bill", "Blue Swedish", "Crested"]], [["African", "Roman Tufted", "Toulouse", "Pilgrim", "Steinbacher"]]], "outputs": [[["Mallard", "Hook Bill", "Crested", "Blue Swedish"]], [["Mallard", "Barbary", "Hook Bill", "Blue Swedish", "Crested"]], [[]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 22,112 |
def goose_filter(birds):
|
4ed74ab92fcab85cf5a69f9ce07952cd | UNKNOWN | Hi! Welcome to my first kata.
In this kata the task is to take a list of integers (positive and negative) and split them according to a simple rule; those ints greater than or equal to the key, and those ints less than the key (the itself key will always be positive).
However, in this kata the goal is to sort the numbers IN PLACE, so DON'T go messing around with the order in with the numbers appear.
You are to return a nested list. If the list is empty, simply return an empty list.
Confused? Okay, let me walk you through an example...
The input is: [1, 1, 1, 0, 0, 6, 10, 5, 10], the key is: 6
Okay so the first five numbers are less than the key, 6, so we group them together.
[1, 1, 1, 0, 0]
The next two numbers, 6 & 10, are both >= 6 to they belong in a seperate group, which we will add to the first group. Like so:
[[1, 1, 1, 0, 0], [6, 10]]
The next two numbers are 5 & 10. Since the key is 6 these two numbers form seperate groups, which we will add to the previous result. like so:
[[1, 1, 1, 0, 0], [6, 10], [5], [10]]
And voila! We're done.
Here are a few more basic examples:
group_ints([1, 0], key= 0)
--> [[1,0]]
group_ints([1, 0, -1, 5], key= 0)
--> [[1, 0], [-1], [5]]
group_ints([1, 0, -1, 5], key= 5)
--> [[1, 0, -1], [5]]
Good luck guys/gals! | ["from itertools import groupby\n\n\ndef group_ints(lst, key=0):\n return [list(g) for _, g in groupby(lst, lambda a: a < key)]\n\n\n# PEP8: function name should use snake_case\ngroupInts = group_ints", "from itertools import groupby\n\ndef group_ints(lst, key=0):\n return [list(g) for _, g in groupby(lst, key.__gt__)]", "def group_ints(lst, key=0):\n from itertools import groupby\n return [list(group) for _, group in groupby(lst, lambda v: v >= key)]\n", "from itertools import groupby\nfrom operator import itemgetter\n\ndef group_ints(lst, key=0):\n # I'm keeping the cat!\n #\n # _ |\\_\n # \\` ..\\\n # __,.-\" =__Y=\n # .\" )\n # _ / , \\/\\_\n # ((____| )_-\\ \\_-`\n # `-----'`-----` `--`\n \n return list(map(list, map(itemgetter(1), groupby(lst, key.__gt__))))", "def group_ints(lst, key=0):\n first = []\n second = []\n final = []\n for i in lst:\n if i < key:\n if second:\n final.append(second)\n second = []\n first.append(i)\n else:\n if first:\n final.append(first)\n first = []\n second.append(i)\n if first:\n final.append(first)\n if second:\n final.append(second)\n return final\n", "def group_ints(lst, key=0):\n if not lst: return []\n l, index = [[lst[0]]], 0\n for x in lst[1:]:\n if l[index][-1] < key and x < key:\n l[index].append(x)\n elif l[index][-1] >= key and x >= key:\n l[index].append(x)\n else:\n l.append([x])\n index += 1\n return l", "class Nest():\n \n def __init__(self, key, list):\n self.key = key\n self.list = list\n self.chen = 0\n self.temp_list = []\n self.new_list = []\n \n self.ACT = { \n 1:self.__ap_end__, \n 0:self.__swich__ \n }\n \n self.OPER = { \n 0:lambda a, b: a < b ,\n 1:lambda a, b : a >= b \n }\n \n def __ap_end__(self, c_list, element ): \n c_list.append(element)\n \n def __swich__(self, c_list, element):\n if c_list: \n self.__ap_end__(self.new_list, c_list)\n self.temp_list = [element]\n self.chen = not self.chen\n \n def do_sort(self ):\n if not self.list: return []\n for e in self.list: \n self.ACT[ self.OPER[self.chen]( e,self.key ) ]( self.temp_list, e )\n return self.new_list + [self.temp_list]\n\ngroup_ints = lambda lst, key=0 : Nest( key, lst ).do_sort() ", "def group_ints(lst, key=0):\n if not lst: return lst\n oper, temp, last, chen = ['<','>='], [], [], 0\n for e in lst:\n if eval(f'{e}{oper[chen]}{key}'):\n temp.append(e)\n else:\n if temp: last.append(temp)\n temp, chen = [e], not chen\n return last + [temp]\n", "from itertools import groupby\n\ndef group_ints(lst, key=0):\n return [list(grp) for k, grp in groupby(lst, key=lambda x: x < key)]", "from itertools import groupby\n\ndef group_ints(lst, key=0):\n return [list(g) for _, g in groupby(lst, lambda x: x < key)]\n"] | {"fn_name": "group_ints", "inputs": [[[], 0], [[1], 1], [[1, 2, 3], 0], [[1, 2, 3], 3], [[1, 1, 1, 0, 0, 6, 10, 5, 10], 6]], "outputs": [[[]], [[[1]]], [[[1, 2, 3]]], [[[1, 2], [3]]], [[[1, 1, 1, 0, 0], [6, 10], [5], [10]]]]} | INTRODUCTORY | PYTHON3 | CODEWARS | 3,404 |
def group_ints(lst, key=0):
|
fe2779c7fbca7fb1f8ae6e1fa58faed5 | UNKNOWN | Every non-negative integer N has a binary representation. For example, 5 can be represented as "101" in binary, 11 as "1011" in binary, and so on. Note that except for N = 0, there are no leading zeroes in any binary representation.
The complement of a binary representation is the number in binary you get when changing every 1 to a 0 and 0 to a 1. For example, the complement of "101" in binary is "010" in binary.
For a given number N in base-10, return the complement of it's binary representation as a base-10 integer.
Example 1:
Input: 5
Output: 2
Explanation: 5 is "101" in binary, with complement "010" in binary, which is 2 in base-10.
Example 2:
Input: 7
Output: 0
Explanation: 7 is "111" in binary, with complement "000" in binary, which is 0 in base-10.
Example 3:
Input: 10
Output: 5
Explanation: 10 is "1010" in binary, with complement "0101" in binary, which is 5 in base-10.
Note:
0 <= N < 10^9
This question is the same as 476: https://leetcode.com/problems/number-complement/ | ["class Solution:\n def bitwiseComplement(self, N: int) -> int:\n return (1 << len(bin(N))-2) - N - 1", "class Solution:\n def bitwiseComplement(self, N: int) -> int:\n \n if N==0:\n return 1\n \n dummy_num=N\n \n n=0\n while(dummy_num):\n n+=1\n dummy_num>>=1\n \n ans=0\n \n for i in range(n-1,-1,-1):\n \n if (N>>i)&1==0:\n ans|=(1<<i)\n \n \n return ans", "class Solution:\n def bitwiseComplement(self, N: int) -> int:\n binn = bin(N)\n binn = binn[2:]\n binn = binn.replace('0','#')\n binn = binn.replace('1','0')\n binn = binn.replace('#','1')\n return int(binn,2)"] | {"fn_name": "bitwiseComplement", "inputs": [[5]], "outputs": [2]} | INTRODUCTORY | PYTHON3 | LEETCODE | 810 |
class Solution:
def bitwiseComplement(self, N: int) -> int:
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.