Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
After some investigation and re-reading what g964 was getting at - I've learned the solution is correct and consistent. Previously I was using format but on a cast, not leveraging actual formatted display of floats. (I knew I was doing something foolish)
For those stuck on this, scratching their heads - I would encourage you to read up on this:
https://users.rust-lang.org/t/formatting-floats-and-rounding/10235
Thank you for the kata, I learned something new.
I am still confused, inspite of your thorough description.
One of the basic tests is as follows; the raw sell value is 6407.6, but 6408 is expected?
This lead me to round, in spite of the instructions. Afterwhich I was met with this random test:
These values seem to be rounded (inconsistently) as well, not trucated.
Perhaps (most likely), I'm doing something foolish here. Any insight would be appreciated, as I've attempted format! and write! as well as rounding to no avail.
Thank you.
I like this because it does integer division, not float division.
Anyway, it should have been
std::span
if C++20 was available here.That's fair - I didn't even notice the const& - but you can also move into it when it's by value, not just copy. You can't move with this signature (and thus you are forced to do a heap allocation). And I would think that we should stick with the signature that is given.
Other solutions copy the whole input vector by accepting it by value, this one doesn't.
Other solutions reuse the parameter vector instead of creating a new one, avoiding a heap allocation. It seems like this shouldn't be at the top.
Considering the return type is
unsigned int
, you should use anunsigned int
for the running sum, as it (normally) has a greater range of values thanint
. And signed integer overflow is undefined behavior. Unsigned integer overflow isn't - you could safely overflow and underflow and still arrive at the correct answer as long as it fits inunsigned int
.m_actualTimeUs
can still overflow, leading to incorrect behavior. Granted, it would take over 500,000 years for it to happen...The problem statement asks for an O(1) space solution, but this is O(n).
I am not the Rust translator but I have fixed it. Thanks!
In Rust, the random tests may have any of
g
,v1
andv2
equal to 0.It's not a big deal, but it is not consistent with what is said in the instructions.
Good idea, done in all translations. Thanks!
I agree, kata with double or float are often tricky since different languages can have different ways of formatting. I can be wrong but I think part of the fun is finding your way to a solution that is accepted by the tests.
Moreover in this kata many people have problems with the placement of white spaces all the more that CW output compresses many spaces into one.
In my previous post I answered about Rust but as far as I know all 24 translations (there are several translators) give the same results with fixed tests.
Anyway thank for your post.
This can still be a little bit tricky, because
I am not taking any position here and I am not fighting for any specific approach, I just want to show that there can, and will, be some some problems whatever you decide :)
What you can do, is to add such test case to sample tests. It will help to verify the solution early.
Loading more items...