Archived

This topic is now archived and is closed to further replies.

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/

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

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

Share this post


Link to post
Share on other sites