我的朋友向我提出了这个问题;感觉很想在这里分享。
给定一副牌,我们将其分成两组,并“将它们交错排列”;让我们将此操作称为“拆分连接”。并在生成的牌组上重复相同的操作。
例如,{ 1, 2, 3, 4 } 变为 { 1, 2 } & { 3, 4 } (拆分) 我们得到 { 1, 3, 2, 4 } (合并) >
此外,如果我们有奇数张牌,即 { 1, 2, 3 },我们可以像 { 1, 2 } & 那样将其拆分。 { 3 }(较大的一半在前)通向 { 1, 3, 2 }
(即,n
分为 Ceil[n/2]
和 n-Ceil[n/2]
)
我朋友的问题问我的是:
需要多少这样的拆分连接才能恢复原始牌组?
这让我想知道:
,则需要多少分割连接
- 如果这副牌有 n 张牌,如果n 是偶数
- ? n 是奇数吗?
- n 是 '2' 的幂吗? [我发现我们需要 log (n) (base 2) 分割连接数...]
- (随意探索这样的不同场景。)
是否有一个简单的模式/公式/ n 与所需拆分连接数量相关的概念?
我相信,这是在 Mathematica 中探索的一件好事,特别是因为它提供了 Riffle[] 方法。
My friend posed this question to me; felt like sharing it here.
Given a deck of cards, we split it into 2 groups, and "interleave them"; let us call this operation a 'split-join'. And repeat the same operation on the resulting deck.
E.g., { 1, 2, 3, 4 } becomes { 1, 2 } & { 3, 4 } (split) and we get { 1, 3, 2, 4 } (join)
Also, if we have an odd number of cards i.e., { 1, 2, 3 } we can split it like { 1, 2 } & { 3 } (bigger-half first) leading to { 1, 3, 2 }
(i.e., n
is split up as Ceil[n/2]
& n-Ceil[n/2]
)
The question my friend asked me was:
HOW many such split-joins are needed to get the original deck back?
And that got me wondering:
If the deck has n cards, what is the number of split-joins needed if:
- n is even ?
- n is odd ?
- n is a power of '2' ? [I found that we then need log (n) (base 2) number of split-joins...]
- (Feel free to explore different scenarios like that.)
Is there a simple pattern/formula/concept correlating n and the number of split-joins required?
I believe, this is a good thing to explore in Mathematica, especially, since it provides the Riffle[]
method.
发布评论
评论(4)
引用MathWorld:
未解决
n
为奇数的情况。请注意,本文还包括一个具有探索 out-shuffle 功能的 Mathematica 笔记本。
To quote MathWorld:
The case when
n
is odd isn't addressed.Note that the article also includes a Mathematica notebook with functions to explore out-shuffles.
如果我们有奇数张牌
n==2m-1
,并且如果我们将牌分开,使得在每次洗牌期间第一组包含m
张牌,第二组包含m
张牌m-1
张牌,并且将组连接起来,使得同一组中没有两张牌彼此相邻,则所需的洗牌次数等于MultiplicativeOrder[2, n ]
。为了说明这一点,我们注意到,在洗牌一次后,位于位置
k
的卡片已移动到位置2k
,其中0<=k并为
2k-2m+1
表示m<=k<2m-1
,其中k
是这样的0<=k<2m-1
。写为模n==2m-1
,这意味着对于所有0<=k,新位置为
Mod[2k, n]
。因此,为了让每张牌返回到其原始位置,我们需要N
次洗牌,其中N
满足Mod[2^N k, n]==Mod[ k, n]
对于所有0<=k ,其中
N
是MultiplicativeOrder[2, n]< 的任意倍数/代码>。
请注意,由于对称性,如果我们以相反的方式拆分牌组,结果将完全相同,即第一组始终包含
m-1
卡,第二组始终包含m< /code> 卡。我不知道如果你交替的话会发生什么,即对于奇数洗牌,第一组包含
m
卡,对于偶数洗牌m-1
卡。If we have an odd number of cards
n==2m-1
, and if we split the cards such that during each shuffle the first group containsm
cards, the second groupm-1
cards, and the groups are joined such that no two cards of the same group end up next to each other, then the number of shuffles needed is equal toMultiplicativeOrder[2, n]
.To show this, we note that after one shuffle the card which was at position
k
has moved to position2k
for0<=k<m
and to2k-2m+1
form<=k<2m-1
, wherek
is such that0<=k<2m-1
. Written modulon==2m-1
this means that the new position isMod[2k, n]
for all0<=k<n
. Therefore, for each card to return to its original position we needN
shuffles whereN
is such thatMod[2^N k, n]==Mod[k, n]
for all0<=k<n
from which is follows thatN
is any multiple ofMultiplicativeOrder[2, n]
.Note that due to symmetry the result would have been exactly the same if we had split the deck the other way around, i.e. the first group always contains
m-1
cards and the second groupm
cards. I don't know what would happen if you alternate, i.e. for odd shuffles the first group containsm
cards, and for even shufflesm-1
cards.魔术师/数学家 Persi Diaconnis 的旧作讲述了如何通过完美的 riffle shuffle 来恢复顺序。 Ian Stewart 在他 1998 年《科学美国人》数学休闲专栏中写到了这项工作 - 请参阅,例如: http://www.whydomath.org/Reading_Room_Material/ian_stewart/shuffle/shuffle.html
There's old work by magician/mathematician Persi Diaconnis about restoring the order with perfect riffle shuffles. Ian Stewart wrote about that work in one of his 1998 Scientific American Mathematical Recreation columns -- see, e.g.: http://www.whydomath.org/Reading_Room_Material/ian_stewart/shuffle/shuffle.html
我知道老问题,但奇怪的是没有人提出实际的数学解决方案。
这处理偶数和奇数情况:
您可以很容易地证明,如果您将一张牌添加到奇数情况下,多余的牌将保留在底部并且不会改变顺序,因此奇数情况结果只是
n+1
偶数结果..old question I know, but strange no one put up an actual mathematica solution..
This handles even and odd cases:
You can readily show if you add a card to the odd-case the extra card will stay on the bottom and not change the sequence, hence the odd case result is just the
n+1
even result..