38
Awesome Team
Jürgen Strobel
Last seen 22 hours ago
Member for 5 years, 1 month, 11 days
Difficulty Normal
It's probably more pythonic to use a straight membership test for mapping than the empty string `''` guard value.
if c not in mapping or mapping[c] == str2[i]:
Maybe shuffle the conditions around too to avoid re-assignments of the same values and better distinguish the 2 interesting cases:
More
Very readable, except for the double negation. You could invert every condition, and use `and` to combine the results without nesting brackets:
return long_enough and has_digit and has_uppercase and has_lowercase
More
Sometimes the most obvious solution works best, even if some people
scoff at a lack of mathematical elegance.
More
As far as I can see there is no reason to put an empty string on the initial stack? If using an empty list, the return value could become just `not stack`.
More
You don't need to break dicts into 1-element dicts if you recurse into `tree.values()` directly just like for lists.
On a side note it's probably more pythonic to use the builtin `isinstance` method for the type check.
More
Looking back at this I discovered I made a mistake and pruning visited parts is inefficient.
More
There are much faster solutions that do not need to fully sort the input, much less sorting several times. Should be filed under creative.
More
There are much faster solutions that do not need to fully sort the input.
More
Overkill, but educational value.
You could replace `count` with a `get_children` function, this way you get by with simpler direct recursion (and without some non obvious edge cases) in tree_walker, and use only half the precious stack space.
_I don't like the single line def formatting._
More
I found this is not very efficient (~20s on the biggest test) yet. Maybe I'll find some time to update it, I suspect tracking non-lamp positions explicitly would greatly improve it.
More
Nicely done, similar to mine in regard to the extracted format function
and the use of bitwise ^. My use of the latter was more extreme though,
flattening each char to a single 15 bit int.
The while loop should probably be a for loop since it's
deterministically enumerating character positions
More
You could move the last clause to the front and just drop its negated form currently there.
More
Nice. I thought about doing a top-down DP solution using `@cache`, but got lazy when the recursive generator felt fast enough.
More
Is this truly correct? It appears to me that the code will not ever multiply by zero.
More
The generator `(x for x in queue)` is weird. On first glance it seems superfluous, but on second glance it is what keeps the for loop going, since its underlying `queue` is extended in the loop body. I am not sure this even defined behavior.
A straight `while` taking the first element of queue woul
More
Strictly speaking the way you `split()` is incorrect. Words might be separated by punctuation only, although no tests do this.
More
That's cool, but I guess it relies on unique node values. Which the examples and tests imply, and maybe graph theory also, but my developer self would have needed it spelled out. :/
More