Ad
  • Default User Avatar

    How many more comments must be made before the author or a codewars mod sees to fixing this.

  • Default User Avatar

    It actually works because the ascii offset should be 96 but by adjusting it to 95 you are adding one additional point for each letter; thus tracking the length implicitly via ascii value.

  • Default User Avatar

    You hard coded the answer to one of the permanent test cases into your result. Not really okay. Sorting on two properties in JS is easily googled.

  • Default User Avatar

    Bump. Someone please fix the random test cases.

  • Default User Avatar

    And I have now coded it with dynamic programming, and I can verify that 45 is the correct answer to this answer set. But alas, that doesn't solve the real issue.

  • Default User Avatar

    You're correct. Greedy only works for the Fractional Knapsack problem, and this is the 0-1 version. Thank you for the clarification, but that still doesn't justify the test cases asking for impossible answers lol.

  • Default User Avatar

    45 is gotton by taking the first 4 and the 6th, equaling a weight of 12

    To get 48 you would have to take the first 5 most valuable elements, but the corresponding weight would be 13 breaking the limit of 12.

    0: {val: 8, score: 8, weight: 1}
    1: {val: 5, score: 5, weight: 1}
    2: {val: 4.5, score: 9, weight: 2}
    3: {val: 3.2, score: 16, weight: 5}
    4: {val: 2.5, score: 10, weight: 4}
    5: {val: 2.3333333333333335, score: 7, weight: 3}
    6: {val: 2, score: 4, weight: 2}
    7: {val: 2, score: 4, weight: 2}
    8: {val: 1.8, score: 9, weight: 5}
    9: {val: 1.5, score: 3, weight: 2}
    10: {val: 1.25, score: 5, weight: 4}

    If you can show me what items you picked to get to 48 while still making the weight cap, I'll take it, but otherwise your code is doing something wrong.

    And regardless of that, the fact that neither one of us is coming up with 62 as the return value is the actual issue at hand, as that is what the test case is looking for.

  • Default User Avatar

    The Test harness for JS is seemingly broken, as it is generating expected values that aren't possible given the score/weight pairs; the comments below back this up and in particular one of my example cases was
    scores: [ 4, 10, 5, 9, 9, 7, 4, 3, 16, 5, 8 ]
    weights: [ 2, 4, 1, 5, 2, 3, 2, 2, 5, 4, 1 ]
    capacity: 12

    Expected: 62, but Highest I could get without breaking capacity by code & by hand was 45

    Marking this as an issue to hopefully highlight the below comments which reinforce the same notion that there is a problem here