Re: Consecutive runs in mathematica
From: Tony King (mathstutoring_at_ntlworld.com)
Date: 03/09/05
- Next message: Richard Fateman: "Re: EE Student, Edit, Proposal Masters, Help (concepts of functional programming, symbolic programming and MATLAB)"
- Previous message: Joachim Durchholz: "Re: EE Student, Edit, Proposal Masters, Help (concepts of functional programming, symbolic programming and MATLAB)"
- In reply to: Dana: "Re: Consecutive runs in mathematica"
- Next in thread: Peter Pein: "Re: Consecutive runs in mathematica"
- Reply: Peter Pein: "Re: Consecutive runs in mathematica"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 09 Mar 2005 14:38:50 GMT
Thank you - I have modified your code slightly and it seems to be working
perfectly
In[72]:=
v = Table[trialQ[k], {k, 1, 1000000}];
In[73]:=
t = Split[v];
({Max[(If[First[#1] === True, Length[#1], 0] & ) /@ t],
Max[(If[First[#1] === False, Length[#1], 0] & ) /@ t]}) // Timing
Out[74]=
{4.157 Second, {5, 2}}
"Dana" <delouis@bellsouth.net> wrote in message
news:haCXd.10644$c72.2059@bignews3.bellsouth.net...
> Don't know if this would be efficient for a large array (million terms),
> but here is one way. I understand your "true/false" to be variables, and
> not the built-in True & False.
>
> v = {true, true, false, true, true, true, false, true};
>
> t = Split[v]
> {{true, true}, {false}, {true, true, true}, {false}, {true}}
>
> Max[(If[First[#1] === true, Length[#1], 0] & ) /@ t]
> 3
>
> Max[(If[First[#1] === false, Length[#1], 0] & ) /@ t]
> 1
>
>
> --
> Dana DeLouis
> Win XP & Office 2003
>
>
> "Tony King" <mathstutoring@ntlworld.com> wrote in message
> news:hiBXd.138$194.116@newsfe2-gui.ntli.net...
>>I have a list which looks something like
>>
>> {true,true,false,true,true,true,false,true.........}
>>
>> that contains something like a million terms, and I would like some code
>> to return the maximum length of consecutive runs of trues and the maximum
>> length of consecutive runs of false.
>>
>> Any ideas / assistance would be greatly appreciated.
>>
>> Best wishes
>>
>> Tony
>>
>
>
- Next message: Richard Fateman: "Re: EE Student, Edit, Proposal Masters, Help (concepts of functional programming, symbolic programming and MATLAB)"
- Previous message: Joachim Durchholz: "Re: EE Student, Edit, Proposal Masters, Help (concepts of functional programming, symbolic programming and MATLAB)"
- In reply to: Dana: "Re: Consecutive runs in mathematica"
- Next in thread: Peter Pein: "Re: Consecutive runs in mathematica"
- Reply: Peter Pein: "Re: Consecutive runs in mathematica"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|