5 kyu

Random sampling in constant time

Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • monadius Avatar

    Authoring Python Content: "The reference solution or data must not be defined in the Preloaded code. The reference solution must not be defined in the top-level scope of the test suite."

    Please copy verify from Preloaded code into the test_random() function. test_example() can be removed from Test Cases. It is fine to keep the existing Preloaded code for running Sample Tests.

  • Kacarott Avatar

    I've featured this kata in a "Daily Beta" thing we have going on in the Codewars Discord, and a few people found the description confusing, in knowing what was actually being asked of them (ie. the actual task).

    Maybe it could be slightly reworked, to more clearly state the actual task? I don't think this is a big problem (hence the 'suggestion' tag), but I thought I would at least mention it.

    • davilla Avatar

      I've expanded the description if it helps. It feels too elaborate, so you're welcome to trim it down.

      Suggestion marked resolved by davilla 3 years ago
  • JohanWiltink Avatar

    The solution above for the make_table pre-processing step is incomplete since it entirely ignores the weights.

    Huh? The initial solution ignores the weights, but the description example seems to implement the example weights ( [3,1,0,1,5] ) perfectly fine.

    Your task is to implement this function

    Maybe I'm just not good at reading Python ( I definitely am no good at reading Python! ), but the whole section of the description under the example code seems written as if we are reading from the initial solution and not the description. But the description should be written to specify the problem, completely, before going on to the trainer. It's not clear that the class definition is going to be in Preloaded and only make_table is in the trainer. I did not even notice that make_table was not a class method initially.

    Maybe split the code block in two, mark one Preloaded and one Solution or something?

    • davilla Avatar

      Yes, it's meant to work for that one example only. I've made the initial solution closer in line to avoid confusion, and implemented your suggestion about sectioning.

      Suggestion marked resolved by davilla 4 years ago
  • JohanWiltink Avatar

    your solution should run in O(n) time

    Should that not be O(1) time?

    Or do you mean generating the table should run in O(n) time, and the sampling will then run in O(1) time?