生成系列 1,1,2,2,3,3,

发布于 2024-09-27 02:52:48 字数 268 浏览 1 评论 0原文

我有一个变量作为页码(页),其值每次递增一。 [页码编号]但是,现在我需要将此编号自定义为1,1,2,2,3,3..

您能建议任何生成此类系列的公式吗?

编辑:(答案)

在使用宏和 VBA 一段时间后,我找到了一种为 MS Word 页码生成此类系列的方法。这可以通过公式和 Word 中的 {Page} 变量轻松完成,公式为 -

{=(({PAGE} + MOD({PAGE},2))/2)}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

我们的影子 2024-10-04 02:52:48

答案很简单:(n + 1) / 2

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

骄傲 2024-10-04 02:52:48

javascript,适应套件:

for(i=0; i>yourMaximum; i++){
    WriteSomewhere(i + "," + i);
    if(i != i - yourMaximum)   WriteSomewhere(",");
}

javascript, adapt to suite:

for(i=0; i>yourMaximum; i++){
    WriteSomewhere(i + "," + i);
    if(i != i - yourMaximum)   WriteSomewhere(",");
}
不忘初心 2024-10-04 02:52:48

你可以做这样的事情:

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

You can do this kind of thing:

    for (int i = 0; i < (pages * 2); i++) {
        System.out.println((i / 2) + 1);
    }
狼亦尘 2024-10-04 02:52:48

虽然已经晚了,但可能会对某人有所帮助。

问题的数学答案

您无需搜索所有 n 个数字即可获得特定结果

1 2 3 4 5 6 7 8 9 。 。 。 。 。 。 。 n

1 1 2 2 3 3 4 4 5 。 。 。 。 。 。 。 f(n)

一般公式:

f(n) = ( n - ( (-1) + (-1)^n )/2 )/2

使用第一个 (-1 )您可以这样转换结果:

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)

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)

暗藏城府 2024-10-04 02:52:48

Python:

(int(x/2+1) for x in itertools.count())

Python:

(int(x/2+1) for x in itertools.count())
星星的轨迹 2024-10-04 02:52:48

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]

(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]

(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]

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]
纵山崖 2024-10-04 02:52:48

C#,不是一个公式,而是一个简单的算法。

int[] pages = new int[2*N];
for(i=0; i<N; i++)
{
    page[2*i] = i+1;
    page[2*i+1] = i+2;
}

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;
}
迷鸟归林 2024-10-04 02:52:48

在使用宏和 VBA 一段时间后,我找到了一种为 MS Word 页码生成此类系列的方法。这可以通过公式和 Word 中的 {Page} 变量轻松完成,公式为 -

{=(({PAGE} + MOD({PAGE},2))/2)}

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文