Compute pi to base 12 using Python?

Bengt Richter bokr at oz.net
Sun Apr 17 05:26:02 EDT 2005


On Sun, 17 Apr 2005 01:00:46 -0700, Dick Moores <rdm at rcblue.com> wrote:

>M.E.Farmer wrote at 23:18 4/14/2005:
>> > >Using the GNU "bc" utility:
>> > >
>> > >   $ bc -l
>> > >   bc 1.06
>> > >   Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation,
>>Inc.
>> > >   This is free software with ABSOLUTELY NO WARRANTY.
>> > >   For details type `warranty'.
>> > >   scale = 3000    # number of output places wanted
>> > >   obase = 12      # output base
>> > >   print 4 * a(1)  # pi = 4*arctan(1)
>
>Wow! this got me the 3003 (changed from 3000) digits of pi to base 12 in 
>60.8 secs. No, I didn't count them yet, nor am I sure they're correct. 
>But I'd bet on them..
>
>Could someone remind me how to get the output of bc -l into a text file 
>on Windows? (I've tried employing " > pi3003.txt" in various ways) OR, 
>how to copy and paste from the command line window, or whatever that 
>window is called? (Sorry for the OT question.)
To copy from the command window to the clipboard:

1. Scroll top of desired stuff to make it visible near top
2. Hold down Alt
3. Tap Space Bar
4. Release Alt
5. Tap e
6. Tap k
7. Use mouse or arrow keys to place cursor on top left corner of desired box
8. Hold down Shift
9. Use arrow keys or mouse-with-left-button-pressed to go to bottom right character of desired box
9a. If the bottom is out of sight, keep holding  shift down and pretend you can cursor down below bottom.
    the attempt should make the screen scroll up and select more desired material. If you overshoot, don't panic,
    just keep holding down shift and use arrows (the are slower) or mouse-with-left-button-still-down to move to
    desired bottom right corner.
10. Release mouse button if using that
11. Release Shift
12. Press Enter
That should copy to the clipboard and make the selection box revert to normal display.

Pasting from clipboard is up to you. Pasting into the command window from clipboard
is 2-5 above, and Tap p

HTH

PS. Redirecting with > from a script whose interpreter was started by windows extension association
doesn't work on some version of windows. To be safe, invoke the interpreter explicitly, e.g.,
    python myscript.py [whatever args here] > pi3003.txt

If myscript.py is not in the current directory, use a sufficient path to it. If your windows is having
that problem, the same will happen with a perl script or other script when you run it as just myscript.ext ...
and depend on windows to start the right interpreter.

Regards,
Bengt Richter



More information about the Python-list mailing list