Re: Sum of list?
Re: Sum of list?
- Subject: Re: Sum of list?
- From: Martin Orpen <email@hidden>
- Date: Wed, 30 Jun 2004 12:14:46 +0100
on 29/6/04 11:35 pm, Nigel Garvey at email@hidden
wrote:
[snip]
>
repeat with i from lenMod10 + 1 to listLength by 10
>
set sum to sum + (item i of o's l) + (item (i + 1) of o's l) + ,
>
(item (i + 2) of o's l) + item (i + 3) of o's l + ,
>
(item (i + 4) of o's l) + item (i + 5) of o's l + ,
>
(item (i + 6) of o's l) + item (i + 7) of o's l + ,
>
(item (i + 8) of o's l) + item (i + 9) of o's l
>
end repeat
Interesting. I thought that this would be no faster than:
repeat with i from 1 to (count theList)
--set sum to sum + (item i of theList)
set sum to sum + (item i of o's l)
end repeat
But it is :-)
However, maybe I'm missing something, but can't you dispense with all that
typing and just have another nested repeat?
repeat with i from lenMod10 + 1 to listLength by 10
repeat with x from 0 to 9
set sum to sum + (item (i + x) of o's l)
end repeat
end repeat
Both versions seem to take identical amounts of time on my laptop (24
seconds for numbers 1 thru 100000).
Regards
--
Martin Orpen
Idea Digital Imaging Ltd -- The Image Specialists
http://www.idea-digital.com
_______________________________________________
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.