Reputation: 3097
I've an variable as page number (page) whose values increment by one each time. [Page numbering] But, now I need to customize this numbering to 1,1,2,2,3,3..
Can you suggest any formula for generate this kind of series?
EDIT: (Answer)
After playing with macros and VBA for some time I've figured out a way to generate this type of series for MS word page numbers. This can be easily done with formulas and {Page} variable in word with formula-
{=(({PAGE} + MOD({PAGE},2))/2)}
Upvotes: 0
Views: 6741
Reputation: 46
It is late, but it might help someone.
A mathematical answer to the problem:
You do not need to search through all n numbers in order to have a specific result
1 2 3 4 5 6 7 8 9 . . . . . . . n
1 1 2 2 3 3 4 4 5 . . . . . . . f(n)
General formula:
f(n) = ( n - ( (-1) + (-1)^n )/2 )/2
Playing with the first (-1) you can shift the results like this:
f(n) = ( n - ( (3) + (-1)^n )/2 )/2
1 2 3 4 5 6 7 8 9 . . . . . . . n
0 0 1 1 2 2 3 3 4 . . . . . . . f(n)
Upvotes: 1
Reputation: 3097
After playing with macros and VBA for some time I've figured out a way to generate this type of series for MS word page numbers. This can be easily done with formulas and {Page} variable in word with formula-
{=(({PAGE} + MOD({PAGE},2))/2)}
Upvotes: 0
Reputation: 29264
C#, not a formula but a simplistic algorithm.
int[] pages = new int[2*N];
for(i=0; i<N; i++)
{
page[2*i] = i+1;
page[2*i+1] = i+2;
}
Upvotes: 0
Reputation: 31438
(1..10).map {|n| [n,n]}.flatten
=> [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]
or
(1..10).inject([]) {|m,n| m<<n<<n}
=> [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]
or
(1..10*2).map {|n| (1+n)/2}
=> [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]
Upvotes: 0
Reputation: 81647
You can do this kind of thing:
for (int i = 0; i < (pages * 2); i++) {
System.out.println((i / 2) + 1);
}
Upvotes: 1
Reputation: 796
javascript, adapt to suite:
for(i=0; i>yourMaximum; i++){
WriteSomewhere(i + "," + i);
if(i != i - yourMaximum) WriteSomewhere(",");
}
Upvotes: 1