34
Last seen 2 years ago
Member for 11 years, 6 months, 10 days
Difficulty Normal
Nice approach. I feared no one else used Bellman-Ford, you proved me wrong ;-)
More
I think your code can be clearer if instead of
if ord(cstring[i+3]) in range(48, 58):
you use
if cstring[i+3].isdigit():
More
Why not use strings for _ranks_ and _suits_? String is also iterable.
ranks, suits = '023456789TJQKA', '0scdh'
You can also write your _hand_ variable like this:
hand = {h: 10 ** n for n, h in enumerate(['0', 'HC', 'OP', 'TP', 'TK', 'St', 'Fl', 'FH', 'FK', 'SF'])}
Or even nicer:
han
More
Tested with Vinc maze and 4 rooms test :D
Lines 22-26 are only here for optimization.
More
Wrong category here. Speedy is for faster solutions. I don't think this one can be faster than nickie's solution for example, with so much branching/
More
Good solution, but not very pythonist.
I know it's an old one, but seems interesting to comment on it, to give tips to future readers.
- First 2 lines: Python allows multi-initializations -> __full, total = 0, 0__
- _int(ceil(radius))_: ceil already generates an integer, no need to use int() on
More
A bit of explanation: this solution is based on coprime triplet (5,6,7).
As they are coprime, for any n < 5 * 6 * 7=210, {n%i | i in (5,6,7)} will be unique.
So, without counting first random try, we can recognize all n < 100 in 3 steps - that is the minimum with divisors <= 10.
More
When I saw Spoty made an [implementation](http://www.checkio.org/mission/bats-bunker/publications/spoty/python-27/first/) based on the same algorithm, I decided to keep same structure.
Feel free to compare.
More
An algorithm with O(n^6) complexity for this task... really frightening...
Especially when Floyd-Warshal has a O(n^3) complexity on a n x n matrix.
Your function *all_cells* introduces a O(n^2) complexith when you only need to do:
for k in range(n):
for i in range(n):
for j
More
Do you know that Python has [complex number](https://en.wikipedia.org/wiki/Complex_numberg) support?
They are often you to represent a grid in 2D, so `x + 1j * y` represents a point at coordinates _(x, y)_.
There is a trick with the second line: `[1j ** k for k in range(4)] produces [1, 1j, -1, -
More