From e7ee4000d06cadd8355404c8ddfb3d16265d24ca Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Sat, 3 Feb 2024 23:34:13 +0000 Subject: [PATCH] utils/permute.lisp (demonstrate-permutation-network): Optionally show offsets. Add an option to print a table showing how far each bit has still to move. This can be helpful for understanding some permutations. Others, not so much. --- utils/permute.lisp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/utils/permute.lisp b/utils/permute.lisp index ee81bb36..884068ac 100644 --- a/utils/permute.lisp +++ b/utils/permute.lisp @@ -207,6 +207,7 @@ (defun demonstrate-permutation-network (n steps &key reference + offsets (stream *standard-output*)) "Print, on STREAM, a demonstration of the permutation STEPS. @@ -218,6 +219,9 @@ 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. @@ -260,6 +264,24 @@ 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) -- 2.11.0