Ad
  • Custom User Avatar

    I added more specification for that rule, Also glad to hear that some coders go to gym!

  • Custom User Avatar

    Definitely correct, see also my more detailed comment above, I only figured this out from garik's comment.
    Including the lightest plate is fine (like your example here with 23kg) but the rules and description don't say anything about 2nd lightest etc.

  • Custom User Avatar

    Update: I figured out from garik322's comment below what is wanted and have now got passing code.
    Rule 5 definitely doesn't make it clear that you want smallest, then second smallest, then 3rd smallest etc.

    I'd suggest a rewrite of rule 5, and split into two rules
    5. Solution should use the least number of weights
    6. If multiple solutions with the least number of weights choose the one with the lightest weight included, if multiple with the lightest weight choose between them based on the second lightest weight, then third lightest and so on until one remains

    Other than that, great kata, thanks! though you did earn me some funny looks at the gym this morning when i tried loading my bar up in this way haha

  • Custom User Avatar

    I think there is an error with some random test cases (in Javascript), ambiguous circumstances where it's not possible to decide between the solution expected and an alternative.
    I'm getting this on 8 of the random tests, have broken out one example in detail below, with the others being similar. Apparently ambiguous with 2 correct answers.
    Let me know if I've missed something here?

    See the code below, I put in a console log for the target weight and weights available for reference.
    Can't see how my answer is either better or worse than the expected answer given the rules

    1. Equal amount of plates each side: yes for both
    2. 2 hyphen gap from end: yes in both
    3. Each plate avilable once: yes used only one
    4. Weight dist matters... : yes heaviest on right then left etc.
    5. If multiple solutions choose the one with least number of plates and the least heavy plate: my solution and expected both include the lightest weight (18kg), and both have the least number of plates (4).
    6. plates shouldn't cross middle: yes, neither crosses middle.

    expected '--|42kg||18kg|------------|27kg||83kg|--' to deeply equal '--|52kg||18kg|------------|21kg||79kg|--'

    Target >> 178
    Weights >> [
    '|79kg|', '|21kg|',
    '|52kg|', '|50kg|',
    '|124kg|', '|42kg|',
    '|57kg|', '|79kg|',
    '|83kg|', '|118kg|',
    '|31kg|', '|18kg|',
    '|43kg|', '|65kg|',
    '|27kg|', '|21kg|',
    '|113kg|'
    ]

  • Custom User Avatar

    Loved this kata, a fun hour of work, thanks!

  • Custom User Avatar
  • Custom User Avatar

    Thanks!

    I'll give it some thought and refactor ... just wanted to confirm it was possible before I bumped my head against the wall for nothing

  • Custom User Avatar

    Yes, the kata can be solved in JS, my solution takes ~4s to run all tests. This kata has performance requirements, you need a better approach than your current one. Your current idea is simply not efficient enough.

  • Custom User Avatar

    I've got a javascript solution that works perfectly for accuracy ... but times out on the largest test, can't seem to figure anyone way to make it run more quickly given the need for recursion and iteration.

    Possibly because javascript is too slow when compared to C to actually calc for the huge array in sub 12 seconds - anyone actually made it work for JS recently?