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] integer k

2 <= k <= 5

  • [output] an integer
Puzzles

Stats:

CreatedFeb 20, 2017
PublishedFeb 20, 2017
Warriors Trained764
Total Skips20
Total Code Submissions2035
Total Times Completed241
JavaScript Completions79
C# Completions30
Python Completions133
Ruby Completions23
Haskell Completions13
Total Stars18
% of votes with a positive feedback rating95% of 83
Total "Very Satisfied" Votes75
Total "Somewhat Satisfied" Votes8
Total "Not Satisfied" Votes0
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • JohanWiltink Avatar
  • Voile Avatar
  • hobovsky Avatar
  • Just4FunCoder Avatar
  • KayleighWasTaken Avatar
  • saudiGuy Avatar
Ad