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.
fixed JS test cases... it was caused by a global variables in author solution.
js version resolved
resolved
How many more comments must be made before the author or a codewars mod sees to fixing this.
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.
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.
Bump. Someone please fix the random test cases.
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.
sure. ;)
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.
you sure...?
being greedy, you wont output the best result
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.
For your case I can get 48 from my code, but I am pretty sure this Kata has some issues or the description is misleading.
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