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.
When your C/C++ program behaves differently when you add/remove printing statements, it almost certainly means that it contains undefined behavior. I put your code in a static analyzer and it turns out that it contains undefined behavior when called with negative numbers.
Here is the culprit line:
In C/C++, the bitshift operators
<<
and>>
are only well defined when0 <= shift < width of the type being shifted
, with the width defined assizeof(type) * 8
, i.e. the number of bits in the type. Using these operators with a shift outside of this range is undefined behavior, and this happens in your code for negative numbers, the shift will be around260
.(Also,
*(unsigned int *)&f
violates the rules of a well-behaved C/C++ program. If you want to reinterpret the bits of a type into another type, you are supposed to usestd::memcpy()
/std::bit_cast()
since C++20).This comment is hidden because it contains spoiler information about the solution
Ruby 3.0 enabled in this fork
O(2*n)
doesn't exist, constants are disregarded.O(n)?
it's O(2*n)
The requirement to give the output in a weirdly formatted string is ridiculous. I have one failed test where the answer only differs by trailing zeros... Basically my code works, but can't be validated:
Test Failed
Expected (max. 6 decimal places necessary): SOLUTION=(-6.000000; 6.500000; -2.875000)
But got: SOLUTION=(-6.0; 6.50; -2.8750)
So checked: SOLUTION=(-6.0; 6.50; -2.8750)
Really??
What an awful description. It simply doesnt tell the case swapping rules in the top part. Also you could shorten the description by half at least.
You could narrow it down to: "Each character case in string A should be changed N times, where N is the number of times the same character occured in the string B, regardless of its case."
I also solved this problem by using the split method to make it more easy for me for solving
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions
I think so too
I've been trying to do it for about a year) I've done it. Many thanks for this amazing kata!)
This is irrelevent, as the kata only concerns itself with arrays that are expected to always have exactly one unique element.
try [1,1,1,2,2] :( will not work correctly to find a unique number because the array does not have a single unique element; it contains two numbers that each appear multiple times.
Loading more items...