#! /usr/bin/gawk -f # Last edited on 1999-07-22 14:12:14 by stolfi # Usage: enum-folio-perms -v elems="XxYyZz..." # # Enumerates all physically valid permutations of a given list of folios. # Assumes "elems" is set to a string of letters that will be used to # identify the folios. Also assumes that folios 1,3,5,... # are attached to folios 2,4,6,... BEGIN { abort = -1; if (elems == "") { error("must define \"elems\""); } s = elems; split("", f); nf = length(s); for (i=0; i "/dev/stderr" if (nf+nh == 0) { print_perm(); return; } if (nh > 0) { # Fold in the last hanging folio: nh--; p[np] = h[nh]; np++; recurse(); np--; h[nh] = p[np]; nh++; } if (nf > 0) { # Place each folio in turn: for (i=0; i "/dev/stderr"; abort = 1; exit 1; }