Re: Sum of list?
Re: Sum of list?
- Subject: Re: Sum of list?
- From: Graff <email@hidden>
- Date: Mon, 28 Jun 2004 21:15:49 -0400
I don't know of any implementations of summation algorithms that don't
do some sort of iteration in order to sum up a 1-D array (list) of
integers. The best you can do is to keep the loop as simple as
possible:
----
set theList to {1, 2, 3}
set theCount to length of theList
set theSum to 0
repeat with i in theList
set theSum to theSum + i
end repeat
set theAverage to theSum / theCount
{theSum, theAverage}
----
If you are dealing with very large amounts of numbers and AppleScript
is too slow then you probably should move to another solution. Maybe
try the shell tool bc or make your project into a Cocoa-AppleScript
project and do the summation in C, calling it from the AppleScript
portion.
- Ken
On Jun 28, 2004, at 7:04 PM, John Mistler wrote:
Does anyone know of a way to get the SUM of integers in a list WITHOUT
having to use a repeat loop? I am trying to speed things up . . .
What about getting the AVERAGE of the integers in a list?
i.e. the SUM of {1,2,3} = 6
and the AVERAGE of {1,2,3} = 2
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.
References: | |
| >Sum of list? (From: John Mistler <email@hidden>) |