problem_id int64 0 4.75k | question stringlengths 146 5.9k | solutions stringlengths 181 1.12M | input_output stringlengths 236 35.4M | difficulty stringclasses 3
values | url stringlengths 47 54 | starter_code stringclasses 158
values | num_tests int64 16 16 |
|---|---|---|---|---|---|---|---|
2,957 | Write a function `getDrinkByProfession`/`get_drink_by_profession()` that receives as input parameter a string, and produces outputs according to the following table:
Input
Output
"Jabroni"
"Patron Tequila"
"School Counselor"
"Anything with Alcohol"
"Programmer"
"Hipster Craft Beer"
"Bike Gang Member"
"Mo... | ["d = {\n \"jabroni\": \"Patron Tequila\",\n \"school counselor\": \"Anything with Alcohol\",\n \"programmer\": \"Hipster Craft Beer\",\n \"bike gang member\": \"Moonshine\",\n \"politician\": \"Your tax dollars\",\n \"rapper\": \"Cristal\"\n}\n\ndef get_drink_by_profession(s):\n return d.get(s.low... | {"fn_name": "get_drink_by_profession", "inputs": [["jabrOni"], ["scHOOl counselor"], ["prOgramMer"], ["bike ganG member"], ["poLiTiCian"], ["rapper"], ["pundit"], ["Pug"], ["jabrOnI"], ["scHOOl COUnselor"], ["prOgramMeR"], ["bike GanG member"], ["poLiTiCiAN"], ["RAPPer"], ["punDIT"], ["pUg"]], "outputs": [["Patron Tequ... | introductory | https://www.codewars.com/kata/568dc014440f03b13900001d |
def get_drink_by_profession(param):
| 16 |
2,959 | Coffee Vending Machine Problems [Part 1]
You have a vending machine, but it can not give the change back. You decide to implement this functionality. First of all, you need to know the minimum number of coins for this operation (i'm sure you don't want to return 100 pennys instead of 1$ coin).
So, find an optimal numb... | ["from functools import lru_cache\n\n\ndef optimal_number_of_coins(n, coins):\n @lru_cache(maxsize=None)\n def f(amount: int, idx: int) -> float:\n q, r = divmod(amount, coins[idx])\n if r == 0:\n return q\n elif amount < 0 or idx <= 0:\n return float(\"inf\")\n e... | {"fn_name": "optimal_number_of_coins", "inputs": [["1", ["1", "2", "5", "10"]], ["5", ["1", "2", "5", "10"]], ["6", ["1", "3", "5", "10"]], ["10", ["1", "2", "5", "10"]], ["53", ["1", "2", "5", "25"]], ["7", ["1", "1", "1", "25"]], ["76", ["1", "3", "4", "10"]], ["33", ["1", "6", "9", "10"]], ["63", ["1", "2", "9", "10... | introductory | https://www.codewars.com/kata/586b1b91c66d181c2c00016f |
def optimal_number_of_coins(n, coins):
| 16 |
2,975 | Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words (that don't contain WUB). To make the dubstep remix of this so... | ["def song_decoder(song):\n return \" \".join(song.replace('WUB', ' ').split())", "def song_decoder(song):\n return \" \".join(song.replace('WUB', ' ').split()).strip()\n", "def song_decoder(song):\n import re\n return re.sub('(WUB)+', ' ', song).strip()\n", "def song_decoder(song):\n return ' '.join([a ... | {"fn_name": "song_decoder", "inputs": [["AWUBBWUBC"], ["AWUBWUBWUBBWUBWUBWUBC"], ["RWUBWUBWUBLWUB"], ["WUBJKDWUBWUBWBIRAQKFWUBWUBYEWUBWUBWUBWVWUBWUB"], ["QWUBQQWUBWUBWUBIWUBWUBWWWUBWUBWUBJOPJPBRH"], ["WUBYYRTSMNWUWUBWUBWUBCWUBWUBWUBCWUBWUBWUBFSYUINDWOBVWUBWUBWUBFWUBWUBWUBAUWUBWUBWUBVWUBWUBWUBJB"], ["AWUBBWUBCWUBD"], ["... | introductory | https://www.codewars.com/kata/551dc350bf4e526099000ae5 |
def song_decoder(song):
| 16 |
2,976 | This time no story, no theory. The examples below show you how to write function `accum`:
**Examples:**
```
accum("abcd") -> "A-Bb-Ccc-Dddd"
accum("RqaEzty") -> "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
accum("cwAt") -> "C-Ww-Aaa-Tttt"
```
The parameter of accum is a string which includes only letters from `a..z` and `A..... | ["def accum(s):\n return '-'.join(c.upper() + c.lower() * i for i, c in enumerate(s))", "def accum(s):\n return '-'.join((a * i).title() for i, a in enumerate(s, 1))\n", "def accum(s):\n output = \"\"\n for i in range(len(s)):\n output+=(s[i]*(i+1))+\"-\"\n return output.title()[:-1]", "def accum(... | {"fn_name": "accum", "inputs": [["ZpglnRxqenU"], ["NyffsGeyylB"], ["MjtkuBovqrU"], ["EvidjUnokmM"], ["VwhvtHtrxfE"], ["KurgiKmkphY"], ["NctlfBlnmfH"], ["VoywwSpqidE"], ["VbaixFpxdcO"], ["JrhfdMtchiH"], ["JiwpcSwslvW"], ["EagpiEvmabJ"], ["RznlcEmuxxP"], ["DriraMtedfB"], ["BjxseRxgtjT"], ["EquhxOswchE"]], "outputs": [["Z... | introductory | https://www.codewars.com/kata/5667e8f4e3f572a8f2000039 |
def accum(s):
| 16 |
3,015 | Given a credit card number we can determine who the issuer/vendor is with a few basic knowns.
```if:python
Complete the function `get_issuer()` that will use the values shown below to determine the card issuer for a given card number. If the number cannot be matched then the function should return the string `Unknown`... | ["def get_issuer(number):\n s = str(number)\n return (\"AMEX\" if len(s)==15 and s[:2] in (\"34\",\"37\") else\n \"Discover\" if len(s)==16 and s.startswith(\"6011\") else\n \"Mastercard\" if len(s)==16 and s[0]==\"5\" and s[1] in \"12345\" else\n \"VISA\" if len(s) ... | {"fn_name": "get_issuer", "inputs": [["4111111111111111"], ["4111111111111"], ["4012888888881881"], ["41111111111111"], ["411111111111111"], ["378282246310005"], ["348282246310005"], ["6011111111111117"], ["5105105105105100"], ["5105105105105106"], ["5205105105105106"], ["5305105105105106"], ["5405105105105106"], ["550... | introductory | https://www.codewars.com/kata/5701e43f86306a615c001868 |
def get_issuer(number):
| 16 |
3,016 | Check if given chord is minor or major.
_____________________________________________________________
Rules:
1. Basic minor/major chord have three elements.
2. Chord is minor when interval between first and second element equals 3 and between second and third -> 4.
3. Chord is major when interval between first and ... | ["from itertools import product\n\nNOTES = [['C'], ['C#', 'Db'], ['D'], ['D#', 'Eb'], ['E'], ['F'], ['F#', 'Gb'], ['G'], ['G#', 'Ab'], ['A'], ['A#', 'Bb'], ['B']]*2\nconfig = [('Major', 4), ('Minor', 3)]\n\nDCT_CHORDS = {c: mode for mode, offset in config\n for i in range(len(NOTES)//2)\n ... | {"fn_name": "minor_or_major", "inputs": [["E G# B"], ["F# A# C#"], ["Bb D F"], ["C Eb G"], ["C# E G#"], ["E G B"], ["F# A C#"], ["G Bb D"], ["G# B D#"], ["Bb Db F"], ["A C D"], ["A C# D#"], ["D F A G"], ["D F"], ["C H G"], ["G E C"]], "outputs": [["Major"], ["Major"], ["Major"], ["Minor"], ["Minor"], ["Minor"], ["Minor... | introductory | https://www.codewars.com/kata/57052ac958b58fbede001616 |
def minor_or_major(chord):
| 16 |
3,045 | Given 2 elevators (named "left" and "right") in a building with 3 floors (numbered `0` to `2`), write a function `elevator` accepting 3 arguments (in order):
- `left` - The current floor of the left elevator
- `right` - The current floor of the right elevator
- `call` - The floor that called an elevator
It should re... | ["def elevator(left, right, call):\n return \"left\" if abs(call - left) < abs(call - right) else \"right\"", "def elevator(left, right, call):\n if abs(left-call) >= abs(right-call):\n return \"right\"\n else:\n return \"left\"", "def elevator(left, right, call):\n return \"left\" if abs(left... | {"fn_name": "elevator", "inputs": [["0", "1", "0"], ["0", "1", "1"], ["0", "0", "0"], ["0", "2", "1"], ["0", "0", "1"], ["1", "0", "0"], ["1", "0", "2"], ["1", "1", "0"], ["1", "1", "1"], ["1", "1", "2"], ["1", "2", "0"], ["1", "2", "1"], ["1", "2", "2"], ["2", "0", "0"], ["2", "1", "0"], ["2", "2", "0"]], "outputs": [... | introductory | https://www.codewars.com/kata/5c374b346a5d0f77af500a5a |
def elevator(left, right, call):
| 16 |
3,066 | In this Kata, you will be given a mathematical string and your task will be to remove all braces as follows:
```Haskell
solve("x-(y+z)") = "x-y-z"
solve("x-(y-z)") = "x-y+z"
solve("u-(v-w-(x+y))-z") = "u-v+w+x+y-z"
solve("x-(-y-z)") = "x+y+z"
```
There are no spaces in the expression. Only two operators are given: `"... | ["from functools import reduce\n\ndef solve(st):\n res, s, k = [], \"\", 1\n for ch in st:\n if ch == '(': res.append(k); k = 1\n elif ch == ')': res.pop(); k = 1\n elif ch == '-': k = -1\n elif ch == '+': k = 1\n else: s+= '-'+ch if (reduce(lambda a,b: a * b,res,1) * (1 if k ==... | {"fn_name": "solve", "inputs": [["a-(b)"], ["a-(-b)"], ["a+(-b)"], ["(((((((m-(-(((((t)))))))))))))"], ["-x"], ["-(-(x))"], ["-((-x))"], ["-(-(x-y))"], ["-(x-y)"], ["x-(y+z)"], ["x-(-y-z)"], ["x-(-((-((((-((-(-(-y)))))))))))"], ["u-(v-w+(x+y))-z"], ["x-(s-(y-z))-(a+b)"], ["u+(g+v)+(r+t)"], ["q+(s-(x-o))-(t-(w-a))"]], "... | introductory | https://www.codewars.com/kata/5a3bedd38f27f246c200005f |
def solve(s):
| 16 |
3,087 | You will be given a string and you task is to check if it is possible to convert that string into a palindrome by removing a single character. If the string is already a palindrome, return `"OK"`. If it is not, and we can convert it to a palindrome by removing one character, then return `"remove one"`, otherwise return... | ["def solve(s):\n isOK = lambda x: x == x[::-1]\n \n return (\"OK\" if isOK(s) else\n \"remove one\" if any( isOK(s[:i]+s[i+1:]) for i in range(len(s)) ) else\n \"not possible\")", "def solve(s):\n if s == s[::-1]:\n return 'OK'\n for i in range(len(s)):\n if s[:i] + ... | {"fn_name": "solve", "inputs": [["abba"], ["abbaa"], ["abbaab"], ["madmam"], ["raydarm"], ["hannah"], ["baba"], ["babab"], ["bababa"], ["abcbad"], ["abcdba"], ["dabcba"], ["abededba"], ["abdcdeba"], ["abcdedba"], ["abbcdedba"]], "outputs": [["OK"], ["remove one"], ["not possible"], ["remove one"], ["not possible"], ["O... | introductory | https://www.codewars.com/kata/5a2c22271f7f709eaa0005d3 |
def solve(s):
| 16 |
3,148 | # Story
John found a path to a treasure, and while searching for its precise location he wrote a list of directions using symbols `"^"`, `"v"`, `"<"`, `">"` which mean `north`, `east`, `west`, and `east` accordingly. On his way John had to try many different paths, sometimes walking in circles, and even missing the tr... | ["def simplify(p):\n new_p=[(0,0)]\n new_str=''\n x=0\n y=0\n for i in p:\n if i == '<':\n x-=1\n elif i == '>':\n x+=1\n elif i == '^':\n y+=1\n elif i == 'v':\n y-=1\n if (x,y) not in new_p:\n new_p.append((x,y))\... | {"fn_name": "simplify", "inputs": [["<>>"], [""], ["v>^<"], [">>>>"], ["^>>>>v"], ["<^^>v<^^^"], ["<^>>v<"], ["<^<<^^>>vv<<<>^^^v^"], ["v<<<<<^^^^^v>v>v>v>v>>"], [">^>^>^>^>^>^>v>v>v>v>v>v>v>v<"], ["^^^>>>>>>^^^<<<vvv<<<vvv"], ["^^^>>>>>>^^^<<<vvv<<<vv"], [">vv<<<^^^^>>>>>vvvvvv<<<<<<^^^^^^^^>>>>vv"], [">vv<<<^^^^>>>>>... | introductory | https://www.codewars.com/kata/56bcafba66a2ab39e6001226 |
def simplify(path):
| 16 |
3,155 | Mr. Square is going on a holiday. He wants to bring 2 of his favorite squares with him, so he put them in his rectangle suitcase.
Write a function that, given the size of the squares and the suitcase, return whether the squares can fit inside the suitcase.
```Python
fit_in(a,b,m,n)
a,b are the sizes of the 2 squares
m... | ["def fit_in(a, b, m, n):\n return max(a, b) <= min(m, n) and a + b <= max(m, n)", "def fit_in(a,b,m,n):\n return a+b<=max(m,n) and max(a,b)<=min(m,n)", "def fit_in(a,b,m,n):\n if m<a+b and n<a+b:\n return False\n if m<max([a,b]) or n<max([a,b]):\n return False\n return True", "def fit_in(a,b,m... | {"fn_name": "fit_in", "inputs": [["1", "2", "1", "2"], ["6", "5", "8", "7"], ["6", "6", "12", "6"], ["7", "1", "7", "8"], ["7", "2", "9", "7"], ["1", "2", "4", "3"], ["1", "4", "3", "2"], ["2", "1", "4", "3"], ["2", "3", "4", "1"], ["2", "4", "3", "1"], ["3", "1", "4", "2"], ["3", "4", "1", "2"], ["4", "2", "3", "1"], ... | introductory | https://www.codewars.com/kata/5c556845d7e0334c74698706 |
def fit_in(a,b,m,n):
| 16 |
3,159 | An array is defined to be `odd-heavy` if it contains at least one odd element and every element whose value is `odd` is greater than
every even-valued element.
eg.
```
Array [11,4,9,2,8] is odd-heavy
because:- its odd elements [11,9] are greater than all the even elements [4,2,8]
Array [11,4,9,2,3,10] is not odd-h... | ["def is_odd_heavy(arr):\n maxEven, minOdd = ( f(filter(lambda n: n%2 == v, arr), default=float(\"-inf\")) for f,v in ((max, 0), (min,1)) )\n return maxEven < minOdd", "odd = lambda x: x&1\n\ndef is_odd_heavy(arr):\n it = iter(sorted(arr))\n return any(map(odd, it)) and all(map(odd, it))", "def is_odd_heavy... | {"fn_name": "is_odd_heavy", "inputs": [[["1", "-2", "-1", "2"]], [["-3", "2", "1", "3", "-1", "-2"]], [["3", "4", "-2", "-3", "-2"]], [["-1", "-2", "21"]], [["0", "0", "0", "0"]], [["0", "-1", "1"]], [["0", "2", "3"]], [["0"]], [[]], [["1"]], [["0", "1", "2", "3", "4", "0", "-2", "-1", "-4", "-3"]], [["1", "-1", "3", "... | introductory | https://www.codewars.com/kata/59c7e477dcc40500f50005c7 |
def is_odd_heavy(arr):
| 16 |
3,165 | Introduction
It's been more than 20 minutes since the negligent waiter has taken your order for the house special prime tofu steak with a side of chili fries.
Out of boredom, you start fiddling around with the condiments tray. To be efficient, you want to be familiar with the choice of sauces and spices before your o... | ["from math import log2\n\ndef t(n):\n if n == 0:\n return 0\n k = int(log2(n))\n i = n - 2**k\n if i == 0:\n return (2**(2*k+1)+1) // 3\n else:\n return t(2**k) + 2*t(i) + t(i+1) - 1\n\ntoothpick = t", "from functools import lru_cache\n\nmsb = lru_cache(maxsize=None)(lambda n: 1 << ... | {"fn_name": "toothpick", "inputs": [["0"], ["16"], ["32"], ["49"], ["327"], ["363"], ["366"], ["512"], ["656"], ["1038"], ["1052"], ["1222"], ["1235"], ["1302"], ["1974"], ["2048"]], "outputs": [["0"], ["171"], ["683"], ["1215"], ["52239"], ["60195"], ["62063"], ["174763"], ["209095"], ["699451"], ["700379"], ["757295"... | introductory | https://www.codewars.com/kata/5c258f3c48925d030200014b |
def toothpick(n):
| 16 |
3,203 | Implement `String#parse_mana_cost`, which parses [Magic: the Gathering mana costs](http://mtgsalvation.gamepedia.com/Mana_cost) expressed as a string and returns a `Hash` with keys being kinds of mana, and values being the numbers.
Don't include any mana types equal to zero.
Format is:
* optionally natural number re... | ["\nimport re\ndef parse_mana_cost(mana):\n n={c:mana.lower().count(c) for c in 'wubrg' if mana.lower().count(c)>0}\n m=re.split(r'\\D',mana) \n if sum(n.values())+sum([len(c) for c in m]) != len(mana): return None\n p = sum([int(c) for c in m if c!=''])\n if p>0: n['*']=p\n return n\n", "import re\... | {"fn_name": "parse_mana_cost", "inputs": [["1rw"], ["1uub"], ["2uuu"], ["3wbb"], ["4bg"], ["4rg"], ["4ur"], ["4uuu"], ["4wwbb"], ["5guu"], ["5urg"], ["5www"], ["6gg"], ["8b"], ["gwub"], ["ur"]], "outputs": [[{"*": "1", "w": "1", "r": "1"}], [{"*": "1", "u": "2", "b": "1"}], [{"*": "2", "u": "3"}], [{"*": "3", "w": "1",... | introductory | https://www.codewars.com/kata/5686004a2c7fade6b500002d |
def parse_mana_cost(mana):
| 16 |
3,222 | Given two integers `a` and `b`, which can be positive or negative, find the sum of all the numbers between including them too and return it. If the two numbers are equal return `a` or `b`.
**Note:** `a` and `b` are not ordered!
## Examples
```python
get_sum(1, 0) == 1 // 1 + 0 = 1
get_sum(1, 2) == 3 // 1 + 2 = 3... | ["def get_sum(a,b):\n return sum(range(min(a, b), max(a, b) + 1))", "def get_sum(a, b):\n return (a + b) * (abs(a - b) + 1) // 2", "def get_sum(a,b):\n soma=0\n if a==b:\n return a\n elif a > b:\n for i in range(b,a+1):\n soma += i\n return soma\n else:\n for i i... | {"fn_name": "get_sum", "inputs": [["0", "1"], ["1", "2"], ["5", "-1"], ["505", "4"], ["321", "123"], ["0", "-1"], ["-50", "0"], ["-1", "-5"], ["-5", "-5"], ["-505", "4"], ["-321", "123"], ["0", "0"], ["-5", "-1"], ["5", "1"], ["-17", "-17"], ["17", "17"]], "outputs": [["1"], ["3"], ["14"], ["127759"], ["44178"], ["-1"]... | introductory | https://www.codewars.com/kata/55f2b110f61eb01779000053 |
def get_sum(a,b):
| 16 |
3,242 | # Task
Given an integer array `arr`. Your task is to remove one element, maximize the product of elements.
The result is the element which should be removed. If more than one valid results exist, return the smallest one.
# Input/Output
`[input]` integer array `arr`
non-empty unsorted integer array. It contains p... | ["def maximum_product(arr):\n if arr.count(0) > 1:\n return min(arr)\n neg = [n for n in arr if n < 0]\n pos = [n for n in arr if n >= 0]\n if len(neg) % 2:\n return min(neg) if 0 in arr else max(neg)\n else:\n return min(pos) if pos else min(neg)", "from operator import mul\nfrom fu... | {"fn_name": "maximum_product", "inputs": [[["1", "2", "3"]], [["-1", "2", "-3"]], [["-1", "-2", "-3"]], [["-1", "-2", "-3", "-4"]], [["0", "1", "2", "3"]], [["0", "-1", "-2", "-3"]], [["0", "-1", "2", "3"]], [["0", "-1", "-2", "-3", "4"]], [["0", "0", "1"]], [["0", "-1", "1"]], [["0", "0", "-1", "1"]], [["0", "0", "0"]... | introductory | https://www.codewars.com/kata/592e2446dc403b132d0000be |
def maximum_product(arr):
| 16 |
3,250 | Bob is a theoretical coder - he doesn't write code, but comes up with theories, formulas and algorithm ideas. You are his secretary, and he has tasked you with writing the code for his newest project - a method for making the short form of a word. Write a function ```shortForm```(C# ```ShortForm```, Python ```short_for... | ["from re import *\ndef short_form(s):\n return sub(r\"(?<!^)[aeiou](?=.)\", '', s, flags=I)", "import re\n\ndef short_form(s):\n regex = re.compile(\"(?!^)[aeiou](?!$)\", re.I)\n return re.sub(regex, \"\", s)\n", "def short_form(s):\n return s[0]+''.join(x for x in s[1:-1] if x not in 'aeiouAEIOU')+s[-1]",... | {"fn_name": "short_form", "inputs": [["typhoid"], ["fire"], ["destroy"], ["kata"], ["codewars"], ["assert"], ["insane"], ["nice"], ["amazing"], ["incorrigible"], ["HeEllO"], ["inCRediBLE"], ["IMpOsSiblE"], ["UnInTENtiONAl"], ["AWESOme"], ["pygmy"]], "outputs": [["typhd"], ["fre"], ["dstry"], ["kta"], ["cdwrs"], ["assrt... | introductory | https://www.codewars.com/kata/570cbe88f616a8f4f50011ac |
def short_form(s):
| 16 |
3,259 | # Background
My TV remote control has arrow buttons and an `OK` button.
I can use these to move a "cursor" on a logical screen keyboard to type words...
# Keyboard
The screen "keyboard" layout looks like this
#tvkb {
width : 400px;
border: 5px solid gray; border-collapse: collapse;
}
#tvkb td {
... | ["import re\n\nKEYBOARD = \"abcde123fghij456klmno789pqrst.@0uvwxyz_/* \"\nMAP = {c: (i//8, i%8) for i,c in enumerate(KEYBOARD)}\n\n\ndef manhattan(*pts): return 1 + sum( abs(z2-z1) for z1,z2 in zip(*pts))\n\ndef toggle(m):\n ups, end = m.group(1), m.group(2)\n off = '*' * bool(end)\n return f'*{ups.lower(... | {"fn_name": "tv_remote", "inputs": [["solution"], ["for"], ["these"], ["words"], ["WORDS"], ["Your"], ["These"], ["A/A/A/A/"], ["1234567890"], ["a/a/a/a/"], ["ooo oXo ooo"], ["ooo ooo oXo"], ["ooo ooo ooX"], ["The Quick Brown Fox Jumps Over A Lazy Dog."], [" "], [" x X "]], "outputs": [["33"], ["12"], ["27"], [... | introductory | https://www.codewars.com/kata/5b277e94b6989dd1d9000009 |
def tv_remote(words):
| 16 |
3,278 | Given a string that includes alphanumeric characters ('3a4B2d') return the expansion of that string: The numeric values represent the occurrence of each letter preceding that numeric value. There should be no numeric characters in the final string. Empty strings should return an empty string.
The first occurrence of... | ["def string_expansion(s):\n m,n = '',1\n for j in s:\n if j.isdigit():\n n = int(j)\n else:\n m += j*n\n return m", "import re\n\ndef string_expansion(s):\n return ''.join(''.join(int(n or '1')*c for c in cc) for n,cc in re.findall(r'(\\d?)(\\D+)', s))\n", "def string_ex... | {"fn_name": "string_expansion", "inputs": [["3n6s7f3n"], ["0d4n8d2b"], ["3A5m3B3Y"], ["5M0L8P1"], ["2B"], ["A4g1b4d"], ["111111"], ["4d324n2"], ["6o23M32d"], ["23M31r2r2"], ["8494mM25K2A"], ["23D42B3A"], ["asdf"], ["43ibadsr3"], ["davhb327vuc"], [""]], "outputs": [["nnnssssssfffffffnnn"], ["nnnnddddddddbb"], ["AAAmmmmm... | introductory | https://www.codewars.com/kata/5ae326342f8cbc72220000d2 |
def string_expansion(s):
| 16 |
3,309 | ## Overview
Resistors are electrical components marked with colorful stripes/bands to indicate both their resistance value in ohms and how tight a tolerance that value has. If you did my Resistor Color Codes kata, you wrote a function which took a string containing a resistor's band colors, and returned a string identi... | ["c='black brown red orange yellow green blue violet gray white'.split()\ndef encode_resistor_colors(ohms_string):\n ohms = str(int(eval(ohms_string.replace('k', '*1000').replace('M', '*1000000').split()[0])))\n return '%s %s %s gold' % (c[int(ohms[0])], c[int(ohms[1])], c[len(ohms[2:])])", "COLORS = {'0': 'bla... | {"fn_name": "encode_resistor_colors", "inputs": [["10 ohms"], ["47 ohms"], ["100 ohms"], ["220 ohms"], ["330 ohms"], ["470 ohms"], ["680 ohms"], ["1k ohms"], ["4.7k ohms"], ["10k ohms"], ["22k ohms"], ["47k ohms"], ["100k ohms"], ["330k ohms"], ["1M ohms"], ["2M ohms"]], "outputs": [["brown black black gold"], ["yellow... | introductory | https://www.codewars.com/kata/5855777bb45c01bada0002ac |
def encode_resistor_colors(ohms_string):
| 16 |
3,355 | In this Kata, you will be given a number and your task will be to rearrange the number so that it is divisible by `25`, but without leading zeros. Return the minimum number of digit moves that are needed to make this possible. If impossible, return `-1` ( `Nothing` in Haskell ).
For example:
More examples in test cas... | ["def solve(n):\n moves = []\n for a, b in [\"25\", \"75\", \"50\", \"00\"]:\n s = str(n)[::-1]\n x = s.find(a)\n y = s.find(b, x+1 if a == \"0\" else 0)\n if x == -1 or y == -1:\n continue\n moves.append(x + y - (x > y) - (a == b))\n s = s.replace(a, \"\", 1).... | {"fn_name": "solve", "inputs": [["521"], ["5071"], ["705"], ["1241367"], ["1002"], ["2057"], ["50001111312"], ["71255535569"], ["72046951686"], ["75733989998"], ["87364011400"], ["81737102196"], ["50892869177"], ["500033332"], ["20"], ["5"]], "outputs": [["3"], ["4"], ["1"], ["-1"], ["2"], ["1"], ["13"], ["9"], ["12"],... | introductory | https://www.codewars.com/kata/5b165654c8be0d17f40000a3 |
def solve(n):
| 16 |
3,358 | Character recognition software is widely used to digitise printed texts. Thus the texts can be edited, searched and stored on a computer.
When documents (especially pretty old ones written with a typewriter), are digitised character recognition softwares often make mistakes.
Your task is correct the errors in the dig... | ["def correct(string):\n return string.translate(str.maketrans(\"501\", \"SOI\"))", "def correct(string):\n return string.replace('1','I').replace('0','O').replace('5','S')", "tr=str.maketrans('015','OIS')\n\ndef correct(string):\n return string.translate(tr)", "def correct(string):\n return string.replace(... | {"fn_name": "correct", "inputs": [["1F-RUDYARD K1PL1NG"], ["R0BERT MERLE - THE DAY 0F THE D0LPH1N"], ["R1CHARD P. FEYNMAN - 5TAT15T1CAL MECHAN1C5"], ["5TEPHEN HAWK1NG - A BR1EF H15T0RY 0F T1ME"], ["5TEPHEN HAWK1NG - THE UN1VER5E 1N A NUT5HELL"], ["ERNE5T HEM1NGWAY - A FARWELL T0 ARM5"], ["ERNE5T HEM1NGWAY - THE 0LD MAN... | introductory | https://www.codewars.com/kata/577bd026df78c19bca0002c0 |
def correct(string):
| 16 |
3,371 | Implement `String.eight_bit_signed_number?` (Ruby), `String.eightBitSignedNumber()` (Python), `eight_bit_signed_number()` (JS) or `StringUtils.isSignedEightBitNumber(String)` (Java) which should return `true/True` if given object is a number representable by 8 bit signed integer (-128 to -1 or 0 to 127), `false/False` ... | ["import re\ndef signed_eight_bit_number(number):\n return bool(re.match(\"(0|-128|-?([1-9]|[1-9]\\d|1[01]\\d|12[0-7]))\\Z\", number))", "def signed_eight_bit_number(number):\n if number in list(map(str,list(range(-128,128)))):\n return True\n return False\n \n", "import re\n\nSIGNED_BYTE_PATTERN... | {"fn_name": "signed_eight_bit_number", "inputs": [[""], ["0"], ["-0"], ["55"], ["-23"], ["042"], ["128"], ["-128"], ["-129"], ["-999"], ["1 "], [" 1"], ["1\n2"], ["--1"], ["01"], ["-01"]], "outputs": [[false], [true], [false], [true], [true], [false], [false], [true], [false], [false], [false], [false], [false], [false... | introductory | https://www.codewars.com/kata/567ed73340895395c100002e |
def signed_eight_bit_number(number):
| 16 |
3,377 | Given time in 24-hour format, convert it to words.
```
For example:
13:00 = one o'clock
13:09 = nine minutes past one
13:15 = quarter past one
13:29 = twenty nine minutes past one
13:30 = half past one
13:31 = twenty nine minutes to two
13:45 = quarter to two
00:48 = twelve minutes to one
00:08 = eight minutes p... | ["def solve(time):\n def number(n):\n if n > 20: return \"twenty {}\".format(number(n - 20))\n return [\n None, \"one\", \"two\", \"three\", \"four\",\n \"five\", \"six\", \"seven\", \"eight\", \"nine\",\n \"ten\", \"eleven\", \"twelve\", \"thirteen\",\n \"fo... | {"fn_name": "solve", "inputs": [["13:00"], ["13:09"], ["13:15"], ["13:29"], ["13:30"], ["13:45"], ["13:59"], ["00:08"], ["12:00"], ["07:01"], ["01:59"], ["12:01"], ["00:01"], ["23:31"], ["11:59"], ["01:45"]], "outputs": [["one o'clock"], ["nine minutes past one"], ["quarter past one"], ["twenty nine minutes past one"],... | introductory | https://www.codewars.com/kata/5c2b4182ac111c05cf388858 |
def solve(time):
| 16 |
3,402 | **Debug** a function called calculate that takes 3 values. The first and third values are numbers. The second value is a character. If the character is "+" , "-", "\*", or "/", the function will return the result of the corresponding mathematical function on the two numbers. If the string is not one of the specified ch... | ["from operator import add, sub, mul, truediv\nD = {'+':add, '-':sub, '*':mul, '/':truediv}\n\ndef calculate(a, o, b):\n try: return D[o](a, b)\n except: pass", "def calculate(a, o, b):\n result = 0\n if(o == \"+\"):\n return a + b\n elif(o == \"-\"):\n return a - b\n elif(o == \"/\" and... | {"fn_name": "calculate", "inputs": [["2", "+", "4"], ["-4", "*", "8"], ["49", "/", "-7"], ["8", "m", "2"], [3.2, "+", "8"], [3.2, "-", "8"], [3.2, "/", "8"], [3.2, "*", "8"], ["-3", "+", "0"], ["-3", "-", "0"], ["-3", "/", "0"], ["-2", "/", "-2"], ["-2", "codewars", "-2"], ["0", "*", "0"], ["-3", "w", "0"], ["0", "/", ... | introductory | https://www.codewars.com/kata/56368f37d464c0a43c00007f |
def calculate(a, o, b):
| 16 |
3,411 | The description is rather long but it tries to explain what a financing plan is.
The fixed monthly payment for a fixed rate mortgage is the amount paid by the borrower every month that ensures
that the loan is paid off in full with interest at the end of its term.
The monthly payment formula is based on the annuit... | ["def amort(rate, bal, term, num_payments):\n monthlyRate = rate / (12 * 100)\n c = bal * (monthlyRate * (1 + monthlyRate) ** term) / (((1 + monthlyRate) ** term) - 1)\n newBalance = bal\n for i in range(num_payments):\n interest = newBalance * monthlyRate\n princ = c - interest\n newBa... | {"fn_name": "amort", "inputs": [[7.4, "10215", "24", "20"], [7.9, "107090", "48", "41"], [1.9, "182840", "48", "18"], [2.2, "112630", "60", "11"], [9.8, "67932", "60", "34"], [4.6, "85591", "36", "5"], [7.0, "168742", "48", "16"], [9.6, "17897", "60", "23"], [8.0, "128263", "36", "26"], [1.2, "146157", "48", "20"], [9.... | introductory | https://www.codewars.com/kata/59c68ea2aeb2843e18000109 |
def amort(rate, bal, term, num_payments):
| 16 |
3,414 | # Introduction:
Reversi is a game usually played by 2 people on a 8x8 board.
Here we're only going to consider a single 8x1 row.
Players take turns placing pieces, which are black on one side and white on the
other, onto the board with their colour facing up. If one or more of the
opponents pieces are sandwiched by ... | ["import re\ndef reversi_row(moves):\n row = '........'\n stones = '*O'\n for i, m in enumerate(moves):\n L, M, R = row[:m], stones[i%2], row[m+1:]\n if R!='' and R[0] == stones[(i+1)%2] and R.find(stones[i%2])>0 and '.' not in R[:R.find(stones[i%2])]:\n R = R.replace(stones[(i+1)%2], ... | {"fn_name": "reversi_row", "inputs": [[["0"]], [["0", "1"]], [["0", "7", "4"]], [["3", "4"]], [["3", "4", "5"]], [["2", "1", "0"]], [["0", "1", "4", "3", "2"]], [["0", "1", "7", "2", "3"]], [["3", "2", "7", "1", "0"]], [["3", "4", "5", "6", "0", "2"]], [["0", "1", "2", "3", "4", "5", "6", "7"]], [["7", "0", "1"]], [["0... | introductory | https://www.codewars.com/kata/55aa92a66f9adfb2da00009a |
def reversi_row(moves):
| 16 |
3,425 | A [Word Square](https://en.wikipedia.org/wiki/Word_square) is a set of words written out in a square grid, such that the same words can be read both horizontally and vertically. The number of words, equal to the number of letters in each word, is known as the *order* of the square.
For example, this is an *order* `5` ... | ["from collections import Counter\ndef word_square(ls):\n n = int(len(ls)**0.5)\n return n*n==len(ls) and sum(i%2 for i in list(Counter(ls).values())) <= n\n", "def word_square(letters):\n root = int(len(letters)**0.5)\n return len(letters)**0.5 == root and sum([ letters.count(i)%2 for i in set(letters) ]) ... | {"fn_name": "word_square", "inputs": [["SATORAREPOTENETOPERAROTAS"], ["NOTSQUARE"], ["BITICETEN"], ["CARDAREAREARDART"], ["CODEWARS"], ["AAAAACEEELLRRRTT"], ["AAACCEEEEHHHMMTT"], ["AAACCEEEEHHHMMTTXXX"], ["GHBEAEFGCIIDFHGG"], ["AAHHFDKIHHFCXZBFDERRRTXXAA"], ["FRACTUREOUTLINEDBLOOMINGSEPTETTE"], ["GLASSESRELAPSEIMITATES... | introductory | https://www.codewars.com/kata/578e07d590f2bb8d3300001d |
def word_square(letters):
| 16 |
3,426 | Write a function to calculate compound tax using the following table:
For $10 and under, the tax rate should be 10%.
For $20 and under, the tax rate on the first $10 is %10, and the tax on the rest is 7%.
For $30 and under, the tax rate on the first $10 is still %10, the rate for the next $10 is still 7%, and everythi... | ["def tax_calculator(total):\n if not isinstance(total, (int, float)) or total < 0: return 0\n \n tax = 0\n \n if total > 30: tax = 2.2 + (total - 30) * 0.03\n elif total > 20: tax = 1.7 + (total - 20) * 0.05\n elif total > 10: tax = 1 + (total-10) * 0.07\n elif total > 0: tax = total / 10.0\n\n... | {"fn_name": "tax_calculator", "inputs": [["10"], ["11"], ["15"], ["18"], ["21"], ["26"], ["30"], [30.49], ["35"], ["100"], ["1000000"], ["0"], ["-3"], [null], ["monkey"], [{}]], "outputs": [["1"], [1.07], [1.35], [1.56], [1.75], ["2"], [2.2], [2.21], [2.35], [4.3], [30001.3], ["0"], ["0"], ["0"], ["0"], ["0"]]} | introductory | https://www.codewars.com/kata/56314d3c326bbcf386000007 |
def tax_calculator(total):
| 16 |
3,465 | # Description
Write a function that checks whether a credit card number is correct or not, using the Luhn algorithm.
The algorithm is as follows:
* From the rightmost digit, which is the check digit, moving left, double the value of every second digit; if the product of this doubling operation is greater than 9 (e.g.... | ["def valid_card(card):\n s = list(map(int, str(card.replace(' ', ''))))\n s[0::2] = [d * 2 - 9 if d * 2 > 9 else d * 2 for d in s[0::2]]\n return sum(s) % 10 == 0", "def valid_card(card_number):\n total = 0\n for i, a in enumerate(reversed(card_number.replace(' ', ''))):\n if i % 2:\n ... | {"fn_name": "valid_card", "inputs": [["5457 6238 9823 4311"], ["8895 6238 9323 4311"], ["5457 6238 9323 4311"], ["5457 1125 9323 4311"], ["1252 6238 9323 4311"], ["9999 9999 9999 9995"], ["0000 0300 0000 0000"], ["4444 4444 4444 4448"], ["5457 6238 9323 1252"], ["5457 6238 0254 4311"], ["8888 8888 8888 8888"], ["0025 2... | introductory | https://www.codewars.com/kata/56d55dcdc87df58c81000605 |
def valid_card(card):
| 16 |
3,475 | Implement a function/class, which should return an integer if the input string is in one of the formats specified below, or `null/nil/None` otherwise.
Format:
* Optional `-` or `+`
* Base prefix `0b` (binary), `0x` (hexadecimal), `0o` (octal), or in case of no prefix decimal.
* Digits depending on base
Any extra char... | ["import re\n\ndef to_integer(s):\n if re.match(\"\\A[+-]?(\\d+|0b[01]+|0o[0-7]+|0x[0-9a-fA-F]+)\\Z\", s):\n return int(s, 10 if s[1:].isdigit() else 0)", "from re import compile, match\n\nREGEX = compile(r'[+-]?(0(?P<base>[bxo]))?[\\d\\w]+\\Z')\n\n\ndef to_integer(strng):\n try:\n return int(strng,... | {"fn_name": "to_integer", "inputs": [["0o123"], ["0123"], ["123 "], [" 123"], ["0b1010"], ["+123"], ["-123"], ["0B1010"], ["0b12"], ["-0x123"], ["123\n"], ["\n123"], ["-0b1010"], ["0xDEADbeef"], ["0O123"], ["0o18"]], "outputs": [["83"], ["123"], [null], [null], ["10"], ["123"], ["-123"], [null], [null], ["-291"], [null... | introductory | https://www.codewars.com/kata/5682e1082cc7862db5000039 |
def to_integer(string):
| 16 |
3,498 | ## Overview
Resistors are electrical components marked with colorful stripes/bands to indicate both their resistance value in ohms and how tight a tolerance that value has. While you could always get a tattoo like Jimmie Rodgers to help you remember the resistor color codes, in the meantime, you can write a function th... | ["code = {'black': 0, 'brown': 1, 'red': 2, 'orange': 3, 'yellow': 4,\n'green': 5, 'blue': 6, 'violet': 7, 'gray': 8, 'white': 9,\n'gold': 5, 'silver': 10, '': 20}\ndef decode_resistor_colors(bands):\n colors = (bands + ' ').split(' ')\n value = 10 * code[colors[0]] + code[colors[1]]\n value *= 10 ** code[colo... | {"fn_name": "decode_resistor_colors", "inputs": [["yellow violet black"], ["yellow violet red gold"], ["brown black green silver"], ["brown black black"], ["brown black brown gold"], ["red red brown"], ["orange orange brown gold"], ["yellow violet brown silver"], ["blue gray brown"], ["brown black red silver"], ["brown... | introductory | https://www.codewars.com/kata/57cf3dad05c186ba22000348 |
def decode_resistor_colors(bands):
| 16 |
3,499 | Converting a normal (12-hour) time like "8:30 am" or "8:30 pm" to 24-hour time (like "0830" or "2030") sounds easy enough, right? Well, let's see if you can do it!
You will have to define a function named "to24hourtime", and you will be given an hour (always in the range of 1 to 12, inclusive), a minute (always in th... | ["def to24hourtime(hour, minute, period):\n return '%02d%02d' % (hour % 12 + 12 * (period == 'pm'), minute)", "from datetime import datetime\n\ndef to24hourtime(h, m, p):\n return datetime.strptime('%02d%02d%s' % (h, m, p.upper()), '%I%M%p').strftime('%H%M')", "from datetime import datetime\n\ndef to24hourtime(h,... | {"fn_name": "to24hourtime", "inputs": [["1", "18", "am"], ["2", "6", "am"], ["5", "7", "am"], ["6", "49", "am"], ["10", "16", "am"], ["10", "28", "am"], ["11", "1", "am"], ["2", "14", "pm"], ["3", "11", "pm"], ["3", "46", "pm"], ["4", "57", "pm"], ["5", "33", "pm"], ["7", "15", "pm"], ["10", "53", "pm"], ["11", "1", "p... | introductory | https://www.codewars.com/kata/59b0a6da44a4b7080300008a |
def to24hourtime(hour, minute, period):
| 16 |
3,505 | In the wake of the npm's `left-pad` debacle, you decide to write a new super padding method that superceds the functionality of `left-pad`. Your version will provide the same functionality, but will additionally add right, and justified padding of string -- the `super_pad`.
Your function `super_pad` should take three ... | ["def super_pad(string, width, fill=\" \"):\n if fill.startswith('>'):\n return (string + width * fill[1:])[:width]\n elif fill.startswith('^'):\n pad = (width * fill[1:])[:max(0, width - len(string) + 1) // 2]\n return (pad + string + pad)[:width]\n else:\n if fill.startswith('<'):... | {"fn_name": "super_pad", "inputs": [["test", "10", "x"], ["test", "10", "xO"], ["test", "10", "xO-"], ["some other test", "10", "nope"], ["some other test", "10", "> "], ["test", "7", ">nope"], ["test", "7", ""], ["test", "10", "< "], ["test", "3"], ["test", "3", "> "], ["test", "10", ""], ["test", "10", ">"], ["test",... | introductory | https://www.codewars.com/kata/56f3ca069821793533000a3a |
def super_pad(string, width, fill=" "):
| 16 |
3,506 | We want to know the index of the vowels in a given word, for example, there are two vowels in the word super (the second and fourth letters).
So given a string "super", we should return a list of [2, 4].
Some examples:
Mmmm => []
Super => [2,4]
Apple => [1,5]
YoMama -> [1,2,4... | ["def vowel_indices(word):\n return [i for i,x in enumerate(word,1) if x.lower() in 'aeiouy']", "def vowel_indices(word):\n return [i+1 for i,c in enumerate(word.lower()) if c in 'aeiouy']", "def vowel_indices(word):\n return [index for index, value in enumerate(word.lower(), 1) if value in 'aeyuio']", "VOWELS... | {"fn_name": "vowel_indices", "inputs": [["mmm"], ["apple"], ["super"], ["123456"], ["crIssUm"], ["rIc"], ["UNDISARMED"], ["bialy"], ["stumpknocker"], ["narboonnee"], ["carlstadt"], ["ephodee"], ["spicery"], ["oftenness"], ["bewept"], ["capsized"]], "outputs": [[[]], [["1", "5"]], [["2", "4"]], [[]], [["3", "6"]], [["2"... | introductory | https://www.codewars.com/kata/5680781b6b7c2be860000036 |
def vowel_indices(word):
| 16 |
3,514 | Create a function that will return true if all numbers in the sequence follow the same counting pattern. If the sequence of numbers does not follow the same pattern, the function should return false.
Sequences will be presented in an array of varied length. Each array will have a minimum of 3 numbers in it.
The seque... | ["def validate_sequence(seq):\n return len({a - b for a, b in zip(seq, seq[1:])}) == 1", "def validate_sequence(sequence):\n return sequence == list(range(sequence[0], sequence[-1] + 1, sequence[1] - sequence[0]))\n", "def validate_sequence(s):\n return sum(s) == (s[0] + s[-1]) * len(s) /2", "def validate_sequ... | {"fn_name": "validate_sequence", "inputs": [[["1", "2", "3", "4", "5", "8", "7", "8", "9"]], [["2", "8", "6", "7", "4", "3", "1", "5", "9"]], [["1", "2", "3", "4", "5", "6", "7", "8", "9"]], [["0", "1", "2", "3", "4", "5", "6", "7", "8"]], [["1", "3", "5", "7", "9", "11", "13", "15"]], [["1", "3", "5", "7", "8", "12", ... | introductory | https://www.codewars.com/kata/553f01db29490a69ff000049 |
def validate_sequence(sequence):
| 16 |
3,520 | The prime numbers are not regularly spaced. For example from `2` to `3` the step is `1`.
From `3` to `5` the step is `2`. From `7` to `11` it is `4`.
Between 2 and 50 we have the following pairs of 2-steps primes:
`3, 5 - 5, 7, - 11, 13, - 17, 19, - 29, 31, - 41, 43`
We will write a function `step` with parameters:
... | ["import math\ndef isPrime(n):\n if n <= 1:\n return False\n for i in range(2,int(math.sqrt(n)+1)):\n if n % i == 0:\n return False\n return True\n\ndef step(g,m,n):\n if m >= n:\n return []\n else:\n for i in range(m,n+1-g):\n if isPrime(i) and isPrime(i... | {"fn_name": "step", "inputs": [["2", "100", "110"], ["4", "100", "110"], ["6", "100", "110"], ["8", "300", "400"], ["10", "300", "400"], ["4", "30000", "100000"], ["6", "30000", "100000"], ["11", "30000", "100000"], ["16", "5", "20"], ["10", "4900", "5000"], ["30", "4900", "5000"], ["2", "4900", "5000"], ["2", "4900", ... | introductory | https://www.codewars.com/kata/5613d06cee1e7da6d5000055 |
def step(g, m, n):
| 16 |
3,531 | A [Mersenne prime](https://en.wikipedia.org/wiki/Mersenne_prime) is a prime number that can be represented as:
Mn = 2^(n) - 1. Therefore, every Mersenne prime is one less than a power of two.
Write a function that will return whether the given integer `n` will produce a Mersenne prime or not.
The tests will check ra... | ["def valid_mersenne(n):\n return n in {2,3,5,7,13,17,19,31,61,89,107,127,521,607,1279}", "def valid_mersenne(n):\n '''Currently using the Lucas-Lehmer test.'''\n \n if n < 2:\n return False\n \n if n == 2:\n return True\n \n mersenne = 2**n - 1\n \n residue = 4\n for _ in... | {"fn_name": "valid_mersenne", "inputs": [["3"], ["5"], ["7"], ["11"], ["13"], ["17"], ["19"], ["21"], ["23"], ["49"], ["61"], ["89"], ["221"], ["521"], ["607"], ["1279"]], "outputs": [[true], [true], [true], [false], [true], [true], [true], [false], [false], [false], [true], [true], [false], [true], [true], [true]]} | introductory | https://www.codewars.com/kata/56af6e4198909ab73200013f |
def valid_mersenne(n):
| 16 |
3,540 | According to ISO 8601, the first calendar week (1) starts with the week containing the first thursday in january.
Every year contains of 52 (53 for leap years) calendar weeks.
**Your task is** to calculate the calendar week (1-53) from a given date.
For example, the calendar week for the date `2019-01-01` (string) sho... | ["from datetime import datetime\n\n\ndef get_calendar_week(date_string):\n return datetime.strptime(date_string, \"%Y-%m-%d\").isocalendar()[1] ", "from datetime import date\n\ndef get_calendar_week(s):\n return date(*map(int, s.split(\"-\"))).isocalendar()[1]", "import datetime\nget_calendar_week=lambda d:dat... | {"fn_name": "get_calendar_week", "inputs": [["2017-01-01"], ["2018-12-24"], ["2018-12-31"], ["2019-01-01"], ["2016-02-29"], ["2015-12-29"], ["2025-01-05"], ["2025-01-06"], ["1995-12-31"], ["1996-01-01"], ["1999-12-31"], ["2000-01-03"], ["2016-12-25"], ["2016-12-26"], ["2017-01-02"], ["2018-01-01"]], "outputs": [["52"],... | introductory | https://www.codewars.com/kata/5c2bedd7eb9aa95abe14d0ed |
def get_calendar_week(date_string):
| 16 |
3,552 | You are playing euchre and you want to know the new score after finishing a hand. There are two teams and each hand consists of 5 tricks. The team who wins the majority of the tricks will win points but the number of points varies. To determine the number of points, you must know which team called trump, how many trick... | ["def update_score(score, trump, alone, tricks):\n done = tricks.count(trump)\n mul = 2 if done == 5 and alone else 1\n add = 1 if done in (3, 4) else 2\n winner = trump if done > 2 else (3 - trump)\n return [pts + (add * mul if team == winner else 0) for team, pts in enumerate(score, 1)]", "def update_s... | {"fn_name": "update_score", "inputs": [[["4", "0"], "1", false, ["2", "2", "2", "2", "2"]], [["4", "4"], "2", false, ["2", "2", "2", "2", "2"]], [["4", "6"], "2", true, ["2", "2", "2", "2", "2"]], [["7", "2"], "1", false, ["1", "2", "2", "2", "2"]], [["7", "4"], "1", true, ["1", "2", "2", "2", "2"]], [["7", "7"], "2", ... | introductory | https://www.codewars.com/kata/586eca3b35396db82e000481 |
def update_score(current_score, called_trump, alone, tricks):
| 16 |
3,554 | Zonk is addictive dice game. In each round player rolls 6 dice. Then (s)he composes combinations from them. Each combination gives certain points.
Then player can take one or more dice combinations to his hand and re-roll remaining dice or save his score. Dice in player's hand won't be taken into account in subsequen... | ["def get_score(dice):\n if all(i in dice for i in range(1, 7)):\n return 1000\n if len(dice) == 6 and all(dice.count(d) == 2 for d in set(dice)):\n return 750\n score = 0\n score += sum((dice.count(d)==n) * d * (n-2) * (1000 if d==1 else 100) for d in set(dice) for n in range(3, 7))\n scor... | {"fn_name": "get_score", "inputs": [[["2", "2", "2"]], [["1", "2", "1"]], [["1", "5", "5"]], [["3", "3", "3", "3"]], [["5", "5", "5", "5"]], [["6", "6", "6", "6"]], [["3", "3", "5", "3"]], [["5", "5", "5", "5", "5"]], [["1", "5", "1", "5", "1"]], [["1", "2", "3", "4", "5"]], [["3", "3", "3", "3", "3", "3"]], [["6", "6"... | introductory | https://www.codewars.com/kata/53837b8c94c170e55f000811 |
def get_score(dice):
| 16 |
3,561 | Another Fibonacci... yes but with other kinds of result.
The function is named `aroundFib` or `around_fib`, depending of the language.
Its parameter is `n` (positive integer).
First you have to calculate `f` the value of `fibonacci(n)` with `fibonacci(0) --> 0` and
`fibonacci(1) --> 1` (see: )
- 1) Find the count of ... | ["from collections import Counter\nfib = [0, 1]\n\ndef around_fib(n):\n while len(fib) <= n: fib.append(fib[-1] + fib[-2])\n f = str(fib[n])\n val = max((v, -int(k)) for k,v in Counter(f).items())\n last = f[-(len(f)%25 or 25):]\n return f\"Last chunk {last}; Max is {val[0]} for digit {-val[1]}\"", "def ... | {"fn_name": "around_fib", "inputs": [["617"], ["628"], ["664"], ["749"], ["581"], ["17962"], ["13505"], ["13883"], ["10210"], ["15923"], ["12314"], ["12900"], ["22587"], ["21019"], ["21537"], ["23544"]], "outputs": [["Last chunk 3197; Max is 18 for digit 9"], ["Last chunk 519011; Max is 20 for digit 3"], ["Last chunk 7... | introductory | https://www.codewars.com/kata/59bf943cafcda28e31000130 |
def around_fib(n):
| 16 |
3,562 | In computer science and discrete mathematics, an [inversion](https://en.wikipedia.org/wiki/Inversion_%28discrete_mathematics%29) is a pair of places in a sequence where the elements in these places are out of their natural order. So, if we use ascending order for a group of numbers, then an inversion is when larger num... | ["def count_inversion(nums):\n return sum(a > b for i, a in enumerate(nums) for b in nums[i + 1:])\n", "def count_inversion(s):\n return sum(s[i] > s[j]\n for i in range(len(s) - 1)\n for j in range(i + 1, len(s)))", "def count_inversion(sequence):\n def rec(arr):\n if len(ar... | {"fn_name": "count_inversion", "inputs": [[["-20", "0", "20"]], [["-13", "4", "8"]], [["1", "3", "2"]], [["-2", "-3", "-1"]], [["-20", "20", "0"]], [["-13", "9", "8"]], [["3", "6", "2", "7", "3"]], [["14", "12", "17", "124", "1", "-12", "21", "-24"]], [[]], [["25", "12", "7", "4", "2", "-7", "-12", "-22"]], [["10", "9"... | introductory | https://www.codewars.com/kata/5728a1bc0838ffea270018b2 |
def count_inversion(sequence):
| 16 |
3,582 | Implement `String#digit?` (in Java `StringUtils.isDigit(String)`), which should return `true` if given object is a digit (0-9), `false` otherwise. | ["def is_digit(n):\n return n.isdigit() and len(n)==1", "import re\n\ndef is_digit(n):\n return bool(re.match(\"\\d\\Z\", n))", "import re\ndef is_digit(n):\n return bool(re.fullmatch(r'\\d', n))", "is_digit=lambda n: len(n)==1 and n in \"0123456789\"", "is_digit = set(\"1234567890\").__contains__", "def is_di... | {"fn_name": "is_digit", "inputs": [["!"], ["#"], ["%"], ["&"], [")"], [":"], ["U"], ["^"], ["_"], ["b"], ["g"], ["j"], ["r"], ["t"], ["}"], ["1 "]], "outputs": [[false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false], [false]]} | introductory | https://www.codewars.com/kata/567bf4f7ee34510f69000032 |
def is_digit(n):
| 16 |
3,601 | Your task is to construct a building which will be a pile of n cubes.
The cube at the bottom will have a volume of n^3, the cube above
will have volume of (n-1)^3 and so on until the top which will have a volume of 1^3.
You are given the total volume m of the building.
Being given m can you find the number n of cube... | ["def find_nb(m):\n n = 1\n volume = 0\n while volume < m:\n volume += n**3\n if volume == m:\n return n\n n += 1\n return -1", "def find_nb(m):\n n=s=0\n while True:\n n+=1\n s+=n\n k=s*s\n if k== m:\n return n\n elif k>m:\n r... | {"fn_name": "find_nb", "inputs": [["41364076483082"], ["9541025211025"], ["112668204662785"], ["1788719004901"], ["131443152397956"], ["1801879360282"], ["18262169777476"], ["36099801072722"], ["171814395026"], ["6759306226"], ["33506766981009"], ["14601798712901"], ["603544088161"], ["21494785321"], ["1025251934596364... | introductory | https://www.codewars.com/kata/5592e3bd57b64d00f3000047 |
def find_nb(m):
| 16 |
3,686 | Your task is to define a function that understands basic mathematical expressions and solves them.
For example:
```python
calculate("1 + 1") # => 2
calculate("18 + 4*6") # => 42
calculate("245 - 826") # => -581
calculate("09 + 000482") # => 491
calculate("8 / 4 + 6") # => 8
calculate("5 + 1 / 5") ... | ["import re\ndef calculate(input):\n try:\n return eval(re.sub(r'(\\d+)', lambda m: str(int(m.group(1))), input))\n except:\n return False", "import re\ndef calculate(s):\n try:\n s = re.sub(r'(?<!\\d)0+(0|[1-9]\\d*)', lambda m: m.group(1), s)\n s = re.sub(r'\\d+(?!\\.)', lambda m: ... | {"fn_name": "calculate", "inputs": [["1 + 1"], ["3 * 4"], ["9 / 3"], ["26 + 73"], ["1 / 2"], ["123 * 987 * 135 * 246"], ["5*2/3*9/10*123/8"], ["1*2*3/1/2/3+1+2+3-1-2-3"], ["1+2 * 4"], ["1+2-3*4/6"], [""], ["7 - A"], ["3 + 2 * "], [" / 7 + 3"], ["5"], ["1 / 0"]], "outputs": [["2"], ["12"], ["3"], ["99"], [0.5], ["4031... | introductory | https://www.codewars.com/kata/582b3b085ad95285c4000013 |
def calculate(input):
| 16 |
3,704 | # Solve For X
You will be given an equation as a string and you will need to [solve for X](https://www.mathplacementreview.com/algebra/basic-algebra.php#solve-for-a-variable) and return x's value. For example:
```python
solve_for_x('x - 5 = 20') # should return 25
solve_for_x('20 = 5 * x - 5') # should return 5
solv... | ["from itertools import count\n\ndef solve_for_x(equation):\n return next( x for n in count(0) for x in [n, -n] if eval(equation.replace(\"x\", str(x)).replace(\"=\", \"==\")) )", "import re\ndef solve_for_x(equation):\n left,right = equation.split(\"=\")\n answer = False\n TrialAndErrorRipMs = -1000\n w... | {"fn_name": "solve_for_x", "inputs": [["x - 5 = 20"], ["5 * x + 5 = 30"], ["20 = 5 * x - 5"], ["24 = 4 + 5 * x"], ["x = 5"], ["2 * x = 198"], ["x - 100 + 2 - 50 = 52"], ["x / 3 = 33"], ["x + 80 = 20"], ["x + 20 = -60"], ["5 * x + 20 - x = 60"], ["x + x + 6 = 10"], ["5 * x = x + 8"], ["x = x / 2 + 25"], ["(5 - 3) * x = ... | introductory | https://www.codewars.com/kata/59c2e2a36bddd2707e000079 |
def solve_for_x(equation):
| 16 |
3,747 | Implement `String#ipv4_address?`, which should return true if given object is an IPv4 address - four numbers (0-255) separated by dots.
It should only accept addresses in canonical representation, so no leading `0`s, spaces etc. | ["from re import compile, match\n\nREGEX = compile(r'((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.){4}$')\n\n\ndef ipv4_address(address):\n # refactored thanks to @leonoverweel on CodeWars\n return bool(match(REGEX, address + '.'))\n", "import socket\ndef ipv4_address(address):\n try: # No need to do work that'... | {"fn_name": "ipv4_address", "inputs": [[""], ["127.0.0.1"], ["0.0.0.0"], ["255.255.255.255"], ["10.256.30.40"], ["10.20.030.40"], ["127.0.1"], ["127.0.0.0.1"], ["..255.255"], ["127.0.0.1\n"], ["\n127.0.0.1"], [" 127.0.0.1"], ["127.0.0.1 "], [" 127.0.0.1 "], ["127.0.0.1."], ["127..0.1"]], "outputs": [[false], [true], [t... | introductory | https://www.codewars.com/kata/567fe8b50c201947bc000056 |
def ipv4_address(address):
| 16 |
3,758 | You will be given an array of strings. The words in the array should mesh together where one or more letters at the end of one word will have the same letters (in the same order) as the next word in the array. But, there are times when all the words won't mesh.
Examples of meshed words:
"apply" and "plywood"
... | ["import re\n\ndef word_mesh(arr):\n common = re.findall(r'(.+) (?=\\1)',' '.join(arr))\n return ''.join(common) if len(common) + 1 == len(arr) else 'failed to mesh'", "def word_mesh(arr):\n result = \"\"\n \n for a, b in zip(arr, arr[1:]):\n while not a.endswith(b):\n b = b[:-1]\n ... | {"fn_name": "word_mesh", "inputs": [[["allow", "lowering", "ringmaster", "terror"]], [["abandon", "donation", "onion", "ongoing"]], [["jamestown", "ownership", "hippocampus", "pushcart", "cartographer", "pheromone"]], [["california", "niagara", "arachnophobia", "biannual", "alumni", "nibbles", "blessing"]], [["fortune"... | introductory | https://www.codewars.com/kata/5c1ae703ba76f438530000a2 |
def word_mesh(arr):
| 16 |
3,786 | # Do you ever wish you could talk like Siegfried of KAOS ?
## YES, of course you do!
https://en.wikipedia.org/wiki/Get_Smart
# Task
Write the function ```siegfried``` to replace the letters of a given sentence.
Apply the rules using the course notes below. Each week you will learn some more rules.
Und by ze fif... | ["import re\n\nPATTERNS = [re.compile(r'(?i)ci|ce|c(?!h)'),\n re.compile(r'(?i)ph'),\n re.compile(r'(?i)(?<!\\b[a-z]{1})(?<!\\b[a-z]{2})e\\b|([a-z])\\1'),\n re.compile(r'(?i)th|w[rh]?'),\n re.compile(r'(?i)ou|an|ing\\b|\\bsm')]\n \nCHANGES = {\"ci\": \"si\", \"ce\... | {"fn_name": "siegfried", "inputs": [["1", "Centre receiver"], ["2", "Photo of 5 pheasants with graphs"], ["3", "Meet me at the same place at noon"], ["3", "Be quite quiet"], ["3", "Aardvarks are nice most of the time"], ["5", "And another thing Mr Smart, I want no more trouble!"], ["5", "You ought to behave yourself Sm... | introductory | https://www.codewars.com/kata/57fd6c4fa5372ead1f0004aa |
def siegfried(week, txt):
| 16 |
3,793 | In this kata, you should calculate type of triangle with three given sides ``a``, ``b`` and ``c`` (given in any order).
If all angles are less than ``90°``, this triangle is ``acute`` and function should return ``1``.
If one angle is strictly ``90°``, this triangle is ``right`` and function should return ``2``.
If o... | ["def triangle_type(a, b, c):\n x,y,z = sorted([a,b,c])\n if z >= x + y: return 0\n if z*z == x*x + y*y: return 2\n return 1 if z*z < x*x + y*y else 3", "def triangle_type(a, b, c):\n a,b,c = sorted((a,b,c))\n if a+b <= c: return 0\n t = a**2+b**2 - c**2\n if t > 0: return 1\n if t == 0: return 2\n else: retu... | {"fn_name": "triangle_type", "inputs": [["1", "2", "3"], [5.5, 4.5, "10"], ["7", "3", "2"], ["5", "10", "5"], ["3", "3", "0"], ["3", "3", "1"], ["5", "5", "5"], ["8", "5", "7"], ["3", "4", "5"], ["21", "220", "221"], [8.625, 33.625, 32.5], ["65", "56", "33"], ["68000", "285000", "293000"], ["65", "55", "33"], ["7", "8"... | introductory | https://www.codewars.com/kata/53907ac3cd51b69f790006c5 |
def triangle_type(a, b, c):
| 16 |
3,808 | Remember the movie with David Bowie: 'The Labyrinth'?
You can remember your childhood here: https://www.youtube.com/watch?v=2dgmgub8mHw
In this scene the girl is faced with two 'Knights" and two doors. One door leads the castle where the Goblin King and her kid brother is, the other leads to certain death. She can as... | ["def knight_or_knave(said):\n return \"Knight!\" if eval(str(said)) else \"Knave! Do not trust.\"", "def knight_or_knave(said):\n try:\n return 'Knight!' if eval(said) else 'Knave! Do not trust.'\n except:\n return 'Knight!' if said else 'Knave! Do not trust.'", "knight_or_knave = lambda said: '... | {"fn_name": "knight_or_knave", "inputs": [[false], ["4+2==5"], ["2+2==4"], ["not True and False or False or False"], ["3 is 3"], ["True"], ["not True"], ["2+2==5"], ["4+1==5"], ["4 is 3"], ["9+2==3"], ["105+30076==30181"], ["3 is 3 is 3 is 9"], ["\"orange\" is not \"red\""], ["4 is \"blue\""], ["True is not False"]], "... | introductory | https://www.codewars.com/kata/574881a216ac9be096001ade |
def knight_or_knave(said):
| 16 |
3,814 | Given a time in AM/PM format as a string, convert it to military (24-hour) time as a string.
Midnight is 12:00:00AM on a 12-hour clock, and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock, and 12:00:00 on a 24-hour clock
Sample Input: 07:05:45PM
Sample Output: 19:05:45
Try not to use built in Dat... | ["def get_military_time(time):\n if time[-2:] == 'AM':\n hour = '00' if time[0:2] == '12' else time[0:2]\n else:\n hour = '12' if time[0:2] == '12' else str(int(time[0:2])+12)\n return hour + time[2:-2]", "def get_military_time(time_str):\n hour = int(time_str[:2])\n pm = time_str[-2] == \"... | {"fn_name": "get_military_time", "inputs": [["12:00:01AM"], ["01:02:03AM"], ["03:06:07AM"], ["04:08:09AM"], ["06:12:13AM"], ["07:14:15AM"], ["08:16:17AM"], ["09:18:19AM"], ["10:20:21AM"], ["11:22:23AM"], ["12:24:25PM"], ["01:26:27PM"], ["05:34:35PM"], ["06:36:37PM"], ["08:40:41PM"], ["10:44:45PM"]], "outputs": [["00:00... | introductory | https://www.codewars.com/kata/57729a09914da60e17000329 |
def get_military_time(time):
| 16 |
3,817 | Most languages have a `split` function that lets you turn a string like `“hello world”` into an array like`[“hello”, “world”]`. But what if we don't want to lose the separator? Something like `[“hello”, “ world”]`.
#### Task:
Your job is to implement a function, (`split_without_loss` in Ruby/Crystal, and `splitWithou... | ["def split_without_loss(s, split_p):\n return [i for i in s.replace(split_p.replace('|', ''), split_p).split('|') if i]", "import re\n\ndef split_without_loss(s, m):\n r,iM = m.replace('|',''), m.index('|')\n out,i,j = [],0,0\n while 1:\n j = s.find(r,j)\n if j==-1:\n if i<len(s):... | {"fn_name": "split_without_loss", "inputs": [["hello world!", "ello| "], ["hello world!", "hello wo|rld!"], ["hello world!", "h|ello world!"], ["hello world! hello world!", "o|rl"], ["hello world! hello world!", "ello| "], ["hello hello hello", " | "], [" hello world", " |"], ["aaaa", "|aa"], ["aaa", "|aa"], ["aaaaa"... | introductory | https://www.codewars.com/kata/581951b3704cccfdf30000d2 |
def split_without_loss(s, split_p):
| 16 |
3,826 | Let be `n` an integer prime with `10` e.g. `7`.
`1/7 = 0.142857 142857 142857 ...`.
We see that the decimal part has a cycle: `142857`. The length of this cycle is `6`. In the same way:
`1/11 = 0.09 09 09 ...`. Cycle length is `2`.
# Task
Given an integer n (n > 1), the function cycle(n) returns the length of the... | ["import math\n\ndef cycle(n) :\n if n % 2 == 0 or n % 5 ==0:\n return -1\n k = 1\n while pow(10,k,n) != 1:\n k += 1\n return k\n \n \n \n", "def cycle(n):\n if not n % 2 or not n % 5:\n return -1\n x, mods = 1, set()\n while x not in mods:\n mods.add... | {"fn_name": "cycle", "inputs": [["33"], ["18118"], ["69"], ["65"], ["97"], ["111"], ["53"], ["59"], ["93"], ["183"], ["167"], ["94"], ["133"], ["218713"], ["221193"], ["1234567"]], "outputs": [["2"], ["-1"], ["22"], ["-1"], ["96"], ["3"], ["13"], ["58"], ["15"], ["60"], ["166"], ["-1"], ["18"], ["9744"], ["3510"], ["34... | introductory | https://www.codewars.com/kata/5a057ec846d843c81a0000ad |
def cycle(n) :
| 16 |
3,838 | There is a house with 4 levels.
In that house there is an elevator.
You can program this elevator to go up or down,
depending on what button the user touches inside the elevator.
Valid levels must be only these numbers: `0,1,2,3`
Valid buttons must be only these strings: `'0','1','2','3'`
Possible return values are... | ["levels = [0, 1, 2, 3]\nbuttons = ['0', '1', '2', '3']\ndef goto(level,button):\n if level not in levels or button not in buttons:\n return 0\n else:\n return int(button) - level", "def goto(l,b):\n if b in ('0','1','2','3') and l in (0,1,2,3):\n return int(b)-l\n return 0", "def goto(... | {"fn_name": "goto", "inputs": [["0", "1"], ["0", "2"], ["1", "0"], ["2", "0"], ["2", "2"], ["2", "3"], ["3", "0"], ["3", "2"], ["0", null], ["1", "4"], ["1", null], ["2", "4"], ["2", null], ["4", "2"], ["3", {}], ["2", "3"]], "outputs": [["1"], ["2"], ["-1"], ["-2"], ["0"], ["1"], ["-3"], ["-1"], ["0"], ["0"], ["0"], [... | introductory | https://www.codewars.com/kata/52ed326b8df6540e06000029 |
def goto(level,button):
| 16 |
3,842 | Your job is to write a function that takes a string and a maximum number of characters per line and then inserts line breaks as necessary so that no line in the resulting string is longer than the specified limit.
If possible, line breaks should not split words. However, if a single word is longer than the limit, it o... | ["def word_wrap(s, limit):\n s, i, li = s.split(), 0, []\n while i < len(s):\n t = s[i]\n if len(t) <= limit:\n while i + 1 < len(s) and len(t) + len(s[i + 1]) + 1 <= limit:\n t += ' ' + s[i + 1] ; i += 1\n if len(t) < limit:\n if i + 1 < len(s) an... | {"fn_name": "word_wrap", "inputs": [["hello world", "7"], ["this is a test", "4"], ["areallylongword", "6"], ["aaa", "3"], ["aaaa", "3"], ["a a", "3"], ["a aa", "3"], ["a aaa", "3"], ["a aaaa", "3"], ["a aaaaa", "3"], ["a a a", "3"], ["a aaa a", "3"], ["a aaaaa a", "3"], ["a aaaa aaa", "3"], ["a aaaaa aaa", "3"], ["aaa... | introductory | https://www.codewars.com/kata/55fd8b5e61d47237810000d9 |
def word_wrap(text, limit):
| 16 |
3,884 | # RegExp Fun #1 - When I miss few days of gym
## Disclaimer
The background story of this Kata is 100% fiction. Any resemblance to real people or real events is **nothing more than a coincidence** and should be regarded as such.
## Background Story
You are a person who loves to go to the gym everyday with the squad... | ["import re\n\ndef gym_slang(phrase):\n phrase = re.sub(r'([pP])robably', r'\\1rolly', phrase)\n phrase = re.sub(r'([iI]) am', r\"\\1'm\", phrase)\n phrase = re.sub(r'([iI])nstagram', r'\\1nsta', phrase)\n phrase = re.sub(r'([dD])o not', r\"\\1on't\", phrase)\n phrase = re.sub(r'([gG])oing to', r'\\1onna... | {"fn_name": "gym_slang", "inputs": [["When I miss few days of gym"], ["Squad probably think I am fake"], ["No selfie to post on Instagram either"], ["What if I die fat"], ["What if I do not fit in my clothes now"], ["Going to feel like a new gym member"], ["wait what was my lock combination"], ["probably Probably"], ["... | introductory | https://www.codewars.com/kata/5720a81309e1f9b232001c5b |
def gym_slang(phrase):
| 16 |
3,903 | In Russia, there is an army-purposed station named UVB-76 or "Buzzer" (see also https://en.wikipedia.org/wiki/UVB-76). Most of time specific "buzz" noise is being broadcasted, but on very rare occasions, the buzzer signal is interrupted and a voice transmission in Russian takes place. Transmitted messages have always t... | ["import re\nvalidate = lambda msg: bool(re.match('^MDZHB \\d\\d \\d\\d\\d [A-Z]+ \\d\\d \\d\\d \\d\\d \\d\\d$', msg))", "import re\ndef validate(message):\n return bool(re.match(r\"^MDZHB \\d{2} \\d{3} [A-Z]+ \\d{2} \\d{2} \\d{2} \\d{2}$\", message))", "import re\ndef validate(message):\n return re.match(r'^MDZHB(... | {"fn_name": "validate", "inputs": [["MDZHB 85 596 KLASA 81 00 02 91"], ["MDZHB 12 733 EDINENIE 67 79 66 32"], ["MDZHV 60 130 VATRUKH 58 89 54 54"], ["MD2HB 60 1S0 AKKRETSIA 58 89 54 54"], ["MDZHB 12 733 EDIN ENIE 67 79 66 32"], ["MDZHB 85 596 PALEOLIT 81 12 52 91"], ["MDZHB 12 733 6INITIAL 67 79 66 32"], ["MDZHB 60 130... | introductory | https://www.codewars.com/kata/56445cc2e5747d513c000033 |
def validate(message):
| 16 |
3,909 | In recreational mathematics, a [Keith number](https://en.wikipedia.org/wiki/Keith_number) or repfigit number (short for repetitive Fibonacci-like digit) is a number in the following integer sequence:
`14, 19, 28, 47, 61, 75, 197, 742, 1104, 1537, 2208, 2580, 3684, 4788, 7385, 7647, 7909, ...` (sequence A007629 in the ... | ["def is_keith_number(n):\n numList = [int(i) for i in str(n)] # int array\n if len(numList) > 1: # min 2 digits\n itr = 0\n while numList[0] <= n:\n # replace array entries by its sum:\n numList[itr % len(numList)] = sum(numList)\n itr += 1\n if n in nu... | {"fn_name": "is_keith_number", "inputs": [["14"], ["4"], ["23"], ["0"], ["47"], ["34"], ["61"], ["58"], ["75"], ["742"], ["1104"], ["31331"], ["44121607"], ["251133297"], ["96189170155"], ["855191324330802397989"]], "outputs": [["3"], [false], [false], [false], ["4"], [false], ["6"], [false], ["5"], ["8"], ["9"], ["13"... | introductory | https://www.codewars.com/kata/590e4940defcf1751c000009 |
def is_keith_number(n):
| 16 |
3,926 | While surfing in web I found interesting math problem called "Always perfect". That means if you add 1 to the product of four consecutive numbers the answer is ALWAYS a perfect square.
For example we have: 1,2,3,4 and the product will be 1X2X3X4=24. If we add 1 to the product that would become 25, since the result numb... | ["def check_root(string):\n try:\n a,b,c,d = [int(i) for i in string.split(',')]\n if not (a == b-1 and a == c-2 and a == d-3):\n return 'not consecutive'\n s = a*b*c*d+1\n return str(s)+', '+str(int(s**0.5))\n except:\n return 'incorrect input'", "import re\ndef chec... | {"fn_name": "check_root", "inputs": [["4,5,6,7"], ["3,s,5,6"], ["11,13,14,15"], ["10,11,12,13,15"], ["10,11,12,13"], ["ad,d,q,tt,v"], ["1,2,3,4"], ["20,21,22,24"], ["9,10,10,11"], ["11254,11255,11256,11258"], ["2000000,2000001,2000002,2000003"], ["4,5,6,q"], ["5,6,7"], ["3,5,6,7"], ["-4,-3,-2,-1"], ["-1,0,1,2"]], "outp... | introductory | https://www.codewars.com/kata/55f3facb78a9fd5b26000036 |
def check_root(string):
| 16 |
3,927 | Some numbers have funny properties. For example:
> 89 --> 8¹ + 9² = 89 * 1
> 695 --> 6² + 9³ + 5⁴= 1390 = 695 * 2
> 46288 --> 4³ + 6⁴+ 2⁵ + 8⁶ + 8⁷ = 2360688 = 46288 * 51
Given a positive integer n written as abcd... (a, b, c, d... being digits) and a positive integer p
- we want to find a positive integer k, if i... | ["def dig_pow(n, p):\n s = 0\n for i,c in enumerate(str(n)):\n s += pow(int(c),p+i)\n return s/n if s%n==0 else -1\n", "def dig_pow(n, p):\n k, fail = divmod(sum(int(d)**(p + i) for i, d in enumerate(str(n))), n)\n return -1 if fail else k\n", "def dig_pow(n, p):\n t = sum( int(d) ** (p+i) for i, d in enu... | {"fn_name": "dig_pow", "inputs": [["46288", "3"], ["46288", "5"], ["135", "1"], ["175", "1"], ["518", "1"], ["2646798", "1"], ["3456789", "1"], ["3456789", "5"], ["198", "1"], ["249", "1"], ["1878", "2"], ["7388", "2"], ["2697", "3"], ["6376", "3"], ["6714", "3"], ["10383", "6"]], "outputs": [["51"], ["-1"], ["1"], ["1... | introductory | https://www.codewars.com/kata/5552101f47fc5178b1000050 |
def dig_pow(n, p):
| 16 |
3,930 | You start with a value in dollar form, e.g. $5.00. You must convert this value to a string in which the value is said, like '5 dollars' for example. This should account for ones, cents, zeroes, and negative values. Here are some examples:
```python
dollar_to_speech('$0.00') == '0 dollars.'
dollar_to_speech('$1.00') == ... | ["def dollar_to_speech(value):\n if \"-\" in value:\n return \"No negative numbers are allowed!\"\n d, c = (int(n) for n in value.replace(\"$\", \"\").split(\".\"))\n dollars = \"{} dollar{}\".format(str(d), \"s\" if d != 1 else \"\") if d or not c else \"\"\n link = \" and \" if (d and c) else \"\"\... | {"fn_name": "dollar_to_speech", "inputs": [["$20.18"], ["$5.62"], ["$83.47"], ["$16.93"], ["$0.00"], ["$0.01"], ["$0.63"], ["$0.28"], ["$1.00"], ["$2.00"], ["$31.00"], ["$45.00"], ["$-5843.21"], ["$-45.32"], ["$-2.63"], ["$-234.48"]], "outputs": [["20 dollars and 18 cents."], ["5 dollars and 62 cents."], ["83 dollars a... | introductory | https://www.codewars.com/kata/5b23d98da97f02a5f4000a4c |
def dollar_to_speech(value):
| 16 |
3,945 | Student A and student B are giving each other test answers during a test.
They don't want to be caught so they are sending each other coded messages.
Student A is sending student B the message: `Answer to Number 5 Part b`.
He starts of with a square grid (in this example the grid = 5x5).
He writes the message do... | ["def decipher_message(message):\n n = int(len(message) ** 0.5)\n return ''.join(message[i::n] for i in range(n))", "from math import sqrt\ndef decipher_message(message):\n key = int(sqrt(len(message)))\n plaintext = [\"\"] * key\n current_row = 0\n for symbol in message:\n plaintext[current_ro... | {"fn_name": "decipher_message", "inputs": [["92287a76 585a2y0"], [" a29068686a275y5"], ["8a 55y0y0y5a7 78"], ["9y98a877a95976a758726a89a5659957ya y"], ["aa297625 88a02670997 86ya880 00a9067"], ["826a976a508a9a 687600a2800 895055y a"], [" a702a067629y022ay865y9yy92a60226 9869y0 y88y077"], ["y0y 62 27059y ya6568588a956a... | introductory | https://www.codewars.com/kata/5a1a144f8ba914bbe800003f |
def decipher_message(message):
| 16 |
3,985 | You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N. If there is no index that would make this happen, return `-1`.
__For example:__
Let's say you are given the array `{1... | ["def find_even_index(arr):\n for i in range(len(arr)):\n if sum(arr[:i]) == sum(arr[i+1:]):\n return i\n return -1\n", "def find_even_index(lst):\n left_sum = 0\n right_sum = sum(lst)\n for i, a in enumerate(lst):\n right_sum -= a\n if left_sum == right_sum:\n ... | {"fn_name": "find_even_index", "inputs": [[["1", "2", "3", "4", "3", "2", "1"]], [["1", "100", "50", "-51", "1", "1"]], [["1", "2", "3", "4", "5", "6"]], [["20", "10", "30", "10", "10", "15", "35"]], [["20", "10", "-80", "10", "10", "15", "35"]], [["10", "-80", "10", "10", "15", "35", "20"]], [["0", "0", "0", "0", "0"]... | introductory | https://www.codewars.com/kata/5679aa472b8f57fb8c000047 |
def find_even_index(arr):
| 16 |
4,022 | # A History Lesson
Soundex is an interesting phonetic algorithm developed nearly 100 years ago for indexing names as they are pronounced in English. The goal is for homophones to be encoded to the same representation so that they can be matched despite minor differences in spelling.
Reference: https://en.wikipedia.or... | ["import re\n\nREPLACMENTS = [\"BFPV\", \"CGJKQSXZ\", \"DT\",\"L\",\"MN\",\"R\"]\nER1, ER2 = \"HW\", \"AEIOUY\"\n\nTABLE_ERASE1 = str.maketrans(\"\", \"\", ER1)\nTABLE_NUMS = str.maketrans( ''.join(REPLACMENTS), ''.join( str(n)*len(elt) for n,elt in enumerate(REPLACMENTS, 1)) )\nTABLE_ERASE2 = str.maketrans(\"\"... | {"fn_name": "soundex", "inputs": [["Sarah Connor"], ["Sara Conar"], ["Serah Coner"], ["Sarh Connor"], ["Sayra Cunnarr"], ["Tim"], ["Joe"], ["Bob"], ["Robert"], ["Rupert"], ["Rubin"], ["Ashcraft"], ["Ashcroft"], ["Tymczak"], ["Pfister"], ["uryrtkzp"]], "outputs": [["S600 C560"], ["S600 C560"], ["S600 C560"], ["S600 C560... | introductory | https://www.codewars.com/kata/587319230e9cf305bb000098 |
def soundex(name):
| 16 |
4,031 | # Esolang Interpreters #2 - Custom Smallfuck Interpreter
## About this Kata Series
"Esolang Interpreters" is a Kata Series that originally began as three separate, independent esolang interpreter Kata authored by [@donaldsebleung](http://codewars.com/users/donaldsebleung) which all shared a similar format and were al... | ["def interpreter(code, tape):\n tape = list(map(int, tape))\n ptr = step = loop = 0\n \n while 0 <= ptr < len(tape) and step < len(code):\n command = code[step]\n \n if loop:\n if command == \"[\": loop += 1\n elif command == \"]\": loop -= 1\n \n ... | {"fn_name": "interpreter", "inputs": [["*", "00101100"], ["*>*>*>*>*>*>*>*", "00101100"], ["*>*>>*>>>*>*", "00101100"], [">>>>>*<*<<*", "00101100"], [">*>*;;;.!.,+-++--!!-!!!-", "00101100"], [" * >* >*>*lskdfjsdklfj>*;;+--+--+++--+-+- lskjfiom,x>*sdfsdf>sdfsfsdfsdfwervbnbvn*,.,.,,.,. >*", "00101100"], [... | introductory | https://www.codewars.com/kata/58678d29dbca9a68d80000d7 |
def interpreter(code, tape):
| 16 |
4,046 | # Explanation
It's your first day in the robot factory and your supervisor thinks that you should start with an easy task. So you are responsible for purchasing raw materials needed to produce the robots.
A complete robot weights `50` kilogram. Iron is the only material needed to create a robot. All iron is inserted ... | ["from math import ceil\n\ndef calculate_scrap(arr,n):\n x = 50\n for i in arr:\n x /= (1-i/100)\n return ceil(n*x)", "from functools import reduce\nfrom operator import mul\nfrom math import ceil\n\ndef calculate_scrap(scraps, number_of_robots):\n return ceil(50 * number_of_robots * 100**len(scraps)... | {"fn_name": "calculate_scrap", "inputs": [[["10"], "90"], [["20", "10"], "55"], [["0"], "90"], [["10", "0"], "90"], [["0", "10"], "90"], [["10", "0", "0", "10"], "81"], [["0", "10", "0", "10"], "81"], [["0", "10", "10", "0"], "81"], [["10", "20", "30", "40", "50", "60", "70", "80", "90"], "25"], [["90", "80", "70", "60... | introductory | https://www.codewars.com/kata/5898a7208b431434e500013b |
def calculate_scrap(scraps, number_of_robots):
| 16 |
4,050 | Laura really hates people using acronyms in her office and wants to force her colleagues to remove all acronyms before emailing her. She wants you to build a system that will edit out all known acronyms or else will notify the sender if unknown acronyms are present.
Any combination of three or more letters in upper ca... | ["import re\nfrom functools import reduce\n\n_ACRONYMS = {\n 'KPI': 'key performance indicators',\n 'EOD': 'the end of the day',\n 'EOP': 'the end of the day', # snafu in the tests?\n 'TBD': 'to be decided',\n 'WAH': 'work at home',\n 'IAM': 'in a meeting',\n 'OOO': 'out of office',\n ... | {"fn_name": "acronym_buster", "inputs": [["BRB I need to go into a KPI meeting before EOD"], ["Going to WAH today. NRN. OOO"], ["We're looking at SMB on SM DMs today"], ["KPI"], ["TBD"], ["TBD by EOD"], ["BRB I am OOO"], ["WAH"], ["IAM"], ["Hi PAB"], ["HATDBEA"], ["LDS"], ["PB"], ["FA"], ["CTA and HTTP"], ["My SM accou... | introductory | https://www.codewars.com/kata/58397ee871df657929000209 |
def acronym_buster(message):
| 16 |
4,057 | Complete the function that determines the score of a hand in the card game [Blackjack](https://en.wikipedia.org/wiki/Blackjack) (aka 21).
The function receives an array of strings that represent each card in the hand (`"2"`, `"3",` ..., `"10"`, `"J"`, `"Q"`, `"K"` or `"A"`) and should return the score of the hand (int... | ["def score_hand(a):\n n = sum(11 if x == \"A\" else 10 if x in \"JQK\" else int(x) for x in a)\n for _ in range(a.count(\"A\")):\n if n > 21:\n n -= 10\n return n", "def score_hand(cards):\n total = 0\n number_of_aces = 0\n for i in cards:\n if i == \"A\":\n total ... | {"fn_name": "score_hand", "inputs": [[["2", "3"]], [["4", "5", "6"]], [["7", "7", "8"]], [["9", "2", "10"]], [["4", "7", "8"]], [["J", "3"]], [["K", "J", "Q"]], [["A", "3"]], [["A", "J"]], [["A", "A", "A", "J"]], [["A", "2", "A", "9", "9"]], [["A", "A"]], [["8", "A", "A"]], [["5", "4", "A", "A"]], [["A", "2", "A", "3",... | introductory | https://www.codewars.com/kata/534ffb35edb1241eda0015fe |
def score_hand(cards):
| 16 |
4,069 | I love Fibonacci numbers in general, but I must admit I love some more than others.
I would like for you to write me a function that when given a number (n) returns the n-th number in the Fibonacci Sequence.
For example:
```python
nth_fib(4) == 2
```
Because 2 is the 4th number in the Fibonacci Sequence.
For ... | ["def nth_fib(n):\n a, b = 0, 1\n for i in range(n-1):\n a, b = b, a + b\n return a", "def nth_fib(n):\n a, b = (0, 1)\n for _ in range(n-1):\n a, b = b, a + b\n return a", "def nth_fib(n):\n if n==1:\n return 0\n elif n==2:\n return 1\n else:\n return nth_fib(n-1)+nth_fib(n-2)\n", "from m... | {"fn_name": "nth_fib", "inputs": [["1"], ["2"], ["3"], ["4"], ["6"], ["7"], ["8"], ["9"], ["10"], ["12"], ["14"], ["16"], ["17"], ["22"], ["23"], ["25"]], "outputs": [["0"], ["1"], ["1"], ["2"], ["5"], ["8"], ["13"], ["21"], ["34"], ["89"], ["233"], ["610"], ["987"], ["10946"], ["17711"], ["46368"]]} | introductory | https://www.codewars.com/kata/522551eee9abb932420004a0 |
def nth_fib(n):
| 16 |
4,105 | We have the first value of a certain sequence, we will name it ```initVal```.
We define pattern list, ```patternL```, an array that has the differences between contiguous terms of the sequence.
``` E.g: patternL = [k1, k2, k3, k4]```
The terms of the sequence will be such values that:
```python
term1 = initVal
term2... | ["from itertools import cycle\n\ndef sumDig_nthTerm(initVal, patternL, nthTerm):\n \n for c, i in enumerate(cycle(patternL), 2):\n initVal += i\n \n if c == nthTerm:\n return sum(int(v) for v in str(initVal))", "def sumDig_nthTerm(base, cycle, k):\n loop, remaining = divmod(k - ... | {"fn_name": "sumDig_nthTerm", "inputs": [["10", ["2", "1", "3"], "6"], ["10", ["2", "1", "3"], "50"], ["10", ["2", "1", "3"], "78"], ["10", ["2", "1", "3"], "157"], ["10", ["2", "2", "5", "8"], "6"], ["10", ["2", "2", "5", "8"], "15"], ["10", ["2", "2", "5", "8"], "50"], ["10", ["2", "2", "5", "8"], "78"], ["10", ["2",... | introductory | https://www.codewars.com/kata/55ffb44050558fdb200000a4 |
def sumDig_nthTerm(initVal, patternL, nthTerm):
| 16 |
4,130 | # Valid HK Phone Number
## Overview
In Hong Kong, a valid phone number has the format ```xxxx xxxx``` where ```x``` is a decimal digit (0-9). For example:
## Task
Define two functions, ```isValidHKPhoneNumber``` and ```hasValidHKPhoneNumber```, that ```return```s whether a given string is a valid HK phone number a... | ["import re\n\nHK_PHONE_NUMBER = '\\d{4} \\d{4}'\n\ndef is_valid_HK_phone_number(number):\n return bool(re.match(HK_PHONE_NUMBER+'\\Z',number))\n\ndef has_valid_HK_phone_number(number):\n return bool(re.search(HK_PHONE_NUMBER,number))", "from re import match, search\n\nis_valid_HK_phone_number = lambda n: match('... | {"fn_name": "is_valid_HK_phone_number", "inputs": [["1234 5678"], ["2359 1478"], ["85748475"], ["3857 4756"], ["sklfjsdklfjsf"], [" 1234 5678 "], ["abcd efgh"], ["9684 2396"], ["836g 2986"], ["0000 0000"], ["123456789"], [" 987 634 "], [" 6 "], ["8A65 2986"], ["8368 2aE6"], ["8c65 2i86"]], "outputs": [[tru... | introductory | https://www.codewars.com/kata/56f54d45af5b1fec4b000cce |
def is_valid_HK_phone_number(number):
| 16 |
4,140 | # Bubblesort Algorithm
## Overview
The Bubblesort Algorithm is one of many algorithms used to sort a list of similar items (e.g. all numbers or all letters) into either ascending order or descending order. Given a list (e.g.):
```python
[9, 7, 5, 3, 1, 2, 4, 6, 8]
```
To sort this list in ascending order using Bub... | ["def bubblesort_once(l):\n l = l[:]\n for i in range(len(l)-1):\n if l[i] > l[i+1]:\n l[i], l[i+1] = l[i+1], l[i]\n return l", "def bubblesort_once(L):\n if len(L)<=1 : return L\n if L[0]<=L[1]: return [L[0]] + bubblesort_once(L[1:])\n return [L[1]] + bubblesort_once([L[0]]+L[2:])",... | {"fn_name": "bubblesort_once", "inputs": [[["1", "3"]], [["3", "1"]], [["2", "4", "1"]], [["17", "5", "11"]], [["25", "16", "9"]], [["103", "87", "113"]], [["1032", "3192", "2864"]], [["2", "3", "4", "1"]], [["3", "4", "1", "2"]], [["4", "1", "2", "3"]], [["3", "1", "8", "5"]], [["1", "9", "5", "5"]], [["6", "3", "4", ... | introductory | https://www.codewars.com/kata/56b97b776ffcea598a0006f2 |
def bubblesort_once(l):
| 16 |
4,143 | [Generala](https://en.wikipedia.org/wiki/Generala) is a dice game popular in South America. It's very similar to [Yahtzee](https://en.wikipedia.org/wiki/Yahtzee) but with a different scoring approach. It is played with 5 dice, and the possible results are:
| Result | Points | Rules ... | ["def points(dice):\n dice = sorted([int(d) for d in dice])\n counts = [dice.count(i) for i in range(1, 7)]\n if 5 in counts:\n # GENERALA\n return 50\n if 4 in counts:\n # POKER\n return 40\n if 3 in counts and 2 in counts:\n # FULLHOUSE\n return 30\n if coun... | {"fn_name": "points", "inputs": [["55555"], ["44444"], ["44441"], ["33233"], ["22262"], ["12121"], ["44455"], ["66116"], ["12345"], ["23456"], ["34561"], ["13564"], ["62534"], ["44421"], ["61623"], ["12346"]], "outputs": [["50"], ["50"], ["40"], ["40"], ["40"], ["30"], ["30"], ["30"], ["20"], ["20"], ["20"], ["20"], ["... | introductory | https://www.codewars.com/kata/5f70c55c40b1c90032847588 |
def points(dice):
| 16 |
4,144 | In number theory, an **[abundant](https://en.wikipedia.org/wiki/Abundant_number)** number or an **[excessive](https://en.wikipedia.org/wiki/Abundant_number)** number is one for which the sum of it's **[proper divisors](http://mathworld.wolfram.com/ProperDivisor.html)** is greater than the number itself. The integer *... | ["def abundant(h):\n for n in range(h,0,-1):\n s = sum(i for i in range(1,n) if n % i == 0)\n if s > h:\n return [[n],[s-n]]", "from operator import itemgetter\nfrom bisect import bisect\n\nLIMIT = 2000\n\nmemo, result = [0]*LIMIT, {}\nfor x in range(1, LIMIT):\n if memo[x] > x:\n ... | {"fn_name": "abundant", "inputs": [["15"], ["100"], ["999"], ["200"], ["250"], ["300"], ["350"], ["400"], ["450"], ["500"], ["555"], ["666"], ["707"], ["777"], ["900"], ["1111"]], "outputs": [[[["12"], ["4"]]], [[["100"], ["17"]]], [[["996"], ["360"]]], [[["200"], ["65"]]], [[["246"], ["12"]]], [[["300"], ["268"]]], [[... | introductory | https://www.codewars.com/kata/57f3996fa05a235d49000574 |
def abundant(h):
| 16 |
4,157 | In English and programming, groups can be made using symbols such as `()` and `{}` that change meaning. However, these groups must be closed in the correct order to maintain correct syntax.
Your job in this kata will be to make a program that checks a string for correct grouping. For instance, the following groups are... | ["BRACES = { '(': ')', '[': ']', '{': '}' }\n\ndef group_check(s):\n stack = []\n for b in s:\n c = BRACES.get(b)\n if c:\n stack.append(c)\n elif not stack or stack.pop() != b:\n return False\n return not stack", "def group_check(s):\n while \"{}\" in s or \"()\" ... | {"fn_name": "group_check", "inputs": [["({})"], ["[[]()]"], ["[{()}]"], ["()"], ["([])"], ["{}([])"], ["{[{}[]()[]{}{}{}{}{}{}()()()()()()()()]{{{[[[((()))]]]}}}}(())[[]]{{}}[][][][][][][]({[]})"], [""], ["{(})"], ["[{}{}())"], ["{)[}"], ["[[[]])"], ["{([]})"], ["([]"], ["[])"], ["{{{{{{{{{{{((((((([])))))))}}}}}}}}}}"... | introductory | https://www.codewars.com/kata/54b80308488cb6cd31000161 |
def group_check(s):
| 16 |
4,163 | An array is called `centered-N` if some `consecutive sequence` of elements of the array sum to `N` and this sequence is preceded and followed by the same number of elements.
Example:
```
[3,2,10,4,1,6,9] is centered-15
because the sequence 10,4,1 sums to 15 and the sequence
is preceded by two elements [3,2] and foll... | ["def is_centered(arr,n):\n l = int(len(arr)/2) if len(arr)%2==0 else int((len(arr)-1)/2)\n return any(sum(arr[i:-i])==n for i in range(1, l+1)) or sum(arr)==n", "from itertools import accumulate\n\ndef is_centered(arr, n):\n xs = [0] + list(accumulate(arr))\n return any(b-a==n for a, b in zip(xs[:len(arr)/... | {"fn_name": "is_centered", "inputs": [[["0", "0", "0"], "0"], [["3", "2", "10", "4", "1", "6", "9"], "15"], [["2", "10", "4", "1", "6", "9"], "15"], [["3", "2", "10", "4", "1", "6"], "15"], [["1", "1", "8", "3", "1", "1"], "15"], [["1", "1", "8", "3", "1", "1"], "11"], [["1", "1", "8", "3", "1", "1"], "13"], [["9", "0"... | introductory | https://www.codewars.com/kata/59b06d83cf33953dbb000010 |
def is_centered(arr,n):
| 16 |
4,169 | ### Task:
Your job is to take a pair of parametric equations, passed in as strings, and convert them into a single rectangular equation by eliminating the parameter. Both parametric halves will represent linear equations of x as a function of time and y as a function of time respectively.
The format of the final equ... | ["from fractions import gcd\nimport re\n\n\nINSERTER = re.compile(r'(?<!\\d)(?=[xyt])')\nFINDER = re.compile(r'-?\\d+')\n\n\ndef lcm(a,b): return a*b//gcd(a,b)\ndef simplify(s): return INSERTER.sub('1', s.replace(' ',''))\n\n\ndef para_to_rect(*equations):\n coefs = [ list(map(int, FINDER.findall(eq))) for eq i... | {"fn_name": "para_to_rect", "inputs": [["x = -12t + 18", "y = 8t + 7"], ["x = 12t + 18", "y = -8t + 7"], ["x = -t + 12", "y = 12t - 1"], ["x = -18t + 12", "y = 7t - 8"], ["x = 2t + 5", "y = 3t + 4"], ["x = 15t - 2", "y = -20t - 11"], ["x = 2t - 1", "y = 2t - 1"], ["x = 16t - 16", "y = -8t - 12"], ["x = t + 12", "y = 2t... | introductory | https://www.codewars.com/kata/5b13530f828fab68820000c4 |
def para_to_rect(eqn1, eqn2):
| 16 |
4,174 | 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
Task:
Write
```
smallest(n)
```
that will find the smallest positive number that is evenly divisible by all of the numbers from 1 to n (n <= 40).
E.g
```python
smallest(5) == 60 # 1 to 5 can all divide evenly int... | ["def smallest(n):\n x, y, m = 1, 1, 1\n while m <= n:\n if x % m == 0:\n m += 1\n y = int(x)\n else:\n x += y\n return x\n", "from functools import reduce\nfrom math import gcd\nlcm = lambda x,y: x*y//gcd(x, y)\n\n# Note: there is a lcm function in numpy 1.17 but... | {"fn_name": "smallest", "inputs": [["1"], ["2"], ["3"], ["4"], ["6"], ["8"], ["9"], ["10"], ["11"], ["12"], ["13"], ["15"], ["16"], ["17"], ["19"], ["20"]], "outputs": [["1"], ["2"], ["6"], ["12"], ["60"], ["840"], ["2520"], ["2520"], ["27720"], ["27720"], ["360360"], ["360360"], ["720720"], ["12252240"], ["232792560"]... | introductory | https://www.codewars.com/kata/55e7d9d63bdc3caa2500007d |
def smallest(n):
| 16 |
4,196 | # Summation Of Primes
The sum of the primes below or equal to 10 is **2 + 3 + 5 + 7 = 17**. Find the sum of all the primes **_below or equal to the number passed in_**.
From Project Euler's [Problem #10](https://projecteuler.net/problem=10 "Project Euler - Problem 10"). | ["from bisect import bisect\n\ndef sieve(n):\n sieve, primes = [0]*(n+1), []\n for i in range(2, n+1):\n if not sieve[i]:\n primes.append(i) \n for j in range(i**2, n+1, i): sieve[j] = 1\n return primes\n\nPRIMES = sieve(1000000)\n\ndef summationOfPrimes(n):\n return sum(PRIMES[... | {"fn_name": "summationOfPrimes", "inputs": [["5"], ["6"], ["7"], ["8"], ["9"], ["20"], ["40"], ["100"], ["300"], ["500"], ["1000"], ["2000"], ["3000"], ["4000"], ["5000"], ["25000"]], "outputs": [["10"], ["10"], ["17"], ["17"], ["17"], ["77"], ["197"], ["1060"], ["8275"], ["21536"], ["76127"], ["277050"], ["593823"], [... | introductory | https://www.codewars.com/kata/59ab0ca4243eae9fec000088 |
def summationOfPrimes(primes):
| 16 |
4,198 | ### What is simplifying a square root?
If you have a number, like 80, for example, you would start by finding the greatest perfect square divisible by 80. In this case, that's 16. Find the square root of 16, and multiply it by 80 / 16. Answer = 4 √5.
##### The above example:
:\n for d in range(int(n ** .5), 0, -1):\n if not n % d ** 2: break\n if d*d == n: return '%d' % d\n elif d == 1: return 'sqrt %d' % n\n else: return '%d sqrt %d' % (d, n // d ** 2)\n\ndef desimplify(s):\n x, _, y = s.partition('sqrt')\n return int(x or '1') ** 2 * int(y or '1'... | {"fn_name": "simplify", "inputs": [["2"], ["3"], ["16"], ["18"], ["20"], ["24"], ["32"], ["4"], ["7"], ["9"], ["10"], ["12"], ["13"], ["14"], ["50"], ["80"]], "outputs": [["sqrt 2"], ["sqrt 3"], ["4"], ["3 sqrt 2"], ["2 sqrt 5"], ["2 sqrt 6"], ["4 sqrt 2"], ["2"], ["sqrt 7"], ["3"], ["sqrt 10"], ["2 sqrt 3"], ["sqrt 13... | introductory | https://www.codewars.com/kata/5850e85c6e997bddd300005d |
def simplify(n):
| 16 |
4,227 | Your program will receive an array of complex numbers represented as strings. Your task is to write the `complexSum` function which have to return the sum as a string.
Complex numbers can be written in the form of `a+bi`, such as `2-3i` where `2` is the real part, `3` is the imaginary part, and `i` is the "imaginary ... | ["def complexSum(arr, sub={'1i': 'i', '-1i': '-i', '0i': '0'}):\n s = str(sum(complex(x.replace('i', 'j')) for x in arr)).replace('j', 'i')\n s = s.strip('()')\n s = s.replace('+0i', '')\n return sub.get(s, s) ", "def complexSum(arr):\n a = [complex(i.replace(\"i\", \"j\")) for i in arr]\n s = 0\n ... | {"fn_name": "complexSum", "inputs": [[[]], [["3+4i"]], [["123+456i"]], [["0"]], [["1", "1"]], [["-5", "5"]], [["1", "10", "100", "1000"]], [["5+4i", "11+3i"]], [["-1-i", "7+10i"]], [["10+i", "10-i", "9"]], [["2+i", "3+2i", "-5-4i"]], [["-1000i", "1000i", "1234"]], [["-i", "123", "4-i"]], [["-7+10i", "7+251i"]], [["-25-... | introductory | https://www.codewars.com/kata/5a981424373c2e479c00017f |
def complexSum(arr):
| 16 |
4,232 | In Math, an improper fraction is a fraction where the numerator (the top number) is greater than or equal to the denominator (the bottom number) For example: ```5/3``` (five third).
A mixed numeral is a whole number and a fraction combined into one "mixed" number. For example: ```1 1/2``` (one and a half) is a mixed n... | ["def convert_to_mixed_numeral(parm):\n a, b = list(map(int, parm.split('/')))\n d, r = divmod(abs(a), b)\n s = (0 < a) - (a < 0)\n return parm if d == 0 else ('{}' + ' {}/{}' * (r != 0)).format(d * s, r, b)\n", "def convert_to_mixed_numeral(parm):\n sign, parm = parm[:(\"-\" in parm)], parm[(\"-\" in pa... | {"fn_name": "convert_to_mixed_numeral", "inputs": [["74/30"], ["13/5"], ["1/1"], ["10/10"], ["900/10"], ["9920/124"], ["9/77"], ["12/18"], ["6/36"], ["1/18"], ["-64/8"], ["-6/8"], ["-9/78"], ["-504/26"], ["-47/2"], ["-21511/21"]], "outputs": [["2 14/30"], ["2 3/5"], ["1"], ["1"], ["90"], ["80"], ["9/77"], ["12/18"], ["... | introductory | https://www.codewars.com/kata/574e4175ff5b0a554a00000b |
def convert_to_mixed_numeral(parm):
| 16 |
4,237 | Converting a 24-hour time like "0830" or "2030" to a 12-hour time (like "8:30 am" or "8:30 pm") sounds easy enough, right? Well, let's see if you can do it!
You will have to define a function named "to12hourtime", and you will be given a four digit time string (in "hhmm" format) as input.
Your task is to return a 12... | ["from datetime import datetime\n\ndef to12hourtime(t):\n return datetime.strptime(t, '%H%M').strftime('%I:%M %p').lstrip('0').lower()", "def to12hourtime(t):\n hour = int(t[:2])\n \n if hour >= 12:\n hour -= 12\n suf = 'pm'\n else:\n suf = 'am'\n \n if hour == 0:\n hour... | {"fn_name": "to12hourtime", "inputs": [["0110"], ["0131"], ["0354"], ["0527"], ["0801"], ["0929"], ["0936"], ["1315"], ["1338"], ["1339"], ["1354"], ["1457"], ["1631"], ["1846"], ["1907"], ["2011"]], "outputs": [["1:10 am"], ["1:31 am"], ["3:54 am"], ["5:27 am"], ["8:01 am"], ["9:29 am"], ["9:36 am"], ["1:15 pm"], ["1:... | introductory | https://www.codewars.com/kata/59b0ab12cf3395ef68000081 |
def to12hourtime(t):
| 16 |
4,242 | # Task
You're standing at the top left corner of an `n × m` grid and facing towards the `right`.
Then you start walking one square at a time in the direction you are facing.
If you reach the border of the grid or if the next square you are about to visit has already been visited, you turn right.
You stop w... | ["def direction_in_grid(n, m):\n return \"LR\"[n%2] if m >= n else \"UD\"[m%2]\n", "def direction_in_grid(n,m):\n return \"LRUD\"[n%2 if m>=n else 2+m%2]\n", "NEXT = {'R': 'D', 'D': 'L', 'L': 'U', 'U': 'R'}\n\ndef direction_in_grid(n, m, d='R'):\n while n > 1:\n n, m, d = m, n-1, NEXT[d]\n return d", "... | {"fn_name": "direction_in_grid", "inputs": [["1", "1"], ["2", "2"], ["2", "3"], ["3", "1"], ["3", "2"], ["3", "4"], ["3", "5"], ["4", "2"], ["4", "3"], ["4", "4"], ["4", "5"], ["4", "6"], ["5", "4"], ["5", "5"], ["5", "6"], ["100", "100"]], "outputs": [["R"], ["L"], ["L"], ["D"], ["U"], ["R"], ["R"], ["U"], ["D"], ["L"... | introductory | https://www.codewars.com/kata/58bcd7f2f6d3b11fce000025 |
def direction_in_grid(n,m):
| 16 |
4,262 | Dee is lazy but she's kind and she likes to eat out at all the nice restaurants and gastropubs in town. To make paying quick and easy she uses a simple mental algorithm she's called The Fair %20 Rule. She's gotten so good she can do this in a few seconds and it always impresses her dates but she's perplexingly still si... | ["def calc_tip(p, r):\n if p % 10 < 5:\n p //= 10\n else:\n p = p // 10 + 1\n if r == 1:\n tip = p + 1\n elif r == 0:\n tip = p - 1\n else:\n tip = int(p/2) - 1\n return tip if tip >= 0 else 0", "def calc_tip(p, r):\n if p%10<5: p-=p%10\n else: p+=(10-p%10)\n ... | {"fn_name": "calc_tip", "inputs": [["4", "1"], ["4", "-1"], ["5", "-1"], ["14", "-1"], ["15", "1"], ["15", "0"], ["15", "-1"], ["24", "1"], ["24", "0"], ["24", "-1"], ["25", "1"], ["125", "1"], ["125", "0"], ["144", "1"], ["144", "0"], ["144", "-1"]], "outputs": [["1"], ["0"], ["0"], ["0"], ["3"], ["1"], ["0"], ["3"], ... | introductory | https://www.codewars.com/kata/568c3498e48a0231d200001f |
def calc_tip(p, r):
| 16 |
4,271 | We all know about Roman Numerals, and if not, here's a nice [introduction kata](http://www.codewars.com/kata/5580d8dc8e4ee9ffcb000050). And if you were anything like me, you 'knew' that the numerals were not used for zeroes or fractions; but not so!
I learned something new today: the [Romans did use fractions](https:/... | ["FRACTIONS = \" . : :. :: :.: S S. S: S:. S:: S:.:\".split(\" \")\nUNITS = \" I II III IV V VI VII VIII IX\" .split(\" \")\nTENS = \" X XX XXX XL L LX LXX LXXX XC\" .split(\" \")\nHUNDREDS = \" C CC CCC CD D DC DCC DCCC CM\" .split(\" \")\nTHOUSANDS = \" M MM MMM MMMM MMMMM\" .sp... | {"fn_name": "roman_fractions", "inputs": [["-12"], ["0", "-1"], ["1", "5"], ["1", "9"], ["1632", "2"], ["5000"], ["5001"], ["0", "0"], ["0", "1"], ["0", "3"], ["0", "4"], ["0", "5"], ["0", "6"], ["0", "7"], ["0", "8"], ["0", "10"]], "outputs": [["NaR"], ["NaR"], ["I:.:"], ["IS:."], ["MDCXXXII:"], ["MMMMM"], ["NaR"], ["... | introductory | https://www.codewars.com/kata/55832eda1430b01275000059 |
def roman_fractions(integer, fraction=None):
| 16 |
4,281 | To introduce the problem think to my neighbor who drives a tanker truck.
The level indicator is down and he is worried
because he does not know if he will be able to make deliveries.
We put the truck on a horizontal ground and measured the height of the liquid in the tank.
Fortunately the tank is a perfect cylinder ... | ["import math\ndef tankvol(h, d, vt):\n r = d/2.0\n if h == r: return vt/2 # is the tank half full?\n half = h>r # is it more than half full\n h = d-h if half else h # adjust h accordingly\n a = r-h # perpendicular intercept of the chord\n b = math.sqrt(r**2-... | {"fn_name": "tankvol", "inputs": [["5", "7", "3848"], ["2", "8", "5026"], ["4", "9", "6361"], ["3", "10", "7853"], ["3", "5", "1963"], ["4", "7", "3848"], ["0", "7", "3848"], ["7", "7", "3848"], ["2", "5", "1963"], ["2", "4", "1256"], ["4", "10", "7853"], ["3", "9", "6361"], ["2", "10", "7853"], ["5", "9", "6361"], ["5... | introductory | https://www.codewars.com/kata/55f3da49e83ca1ddae0000ad |
def tankvol(h, d, vt):
| 16 |
4,285 | Given an array of 4 integers
```[a,b,c,d]``` representing two points ```(a, b)``` and ```(c, d)```, return a string representation of the slope of the line joining these two points.
For an undefined slope (division by 0), return ```undefined``` . Note that the "undefined" is case-sensitive.
```
a:x1
b:y1
... | ["def find_slope(points):\n x1, y1, x2, y2 = points\n if x2 - x1 == 0:\n return \"undefined\"\n return str((y2 - y1) // (x2 - x1))", "def find_slope(points):\n x1, y1, x2, y2 = points\n dx = x2 - x1\n dy = y2 - y1\n if dx != 0:\n return str(int(dy / dx))\n else:\n return 'un... | {"fn_name": "find_slope", "inputs": [[["3", "-20", "5", "8"]], [["17", "-3", "17", "8"]], [["1", "-19", "-2", "-7"]], [["6", "-12", "15", "-3"]], [["15", "-3", "15", "-3"]], [["9", "3", "19", "-17"]], [["3", "6", "4", "10"]], [["2", "7", "4", "-7"]], [["1", "24", "2", "88"]], [["4", "16", "4", "18"]], [["7", "28", "9",... | introductory | https://www.codewars.com/kata/55a75e2d0803fea18f00009d |
def find_slope(points):
| 16 |
4,298 | The internet is a very confounding place for some adults. Tom has just joined an online forum and is trying to fit in with all the teens and tweens. It seems like they're speaking in another language! Help Tom fit in by translating his well-formatted English into n00b language.
The following rules should be observed:
... | ["import re\nbase = \"too?|fore?|oo|be|are|you|please|people|really|have|know|s|[.,']\".split('|')\nnoob = \"2|4|00|b|r|u|plz|ppl|rly|haz|no|z|\".split('|')\n\ndef n00bify(text):\n for b, n in zip(base, noob):\n keep_casing = lambda m: n.upper() if m.group().isupper() else n\n text = re.sub(b, keep_cas... | {"fn_name": "n00bify", "inputs": [["Hi, how are you today?"], ["I think it would be nice if we could all get along."], ["Let's eat, Grandma!"], ["Woot woot woot woot woot woot!"], ["Hi, I can have cheeseburger?"], ["Sometimes I use ? in the middle of a sentence; is that ok?!"], ["Unto us a child is born."], ["What happ... | introductory | https://www.codewars.com/kata/552ec968fcd1975e8100005a |
def n00bify(text):
| 16 |
4,339 | Implement function which will return sum of roots of a quadratic equation rounded to 2 decimal places, if there are any possible roots, else return **None/null/nil/nothing**. If you use discriminant,when discriminant = 0, x1 = x2 = root => return sum of both roots. There will always be valid arguments.
Quadratic equa... | ["def roots(a,b,c):\n if b**2>=4*a*c:\n return round(-b/a,2)", "def roots(a,b,c):\n import math\n d = b ** 2 - 4 * a * c\n if d > 0:\n return round(-2 * b / (2 * a), 2)\n elif d == 0:\n x = -b / (2 * a)\n return x * 2\n else:\n return None", "def roots(a,b,c):\n r... | {"fn_name": "roots", "inputs": [["6", "0", "-24"], ["1", "5", "-24"], ["3", "-2", "-5"], ["3", "4", "9"], ["1", "4", "9"], ["2", "8", "8"], ["-3", "0", "12"], ["5", "3", "6"], ["1", "12", "36"], ["2", "5", "11"], ["1", "-3", "0"], ["2", "6", "9"], ["1", "5", "12"], ["1", "-6", "0"], ["1", "-11", "30"], ["8", "47", "41"... | introductory | https://www.codewars.com/kata/57d448c6ba30875437000138 |
def roots(a,b,c):
| 16 |
4,346 | Maya writes weekly articles to a well known magazine, but she is missing one word each time she is about to send the article to the editor. The article is not complete without this word. Maya has a friend, Dan, and he is very good with words, but he doesn't like to just give them away. He texts Maya a number and she ne... | ["hidden=lambda n: \"\".join(\"oblietadnm\"[int(d)] for d in str(n))", "trans = dict(zip('6174329805','abdeilmnot'))\n\ndef hidden(num):\n return ''.join( trans[char] for char in str(num) )", "def hidden(num):\n return str(num).translate(str.maketrans(\"6174329805\", \"abdeilmnot\"))", "def hidden(num):\n d = ... | {"fn_name": "hidden", "inputs": [["49632"], ["1425"], ["12674"], ["4735"], ["7345"], ["2394"], ["2068"], ["137"], ["1065"], ["6509"], ["5394"], ["56124"], ["968"], ["2687"], ["261"], ["8054"]], "outputs": [["email"], ["belt"], ["blade"], ["edit"], ["diet"], ["lime"], ["loan"], ["bid"], ["boat"], ["atom"], ["time"], ["t... | introductory | https://www.codewars.com/kata/5906a218dfeb0dbb52000005 |
def hidden(num):
| 16 |
4,349 | One of the first algorithm used for approximating the integer square root of a positive integer `n` is known as "Hero's method",
named after the first-century Greek mathematician Hero of Alexandria who gave the first description
of the method. Hero's method can be obtained from Newton's method which came 16 centuries ... | ["def int_rac(n, guess):\n \"\"\"Integer Square Root of an Integer\"\"\"\n x = guess\n cnt = 1\n while True:\n newx = (x + n // x) // 2 \n if abs(x - newx) < 1:\n return cnt\n x = newx\n cnt += 1", "def int_rac(n, guess):\n cnt = 0\n \n while True:\n cn... | {"fn_name": "int_rac", "inputs": [["25", "1"], ["125348", "300"], ["236", "12"], ["48981764", "8000"], ["6999", "700"], ["16000", "400"], ["16000", "100"], ["2500", "60"], ["250000", "600"], ["9094947017729282379150390625", "1"], ["246391990316004", "1"], ["403832254158749", "1"], ["217414278071071", "1"], ["6395931783... | introductory | https://www.codewars.com/kata/55efecb8680f47654c000095 |
def int_rac(n, guess):
| 16 |
4,351 | Given a string of characters, I want the function `findMiddle()`/`find_middle()` to return the middle number in the product of each digit in the string.
Example: 's7d8jd9' -> 7, 8, 9 -> 7\*8\*9=504, thus 0 should be returned as an integer.
Not all strings will contain digits. In this case and the case for any non-str... | ["from operator import mul\nfrom functools import reduce\n\ndef find_middle(s):\n if not s or not isinstance(s,str): return -1\n \n lstDig = [int(c) for c in s if c.isnumeric()]\n if not lstDig: return -1\n \n prod = str( reduce(mul,lstDig) )\n i = (len(prod) - 1) // 2\n return int(prod[i:-i ... | {"fn_name": "find_middle", "inputs": [["s7d8jd9"], ["58jd9fgh/fgh6s.,sdf"], ["s7d8jd9dfg4d"], ["asd.fasd.gasdfgsdfgh-sdfghsdfg/asdfga=sdfg"], ["44555"], ["s7d8jd9qwertqwrt v654ed1frg651"], ["asdf544684868"], [["a", "b", "c", "sfd"]], ["5d8jd9fgh/fgh6s.,6574ssdf8sdf9sdf98 3"], [" 99 "], ["58jd9fgh654d/fgh6s.,sdf"... | introductory | https://www.codewars.com/kata/5ac54bcbb925d9b437000001 |
def find_middle(string):
| 16 |
4,353 | The objective is to disambiguate two given names: the original with another
Let's start simple, and just work with plain ascii strings.
The function ```could_be``` is given the original name and another one to test
against.
```python
# should return True if the other name could be the same person
> could_be("Chuc... | ["def could_be(original, another):\n if not another.strip(): return False\n return all(name in original.split() for name in another.split())", "def could_be(original, another):\n original, another = (set(s.split()) for s in (original, another))\n return bool(another) and another <= original", "def could_be(... | {"fn_name": "could_be", "inputs": [["Carlos Ray Norris", "Carlos Ray Norris"], ["Carlos Ray Norris", "Carlos Ray"], ["Carlos Ray Norris", "Ray Norris"], ["Carlos Ray Norris", "Carlos Norris"], ["Carlos Ray Norris", "Carlos"], ["Carlos Ray Norris", "Norris Carlos"], ["Carlos Ray Norris", "Carlos Ray Norr"], ["Carlos Ray... | introductory | https://www.codewars.com/kata/580a429e1cb4028481000019 |
def could_be(original, another):
| 16 |
4,360 | Have a look at the following numbers.
```
n | score
---+-------
1 | 50
2 | 150
3 | 300
4 | 500
5 | 750
```
Can you find a pattern in it? If so, then write a function `getScore(n)`/`get_score(n)`/`GetScore(n)` which returns the score for any positive number `n`:
```c++
int getScore(1) = return 50;
int getS... | ["def get_score(n):\n return n * (n + 1) * 25", "def get_score(n):\n return 50*(n*(n+1))/2\n \n \n \n", "get_score = lambda n: 25 * n * (n + 1)", "get_score = lambda n, a=0: sum(a+i*50 for i in range(n+1))", "def get_score(n):\n return sum([x*50 for x in range(n+1)])", "def get_score(n):\n return 2... | {"fn_name": "get_score", "inputs": [["1"], ["2"], ["3"], ["4"], ["5"], ["6"], ["7"], ["9"], ["10"], ["20"], ["30"], ["123"], ["1000"], ["1234"], ["10000"], ["12345"]], "outputs": [["50"], ["150"], ["300"], ["500"], ["750"], ["1050"], ["1400"], ["2250"], ["2750"], ["10500"], ["23250"], ["381300"], ["25025000"], ["380997... | introductory | https://www.codewars.com/kata/5254bd1357d59fbbe90001ec |
def get_score(n):
| 16 |
4,374 | It's the fourth quater of the Super Bowl and your team is down by 4 points. You're 10 yards away from the endzone, if your team doesn't score a touchdown in the next four plays you lose. On a previous play, you were injured and rushed to the hospital. Your hospital room has no internet, tv, or radio and you don't know ... | ["def did_we_win(plays):\n plays = [p for p in plays if p]\n return all(p != 'turnover' for y,p in plays) and sum(-y if p == 'sack' else y for y,p in plays) > 10 ", "def did_we_win(plays):\n s = 0\n for i in range(4):\n if not plays[i]: break\n if plays[i][1] == \"turnover\": return... | {"fn_name": "did_we_win", "inputs": [[[["8", "pass"], ["5", "sack"], ["3", "sack"], ["5", "run"]]], [[["12", "pass"], [], [], []]], [[["2", "run"], ["5", "pass"], ["3", "sack"], ["8", "pass"]]], [[["5", "pass"], ["6", "turnover"], [], []]], [[["5", "pass"], ["5", "pass"], ["10", "sack"], ["10", "run"]]], [[["5", "pass"... | introductory | https://www.codewars.com/kata/59f69fefa0143109e5000019 |
def did_we_win(plays):
| 16 |
4,387 | Please write a function that sums a list, but ignores any duplicate items in the list.
For instance, for the list [3, 4, 3, 6] , the function should return 10. | ["from collections import Counter\n\n\ndef sum_no_duplicates(nums):\n return sum(k for k, v in list(Counter(nums).items()) if v == 1)\n", "def sum_no_duplicates(l):\n return sum(n for n in set(l) if l.count(n) == 1)", "from collections import Counter\n\ndef sum_no_duplicates(l):\n return sum(k for k,v in list(... | {"fn_name": "sum_no_duplicates", "inputs": [[["5", "6", "10", "3", "10", "10", "6", "7", "0", "9", "1", "1", "6", "3", "1"]], [["7", "2", "10", "9", "10", "2", "7", "3", "10", "8", "2", "5"]], [["7", "2", "0", "3", "5", "7", "8", "3", "2", "10", "9", "5"]], [["7", "10", "10", "9", "0", "2", "5", "10", "3", "8", "1", "4... | introductory | https://www.codewars.com/kata/5993fb6c4f5d9f770c0000f2 |
def sum_no_duplicates(l):
| 16 |
4,403 | In computing, there are two primary byte order formats: big-endian and little-endian. Big-endian is used primarily for networking (e.g., IP addresses are transmitted in big-endian) whereas little-endian is used mainly by computers with microprocessors.
Here is an example (using 32-bit integers in hex format):
Little-... | ["def switch_endian(n, bits):\n out = 0\n while bits > 7:\n bits -= 8\n out <<= 8\n out |= n & 255\n n >>= 8\n return None if n or bits else out", "# Bitwise operators? What's that? Don't need it\ndef switch_endian(n, bits):\n if not (0 <= n < 2**bits and bits == 2**(bits.bit_... | {"fn_name": "switch_endian", "inputs": [["255", "8"], ["256", "8"], ["1534", "32"], ["364334", "32"], ["256245645346", "128"], ["6423", "256"], ["98", "512"], ["9827498275894278943758934789347", "512"], ["111", "1024"], ["859983475894789589772983457982345896389458937589738945435", "1024"], ["98345873489734895", "16"], ... | introductory | https://www.codewars.com/kata/56f2dd31e40b7042ad001026 |
def switch_endian(n, bits):
| 16 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.