help-octave
[Top][All Lists]

## Re: how to make a matrix with all combinations of digits efficiently

 From: Jean Dubois Subject: Re: how to make a matrix with all combinations of digits efficiently Date: Sat, 30 Dec 2017 17:08:18 +0100

```2017-12-29 19:13 GMT+01:00 Juan Pablo Carbajal <address@hidden>:
>> in fact I need decomp(10,10)
>
> The issue with memory or index size are rather unavoidable. Do you
> really need all this?
> What is your intended use of counter? I am pretty sure you do not neet
> to allocate nor have simultaneously such an enormous amount of
> numbers.
> Note that my solution works even for a single number "i", that means
> you could call the function to decompose a given number everytime you
> need a results, i.e.
>
> function digits = dec2digit (num, base = 10)
> nc      = ceil (log (num) / log (base));
> digits = mod( floor (num ./ base.^[(nc-1):-1:0]), base);
> endfunction
>
> example
>
> dec2digit (537)
> ans =
>
>    5   3   7
>
> another one
>
> d = dec2digit (707, 16);
> n = length (d);
> d * 16.^[(n-1):-1:0].'
> ans =  707
>
> another one
>
> num = randi (10e10);
> dec2digit (num)   # this one should be one of the ones you need.
>
> If you are calling this from a loop, then you do not have memory
> problems. You cna also use batches of numbers that follow a memory
> restriction, i.e. work with batches of 1MB, then 1e6/8/10  is more or
> less the number of rows of the matrix for that batch.
Thanks a lot for all the help and suggestions offered, you are right
that I'll have to limit the number of cases involved first myself
rather
than presenting the problem in a brute force way which I first hoped to do.

kind regards,

```