Description says that result should be rounded down so 24.5556 should be displayed as 24 seconds
Hello Yatech, thanks for noticing. Okay, so rounding down is the same as truncating the floating part, which is what I’ve done before coming to this post: when truncating, I pass all the tests but not the first validator and I don’t quite get why…
It looks like I’m missing a whole second, because if I submit a code that adds 1 second to my existing code, the first validator passes.
Most likely it’s the problem with precision. Try using double instead of float
For validator 1 the total minutes have decimal part .333333333333336.
If the type you are using is not precise enough this will turn into 19 seconds instead of 20.
Thanks for the insight, that was a precision issue indeed
However I didn’t have to use double instead of float, because such a piece of code:
float m = 0.333333333333336f;
int s = (int)((m - (int)m) * 60);
Console.WriteLine(s);
Returns the expected result (20).
So instead, I used a comparison like this:
int seconds = (int)((minutes - (int)minutes) * 60);
float secondsF = (minutes - (int)minutes) * 60;
if (Math.Abs(secondsF - (float)(seconds + 1)) < 0.001f)
{
seconds++;
}
Seems to do the trick. Let me know if you have a better solution because it still feels wonky…
Anyway, thanks again!
My C# code is published if you want ot take a look.
I just used double and formatted the answer using TimeSpan.
Hi,
I passed all the initial tests but validator 3 i locked.
would anyone knows its difference versus the tests?
May I’d need its input to debug.
I’ll PM you.
Hi 5DN1L,
Any news on this ?
I should ask you the same question because I sent you a private message 23 hours ago
i am stuck on test validator 5
instead of 88h… i found 33h…
my code pass the other test case
any ideas ?
You may try printing intermediate variables in your calculation and check where it goes wrong.
By the way, that’s Test 5, not Validator 5, they’re different things.
All tests passing, but validator 3 is not passing. I have done it with Python, I have sliced my bath using the heights, I have a duration for every slice, and I thought it can work.
Hey all, I’m doing it in Javascript and the validator 3 doesn’t pass. After googling about it it seems like the thing considers I’m hacking that solution only, but I don’t see how it would pick this up. I don’t think it’s cool to paste code here but I’m not sure how to pass that validator at this point. Can anyone help?
You may send me your code by private message if you want, and I can take a look.
The following custom cases may help those who fail Validator 3 to debug:
(1)
Input:
10700
125
36
15
124 2
11 3
76 1
32 4
83 1
115 5
32 4
50 2
31 2
40 5
14 2
92 2
42 4
47 5
70 1
Output:
Impossible, 92 cm.
(2)
Input:
11200
109
37
15
32 5
60 1
100 4
36 3
25 6
104 4
69 6
33 2
47 2
55 5
6 4
10 4
32 1
62 4
79 6
Output:
Impossible, 62 cm.
Thanks!
Your 1st custom case helped me fixing my code.
I was checking the time to height, instead I should have checked for the current flow
Hello, any hints on validator #4, please? I pass all tests and other validators but fail this one. Tried playing around with precision and edge cases without success.
Great puzzle overall but would really benefit from having more test cases, it’s not a good sign when multiple people report passing all tests and failing validators.
Do the custom cases here help you? If not, you may send me your code in private message and I’ll try to come up with a custom case for you.
Ugh.
non-integer math.
Although, it can be done in integers if your GCDs and LCMs are up to speed!
Use fractions, it’s integer maths.