Learn R Programming

spray (version 1.0-26)

knight: Generating function for a chess knight and king

Description

Generating function for a chess knight and king on an arbitrarily-dimensioned chessboard

Usage

knight(d=2)
king(d=2)

Value

Returns the generating function of the piece in question.

Arguments

d

Dimensionality of the board, defaulting to 2

Author

Robin K. S. Hankin

Examples

Run this code

knight()  # default 2D chess board
king()    # ditto

knight()^2  # generating function for two knight's moves

## How many ways can a knight return to its starting square in 6 moves?
constant(knight()^6)

## How many in 6 or fewer?
constant((1+knight())^6)

## Where does a randomly-moving knight end up?
d <- xyz(2)
kt <- (1+knight())*d^2/9
persp(1:25,1:25,as.array(d*kt^6))


## what is the probability that a 4D king is a knight's move from
##   (0,0,0,0) after 6 moves?

sum(coeffs(((king(4)/80)^4)[knight(4)]))

Run the code above in your browser using DataLab