Re: computing 20! all the way
Re: computing 20! all the way
- Subject: Re: computing 20! all the way
- From: David Sowder <email@hidden>
- Date: Mon, 15 Nov 2004 09:25:53 -0600
Just for completeness. I just after checking this (wrote this code in
a hurry just before I left for the weekend), I broke it in trying to
get the first step to be numbered 1.
#!/usr/bin/env python
p = 1
for i in range( 20 ):
p = i * p
#print i, p
print p
numbers them 0-19.
#!/usr/bin/env python
p = 1
for i in range( 1, 21 ):
p = i * p
#print i, p
print p
numbers them 1-20.
My originally posted code gave 19! rather than 20!
Thanks for sharing the interesting discussion otherwise. I'm not real
suprised AS doesn't deal with really big numbers directly. Python's
done it for awhile, but of course, it has to deal with them in an
internally special mode once they get bigger than a certain number of
bits, depending on the processor it's being run on.
On Thu, 11 Nov 2004 18:11:31 -0600, David Sowder <email@hidden> wrote:
> I'm not sure about really big numbers in AppleScript, but Python ships
> with Mac OS X and the code to get your answer (included below) can be
> dumped to a ASCII text file named file.py and run with:
>
> python file.py
>
> The Python program (uncomment the line beginning with "#print" to see each step.
>
> #!/usr/bin/env python
>
> p = 1
> for i in range( 1, 20 ):
> p = i * p
> #print i, p
> print p
>
>
>
>
> On Thu, 11 Nov 2004 14:56:40 -0800 (PST), Brian Johnson
> <email@hidden> wrote:
> >
> > My daughter is sitting here with an assignment to calculate 20!
> >
> > I did the obvious:
> >
> > set p to 1
> > repeat with i from 1 to 20
> > set p to i * p
> > end repeat
> > p
> > --> 2.43290200817664E+18
> >
> > but it's wanted as a whole number (no scientific notation). Any
> > suggestions? Cobol? used to tolerate really big integers, iirc, but can AS
> > deal with this?
> >
> > - brian johnson
> >
> > _______________________________________________
> > 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
> >
>
>
> --
> David R. Sowder
> University of Texas at Arlington
> Department of Modern Languages
> Language Acquisition Center Supervisor
> Work: email@hidden
> Personal: email@hidden
> Testing: email@hidden
> http://david.sowder.com/
>
--
David R. Sowder
University of Texas at Arlington
Department of Modern Languages
Language Acquisition Center Supervisor
Work: email@hidden
Personal: email@hidden
Testing: email@hidden
http://david.sowder.com/
_______________________________________________
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