I hold the swedish record (See the Guinness Book of Records, swedish edition) in memorizing decimals of it, namely 8050. The first 8050 decimals of pi. But if You think that is a lot, what do You think of the Japanese Goto who currently has the world record. He remembered a whole marathon of digits, i.e. the 3 + 42194 decimals makes 42195.

More fun though, was writing a program that calculated decimals of pi. It is not particularly fancy, it uses common arctan-formulas. The first version (badly written) used the formula pi = 4 * (arctan(1/2) + arctan>1/3)). I stored the digits in character strings and the program took almost a day (on a slow PC 10 years ago) to calculate up to 1000 decimal places. On top of that the program went wrong after 1003 decimals, which was rather lycky for me, because I used the result when I started to memorize the first 1000. After some amendments the program now works correctly up to at least 52000 decimal places and computes approximately 1000 times faster (mainly due to an algorithm with faster convergence).

The first 8050 decimals of pi

1- 14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 -50 51- 58209 74944 59230 78164 06286 20899 86280 34825 34211 70679 -100 101- 82148 08651 32823 06647 09384 46095 50582 23172 53594 08128 -150 151- 48111 74502 84102 70193 85211 05559 64462 29489 54930 38196 -200 201- 44288 10975 66593 34461 28475 64823 37867 83165 27120 19091 -250 251- 45648 56692 34603 48610 45432 66482 13393 60726 02491 41273 -300 301- 72458 70066 06315 58817 48815 20920 96282 92540 91715 36436 -350 351- 78925 90360 01133 05305 48820 46652 13841 46951 94151 16094 -400 401- 33057 27036 57595 91953 09218 61173 81932 61179 31051 18548 -450 451- 07446 23799 62749 56735 18857 52724 89122 79381 83011 94912 -500 501- 98336 73362 44065 66430 86021 39494 63952 24737 19070 21798 -550 551- 60943 70277 05392 17176 29317 67523 84674 81846 76694 05132 -600 601- 00056 81271 45263 56082 77857 71342 75778 96091 73637 17872 -650 651- 14684 40901 22495 34301 46549 58537 10507 92279 68925 89235 -700 701- 42019 95611 21290 21960 86403 44181 59813 62977 47713 09960 -750 751- 51870 72113 49999 99837 29780 49951 05973 17328 16096 31859 -800 801- 50244 59455 34690 83026 42522 30825 33446 85035 26193 11881 -850 851- 71010 00313 78387 52886 58753 32083 81420 61717 76691 47303 -900 901- 59825 34904 28755 46873 11595 62863 88235 37875 93751 95778 -950 951- 18577 80532 17122 68066 13001 92787 66111 95909 21642 01989 -1000 1001- 38095 25720 10654 85863 27886 59361 53381 82796 82303 01952 -1050 1051- 03530 18529 68995 77362 25994 13891 24972 17752 83479 13151 -1100 1101- 55748 57242 45415 06959 50829 53311 68617 27855 88907 50983 -1150 1151- 81754 63746 49393 19255 06040 09277 01671 13900 98488 24012 -1200 1201- 85836 16035 63707 66010 47101 81942 95559 61989 46767 83744 -1250 1251- 94482 55379 77472 68471 04047 53464 62080 46684 25906 94912 -1300 1301- 93313 67702 89891 52104 75216 20569 66024 05803 81501 93511 -1350 1351- 25338 24300 35587 64024 74964 73263 91419 92726 04269 92279 -1400 1401- 67823 54781 63600 93417 21641 21992 45863 15030 28618 29745 -1450 1451- 55706 74983 85054 94588 58692 69956 90927 21079 75093 02955 -1500 1501- 32116 53449 87202 75596 02364 80665 49911 98818 34797 75356 -1550 1551- 63698 07426 54252 78625 51818 41757 46728 90977 77279 38000 -1600 1601- 81647 06001 61452 49192 17321 72147 72350 14144 19735 68548 -1650 1651- 16136 11573 52552 13347 57418 49468 43852 33239 07394 14333 -1700 1701- 45477 62416 86251 89835 69485 56209 92192 22184 27255 02542 -1750 1751- 56887 67179 04946 01653 46680 49886 27232 79178 60857 84383 -1800 1801- 82796 79766 81454 10095 38837 86360 95068 00642 25125 20511 -1850 1851- 73929 84896 08412 84886 26945 60424 19652 85022 21066 11863 -1900 1901- 06744 27862 20391 94945 04712 37137 86960 95636 43719 17287 -1950 1951- 46776 46575 73962 41389 08658 32645 99581 33904 78027 59009 -2000 2001- 94657 64078 95126 94683 98352 59570 98258 22620 52248 94077 -2050 2051- 26719 47826 84826 01476 99090 26401 36394 43745 53050 68203 -2100 2101- 49625 24517 49399 65143 14298 09190 65925 09372 21696 46151 -2150 2151- 57098 58387 41059 78859 59772 97549 89301 61753 92846 81382 -2200 2201- 68683 86894 27741 55991 85592 52459 53959 43104 99725 24680 -2250 2251- 84598 72736 44695 84865 38367 36222 62609 91246 08051 24388 -2300 2301- 43904 51244 13654 97627 80797 71569 14359 97700 12961 60894 -2350 2351- 41694 86855 58484 06353 42207 22258 28488 64815 84560 28506 -2400 2401- 01684 27394 52267 46767 88952 52138 52254 99546 66727 82398 -2450 2451- 64565 96116 35488 62305 77456 49803 55936 34568 17432 41125 -2500 2501- 15076 06947 94510 96596 09402 52288 79710 89314 56691 36867 -2550 2551- 22874 89405 60101 50330 86179 28680 92087 47609 17824 93858 -2600 2601- 90097 14909 67598 52613 65549 78189 31297 84821 68299 89487 -2650 2651- 22658 80485 75640 14270 47755 51323 79641 45152 37462 34364 -2700 2701- 54285 84447 95265 86782 10511 41354 73573 95231 13427 16610 -2750 2751- 21359 69536 23144 29524 84937 18711 01457 65403 59027 99344 -2800 2801- 03742 00731 05785 39062 19838 74478 08478 48968 33214 45713 -2850 2851- 86875 19435 06430 21845 31910 48481 00537 06146 80674 91927 -2900 2901- 81911 97939 95206 14196 63428 75444 06437 45123 71819 21799 -2950 2951- 98391 01591 95618 14675 14269 12397 48940 90718 64942 31961 -3000 3001- 56794 52080 95146 55022 52316 03881 93014 20937 62137 85595 -3050 3051- 66389 37787 08303 90697 92077 34672 21825 62599 66150 14215 -3100 3101- 03068 03844 77345 49202 60541 46659 25201 49744 28507 32518 -3150 3151- 66600 21324 34088 19071 04863 31734 64965 14539 05796 26856 -3200 3201- 10055 08106 65879 69981 63574 73638 40525 71459 10289 70641 -3250 3251- 40110 97120 62804 39039 75951 56771 57700 42033 78699 36007 -3300 3301- 23055 87631 76359 42187 31251 47120 53292 81918 26186 12586 -3350 3351- 73215 79198 41484 88291 64470 60957 52706 95722 09175 67116 -3400 3401- 72291 09816 90915 28017 35067 12748 58322 28718 35209 35396 -3450 3451- 57251 21083 57915 13698 82091 44421 00675 10334 67110 31412 -3500 3501- 67111 36990 86585 16398 31501 97016 51511 68517 14376 57618 -3550 3551- 35155 65088 49099 89859 98238 73455 28331 63550 76479 18535 -3600 3601- 89322 61854 89632 13293 30898 57064 20467 52590 70915 48141 -3650 3651- 65498 59461 63718 02709 81994 30992 44889 57571 28289 05923 -3700 3701- 23326 09729 97120 84433 57326 54893 82391 19325 97463 66730 -3750 3751- 58360 41428 13883 03203 82490 37589 85243 74417 02913 27656 -3800 3801- 18093 77344 40307 07469 21120 19130 20330 38019 76211 01100 -3850 3851- 44929 32151 60842 44485 96376 69838 95228 68478 31235 52658 -3900 3901- 21314 49576 85726 24334 41893 03968 64262 43410 77322 69780 -3950 3951- 28073 18915 44110 10446 82325 27162 01052 65227 21116 60396 -4000 4001- 66557 30925 47110 55785 37634 66820 65310 98965 26918 62056 -4050 4051- 47693 12570 58635 66201 85581 00729 36065 98764 86117 91045 -4100 4101- 33488 50346 11365 76867 53249 44166 80396 26579 78771 85560 -4150 4151- 84552 96541 26654 08530 61434 44318 58676 97514 56614 06800 -4200 4201- 70023 78776 59134 40171 27494 70420 56223 05389 94561 31407 -4250 4251- 11270 00407 85473 32699 39081 45466 46458 80797 27082 66830 -4300 4301- 63432 85878 56983 05235 80893 30657 57406 79545 71637 75254 -4350 4351- 20211 49557 61581 40025 01262 28594 13021 64715 50979 25923 -4400 4401- 09907 96547 37612 55176 56751 35751 78296 66454 77917 45011 -4450 4451- 29961 48903 04639 94713 29621 07340 43751 89573 59614 58901 -4500 4501- 93897 13111 79042 97828 56475 03203 19869 15140 28708 08599 -4550 4551- 04801 09412 14722 13179 47647 77262 24142 54854 54033 21571 -4600 4601- 85306 14228 81375 85043 06332 17518 29798 66223 71721 59160 -4650 4651- 77166 92547 48738 98665 49494 50114 65406 28433 66393 79003 -4700 4701- 97692 65672 14638 53067 36096 57120 91807 63832 71664 16274 -4750 4751- 88880 07869 25602 90228 47210 40317 21186 08204 19000 42296 -4800 4801- 61711 96377 92133 75751 14959 50156 60496 31862 94726 54736 -4850 4851- 42523 08177 03675 15906 73502 35072 83540 56704 03867 43513 -4900 4901- 62222 47715 89150 49530 98444 89333 09634 08780 76932 59939 -4950 4951- 78054 19341 44737 74418 42631 29860 80998 88687 41326 04721 -5000 5001- 56951 62396 58645 73021 63159 81931 95167 35381 29741 67729 -5050 5051- 47867 24229 24654 36680 09806 76928 23828 06899 64004 82435 -5100 5101- 40370 14163 14965 89794 09243 23789 69070 69779 42236 25082 -5150 5151- 21688 95738 37986 23001 59377 64716 51228 93578 60158 81617 -5200 5201- 55782 97352 33446 04281 51262 72037 34314 65319 77774 16031 -5250 5251- 99066 55418 76397 92933 44195 21541 34189 94854 44734 56738 -5300 5301- 31624 99341 91318 14809 27777 10386 38773 43177 20754 56545 -5350 5351- 32207 77092 12019 05166 09628 04909 26360 19759 88281 61332 -5400 5401- 31666 36528 61932 66863 36062 73567 63035 44776 28035 04507 -5450 5451- 77235 54710 58595 48702 79081 43562 40145 17180 62464 36267 -5500 5501- 94561 27531 81340 78330 33625 42327 83944 97538 24372 05835 -5550 5551- 31147 71199 26063 81334 67768 79695 97030 98339 13077 10987 -5600 5601- 04085 91337 46414 42822 77263 46594 70474 58784 77872 01927 -5650 5651- 71528 07317 67907 70715 72134 44730 60570 07334 92436 93113 -5700 5701- 83504 93163 12840 42512 19256 51798 06941 13528 01314 70130 -5750 5751- 47816 43788 51852 90928 54520 11658 39341 96562 13491 43415 -5800 5801- 95625 86586 55705 52690 49652 09858 03385 07224 26482 93972 -5850 5851- 85847 83163 05777 75606 88876 44624 82468 57926 03953 52773 -5900 5901- 48030 48029 00587 60758 25104 74709 16439 61362 67604 49256 -5950 5951- 27420 42083 20856 61190 62545 43372 13153 59584 50687 72460 -6000 6001- 29016 18766 79524 06163 42522 57719 54291 62991 93064 55377 -6050 6051- 99140 37340 43287 52628 88963 99587 94757 29174 64263 57455 -6100 6101- 25407 90914 51357 11136 94109 11939 32519 10760 20825 20261 -6150 6151- 87985 31887 70584 29725 91677 81314 96990 09019 21169 71737 -6200 6201- 27847 68472 68608 49003 37702 42429 16513 00500 51683 23364 -6250 6251- 35038 95170 29893 92233 45172 20138 12806 96501 17844 08745 -6300 6301- 19601 21228 59937 16231 30171 14448 46409 03890 64495 44400 -6350 6351- 61986 90754 85160 26327 50529 83491 87407 86680 88183 38510 -6400 6401- 22833 45085 04860 82503 93021 33219 71551 84306 35455 00766 -6450 6451- 82829 49304 13776 55279 39751 75461 39539 84683 39363 83047 -6500 6501- 46119 96653 85815 38420 56853 38621 86725 23340 28308 71123 -6550 6551- 28278 92125 07712 62946 32295 63989 89893 58211 67456 27010 -6600 6601- 21835 64622 01349 67151 88190 97303 81198 00497 34072 39610 -6650 6651- 36854 06643 19395 09790 19069 96395 52453 00545 05806 85501 -6700 6701- 95673 02292 19139 33918 56803 44903 98205 95510 02263 53536 -6750 6751- 19204 19947 45538 59381 02343 95544 95977 83779 02374 21617 -6800 6801- 27111 72364 34354 39478 22181 85286 24085 14006 66044 33258 -6850 6851- 88569 86705 43154 70696 57474 58550 33232 33421 07301 54594 -6900 6901- 05165 53790 68662 73337 99585 11562 57843 22988 27372 31989 -6950 6951- 87571 41595 78111 96358 33005 94087 30681 21602 87649 62867 -7000 7001- 44604 77464 91599 50549 73742 56269 01049 03778 19868 35938 -7050 7051- 14657 41268 04925 64879 85561 45372 34786 73303 90468 83834 -7100 7101- 36346 55379 49864 19270 56387 29317 48723 32083 76011 23029 -7150 7151- 91136 79386 27089 43879 93620 16295 15413 37142 48928 30722 -7200 7201- 01269 01475 46684 76535 76164 77379 46752 00490 75715 55278 -7250 7251- 19653 62132 39264 06160 13635 81559 07422 02020 31872 77605 -7300 7301- 27721 90055 61484 25551 87925 30343 51398 44253 22341 57623 -7350 7351- 36106 42506 39049 75008 65627 10953 59194 65897 51413 10348 -7400 7401- 22769 30624 74353 63256 91607 81547 81811 52843 66795 70611 -7450 7451- 08615 33150 44521 27473 92454 49454 23682 88606 13408 41486 -7500 7501- 37767 00961 20715 12491 40430 27253 86076 48236 34143 34623 -7550 7551- 51897 57664 52164 13767 96903 14950 19108 57598 44239 19862 -7600 7601- 91642 19399 49072 36234 64684 41173 94032 65918 40443 78051 -7650 7651- 33389 45257 42399 50829 65912 28508 55582 15725 03107 12570 -7700 7701- 12668 30240 29295 25220 11872 67675 62204 15420 51618 41634 -7750 7751- 84756 51699 98116 14101 00299 60783 86909 29160 30288 40026 -7800 7801- 91041 40792 88621 50784 24516 70908 70006 99282 12066 04183 -7850 7851- 71806 53556 72525 32567 53286 12910 42487 76182 58297 65157 -7900 7901- 95984 70356 22262 93486 00341 58722 98053 49896 50226 29174 -7950 7951- 87882 02734 20922 22453 39856 26476 69149 05562 84250 39127 -8000 8001- 57710 28402 79980 66365 82548 89264 88025 45661 01729 67026 -8050

