Compute pi to base 12 using Python?
Dick Moores
rdm at rcblue.com
Sun Apr 17 03:00:36 EDT 2005
Tim Roberts wrote at 22:05 4/16/2005:
>Dick Moores <rdm at rcblue.com> wrote:
> >>
> >># Reading/writing Python source often gives me the impression of
> >># reading/writing a poem!
> >># Layout, indentation, rythm, I like the look and feel!
> >>
> >># What does this tiny program do? It is not a sonnet, even not a
> >># pi-sonnet, but it surely produces Pi!
> >
> >It sure does. When I ran it my jaw dropped. I had 7,947 CORRECT digits in
> >2 minutes 0 seconds (by my stopwatch)!
>
>How do you know? I think the 7,912th digit is wrong.
>
>;)
I suppose you're joshing, Tim, but I really did check by using my trusty
====================================
def compareSequences(seq1, seq2):
"""
find first index at which two sequences differ
"""
if s1 == s2:
print "Sequences are identical"
return None
if len(seq1) >= len(seq2):
shorterOrEqualSequence = seq2
else:
shorterOrEqualSequence = seq1
for index in range(len(shorterOrEqualSequence)):
if seq1[index] != seq2[index]:
print "sequences first differ at index", index
print "s1 at that index is", s1[index]
print "s2 at that index is", s2[index]
break
if index == len(shorterOrEqualSequence)-1:
print "sequences are identical thru end of shorter sequence at
index", index
==================================
I got the "correct" pi from
<http://www.ballandclaw.com/upi/pi.50000.html>. By inspection of the text
file I copied this to (removing the "3." of "3.1"), the 7,912th digit is
"2" (I'm using Textpad). If you begin with "31", which what the speedy
script does, the 7,912th digit is "6".
Now, I've shown you mine. Show me yours. ;-)
Dick
More information about the Python-list
mailing list