Programming Questions

  • Newest
  • Popular Tags
  • Ask A Question
  • Something strange with Array Addition
    Hi, I just completed the "Array Addition I" problem there seems to be an error either with the problem description or the test cases. The problem states that the program should return true if any combination of the array numbers add up to the largest array number. The example it gives is explicit in that not all numbers must be taken into consideration for the addition. The example is {4,6,23,10,1,3} and it should return true because 4+6+10+3 = 23 and 23 is the largest number in the array. Notice that the number 1 was not used. So I did a recursive search through all possible combinations of additions. It took me 43 minutes for it to work. When I saw another user's code, it's clear that he just added the remaining numbers after removing the largest one. That should not pass the example test case. Yet apparently it passed all test cases. Either the example is wrong (and the description should be clarified), or the test cases don't include a case like the example, where not all numbers are used.
    jhandl posted this question on 9/1/14 | array, addition
    Answers
  • +
  • 0
  • -
  • I agree. Check the top 4-5 solution with this parameter: [4, -100, 3, 7]. That should return true, but several of the the top solutions return false.
  • +
  • 0
  • -
  • @mattlarsh Here's code that shouldn't work but does pass all the test cases: coderbyte.com/CodingArea/Questions/Q/?q=array-addition-is-my-solution-too-easy
  • +
  • 0
  • -
  • Actually, I can see how the first code passes the example case. It's either clever or lucky. :) If you include the following test case it should discriminate between this and a correct solution {5,6,23,10,1,3}.
  • +
  • 0
  • -
  • Sure, here’s one example: www.coderbyte.com/CodingArea/Results.php?ct=Array%20Addition%20I&user=Redmanter&lan=Java This code should have failed for two reasons: it adds all remaining numbers, failing the example case, and it returns true even if the sum exceeds the max value. Looking through other submissions I came across this one: www.coderbyte.com/CodingArea/Results.php?ct=Array%20Addition%20I&user=synapse123&lan=Java Note that it took 1 minute to write a non-trivial recursive function. This user clearly re-did the challenge and pasted the finished code. I'm sure everyone writes and tests the code on their own terminals or IDEs and then paste the finished code (this is necessary because the site does not provide compiler output) but I'm also sure (or hope) that most don't redo the challenges to cheat the time limit. One solution would be to disable the paste event, but this is not an option until compiler output is shown. Also, when looking at another user’s code tests cannot be run, it returns “Error: Main method not found in class Function, please define the main method as: public static void main(String[] args)” I really like the site and the idea, I hope you find the time to fix these problems! :)
  • +
  • 0
  • -
  • Can you give us the code that you think should not work?
    Log in to write an answer.