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
Similar Kata:
Stats:
Created | Sep 23, 2017 |
Published | Oct 4, 2017 |
Warriors Trained | 8681 |
Total Skips | 3288 |
Total Code Submissions | 21659 |
Total Times Completed | 872 |
Java Completions | 150 |
JavaScript Completions | 220 |
Python Completions | 386 |
C# Completions | 91 |
Haskell Completions | 27 |
Ruby Completions | 20 |
Total Stars | 428 |
% of votes with a positive feedback rating | 86% of 240 |
Total "Very Satisfied" Votes | 185 |
Total "Somewhat Satisfied" Votes | 44 |
Total "Not Satisfied" Votes | 11 |
Total Rank Assessments | 3 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 5 kyu |