Re: Consecutive runs in mathematica
From: Peter Pein (petsie_at_arcor.de)
Date: 03/11/05
- Previous message: John Creighton: "Re: EE Student, Edit, Proposal Masters, Help (concepts of functional programming, symbolic programming and MATLAB)"
- In reply to: Dana: "Re: Consecutive runs in mathematica"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 11 Mar 2005 04:29:09 +0100
Dana wrote:
> Thanks Peter. Very nice. I've tried to study the Repeated pattern object,
> but never quite got it down. I'll study this example for sure. Thanks
> again. :>).
>
> Off topic I know, but as a side note, I tried your code with the following.
> Your code was faster than what I had from before. :>)
> What this little example does is look at the first 100,000 digits of Pi, and
> determines that the number '9 had a run of 6 positions. This was slightly
> more than the other digits.
> Again, off topic, but I was curious on your time. :>)
>
> t = Split[RealDigits[Pi, 10, 100000][[1]]];
> Timing[Apply[Max, (Cases[t, lst:{#1..} :> Length[lst]] & ) /@ Range[0, 9],
> {1}]]
> {0.39*Second, {5, 5, 5, 5, 4, 5, 5, 4, 4, 6}}
>
Dear Dana,
My timing for your example is 0.434 seconda.
But to be serious, we have to take the total time for generating the
list t and for the examination:
Your code gives on my box:
Timing[
t = Split[RealDigits[Pi, 10, 100000][[1]]];
Apply[Max, (Cases[t, lst:{#1..} :> Length[lst]] & ) /@
Range[0, 9], {1}]
]
{0.515 Second,{5,5,5,5,4,5,5,4,4,6}}
and making it easier for Cases[] by applying Union[] to t:
Timing[
t = Union[Split[RealDigits[Pi, 10, 100000][[1]]]];
Apply[Max, (Cases[t, lst:{#1..} :> Length[lst]] & ) /@
Range[0, 9], {1}]
]
{0.203 Second,{5,5,5,5,4,5,5,4,4,6}}
-- Peter Pein Berlin
- Previous message: John Creighton: "Re: EE Student, Edit, Proposal Masters, Help (concepts of functional programming, symbolic programming and MATLAB)"
- In reply to: Dana: "Re: Consecutive runs in mathematica"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|