Ad
  • Custom User Avatar

    Yours was rejected by someone but a variation of it has been approved!

  • Custom User Avatar

    Whatever is needed, should be done, I think. Tests should include:

    • More ingredients available than required for the recipe
    • Missing ingredient types needed for the recipe
    • Ingredients present, but in insufficient quantities

    It is possible to generate such tests deterministically, and it would behoove a translator to implement such. I do not have the time right now, otherwise I'd fork and write one myself, but I'm sure Pearce is up to it.

    Edit: Here's a sample algorithm:

    For each test:

    • Clone the list of all ingredients, shuffle it
    • Partition it at a random index.
    • The first partition becomes the available ingredients. Add random amounts to each.
    • For a positive test:
      • Sample between 1 and all available ingredients as the recipe.
      • Choose amounts less than or equal to the amount of the respective available ingredient
    • For a negative test:
      • Do as in the positive test, but then do one of the following
        1. Add random ingredients from the second partition (that are not in the available ingredients)
        2. For random ingredients in the recipe, increase the amount beyond that in the recipe
    • Choose a ratio (e.g. 3:1) for positive and negative tests. Either you can generate all test cases with known numbers (e.g. 75 positive, 25 negative) and shuffle them or you can gen_bool(0.75) to generate a positive case, otherwise a negative one. The first option lets you choose the exact number of each test, the second one relies on sufficent cases to produce the desired ratio.
  • Custom User Avatar

    true but then you'd need two separate cases as opposed to one

  • Custom User Avatar

    I'd do it the other way around: generate available, and sample a random subset of those to form a recipe which is guaranteed to add up at least once. You can then play with the numbers for each ingredient.

  • Custom User Avatar

    You can get closer to a 50/50 split without much complexity by either one (or both) of these two means:

    1. Do not use the same range of lengths for both hashmaps. Skew recipe towards having a smaller length and available towards having a larger length. Most translations don't use the same process to generate both from what I've seen.
    2. Generate available after generating recipe. This allows you to subsequently specify that, say 50% of the time, you merge all the keys (ingredients) of recipe into whatever you got from INGREDIENTS.choose_multiple before collecting to a dictionary. I don't know if this is convenient in Rust, but it was easy to do in C#.

    So far the chance of not getting a 0 is 4-5%; I think you should at least incorporate the first approach since most translations do it and it helps even the odds a bit.

  • Custom User Avatar

    Done and done. Pass by value makes it easier for the consumer, but by reference is the better api decision, and at this kata level they can handle it.

    Ingredient diversity and count have been reduced for random tests. It's still likely to be mostly 0s, but before there was a decent chance they'd all be 0s. A more nuanced approach would be possible, but require complexity beyond what I think is necessary.

  • Custom User Avatar
    • Missing assertion messages
    • I'd suggest passing references instead of owned values to the solution function. They only need to be read-only, after all. At the very least this saves you a clone().
    • Have you checked how many random tests produce recipes that can't be baked even once due to missing ingredients? Not that this makes a functional difference, but having a statistically large portion of the tests require the same result (0) would be kinda boring.
  • Custom User Avatar

    Should be const instead of static. Variables should be SCREAMING_SNAKE_CASE.

  • Custom User Avatar

    I agree. I believe my solution has the correct behavior, but it's hard to say without proper testing.

    There might also be an edge case where it's important to prioritize bloodied enemies, but I couldn't find one.

  • Custom User Avatar

    Rejected because no answer to requests for more than one year. I think this is not approvable as is. It's always possible to create a new fork and make the required changes.

  • Custom User Avatar

    Needs edge case [1, 1, 2, 2, 4]. This should expect 2 (kill 2 wolves with melee and shoot the farther wolf once, for 2 turns), but every solution, including author solution, expects 3.

    Well, except one solution, but this solution has incorrect handling, and fails at [2, 2].

  • Custom User Avatar

    The fixed tests are too weak: there are at least several solutions with incorrect checking and still passes. There is one hard-coding solution, and one solution that fails at [2, 2].

  • Custom User Avatar

    Random tests almost always has an expected value of max(distances) - 3.

  • Custom User Avatar

    Please fix mispelling in description too. Also update to the latest version.

  • Default User Avatar
  • Loading more items...