Ad
  • Custom User Avatar
  • Custom User Avatar

    Genralized tip:

    def kata_solution(arg):
        print(arg)
    

    You'll fail all the test, but usually you'll see the input. (Except, as you'll discover here, not always.)

    def kata_solution(arg):
      pass
    

    Often this will help you find out the count of tests. (Although, again not always.)

    I was able to reach 65 tests, but still timed out. I suspect we're using the same algorithm (but I've optimized mine as much as possible). I have in mind another algorithm which I think may be faster, but don't have time to implement it at the moment. I'd encourage you to try a different approach. 232 people have solved it in Python, so it should be doable.

    No spoilers, sorry. :)

  • Custom User Avatar

    Looks great.

  • Custom User Avatar

    I think that's a lot clearer. It makes it clear that elements can't be re-used but that values may appear more than once.

    Alternatively, you could have the output be a value:multiplicity mapping which might be more readable than a list of indices and is easy to check.

  • Custom User Avatar

    I don't know if it is needed to change the kata in order to fix the description, but if that is the new requirement of the kata:

    Given a possibly empty list... return a subsequence of the list which sums to the target number...

    The subsequence must consist of elements from the original list without re-ordering, but the elements need not be contiguous (i.e., skipping elements is fine). ((Possible examples here)) An empty subsequence is defined as summing to zero. ((Maybe a per-language bit about the form of the returned subsequence.))

    The target will never ...

    I think this uses clear terminology, but also restates the definition in a way that (I hope) avoids potential confusion.

  • Custom User Avatar

    That'd certainly be clearer, and even if someone is led astray by it (since it isn't a strict requirement), they can still arrive at a solution.

  • Custom User Avatar

    While that is a fair point, I don't think it addreses my criticism. The kata being named after its source problem in mathematics makes sense, but my criticism is about clarity. 'Set' has meaning in both domains and we should use it carefully and explicitly. Additionally, solutions to the SSP are often actual sets (indices or pairs of (value, multiplicity)) rather than multisets. I think even linking to the wiki page or using the word 'multiset' would help clarity tremendously.

    Edit: I was writing my reply to @Mednoob concurrent with yours, @JohanWitlink. It was not meant as a response to you.

  • Custom User Avatar

    The kata title and description are unclear. It is called "Subset Sum", but the input is a list and the output requires a list. We are looking for a sublist sum of a list and "sublist sum" may be a better title.

    The kata description reads:

    A subset cannot use elements multiple times, but does not have to be ordered. If a particular number occurs more than one time in the input list, you can use it up to as many times as it occurs.

    I think this should be rephrased. I understand that it is getting at the difference between elements and values, saying you can use values multiple times iff there are multiple elements with those values, and that any element can only be used once. However, it took quite a bit of mental parsing to understand (which was further confused by the title).

    Edit: I realize that 'sublist' may also be unclear here, because it may be interpretted as 'contiguous sublist'; so I'm not quite certain what I would call it, so 'subset' may be more appropriate, thinking of it as a subset of elements, rather than values. But if so that distinction of elements and values should probably be more prominant.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    I don't know why this was downvoted. The description doesn't say anything about per-test time limits nor is it specified anywhere what these limits should be. This information should be in the description.

    Why it matters: Knowing whether your code is a few milliseconds off or an order of magnitude off affects your approach on solving the problem. Imagine if the time requirement was 240 microseconds. Then the solution might just be to modify a conditional or include a called function's code directly in your main function. Now imagine if the time requirement was 10 microseconds: You'd be pretty sure your entire approach should be questioned.

    For anyone looking for what time they need to get it to pass, the slowest run of my passing solution was around 90 ms for the batch. Guessing the cut-off is 100?

  • Custom User Avatar

    The input should be specified. Mention it's structure, and also define what is meant by 0, 1, and 2.

  • Custom User Avatar
    expr = "__import__('malicious_code').execute();5 3 +"
    
  • Custom User Avatar

    For anyone confused by this, read the comments that are pre-loaded in the solution box (where you write your code).

  • Custom User Avatar

    I realize these comments are quite old, but @DworkinFromChaos is right.

    Specifications don't belong in the (mutable!) fields of the kata. They should be in the description, perhaps especially in the case where they cause otherwise working solutions to fail.

  • Custom User Avatar

    Isn't @paraliterary's point that the field is invalid but your solution returns True indicating that it is valid?

  • Loading more items...