Where can the knight be in N moves? This is Hole-3 from The Autumn Tournament of APL CodeGolf. I am the original author of the problem there, and thus allowed to re-post it here.

Given:

a number of turns (please state if no movements is 0, otherwise we'll assume it is called 1) and

a list of one or more starting positions (in any form, e.g. 0 or 1 indexed coordinates or 64 consecutive numbers/characters or A1–H8 – state which), on an 8-by-8 chessboard,


return (in any order) the list of unique positions (in the same format as the input) that knight(s) can be at after the given number of turns.

Each knight must move with every turn, but you do not have to worry about multiple knights occupying the same square.

A knight can only move to the positions marked with X relative to its current position, marked with ♞:



Examples (1-indexed coordinates)
1 move from [[1,1]]: [[2,3],[3,2]]
2 moves from [[1,1]]: [[1,1],[1,3],[1,5],[2,4],[3,1],[3,5],[4,2],[4,4],[5,1],[5,3]]
1 move from [[1,1],[5,7]]: [[2,3],[3,2],[3,6],[3,8],[4,5],[6,5],[7,6],[7,8]]
2 moves from [[1,1],[5,7]]: [[1,1],[1,3],[1,5],[1,7],[2,4],[2,6],[2,8],[3,1],[3,3],[3,5],[3,7],[4,2],[4,4],[4,6],[4,8],[5,1],[5,3],[5,5],[5,7],[6,4],[6,6],[6,8],[7,3],[7,7],[8,4],[8,6],[8,8]]
0 moves from [[3,4]]: [[3,4]]
Wolfram Language (Mathematica), 45 bytes

Because the other solution is incorrect (see Martin's comment below), so I decide to post my solution:

8~KnightTourGraph~8~AdjacencyList~#&amp;~Nest~##&amp;


Try it online!

Ultimate infix notation...

Takes 2 input, the first one is a list of numbers in range [1,64] describe the starting positions of the knight, the second one is the number of steps.

This solution relies on the extreme convenience of Mathematica builtin functions:


AdjacencyList may takes a list of vertices on its right side, and return a list of vertices adjacent to any of those, already removed duplicates and sorted.
KnightTourGraph is a builtin. Not surprise.
Nest takes arguments in order Nest[f, expr, n], which we can splat the ## over its right side as Nest[f, ##].
And finally, Mathematica parse a~b~c~d~e as (a~b~c)~d~e, so no square bracket is necessary. Without infix notation and flatten ##, it would be Nest[AdjacencyList[KnightTourGraph[8, 8], #] &amp;, #, #2]&amp;.