A C-program that calculates decimals of pi


#include <alloc.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>

#define N     1000L
#define BASE  4
#define MULT  10000L

long *pi;
long *sum;
long *term;

void fracdiv (long n, long src[], long res[], unsigned int start)
{
    static long div, r;
    static long i;

    div = 0L;
    for (i= start; i<N; i++) {
	    div = div * MULT + src[i];
	    r = div / n;
	    res [i] = r;
	    div -= r * n;
    }
}

void fracsum (long sum[], long term[], long first)
// adds term to sum element by element, with final carry of MULT
// term contains zero in elements before first
{
    static long i;

    for (i=N-1; i>=first; i--) {
        sum[i] += term[i];
        if (i>0 && sum[i] >= MULT) {
           sum[i-1]++;
	       sum[i] -= MULT;
        }
    }
}

void fracdiff (long sum[], long term[], long first)
// subtracts term from sum element by element, with final carry of MULT
// term contains zero in elements before first
{
    static long i;

    for (i=N-1; i>=first; i--) {
        sum[i] -= term[i];
        if (i>0 && sum[i] < 0) {
            sum[i-1]--;
	        sum[i] += MULT;
        }
    }
}

void printdig (int dig)
{
    static unsigned i = 0;

    i++;
    putchar(dig + '0');
    if (i % 5 == 0) putchar(' ');
    if (i % 50 == 0) {
	printf (" %6d\n", -i);
	if (i % 250 == 0) printf ("\n");
	printf ("%5d-  ", i+1);
    }
}

