Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with "Bonfire: Pairwise". Test wrong? #3375

Closed
soulchainer opened this issue Sep 20, 2015 · 7 comments
Closed

Issue with "Bonfire: Pairwise". Test wrong? #3375

soulchainer opened this issue Sep 20, 2015 · 7 comments

Comments

@soulchainer
Copy link

I was going to do this bonfire, and, after a time thinking about how to do it, I noticed this test:

expect(pairwise([0, 0, 0, 0, 1, 1], 1)).to.equal(10);
expected 1 to equal 10

That's arr[0] + arr[4] = 0+4 = 4
And arr[1] + arr[5] = 1 + 5 = 6
6 + 4 = 10

These are [0,1] pairs, repeated.

Well, the explanation of this bonfire says this:

Bla bla bla
If multiple sums are possible, return the smallest sum. Once an element has been used, it cannot be reused to pair with another.

So, if you get the same pair, Only use the smallest sum of indexes, right?
This test breaks this condition. With this, I don't know if even I can trust in the exercise description. I don't know if the exercise is wrong, if the description is misleading or if only the test is wrong, but something seems to be wrong.

@natac13
Copy link
Contributor

natac13 commented Sep 20, 2015

I believe I see what you are saying... where the first and 4th test are expecting the sum of all the indices that can be paired to add to the 2 param. But if the description say to only return the smallest sum then test one expect(pairwise([1, 4, 2, 3, 0, 5], 7)).to.equal(11) should equal 4 (from the 4 and 3 being added) and the 4th test (the one you mentioned) should be 4?

@soulchainer
Copy link
Author

No, @natac13 , because these aren't repeated pairs. I mean, in the test I said, they get the pairs:
[0, 1] and [0, 1]. It's the same sum. So, you are supposed to only keep the smallest one sum of indexes for that specific combination of numbers that sums 1.
In case of test first, it's OK, because you have:
[4, 3], [2, 5] that have indexes 1 + 2 + 3 + 5 that equals to 11. That's fine. The case I mentioned, I believed not.

@natac13
Copy link
Contributor

natac13 commented Sep 20, 2015

Fair enough I am just going of the if there are multiple sums then return the smallest sum... so because there are two different sum that equal 7 for the first test I though it should only return the sum of [4, 3] being index 1 + 3 to equal 4... I apologize for misunderstanding your inquire

@richchurcher
Copy link
Contributor

@soulchainer I've often thought this exercise and its description caused more confusion than it was worth.

I believe the test is ok, though. It only says once an element has been used it can't be re-used... it doesn't say, once an integer has been used. It also asks for the sum of all indices that can be paired. The test provides multiple elements with the same value for the purpose of checking if the provided solution can detect the lowest possible combination. Possible answers include:

[0, 0, 0, 0, 1, 1]
Indices: 0 + 4, 1 + 5 = 10
Indices: 1 + 4, 2 + 5 = 12
Indices: 2 + 4, 3 + 5 = 14

So the test is required to ensure that the solution has correctly picked the lowest sum.

@soulchainer
Copy link
Author

Oh. I see. That makes sense, @richchurcher :).
Thanks. Description limits itself to the most simple cases and there you have no confusion, till you see the test cases.

@ltegman
Copy link
Member

ltegman commented Oct 15, 2015

Closing this issue as resolved. Feel free to follow up if you still have concerns with this bonfire.

Thanks and happy coding!

@diogogomeswww
Copy link

I don't understand.
The problem clearly says If multiple pairs are possible that have the same numeric elements but different indexes, return the smallest sum of indexes.

So for test case:
[0, 0, 0, 0, 1, 1] Indexes: [0,4], [1,5] Values: [0,1],[0,1]

The indexes 1+5 should be not included, hence the answer should be 0+4 = 4, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants