Bubble in Array input data clarification

Back to General discussions forum

sethwh     2019-05-07 19:27:36

According to the instructions: "Input data contain sequence of elements of the array, all positive"

However, input data contains 0s which is neither positive or negative. My logic to read and build an array by only appending values greater than zero failed. So once I figured it out, I changed to != -1 and all values came in.

Not a big deal. Just thought it might need to be clarified that zeros are contained in input data.

Thanks!

Rodion (admin)     2019-05-08 04:17:01
User avatar

Hello! And thanks for your message!

Well, this is really embarrassing. Positively, I don't know what is positive... :)

You are quite right, I wrote "all positive" in the text, but in the checker code I fill the array like this:

array_push($a, rand(0, pow(10, rand(1, 5))));

where rand(x, y) yields integers between x and y inclusive. Thus zero could appear, though one needs certain amount of luck to meet it...

So thanks a lot for the hint, let the adjective in the statement be changed to non-negative! Sorry for this bewilderment!

Quandray     2019-05-08 06:24:20
User avatar

I suggest that, if you write code to check that the input values are valid, don't just "ignore" values that your code thinks are invalid, output an error message. That will make it easier for you to debug your code.

sethwh     2019-05-08 16:29:56

Thank you, Rodion. And yes, I someohow got zeroes twice when I submitted :/ fail

Quandray Will do. Once I did a print(array) after building the array from the input data I knew my logic was flawed (when 0s present).

Please login and solve 5 problems to be able to post at forum