Jump to content
Sign in to follow this  
n4gix

Some Programming Fun

Recommended Posts

Here's a short C routine that will (eventually) print a googolplex, that is 10^googol power.A googol, for those who may not remember is simply 10^100 power, or 1 followed by 100 zeros.Now, given today's processor speeds, how long would it take to complete printing? :)#include #include int main (int argc, char *argv[]){ int *vals, *ptr, max; if (argc == 2) max = atoi (argv[1]); else max = 100; printf ("1"); if ((vals = malloc ((max + 1) * sizeof (int))) == NULL) { fprintf (stderr, "Error allocating memory.n"); return 1; } memset (vals, '0', (max + 1) * sizeof (int)); while (!vals[max]) { *(ptr = vals) += 1; while (*ptr == 10) { *ptr++ = 0; *ptr += 1; } printf ("0"); } printf ("n"); free (vals); return 0;}http://fpx.de/fp/Fun/Googolplex/


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

The fastest available desktop computers of today will run the program at a speed that allows the printing of about 10 to the power of 7 digits per second. The average year has roughly 3.2*10^7 seconds, so this machine will print about 3.2*10^14 digits per year. We conclude that this machine will need 3.125*10^85 years to finish printing Googolplex. Lucas Watson (lwatkins@scri.fsu.edu) took a different approach, and pointed out that this program will be useless even in a million years, simply because there isn't enough matter (in the universe) to print a Googolplex on (and this fact is unlikely to change). According to him, this idea originated on Carl Sagan's Cosmos TV show. Of course printing a Googolplex in base Googolplex is easy:If we switch to base Googolplex, you can print it simply as 10


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...