38
Awesome Team
Jürgen Strobel
Last seen 7 hours ago
Member for 5 years, 1 month, 25 days
Difficulty Normal
Nice. For degenerated triangles it should also return 0,0,0, so I think it should be a+b < c etc. in the guarding if.
More
Separation of coordinate conversion and checking logic in int coordinates would make this both easier to read and possibly faster.
More
This is not speedy, it's doing 2 nested loops over weights, for a O(n^2) solution. This can be done in O(n).
More
Cool. There's `graphlib.TopologicalSorter` in the stdlib now too, but it needs some tweaking to get the [alphabetical order correct](https://py.checkio.org/mission/determine-the-order/publications/juestr/python-3/graphlibtopologicalsorter/).
More
A lot of code duplication. key() is called multiple times per element. Does it handle custom types?
More
Ha I missed how the strings can be compared safely, else I did the same with key=.
More
Using a bit more from numpy you could vectorize everything in this mission.
E.g. `numpy.subtract.outer` on points basically replaces your 2 outermost loops, it creates a matrix using a full outer join with pairwise subtraction for all points.
More
Regarding rank, summing the indices appears to be flawed to me (despite
weak tests). What you'd really want is the minimum num with the minimum
of the first index as tie breaker, not the minimum sum of indices.
Unless you can prove these 2 definitions are equivalent?
More
Python's rather new built-in `int.bit_length` makes `msb` superfluous. Curiously everyone copied it or imported `math.log2` instead.
More
Using // (floor division) instead of / you wouldn't need to do conversion back to int.
More
A few suggestions:
- ```for row, line in enumerate(lines)```, manual counting isn't very pythonic
- shortcut returns directly in the for loops would be good here, no need for the 4 result vars at all, and wasted effort to continue after finding a match
- transposing with zip_longest is neat, but you
More
Fraction is a nice touch, I was worried about using float but it did work for the current tests...
More
```if COND return True else return False``` can be trivially shortenend to ```return COND```, or ```return bool(COND)``` if COND is not of type bool already.
More
Index-based iteration is non-pythonic. This is much easier using language features properly, like str.split() or regular expressions and iteration with for.
More
I thought about this too and it works atm, but maketrans is not defined for the case of an inconsistent mapping. Future or other python implementations may raise an Exception without warning, and I'd rather call it creative for that reason.
https://docs.python.org/3/library/stdtypes.html?highlight=
More
Using ```min``` instead of ```sorted``` would be much more efficient with almost the same code.
More
Nice, I also tried an approach with permutations().
However checking adjacent pieces corresponding heights at the top of can_restore was not intended, and breaks some of the random tests. You likely got lucky, an example which is supposed to work but doesn't with your code is:
[[0, 5, 1, 1, 0
More
I don't see how the key lambda can work? In the first example both 6 and 2 get the same frequency hence the output should be in order of input: [4, 4, 4, 4, 6, 2, 2, 6]. That was my first attempt too but it got rejected.
More
Tricky and very inefficient for large numbers, should be in weird category.
More