5 kyu

Boxes in boxes

68 of 115dfhwze
Description
Loading description...
Algorithms
ASCII Art
Performance
Strings
Puzzles
Memoization
Recursion
Mathematics
Dynamic Programming
  • Please sign in or sign up to leave a comment.
  • ahmet_popaj Avatar

    Great kata of the ASCII art series, quite challenging.

  • Madjosz Avatar

    Typo: hadcoding

  • LosBlobbos Avatar
  • andreweinhorn Avatar

    My code passes all the sample tests, and the fixed tests, and passes 12 of the random tests before timing out. Is anyone else seeing this? And is there a way to bypass the timeout to see if my solution can complete all the tests succesfully?

    I would like to see how other people solved this, but can't do that until my code completes its attempt.

    Ps. I'm reasonably sure my code is pretty efficient, and it is creating the boxes-in-boxes correctly.

    • dfhwze Avatar

      I've had a look at your current solution. You need to optimise for performance. I suggest you keep trying to make your solution faster.

  • andreweinhorn Avatar

    I think there is an error in the diagram on alignment (showing spaces as asterisks).

    We were given:

    *_*_*_*
    |*** _|           
    |* _|_|   
    |*|* _|   
    |_|_|_|   
    

    But I'm fairly sure the diagram should be:

    *_*_*_*
    |****_|           
    |**_|_|   
    |*|**_|   
    |_|_|_|   
    

    There must be 7 characters on each line

  • lbermudez Avatar

    I have a posible solution but in the test with n = 20 it shows the next error: RangeError: Maximum call stack size exceeded at draw (test.js:10:11) at act (test.js:55:26) at Context. (test.js:173:9) at process.processImmediate (node:internal/timers:471:21)

    It could be because the last step when convert de array to string joining with \n?

    • dfhwze Avatar

      Are you using a recursive solution?

    • lbermudez Avatar

      No, but the last 'join' was not the problem. It seems the spread operator applied to big array and pushed to anoher array caused the error on the stack.

      bigArray.push(...bigArray.slice(1).map(blabla))

      I found this explanation:

      "The RangeError: Maximum call stack size exceeded is thrown when a function call is made that exceeds the call stack size. This can occur due to the following reasons:

      • Too many function calls.
      • Issues in handling recursion, e.g. missing base case in a recursive function to stop calling itself infinitely.
      • Out of range operations."

      In my case I think the third point is the cause: "Out of range operations" when I use 'push(...bigArray)' because they are too many args to the function. I've fixed it.;)

  • myjinxin-2015 Avatar

    Awaiting approval ;-]

  • Blind4Basics Avatar

    Hi,

    Last line of the example of the "Alignment" section:

    |*|_|_|  
     ^
     should be a "_"
     
    

    suggestion: you could maybe use multiline strings, to format the outputs (not that it changes much. Your call... Might actually be a "bad" idea, because the leading and trailing spaces are less obvious...)

    
                act(4, '\n'.join([
                    " _ _ _ _ ",
                    "|      _|",
                    "|    _|_|",
                    "|   |  _|",
                    "|  _|_|_|",
                    "| |    _|",
                    "| |  _|_|",
                    "| | |  _|",
                    "|_|_|_|_|"])) 
    

    becomes for example

    
                act(4,'''\
     _ _ _ _ 
    |      _|
    |    _|_|
    |   |  _|
    |  _|_|_|
    | |    _|
    | |  _|_|
    | | |  _|
    |_|_|_|_|''') 
    
  • Voile Avatar

    Should enforce a code length limit to prevent excessive hardcoding.

  • JohanWiltink Avatar
    ---------------------------------
     n            box   height width
    ---------------------------------
                    _
     1             |_|       2     1
    

    Shouldn't that width be 3 ?