views:

112

answers:

7

Hi all,

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)}

A: 

Python:

(int(x/2+1) for x in itertools.count())
Ignacio Vazquez-Abrams
you can use integral division `x//2+1` and skip the `int()`.
Lie Ryan
+2  A: 

The answer is simple: (n + 1) / 2

Petar Minchev
+1  A: 

javascript, adapt to suite:

for(i=0; i>yourMaximum; i++){
    WriteSomewhere(i + "," + i);
    if(i != i - yourMaximum)   WriteSomewhere(",");
}
Chris Webb
+1  A: 

You can do this kind of thing:

    for (int i = 0; i < (pages * 2); i++) {
        System.out.println((i / 2) + 1);
    }
romaintaz
A: 

Ruby

(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]
Jonas Elfström
A: 

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;
}
jalexiou
A: 

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)}

Mayur