Ad
  • Default User Avatar

    it's not a completely ridiculous solution though.

  • Custom User Avatar

    fun kata but it would be more interesting if there was a performance version

  • Custom User Avatar

    What is your point exactly, did the chicken lay an egg or the egg produce a chicken?

  • Custom User Avatar

    I asked chatGPT to solve this kata, and this function with regular expression is the answer.

  • Custom User Avatar

    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!

  • Custom User Avatar
  • Default User Avatar

    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......

  • Custom User Avatar
    ~XXXXX~
    ~X~~~X~
    ~X~X~X~
    ~X~~~X~
    ~XXXXX~
    

    this is supposed to be two islands and not one ? Am I missing something?

  • Custom User Avatar

    I'm getting this error:

    Cannot read properties of undefined (reading 'replace')
    

    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.

  • Custom User Avatar

    I finally got top answer.

  • Default User Avatar

    Critically, the description specifies:

    allocate(size) reserves a sequential block (sub-array) of size ...

    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):

    memory = MemoryManager(<array of size 64>)
    ptr1 = mem.allocate(32)
    ptr2 = mem.allocate(32)
    mem.release(pointer1)
    try:
      ptr3 = mem.allocate(32)
    catch:
      fail_test("should be able to allocate 32 after releasing 32")
    

    Without fragmentation, this can only work if we allocated the first pointer at address 0 and the second one at address 32.

  • Default User Avatar

    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.

  • Custom User Avatar

    what is the size limit to check for? Is it 256 per allocation.

  • Custom User Avatar

    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.

  • Custom User Avatar
  • Loading more items...