forked from numberscope/backscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch-A321580.json
111 lines (111 loc) · 5.38 KB
/
search-A321580.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
{
"greeting": "Greetings from The On-Line Encyclopedia of Integer Sequences! http://oeis.org/",
"query": "A321580",
"count": 2,
"start": 0,
"results": [
{
"number": 321580,
"data": "1,2,4,8,10,12,16,18,24,26,28,32,36,40,42,52,56,58,60,64,66,80,82,96,98,100,106,108,112,120,124,128,130,136,138,144,148,156,162,168,170,172,176,178,180,184,192,196,200,204,208,210,226,228,240,242,248,250",
"name": "Numbers k such that it is possible to reverse a deck of k cards by a sequence of perfect Faro shuffles with cut.",
"comment": [
"Except for 1, it isn't possible to shuffle backwards an odd number of cards."
],
"link": [
"Andrew Howroyd, \u003ca href=\"/A321580/b321580.txt\"\u003eTable of n, a(n) for n = 1..2000\u003c/a\u003e",
"Wikipedia, \u003ca href=\"https://en.wikipedia.org/wiki/Faro_shuffle\"\u003eFaro shuffle\u003c/a\u003e"
],
"example": [
"For a deck of 4 cards we'll have the following sequence of shuffles: 1234, 2413, 4321, 3142, 1234. Observe that the reverse order (4321) of 1234 appears in the sequence of shuffles.",
"For a deck of 5 cards: 12345, 24135, 43215, 31425, 12345. Observe that the reverse order (54321) of 12345 does not appear in the sequence of shuffles."
],
"program": [
"(Python)",
"for n in range(1, 501):",
" cards = [i for i in range(1, n + 1)]",
" reverse = cards[::-1]",
" shuffled = cards.copy()",
" reversein = False",
" for i in range(n):",
" evens = shuffled[1::2]",
" odds = shuffled[0::2]",
" shuffled = evens + odds",
" if shuffled == reverse:",
" reversein = True",
" print(n, end=\", \")",
" break",
"(PARI)",
"shuffle(v)={my(h=#v\\2); vector(#v, i, if(i\u003c=h, 2*i, 2*(i-h)-1))}",
"permcycs(v)={my(f=vector(#v), L=List()); for(i=1, #v, if(!f[i], my(T=List(), j=i); while(!f[j], f[j]=1; listput(T,j); j=v[j]); listput(L, Vec(T)))); Vec(L)}",
"ok(n)={my(v=permcycs(shuffle([1..n])), e=-1); for(k=1, #v, my(p=v[k]); if(#p\u003e1||n%2==0||2*p[1]\u003c\u003en+1, my(h=#p\\2); if(e\u003c0, e=valuation(#p,2)); if(valuation(#p,2)\u003c\u003ee || e==0 || p[1..h]+p[h+1..2*h]\u003c\u003evector(h,i,n+1), return(0)))); 1} \\\\ _Andrew Howroyd_, Nov 13 2018"
],
"xref": [
"Cf. A024222, A071642, A321512."
],
"keyword": "nonn",
"offset": "1,2",
"author": "_Pedro Menezes_, Nov 13 2018",
"references": 2,
"revision": 26,
"time": "2023-03-21T18:09:02-04:00",
"created": "2018-11-14T01:47:43-05:00"
},
{
"number": 321512,
"data": "1,1,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,1,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,1",
"name": "Characteristic function of the reverse in the shuffle (perfect faro shuffle with cut): 1 if the sequence of shuffles of n cards contains the reverse of the original order of cards, 0 if not.",
"comment": [
"The characteristic function of A321580: 1 if in the sequence of Faro's shuffle of n cards there is at some point the exact reverse of the initial order (the cards are backwards); 0 if not."
],
"link": [
"Antti Karttunen, \u003ca href=\"/A321512/b321512.txt\"\u003eTable of n, a(n) for n = 1..65537\u003c/a\u003e",
"\u003ca href=\"/index/Ch#char_fns\"\u003eIndex entries for characteristic functions\u003c/a\u003e"
],
"example": [
"For example, for n = 4, we have the following sequence of shuffles:",
" c(1) = 1234 \u003c- initial order of cards",
" c(2) = 2413",
" c(3) = 4321 \u003c- here's the reverse of c(1)",
" c(4) = 3142",
" c(5) = 1234",
"Hence the characteristic function at n = 4 is 1.",
"For n = 5,",
" c(1) = 12345",
" c(2) = 24135",
" c(3) = 43215",
" c(4) = 31425",
" c(5) = 12345",
"Observe that for n = 5, there's no 54321 in the c(i) sequence, so the characteristic function at n = 5 is 0."
],
"program": [
"(Python)",
"for n in range(1, 101):",
" cards = [i for i in range(1, n + 1)]",
" reverse = cards[::-1]",
" shuffled = cards.copy()",
" reversein = False",
" for i in range(n):",
" evens = shuffled[1::2]",
" odds = shuffled[0::2]",
" shuffled = evens + odds",
" if shuffled == reverse:",
" reversein = True",
" print(n, int(reversein))",
"(PARI)",
"shuffle(v) = {my(h=#v\\2); vector(#v, i, if(i\u003c=h, 2*i, 2*(i-h)-1))};",
"permcycs(v) = {my(f=vector(#v), L=List()); for(i=1, #v, if(!f[i], my(T=List(), j=i); while(!f[j], f[j]=1; listput(T, j); j=v[j]); listput(L, Vec(T)))); Vec(L)};",
"A321512(n)={my(v=permcycs(shuffle([1..n])), e=-1); for(k=1, #v, my(p=v[k]); if(#p\u003e1||n%2==0||2*p[1]\u003c\u003en+1, my(h=#p\\2); if(e\u003c0, e=valuation(#p, 2)); if(valuation(#p, 2)\u003c\u003ee || e==0 || p[1..h]+p[h+1..2*h]\u003c\u003evector(h, i, n+1), return(0)))); 1}; \\\\ This is _Andrew Howroyd_'s Nov 13 2018 code for the characteristic function of A321580, given under that entry with the name \"ok\". Copied here by _Antti Karttunen_, Dec 06 2021"
],
"xref": [
"Cf. A024222, A123320, A049206, A321580."
],
"keyword": "nonn",
"offset": "1",
"author": "_Pedro Menezes_, Nov 11 2018",
"references": 2,
"revision": 24,
"time": "2023-05-03T15:03:28-04:00",
"created": "2018-11-14T01:48:07-05:00"
}
]
}