Re: How to calculate/process this one?
Re: How to calculate/process this one?
- Subject: Re: How to calculate/process this one?
- From: Mr Tea <email@hidden>
- Date: Sat, 27 Apr 2002 14:29:31 +0100
This from Martin Michel - dated 27/4/02 01.10 pm:
>
I have a problem thinking of a routine which does the following:
>
>
Let's say I have a random number like 11050. Now I want to add each pair
>
of consecutive digits to give the next line (so 11050 becomes 2155). I
>
want to repeat this step until I have a two-digit number.
>
>
I tried over and over again but did not find a solution for this problem.
>
>
Anybody out there who could help me?
Ooh! ooh! Me me me!
There's nowt like an AppleScript challenge to keep my mind off all the DIY
jobs I'm supposed to be doing this weekend.
Off the top of my head, how about this:
set theNum to random number from 10000 to 999999
set theStartNum to theNum
repeat
set theNumList to every character of (theNum as string)
set theNumCount to count of theNumList
if theNumCount > 2 then
set tempList to {}
set addThis to 0
repeat
if addThis < theNumCount then
if addThis + 1 is not theNumCount then
set end of tempList to ((item (addThis + 1) of
theNumList) as integer) + ((item (addThis + 2) of theNumList) as integer) as
string
else
set end of tempList to item theNumCount of theNumList
end if
else
exit repeat
end if
set addThis to addThis + 2
set theNum to ((tempList as string) as integer)
end repeat
else
exit repeat
end if
end repeat
{theStartNum, theNum}
HTH
Mr Tea
--
Brew of the day: Darjeeling
_______________________________________________
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.