(defun demonstrate-permutation-network
(n steps
&key reference
+ offsets
(stream *standard-output*))
"Print, on STREAM, a demonstration of the permutation STEPS.
earliest unpaired `#' marker. The right hand side shows the arrangement
of the original input bits.
+ If OFFSETS is non-nil, then also print a table of offsets showing how far
+ each bit has yet to move.
+
If REFERENCE is not nil, then print a final pair of diagrams. This time,
the map shows `-' for correct bits and `x' for incorrect ones, with the
right hand side showing the expected arrangement of input bits.
stream)))
(write-string " | " stream)
+ (when offsets
+ (dotimes (j mapwd)
+ (let ((k (+ i j)))
+ (when (plusp j) (write-char #\space stream))
+ (cond ((>= k n)
+ (format stream "~v@T" (1+ ixwd)))
+ (t
+ (format stream "~*~[~2:*~vD~:;~2:*~v@D~]"
+ (1+ ixwd)
+ (- (aref end-inv (aref v k)) k))))))
+ (write-string " | " stream))
+
+ (dotimes (j (min mapwd (- n i)))
+ (let ((k (+ i j)))
+ (when (plusp j) (write-char #\space stream))
+ (format stream "~vD" ixwd (aref v k))))
+ (terpri))))
+
(fresh-line)
(show-stage 0 0 v)