Hi all,
I am trying to write a program that simulates scanning pages one side then the other to simulate a duplex scan and then reorder the pages into their logical sequence.
For example
if I scan a bunch pages in the order 1,3,5 then the other side 6,4,2. The second scan you flip the pages so it starts at the last page hence the 6,4,2 sequence. I end up with the page number in order of 1,3,5,6,4,2 with only swapping the numbers I want the sequence to be 1,2,3,4,5,6. (It must swap as the class won't allow adding, inserting removing.)
I have run through a few examples manually below but apart from the start of the swaps being the same I can't see a pattern that I can use to put this into a formula and loop. The numbers below show the scan sequence for various stack size of pages, the next column is the swap order to get them aligned. The next line show the swapped pages and then the next swap sequence
Does anyone see a pattern or better still have an algorithm?
2 sheets of paper 4 sides
1,3,4,2 : 2-4
1,2,4,3 : 3-4
1,2,3,4
3 sheets of paper 6 sides
1,3,5,6,4,2 : 2-6
1,2,5,6,4,3 : 3-6
1,2,3,6,4,5 : 4-5
1,2,3,4,6,5 : 5-6
1,2,3,4,5,6
4 sheets of paper 8 sides
1,3,5,7,8,6,4,2 : 2-8
1,2,5,7,8,6,4,3 : 3-8
1,2,3,7,8,6,4,5 : 4-7
1,2,3,4,8,6,7,5 : 5-8
1,2,3,4,5,6,7,8
5 sheets of paper 10 sides
1,3,5,7,9,10,8,6,4,2 : 2-10
1,2,5,7,9,10,8,6,4,3 : 3-10
1,2,3,7,9,10,8,6,4,5 : 4-9
1,2,3,4,9,10,8,6,7,5 : 5-10
1,2,3,4,5,10,8,6,7,9 : 6-8
1,2,3,4,5,6,8,10,7,9 : 7-9
1,2,3,4,5,6,7,10,8,9 : 8-9
1,2,3,4,5,6,7,8,10,9 : 9-10
1,2,3,4,5,6,7,8,9,10
6 sheets of paper 12 sides
1,3,5,7,9,11,12,10,8,6,4,2 : 2-12
1,2,5,7,9,11,12,10,8,6,4,3 : 3-12
1,2,3,7,9,11,12,10,8,6,4,5 : 4-11
1,2,3,4,9,11,12,10,8,6,7,5 : 5-12
1,2,3,4,5,11,12,10,8,6,7,9 : 6-10
1,2,3,4,5,6,12,10,8,11,7,9 : 7-9
1,2,3,4,5,6,7,10,8,11,12,9 : 8-9
1,2,3,4,5,6,7,8,10,11,12,9 : 9-12
1,2,3,4,5,6,7,8,9,11,12,10 : 10-12
1,2,3,4,5,6,7,8,9,10,12,11 : 11-12
1,2,3,4,5,6,7,8,9,10,11,12