On Dec 8, 3:58 pm, achrzesz <[email protected]> wrote:
> On Dec 8, 3:48 pm, Eric Kangas <[email protected]> wrote:
>
>
>
> > thanks i tried it with N(pi, digits = 100) and sage didn't like that
> > format.
>
> > On Dec 8, 6:39 am, Jason Grout <[email protected]> wrote:
>
> > > On 12/8/11 7:16 AM, Eric Kangas wrote:
>
> > > > Hi,
>
> > > > I remembering reading one of the pdf's for sage when I found this
> > > > peice of code that turns a number into a list of individual numbers. I
> > > > can't seem to find this code again. An example of this code would be
> > > > taking Pi out to 100 sig figs, and get an output of each individual
> > > > sig fig in a list.
>
> > > Like this?
>
> > > sage: a=list(str(n(pi,100)))
> > > sage: a
> > > ['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', '3']
> > > sage: a.remove('.')
> > > sage: a
> > > ['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', '3']
> > > sage: [int(x) for x in a]
> > > [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, 3]
>
> > > On the other hand, if you have an integer, you can use the digits()
> > > method:
>
> > > sage: 100100299499523949.digits()
> > > [9, 4, 9, 3, 2, 5, 9, 9, 4, 9, 9, 2, 0, 0, 1, 0, 0, 1]
> > > sage: list(reversed(100100299499523949.digits()))
> > > [1, 0, 0, 1, 0, 0, 2, 9, 9, 4, 9, 9, 5, 2, 3, 9, 4, 9]
>
> > > Thanks,
>
> > > Jason
>
> sage: b=list(n(pi,digits=100).str());b.remove('.');map(int,b)
> [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, 8]
Also:
map(int,(N(pi,digits=100).str()).replace('.',''))
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org