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.
Rust tests need to verify return type, otherwise my solution works (return
Cheat
type, which equals everything).This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
I updated the Rust tests, removing all cases where
b <= a
. The previously enforced behavior was unintuitive.Other languages do not test
b < a
either, as the behavior is not specified in the description.Good work! One small oddity: for inputs like "-0", the function cannot return "-0/1"; it must remove the negative sign. I'm not sure if that was intended. You might want to clarify in the description, or allow "-0/1", or completely remove any test cases with "-0".
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
@JohanWiltink:
The description was misleading, I clarified it. The intention of "Tests use large m," was to test high values in m, not a large set size.
I specifically included large values in m, because they can cause overflow problems. My first naive Rust solution panicked on large m values.
Testing large m set size does not seem necessary.
My intention is to allow any O(n) solution, and deny the naive solution which repeatedly scans further and further back into the sequence. Balancing the correct amount of tests to achieve this can be difficult, especially when execution time varies based on server load and language version.
the slice index must be usize, not i32
https://doc.rust-lang.org/std/slice/trait.SliceIndex.html
Should remove the test case for (4, 1), since a divisor is guaranteed to exist.
You need
chars()
to safely iterate UTF characters of astr
. Strings are always UTF-8 encoded, so accessing the bytes directly would be problematic. Thecollect()
at the end consumes theIterator
into aString
.For better functional composition, a more flexible signature would be:
This way you could pass any iterable into the function (including
str.chars()
), and chain the function lazily, without allocating a String for output.Loading more items...