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.
it's not a completely ridiculous solution though.
fun kata but it would be more interesting if there was a performance version
What is your point exactly, did the chicken lay an egg or the egg produce a chicken?
I asked chatGPT to solve this kata, and this function with regular expression is the answer.
Test cases don't cover case when after releasing memory we have two adjacent blocks. All three blocks have to be merged to one block, and then test should check it. Something like this:
const mem = new MemoryManager(new Array(80));
const pointer1 = mem.allocate(16);
const pointer2 = mem.allocate(16);
const pointer3 = mem.allocate(16);
const pointer4 = mem.allocate(16);
const pointer5 = mem.allocate(16);
mem.release(pointer2); // release left block
mem.release(pointer4); // release right block
mem.release(pointer3); // release center block
mem.allocate(48); // try allocate size = 3 * 16
My code doesn't cover this case but still passed all tests!
clever
Loved the Kata, interpereters are always fun, but I was able to brute force the random tests with a bit of good RNG.
Now I gotta find something else to do......
this is supposed to be two islands and not one ? Am I missing something?
I'm getting this error:
My code does pass the example tests fine; the issue is on the random tests. That said, I don't have a
.replace
in my code, so I'm not sure if this is my mistake or not. If it is, then the error message should be improved.I finally got top answer.
Critically, the description specifies:
So we are specifically asked not to fragment the allocated block into several sub-blocks (as opposed to what modern, real-life MMUs allow).
Then there is this test (in pseudocode):
Without fragmentation, this can only work if we allocated the first pointer at address
0
and the second one at address32
.Are you sure that's what the tests are expecting? My understanding is that by returning the pointer on allocate, we allow the checker to verify correct performance without making any assumptions on the implementation of memory allocation.
For your example:
allocate(16) -> 5
allocate(16) -> 40
allocate(16) -> 22
The checker can deduce that 0-4, 21, 38-39, 56-63 are free based on the previous inputs and outputs so it would expect an error on the next allocate(16).
That is of course just my guess. If it is expecting certain implementations, that needs to be fixed.
what is the size limit to check for? Is it 256 per allocation.
That's part of the challenge. This kata is really easy for a 4kyu, completely naive solutions will pass, you should not expect more hints in discussion.
Please review: TypeScript Translation
Loading more items...