Re: Consecutive runs in mathematica
From: Dana (delouis_at_bellsouth.net)
Date: 03/09/05
- Next message: Joachim Durchholz: "Re: EE Student, Edit, Proposal Masters, Help (concepts of functional programming, symbolic programming and MATLAB)"
- Previous message: Tony King: "Consecutive runs in mathematica"
- In reply to: Tony King: "Consecutive runs in mathematica"
- Next in thread: Tony King: "Re: Consecutive runs in mathematica"
- Reply: Tony King: "Re: Consecutive runs in mathematica"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 9 Mar 2005 07:41:41 -0500
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: Joachim Durchholz: "Re: EE Student, Edit, Proposal Masters, Help (concepts of functional programming, symbolic programming and MATLAB)"
- Previous message: Tony King: "Consecutive runs in mathematica"
- In reply to: Tony King: "Consecutive runs in mathematica"
- Next in thread: Tony King: "Re: Consecutive runs in mathematica"
- Reply: Tony King: "Re: Consecutive runs in mathematica"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|