找出 π 的数位序列
全新函数 SequenceCases、SequencePosition 和 SequenceCount 为使用模式匹配提取序列提供了全新功能.
找出在 π 的小数位中出现的 Mathematica 首次发布的日期.
In[1]:=
![Click for copyable input](assets.zh/find-a-sequence-in-the-digits-of-pi/In_26.png)
EntityValue[
Entity["ProgrammingLanguage", "WolframLanguage"], "DateIntroduced"]
Out[1]=
![](assets.zh/find-a-sequence-in-the-digits-of-pi/O_36.png)
将这些日期改变为符合该查询的格式.
In[2]:=
![Click for copyable input](assets.zh/find-a-sequence-in-the-digits-of-pi/In_27.png)
EntityValue[
Entity["ProgrammingLanguage", "WolframLanguage"], "DateIntroduced"];
date = Characters[DateString[%, {"Month", "Day", "YearShort"}]]
Out[2]=
![](assets.zh/find-a-sequence-in-the-digits-of-pi/O_37.png)
生成 π 的前 300 万个小数位.
In[3]:=
![Click for copyable input](assets.zh/find-a-sequence-in-the-digits-of-pi/In_28.png)
pi = Characters[ToString@N[Pi, 3000000]];
SequencePosition 给出格式化后的日期的开始和结束位置.
In[4]:=
![Click for copyable input](assets.zh/find-a-sequence-in-the-digits-of-pi/In_29.png)
pos = SequencePosition[pi, date]
Out[4]=
![](assets.zh/find-a-sequence-in-the-digits-of-pi/O_38.png)
在 π 的前 300 万个小数位中其仅出现过一次. 可以用 Grid 对象简单表示.
显示完整的 Wolfram 语言输入
In[6]:=
![Click for copyable input](assets.zh/find-a-sequence-in-the-digits-of-pi/In_31.png)
Grid[Partition[chars, 8]]
Out[6]=
![](assets.zh/find-a-sequence-in-the-digits-of-pi/O_39.png)
测试其他日期并在此找出自己的 π 日!