6 kyu
Simple Fun #150: Robot Transfer
133 of 241myjinxin2015
Description:
Task
We have a N×N matrix
(N<10) and a robot.
We wrote in each point of matrix x and y coordinates of a point of matrix.
When robot goes to a point of matrix, reads x and y and transfer to point with x and y coordinates.
For each point in the matrix we want to know if robot returns back to it after EXACTLY k
moves. So your task is to count points to which Robot returns in EXACTLY k
moves.
You should stop counting moves as soon as the robot returns to the starting point. That is, if the robot returns to the starting point in fewer than k moves, that point should not count as a valid point.
example
For:
matrix=[
["0,1","0,0","1,2"],
["1,1","1,0","0,2"],
["2,1","2,0","0,0"]]
k= 2
The result should be 8
Robot start at (0,0) --> (0,1) --> (0,0), total 2 moves
Robot start at (0,1) --> (0,0) --> (0,1), total 2 moves
Robot start at (0,2) --> (1,2) --> (0,2), total 2 moves
Robot start at (1,2) --> (0,2) --> (1,2), total 2 moves
Robot start at (1,0) --> (1,1) --> (1,0), total 2 moves
Robot start at (1,1) --> (1,0) --> (1,1), total 2 moves
Robot start at (2,0) --> (2,1) --> (2,0), total 2 moves
Robot start at (2,1) --> (2,0) --> (2,1), total 2 moves
Robot start at (2,2) --> (0,0) --> (0,1) --> (0,0) --> (0,1) ....
(Robot can not transfer back to 2,2)
So the result is 8.
Input/Output
[input]
2D integer array matrix
n x n matrix. 3 <= n <=9
[input]
integerk
2 <= k <= 5
[output]
an integer
Puzzles
Similar Kata:
Stats:
Created | Feb 20, 2017 |
Published | Feb 20, 2017 |
Warriors Trained | 764 |
Total Skips | 20 |
Total Code Submissions | 2035 |
Total Times Completed | 241 |
JavaScript Completions | 79 |
C# Completions | 30 |
Python Completions | 133 |
Ruby Completions | 23 |
Haskell Completions | 13 |
Total Stars | 18 |
% of votes with a positive feedback rating | 95% of 83 |
Total "Very Satisfied" Votes | 75 |
Total "Somewhat Satisfied" Votes | 8 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 5 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 6 kyu |
Lowest Assessed Rank | 7 kyu |