Skip to content

Enumerates the possible movement sequences of a knight on a chess board shaped like a phone key pad

Notifications You must be signed in to change notification settings

cagdasgerede/knight-move-on-phone-keypad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Enumerates all possible sequences of moves of length n of a knight in chess on a chess 
board shaped like a phone key pad. See below:

Phone Keypad:
1 2 3
4 5 6
7 8 9
  0


A knight can move in L shape. For instance, starting at 1, it can go to 8 or 6.

In general there are always 2 possible positions a knight can move to from any position other than 5.
5 can never be visited. Also starting at 5 a knight cannot move to any other position.

As a result, there are 2^n possible sequences of length n for a knight starting at any position other than 5.


Here is an example showing how to run this code:
> ruby chess.rb 1 5
1,6,1,6
1,6,1,8
1,6,7,2
1,6,7,6
1,8,1,6
1,8,1,8
1,8,3,4
1,8,3,8
done


The first argument is the knight's starting position. The second argument is the number of times the knight moves.


About

Enumerates the possible movement sequences of a knight on a chess board shaped like a phone key pad

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages