Coding Games and Programming Challenges to Code Better
Send your feedback or ask for help here!
Created by @Tatur2000,validated by @Razovsky,@Diabetos and @sammck.
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 @Tatur2000,validated by @Razovsky,@Diabetos and @sammck.
If you have any issues, feel free to ping them.
Passed all tests, can’t pass validator 2 and 5. I use cm per seconds, so when water’s level get to (h-level) I get time needed to fill bath, then translate seconds to hours and minutes.
Types of variables are double (C++).
Have done by another method: counted time in depends of baths volume devided on filliing volume till leaks point.
Passed all tests, but didn’t pass validator 3
Hello, great problem so far! I had the same first approach as @Oliverri , very inefficient, I got performance issues on the last test. This made me rethink the problem and I found a much more elegant solution. I think its pretty much the same as Oliverri’s second method actually.
I pass all the tests but not the first validator, and I don’t get why. Do you have some hints? Thanks!
EDIT: oh, I think I got something. Now I’m computing minutes and deducing seconds and hours from it, for test 2 I get 17.40926 minutes, so 17 minutes and 0.40926 * 60 = 24.5556 seconds. I round to 25 but the expected answer is 24. Why is that? Am I losing precision somewhere?
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