57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 11 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.
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
Recursion is not a good solution here (although it first pops to mind), since as you have seen, there is a lot of copying going around just to save state to possibly return to it later. It _could_ be done without it, but it's much harder and not really worth it IMO.
More
numstring is semantically empty, str(number) says the same thing in a clearer way.
You could even iterate
for digit in map(int, str(number)):
You don't need != 0 in line 7:
if digit:
answer *= digit
More
You don't need to import date. ;-)
You can just say timedelta(1).
diff is a strange name for what you're really calculating.
"in {5, 6}" is probably nicer than "in [5, 6]". Or just > 4. :-)
Line 4 is O_O. :-P
More
Seriously? Customized Y combinator you consider Clear? .-o
More
avoidable(p, q) = all(map(int.__ne__, index(p), index(q)))
Many people don't know map can take more than 2 arguments. :-) Also,
for spam in (blah for eggs in ham):
yoord
is really nicer written as:
for eggs in ham:
spam = blah
yoord
Also, you can
More
Yes, that's how a 7bit washing machine embedded microprocessor would solve the problem. :-D Python has a bit richer data structures on your disposal. :-]
(Unfortunately, the code for 8 is not valid ASCII... but neither is its complement. Ah, the good old times of punched cards...:)
More
When you're bad, be truly bad. :-]
filter('0'.__ne__, str(number))
Of course, much better is
filter(int, str(number))
\- not bad at all. ;-)
More
Line 2 is totally pointless. Lines 15-18 are also pointless. Line 12 is just `fhands |= it`. Lines 10 and 11 can be written in the same way. Lines 6, 13 and 14 can be written using `else` loops.
More
Again, obsession with lists. `merged` is the true solution, line 13 is just bureaucracy. :-)
More
What's the point of having a good solution in the docstring, and then an inferior one in the code?
More
`max` has a `default` keyword, too, which you can use to avoid lines 5 and 6.
Also, re's forward looking might help you so you don't have to extract `group(0)` as a separate operation.
More