38
Awesome Team
Jürgen Strobel
Last seen 12 hours ago
Member for 5 years, 1 month, 1 day
Difficulty Normal
Very nice. In the if-branch **dice_number can be removed since it is known to be 1.
More
Strictly speaking since `items` is an `Iterable` we shouldn't use `[]` on it. (The tests are bad.)
More
You could replace the first inline-if too:
return num and (num % 9 or 9)
More
I don't see the Memento pattern here. The Text class has no method returning its state. The Memento pattern is about encapsulating the the logic to create and restore internal state via an opaque data object (=Memento) in the originating class, see the WikiPedia article.
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
IMHO State has a lot of boilerplate over just using a tuple, @dataclass at least would reduce this.
Search would be more efficient if State.__lt__ also includes len(remains) as a tie breaker for states closer to the goal.
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
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
Nice, I felt changing the const arrays was cheating, but it really makes it much simpler so why not.
More
Nice solution overall. The range checking if statement could be improved
in readability by using python's great chained comparison feature
0 < x <= xsize etc
although you might have to negate the whole thing, or rearrange the
following for statement.
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
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
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
```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
Separation of coordinate conversion and checking logic in int coordinates would make this both easier to read and possibly faster.
More
Ha I missed how the strings can be compared safely, else I did the same with key=.
More
Using // (floor division) instead of / you wouldn't need to do conversion back to int.
More