3 kyu

Line Safari - Is that a line?

393 of 889dinglemouse
Description
Loading description...
Algorithms
  • Please sign in or sign up to leave a comment.
  • fiddlemath Avatar

    I suspect part of what's confusing people in this kata description is "Sometimes a line may be valid in one direction but not the other. Such a line is still considered valid."

    I think, but am not sure, that you mean "Sometimes a line may be valid when starting from one endpoint, but not the other. Such a line is still considered valid". I think you do not mean something like "Sometimes a line may be valid if you take one turning at a +, but not a different turning at a +. Such a line is still considered valid". (Viewed narrowly, I think that'd be a reasonable interpretation, but it's hard to make sense of given the other rules.)

    Right?

  • Vladyslav Abramov Avatar

    What is the main difference between Good5 and Bad5? For me, the paths are equal.

  • avermakov Avatar
  • Nazarbek7777 Avatar

    Traceback (most recent call last): File "/workspace/default/tests.py", line 16, in test.assert_equals(line(show(grid)), expected) ^^^^ NameError: name 'line' is not defined. Did you mean: 'slice'?

    when i run my code in my pc it is working great but if i try to past the same code to codewar and run it it gives error

  • Lekret Avatar

    Yeah, that was hardest so far and took me a couple of hours to solve. When first tests passes you think it will be easy, but then submit tests kick in, and you think about skipping the kata. Then after hours of attempts and rereading the rules you finally understand what is considered ambiguity and what kata wants from you. It's not very clear from the rules imo.

  • vltspr Avatar

    In C# tests, test named "ExBad5" has a useless trailing comma in the last grid row. Sorry, but I had to point it out :)

  • jphamilton Avatar

    Awesome kata. Thought this would be easier than "Blaine is a pain" because they seem similar, but it was tricky in a different way. At first I was convinced the "ambiguity" rules made no sense...then I saw it! Makes perfect sense.

  • MelonFruit Avatar

    Awesome kata, had to keep reading the rules cause one of the cases was tripping me up. If I had to give any advice for people failing cases it would be to reread the valid line rules.

  • DJ3R0M Avatar

    Nice brain twister! It took me a day to get it right. The testing part is clearly solid and exaustive. Thx for this kata!

  • AdiPassover Avatar

    Nice kata. it was enjoyable at first but only after I passed the tests I found out that I didn't understand the description. I think that the description didn't do a good job at defining "ambiguity". It also should have specified that you can start from both points but the path doesn't have to be legal from both of the points. I think the some of the tests of "loopAmbiguous()" would make perfect examples.

    Other than that, I did enjoy the kata and while I think that some of the rules are unintuitive, the tests were really good at helping me understand them. I'm amazed by the number of tests and it looks like a lot of work has gone into this kata.

  • iqbalap3 Avatar

    and also the solution for this pattern is False, i always failed for this 2 pattern(include the previous post), can anyone help me explain why it is False? thx (python)

      +-+    
      | |    
      ++++   
      ++++   
     X+++    
       +---X
    
  • iqbalap3 Avatar

    This pattern must True right? the solution said that it is False, can anyone explain why it is False? thx

      ++      
     ++++     
     ++++
    X-++-X 
    
  • voodookiidoo Avatar

    How comes the breacumb test return false? The path is ambigious from one way, but from another it is definently onle one possible

  • ArtBalan Avatar

    Can someone explain me the difference between the 5th bad exemple and the 5th good exemple ? For me there are the same.

  • svemij Avatar

    I would agree with most of the people about the deffinition of "ambiguous", it would be nice to elaborate it better in the task.

    I have some interesting question, hopefuly. I suppose that this is FALSE (. is space, I don't know how to type space):

    "X--+...",

    "...|...",

    ".+-++-+",

    ".+--+.X"

    However, if we assume "smart walker" when reaching the "critical" + it should be clear that one should turn to the -, not +. The reason is if the walker turns to +, instead of - it will certanly be impossible to complete the line, because that - must be covered sometime, but it can be reached only from the oposite side of the "critical" +, and then only option is to go again to the "critical" +, which is forbidden. Thus, it is clear that in such case the walker should turn to the -. This is wrong if we assume "dumb walke" that cannot "think" in such a way.

  • hua-zhi-wan Avatar

    In ex-good-#5 in javascript, last row of the matrix have an unnecessary space.
    It's just a small mistake, but makes me feel uncomfortable...

    it("ex good #5", function(){
      var grid = preloaded.makeGrid([
      "                      ",    
      "   +-------+          ",
      "   |      +++---+     ",
      "X--+      +-+   X      "   // <---- Here!
      ]);
      preloaded.showGrid(grid);
      var actual = line(grid);
      Test.assertEquals(actual, true);
    });
    
  • amitznati Avatar

    I read the discussions, and I still don't get why it's invalid test:

        +-+
        | |
        ++++
        ++++
       X+++
         +---X
    

    there is only one path forward and backward, isn't it?

    is it possible to pass on corner twice but to different directions?

  • udah1 Avatar

    Why is this false? +------+ | | X-----+------+ |
    X
    The only valid path is down at the first +.

    If I go up, then right then down then left, I need to go thorugh the same + again, which is invalid (same if I go drom second X)

  • sbam Avatar

    this took so long but i loved all the practice it made me go through! thanks for the brain teaser!

  • fibonaccios Avatar

    Alright, I think I have solved all your katas except 6Kyus+ I need some kind of DingleBadge don't you think?

  • satisfiedblackhole Avatar

    I love your katas! T_T

  • rfyoro Avatar

    Nice Kata!!

  • reggaeguitar Avatar

    Would be nice if the C# tests used a char[][] as an argument so I didn't have to reimplement Preloaded.MakeGrid. Other than that awesome kata!

  • Opabinia Avatar

    The fifth good example is ambiguous from both ends!

       +-------+
       |      +++---+
    X--+      +-+   X
    

    From the left: You reach the + and can go either ← or → . Ambiguous, disqualified. From the right: You reach the + and can go either ↓ or ← . Ambiguous, disqualified.

    Help me out?

  • jeroonk Avatar

    The input grid given for the (Python) test "Loops > Ambiguous loop2":

       X-----+  
       |     |  
       |     |  
       |     |  
       +-----W  
    

    Does not satisfy the guarantee given in the test description:

    You are given a grid, which always includes exactly two end-points indicated by X

    Moreover, it contains the unspecified character W (a simple typo for X?).

  • martin3141 Avatar

    My solution failed a single test (the "more edge cases"), can I see the corresponding mazes? I cannot find my mistake.

  • mateuszmacheta Avatar

    The best kata I've done so far. It took me a couple of days of thinking how to implement it. Thank you!

  • rosstheboss Avatar

    Two of the paths I don't understand why they should fail:

    This one is apparently false for ambiguousness... but I am not clear from the instructions why:

     X-----+  
     X     |  
     |     |  
     |     |  
     +-----+  
    

    The second one is this and all the test says is that it is an edge case but it looks like it has only one legit path (well from each direction). Why is this one false?

      ++++     
     X++++     
         X     
    
  • adityagarg Avatar

    How is Good line example No. 5 a good line? There is ambiguity in following that line!

  • DunetsNM Avatar

    This comment has been hidden.

  • Courtland9777 Avatar

    In the Good5 test in C# all of the strings are not the same length. It doesn't say they have to be but "grid" does kind of imply that they will be the same length. Fun Kata though.

  • user8436785 Avatar
  • harvester83 Avatar

    Hello I need help here, I have error with Preloaded.makeGrid, I am using intellij, and there is not import missing library available, I googled it and I couldn`t find any relevant, the error stack bellow.

    Error:(12, 27) java: cannot find symbol symbol: variable Preloaded location: class com.company.DingleMouseTests

  • prichuda Avatar

    hi, about testcase moreEdgeCases. I tested it on my local machine and it return false as expected, is it 1 test contains 2 figures, or 2 different tests? anyway could it be reformatted to make it clear where are the boundaries of test, because now it's not so clear for me

    upd may be someone can explain the difference between breadcrumbsTwoWays and moreEdgeCases, they seems the same but one is passed another is not :-(

  • hbsun2113 Avatar

    This description should be more detailed and accurate.

  • K3nH2l Avatar

    Another excellent challenge. I can say without reservation that, to date, your Kata are the most engaging and satisfying I've found on Code Wars. Your test cases are exemplary. Thank you, and keep them coming!

  • maxchiodo Avatar

    Interesting kata. The graph traversal part is the easy part. What makes it more tricy is to determine what nodes are legal dependin on where you came from. Will get back to it.

  • mvhv0 Avatar

    A begging suggestion, actually it's borderline issue, or so I believe. Please refactor explaination about that 'ambiguity' stuff because it's not clear enough. At least not for guys not natively fluent in English.

    It must be possible to follow the line with no ambiguity (lookahead of just one step, and never treading on the same spot twice).

    this "lookahead" part makes sence only after realizing what it should mean, usually after 'attempt' failing and digging into discource.

    also that Hint:

    Imagine yourself walking a path where you can only see your very next step. Can you know which step you must take, or not?

    don't help with this 'ambiguity' either. It looks like it suggests to use some pathfinding method.

    It should more look like:

    BEWARE OF AMBIGUITIES

    if after '+' corner symbol line can be proceed in more than one direction the path is considered ambiguous which means: False. so make sure each corner is a corner, not an intersection

    example

    Screenshot-from-2019-11-12-23-17-16

    If you look carefully, you can clearly see a lot of confused warriors in discussion and also a lot of solutions which rigs 'ambiguous' part in 'not very honest' ways. I wish that explaination could help them..

  • shoq Avatar
    X-----+  
          |  
    X-----+  
          |  
    ------+  
    

    It has been asked before but I can not see answer - why would that be invalid? Sure when you start with the lower X then the first corner is ambiguous but if you start with the top one it's very simple because the second '+' must be a turn

  • bentaye Avatar

    This case has been addressed in a post below, but the answer is hidden

     X-----+  
     X     |  
     |     |  
     |     |  
     +-----+    
    

    I do not understand why this is not valid? There is only one valid path using all the signs. Going directly from X to X is not valid as it does not use all the signs.

    EDIT: I think I understood, the fact that there is a choice to go right or down at the beginning makes it anbiguous so invalid. Is that correct?

  • safiir Avatar

    This comment has been hidden.

  • RobinBennett Avatar

    Another great kata, thank you!

    One suggestion though: the 'breadcrumb' tests require a rule that I don't think is adequately covered by the description. "If you come to an ambiguous corner but you've already visited one of the options, then it doesn't count as ambiguous."

    People who don't recognise the cultural significance of Hansel and Gretal leaving a trail of breadcrumbs might not realise why those tests count as valid lines, and not ambiguous loops. Is the story widely known in (for example) East Asia?

  • JohanWiltink Avatar

    Haskell translation

    Yes, all the tests are there. And all the logging. ( Based on JS. Sincerely hope that version is complete. )

  • KataSideKick Avatar

    C# Translation added.Please review and approve~

    Notice: In java translation, part of loopAmbiguous Test5 are lost.Please improve it.C# version already added.

  • Kronodeus Avatar

    I'm passing 23 out of 24 tests, but failing on this one:

        +-+
        | |
        ++++
        ++++
       X+++
         +---X
    

    It's supposed to be invalid but I do not understand how this is invalid. Seems perfectly valid to me and my code agrees.

    EDIT:

    I understand it now, this is not valid because there are places where you could turn left or right. I had an incorrect understanding of one of the examples which lead me to a false assumption about what was considered ambiguous.

  • rahulk8671 Avatar
         +-------+          
         |      +++---+     
      X--+      +-+   X  
    

    ex good #5

    on 4th + it has a choice, whether to go left or right, its ambiguous, shouldn't it be false?

  • Jomopipi Avatar

    the fourth "good" line is an example of one that's valid one way but not the other, right?

  • omiceron Avatar

    This one

    "     ++      ",
    "    ++++     ",
    "    ++++     ",
    "   X-++-X    "

    should return true, because it has only one way:

    "     →↓      ",
    "    →↑→↓     ",
    "    ↑←↓←     ",
    "   X→↑→→X    "

    This line is not valid, because it's a lot of characters that aren't part of the line:

    "     ++      ",
    "    ++++     ",
    "    +→↓+     ",
    "   X→↑→→X    "

    So we have only 1 valid solution => true

    And why this should return false?

    "    +-+    ",
    "    | |    ",
    "    ++++   ",
    "    ++++   ",
    "   X+++    ",
    "     +---X "

    It's possible to draw only one line => true.

    JavaScript btw.

  • Blind4Basics Avatar

    Python translation!

    The random tests are... let's say...:

    • "interesting" in their randomness ;)
    • especially funny! (if I didn't have wrote the code like I did, I believe I would never have seen the "thing"! ;) )

    Would be nice to implement a complete random path generator. Quite a task, though... :o If I find the courage (and if you're interested in it!), I'll try later.

  • Blind4Basics Avatar

    This comment has been hidden.

  • dinglemouse Avatar

    @ZED.CWT thanks for approving :-)

  • JohanWiltink Avatar

    This comment has been hidden.

  • user4156440 Avatar

    [edited] got an issue: in randomTest a grid was being reused. I had edited the grid to account for the fact that x and y are swapped (y being horizontal)

    also a question: why is

    #---+
    #   |
    |   |
    +---+
    

    (test example was a bit bigger i think) not legal?

  • Blind4Basics Avatar

    Hi again,

    Found some time... I have to say I'm a bit confused about some examples:

     X-----+  
     X     |  
     |     |  
     |     |  
     +-----+     => expected: false
     
    

    => but why? Seems pretty valid to me

     X-----+  
           |  
     X-----+  
           |  
     ------+     => expected: false
    

    => but why? Seems pretty valid to me and wouldn't true be consistent with this rule of the description: Sometimes a line may be valid in one direction but not the other. Such a line is still considered valid.

    Err... Just realized that is surely because you detect a straight line around a +? But in that case, shouldn't the Good5 example rather be considered false because of the +++ section:

       +-------+          
       |      +++---+     
    X--+      +-+   X 
    
  • Blind4Basics Avatar

    Very interesting one!! Not finished yet (office time... So not enough time to debug my code yet :/ ), but I believe I know where you may have found the idea and some of the examples... ;-D (it's still waiting for its first Java completion, btw! ;) )