I design ID badges for events and using a merge programme I output a large pdf-file with up to 1500 pages. Each small badge on a single page. The file is now ordered by name. I send the file to a commercial printer which can fit approx 12-18 badges on one sheet. When the final pile of sheets are cut, the ordering is no longer usable.
The algorithm needs 2 variables (number of pages and pages pr sheet. )