Chess knight
knight.RdGenerating function for a chess knight on an infinite \(d\)-dimensional chessboard
Note
The function is a slight modification of spray::knight().
Examples
knight(2) # regular chess knight on a regular chess board
#> mvp object algebraically equal to
#> a^-2 b^-1 + a^-2 b + a^-1 b^-2 + a^-1 b^2 + a b^-2 + a b^2 + a^2 b^-1 + a^2 b
knight(2, TRUE) # regular chess knight that can stay still
#> mvp object algebraically equal to
#> 1 + a^-2 b^-1 + a^-2 b + a^-1 b^-2 + a^-1 b^2 + a b^-2 + a b^2 + a^2 b^-1 + a^2
#> b
# Q: how many ways are there for a 3D knight to return to its starting
# square after four moves?
# A:
constant(knight(3)^4)
#> [1] 2520
# Q ...and how many ways in four moves or fewer?
# A1:
constant(knight(3, TRUE)^4)
#> [1] 2665
# A2:
constant((1+knight(3))^4)
#> [1] 2665