57
Awesome Team
Vedran Čačić
https://web.math.hr/~veky
Last seen 22 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.
You're the one who said you'd like to code as I do, right? Ok, first lesson: [`len`](https://docs.python.org/3/library/functions.html#len) builtin function.
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
Don't worry about English, worry about Python. ;-] Second lesson: [`ord`](https://docs.python.org/3/library/functions.html#ord) builtin function. ;-)
More
Slicing is better than indexing by range. And you don't need those mins then.
More
Line 18 is wrong. rounded gamma is _not_ necessarily equal to 180 - rounded alpha - rounded beta.
BTW why do you reinvent the wheel (in this case, builtin round function)?
More
namedtuple('complex', 'real imag') is better, it supports more operations. ;-)
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
Interesting idea to use numpy to solve the system. However the system is
modular, so you have to guess k (additional number of turns) so the whole
thing becomes a bit clumsy. (But still, explicit loop would probably be
better than recursion with a default parameter.) Numpy _can_ be exploited
to
More
First,
array[len(array)-1] ~~~> array[-1]
Second, don't ever write empty except! Say what you really guard against:
except IndexError:
More
Line 17 is really pointless. :-)
You don't need zip inside map. map(sum, p, dp) is ok.
Start of line 23 can be written: np in m.keys() - visited. Not very useful here, but good to know: keys is a set-like object.
More
You like those complicated control flows very much, do you? :-D
You're one of rare people here that can stuff if/if/else, nested if, not, or, continue and return from for loop in about 6 PEP8-approved lines. :-D
More
Very high level code. Exact, documented, with references. I like it.
BTW line 28 made me laugh. Avoiding code duplication at every price. :-D
More