Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #3062 > unrolled thread
| Started by | Guillermo Sanchez <guillermo.sanchez@hotmail.com> |
|---|---|
| First post | 2011-06-10 10:38 +0000 |
| Last post | 2011-06-12 09:07 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
Seaching in Pi a sequence. Looking for a faster method Guillermo Sanchez <guillermo.sanchez@hotmail.com> - 2011-06-10 10:38 +0000
Re: Seaching in Pi a sequence. Looking for a faster method rafapa <rafapa@us.es> - 2011-06-12 09:07 +0000
| From | Guillermo Sanchez <guillermo.sanchez@hotmail.com> |
|---|---|
| Date | 2011-06-10 10:38 +0000 |
| Subject | Seaching in Pi a sequence. Looking for a faster method |
| Message-ID | <isss68$jdf$1@smc.vnet.net> |
Dear Group
I have developed this function
piesimo[n_, m_, r_] := Module[{a}, a = Split[RealDigits[Pi - 3, 10, n]
[[1]]]; Part[Accumulate[Length /@ a], Flatten[Position[a, Table[m,
{r}]]] - 1] + 1]
n is the digits of Pi, after 3, where to search a sequence of m digit
r times consecutives.
For instance:
piesimo[10^7, 9, 7]
Gives that the sequence 9999999 happens in positions:
{1722776, 3389380, 4313727, 5466169}
I know that in this group I will find faster methods. Any idea?
Guillermo
[toc] | [next] | [standalone]
| From | rafapa <rafapa@us.es> |
|---|---|
| Date | 2011-06-12 09:07 +0000 |
| Message-ID | <it1vk4$b6q$1@smc.vnet.net> |
| In reply to | #3062 |
On Jun 10, 12:38 pm, Guillermo Sanchez <guillermo.sanc...@hotmail.com>
wrote:
> Dear Group
>
> I have developed this function
>
> piesimo[n_, m_, r_] := Module[{a}, a = Split[RealDigits[Pi - 3, 10, n]
> [[1]]]; Part[Accumulate[Length /@ a], Flatten[Position[a, Table[m,
> {r}]]] - 1] + 1]
>
> n is the digits of Pi, after 3, where to search a sequence of m digit
> r times consecutives.
> For instance:
>
> piesimo[10^7, 9, 7]
>
> Gives that the sequence 9999999 happens in positions:
>
> {1722776, 3389380, 4313727, 5466169}
>
> I know that in this group I will find faster methods. Any idea?
>
> Guillermo
What about
piesimoR[n_, m_String] := First /@
StringPosition[StringDrop[ToString[N[Pi, n]], 2], m]
piesimoR[10^7, "9999999"]//Timing
{4.04938, {1722776, 3389380, 4313727, 5466169}}
The original gave
piesimo[10^7, 9, 7]
{9.56055, {1722776, 3389380, 4313727, 5466169}}
If you intend to search several sequences it's better to save the
stringfied pi
pistring = StringDrop[ToString[N[Pi, 10^7]], 2];
piesimoS[m_String] := First /@ StringPosition[pistring, m]
piesimoS["9999999"]//Timing
{0.203969, {1722776, 3389380, 4313727, 5466169}}
piesimoS["1234567"]//Timing
{0.203969, {9470344}}
Rafael
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web