Ad
  • Custom User Avatar
  • Custom User Avatar

    Uses a lazy collection to filter and sum the multiples. This is memory efficient because it doesn't create an intermediate array.

  • Custom User Avatar

    A bit late, but you can use something like a std::sync::atomic::AtomicU16 or just a static 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.

  • Default User Avatar

    In Rust, there is a distinction between to_ascii_lowercase and to_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

  • Custom User Avatar

    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.

  • Custom User Avatar

    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.

  • Custom User Avatar

    What if i wanna return the same input?

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    @p7r But it's also more optimized. O(n) vs. O(n^2).

  • Custom User Avatar

    How do you even think of this?

  • Custom User Avatar
  • Default User Avatar

    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.