3 kyu

Line Safari - Is that a line?

150 of 872dinglemouse

Description:

Kata Task

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

You simply need to return true/false if you can detect a one and only one "valid" line joining those points.

A line can have the following characters :

  • - = left / right
  • | = up / down
  • + = corner

Rules for valid lines

  • The most basic kind of valid line is when the end-points are already adjacent
    X
    X
    
    XX
    
  • The corner character (+) must be used for all corners (but only for corners).
  • If you find yourself at a corner then you must turn.
  • It must be possible to follow the line with no ambiguity (lookahead of just one step, and never treading on the same spot twice).
  • The line may take any path between the two points.
  • Sometimes a line may be valid in one direction but not the other. Such a line is still considered valid.
  • Every line "character" found in the grid must be part of the line. If extras are found then the line is not valid.

Examples

Good lines

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

Bad lines

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

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?

Algorithms

Stats:

CreatedSep 23, 2017
PublishedOct 4, 2017
Warriors Trained8681
Total Skips3288
Total Code Submissions21659
Total Times Completed872
Java Completions150
JavaScript Completions220
Python Completions386
C# Completions91
Haskell Completions27
Ruby Completions20
Total Stars428
% of votes with a positive feedback rating86% of 240
Total "Very Satisfied" Votes185
Total "Somewhat Satisfied" Votes44
Total "Not Satisfied" Votes11
Total Rank Assessments3
Average Assessed Rank
4 kyu
Highest Assessed Rank
3 kyu
Lowest Assessed Rank
5 kyu
Ad
Contributors
  • dinglemouse Avatar
  • JohanWiltink Avatar
  • Blind4Basics Avatar
  • KataSideKick Avatar
  • ZED.CWT Avatar
  • hobovsky Avatar
  • user8436785 Avatar
  • avermakov Avatar
Ad