7 - The Bell Curve

Back to Topic List

aszaloki     2024-08-29 19:22:13

Hi Kevin,

may i suggest (and rather ask you to) to make the checker a little bit more permessive? My solution always has a few results which differs from the expected value in the sixth decimal place. My solution calculates the density function values and the trapezoid rule (with 50.000 subregion to make it more precise) in order to obtain the specific area under the curve instead of using a lookup table.

I think if someone implements the solution correctly and only the accuracy is problematic in this level (I mean 1e-6) it might make him a little bit nervous :)

Thanks in advance and If you insist on this accuracy I will understand :)

admin (Kevin)     2024-08-29 21:13:19
User avatar

Hi Adam!

The current PHP "checker" code for that problem also uses the trapezoid rule to calculate the answer! It dynamically updates the quantity of subdivisions required in order to ensure that the answers are accurate to 1e-6 for each testcase, although they usually require many less than what you are using in your solution so while I'm not fluent in C#, it looks like you should be getting an accurate answer...

Instead, I'm wondering if the issue could be with rounding... PHP uses "round half up" in which a decimal ending in .5 will be rounded upwards always (so 1.5 -> 2, and 2.5 -> 3). However C# uses "round half to even" in which a decimal ending in .5 will be rounded instead to the nearest even integer (so 1.5 -> 2, and 2.5 -> 2). Maybe this is causing the occasional inaccuracy in the final decimal point?

Luckily the PHP checker code allows you to submit "unrounded" answers, and will double-check server-side if they would be accurate enough after rounding. Maybe try not rounding your answers before submitting them, and see if that might fix things?

I don't want to dismiss the possibility that the checker code isn't accurate enough though, so if you keep seeing the issue let me know of a specific testcase you saw an issue on and I can try to confirm what's going on. Quite a few languages have built-in functions to directly compute these exact equations with high precision, but unfortunately neither PHP nor C# are among those languages :)

admin (Kevin)     2024-08-29 21:41:25
User avatar

I should correct myself - when negative numbers are involved it's not always clear which way "half up" is... The default PHP rounding mode is "half away from zero", so -2.5 -> -3. In a "half towards even" mode, -2.5 -> -2.

aszaloki     2024-08-30 07:49:01

Hi Kevin!

Thank you for the quick response. I am quite sure that the mode of rounding causes the minor differences in the resulting values. I have tried not rounding my results, unfortunately the checker does not accept it. Could you please check that the checker really allows to submit unrounded anwers? Because one of the problem (i do not remember which one) I solved here did not accept my unrounded results either and I had to round to the expected decimal places. Maybe the situation is the same for this problem too.

Anyway if you confirm that the checker accepts unrounded results I am not going to investigate my solution further, I will consider it as it is correct :D

admin (Kevin)     2024-08-30 16:01:59
User avatar

Hi Adam!

I went through a few things and did find a couple issues server-side. I aplogize for before thinking that the issue was with your code...

There was some confusion on my part regarding how the "decimal comparison" feature worked, and so you are correct that many answers would have been required to be rounded to the nearest 1e-6. That should be fixed now and things should be working as intended - any submitted answer with with error less than 1e-6 deviation from the calculated answer will now be accepted, regardless of trailing decimals. I also updated the wording in the problems to be more explicit (since "accurate to x" is rather ambiguous), and made sure that they are being checker to the accuracy they request.

I do appreciate you troubleshooting these issues - thanks!!

aszaloki     2024-08-30 16:09:03

Hi Kevin,

When I run into such a problem I always think that the issue is with my code :))) No problem, we are human and sometimes make mistakes, that is so natural. Thank you for your time and the fixes, now my solution has been accepted.

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