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
Came up with the same solution!
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.
The kata description says that your solution should use
with
. Start from there. Iswith
a keyword? Look it up! How does it work?It means that there was an error in the test suite. Your solution failed, but the failure message is missing, which has been fixed. Try again!
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!
hi,
I'm not entirely sure about what you did, but if your problem is only about the id numbers, don't try to keep track of them, just redefine them when you unlock. See:
if that's not enough, maybe you have troubles about chaining or you're not removing some hydrogens when unlocking?
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!I ran into the same issue! I belive that the intersection operator does not work because the intersection does not include elements that appear in only one of the key lists.
My solution was to create two new variables - k1 and k2, which were sets of the key lists of c1 and c2 - and use the union of the the two sets.
Therefore, my replacement was k1.union(k2), which creates a new set with elements from both key sets. Note: union is a built-in function that only works for sets.
I hope this is helpful!
Loading more items...