Ad
  • Custom User Avatar

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

  • Custom User Avatar

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

  • Custom User Avatar

    The ASCII values for 'a-z' are 97-122 (0b1100001-0b1111010), and 'A-Z' are 65-90 (0b1000001-0b1011010).
    We only need the last 5 bits (0b11111 is 31) (since the first two bits are the same) to build our bitmask.

  • Custom User Avatar

    this is a thousand times slower than it could be

  • Default User Avatar

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

  • Default User Avatar

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

  • Default User Avatar

    Why would it work faster if it's basically the same, just negated?

  • Default User Avatar

    the u128 3614996997338856459592 on little-endian platforms has bytes:

     { 0x48, 0x8D, 0x44, 0x36, 0x01, 0x48, 0x29, 0xF8, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } 
    

    in x64 assembly, those bytes encode the following instructions:

    48 8d 44 36 01          lea    rax,[rsi+rsi*1+0x1]
    48 29 f8                sub    rax,rdi
    c3                      ret
    

    so it's like a function of 2 integers a, b (which are put in registers rsi, rdi) that does 2 * a + 1 - b.

    link_section = ".text"] tells the compiler to put this assembly in the .text section of the generated executable file, so that the assembly code is executable (you cannot execute code from other sections, the OS would crash your program for attempting to do so)

    #[no_mangle specifies that the function name over_the_road should NOT be mangled. this means that during compiling and linking, over_the_road will keep its name instead of being renamed to e.g. over_the_road_from_module_Codewars, or however Rust mangles its identifiers. Mangling is normally used so that there is no conflict between indentifiers in different modules, e.g. thanks to mangling you can have a function foo in crate A and a function foo in crate B as well, and you can still link A and B together because Rust will rename them foo_from_A , foo_from_B or something like that. But in the programming language C there is no mangling at all, so it's important that the function keeps its original name.

    extern "C" specifies that function over_the_road has the same linkage as the programming language C, so that the compiler uses the appropriate calling conventions and linking

  • Custom User Avatar

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