Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #3063 > unrolled thread

Re: Seaching in Pi a sequence. Looking for a faster method

Started byDrMajorBob <btreat1@austin.rr.com>
First post2011-06-11 07:58 +0000
Last post2011-06-11 07:58 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Seaching in Pi a sequence. Looking for a faster method DrMajorBob <btreat1@austin.rr.com> - 2011-06-11 07:58 +0000

#3063 — Re: Seaching in Pi a sequence. Looking for a faster method

FromDrMajorBob <btreat1@austin.rr.com>
Date2011-06-11 07:58 +0000
SubjectRe: Seaching in Pi a sequence. Looking for a faster method
Message-ID<isv76c$5p$1@smc.vnet.net>
This corrects the Dispatch table from my earlier solution (it wasn't  
general enough).

It also uses Sow, Reap, and Scan rather than Position, Part, and  
Accumulate.

It's not as fast as the other solution, but it's interesting.

Quit

piesimo3[n_, m_, r_] :=
  Module[{d = Dispatch@Thread[DeleteCases[Range[0, 9], m] -> -1],
    count = 1},
   First@Last@
     Reap@Scan[(Length@# == r && First@# == m && Sow@count;
         count += Length@#) &,
       Split[RealDigits[Pi - 3, 10, n][[1]] /. d]]
   ]
Timing@piesimo3[10^7, 9, 7]

{38.6643, {1722776, 3389380, 4313727, 5466169}}

Bobby

On Fri, 10 Jun 2011 05:38:05 -0500, Guillermo Sanchez  
<guillermo.sanchez@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
>
>


-- 
DrMajorBob@yahoo.com

[toc] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web