[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Speaking of Pi



It would be cool if it calculated the digits on the fly though, right?  Here
are a couple of methods for doing that:

  http://forum.swarthmore.edu/dr.math/problems/wallbank8.1.html


webmaster@mycoinfo.com (Brian McNett) wrote:
>#!perl -w
>
># Speaking of Pi (speaking_of_pi.plx)
># How to Speak Pi to any precision!
># Thanks to Creede Lambard for supplying Pi to more
># precison than I'm actually using.
>#
># "Fred" seems to be the best voice for this.
>
>use Mac::Speech;
>
>$speaker = "Fred";
>
>$speech = <<INTRO ;
>    I can speak Pie up to 512 signifigant digits.
>    How many digits do you wish me to speak?
>INTRO
>
>&give_speech;
>
>$pi_length = MacPerl::Ask('How Many digits do you wish me to speak?');
>$double_len = (2 * $pi_length);
>
>$pi = <<EOS ;
>3.1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 2 8
>8 4 1 9 7 1 6 9 3 9 9 3 7 5 1 0 5 8 2 0 9 7 4 9 4 4 5 9 2 3 0 7 8 1 6
>4 0 6 2 8 6 2 0 8 9 9 8 6 2 8 0 3 4 8 2 5 3 4 2 1 1 7 0 6 7 9 8 2 1 4
>8 0 8 6 5 1 3 2 8 2 3 0 6 6 4 7 0 9 3 8 4 4 6 0 9 5 5 0 5 8 2 2 3 1 7
>2 5 3 5 9 4 0 8 1 2 8 4 8 1 1 1 7 4 5 0 2 8 4 1 0 2 7 0 1 9 3 8 5 2 1
>1 0 5 5 5 9 6 4 4 6 2 2 9 4 8 9 5 4 9 3 0 3 8 1 9 6 4 4 2 8 8 1 0 9 7
>5 6 6 5 9 3 3 4 4 6 1 2 8 4 7 5 6 4 8 2 3 3 7 8 6 7 8 3 1 6 5 2 7 1 2
>0 1 9 0 9 1 4 5 6 4 8 5 6 6 9 2 3 4 6 0 3 4 8 6 1 0 4 5 4 3 2 6 6 4 8
>2 1 3 3 9 3 6 0 7 2 6 0 2 4 9 1 4 1 2 7 3 7 2 4 5 8 7 0 0 6 6 0 6 3 1
>5 5 8 8 1 7 4 8 8 1 5 2 0 9 2 0 9 6 2 8 2 9 2 5 4 0 9 1 7 1 5 3 6 4 3
>6 7 8 9 2 5 9 0 3 6 0 0 1 1 3 3 0 5 3 0 5 4 8 8 2 0 4 6 6 5 2 1 3 8 4
>1 4 6 9 5 1 9 4 1 5 1 1 6 0 9 4 3 3 0 5 7 2 7 0 3 6 5 7 5 9 5 9 1 9 5
>3 0 9 2 1 8 6 1 1 7 3 8 1 9 3 2 6 1 1 7 9 3 1 0 5 1 1 8 5 4 8 0 7 4 4
>6 2 3 7 9 9 6 2 7 4 9 5 6 7 3 5 1 8 8 5 7 5 2 7 2 4 8 9 1 2 2 7 9 3 8
>1 8 3 0 1 1 9 4 9 1 2 9 8 3 3 6 7 3 3 6 2 4 4 0 6 5 6 6 4 3 0 8 6 0 2
>1 3 9 4 9 4 6 3
>EOS
>
>if ($double_len < 1024) {
>        $speak_pi = substr( $pi , 0, $double_len);
>        $speech = "Pie is equal to approximately: $speak_pi";
>        &give_speech;
>    } else {
>        $speech = "I'm sorry, I can't speak Pie to that precision";
>        &give_speech;
>}
>
>sub give_speech {
>    if (! $speaker) { $speaker = "Fred" }
>    $voice = $Voice{$speaker};
>    $channel = NewSpeechChannel($voice) or die $^E;
>        SpeakText($channel, $speech) || die $^E;
>        while (SpeechBusy()) {}
>        DisposeSpeechChannel($channel);
>        $speech=$speaker="";
>}
>
>#  Even more digits of Pi if you want them!
>#3.141592653589793238462643383279502884197169399375105820974944592307816406
>2862
>#  
>089986280348253421170679821480865132823066470938446095505822317253594081284
>8
>#  
>111745028410270193852110555964462294895493038196442881097566593344612847564
>8
>#  
>233786783165271201909145648566923460348610454326648213393607260249141273724
>5
>#  
>870066063155881748815209209628292540917153643678925903600113305305488204665
>2
>#  
>138414695194151160943305727036575959195309218611738193261179310511854807446
>2
>#  
>379962749567351885752724891227938183011949129833673362440656643086021394946
>3
>#  
>952247371907021798609437027705392171762931767523846748184676694051320005681
>2
>#  
>714526356082778577134275778960917363717872146844090122495343014654958537105
>0
>#  
>792279689258923542019956112129021960864034418159813629774771309960518707211
>3
>#  
>499999983729780499510597317328160963185950244594553469083026425223082533446
>8
>#  
>503526193118817101000313783875288658753320838142061717766914730359825349042
>8
>#  
>755468731159562863882353787593751957781857780532171226806613001927876611195
>9
>#  092164201989
>
>
># Fungal Parataxonomy                   Mycology Information (Mycoinfo)
># Webmaster, Staff Writer      **The World's First Mycology E-Journal**   
># <mailto:webmaster@mycoinfo.com>            <http://www.mycoinfo.com/> 
>#
># First they ignore you. Then they laugh at you. Then they fight you.
># Then you win.                                     --Mohandas Gandhi
>
>
>===== Want to unsubscribe from this list?
>===== Send mail with body "unsubscribe" to macperl-request@macperl.org
>

  -------------------                            -------------------
  Ken Williams                             Last Bastion of Euclidity
  ken@forum.swarthmore.edu                            The Math Forum



===== Want to unsubscribe from this list?
===== Send mail with body "unsubscribe" to macperl-request@macperl.org