6 kyu
Plus - minus - plus - plus - ... - Sum
105 of 298kdmatrosov
Loading description...
Algorithms
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
What is goal? It one of the inputs. Any help?
goal
is the target sum.Any performance constraints? Permutations time out.
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 :(
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:
At least for me that was not obvious
Python Translation
approved by
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.
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.
Added array copy
Kata approved ;)
Haskell translation
Approved
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
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! :)Done. Your code now is oin random tests. Thanks
Example Tests:
Why is
+ 1 + 5 + 3 - 2 - 5
not a solution?Also,
25
and30
seem too big.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 solutionsI didnt understand( Why big? In which cases are they big?
Oh wait, that's
2
, not-2
. Sorry.25
and30
are too big for the description.Tests were fixed
I may have copied them over for the Haskell translation. :O
I'll fix that if and when you approve it.
Oh, you already did that! Thanks.
I fixed the JS initial code; return value should not be a
String
but aBoolean
.parseSolution
does not actually test if exactly provided numbers are all used and concated using only+/-
. Or you can change it tosince there are
No Solution
tests to judge if the users' solution actually complete the job.Or.. just change to
true
andfalse
...Thanks for feedback
parseSolution
true
andfalse
You code was broken. Sorry