inputs
stringlengths 50
14k
| targets
stringlengths 4
655k
|
|---|---|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(letter):
msg = 'Position of alphabet: '
return f'{msg}{"abcdefghijklmnopqrstuvwxyz".find(letter) + 1}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
alphabet.lower()
al='abcdefghijklmnopqrstuvwxyz'
ind = al.index(alphabet)
return "Position of alphabet: {}".format(ind+1)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
import string
a = string.ascii_lowercase.index(alphabet)
b = a + 1
c = str(b)
return ("Position of alphabet: " + (c))
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(char):
return 'Position of alphabet: {}'.format(ord(char) - 96)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
alph = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
for i in range(26):
if alph[i] == alphabet: return "Position of alphabet: " + str(i+1)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
dict_alpha = {
"a" : 1,
"b" : 2,
"c" : 3,
"d" : 4,
"e" : 5,
"f" : 6,
"g" : 7,
"h" : 8,
"i" : 9,
"j" : 10,
"k" : 11,
"l" : 12,
"m" : 13,
"n" : 14,
"o" : 15,
"p" : 16,
"q" : 17,
"r" : 18,
"s" : 19,
"t" : 20,
"u" : 21,
"v" : 22,
"w" : 23,
"x" : 24,
"y" : 25,
"z" : 26
}
pos = dict_alpha.get(alphabet)
return f'Position of alphabet: {pos}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
x = "Position of alphabet: " + (str(ord(alphabet)-96))
return x
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(ch):
for i in range(26):
if ch.lower() == "abcdefghijklmnopqrstuvwxyz"[i]: return f"Position of alphabet: {i+1}"
return False
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
position=ord(alphabet.lower())-96
return f"Position of alphabet: {position}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
abcd = "abcdefghijklmnopqrstuvwxyz"
pos = abcd.index(alphabet)
return "Position of alphabet: {}".format(pos+1)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
import string
def position(alphabet):
ab = dict(zip(string.ascii_lowercase, range(1,27)))
return f"Position of alphabet: {ab.get(alphabet)}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(c):
return f"Position of alphabet: {ord(c.lower()) - 96}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
import string
x=list(string.ascii_lowercase)
return f'Position of alphabet: {x.index(alphabet)+1}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
alf = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
def position(alphabet):
nonlocal alf
return f'Position of alphabet: {alf.index(alphabet) + 1}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
import string
characters = {char: str(idx) for idx, char in enumerate(string.ascii_lowercase, 1)}
return f"Position of alphabet: {characters[alphabet]}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
num = (ord(alphabet))
num -= 96
return f"Position of alphabet: {num}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
letters ={
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6,
"g": 7,
"h": 8,
"i": 9,
"j": 10,
"k": 11,
"l": 12,
"m": 13,
"n": 14,
"o": 15,
"p": 16,
"q": 17,
"r": 18,
"s": 19,
"t": 20,
"u": 21,
"v": 22,
"w": 23,
"x": 24,
"y": 25,
"z": 26
}
def position(alphabet):
if alphabet in letters:
return f"Position of alphabet: {letters.get(alphabet)}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
from string import ascii_lowercase as al
def position(alphabet):
return f'Position of alphabet: {[pos for pos, x in enumerate(al, 1) if x == alphabet.lower()][0]}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
index_alphabet = "abcdefghijklmnopqrstuvwxyz"
return "Position of alphabet: " + str(index_alphabet.index(alphabet) + 1)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
alph = 'abcdefghijklmnopqrstuvwxyz'
return f'Position of alphabet: {alph.index(alphabet) + 1}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
alpha = '1abcdefghijklmnopqrstuvwxyz'
return "Position of alphabet: " + str(alpha.find(alphabet))
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
letters = [0,"a", "b", "c", "d", "e", "f", "g", "h",
"i", "j", "k", "l", "m", "n", "o", "p",
"q", "r", "s", "t", "u", "v", "w", "x",
"y", "z"]
return "Position of alphabet: {}".format(letters.index(alphabet.lower()))
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
position = lambda alphabet: f'Position of alphabet: {ord(alphabet) - 96}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(letter):
print (letter)
alph='abcdefghijklmnopqrstuvwxyz'
for i, elem in enumerate(alph):
if elem==letter:
return f"Position of alphabet: {i+1}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
r= (ord(alphabet)-96)
return "Position of alphabet: {}".format(r)
pass
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
return "Position of alphabet: {}".format(str(ord(alphabet)+1-ord('a')))
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
position=lambda s:f"Position of alphabet: {__import__('string').ascii_letters.index(s)+1}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
import string
def position(alphabet):
dict_alphabet = dict(zip(string.ascii_lowercase,range(1,27)))
return f'Position of alphabet: {dict_alphabet[alphabet]}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
alp =['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
n = 0
for i in range(0,26):
if alp[i] == alphabet:
a = int(alp.index(alp[i])) + 1
return "Position of alphabet: {}".format(a)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
a = ' abcdefghijklmnopqrstuvwxyz'
return 'Position of alphabet: ' + str(a.find(alphabet))
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(a):
return "Position of alphabet: {}".format(ord(a)-ord('a')+1)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(letter: str) -> str:
return f"Position of alphabet: {ord(letter) - 96}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
abc = 'abcdefghijklmnopqrstuvwxyz'
return f'Position of alphabet: {abc.index(alphabet)+1}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
import string
def position(alphabet):
return f"Position of alphabet: {string.ascii_lowercase.index(alphabet.lower()) + 1}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
position = lambda c: f'Position of alphabet: {ord(c) - 96}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
whole_alphabet = {
"a" : 1 ,
"b" : 2 ,
"c" : 3 ,
"d" : 4 ,
"e" : 5 ,
"f" : 6 ,
"g" : 7 ,
"h" : 8 ,
"i" : 9 ,
"j" : 10 ,
"k" : 11 ,
"l" : 12 ,
"m" : 13 ,
"n" : 14 ,
"o" : 15 ,
"p" : 16 ,
"q" : 17 ,
"r" : 18 ,
"s" : 19 ,
"t" : 20 ,
"u" : 21 ,
"v" : 22 ,
"w" : 23 ,
"x" : 24 ,
"y" : 25 ,
"z" : 26
}
position = whole_alphabet[alphabet]
return f"Position of alphabet: {whole_alphabet[alphabet]}"
print((position("h")))
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
pos = ord(alphabet) - ord('a') + 1
return f'Position of alphabet: {pos}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
return "Position of alphabet: %i" % (ord(alphabet.lower()) - 96)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
return "Position of alphabet: "+str(ord(alphabet)%ord('a')+1)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
import string
def position(alphabet):
return f'Position of alphabet: {string.ascii_letters.index(alphabet)+1}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
txt = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
x = txt.lower().find(alphabet) + 1
solution = 'Position of alphabet: {}'
return solution.format(x)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
position = ord(alphabet) - 96
return f'Position of alphabet: {position}'
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
abc=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
return "Position of alphabet: "+ str(abc.index(alphabet)+1)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
a=" abcdefghijklmnopqrstuvwxyz"
return f"Position of alphabet: {a.index(alphabet)}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
from string import ascii_lowercase as alphabet
def position(letter):
return 'Position of alphabet: {}'.format(alphabet.find(letter) + 1)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(a):
g = 'abcdefghijklmnopqrstuvwxyz'
return "Position of alphabet: " + str(g.find(a)+1)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
a = list("abcdefghijklmnopqrstuvwxyz")
return f"Position of alphabet: {a.index(alphabet)+1}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(letter):
return f"Position of alphabet: {ord(letter) - 96}"
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
import string
def position(alphabet):
al = list(enumerate(list(string.ascii_lowercase),1))
d = {}
for e in al:
x = {e[1]: e[0]}
d.update(x)
return 'Position of alphabet: ' + str(d[alphabet])
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
return "Position of alphabet: {0}".format('abcdefghijklmnopqrstuvwxyz'.index(alphabet) + 1)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(a):
pos = ord(a) - ord("a") + 1
return 'Position of alphabet: {}'.format(pos)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
value = ord(alphabet)-96
print(value)
return "Position of alphabet: " + str(value)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
letters = '0abcdefghijklmnopqrstuvwxyz'
return 'Position of alphabet: ' + str(letters.index(alphabet))
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(l): return "Position of alphabet: " + str(ord(l.lower())-96)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(alphabet):
dictionary = {chr(96+i) : i for i in range (1, 27)}
return "Position of alphabet: " + str(dictionary[alphabet])
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
position=lambda a:"Position of alphabet: "+ str("0abcdefghijklmnopqrstuvwxyz".index(a))
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(s):
return 'Position of alphabet: '+str(ord(s) - 96)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
import string
def position(a):
return "Position of alphabet: {}".format(list(string.ascii_lowercase).index(a)+1)
|
When provided with a letter, return its position in the alphabet.
Input :: "a"
Ouput :: "Position of alphabet: 1"
`This kata is meant for beginners. Rank and upvote to bring it out of beta`
|
def position(letter):
return f"Position of alphabet: {ord(letter)-ord('a')+1}"
|
Help Suzuki rake his garden!
The monastery has a magnificent Zen garden made of white gravel and rocks and it is raked diligently everyday by the monks. Suzuki having a keen eye is always on the lookout for anything creeping into the garden that must be removed during the daily raking such as insects or moss.
You will be given a string representing the garden such as:
```
garden = 'gravel gravel gravel gravel gravel gravel gravel gravel gravel rock slug ant gravel gravel snail rock gravel gravel gravel gravel gravel gravel gravel slug gravel ant gravel gravel gravel gravel rock slug gravel gravel gravel gravel gravel snail gravel gravel rock gravel snail slug gravel gravel spider gravel gravel gravel gravel gravel gravel gravel gravel moss gravel gravel gravel snail gravel gravel gravel ant gravel gravel moss gravel gravel gravel gravel snail gravel gravel gravel gravel slug gravel rock gravel gravel rock gravel gravel gravel gravel snail gravel gravel rock gravel gravel gravel gravel gravel spider gravel rock gravel gravel'
```
Rake out any items that are not a rock or gravel and replace them with gravel such that:
```
garden = 'slug spider rock gravel gravel gravel gravel gravel gravel gravel'
```
Returns a string with all items except a rock or gravel replaced with gravel:
```
garden = 'gravel gravel rock gravel gravel gravel gravel gravel gravel gravel'
```
Please also try the other Kata in this series..
* [Help Suzuki count his vegetables...](https://www.codewars.com/kata/56ff1667cc08cacf4b00171b)
* [Help Suzuki purchase his Tofu!](https://www.codewars.com/kata/57d4ecb8164a67b97c00003c)
* [Help Suzuki pack his coal basket!](https://www.codewars.com/kata/57f09d0bcedb892791000255)
* [Suzuki needs help lining up his students!](https://www.codewars.com/kata/5701800886306a876a001031)
* [How many stairs will Suzuki climb in 20 years?](https://www.codewars.com/kata/56fc55cd1f5a93d68a001d4e)
|
VALID = {'gravel', 'rock'}
def rake_garden(garden):
return ' '.join(a if a in VALID else 'gravel' for a in garden.split())
|
Help Suzuki rake his garden!
The monastery has a magnificent Zen garden made of white gravel and rocks and it is raked diligently everyday by the monks. Suzuki having a keen eye is always on the lookout for anything creeping into the garden that must be removed during the daily raking such as insects or moss.
You will be given a string representing the garden such as:
```
garden = 'gravel gravel gravel gravel gravel gravel gravel gravel gravel rock slug ant gravel gravel snail rock gravel gravel gravel gravel gravel gravel gravel slug gravel ant gravel gravel gravel gravel rock slug gravel gravel gravel gravel gravel snail gravel gravel rock gravel snail slug gravel gravel spider gravel gravel gravel gravel gravel gravel gravel gravel moss gravel gravel gravel snail gravel gravel gravel ant gravel gravel moss gravel gravel gravel gravel snail gravel gravel gravel gravel slug gravel rock gravel gravel rock gravel gravel gravel gravel snail gravel gravel rock gravel gravel gravel gravel gravel spider gravel rock gravel gravel'
```
Rake out any items that are not a rock or gravel and replace them with gravel such that:
```
garden = 'slug spider rock gravel gravel gravel gravel gravel gravel gravel'
```
Returns a string with all items except a rock or gravel replaced with gravel:
```
garden = 'gravel gravel rock gravel gravel gravel gravel gravel gravel gravel'
```
Please also try the other Kata in this series..
* [Help Suzuki count his vegetables...](https://www.codewars.com/kata/56ff1667cc08cacf4b00171b)
* [Help Suzuki purchase his Tofu!](https://www.codewars.com/kata/57d4ecb8164a67b97c00003c)
* [Help Suzuki pack his coal basket!](https://www.codewars.com/kata/57f09d0bcedb892791000255)
* [Suzuki needs help lining up his students!](https://www.codewars.com/kata/5701800886306a876a001031)
* [How many stairs will Suzuki climb in 20 years?](https://www.codewars.com/kata/56fc55cd1f5a93d68a001d4e)
|
def rake_garden(garden):
return " ".join(w if w == "rock" else "gravel" for w in garden.split())
|
Help Suzuki rake his garden!
The monastery has a magnificent Zen garden made of white gravel and rocks and it is raked diligently everyday by the monks. Suzuki having a keen eye is always on the lookout for anything creeping into the garden that must be removed during the daily raking such as insects or moss.
You will be given a string representing the garden such as:
```
garden = 'gravel gravel gravel gravel gravel gravel gravel gravel gravel rock slug ant gravel gravel snail rock gravel gravel gravel gravel gravel gravel gravel slug gravel ant gravel gravel gravel gravel rock slug gravel gravel gravel gravel gravel snail gravel gravel rock gravel snail slug gravel gravel spider gravel gravel gravel gravel gravel gravel gravel gravel moss gravel gravel gravel snail gravel gravel gravel ant gravel gravel moss gravel gravel gravel gravel snail gravel gravel gravel gravel slug gravel rock gravel gravel rock gravel gravel gravel gravel snail gravel gravel rock gravel gravel gravel gravel gravel spider gravel rock gravel gravel'
```
Rake out any items that are not a rock or gravel and replace them with gravel such that:
```
garden = 'slug spider rock gravel gravel gravel gravel gravel gravel gravel'
```
Returns a string with all items except a rock or gravel replaced with gravel:
```
garden = 'gravel gravel rock gravel gravel gravel gravel gravel gravel gravel'
```
Please also try the other Kata in this series..
* [Help Suzuki count his vegetables...](https://www.codewars.com/kata/56ff1667cc08cacf4b00171b)
* [Help Suzuki purchase his Tofu!](https://www.codewars.com/kata/57d4ecb8164a67b97c00003c)
* [Help Suzuki pack his coal basket!](https://www.codewars.com/kata/57f09d0bcedb892791000255)
* [Suzuki needs help lining up his students!](https://www.codewars.com/kata/5701800886306a876a001031)
* [How many stairs will Suzuki climb in 20 years?](https://www.codewars.com/kata/56fc55cd1f5a93d68a001d4e)
|
import re
def rake_garden(garden):
return re.sub(r'(?<!\S)(?!gravel|rock)\S+', 'gravel', garden)
|
Help Suzuki rake his garden!
The monastery has a magnificent Zen garden made of white gravel and rocks and it is raked diligently everyday by the monks. Suzuki having a keen eye is always on the lookout for anything creeping into the garden that must be removed during the daily raking such as insects or moss.
You will be given a string representing the garden such as:
```
garden = 'gravel gravel gravel gravel gravel gravel gravel gravel gravel rock slug ant gravel gravel snail rock gravel gravel gravel gravel gravel gravel gravel slug gravel ant gravel gravel gravel gravel rock slug gravel gravel gravel gravel gravel snail gravel gravel rock gravel snail slug gravel gravel spider gravel gravel gravel gravel gravel gravel gravel gravel moss gravel gravel gravel snail gravel gravel gravel ant gravel gravel moss gravel gravel gravel gravel snail gravel gravel gravel gravel slug gravel rock gravel gravel rock gravel gravel gravel gravel snail gravel gravel rock gravel gravel gravel gravel gravel spider gravel rock gravel gravel'
```
Rake out any items that are not a rock or gravel and replace them with gravel such that:
```
garden = 'slug spider rock gravel gravel gravel gravel gravel gravel gravel'
```
Returns a string with all items except a rock or gravel replaced with gravel:
```
garden = 'gravel gravel rock gravel gravel gravel gravel gravel gravel gravel'
```
Please also try the other Kata in this series..
* [Help Suzuki count his vegetables...](https://www.codewars.com/kata/56ff1667cc08cacf4b00171b)
* [Help Suzuki purchase his Tofu!](https://www.codewars.com/kata/57d4ecb8164a67b97c00003c)
* [Help Suzuki pack his coal basket!](https://www.codewars.com/kata/57f09d0bcedb892791000255)
* [Suzuki needs help lining up his students!](https://www.codewars.com/kata/5701800886306a876a001031)
* [How many stairs will Suzuki climb in 20 years?](https://www.codewars.com/kata/56fc55cd1f5a93d68a001d4e)
|
def rake_garden(garden):
return " ".join(i if i in "gravelrock" else "gravel" for i in garden.split())
|
Help Suzuki rake his garden!
The monastery has a magnificent Zen garden made of white gravel and rocks and it is raked diligently everyday by the monks. Suzuki having a keen eye is always on the lookout for anything creeping into the garden that must be removed during the daily raking such as insects or moss.
You will be given a string representing the garden such as:
```
garden = 'gravel gravel gravel gravel gravel gravel gravel gravel gravel rock slug ant gravel gravel snail rock gravel gravel gravel gravel gravel gravel gravel slug gravel ant gravel gravel gravel gravel rock slug gravel gravel gravel gravel gravel snail gravel gravel rock gravel snail slug gravel gravel spider gravel gravel gravel gravel gravel gravel gravel gravel moss gravel gravel gravel snail gravel gravel gravel ant gravel gravel moss gravel gravel gravel gravel snail gravel gravel gravel gravel slug gravel rock gravel gravel rock gravel gravel gravel gravel snail gravel gravel rock gravel gravel gravel gravel gravel spider gravel rock gravel gravel'
```
Rake out any items that are not a rock or gravel and replace them with gravel such that:
```
garden = 'slug spider rock gravel gravel gravel gravel gravel gravel gravel'
```
Returns a string with all items except a rock or gravel replaced with gravel:
```
garden = 'gravel gravel rock gravel gravel gravel gravel gravel gravel gravel'
```
Please also try the other Kata in this series..
* [Help Suzuki count his vegetables...](https://www.codewars.com/kata/56ff1667cc08cacf4b00171b)
* [Help Suzuki purchase his Tofu!](https://www.codewars.com/kata/57d4ecb8164a67b97c00003c)
* [Help Suzuki pack his coal basket!](https://www.codewars.com/kata/57f09d0bcedb892791000255)
* [Suzuki needs help lining up his students!](https://www.codewars.com/kata/5701800886306a876a001031)
* [How many stairs will Suzuki climb in 20 years?](https://www.codewars.com/kata/56fc55cd1f5a93d68a001d4e)
|
KEEP = ["gravel", "rock"]
REPLACE_WITH = "gravel"
def rake_garden(garden):
return " ".join([item if item in KEEP else REPLACE_WITH for item in garden.split()])
|
Help Suzuki rake his garden!
The monastery has a magnificent Zen garden made of white gravel and rocks and it is raked diligently everyday by the monks. Suzuki having a keen eye is always on the lookout for anything creeping into the garden that must be removed during the daily raking such as insects or moss.
You will be given a string representing the garden such as:
```
garden = 'gravel gravel gravel gravel gravel gravel gravel gravel gravel rock slug ant gravel gravel snail rock gravel gravel gravel gravel gravel gravel gravel slug gravel ant gravel gravel gravel gravel rock slug gravel gravel gravel gravel gravel snail gravel gravel rock gravel snail slug gravel gravel spider gravel gravel gravel gravel gravel gravel gravel gravel moss gravel gravel gravel snail gravel gravel gravel ant gravel gravel moss gravel gravel gravel gravel snail gravel gravel gravel gravel slug gravel rock gravel gravel rock gravel gravel gravel gravel snail gravel gravel rock gravel gravel gravel gravel gravel spider gravel rock gravel gravel'
```
Rake out any items that are not a rock or gravel and replace them with gravel such that:
```
garden = 'slug spider rock gravel gravel gravel gravel gravel gravel gravel'
```
Returns a string with all items except a rock or gravel replaced with gravel:
```
garden = 'gravel gravel rock gravel gravel gravel gravel gravel gravel gravel'
```
Please also try the other Kata in this series..
* [Help Suzuki count his vegetables...](https://www.codewars.com/kata/56ff1667cc08cacf4b00171b)
* [Help Suzuki purchase his Tofu!](https://www.codewars.com/kata/57d4ecb8164a67b97c00003c)
* [Help Suzuki pack his coal basket!](https://www.codewars.com/kata/57f09d0bcedb892791000255)
* [Suzuki needs help lining up his students!](https://www.codewars.com/kata/5701800886306a876a001031)
* [How many stairs will Suzuki climb in 20 years?](https://www.codewars.com/kata/56fc55cd1f5a93d68a001d4e)
|
rake_garden = lambda g: ' '.join('gravel' if e not in ['gravel','rock'] else e for e in g.split())
|
Help Suzuki rake his garden!
The monastery has a magnificent Zen garden made of white gravel and rocks and it is raked diligently everyday by the monks. Suzuki having a keen eye is always on the lookout for anything creeping into the garden that must be removed during the daily raking such as insects or moss.
You will be given a string representing the garden such as:
```
garden = 'gravel gravel gravel gravel gravel gravel gravel gravel gravel rock slug ant gravel gravel snail rock gravel gravel gravel gravel gravel gravel gravel slug gravel ant gravel gravel gravel gravel rock slug gravel gravel gravel gravel gravel snail gravel gravel rock gravel snail slug gravel gravel spider gravel gravel gravel gravel gravel gravel gravel gravel moss gravel gravel gravel snail gravel gravel gravel ant gravel gravel moss gravel gravel gravel gravel snail gravel gravel gravel gravel slug gravel rock gravel gravel rock gravel gravel gravel gravel snail gravel gravel rock gravel gravel gravel gravel gravel spider gravel rock gravel gravel'
```
Rake out any items that are not a rock or gravel and replace them with gravel such that:
```
garden = 'slug spider rock gravel gravel gravel gravel gravel gravel gravel'
```
Returns a string with all items except a rock or gravel replaced with gravel:
```
garden = 'gravel gravel rock gravel gravel gravel gravel gravel gravel gravel'
```
Please also try the other Kata in this series..
* [Help Suzuki count his vegetables...](https://www.codewars.com/kata/56ff1667cc08cacf4b00171b)
* [Help Suzuki purchase his Tofu!](https://www.codewars.com/kata/57d4ecb8164a67b97c00003c)
* [Help Suzuki pack his coal basket!](https://www.codewars.com/kata/57f09d0bcedb892791000255)
* [Suzuki needs help lining up his students!](https://www.codewars.com/kata/5701800886306a876a001031)
* [How many stairs will Suzuki climb in 20 years?](https://www.codewars.com/kata/56fc55cd1f5a93d68a001d4e)
|
import re
def rake_garden(g):
return re.sub(r'\b(?!gravel|rock\b)\w+','gravel',g)
|
Help Suzuki rake his garden!
The monastery has a magnificent Zen garden made of white gravel and rocks and it is raked diligently everyday by the monks. Suzuki having a keen eye is always on the lookout for anything creeping into the garden that must be removed during the daily raking such as insects or moss.
You will be given a string representing the garden such as:
```
garden = 'gravel gravel gravel gravel gravel gravel gravel gravel gravel rock slug ant gravel gravel snail rock gravel gravel gravel gravel gravel gravel gravel slug gravel ant gravel gravel gravel gravel rock slug gravel gravel gravel gravel gravel snail gravel gravel rock gravel snail slug gravel gravel spider gravel gravel gravel gravel gravel gravel gravel gravel moss gravel gravel gravel snail gravel gravel gravel ant gravel gravel moss gravel gravel gravel gravel snail gravel gravel gravel gravel slug gravel rock gravel gravel rock gravel gravel gravel gravel snail gravel gravel rock gravel gravel gravel gravel gravel spider gravel rock gravel gravel'
```
Rake out any items that are not a rock or gravel and replace them with gravel such that:
```
garden = 'slug spider rock gravel gravel gravel gravel gravel gravel gravel'
```
Returns a string with all items except a rock or gravel replaced with gravel:
```
garden = 'gravel gravel rock gravel gravel gravel gravel gravel gravel gravel'
```
Please also try the other Kata in this series..
* [Help Suzuki count his vegetables...](https://www.codewars.com/kata/56ff1667cc08cacf4b00171b)
* [Help Suzuki purchase his Tofu!](https://www.codewars.com/kata/57d4ecb8164a67b97c00003c)
* [Help Suzuki pack his coal basket!](https://www.codewars.com/kata/57f09d0bcedb892791000255)
* [Suzuki needs help lining up his students!](https://www.codewars.com/kata/5701800886306a876a001031)
* [How many stairs will Suzuki climb in 20 years?](https://www.codewars.com/kata/56fc55cd1f5a93d68a001d4e)
|
def rake_garden(garden):
garden = garden.split(" ")
for i in range(len(garden)):
if garden[i] != "gravel" and garden[i]!= "rock":
garden[i] = "gravel"
return " ".join(garden)
|
Help Suzuki rake his garden!
The monastery has a magnificent Zen garden made of white gravel and rocks and it is raked diligently everyday by the monks. Suzuki having a keen eye is always on the lookout for anything creeping into the garden that must be removed during the daily raking such as insects or moss.
You will be given a string representing the garden such as:
```
garden = 'gravel gravel gravel gravel gravel gravel gravel gravel gravel rock slug ant gravel gravel snail rock gravel gravel gravel gravel gravel gravel gravel slug gravel ant gravel gravel gravel gravel rock slug gravel gravel gravel gravel gravel snail gravel gravel rock gravel snail slug gravel gravel spider gravel gravel gravel gravel gravel gravel gravel gravel moss gravel gravel gravel snail gravel gravel gravel ant gravel gravel moss gravel gravel gravel gravel snail gravel gravel gravel gravel slug gravel rock gravel gravel rock gravel gravel gravel gravel snail gravel gravel rock gravel gravel gravel gravel gravel spider gravel rock gravel gravel'
```
Rake out any items that are not a rock or gravel and replace them with gravel such that:
```
garden = 'slug spider rock gravel gravel gravel gravel gravel gravel gravel'
```
Returns a string with all items except a rock or gravel replaced with gravel:
```
garden = 'gravel gravel rock gravel gravel gravel gravel gravel gravel gravel'
```
Please also try the other Kata in this series..
* [Help Suzuki count his vegetables...](https://www.codewars.com/kata/56ff1667cc08cacf4b00171b)
* [Help Suzuki purchase his Tofu!](https://www.codewars.com/kata/57d4ecb8164a67b97c00003c)
* [Help Suzuki pack his coal basket!](https://www.codewars.com/kata/57f09d0bcedb892791000255)
* [Suzuki needs help lining up his students!](https://www.codewars.com/kata/5701800886306a876a001031)
* [How many stairs will Suzuki climb in 20 years?](https://www.codewars.com/kata/56fc55cd1f5a93d68a001d4e)
|
def rake_garden(garden):
return ' '.join(element if element == 'gravel' or element == 'rock' else 'gravel' for element in garden.split())
|
Help Suzuki rake his garden!
The monastery has a magnificent Zen garden made of white gravel and rocks and it is raked diligently everyday by the monks. Suzuki having a keen eye is always on the lookout for anything creeping into the garden that must be removed during the daily raking such as insects or moss.
You will be given a string representing the garden such as:
```
garden = 'gravel gravel gravel gravel gravel gravel gravel gravel gravel rock slug ant gravel gravel snail rock gravel gravel gravel gravel gravel gravel gravel slug gravel ant gravel gravel gravel gravel rock slug gravel gravel gravel gravel gravel snail gravel gravel rock gravel snail slug gravel gravel spider gravel gravel gravel gravel gravel gravel gravel gravel moss gravel gravel gravel snail gravel gravel gravel ant gravel gravel moss gravel gravel gravel gravel snail gravel gravel gravel gravel slug gravel rock gravel gravel rock gravel gravel gravel gravel snail gravel gravel rock gravel gravel gravel gravel gravel spider gravel rock gravel gravel'
```
Rake out any items that are not a rock or gravel and replace them with gravel such that:
```
garden = 'slug spider rock gravel gravel gravel gravel gravel gravel gravel'
```
Returns a string with all items except a rock or gravel replaced with gravel:
```
garden = 'gravel gravel rock gravel gravel gravel gravel gravel gravel gravel'
```
Please also try the other Kata in this series..
* [Help Suzuki count his vegetables...](https://www.codewars.com/kata/56ff1667cc08cacf4b00171b)
* [Help Suzuki purchase his Tofu!](https://www.codewars.com/kata/57d4ecb8164a67b97c00003c)
* [Help Suzuki pack his coal basket!](https://www.codewars.com/kata/57f09d0bcedb892791000255)
* [Suzuki needs help lining up his students!](https://www.codewars.com/kata/5701800886306a876a001031)
* [How many stairs will Suzuki climb in 20 years?](https://www.codewars.com/kata/56fc55cd1f5a93d68a001d4e)
|
rake_garden = lambda g: " ".join(['gravel', 'rock'][e == 'rock']for e in g.split())
|
Write a function generator that will generate the first `n` primes grouped in tuples of size `m`. If there are not enough primes for the last tuple it will have the remaining values as `None`.
## Examples
```python
For n = 11 and m = 2:
(2, 3), (5, 7), (11, 13), (17, 19), (23, 29), (31, None)
For n = 11 and m = 3:
(2, 3, 5), (7, 11, 13), (17, 19, 23), (29, 31, None)
For n = 11 and m = 5:
(2, 3, 5, 7, 11), (13, 17, 19, 23, 29), (31, None, None, None, None)]
For n = 3 and m = 1:
(2,), (3,), (5,)
```
Note: large numbers of `n` will be tested, up to 50000
|
# generate primes up to limit
LIMIT = 10**6
sieve = [0]*2 + list(range(2, LIMIT))
for n in sieve:
if n:
for i in range(n*n, LIMIT, n):
sieve[i] = 0
PRIMES = list(n for n in sieve if n)
def get_primes(n, m=2):
primes_ = PRIMES[:n] + [None] * m
return ( tuple(primes_[i:i+m]) for i in range(0, n, m) )
|
Write a function generator that will generate the first `n` primes grouped in tuples of size `m`. If there are not enough primes for the last tuple it will have the remaining values as `None`.
## Examples
```python
For n = 11 and m = 2:
(2, 3), (5, 7), (11, 13), (17, 19), (23, 29), (31, None)
For n = 11 and m = 3:
(2, 3, 5), (7, 11, 13), (17, 19, 23), (29, 31, None)
For n = 11 and m = 5:
(2, 3, 5, 7, 11), (13, 17, 19, 23, 29), (31, None, None, None, None)]
For n = 3 and m = 1:
(2,), (3,), (5,)
```
Note: large numbers of `n` will be tested, up to 50000
|
# Known primes
primes = [2, 3, 5, 7, 11]
# Generate prime numbers in sequence
def gen_primes():
yield from primes
candidate = primes[-1]
candidate_root = int(candidate ** 0.5) + 1
while True:
candidate += 2
if candidate_root * candidate_root < candidate:
candidate_root += 1
for p in primes:
if candidate % p == 0:
break
if p > candidate_root:
primes.append(candidate)
yield candidate
break
def get_primes(how_many, group_size=2):
result = []
for i, p in enumerate(gen_primes(), start=1):
result.append(p)
if len(result) == group_size:
yield tuple(result)
result = []
if i == how_many:
break
if len(result) > 0:
while len(result) < group_size:
result.append(None)
yield tuple(result)
|
Write a function generator that will generate the first `n` primes grouped in tuples of size `m`. If there are not enough primes for the last tuple it will have the remaining values as `None`.
## Examples
```python
For n = 11 and m = 2:
(2, 3), (5, 7), (11, 13), (17, 19), (23, 29), (31, None)
For n = 11 and m = 3:
(2, 3, 5), (7, 11, 13), (17, 19, 23), (29, 31, None)
For n = 11 and m = 5:
(2, 3, 5, 7, 11), (13, 17, 19, 23, 29), (31, None, None, None, None)]
For n = 3 and m = 1:
(2,), (3,), (5,)
```
Note: large numbers of `n` will be tested, up to 50000
|
from itertools import zip_longest
import math
def get_primes(how_many, group_size=2):
if how_many>0:
pr = primes(how_many)
yield from [ tuple(e) for e in zip_longest(*[iter(pr)]*group_size ) ]
def is_prime(n):
return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2))
def primes(n):
i, pr = 3, [2]
while n>1:
if is_prime(i):
n -= 1
pr.append(i)
i += 2
return pr
|
Write a function generator that will generate the first `n` primes grouped in tuples of size `m`. If there are not enough primes for the last tuple it will have the remaining values as `None`.
## Examples
```python
For n = 11 and m = 2:
(2, 3), (5, 7), (11, 13), (17, 19), (23, 29), (31, None)
For n = 11 and m = 3:
(2, 3, 5), (7, 11, 13), (17, 19, 23), (29, 31, None)
For n = 11 and m = 5:
(2, 3, 5, 7, 11), (13, 17, 19, 23, 29), (31, None, None, None, None)]
For n = 3 and m = 1:
(2,), (3,), (5,)
```
Note: large numbers of `n` will be tested, up to 50000
|
from itertools import compress, islice, zip_longest
import numpy as np
s = np.ones(1000000)
s[:2] = s[4::2] = 0
for i in range(3, int(len(s)**0.5)+1, 2):
if s[i]:
s[i*i::i] = 0
primes = list(compress(range(len(s)), s))
def get_primes(how_many, group_size=2):
yield from zip_longest(*[islice(primes, how_many)] * group_size)
|
Write a function generator that will generate the first `n` primes grouped in tuples of size `m`. If there are not enough primes for the last tuple it will have the remaining values as `None`.
## Examples
```python
For n = 11 and m = 2:
(2, 3), (5, 7), (11, 13), (17, 19), (23, 29), (31, None)
For n = 11 and m = 3:
(2, 3, 5), (7, 11, 13), (17, 19, 23), (29, 31, None)
For n = 11 and m = 5:
(2, 3, 5, 7, 11), (13, 17, 19, 23, 29), (31, None, None, None, None)]
For n = 3 and m = 1:
(2,), (3,), (5,)
```
Note: large numbers of `n` will be tested, up to 50000
|
def get_primes(how_many, group_size):
primes = [False] * 2 + list(range(2, 13*how_many))
for x in primes:
if x:
for i in range(x*x, 13*how_many, x):
primes[i] = False
seq = sorted(set(primes))[1:how_many+1]
while len(seq) % group_size != 0:
seq += [None]
return (tuple(seq[x:x+group_size]) for x in range(0, len(seq), group_size))
|
Write a function generator that will generate the first `n` primes grouped in tuples of size `m`. If there are not enough primes for the last tuple it will have the remaining values as `None`.
## Examples
```python
For n = 11 and m = 2:
(2, 3), (5, 7), (11, 13), (17, 19), (23, 29), (31, None)
For n = 11 and m = 3:
(2, 3, 5), (7, 11, 13), (17, 19, 23), (29, 31, None)
For n = 11 and m = 5:
(2, 3, 5, 7, 11), (13, 17, 19, 23, 29), (31, None, None, None, None)]
For n = 3 and m = 1:
(2,), (3,), (5,)
```
Note: large numbers of `n` will be tested, up to 50000
|
def makePrimes(n):
sieve, primes = [0]*(n+1), []
for i in range(2, n+1):
if not sieve[i]:
primes.append(i)
for j in range(i**2, n+1, i): sieve[j] = 1
return primes
PRIMES = makePrimes(650000) # => 52831 prime numbers
def get_primes(how_many, group_size=2):
lst = PRIMES[:how_many] + [None] * (group_size - how_many%group_size)
for n in range(how_many//group_size + bool(how_many%group_size)):
yield tuple(lst[n*group_size : (n+1)*group_size])
|
Write a function generator that will generate the first `n` primes grouped in tuples of size `m`. If there are not enough primes for the last tuple it will have the remaining values as `None`.
## Examples
```python
For n = 11 and m = 2:
(2, 3), (5, 7), (11, 13), (17, 19), (23, 29), (31, None)
For n = 11 and m = 3:
(2, 3, 5), (7, 11, 13), (17, 19, 23), (29, 31, None)
For n = 11 and m = 5:
(2, 3, 5, 7, 11), (13, 17, 19, 23, 29), (31, None, None, None, None)]
For n = 3 and m = 1:
(2,), (3,), (5,)
```
Note: large numbers of `n` will be tested, up to 50000
|
import gmpy2
def get_primes(how_many, group_size):
n = 2
count = 0
while count < how_many:
res = []
for i in range(group_size):
res.append(int(n) if count < how_many else None)
n = gmpy2.next_prime(n)
count += 1
yield tuple(res)
|
Write a function generator that will generate the first `n` primes grouped in tuples of size `m`. If there are not enough primes for the last tuple it will have the remaining values as `None`.
## Examples
```python
For n = 11 and m = 2:
(2, 3), (5, 7), (11, 13), (17, 19), (23, 29), (31, None)
For n = 11 and m = 3:
(2, 3, 5), (7, 11, 13), (17, 19, 23), (29, 31, None)
For n = 11 and m = 5:
(2, 3, 5, 7, 11), (13, 17, 19, 23, 29), (31, None, None, None, None)]
For n = 3 and m = 1:
(2,), (3,), (5,)
```
Note: large numbers of `n` will be tested, up to 50000
|
from itertools import islice, chain, repeat
def gen_primes():
D = {}; q = 2
while True:
if q not in D: yield q; D[q * q] = [q]
else:
for p in D[q]: D.setdefault(p + q, []).append(p)
del D[q]
q += 1
def get_primes(how_many, group_size=2):
return (t for t in zip(*[chain(islice(gen_primes(), how_many), repeat(None, group_size-1))]*group_size))
|
Write a function generator that will generate the first `n` primes grouped in tuples of size `m`. If there are not enough primes for the last tuple it will have the remaining values as `None`.
## Examples
```python
For n = 11 and m = 2:
(2, 3), (5, 7), (11, 13), (17, 19), (23, 29), (31, None)
For n = 11 and m = 3:
(2, 3, 5), (7, 11, 13), (17, 19, 23), (29, 31, None)
For n = 11 and m = 5:
(2, 3, 5, 7, 11), (13, 17, 19, 23, 29), (31, None, None, None, None)]
For n = 3 and m = 1:
(2,), (3,), (5,)
```
Note: large numbers of `n` will be tested, up to 50000
|
get_primes=lambda n,m:(tuple(g)for g in zip(*[iter([2]+[p for p in range(3,15*n,2)if all(p%d for d in range(3,int(p**.5)+1,2))][:n-1]+[None]*(m-1))]*m))
|
Write a function generator that will generate the first `n` primes grouped in tuples of size `m`. If there are not enough primes for the last tuple it will have the remaining values as `None`.
## Examples
```python
For n = 11 and m = 2:
(2, 3), (5, 7), (11, 13), (17, 19), (23, 29), (31, None)
For n = 11 and m = 3:
(2, 3, 5), (7, 11, 13), (17, 19, 23), (29, 31, None)
For n = 11 and m = 5:
(2, 3, 5, 7, 11), (13, 17, 19, 23, 29), (31, None, None, None, None)]
For n = 3 and m = 1:
(2,), (3,), (5,)
```
Note: large numbers of `n` will be tested, up to 50000
|
import itertools
def prime(a):
return not (a < 2 or any(a % x == 0 for x in range(2, int(a**0.5) + 1)))
def get_primes(how_many, group_size=2):
primes = filter(prime, itertools.count(2))
yield from itertools.zip_longest(*[itertools.islice(primes, how_many)] * group_size)
|
Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return `true` if the string is valid, and `false` if it's invalid.
This Kata is similar to the [Valid Parentheses](https://www.codewars.com/kata/valid-parentheses) Kata, but introduces new characters: brackets `[]`, and curly braces `{}`. Thanks to `@arnedag` for the idea!
All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: `()[]{}`.
### What is considered Valid?
A string of braces is considered valid if all braces are matched with the correct brace.
## Examples
```
"(){}[]" => True
"([{}])" => True
"(}" => False
"[(])" => False
"[({})](]" => False
```
|
def validBraces(string):
braces = {"(": ")", "[": "]", "{": "}"}
stack = []
for character in string:
if character in braces.keys():
stack.append(character)
else:
if len(stack) == 0 or braces[stack.pop()] != character:
return False
return len(stack) == 0
|
Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return `true` if the string is valid, and `false` if it's invalid.
This Kata is similar to the [Valid Parentheses](https://www.codewars.com/kata/valid-parentheses) Kata, but introduces new characters: brackets `[]`, and curly braces `{}`. Thanks to `@arnedag` for the idea!
All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: `()[]{}`.
### What is considered Valid?
A string of braces is considered valid if all braces are matched with the correct brace.
## Examples
```
"(){}[]" => True
"([{}])" => True
"(}" => False
"[(])" => False
"[({})](]" => False
```
|
def validBraces(s):
while '{}' in s or '()' in s or '[]' in s:
s=s.replace('{}','')
s=s.replace('[]','')
s=s.replace('()','')
return s==''
|
Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return `true` if the string is valid, and `false` if it's invalid.
This Kata is similar to the [Valid Parentheses](https://www.codewars.com/kata/valid-parentheses) Kata, but introduces new characters: brackets `[]`, and curly braces `{}`. Thanks to `@arnedag` for the idea!
All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: `()[]{}`.
### What is considered Valid?
A string of braces is considered valid if all braces are matched with the correct brace.
## Examples
```
"(){}[]" => True
"([{}])" => True
"(}" => False
"[(])" => False
"[({})](]" => False
```
|
def validBraces(s, previous = ''):
while s != previous: previous, s = s, s.replace('[]','').replace('{}','').replace('()','')
return not s
|
Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return `true` if the string is valid, and `false` if it's invalid.
This Kata is similar to the [Valid Parentheses](https://www.codewars.com/kata/valid-parentheses) Kata, but introduces new characters: brackets `[]`, and curly braces `{}`. Thanks to `@arnedag` for the idea!
All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: `()[]{}`.
### What is considered Valid?
A string of braces is considered valid if all braces are matched with the correct brace.
## Examples
```
"(){}[]" => True
"([{}])" => True
"(}" => False
"[(])" => False
"[({})](]" => False
```
|
BRACES = {"(":")", "{":"}","[":"]"}
def validBraces(string):
waiting = []
for l in string:
if l in BRACES.keys():
waiting.append(BRACES[l])
elif not waiting or waiting.pop() != l:
return False
return not waiting
|
Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return `true` if the string is valid, and `false` if it's invalid.
This Kata is similar to the [Valid Parentheses](https://www.codewars.com/kata/valid-parentheses) Kata, but introduces new characters: brackets `[]`, and curly braces `{}`. Thanks to `@arnedag` for the idea!
All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: `()[]{}`.
### What is considered Valid?
A string of braces is considered valid if all braces are matched with the correct brace.
## Examples
```
"(){}[]" => True
"([{}])" => True
"(}" => False
"[(])" => False
"[({})](]" => False
```
|
def validBraces(string):
while '()' in string or '{}' in string or '[]' in string:
string = string.replace('()', '')
string = string.replace('{}', '')
string = string.replace('[]', '')
return False if len(string) != 0 else True
|
Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return `true` if the string is valid, and `false` if it's invalid.
This Kata is similar to the [Valid Parentheses](https://www.codewars.com/kata/valid-parentheses) Kata, but introduces new characters: brackets `[]`, and curly braces `{}`. Thanks to `@arnedag` for the idea!
All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: `()[]{}`.
### What is considered Valid?
A string of braces is considered valid if all braces are matched with the correct brace.
## Examples
```
"(){}[]" => True
"([{}])" => True
"(}" => False
"[(])" => False
"[({})](]" => False
```
|
def validBraces(string):
while len(string) > 0:
if "()" in string:
string = string.replace("()", "")
elif "[]" in string:
string = string.replace("[]", "")
elif "{}" in string:
string = string.replace("{}", "")
else:
return False
return True
|
Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return `true` if the string is valid, and `false` if it's invalid.
This Kata is similar to the [Valid Parentheses](https://www.codewars.com/kata/valid-parentheses) Kata, but introduces new characters: brackets `[]`, and curly braces `{}`. Thanks to `@arnedag` for the idea!
All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: `()[]{}`.
### What is considered Valid?
A string of braces is considered valid if all braces are matched with the correct brace.
## Examples
```
"(){}[]" => True
"([{}])" => True
"(}" => False
"[(])" => False
"[({})](]" => False
```
|
def validBraces(string):
stack = []
delim = {'(':')', '[':']', '{':'}'}
for c in string:
if c in list(delim.keys()): stack.append(c)
elif c in list(delim.values()):
if not stack or delim[stack.pop()] != c: return False
return not stack
|
Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return `true` if the string is valid, and `false` if it's invalid.
This Kata is similar to the [Valid Parentheses](https://www.codewars.com/kata/valid-parentheses) Kata, but introduces new characters: brackets `[]`, and curly braces `{}`. Thanks to `@arnedag` for the idea!
All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: `()[]{}`.
### What is considered Valid?
A string of braces is considered valid if all braces are matched with the correct brace.
## Examples
```
"(){}[]" => True
"([{}])" => True
"(}" => False
"[(])" => False
"[({})](]" => False
```
|
def validBraces(s):
pairs = ['{}', '()', '[]']
while any(pair in s for pair in pairs):
for pair in pairs:
s = s.replace(pair, "")
return s == ""
|
Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return `true` if the string is valid, and `false` if it's invalid.
This Kata is similar to the [Valid Parentheses](https://www.codewars.com/kata/valid-parentheses) Kata, but introduces new characters: brackets `[]`, and curly braces `{}`. Thanks to `@arnedag` for the idea!
All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: `()[]{}`.
### What is considered Valid?
A string of braces is considered valid if all braces are matched with the correct brace.
## Examples
```
"(){}[]" => True
"([{}])" => True
"(}" => False
"[(])" => False
"[({})](]" => False
```
|
def validBraces(string):
while '()' in string or '[]' in string or '{}' in string:
string = string.replace('{}','')
string = string.replace('()','')
string = string.replace('[]', '')
return not string
|
Write a function that takes a string of braces, and determines if the order of the braces is valid. It should return `true` if the string is valid, and `false` if it's invalid.
This Kata is similar to the [Valid Parentheses](https://www.codewars.com/kata/valid-parentheses) Kata, but introduces new characters: brackets `[]`, and curly braces `{}`. Thanks to `@arnedag` for the idea!
All input strings will be nonempty, and will only consist of parentheses, brackets and curly braces: `()[]{}`.
### What is considered Valid?
A string of braces is considered valid if all braces are matched with the correct brace.
## Examples
```
"(){}[]" => True
"([{}])" => True
"(}" => False
"[(])" => False
"[({})](]" => False
```
|
import re
class Stack(object):
def __init__(self): self._vals = []
def push(self, i): self._vals.append(i)
def peek(self): return self._vals[-1] if not self.is_empty() else None
def pop(self): self._vals.pop()
def is_empty(self): return len(self._vals) == 0
def validBraces(string):
openers, closers = list(map(list, ('({[', ')}]')))
pairs = list(zip(openers, closers))
s = Stack()
for char in list(string):
if char in openers:
s.push(char)
elif (char in closers and (s.peek(), char) in pairs):
s.pop()
return s.is_empty()
|
You have been tasked with converting a number from base i (sqrt of -1) to base 10.
Recall how bases are defined:
abcdef = a * 10^5 + b * 10^4 + c * 10^3 + d * 10^2 + e * 10^1 + f * 10^0
Base i follows then like this:
... i^4 + i^3 + i^2 + i^1 + i^0
The only numbers in any place will be 1 or 0
Examples:
101 in base i would be:
1 * i^2 + 0 * i^1 + 1*i^0 = -1 + 0 + 1 = 0
10010 in base i would be:
1*i^4 + 0 * i^3 + 0 * i^2 + 1 * i^1 + 0 * i^0 = 1 + -i = 1-i
You must take some number, n, in base i and convert it into a number in base 10, in the format of a 2x1 vector.
[a,b] = a+b*i
The number will always be some combination of 0 and 1
In Python you will be given an integer.
In Javascript and C++ you will be given a string
|
def convert(n):
ds = list(map(int, reversed(str(n))))
return [sum(ds[::4]) - sum(ds[2::4]), sum(ds[1::4]) - sum(ds[3::4])]
|
You have been tasked with converting a number from base i (sqrt of -1) to base 10.
Recall how bases are defined:
abcdef = a * 10^5 + b * 10^4 + c * 10^3 + d * 10^2 + e * 10^1 + f * 10^0
Base i follows then like this:
... i^4 + i^3 + i^2 + i^1 + i^0
The only numbers in any place will be 1 or 0
Examples:
101 in base i would be:
1 * i^2 + 0 * i^1 + 1*i^0 = -1 + 0 + 1 = 0
10010 in base i would be:
1*i^4 + 0 * i^3 + 0 * i^2 + 1 * i^1 + 0 * i^0 = 1 + -i = 1-i
You must take some number, n, in base i and convert it into a number in base 10, in the format of a 2x1 vector.
[a,b] = a+b*i
The number will always be some combination of 0 and 1
In Python you will be given an integer.
In Javascript and C++ you will be given a string
|
def convert(n):
s = str(n)[::-1]
return [sum(p * s[i - p::4].count("1") for p in (1, -1)) for i in (1, 2)]
|
You have been tasked with converting a number from base i (sqrt of -1) to base 10.
Recall how bases are defined:
abcdef = a * 10^5 + b * 10^4 + c * 10^3 + d * 10^2 + e * 10^1 + f * 10^0
Base i follows then like this:
... i^4 + i^3 + i^2 + i^1 + i^0
The only numbers in any place will be 1 or 0
Examples:
101 in base i would be:
1 * i^2 + 0 * i^1 + 1*i^0 = -1 + 0 + 1 = 0
10010 in base i would be:
1*i^4 + 0 * i^3 + 0 * i^2 + 1 * i^1 + 0 * i^0 = 1 + -i = 1-i
You must take some number, n, in base i and convert it into a number in base 10, in the format of a 2x1 vector.
[a,b] = a+b*i
The number will always be some combination of 0 and 1
In Python you will be given an integer.
In Javascript and C++ you will be given a string
|
def convert(n):
result = sum(1j ** i for i, x in enumerate(str(n)[::-1]) if x == '1')
return [result.real, result.imag]
|
You have been tasked with converting a number from base i (sqrt of -1) to base 10.
Recall how bases are defined:
abcdef = a * 10^5 + b * 10^4 + c * 10^3 + d * 10^2 + e * 10^1 + f * 10^0
Base i follows then like this:
... i^4 + i^3 + i^2 + i^1 + i^0
The only numbers in any place will be 1 or 0
Examples:
101 in base i would be:
1 * i^2 + 0 * i^1 + 1*i^0 = -1 + 0 + 1 = 0
10010 in base i would be:
1*i^4 + 0 * i^3 + 0 * i^2 + 1 * i^1 + 0 * i^0 = 1 + -i = 1-i
You must take some number, n, in base i and convert it into a number in base 10, in the format of a 2x1 vector.
[a,b] = a+b*i
The number will always be some combination of 0 and 1
In Python you will be given an integer.
In Javascript and C++ you will be given a string
|
def convert(n):
ls = [int(j) if i%4<=1 else -int(j) for i,j in enumerate(str(n)[::-1])]
return [sum(ls[::2]),sum(ls[1::2])]
|
You have been tasked with converting a number from base i (sqrt of -1) to base 10.
Recall how bases are defined:
abcdef = a * 10^5 + b * 10^4 + c * 10^3 + d * 10^2 + e * 10^1 + f * 10^0
Base i follows then like this:
... i^4 + i^3 + i^2 + i^1 + i^0
The only numbers in any place will be 1 or 0
Examples:
101 in base i would be:
1 * i^2 + 0 * i^1 + 1*i^0 = -1 + 0 + 1 = 0
10010 in base i would be:
1*i^4 + 0 * i^3 + 0 * i^2 + 1 * i^1 + 0 * i^0 = 1 + -i = 1-i
You must take some number, n, in base i and convert it into a number in base 10, in the format of a 2x1 vector.
[a,b] = a+b*i
The number will always be some combination of 0 and 1
In Python you will be given an integer.
In Javascript and C++ you will be given a string
|
from itertools import cycle
def convert(n):
c, i, val = cycle([1,1,-1,-1]), cycle([0,1]), [0, 0]
for l in str(n)[::-1]: val[next(i)] += next(c) * (l == '1')
return val
|
You have been tasked with converting a number from base i (sqrt of -1) to base 10.
Recall how bases are defined:
abcdef = a * 10^5 + b * 10^4 + c * 10^3 + d * 10^2 + e * 10^1 + f * 10^0
Base i follows then like this:
... i^4 + i^3 + i^2 + i^1 + i^0
The only numbers in any place will be 1 or 0
Examples:
101 in base i would be:
1 * i^2 + 0 * i^1 + 1*i^0 = -1 + 0 + 1 = 0
10010 in base i would be:
1*i^4 + 0 * i^3 + 0 * i^2 + 1 * i^1 + 0 * i^0 = 1 + -i = 1-i
You must take some number, n, in base i and convert it into a number in base 10, in the format of a 2x1 vector.
[a,b] = a+b*i
The number will always be some combination of 0 and 1
In Python you will be given an integer.
In Javascript and C++ you will be given a string
|
def convert(n):
res = sum(x * 1j**i for i,x in enumerate(map(int, str(n)[::-1])))
return [res.real, res.imag]
|
You have been tasked with converting a number from base i (sqrt of -1) to base 10.
Recall how bases are defined:
abcdef = a * 10^5 + b * 10^4 + c * 10^3 + d * 10^2 + e * 10^1 + f * 10^0
Base i follows then like this:
... i^4 + i^3 + i^2 + i^1 + i^0
The only numbers in any place will be 1 or 0
Examples:
101 in base i would be:
1 * i^2 + 0 * i^1 + 1*i^0 = -1 + 0 + 1 = 0
10010 in base i would be:
1*i^4 + 0 * i^3 + 0 * i^2 + 1 * i^1 + 0 * i^0 = 1 + -i = 1-i
You must take some number, n, in base i and convert it into a number in base 10, in the format of a 2x1 vector.
[a,b] = a+b*i
The number will always be some combination of 0 and 1
In Python you will be given an integer.
In Javascript and C++ you will be given a string
|
def convert(n):
b = 1
s = 0
while n > 0:
if n % 10 == 1: s += b
n //= 10
b *= 1j
return [int(s.real), int(s.imag)]
|
You have been tasked with converting a number from base i (sqrt of -1) to base 10.
Recall how bases are defined:
abcdef = a * 10^5 + b * 10^4 + c * 10^3 + d * 10^2 + e * 10^1 + f * 10^0
Base i follows then like this:
... i^4 + i^3 + i^2 + i^1 + i^0
The only numbers in any place will be 1 or 0
Examples:
101 in base i would be:
1 * i^2 + 0 * i^1 + 1*i^0 = -1 + 0 + 1 = 0
10010 in base i would be:
1*i^4 + 0 * i^3 + 0 * i^2 + 1 * i^1 + 0 * i^0 = 1 + -i = 1-i
You must take some number, n, in base i and convert it into a number in base 10, in the format of a 2x1 vector.
[a,b] = a+b*i
The number will always be some combination of 0 and 1
In Python you will be given an integer.
In Javascript and C++ you will be given a string
|
def convert(n):
base = 1j
val = 0
for c in str(n):
val*= base
val += int(c)
return [val.real , val.imag]
|
You have been tasked with converting a number from base i (sqrt of -1) to base 10.
Recall how bases are defined:
abcdef = a * 10^5 + b * 10^4 + c * 10^3 + d * 10^2 + e * 10^1 + f * 10^0
Base i follows then like this:
... i^4 + i^3 + i^2 + i^1 + i^0
The only numbers in any place will be 1 or 0
Examples:
101 in base i would be:
1 * i^2 + 0 * i^1 + 1*i^0 = -1 + 0 + 1 = 0
10010 in base i would be:
1*i^4 + 0 * i^3 + 0 * i^2 + 1 * i^1 + 0 * i^0 = 1 + -i = 1-i
You must take some number, n, in base i and convert it into a number in base 10, in the format of a 2x1 vector.
[a,b] = a+b*i
The number will always be some combination of 0 and 1
In Python you will be given an integer.
In Javascript and C++ you will be given a string
|
def convert(n):
r=[0,0]
for i,d in enumerate(str(n)[::-1]):
if i%4==0:
r[0]+=int(d)
elif i%4==2:
r[0]-=int(d)
elif i%4==1:
r[1]+=int(d)
else:
r[1]-=int(d)
return r
|
You have been tasked with converting a number from base i (sqrt of -1) to base 10.
Recall how bases are defined:
abcdef = a * 10^5 + b * 10^4 + c * 10^3 + d * 10^2 + e * 10^1 + f * 10^0
Base i follows then like this:
... i^4 + i^3 + i^2 + i^1 + i^0
The only numbers in any place will be 1 or 0
Examples:
101 in base i would be:
1 * i^2 + 0 * i^1 + 1*i^0 = -1 + 0 + 1 = 0
10010 in base i would be:
1*i^4 + 0 * i^3 + 0 * i^2 + 1 * i^1 + 0 * i^0 = 1 + -i = 1-i
You must take some number, n, in base i and convert it into a number in base 10, in the format of a 2x1 vector.
[a,b] = a+b*i
The number will always be some combination of 0 and 1
In Python you will be given an integer.
In Javascript and C++ you will be given a string
|
def convert(n):
s = str(n)[::-1]
p = [s[i::4].count('1') for i in range(4)]
return [p[0] - p[2], p[1] - p[3]]
|
You are given an n by n ( square ) grid of characters, for example:
```python
[['m', 'y', 'e'],
['x', 'a', 'm'],
['p', 'l', 'e']]
```
You are also given a list of integers as input, for example:
```python
[1, 3, 5, 8]
```
You have to find the characters in these indexes of the grid if you think of the indexes as:
```python
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
```
Remember that the indexes start from one and not zero.
Then you output a string like this:
```python
"meal"
```
All inputs will be valid.
|
def grid_index(grid, idxs):
return ''.join(grid[x][y] for x,y in map(lambda n: divmod(n-1,len(grid)),idxs))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.