Re: How to calculate/process this one?
Re: How to calculate/process this one?
- Subject: Re: How to calculate/process this one?
- From: Arthur J Knapp <email@hidden>
- Date: Sat, 27 Apr 2002 13:14:16 -0400
>
> Date: Sat, 27 Apr 2002 14:10:01 +0200
>
> Subject: How to calculate/process this one?
>
> From: Martin Michel <email@hidden>
>
> 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 don't understand, how does 11050 become 2155 ???
>
set x to 11050
>
set s to "" & x --> does not take scientific notation into account
>
set a to s's items --> {"1", "1", "0", "5", "0"}
>
tell a -- save some typing: "item x" instead of "item x of a"
[snip]
Whoops, sorry everyone. In trying to perform some fancy list processing,
I made a huge mistake in my last posting. Try this script instead:
set x to 11050
set a to ("" & x)'s items --> {"1", "1", "0", "5", "0"}
repeat until a's length = 2
set b to {}
repeat with i from 2 to a's length by 2
set b's end to (a's item (i - 1)) + (a's item i)
end repeat
if (i < a's length) then set b's end to a's item -1
set a to ("" & b)'s items
end repeat
set x to 0 + ("" & a)
I'm not sure if this is exactly what the poster wanted, but it does
take any number whose count of digits is 2 or greater and gradually
reduces them to a 2 digit number.
{ Arthur J. Knapp, of <
http://www.STELLARViSIONs.com>
<
mailto:email@hidden>
try
<
http://www.MacScripter.net/>
on error number -128
end try
}
_______________________________________________
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.