Re: 2^[1,3]
"Ruud H.G. van Tol" <[email protected]>
| Newsgroups | gmane.comp.mathematics.pari.user |
|---|---|
| Message-ID | <[email protected]> |
On 2025-01-29 22:07, Bill Allombert wrote:
> On Wed, Jan 29, 2025 at 03:51:26PM +0100, Bill Allombert wrote:
>> On Wed, Jan 29, 2025 at 03:24:02PM +0100, Ruud H.G. van Tol wrote:
>>> On 2025-01-29 14:42, Bill Allombert wrote:
>>>> On Wed, Jan 29, 2025 at 02:28:46PM +0100, Ruud H.G. van Tol wrote:
>>>>> ? vecsum(2^[1,3])
>>>>> % 10.000000000000000000000000000000000000
>
> I geuss you can do vecsum([2^i|i<-[1,3]])
Yes, that is what was used in the initial email of this thread.
The shown example usage is to sum(2^[distinct decimal digits of a number]),
to derive a Map-key, for sorting integers into buckets.
I guess the basic wish here, is to more canonically create a meta-bitmap
from a Set(), and/or from the (non-negative integer) keys of a Map(), etc.
-- Ruud
Example usage:
? {
my(r=Map());
for(i=1, 200
, my(k=vecsum([ 1<<e |e<-Set(digits(i))]), v);
if(mapisdefined(r,k,&v), v=concat(v,[i]), v=[i]);
mapput(~r, k, v)
);
foreach(r, e \\ how to properly traverse a Map?
, my([k,v]=e[1]);
if(#v > 2
, printf("%4s => %s\n", k, v)
)
);
}
2 => [1, 11, 111]
3 => [10, 100, 101, 110]
6 => [12, 21, 112, 121, 122]
10 => [13, 31, 113, 131, 133]
18 => [14, 41, 114, 141, 144]
34 => [15, 51, 115, 151, 155]
66 => [16, 61, 116, 161, 166]
130 => [17, 71, 117, 171, 177]
258 => [18, 81, 118, 181, 188]
514 => [19, 91, 119, 191, 199]