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.
elegant
Uses a lazy collection to filter and sum the multiples. This is memory efficient because it doesn't create an intermediate array.
A bit late, but you can use something like a
std::sync::atomic::AtomicU16
or just astatic mut u16
as like a question counter, and then just return false when that counter hits a certain value.The only slight issue is that Rust tests are run in parallel, but I'm assuming only one of the test categories are timing out, so this should be fine.
In Rust, there is a distinction between
to_ascii_lowercase
andto_lowercase
.to_ascii_lowercase
is specifically designed for ASCII characters, while to_lowercase is used for Unicode characters.to_lowercase
function should be used for general case conversion of characters, including non-ASCII characters.This is due to the fact that Rust doesn't simplify for you the strings.
"hello world" has obviously 11 characters, but it is not always 8 bit each, hence, the necessity for different methods based on the type.
I'm studying rust, and maybe my explanation it is not 100% correct. The free microsoft course for Rust explains very well strings, but the rust doc go deep inside the problem: https://doc.rust-lang.org/std/primitive.char.html
Thanks for the suggestion! Unfortunately, this doesn't appear to work for me. I was previously writing to stderr unbuffered, but writing to stdout and flushing also appears to produce no output. (And to be clear, I'm writing the inputs out immediately upon the function call, not after doing any sort of processing.)
I suspect there isn't much I can do here.
I've passed all of the unit tests, but it appears that the random tests are timing out for me. AFAICT, there's no way to find out which specific test data is causing the timeout, right? I tried logging test cases to stderr, but it appears that when a test times out, Codewars just won't show the log for that test, unless I'm missing something. (When I explicitly fail a test, I do have the option to expand the log.)
Certainly a fault of my algorithm, but it's hard to know what to benchmark without having solid examples (which are otherwise difficult to generate by hand). I'd love to be able to time profile a known failing test, because I really enjoyed working on this kata and I'd love to complete it.
What if i wanna return the same input?
This comment is hidden because it contains spoiler information about the solution
@p7r But it's also more optimized. O(n) vs. O(n^2).
How do you even think of this?
clever one +1
Obviously this is quite elegant, but it's also not obvious to anybody who stumbles across it.
So clever, but in production code this feels like obfuscation.