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.
Updated the test organization, imported codewars_test instead of implicitly (which was deprecated since Python 3.8), and added assertions for only using digits and "()-=/" and 3 operators to the random tests.
Does this apply to translations too? (can I use integers?)
Right now the open C++ translation uses floats, and the Python random tests use a less-than-epsilon type comparison for supporting float imprecision. If it's really not supposed to use intermediate floats, shouldn't it use the // operator in Python instead of the float / operator?
This comment is hidden because it contains spoiler information about the solution
There we go, I switched it to give the expected length as an argument so it's as easy as other languages while still allowing bounds checking if you want.
Good point with the
static
!aligned_alloc
should allow the memory allocator to choose not to align it on the maximum struct alignment but instead a multiple of the alignment you specify. I had specified 1 because a char* string is made of bytes, but I'm pretty sure an alignment 4 or 8 would be easier for optimized library string handling functions to deal with.I removed the preallocation instead.
A mix of both options would be to pass the expected length as a second parameter, so that the user doesn't need to calculate it themselves.
Looks good to me!
a minor change might be to switch from mapM_ to forM_ so that the list isn't at the end of the line, and it would also let you avoid those parentheses
QuickCheck is fine, but there are only 10 cases, so exhaustive testing is better than entirely random for this.
QuickCheck has a shuffle function of its own that you should probably use instead of an Arbitrary instance -- this would allow you to both ensure that all cases are tested and in a random order to prevent order-sensitive code from working.
Fixed it by matching on the character values (like c >= '0' && c <= '9')
it's usual to say both the user's answer and the expected result
Otherwise it looks good!
why did you use "strin" instead of "str" or "string"?
i suggest using the whole word 'string' when it's reasonable
more importantly, why do the tests repeat so much code? you should write a function, macro, or template so it's easier to read and maintain
All I can think of is that sometimes people call 0 "Zed" instead; it's more common outside the US.
Solved with a wrapper function
Random tests added in C, C++, Java, and JavaScript.
the indentation for the normal test cases is inconsistent
Also, you don't need to change it but can I suggest a solution based on fenwick trees for the random test solution? The code ends up being simpler, but I haven't checked if it's faster
How is this kata possible?
From what I understand neither 2 nor 0 will work for any integer base...
0: ""_1, 0_2, 0_3, 0_4, ...
2: 00_1, 10_2, 2_3, 2_4, ...
Loading more items...