| |||
| [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] |
|
On Nov 16, 2006, at 2:59 PM, CYB wrote: Thanks Andrew, wonderful idea Hopefully this will give you some pointers. Given a list of coordinates ('coords') this script shows you ways of a) finding their mean squares, b) finding the closest to top-left, c) finding the furthest from top-left, and d) sorting them in order of closest to furthest: global coords, squares set coords to {{5.0, 120}, {10.0, 10.0}, {70.0, 20.0}, {70.0, 80.0}} set squares to {} repeat with eachCoord in coords copy (getSquared(eachCoord)) to end of squares end repeat -- so now you have a list of coordinates (coords) and their squared values (squares) set minItem to findMin() -- find the smallest (closest to top-left) set maxItem to findMax() -- find the largest (furthest from top-left) sortCoords() -- sort them. not needed here, just for demo on findMin() set min to 1 repeat with i from 2 to (count squares) if item i of squares < item min of squares then set min to i end if end repeat return min -- the index to the closest item end findMin on findMax() set max to 1 repeat with i from 2 to (count squares) if item i of squares > item max of squares then set max to i end if end repeat return max -- the index to the furthest item end findMax on sortCoords() -- use a double list bubble sort (although any sort algorithm will work) -- iterate through one list (squares). For each swap, swap the corrsponding items in the other list set sorted to false repeat until sorted is true set sorted to true repeat with i from 2 to (count coords) if item (i - 1) of squares > (item i of squares) then set tempOutput to item (i - 1) of squares set tempInput to item (i - 1) of coords set item (i - 1) of squares to item i of squares set item (i - 1) of coords to item i of coords set item i of squares to tempOutput set item i of coords to tempInput set sorted to false end if end repeat end repeat end sortCoords on getSquared(inputVals) set outputVal to 0 repeat with eachVal in inputVals set outputVal to outputVal + (eachVal ^ 2) end repeat return outputVal / (count inputVals) end getSquared |
_______________________________________________ Do not post admin requests to the list. They will be ignored. AppleScript-Users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/applescript-users/email@hidden Archives: http://lists.apple.com/mailman//archives/applescript-users This email sent to email@hidden
| References: | |
| >Re: Sort a list of lists (From: CYB <email@hidden>) |
| Home | Archives | FAQ | Terms/Conditions | Contact | RSS | Lists | About |
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE
Contact Apple | Terms of Use | Privacy Policy
Copyright © 2007 Apple Inc. All rights reserved.