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.
cheater
you play with aim here
i just ran this code in chat gpt and it call it old style python =) sounds funny
"""is a list comprehension that formats each line from the lines list into a numbered string using the old-style Python string formatting (% operator). Let’s break it down step by step.© """ chatGPT
Had no idea this could get solved like this, thanks for the trick. Took me time to wrap my head around it and hopefully i get to use it in the future with problems that needs intricate solving!
thanks, I didn't know you could start the counting at an arbitrary number in enumerate.
This comment is hidden because it contains spoiler information about the solution
Smart usage of formatting
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()
.Yup. Forgot that
%
operator formatting detail myself that it accepts tuples.What does the % v specifically the % ...? Thanks !
This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Learned string formatting! Thanks :)
he need change the value of ret
the return must be a pointer to a (free-able) dynamically allocated string
This comment is hidden because it contains spoiler information about the solution
Loading more items...