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.
I'm not sure what are the criteria for ranking katas, but I feel this should not be ranked 5kyu. Please, don't bother, just my feeling.
This comment is hidden because it contains spoiler information about the solution
OK. But, perhaps you should admit that your code returns "YES" when an empty list is given. And perhaps it's no a coincidence.
No, regarding the expression "guarded by an assert" I mean this construction:
Better than a try-except for checking parameters validity at the very beginning.
Again, please, no harm intended.
BTW, how is it that you post a link to a solution within these "discourse cells"? You told me that is better than refering to the authors, and I agree. But I don't see how to do it. At least, not at first sight.
Thank you for your advice.
Regarding the comments of the code, some user (Firefly2002) actually commented that he liked the comments. I'd not have commented so profusely though if it were not because of the restriction over the complexity of the solution. By the way, you're right, it's not O(2n) but O(4n). I realized of the mistake after publishing the solution, but I forgot to update the comments (actually, as you can see there is a dangling comment that says "Also, since". My fault.
The fact that the solution is not pythonic... you're right.
nums.count(0)
is definitely better that the awfull list comprehension that I wrote... and most pythonist look down onmap
(that's why Python is not and won't ever be a proper functional language). But, correct me if I'm wrong, I'd say thatfilter(None, nums)
is not very pythonic either. I mean, may be that it does what is pretended (to strip all zeroes from nums), but it does so through a very obscure syntax that seems to aim something just the opposite of what it's done. I'd rather use:filter(( lambda x: x!=0 ), nums)
or even[x for x in nums if x != 0]
(probably this latter is the most pythonic of them all). Both are cleaner (though a bit more verbose).Regarding the use of
//
instead of/
, I actually though of using it, but since product has all the elements in nums but the zeroes... I guess that the result should be the same. And bad if it's not.Also, I'd say that the second call to
nums.count(0)
(inif nums.count(0) > 1:
) could be rewritten just asif zeros > 1:
. Actually a tiny improvement that avoids a second iteration through nums.Nevertheless, of course your solution is far better than mine. Perhaps that's why you're 1 kyu and I'm only level six. Still learning ;-)
Please, take it easy. I'm not here to quarrel over anything. I'm here to improve my coder's skills, to learn and, whenever I can, to give advise to less experienced coders. I though that the "War" part of the name of this site was a mere literary figure, but I can see that it's one of the features of the site ;-)
If I said that "you" though that the answer to tickets([]) == "YES" is because your solution behave that way. As most published solutions do. I didn't pretend to read your thoughs or your preferences.
Whether an empty list is a valid input or not... well, I've checked the Kata constraints and, up to my understanding, they don't say anywhere that the empty list is not a valid input. Actually, most people's solutions treat the empty list as a proper input. Were it not a proper input, I guess that it should be guarded by an assert (yes, I know, I know: that's the boilerplate that so many Pythonist just hate).
Yes. I'm new to the platform and I don't know how to use it propery yet. I didn't know how to place a link into a "discourse" item. Perhaps you could me say how. I'd be most grateful :-)
It makes every sense if there is not any restriction on an empty list of people (a "huge" empty list of people, though :).
Some of the programs posted just break if you feed an empty list (for example, timakz11 and hainihao's ones). That's plain wrong.
Now, another issue is which should be the correct answer on such a situation (empty lists): "YES" or "NO".
Most people who have posted a solution think that the solution is "YES". You yourself think that way.
Some few return "NO" when the empty list is there (technout and kill-that-Hohhot-man to name just two).
I'd say that the "technically" right result (that is the "YES" answer) is the correct one. At least this is what most people think.
The test suite is incomplete. It needs at least the followning:
This is because any list of buyers that begins with a 100$ bill or a 50$ bill must return "NO" whatever the rest of the list is (since at the beginning the till is empty and Vasya can't return any change. Also, if the list of buyers is empty, Vasya is OK (he doesn't fail to give the returns)... though I guess that the cinema's owner won't.
Some solutions posted and acepted as right are actually wrong because of this (ie. Wangsihe, Hickock). Specially all the solutions that merely count the number of bills received of each class or solutions that don't take into account empty lists of people.