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
Although probably never will be hit, assuming the max count of any items is 3 digits (minus a nul terminator) is kinda iffy.
Also, if the string is zero length, it will return an invalid string (i.e. no nul terminator).
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 do we need list comprehension [] here?
This comment is hidden because it contains spoiler information about the solution
Initializing a hash array and temp string with calloc is lame. Better initalization would be: int arr[256] = {[0 ... 255] = 0}; char numstring[5] = {[0 ... 4] = '\0'};
Also, you forgot to free numstring! So how is this BestPractices???
calloc allocated blocks come earased
I think this is a great Kata. It's dealing with a baffeling and somewhat mysterious sequence. There is for sure a recursive solution to calculate the numbers. But it should be considered, that recursive solutions could be waaayyy too slow calculating higher numbers...
This is kind of verbose!
What regex is made for: to shorten such code.
Yeah, me too, I definitely join the downvoters.
But it's something like a valid solution.
Oh, my, as I expectd, my brute force approach for JavaScript passed the first tests but timed out on the 'attempt'-tests. So I have to try something different... Maybe with a generator-function.
it's not about allocation, it's about casting.
strlen()
returns asize_t
value, comperable tounsigned long
. so, just change the type ofi
in yourfor
loop and that should do itOK, solved!
In my C solution the test always says:
Test Crashed Caught unexpected signal: 6
Completed in 0.0000ms
STDERR
setup.c:46:21: warning: comparison of integers of different signs: 'int' and 'unsigned long' [-Wsign-compare]
for (int i = 0; i < strlen(str); i++) {
~ ^ ~~~~~~~~~~~
1 warning generated.
munmap_chunk(): invalid pointer
On my computer it runs perfectly, also with valgrind, I cannot find a memory leak.
I checked the mallocs, but everything seems to be fine. Maybe I should increase/decrease the size of the allocated memory?
Loading more items...