• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: computing 20! all the way
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: computing 20! all the way


  • Subject: Re: computing 20! all the way
  • From: Richard Morton <email@hidden>
  • Date: Fri, 12 Nov 2004 17:37:12 +1100

On 12 Nov 2004, at 11:29 AM, Martin Orpen wrote:
on 11/11/04 10:56 pm, Brian Johnson wrote:
 > My daughter is sitting here with an assignment to calculate 20!
 >
 > I did the obvious..

> but it's wanted as a whole number (no scientific notation)...

If you/she uses OS X then you use bc when you want to work with *big* numbers:

set nString to {"1"}
repeat with n from 1 to 20
    set end of nString to "*" & n
end repeat

I came across another way of doing this bit some time back. The original was in C and I just rewrote it as AS:


on factorial from n
    if n = 0 then return 1
    return n * (factorial from (n - 1))
end factorial



set theResult to do shell script "echo " & (nString as string) & " | bc"

The above still needs something to turn the result back into an integer though. NG has posted a vanilla AS method for this. I thought I saw it on Macscripter too but couldn't find it there just now.


Cheers,

Max Factor
_______________________________________________
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


  • Follow-Ups:
    • Re: computing 20! all the way
      • From: Doug McNutt <email@hidden>
    • Reading contents of a clipping file?
      • From: Richard Rönnbäck <email@hidden>
References: 
 >Re: computing 20! all the way (From: Martin Orpen <email@hidden>)

  • Prev by Date: Re: computing 20! all the way
  • Next by Date: Reading contents of a clipping file?
  • Previous by thread: Re: computing 20! all the way
  • Next by thread: Reading contents of a clipping file?
  • Index(es):
    • Date
    • Thread