← Back to problems
UNSW COMP2041 · hard

21T2 Q12 — Knight's reachable squares

Argument 1 is a chessboard square (e.g. d4). Print, one line per BFS layer: line 1 = the start square; each next line = the new squares a knight can reach from the previous line. Stop when no new square is reachable. Squares on each line are sorted and space-separated.

$ ./prog a1
a1
b3 c2
a3 a5 b4 c1 c5 d2 d4 e1 e3
...

POSIX shell only (#!/bin/dash); standard UNIX filters; no awk, Perl, C or Python. From COMP2041/9044 21T2 Final.