637 - Booklet Printing


Difficulty : easy

Solution Description :

Ad hoc problem

Notice that pages get printed in a sort of zigzag pattern. So for 12 pages:


12, 1
 2,11
10, 3
 4, 9
 8, 5
 6, 7


sheet = ceil(n/4)
set a=1 and b=sheet*4

now for i=1 to sheet
---Print for front b,a and b-- & a++  // here remember that if b is
greater than n then print blank
---print for back a,b and b-- & a++  // here remember that if b is
greater than n then print blank

This pattern holds for any number of pages > 1. When you have only 1
page, then you get a special case where you only use one side of the
piece of paper.