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.
Is this mathematically correct ? I don't think it will work for all integers..
For what purpose do you use dynamic memory allocation here?
I think that one of them is clearly wrong, to pass it I hardcoded the specific test case.
This killed the joy of seeing the K-Means algorithm decoding that last message.
If
str_in
is empty string thenstr_out[str_out_idx - 1]
is unallocated memoryupd: OMFG I did it! I fucking did it!!
So, after creating those posts I decided to take a break and went to read "The C Programming Language" by Kernighan & Ritchie and suddenly I got reminded that strlen() function reads through the whole string in order to find out it's length. That got me thinking: "Hmm... My program is actually using this function every time it has to translate a bit of BF code into C code... Hmm... AM I SURE, this is the right thing to do, concidering input size can reach up to a million characters? ABSOLUTELY FUCKING NOT!!" So I went back to my stack solution and refactored it to calculate C code idx using log10 for the character length of counts.
After that, my timeouts were gone! But now it would fail on super_input 8, so I did some investigation by compiling and running a local version of this code — it gave me a Segmentation Fault, so I figured out the only way this could happen is if I didn't allocate enough space for resulting C code string. So I raised the size of the buffer and voilà! All green! Wo-hooooooow! I feel like such a hacker now... :)))
(I'm only using static size array to avoid millions of realloc-s, but will see if I can make it dinamic since it only takes 3 seconds to run my code now.)
By the way, how many tests are there? Maybe there is a way to optimize one of my solutions to pass it? I tried to modify the stack to use a doubly linked list so I don't have to reverse it but that caused it to crash on
(*root)->prev = stack_node;
somehow. Weird...This comment is hidden because it contains spoiler information about the solution
This comment is hidden because it contains spoiler information about the solution
Tried two different approaches — both of them pass 53 tests and then timeout (super_input 6 of 6).
For anyone considering solving this kata: this is NOT A 4kyu KATA! It seems like the only way to solve it and not get a timeout is to somehow transpile the whole thing on the fly in one pass — something that should have been mentioned in the description. :|
I'm gonna post both of my solutions in comments to this post just in case...
Done!
I've found two more:
You task
should beYour task
langauge
should belanguage
Thanks!
This comment is hidden because it contains spoiler information about the solution
Fixed
Typo in description,
equivilent
should beequivalent
.Loading more items...