Coding Games and Programming Challenges to Code Better
Send your feedback or ask for help here!
Created by @Cakeisalie5,validated by @LeMasSon,@Mohamed_Kharrat and @Wontonimo.
If you have any issues, feel free to ping them.
Coding Games and Programming Challenges to Code Better
Send your feedback or ask for help here!
Created by @Cakeisalie5,validated by @LeMasSon,@Mohamed_Kharrat and @Wontonimo.
If you have any issues, feel free to ping them.
My code passes all exemple tests but fail at submission 3. I can’t find why.
If you want, you may send me your code in private message and I’ll take a look.
The following custom case may help those who fail Validator 3:
Input
04:19:40 UTC-09:49
Output
@631.02
Thank you very much 5DN1L I could find my error with your test case.
I’m interested in what error you identify using this test case, if you have the time to write a message on the contribution page for the puzzle, so that I can adapt the test cases to suit this ![]()
Validator 3 no longer fails on that mistake, but a new specific test/validator pair now exists for this case specifically. Thanks @5DN1L! ![]()
My code pass everything except validator 5, can’t pin down why
In Validator 5, the given time is close to midnight, and the given time zone is close to UTC (hours = 0, minutes ≠ 0). Try creating some custom cases like that to test your code.
thanks ! I got it with that hint !
The idea of the puzzle itself is interesting, but the part with a floating point, it is not clear what it is for, this is the result I got using Java, and if you do not understand what is happening and how to deal with it (and I spent a decent amount of time to figure it out) the puzzle may not be solved.
Console output
Standard Output Stream:
@501.87
Failure
Found:
@501.87
Expected:
@501.88
(Double)
501.87499999999994
(Float)
501.875
Maybe floating points are not the correct tool for the job, and you should choose types that allow you to have precise control over the rounding algorithm. I don’t know Java, but MathContext and BigDecimal seem to be that tool for the language ![]()
Thanks for the article, I read it all the way through — new knowledge is good. The problem here isn’t the algorithm, but how Java performs the calculations that result in a floating-point number.
If you execute a code below on an attached site or another place where you can execute java code you will get: 501.87 instead of expected 501.88. And in most cases you must use double(or of course you can use BigDecimal but you should know for sure why you should use this class) for work with floating-point numbers and keep in mind a such situation can occurs but you can not predict when and with which numbers it will happened.
System.out.printf("%s", new BigDecimal(43362).divide(new BigDecimal(86.4),2,RoundingMode.HALF_UP));