6 kyu

Plus - minus - plus - plus - ... - Sum

105 of 298kdmatrosov
Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • beginnerxo Avatar

    What is goal? It one of the inputs. Any help?

  • dfhwze Avatar

    Any performance constraints? Permutations time out.

    • oliverboehme Avatar

      My solution times out against the random tests too every time (Kotlin). On my computer even for very long arrays it completes in under 1 second :(

  • TonyD Avatar

    Great kata, thanks!

    I struggled for a second with the edge case when my script found a solution that used the first number in array as a negative, resulting in a false positive answer. It does say "between" numbers in the description, but I think it's best if you emphasize it a little more suggestions:

    1. make "between" bold in the description
    2. add short explanation in brackets saying "first number should always be positive"

    At least for me that was not obvious

  • Fluw Avatar
  • Coderdood Avatar

    Maybe it's me but I find the task description quite confusing. Judging by the conversation here you can alternate signs other than + followed by - then followed by + and so on... The description and examples give another idea.

  • user6793616 Avatar

    If the submitted solution mutates the input array, the tests become unreliable. To solve this, the tests should first determine the correct answer and only then call the user's function. Or, alternatively, a copy of the array should be passed to the function so that any mutation is harmless for the verification.

  • JohanWiltink Avatar
  • JohanWiltink Avatar

    This comment has been hidden.

    • kdmatrosov Avatar

      This comment has been hidden.

    • JohanWiltink Avatar

      No, use it to check the random tests. That's what I call the reference solution; the Complete Solution I call the example solution. The example solution is your solution for the kata, which is visible to everyone after submitting; the reference solution is hidden away in the tests ( you can see it, but you have to go looking ).

      DFS stand for Depth First Search. ( There is also Breadth First Search, which generally finds the ( or a ) first shortest solution. )

      A BFS search would be "make the sum with as few as possible -s". ( Hey, that's not a bad idea! :)

    • kdmatrosov Avatar

      Done. Your code now is oin random tests. Thanks

      Suggestion marked resolved by kdmatrosov 7 years ago
  • JohanWiltink Avatar

    Example Tests:

    Test.assertEquals(getSolution([1, 3, 4, 6, 8], -2), true);
    Test.assertEquals(getSolution([15, 25, 30], 10), true);
    Test.assertEquals(getSolution([1, 5, 3, 2, 5], -2), false);
    

    Why is + 1 + 5 + 3 - 2 - 5 not a solution?

    Also, 25 and 30 seem too big.

    • kdmatrosov Avatar

      Why is + 1 + 5 + 3 - 2 - 5 not a solution?

      Due to the task we must put signs between numbers.

      If we define sign for every number then it will be another task with new array of solutions

      Also, 25 and 30 seem too big.

      I didnt understand( Why big? In which cases are they big?

    • JohanWiltink Avatar

      Oh wait, that's 2, not -2. Sorry.

      25 and 30 are too big for the description.

      0 <= xi <= 20

    • kdmatrosov Avatar

      Tests were fixed

      Question marked resolved by kdmatrosov 7 years ago
    • JohanWiltink Avatar

      I may have copied them over for the Haskell translation. :O

      I'll fix that if and when you approve it.

    • JohanWiltink Avatar

      Oh, you already did that! Thanks.

      I fixed the JS initial code; return value should not be a String but a Boolean.

  • ZED.CWT Avatar

    parseSolution does not actually test if exactly provided numbers are all used and concated using only +/-. Or you can change it to

    If there are solutions then return the sum
    

    since there are No Solution tests to judge if the users' solution actually complete the job.

    Or.. just change to true and false...

    • kdmatrosov Avatar

      Thanks for feedback

      1. removed parseSolution
      2. changed expected result to true and false
      3. updated description

      You code was broken. Sorry

      Issue marked resolved by kdmatrosov 7 years ago