Mathematica 78 53个字符
尽管未经证实,但Pi的二进制表示形式的数字似乎表现得好像是混沌生成的。
以下简单例程确定性地返回pi的二进制数字(对应于d
十进制数字)作为字符串:
f[d_]:=ToString@FromDigits@RealDigits[N[Pi,d],2][[1]]
用法
如果我们要求Pi的301个十进制数字的对端,我们将接收1000个二进制数字。
f[301]
StringLength[%]
(* out *)
1100100100001111110110101010001000100001011010001100001000110100110001001100011001100010100010111000000011011100000111001101000100101001000000100100111000001000100010100110011111001100011101000000001000001011101111101010011000111011000100111001101100100010010100010100101000001000011110011000111000110100000001001101110111101111100101010001100110110011110011010011101001000011000110110011000000101011000010100110110111110010010111110001010000110111010011111110000100110101011011010110110101010001110000100100010111100100100001011011010101110110011000100101111001111110110001101111010001001100010000101110100110100110001101111110110101101011000010111111111101011100101101101111010000000110101101111110110111101110001110000110101111111011010110101000100110011111101001011010111010011111001001000001000101111100010010110001111111100110010010010010100001100110010100011110110011100100010110110011110111000010000000000111110010111000101000010110001110111111000001011001100011011010010010000011011000011100011
1000 (* characters *)
因为Pi是一个无理数,所以没有句号。但是,由于硬件正在运行,因此会有实际的限制。
测试1
对我来说看起来不错。
测试2
d=301;
Partition[RealDigits[N[Pi,d],2][[1]],{3}];
Tally[%]
(* out *)
{{{1,1,0},35},{{0,1,0},45},{{0,0,0},41},{{1,1,1},40},
{{0,1,1},50},{{1,0,1},32},{{1,0,0},43},{{0,0,1},47}}
更彻底的检查:
d=10^6;
Partition[RealDigits[N[Pi,d],2][[1]],{3}];
Tally[%]
{{{1,1,0},138565},{{0,1,0},138146},{{0,0,0},138260},{{1,1,1},138427},
{{0,1,1},139119}, {{1,0,1},138404},{{1,0,0},137926},{{0,0,1},138462}}
测试3:运行
d=10^6;
res3=SortBy[Tally@Split@RealDigits[N[Pi,d],2][[1]],Last]/.{a_,b_}:> {Length[a],b}
ListPlot[res3 ,AxesLabel-> {"Run Length","Runs"},AxesOrigin->{0,0}]
我运行了很多案例来系统地检查运行的分布。在大约300万个二进制数字中,有830k个运行1,1,416k个运行2,208k个运行3,104k个运行4,等等。
测试4:数据的前半部分和后半部分的匹配
匹配为0和2的212个案例;不匹配是208个案例,其中各个数字的总和为1。
d=301;
Tally[Plus@@Partition[Take[RealDigits[N[Pi,d],2][[1]],840],420]]
(* out *)
{{1,208},{0,108},{2,104}}
定时
计算3321928个二进制数字(对应于10 ^ 6个十进制数字)需要不到2秒的时间。
(r=f[10^6]);//AbsoluteTiming
StringLength[r]
(*out*)
{1.785928,Null}
3321928