5 kyu

Draw the borders I - Simple ascii border

25 of 30mauro-1
Description
Loading description...
Geometry
Strings
ASCII Art
Algorithms
View
AllIssues2QuestionsSuggestions1Show Resolved
  • Please sign in or sign up to leave a comment.
  • Voile Avatar

    It is entirely unclear when should a boundary be |/- instead of +. e.g:

    +--------+
    |        |
    | +---++ |
    |     || |
    +---+ || +--+
    |     ||    |
    +-----++----+
    

    I'm even seeing these in the random tests:

           +-+-++-+
           | + ++ +-+
           |        |
          ++        ++
          |       ++ |
          |       ++++
          ++        |
         +-+       ++
       +-+          ++
     +-+             |
    ++               |
    

    Why is the left side

     ++
    +-+
    

    instead of

     ++
    +++
    

    when the right side has

    ++ |
    ++++
      |
    

    instead of

    ++ |
    +-++
      |
    

    ?

    • mauro-1 Avatar
      • + = corner, the border turns left, right or back
      • '-','|' = straight border

      If the border passes two times in the same cell, + takes precedence.

      Left side, no corners in lower middle char:

        ░░        ░░
       ++░       ┗┓░
      +-+░   =  ┏━┛░
       ░░░       ░░░
      

      Right side, at least one corner in all middle row:

      ░░░         ░░░  
      ░++░|       ░┏┓░┃
      ░++++   =   ░┗┻┳┛
      ░░░|        ░░░┃ 
      
    • Voile Avatar

      But couldn't it be these too?

        ░░        ░░
       ++░       ┝┓░
      +++░   =  ┏┻┛░
       ░░░       ░░░
      
        ░░        ░░
       ++░       ┝╸░
      +++░   =  ┏┻╸░
       ░░░       ░░░
      
      ░░░         ░░░  
      ░++░|       ░┏╸░┃
      ░+-++   =   ░┗━┳┛
      ░░░|        ░░░┃ 
      
    • mauro-1 Avatar

      No, the border can't go straight into the shape. If there are blocks up and right and spaces left and down, then the border is a top right corner -> +.

        ░
       ╶┓░ 
        ╵    
      
    • Voile Avatar

      Okay, what about the first example?

      +--------+
      |        |
      | +---++ |
      |     || |
      +---+ || +--+
      |     ||    |
      +-----++----+
      

      Why is it

      ++
      ||
      ||
      ||
      ++
      

      and not

      ++
      ++
      ++
      ++
      ++
      

      ?

    • mauro-1 Avatar
      +--------+           ┏━━━━━━━━┓     
      |░░░░░░░░|           ┃░░░░░░░░┃   
      |░+---++░|           ┃░╺━━━┳┓░┃   
      |░░░░░||░|      =    ┃░░░░░┃┃░┃   
      +---+░||░+--+        ┣━━━╸░┃┃░┗━━┓
      |░░░░░||░░░░|        ┃░░░░░┃┃░░░░┃
      +-----++----+        ┗━━━━━┛┗━━━━┛
      
    • dfhwze Avatar

      I do think the description, not just the comment section, should mention when a square is considered a corner. It is either:

      • (left or right is in shape) and (up or down is in shape)
      • (any diagonally is in shape) and (both connecting neighbours are not in shape)

      and the square needs to be on the outer border

  • natan Avatar

    Haskell translation

    Tests are directly translated from python. As a basic sanity check I have executed the tests once, writing input/output to file and checked them against the python reference solution.

    • mauro-1 Avatar

      I don't speak haskell. Can someone check translation before approval?

    • natan Avatar

      Some things to look for (and maybe consider regardless of reading the translation)

      I don't know if I like requiring the rawError flag to be defined by the solution (cannot be removed) An option could be a magic comment that is checked for in the source ... but I'm not much a fan of that either. I had a thought involving unsafePerformIO but getting the user to force that thunk might seem difficult. Among non-optimal options I went with simple. happy to modify it.

      oh and I changed the number of small tests to 100... is that bad? it makes the description lie a bit, something I saw later. (lol who reads descriptions before translating amirite) It's trivial to change of course.

      And ... it takes a while to run. It reports 6-7 seconds or so. ~3 is compilation, 1.5 for reference, 1.5 for solution. My solution is far from optimized so swapping in a different one might make that number more sane... Performance isn't supposed to matter but err I guess it does. Locally, my python solution + the test suite runs in 0.9s, and my haskell solution + test suite runs in 0.7s so it's arguably same/faster ... just that the haskell runner isn't so great

      I changed the input type from set to list. This avoids forcing an import on the solution. I think that's the right choice, leaving the user to use whatever data structure they want. The shape of the data is still the same, a bunch of coordinates. This 100% does not need to be mentioned in description since the type signature makes this very clear and list can be interpreted as set imo... especially when the values are unique, which I do ensure.

    • mauro-1 Avatar

      I don't know if I like requiring the rawError flag to be defined by the solution (cannot be removed)

      In python it isn't required (not defined is the same as False). I don't know if in haskell there are better ways (something in predefined?).

      oh and I changed the number of small tests to 100...

      IMHO 32 are enough, but there isn't a big difference. The main goal of small random tests is to provide some easily debuggable random test.

      I changed the input type from set to list.

      It can make difference if there are many membership tests (if (x,y) in shape).

    • natan Avatar

      No there are no mutable variables. Can't put it somewhere else because it can't be changed. It is possible to have a reference to something mutable, however, modifying that requires sequencing an IO action, that is, program control has to go through it and that doesn't happen if it's just a global "statement" unless it was looked at (evaluated) which means the user solution would have to put it within its evaluation path which will confuse ppl. Plus, it involves a hack to put IO code in side-effect-free code so it's bad all around. The closest thing would be a comment, I think. Anyway, I decided to display BOTH. I think that works well. The flag is now entirely gone.

      > drawBorders [(1,1)]
        Expected "+-+\n| |\n+-+"
        +-+
        | |
        +-+
         but got "+-+"
        +-+
      

      ye?

      I changed the test sizes to match. 32 45 50. I think the small ones are good opportunity to catch as much as possible but uh. I don't really know nor care. Happy to match them to the description.

      The list stays. Obviously ppl should use data structures that support what they are doing. But since I cannot say what that data structure is, all that remains for me to do is to pass them the data. There is no standard set type like in python. And in python there is only one obvious choice, that's also not the case. And it's an import from outside the standard library. You wouldn't import numpy to pass in a 2d array. It's not the fastest data structure for lookups either because it's a tree set, not a hash set. Faster would be to use Array, but now the shape of the data changes because it becomes key->value. List.

      Thank you for letting me know how you feel about things, it helps so much!

    • mauro-1 Avatar

      It seems ok to me (but I'm not an haskell programmer).

      I will approve it, hoping there will not be complaints from haskell experts after approval (in two days of "beta" there was no trace of haskell reviewers).

      Suggestion marked resolved by mauro-1 4 years ago
  • jacosta66 Avatar

    Python: I feel lost..can someone explain this kata please. Thank you! I dont understand the coordinates and how they create a square vs a triangle and its relation with width and weight. I'm imagining a chart for x and y, maybe this is where I'm wrong and just not understanging how the coordinates relate to the figure

    • mauro-1 Avatar

      The figure is the union of unit squares, there aren't triangles.

      Imagine a plane divided in unit squares, each square has (x,y) coordinates.

      Added an image with examples in description.

    • jacosta66 Avatar

      Thanks! Have a better grasp now. The figure in the description helped also.

  • Tyson Asda Avatar

    Why is the level of difficulty of this kata pre-assumed at 7 kyu or even 6 (*_*)? The fact that you can solve it only with built-in functions (in Python) shouldn't ignore the experience in this area of math... (+ geometry code experience). I wouldn't dare to go and try (with a pretty long code, I assume) to transform in '-' and '|' some (between-)coordonates. So, why should one believe that this kata is easier (in any way) than the 4 kyu Snail (https://www.codewars.com/kata/521c2db8ddc89b9b7a0000c1), where you can definitely proceed with append only?

    • mauro-1 Avatar

      IMHO it's a 5 kyu or maybe 4 kyu. My initial rank assessment is 5 kyu, as you can see from katas list.

      Someone ranks everything 8 kyu (and downotes everything), someone ranks 1kyu easy katas. Min/max/avg ranks on kata page aren't very reliable, especially with few assessments.

  • Blind4Basics Avatar

    The shape may have holes. Holes must be ignored,

    That's pretty unfair...

    1. why?
    2. if so, you have to provide an example with that at the beginning of the description
    • user9644768 Avatar

      Yup, that's unfair. XD I've to write extra 20 lines of FF to clean up the holes stuffs.

      But if your point is that avoidance of holes reduces difficulty, then I would say that it is contextual, because in my case it increased the number of lines, but if one solves the problem in other ways(edges tracing), it is easier in those approaches.

    • mauro-1 Avatar

      That's pretty unfair...

      Why?

      If so, you have to provide an example with that at the beginning of the description

      I will do...

      IMHO drawing only outer borders is more interesting.
      If you want to draw all borders there is the (simpler) draw th borders II.

    • Blind4Basics Avatar

      Thing is, it feels like you're mixing too much stuff in your kata (plural). Like, adding perf requirements to enforce a specific kind of algorithm while nothing is told about what you expect, that the descriptions (currently) do not make stand out the differences clearly enough so that the user can actually spot what you want.

      Currently, I feel like I'm poking in the dark, when you're talking about different kind of algo for those tasks. I don't know any specific kind of algo for these tasks. I just build them out of my mind. So I could use any kind of approach, using only variations to solve each of them and I doubt there would be different time complexities for those. So I really don't follow your train of thoughts.

      What are the time complexities of those alogrithm you talk about? Are they actually different? The very least would be a hint about waht you expect.

    • mauro-1 Avatar

      There isn't a specific algorithm for border drawing, and in this kata there are 3 solutions with 3 diffrent algorithms.

      Different kata requirements may restrict the choice of algorithm. If there is a common algorithm it's a single kata (unless the algorithm is 90% of one kata and 10% of the other).

      In this kata the main problem is avoid holes (which exclude some simple algorithm), in the second kata the main problem is speed (which exclude more complex algorithms), in the third is ... (top secret).

      In general the choice of algorithm is free, in the second kata it's more forced, but in a performance kata it's normal to require the fastest algorithm and/or some micro-optimizations.

      May be useful to have a comparative table in description?

    • Blind4Basics Avatar

      from what you're telling, there shouldn't by any perf requirement for the present one, so.

    • mauro-1 Avatar

      from what you're telling, there shouldn't by any perf requirement for the present one, so.

      There aren't performance requirement.

      There is the default 12 seconds timeout, but it shouldn't be a problem. Reference solution complete all tests in 120 ms (lesss than 2 s including startup and test case generation).

    • Blind4Basics Avatar

      wth... x/

      Performances and tests

      sorry, I misread/misinterpreted this (this is definitely a bad day of those... :/ )

      Maybe change the title to Test contraints ? x)

      Issue marked resolved by Blind4Basics 4 years ago
    • mauro-1 Avatar

      Maybe change the title to Test contraints ? x)

      Description updated.