57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 12 hours ago
Member for 11 years, 6 months, 24 days
Difficulty Advanced
We shall not cease from exploration, and the end of all our exploring will be to arrive where we started and know the place for the first time.
Line 4 is a perfect example of what horribilities people go through, just to avoid writing another newline. It's not worth it. :-P
digit = int(i)
if digit:
s *= digit
More
This recursion is really misplaced here. Python is not particularly recursive language, depth is cut off after 100 iterations. And [:-1] makes a copy of (almost) a whole list every time.
More
Waitaminute. This is sarcasm, right?
And you dare to call my code unreadable? :-O
Ok, let's see.
* Variable names: data, result, temp, i, val. Completely generic and without any semantic context. temp is as temporary as everything else. result is in fact a negation of real result. val is so
More
Nice solution (as always:). A few details:
* For distance, see complex and abs. Or at least math.hypot.
* For reachable, you don't have to invert each and every one of them... "all(not blah)" is "not any(blah)". It even seems more readable. :-)
* For intersect_cell, you don't need all four
More
Nice and clear. Of course, Py2.7 is complicated with having to be forced to
float division, but still, 12. and 60. in the divisor might be better than
H = float(H) and M = float(M). Also, H %= 12 is a nicer way to write that
if.
More
Lines 10, 11, 12 and 13 are just
return max(wheat, pigeons)
Also, I know you know about +=, since you use it in line 8. Use it also in line 14 (and use -= in line 7).
Thirdly, condition 0 > a - (b + c) is really weirdly written. It's really just a < b + c.
Fourthly, lines 3 and 4 can
More
You might wish to study str.zfill and dict.get methods. But especially the first one. ;-)
u, t, h, T = str(data).zfill(4)
You can even "map(int," over them, but that might be too advanced. :-)
More
Flat is better than nested, indeed. :-D The only thing you missed is that
you could write line 25 as
cube_volume = 3..__rpow__
:-D
More
You're writing docstrings on the wrong side. :-P
Also, that action at a distance via changing retlist is much more naturally written using a generator.
More
Comprehensions / generator expressions are usually better than higher order functions.
map(int, map(methodcaller('replace', ':', ''), entry)) ~~~>
int(time.replace(':', '')) for time in entry
And your love for oneliners is no valid excuse for that horrible duplication of code. :-P
(
More
Yes, of course complex numbers are a natural representation of 2D. But you can go _much_ further. For example, instead of dirs[dir_idx], you can just use (-1j)**dir_idx. The set of complex numbers is not just 2D vector space, it's also a field. ;-)
More
This is one of those rare places where functools.reduce might actually be
more readable. ;-P
More
Those Lego bricks really fit into one another. :-D
More
"Improvement" depends on the criteria. I surely think that just trying the bases until one works is more intuitive than calculating the maximal digit value --- but of course, the second one is faster.
More