39
Axel
Last seen 1 month ago
Member for 2 years, 9 months, 4 days
Difficulty Normal
Thanks for remembering complex numbers for map tasks!
It helps to shrink my solution to 10 lines: https://py.checkio.org/mission/lantern-river/publications/CDG.Axel/python-3/complex-isnt-complex/
More
It looks like inappropriate using of spec and name for class Army (class variables for instead of local variables). IMO this looks better
def train_swordsman(self, name):
return Swordsman(self.types['swordsman'], name, self.army, 'swordsman')
More
Think it won't work with 'jack'*20 or something like this :)
Btw it's 362880 variants even with max 9 monsters
More
very short, but without abstract. plus you may omit dataclass, field and defaultdict using and simplify your code something like that:
cuisine, order = tuple(), [0, 0]
def add_food(self, food_amount, food_price, dish=0):
order[0] += food_amount * food_price
def add_drink(self
More
Some optimization:
- sum eats iterable, so [] is unnecessary
- you can sum boolean, and need no if-comprehension
More
Impressive solution!
Btw join eats iterables, so [] inside isn't necessary
More
another solution is reduce from functools (based on your solution)
from functools import reduce
def check_command(pattern, command):
return pattern == reduce(lambda a, b: a * 2 + b.isalpha(), command, 0)
More
some optimization:
- you may first calculate ans, then control sun visibility with one condition like x <= ans <= y
- abs(min) looks superfluous
More
some ideas for one-liner:
- f-string
- := operator
- % operator
- hint that 0 or x == x
- indexing string with bool to get first or second symbol of string
More
first you may use this instead of binar_morze(). In addition you may remove 'bm = '.'*(nums[i] - len(bm)) + bm'
def binar_morze(n):
return f'{1:04b}'.replace('0', '.').replace('1', '-')
second you may to parse source data to 6 variables (it is possible in one line)
then use f-string t
More
you should use "return bool" instead of
if bool:
return True
else:
return False
More
Great abstraction and polymorphism using!
But for my solution I economize with volume(). I made it non-abstract with 0 result )
More
you can use -x[1] instead of x[1] and omit 'reverse=True'
More