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.
This comment is hidden because it contains spoiler information about the solution
lol
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
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.
this is a thousand times slower than it could be
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Why would it work faster if it's basically the same, just negated?
the u128
3614996997338856459592
on little-endian platforms has bytes:in x64 assembly, those bytes encode the following instructions:
so it's like a function of 2 integers
a
,b
(which are put in registersrsi
,rdi
) that does2 * 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 nameover_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 functionfoo
in crateA
and a functionfoo
in crateB
as well, and you can still linkA
andB
together because Rust will rename themfoo_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 functionover_the_road
has the same linkage as the programming language C, so that the compiler uses the appropriate calling conventions and linkingThis comment is hidden because it contains spoiler information about the solution