27
Last seen 8 hours ago
Member for 1 year, 6 months, 15 days
Difficulty Normal
Thanks for that solution. I didn't know you could flatten lists/sets like that.
sum(matrix, tuple())
More
Yeah, thats the good stuff! I would give you points for it, but sadly that doesn't work in 'random soulution'.. ;)
More
Oh wow, now THIS one is quick :D
Takes 0.00 seconds for 1000 runs of is_perfect(100000000). Mine takes 0.40 seconds.. Nice one!
More
It's very slow though.. Takes over 4 seconds for n == 100'000'000 on my computer. You could at least go for
divisors = filter(lambda x: n % x == 0, range(1, (n + 2) // 2))
More
it's pretty slow though.. Takes 2.5 seconds on my computer for is_perfect(100000000). You could at least go for
def is_perfect(n: int) -> bool:
def find_divisors(m):
for i in range(1, (m + 2) // 2):
if m % i == 0:
yield i
return sum(find_divisors(n))
More
Loved your "Clear" solution, but now this is just a nightmare! ;)
More
Loved this one! Lots of things to learn here.
code[i] or '0'
Nice!
'01'[i in rs]
Very nice! :)
More
No need for those len()'s :D
import re
def checkio(expression):
s = re.sub(r'[^\][(){}]', '', expression)
n = 1
while s and n:
s, n = re.subn(r'\[]|\(\)|{}', '', s)
return s == ''
More
I like the logic, but I think you could make it more compact
def checkio(exp):
# From the input exp, create a new string with only the brackets allowed in it.
b_in_exp = ''.join(c for c in exp if c in '()[]{}')
# Replace all brackets in the new string with empty strings. Retur
More
Very nice! Thanks for reminding me that map can take more than one iterable.
More
No need for the list comprehensions and the len :)
return max(args) - min(args) if args else 0
More
if s2[0] >s1[0]+s1[2] or s2[0] < s1[0]:
if s2[1] > s1[1]+s1[2] or s2[1]s1[0]+s1[2] or s2[0] < s1[0]) and (s2[1] > s1[1]+s1[2] or s2[1]More
if s2[0]<=s1[0]+s1[2] and s2[0]>=s1[0]-s2[2]:
return True
else:
return False
could be
return s2[0]<=s1[0]+s1[2] and s2[0]>=s1[0]-s2[2]
More
This code could need some cleanups..
For example, all the print statements are redundant. You could replace the 'items[len(items)-1]'-like statements with just 'items[-1].
More
I have some issues with this solution..
In combinations_with_replacement you take range(1, 18) -> 1 to 17, but max(die) is <= 18.
Also, you could optimize that to range(1, min(19, sum(enemy_die) - len(enemy_die) + 2)
More
No need for an 'else' clause:
from collections.abc import Iterable
def duplicate_zeros(donuts: list[int]) -> Iterable[int]:
res = []
for x in donuts:
res.append(x)
if x == 0:
res.append(x)
return res
More