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.
Expressive and elegant. And it compiles to just 4 instructions (for x64 and GCC at least).
This comment is hidden because it contains spoiler information about the solution
Well, if we're trying to learn how to efficiently solve actual day-to-day programmer problems, this is the best solution I'd imagine.
This comment is hidden because it contains spoiler information about the solution
For experienced C++ coders, is this a clear and easily grokable solution?
I learn new standard library methods by seeing other people's solutions WAY faster than reading by the references.
Is using using
t
better than simply using yourint i
?Nice! This is the fastest implementation based on my rough profile testing. Efficient!
This is a quite different language from C...
This comment is hidden because it contains spoiler information about the solution
Based on my understanding, it is a difference of stack variable vs heap variable.
char res[len + 1]
would make a local variable on the stack.There are two problems with this. 1) it is a local variable, so it can't be easily seen or used outside of the function. 2) it is on the stack, and the compiler needs to know ahead of time exactly how much space to put on the stack.
If you don't know ahead of time how much space you need, the variable must be allocated on the heap.
char *res = malloc(len + 1);
creates a space on the heap.Since we don't know ahead of time how long the input DNA sequence is going to be, the program will only work if you allocate it on the heap.
Also, the test suite that "uses" our code expects that we allocated on the heap, so it will try to
free()
.You don't need to check
== 1
because1
is alreadytrue
.This comment is hidden because it contains spoiler information about the solution
Nice doing the calculatuon with only 1 loop.
This was a fantastically fun kata to do--got to delve into the weeds of assembly, registers, and stack address calculations! I kept tripping over C statements that cobblered registers. This was a joy of a kata.
Loading more items...