3 kyu
Knight's Attack!
99 of 102rsdah13
Description:
Time to train your knights...
Considere an infinite chessboard... With obstacles on it...
You're provided with a start point and an end point (as tuples (x,y)
), and a tuple of all coordinates that are blocked by obstacles. Your goal is to find the number of minimal moves required to reach the destination, coming from the start.
If the destination isn't reachable, return None/nil
.
DETAILS
- A knight moves in an "L" shape: two positions in one direction, then one position in a perpendicular direction.
- Be extremly careful about performances, there are some strict contraints to match (see below)
- It may rarely happen that the random generator fails to generate starting or ending positions. If it happens, you'll get an error message about that. Just try again, and you should be fine.
Performances requirements
- Your code will be tested in different situations and should be as fast as possible.
- Moreover, its performances should be independant of the direction it searches in (meaning, they should stay the same when exchanging start and destination).
- Your code will be compared to the reference implementation and you'll have to be at most 3 to 6 times slower in the timed tests (the actual factor value depends on the kind of test).
You are provided with 2 functions (in the preloaded section) to be able to display some inputs if needed (it's already done in the fixed tests):
def display(start, dest, obst, limit=((0,20),(0,20))):
""" Display function... (how surprizing!)
start: start
dest: destination
obst: data about obstacles
limit: area of the chessboard that will be printed, as ((xmin,xmax),(ymin,ymax))
(note: axis are like indexing: x>0 is vertical descendant,
y>0 is horizontal going right)
return: None
"""
def data_builder(s,print_it=True):
""" Convert a string representation of a chessboard to the set of
corresponding inputs for your "attack" function
s: string representation of the board
printIt: display the input
return: start, dest, obst
"""
Algorithms
Graph Theory
Similar Kata:
Stats:
Created | Apr 7, 2017 |
Published | Apr 7, 2017 |
Warriors Trained | 1694 |
Total Skips | 526 |
Total Code Submissions | 3957 |
Total Times Completed | 102 |
Python Completions | 99 |
Ruby Completions | 5 |
Total Stars | 104 |
% of votes with a positive feedback rating | 83% of 41 |
Total "Very Satisfied" Votes | 29 |
Total "Somewhat Satisfied" Votes | 10 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 6 |
Average Assessed Rank | 4 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 5 kyu |