Hi there, which would be your most elegant way to split a number into a list of digits? that is, I have the number 512 and I want the list 5 1 2
You can do this:
"5 1 2"
Le dim. 17 janv. 2021 à 18:23, Jeppi Jeppi jeppiot@hotmail.com a écrit :
Hi there, which would be your most elegant way to split a number into a list of digits? that is, I have the number 512 and I want the list 5 1 2 _______________________________________________ Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list
Wow brilliant, super elegant. many thanks! josep m ________________________________ From: Antoine Rousseau antoine@metalu.net Sent: Sunday, January 17, 2021 7:15 PM To: Jeppi Jeppi jeppiot@hotmail.com Cc: pd-list@lists.iem.at pd-list@lists.iem.at Subject: Re: [PD] split number into digits
You can do this:
Le dim. 17 janv. 2021 à 18:23, Jeppi Jeppi <jeppiot@hotmail.commailto:jeppiot@hotmail.com> a écrit : Hi there, which would be your most elegant way to split a number into a list of digits? that is, I have the number 512 and I want the list 5 1 2 _______________________________________________ Pd-list@lists.iem.atmailto:Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list
maybe with [mod]. Is the number always going to have 3 digits??
playing around in 3 minutes, I came up with this (see picture attached). I do not consider it to be elegant, but maybe its a place to start
cheers
On Sun, Jan 17, 2021 at 1:18 PM Antoine Rousseau antoine@metalu.net wrote:
You can do this:
- transform "float 512" into "symbol 512" using [makefilename %d]
- then transform "symbol 512" into "list 53 49 50" with [list fromsymbol].
- finally subtract 48 (which is the ascii for "0") from every item, you
get "5 1 2"
Le dim. 17 janv. 2021 à 18:23, Jeppi Jeppi jeppiot@hotmail.com a écrit :
Hi there, which would be your most elegant way to split a number into a list of digits? that is, I have the number 512 and I want the list 5 1 2 _______________________________________________ Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list
Pd-list@lists.iem.at mailing list UNSUBSCRIBE and account-management -> https://lists.puredata.info/listinfo/pd-list
On Sun, 2021-01-17 at 13:29 -0500, José Rafael Subía Valdez wrote:
maybe with [mod]. Is the number always going to have 3 digits??
playing around in 3 minutes, I came up with this (see picture attached). I do not consider it to be elegant, but maybe its a place to start
attached patch works with any number of digits (following Claude's suggestion).
On 17/01/21 22:07, Roman Haefeli wrote:
On Sun, 2021-01-17 at 13:29 -0500, José Rafael Subía Valdez wrote:
maybe with [mod]. Is the number always going to have 3 digits??
playing around in 3 minutes, I came up with this (see picture attached). I do not consider it to be elegant, but maybe its a place to start
attached patch works with any number of digits (following Claude's suggestion).
And a variation on the theme (still seems to have problems with 'larger' numbers...) :-)
Hi Antoine,
On 17/01/2021 18:15, Antoine Rousseau wrote:
- transform "float 512" into "symbol 512" using [makefilename %d]
I would not recommend this, because symbols stick around forever and Pd gets slower the more symbols there are. AKA "symbol table pollution".
Instead, better to use [mod 10] to get the least significant digit, and [div 10] to get the most significant digits (then repeat until you have all the digits). This approach also works for bases other than 10.
Em dom., 17 de jan. de 2021 às 16:18, Claude Heiland-Allen < claude@mathr.co.uk> escreveu:
Hi Antoine,
On 17/01/2021 18:15, Antoine Rousseau wrote:
- transform "float 512" into "symbol 512" using [makefilename %d]
I would not recommend this, because symbols stick around forever and Pd gets slower the more symbols there are. AKA "symbol table pollution".
But at what point does this become a real issue? And how come we don't have a better way to convert it to symbols?
On 1/17/21 9:35 PM, Alexandre Torres Porres wrote:
But at what point does this become a real issue? And how come we don't have a better way to convert it to symbols?
the problem is not with the "way to convert it to symbols", but with symbols itself.
it's the nature of symbols to not get lost. so the more symbols you create, the more they will clog your memory. with modern memory sizes this is usually not a problem. however, the way Pd stores and retrieves symbols is suboptimal, and degrades heavily with high numbers of symbols.
there's a PR (#1172) that attempts to alleviate the problem, but it hasn't been accepted into mainline Pd yet.
gfamdsr IOhannes