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.
Only thing to note about this pattern is that every boolean statement is evaluated. It's fine here, but if the conditionals were more complex/long-running functions, every single one of them would be called. You could instead return a function from the dictionary, and call that function with the
num
argument, to evaluate it.The solutions that use sorting may be shorter in code length, however this code and similar variations are shorter in execution time, O(n).
wow, just absolutely ruthless
To specify the exception, in this case it would be a TypeError for trying to iterate over an int or None. Not sure what other types are present in the tests. If it is some other iterable, like a list of ints, the exception would be an AttributeError since the int type does not implement .lower()
no need for 'digits' to be a list. You can pass str(n) into the map since it's iterable in the same way
It seems the codewars wikipedia may have changed again? - 11/04/20
The expected results differ between the sample test and full test. Seems the links under 'See Also' are expected in the full suite, but not in the sample test.
Could someone please help me with this Exit Code?
I am passing all sample tests but not the full test. I know most likely the problem is with my implementation :) but wanted to check.
Thanks for the reply!
My implementation is 'tracking' atom creation via a simple attribute in the Molecule instance, in order to provide the next continuous id number to new atom instances created from the brancher, add/add_chaining, and closer methods.
When unlocking, I am noting which atoms will need to change id number, then updating them after all hydrogens have been removed.
My main assumption: If atoms remaining in the molecule have a higher id number than a deleted hydrogen, they were created after, so their id number should decrease (There is 'room' below them)
Working on a better way to do this, as I think it may be simpler
Edit: Figured it out. Was way simpler, haha. Thanks!
I am primarily getting tripped up by the reordering of the ids during the unlock method.
I'm passing the fixed tests for the full test suite (thanks so much for the GREAT test suite btw), but failing a handful of random tests. Examining the 'actual' versus 'expected' output, I'm usually off by one or two for my id values. It's pretty likely the way I'm tracking
atom.id
s is extremely janky from the get-go, and by the time I'm removing hydrogens and possibly dealing with orphaned chains/branchs, it's all gone to sh**. Without giving too much away, is there some suggested design to be using here? I understand if this question can't be answered without spoiling the solution. I've just been working for a few days on this one and was feeling so close but now totally stuck. Any nudges in the right direction greatly appreciated, thanks!This comment is hidden because it contains spoiler information about the solution