Re: Re: Super-Increasing List
- To: mathgroup at smc.vnet.net
- Subject: [mg40472] Re: [mg40456] Re: Super-Increasing List
- From: Dr Bob <majort at cox-internet.com>
- Date: Mon, 7 Apr 2003 04:54:18 -0400 (EDT)
- References: <200304060834.EAA01887@smc.vnet.net>
- Reply-to: majort at cox-internet.com
- Sender: owner-wri-mathgroup at wolfram.com
Bill,
If you're going to test for property (a) first, you should do it this way
instead:
superIncreasingQ[data_List] :=
OrderedQ[data] && And @@ Flatten[
MapThread[OrderedQ[{#1, #2}] &, {Drop[FoldList[Plus, 0, data], -1],
data}]]
The other way, MapThread will be executed to check property (b) even if the
list has already flunked the test for property (a). If we knew which test
is more likely to fail lists we'll encounter, we should put that test
first. If we knew that most lists will pass test (a) but many will fail
test (b), we'd write it as
superIncreasingQ[data_List] :=
And[And @@ Flatten[
MapThread[OrderedQ[{#1, #2}] &, {Drop[FoldList[Plus, 0, data], -1],
data}]],
OrderedQ[data]]
Also, MapThread and FoldList are computed all the way to the end of the
list, even if the very first comparison will fail.
Bobby
On Sun, 6 Apr 2003 04:34:30 -0400 (EDT), Bill Rowe <listuser at earthlink.net>
wrote:
> On 4/5/03 at 4:00 AM, flip_alpha at safebunch.com (flip) wrote:
>
>
>> does a command or module exist which can test a list of values and
>> determine if it is a super-increasing list?
>
>> A super-increasing list satifies the conditions:
>
>> a. the list is in increasing order
>> b. each element of the list is greater than the sum of it's previous
>> elements
>
>> Example:
>
>> list = {2, 3, 7, 15, 31}
>
> SuperIncreasingQ[data_List] :=
> And @@ Flatten[{OrderedQ[data],
> MapThread[OrderedQ[{#1, #2}] &, {Drop[FoldList[Plus, 0, data], -1],
> data}]}]
> SuperIncreasingQ[list]
> True
>
>
--
majort at cox-internet.com
Bobby R. Treat
- References:
- Re: Super-Increasing List
- From: Bill Rowe <listuser@earthlink.net>
- Re: Super-Increasing List