<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: The Digits of Pi</title>
	<atom:link href="http://programmingpraxis.com/2009/02/20/the-digits-of-pi/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingpraxis.com/2009/02/20/the-digits-of-pi/</link>
	<description>A collection of etudes, updated weekly, for the education and enjoyment of the savvy programmer</description>
	<lastBuildDate>Mon, 28 May 2012 03:30:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: David</title>
		<link>http://programmingpraxis.com/2009/02/20/the-digits-of-pi/#comment-4850</link>
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 20 May 2012 01:28:16 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=56#comment-4850</guid>
		<description><![CDATA[For the curious, all first 1000 digits (it ran off last post there...)

[sourcecode language=&quot;text&quot;]
&gt;&gt;&gt; print_pi(1000)
pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328
230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378
678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789
259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188
575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766
940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212
902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334
468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185
77805321712268066130019278766111959092164201989
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>For the curious, all first 1000 digits (it ran off last post there&#8230;)</p>
<pre class="brush: plain;">
&gt;&gt;&gt; print_pi(1000)
pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328
230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378
678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789
259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188
575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766
940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212
902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334
468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185
77805321712268066130019278766111959092164201989
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: David</title>
		<link>http://programmingpraxis.com/2009/02/20/the-digits-of-pi/#comment-4849</link>
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 20 May 2012 01:23:26 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=56#comment-4849</guid>
		<description><![CDATA[Python:

[sourcecode language=&quot;python&quot;]
def pi_spigot():
    (q, r, t, k, n, l) = (1, 0, 1, 1, 3, 3)
    while True:
        if 4*q+r-t &lt; n*t:
            yield n
            (q, r, t, k, n, l) = (10*q, 10*(r-n*t), t, k, (10*(3*q+r))//t-10*n, l)
        else:
             (q, r, t, k, n, l) = (q*k, (2*q+r)*l, t*l, k+1, (q*(7*k+2)+r*l)//(t*l), l+2)


def print_pi(n):
    digits = pi_spigot()
    print(&#039;pi =&#039;, str(next(digits)) + &#039;.&#039;, end=&#039;&#039;)
    while n &gt; 0:
        print(str(next(digits)), end=&#039;&#039;)
        n -= 1

    print()
[/sourcecode]

Running:

[sourcecode language=&quot;text&quot;]
&gt;&gt;&gt; print_pi(20)
pi = 3.14159265358979323846
&gt;&gt;&gt; print_pi(1000)
pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989
[/sourcecode]]]></description>
		<content:encoded><![CDATA[<p>Python:</p>
<pre class="brush: python;">
def pi_spigot():
    (q, r, t, k, n, l) = (1, 0, 1, 1, 3, 3)
    while True:
        if 4*q+r-t &lt; n*t:
            yield n
            (q, r, t, k, n, l) = (10*q, 10*(r-n*t), t, k, (10*(3*q+r))//t-10*n, l)
        else:
             (q, r, t, k, n, l) = (q*k, (2*q+r)*l, t*l, k+1, (q*(7*k+2)+r*l)//(t*l), l+2)


def print_pi(n):
    digits = pi_spigot()
    print('pi =', str(next(digits)) + '.', end='')
    while n &gt; 0:
        print(str(next(digits)), end='')
        n -= 1

    print()
</pre>
<p>Running:</p>
<pre class="brush: plain;">
&gt;&gt;&gt; print_pi(20)
pi = 3.14159265358979323846
&gt;&gt;&gt; print_pi(1000)
pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Kennedy</title>
		<link>http://programmingpraxis.com/2009/02/20/the-digits-of-pi/#comment-3199</link>
		<dc:creator><![CDATA[Sam Kennedy]]></dc:creator>
		<pubDate>Tue, 05 Jul 2011 16:11:44 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=56#comment-3199</guid>
		<description><![CDATA[It isn&#039;t pretty but it works:

&lt;code&gt;
#!/usr/bin/perl

$&#124; = 1;

push(@B, 0);

$counter = 3;
for($i = 0;$i&lt;=33223;$i++){
    push(@A,$i);
    push(@remainder, 2);
    push(@B, $counter);
    $counter += 2;
}

for($x = 1; $x=1;$i--){
        $m10[$i] = $remainder[$i] * 10;
        $sum[$i] = $m10[$i] + $carried[$i];
        $remainder[$i] = $sum[$i] % $B[$i];
        $carried[$i - 1] = (($sum[$i] - $remainder[$i]) / $B[$i]) * $A[$i];
	}
	
    $m10[0] = $remainder[0] * 10;
    $sum[0] = $m10[0] + $carried[0];
    $remainder[0] = $sum[0]%10;
	$predigit = int($sum[0]/10);
	
	push(@predigits, $predigit);
	
	if($predigit &lt; 9){
		for($i = 0; $i&lt;((scalar @predigits)-1); $i++){
			print $predigits[$i];
		}
		undef @predigits;
		push(@predigits, $predigit);
	}
	
	if($predigit == 10){
		for($i = 0; $i&lt;((scalar @predigits)-1); $i++){
			if($predigits[$i] == 9) { print 0; }
			else {
				$predigits[$i] = $predigits[$i] + 1;
				print $predigits[$i];
			}
		}
		undef @predigits;
		push(@predigits, 0);
	}
}
&lt;/code&gt;]]></description>
		<content:encoded><![CDATA[<p>It isn&#8217;t pretty but it works:</p>
<p><code><br />
#!/usr/bin/perl</p>
<p>$| = 1;</p>
<p>push(@B, 0);</p>
<p>$counter = 3;<br />
for($i = 0;$i&lt;=33223;$i++){<br />
    push(@A,$i);<br />
    push(@remainder, 2);<br />
    push(@B, $counter);<br />
    $counter += 2;<br />
}</p>
<p>for($x = 1; $x=1;$i--){<br />
        $m10[$i] = $remainder[$i] * 10;<br />
        $sum[$i] = $m10[$i] + $carried[$i];<br />
        $remainder[$i] = $sum[$i] % $B[$i];<br />
        $carried[$i - 1] = (($sum[$i] - $remainder[$i]) / $B[$i]) * $A[$i];<br />
	}</p>
<p>    $m10[0] = $remainder[0] * 10;<br />
    $sum[0] = $m10[0] + $carried[0];<br />
    $remainder[0] = $sum[0]%10;<br />
	$predigit = int($sum[0]/10);</p>
<p>	push(@predigits, $predigit);</p>
<p>	if($predigit &lt; 9){<br />
		for($i = 0; $i&lt;((scalar @predigits)-1); $i++){<br />
			print $predigits[$i];<br />
		}<br />
		undef @predigits;<br />
		push(@predigits, $predigit);<br />
	}</p>
<p>	if($predigit == 10){<br />
		for($i = 0; $i&lt;((scalar @predigits)-1); $i++){<br />
			if($predigits[$i] == 9) { print 0; }<br />
			else {<br />
				$predigits[$i] = $predigits[$i] + 1;<br />
				print $predigits[$i];<br />
			}<br />
		}<br />
		undef @predigits;<br />
		push(@predigits, 0);<br />
	}<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Kennedy</title>
		<link>http://programmingpraxis.com/2009/02/20/the-digits-of-pi/#comment-3176</link>
		<dc:creator><![CDATA[Sam Kennedy]]></dc:creator>
		<pubDate>Wed, 29 Jun 2011 13:06:08 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=56#comment-3176</guid>
		<description><![CDATA[This seems like a really interesting exercise, however I cannot understand how this spigot algorithm works. I read the PDF, but I could not follow the maths in the diagram, is there an easier explanation for someone who doesn&#039;t have a massive background in maths?

Cheers,
-Sam]]></description>
		<content:encoded><![CDATA[<p>This seems like a really interesting exercise, however I cannot understand how this spigot algorithm works. I read the PDF, but I could not follow the maths in the diagram, is there an easier explanation for someone who doesn&#8217;t have a massive background in maths?</p>
<p>Cheers,<br />
-Sam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Graham</title>
		<link>http://programmingpraxis.com/2009/02/20/the-digits-of-pi/#comment-3041</link>
		<dc:creator><![CDATA[Graham]]></dc:creator>
		<pubDate>Tue, 17 May 2011 18:07:22 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=56#comment-3041</guid>
		<description><![CDATA[I modified the fixed-point approach for arccot found
&lt;a href=&quot;http://www.reddit.com/r/lisp/comments/93ofv/how_fast_does_your_lisp_compute_10000_digits_of_pi/&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;
and used it with Wikipedia&#039;s most efficient Machin-Like formula found
&lt;a href=&quot;http://en.wikipedia.org/wiki/Machin-like_formula&quot; rel=&quot;nofollow&quot;&gt;here&lt;/a&gt;
&lt;a href=&quot;https://gist.github.com/976997&quot; rel=&quot;nofollow&quot;&gt;My submission&lt;/a&gt;]]></description>
		<content:encoded><![CDATA[<p>I modified the fixed-point approach for arccot found<br />
<a href="http://www.reddit.com/r/lisp/comments/93ofv/how_fast_does_your_lisp_compute_10000_digits_of_pi/" rel="nofollow">here</a><br />
and used it with Wikipedia&#8217;s most efficient Machin-Like formula found<br />
<a href="http://en.wikipedia.org/wiki/Machin-like_formula" rel="nofollow">here</a><br />
<a href="https://gist.github.com/976997" rel="nofollow">My submission</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: programmingpraxis</title>
		<link>http://programmingpraxis.com/2009/02/20/the-digits-of-pi/#comment-1555</link>
		<dc:creator><![CDATA[programmingpraxis]]></dc:creator>
		<pubDate>Fri, 06 Aug 2010 11:59:01 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=56#comment-1555</guid>
		<description><![CDATA[Alexander J. Yee &amp; Shigeru Kondo recently &lt;a href=&quot;http://www.numberworld.org/misc_runs/pi-5t/details.html&quot; rel=&quot;nofollow&quot;&gt;computed&lt;/a&gt; five trillion digits of pi.]]></description>
		<content:encoded><![CDATA[<p>Alexander J. Yee &amp; Shigeru Kondo recently <a href="http://www.numberworld.org/misc_runs/pi-5t/details.html" rel="nofollow">computed</a> five trillion digits of pi.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Matt Weaver</title>
		<link>http://programmingpraxis.com/2009/02/20/the-digits-of-pi/#comment-645</link>
		<dc:creator><![CDATA[Matt Weaver]]></dc:creator>
		<pubDate>Sun, 27 Sep 2009 01:58:04 +0000</pubDate>
		<guid isPermaLink="false">http://programmingpraxis.wordpress.com/?p=56#comment-645</guid>
		<description><![CDATA[My solution, written in C:

http://codepad.org/WOEQnbTt

This version calculates the requested digit directly, based on the method described in &quot;Computation of the nth decimal digit of pi with low memory&quot;: http://numbers.computation.free.fr/Constants/Algorithms/nthdecimaldigit.pdf (and I must admit I also peeked a little at the implementation at http://numbers.computation.free.fr/Constants/Algorithms/nthdigit.html)

It lacks the conciseness and elegance of the spigot solution, but makes up for it in efficiency.  The spigot version works well until it runs out of main memory and starts paging, at which point performance really hits a wall.  On my computer that point is somewhere between the 20,000th digit (took 1:48) and the 50,000th (I killed it after 3.5 hours).  For comparison, this solution returns the 50,000th digit in ~12 seconds.]]></description>
		<content:encoded><![CDATA[<p>My solution, written in C:</p>
<p><a href="http://codepad.org/WOEQnbTt" rel="nofollow">http://codepad.org/WOEQnbTt</a></p>
<p>This version calculates the requested digit directly, based on the method described in &#8220;Computation of the nth decimal digit of pi with low memory&#8221;: <a href="http://numbers.computation.free.fr/Constants/Algorithms/nthdecimaldigit.pdf" rel="nofollow">http://numbers.computation.free.fr/Constants/Algorithms/nthdecimaldigit.pdf</a> (and I must admit I also peeked a little at the implementation at <a href="http://numbers.computation.free.fr/Constants/Algorithms/nthdigit.html" rel="nofollow">http://numbers.computation.free.fr/Constants/Algorithms/nthdigit.html</a>)</p>
<p>It lacks the conciseness and elegance of the spigot solution, but makes up for it in efficiency.  The spigot version works well until it runs out of main memory and starts paging, at which point performance really hits a wall.  On my computer that point is somewhere between the 20,000th digit (took 1:48) and the 50,000th (I killed it after 3.5 hours).  For comparison, this solution returns the 50,000th digit in ~12 seconds.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

