March 14, 2010Python pi.py SpigotHere is pi.py (not to be confused with pypy), a short python implementation of Jeremy Gibbons's 2005 spigot generator for decimal digits of pi: def pi_decimal_digits(): q, r, t, j = 1, 180, 60, 2 while True: u, y = 3*(3*j+1)*(3*j+2), (q*(27*j-12)+5*r)//(5*t) yield y q, r, t, j = 10*q*j*(2*j-1), 10*u*(q*(5*j-2)+r-y*t), t*u, j+1 The code to drive the algorithm is longer than the algorithm: count, digits = 0, pi_decimal_digits() while 1: print '%6d: %s' % ( count, ''.join([str(digits.next()) for j in xrange(50)])) count += 50 This little script can be quite handy if, for example, you want to look up where in the digits of pi you can find the phone number for the Mass Audubon Society that is down the road from my house: > ./pi.py | grep --color 2599661 3050: 56638937787083039069792077346722182562599661501421 Conveniently, their phone number starts at the very visible 3087th digit of pi after the decimal point. My home phone number is a little bit further into the private section the pi phone book, at the 6,301,261th digit. And, if you must, you can reach me at my cell at the 22,000,091th digit, although I should warn you that my reception is not very good out here in the boonies. Happy pi day. Posted by David at March 14, 2010 08:35 AMComments
A couple things to note. Davidmay points out that because of line breaks, you can't actually find all subsequences just by grepping like this. If you want to really do exhaustive searches, you'd have to do a real search without discontinuities. Also, this algorithm isn't really fast enough to let me compute the 22,000,091th digit in a reasonable amount of time on my laptop. I had to cheat and use a pi searching service, of which there are several different flavors online. Posted by: David at March 14, 2010 02:10 PMThere is something very odd about Pi. 355/113 = 3.141592 Now Reverse, i.e. reverse the record (as if reversing the direction of the playing record). 553 + 113 = 666 It's creepy how accurate it is (up to 6 decimal places, now that's a very accurate number, i.e. to get 6 places correct after the decimal) From 3 scripts in Revelations: the Bible says 144 000 people will be alive on Earth at the end of days.... I dunno it seems there may be some puzzle out there people must figure out and this is all just a big test while we are travelling between galaxies at light speed between galaxies hahaha But seriously though, 355/113 = 3.141592 now reverse 355 to 553 and add 113 and you get the mark of the Beast 144,000x3=432,000 Post a comment
|
Copyright 2010 © David Bau. All Rights Reserved. |