[Maxima] transforming a number to a list
reyssat
eric.reyssat at math.unicaen.fr
Sun Jun 7 15:08:28 CDT 2009
Gosse michel a écrit :
> Hello
>
> How can i transform a number to list of its digits :
> For instance, 345 -> [3,4,5]
>
Hello Michel
maybe this is what you want :
(%i1) f(x):=charlist(string(x));
(%o1) f(x) := charlist(string(x))
(%i2) f(345); f(3^20); f(-3^20); f(3.1^10);
(%o2) [3, 4, 5]
(%o3) [3, 4, 8, 6, 7, 8, 4, 4, 0, 1]
(%o4) [-, 3, 4, 8, 6, 7, 8, 4, 4, 0, 1]
(%o5) [8, 1, 9, 6, 2, ., 8, 2, 8, 6, 9, 8, 0, 8, 0, 1, 5]
If you don't want to get the sign or period then
%i6) g(x):=sublist(f(x),alphanumericp);
(%o6) g(x) := sublist(f(x), alphanumericp)
(%i7) g(345); g(3^20); g(-3^20); g(3.1^10);
(%o7) [3, 4, 5]
(%o8) [3, 4, 8, 6, 7, 8, 4, 4, 0, 1]
(%o9) [3, 4, 8, 6, 7, 8, 4, 4, 0, 1]
(%o10) [8, 1, 9, 6, 2, 8, 2, 8, 6, 9, 8, 0, 8, 0, 1, 5]
nobody is perfect :
(%i11) g(3.1^50);
(%o11) [3, 6, 9, 9, 0, 0, 3, 0, 6, 9, 6, 0, 7, 6, 1, 2, 2, E, 2, 4]
(and if you delete the E, it is even worse because mixes mantissa and
exponent !)
Eric
> Best regards
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>
More information about the Maxima
mailing list