Ad
  • Custom User Avatar
  • Custom User Avatar

    I keep doing the same thing if the first thing I would do would be to make an exact copy. The thing is the argument passed by value is just your local copy and you can do whathever you want with it without having it an effect for the caller. For the caller it matters little whether you take const & and do a copy explicitly or take argument by value. No changes are visible outside of a function.

  • Custom User Avatar

    On x86_64 Linux (this case I presume) size_t is usually typedef for unsigned long. So sizeof(size_t) will be 8 and sizeof(int) will be 4. With size_t you need store how big something is in memory, so it's unlikely be shorter than int anywhere, but it's still wasting memory. At least half of that diffArr array is always empty. That cast from malloc is not needed in C either as (void *) is implicitly converted to any kind of pointer (Unlike in C++).

  • Custom User Avatar

    Thanks for the Kata! It brings back memories. I haven't seen Pascal for like 18 years. :-)

  • Custom User Avatar

    I'm absolutely unable to pass random tests for D. It tells me for example:

    Because text = "hHk7HB1sv1Bzh4tSDrwCvyqfJNvDPgdJ", duplicateCount(text) should equal 6. 7 is not equal to 6.
    

    But no matter how am I counting I'm unable to find a mistake. I'm looking for duplicate case-insensitive alphanumeric characters. What am I missing?

      1 1 1
      2 B B
      3 d D D
      4 h h H H
      5 J J
      6 s S
      7 v v v
    
    hHk7HB1sv1Bzh4tSDrwCvyqfJNvDPgdJ
    ^^  ^^^^^^^ ^  ^^   ^   ^ ^^  ^^  
    44  4216712 4  63   7   5 73  35  
    
  • Custom User Avatar

    When it comes to D version, it seems to me, that the sample tests are missing two imports import solution : findShort; and import std.string : format;. Main tests are fine.

  • Custom User Avatar

    Clever it might be. But you better be sure that p1 and p2 can never point to the same memory location before even thinking about this.

  • Custom User Avatar

    I think you have 2 typos in the description on the line: f(x) = (key_a * x + key_i) mad m. It should read f(x) = (key_a * x + key_b) mod m. mod instead of mad and key_b instead of key_i.

  • Custom User Avatar

    I'm proposing 3 minor changes to C++ version

    • Fixing broken sample test cases
    • passing std::string by const & instead of by value to the function itself
    • some whitespace fixes

    Please reaview and/or approve.

  • Custom User Avatar

    Rust translation. Please, review and approve.

  • Custom User Avatar

    Nice! I didn't know about std::clamp.

  • Custom User Avatar

    No reason. It was just the first thing that came to my mind when I was writing it. Subscript notation would be shorter for sure.

  • Custom User Avatar

    You are right. I don't know what I was thinking. :-)

  • Custom User Avatar

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

  • Custom User Avatar

    I don't think this is standard C++ (ranges in switch case). Originally GCC extension, perhaps Clang has it these days as well. But don't be surprise if your compiler doesn't support it.