void printpi ()
{
    static int i, j, digs[BASE];

    printf ("\n        ");
    for (i=0; i<N; i++) {
        for (j=BASE; j; j--) {
            digs[j-1] = pi[i] % 10;
            pi[i]    /= 10;
        }
        for (j=0; j<BASE; j++) printdig (digs[j]);
    }
    putchar('\n');
}

void arctan (long x, long fak, int sign)
// evaluates fak * arctan (1/x) by serial atan(x) = x/1-x3/3+x5/5-x7/7 etc.
// successive divisions by xsq, res in term, by 1 3 5 7... in sum.
{
    long           denom, xsquare;
    long  nonzero, i;

    xsquare = x * x;
    denom   = 1L;
    nonzero = 0;
    for (i=0; i<N; i++) term[i] = 0;
    term[0] = fak * MULT;
    fracdiv (x, term, term, nonzero);   // =  1/x, first term in expansion
    if (sign > 0) fracsum (pi, term, nonzero);
    else          fracdiff (pi, term, nonzero);
    // two terms each loop, one negative and one positive
    while (nonzero < N) {
        denom += 2L;
        fracdiv (xsquare, term, term, nonzero);
        fracdiv (denom, term, sum, nonzero);
        if (sign > 0) fracdiff (pi, sum, nonzero);
        else          fracsum (pi, sum, nonzero);
        denom += 2L;
        fracdiv (xsquare, term, term, nonzero);
        fracdiv (denom, term, sum, nonzero);
        if (sign > 0) fracsum (pi, sum, nonzero);
        else          fracdiff (pi, sum, nonzero);
        while (term[nonzero] == 0 && nonzero < N) nonzero++;
    }
}

void main ()
{
    long int i, tim;

    sum  = (long *) malloc (sizeof(long)*(N+1));
    term = (long *) malloc (sizeof(long)*(N+1));
    pi   = (long *) malloc (sizeof(long)*(N+1));
    if (!pi) { printf ("Not enough memory!\n"); return; }

    fprintf (stderr, "Calculating PI to %d decimal places\n", N*BASE);
    tim = time(NULL);
    for (i=0; i<N; i++) pi[i] = 0;

    // pi = 20*arctan(1/13)+8*arctan(1/18)+20*arctan(1/21)+12*arctan(1/57)

    arctan (13L, 20L, i);
    arctan (18L, 8L, i);
    arctan (21L, 20L, i);
    arctan (57L, 12L, i);

    tim = time (NULL) - tim;
    fprintf (stderr, "Time taken: %ld secs.\n", tim);
    printpi ();
}

Back to home page