Re: How to calculate/process this one?
Re: How to calculate/process this one?
- Subject: Re: How to calculate/process this one?
- From: nicolas descombes <email@hidden>
- Date: Sun, 28 Apr 2002 23:51:12 +0200
>
Le 27/04/02 18:36, Paul Berkowitz a icrit :
>
On 4/27/02 7:21 AM, "Martin Michel" <email@hidden> wrote:
>
>
> b) Sometimes the numbers are not getting smaller and smaller by the time
>
> but bigger and bigger. I do not know how to get rid of this problem.
>
>
That "problem" is where you started out. It's built into your exercise. It
>
has nothing whatsoever to do with AppleScript. it's what makes the entire
>
exercise pointless and futile. Find something else to think about. If you
>
had started out with a number like 99595, you would have seen the "problem"
>
immediately. Think of another game, because this one is never going to work.
this script works :
[SCRIPT]
(*
* Author : Nicolas DESCOMBES
* country : France
* Date : 28/04/2002
*)
global nombreInferieur
set nombreInitial to "11050"
(* 11050
* 2155
* 370
* 107
* 17
*)
(* For large numbers, only string. ex : "12345678912345678912345678"
* For little numbers, integers are accepted since 536870909
* exponential notation is not handled
*)
set t0 to the ticks -- OSAX Jon's commands
niveauInferieur(nombreInitial, 2)
-- result : {"time : 1", "Result : 17"}
set t1 to the ticks -- OSAX Jon's commands
{"time : " & (t1 - t0), "Result : " & (nombreInferieur as string)}
on niveauInferieur(n, p)
-- p = length of result
if (((n as string)'s length) as number) = p then
set nombreInferieur to n
return nombreInferieur
end if
if (((n as string)'s length) as number) < p then
display dialog (n as string) & ,
" is too small for getting a number with " & p & " digits."
set nombreInferieur to ""
return nombreInferieur
end if
set listeNombre to {}
set listeNombre to (n as string)'s characters
set couples to {}
set rang to 2
repeat with i in listeNombre
try
copy {i as string, (item rang of listeNombre)} ,
to the end of couples
set rang to rang + 1
on error
end try
end repeat
set reste to 0
set nombreInferieur to ""
repeat with j in (reverse of couples)
set total to ((item 1 of j) + ((item 2 of j) + reste))
if total < 10 then
set nombreInferieur to total & nombreInferieur
set reste to 0
else
set nombreInferieur to (character 2 of ,
((total as string)) as integer) & nombreInferieur
set reste to 1
end if
end repeat
if reste > 0 then
set nombreInferieur to (reste as string) & nombreInferieur
end if
if (length of (nombreInferieur as string)) > p then
niveauInferieur(nombreInferieur, p)
else
return nombreInferieur
end if
end niveauInferieur
[/SCRIPT]
it's not certainly optimized but it works perfectly.
a+
Nicolas
--
Traduction frangaise de
AppleScript Language Guide 1.3.7
Tome 1 -> 6 disponibles
Sommaire giniral avec liens directs
<
http://trad.applescript.free.fr/Accueil.html>
--
_______________________________________________
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.