Re: minimum function?
Re: minimum function?
- Subject: Re: minimum function?
- From: "Mark J. Reed" <email@hidden>
- Date: Wed, 6 Apr 2005 16:14:31 -0400
On Apr 6, 2005 11:50 AM, Martin Orpen <email@hidden> wrote:
Definition of the term: somebody who wipes that self-satisfied smile from
your face by posting a script that is both simpler, more efficient - and
yet, at the same time, more cunning - than the one that you posted less than
twelve hours before.
Ah, one of those folks. Handy to have around, if occasionally infuriating. :)
Anyhow, back to scripting - I'm crying foul because I think that we should
compare like with like.
My script is sorting the whole bloody list and then grabbing the first item.
How long would it take a vanilla AppleScript to sort the whole list? You
wouldn't need Smile to measure that - a sundial would be sufficient.
Note to self: write a shell script to do a simple selection sort on way home
- call it "script g".
Hm. Lessee. Since we're in OS X land, I assume bashisms are acceptable. Arrays make this easier.
#!/bin/bash
# Selection sort in bash
# sorts input lines
a=()
let i=0
while read a[i]; do
let i+=1
done
for (( i=0; i<${#a[@]}; ++i )); do
let min=i
for (( j=i+1; j<${#a[@]}; ++j )); do
if [[ "${a[j]}" < "${a[min]}" ]]; then
let min=j
fi
done
temp="${a[min]}"
a[min]="${a[i]}"
a[i]="$temp"
done
for (( i=0; i<${#a[@]}; ++i )); do
echo "${a[i]}"
done
:)
--
Mark J. Reed <
email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden