Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
It is quite frequent (and sometimes natural) to name callable classes as if they were functions.
Yes you should be reading instead of asking, it's easily found in the documentation.
That's mixing functions and classes naming conventions, but well, it's in line with the requested syntax (ugly to me)
I started with this way, however for testing that the node is the same memory object, we can just use
id()
built-in function.Works for an arbitrary number of dices; may however miss the point of the kata.
Also, the
count
is performed at least twice per rule: not very clever.This comment is hidden because it contains spoiler information about the solution
Best solution so far, better than using
collections.defaultdict
ascollections.Counter
is explicitly made for this. Well done!Agreed:
filter
lies in the paradigm of functional programming, and the proposed answers relies oncount
to keep some permanent state (in fact, modifyingc
counter, whilefilter
does the looping).So, while I find it clever, this solution is not easy to understand.
It does not work for you because you got newlines (
\n
) in your test string, that are not allowed by the rules of the kata.Take care to use
"""....""".replace('\n', '')
if you want to use such multi-line strings as long strings.This comment is hidden because it contains spoiler information about the solution
Untrue:
len(walk)
is not looping onwalk
, it accesses a parameter oflist
instance.Moreover, looping over
walk
and counting the items would miss the optimization to directly reject awalk
of wrong size, before even looking at the directions one after another.