lrobbo314
Well-known Member
- Joined
- Jul 14, 2008
- Messages
- 3,927
- Office Version
- 365
- Platform
- Windows
I was looking at this old challenge from @MrExcel, 'Perfect Shuffle Challenge'. It's from back in 2013. I thought that it would be fun to try this challenge with the new dynamic array formulas.
The objective is to see how many times you would need to do a perfect riffle shuffle in order for the deck to get back in its original order. I used 2 formulas. SHUFFLE, and RX, which is a recursive function.
SHUFFLE
RX
The objective is to see how many times you would need to do a perfect riffle shuffle in order for the deck to get back in its original order. I used 2 formulas. SHUFFLE, and RX, which is a recursive function.
SHUFFLE
Excel Formula:
=LAMBDA(deck,LET(d,deck,r,ROWS(d),s,SEQUENCE(r,,0),cc,HSTACK(TAKE(d,r/2),TAKE(d,-r/2)),INDEX(cc,QUOTIENT(s,2)+1,MOD(s,2)+1)))
RX
Excel Formula:
=LAMBDA(rng,[cnt],LET(s,SHUFFLE(rng),IF(AND(s=SEQUENCE(ROWS(s))),cnt+1,RX(s,cnt+1))))
PERFECT SHUFFLE | ||||
---|---|---|---|---|
H | I | |||
2 | 4 | 2 | ||
3 | 6 | 4 | ||
4 | 8 | 3 | ||
5 | 10 | 6 | ||
6 | 12 | 10 | ||
7 | 14 | 12 | ||
8 | 16 | 4 | ||
9 | 18 | 8 | ||
10 | 20 | 18 | ||
11 | 22 | 6 | ||
12 | 24 | 11 | ||
13 | 26 | 20 | ||
14 | 28 | 18 | ||
15 | 30 | 28 | ||
16 | 32 | 5 | ||
17 | 34 | 10 | ||
18 | 36 | 12 | ||
19 | 38 | 36 | ||
20 | 40 | 12 | ||
21 | 42 | 20 | ||
22 | 44 | 14 | ||
23 | 46 | 12 | ||
24 | 48 | 23 | ||
25 | 50 | 21 | ||
26 | 52 | 8 | ||
27 | 54 | 52 | ||
28 | 56 | 20 | ||
29 | 58 | 18 | ||
30 | 60 | 58 | ||
31 | 62 | 60 | ||
32 | 64 | 6 | ||
33 | 66 | 12 | ||
34 | 68 | 66 | ||
35 | 70 | 22 | ||
Sheet1 |
Cell Formulas | ||
---|---|---|
Range | Formula | |
H2:H301 | H2 | =SEQUENCE(300,,4,2) |
I2:I35 | I2 | =RX(SEQUENCE(H2)) |
Dynamic array formulas. |