MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Variable-length list?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83489] Re: [mg83417] Variable-length list?
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Wed, 21 Nov 2007 03:01:25 -0500 (EST)
  • References: <26494129.1195601742132.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

This is precisely what Array does. For instance:

Clear[f, g]
f[m_?(VectorQ[#, IntegerQ] &)] := Flatten[Array[g, m], Length@m - 1]

g = List[##] &;
f[{3, 4, 2}]

{{1, 1, 1}, {1, 1, 2}, {1, 2, 1}, {1, 2, 2}, {1, 3, 1}, {1, 3, 2}, {1,
    4, 1}, {1, 4, 2}, {2, 1, 1}, {2, 1, 2}, {2, 2, 1}, {2, 2, 2}, {2,
   3, 1}, {2, 3, 2}, {2, 4, 1}, {2, 4, 2}, {3, 1, 1}, {3, 1, 2}, {3, 2,
    1}, {3, 2, 2}, {3, 3, 1}, {3, 3, 2}, {3, 4, 1}, {3, 4, 2}}

or

g = Print[Times[##]] &;
f[{3, 4}];

1

2

3

4

2

4

6

8

3

6

9

12

Bobby

On Tue, 20 Nov 2007 02:45:46 -0600, Hoa Bui <hoabui05 at gmail.com> wrote:

> Hi all,
>
> I want to have either a module or a function that inputs a
> varying-length list M[[nx]], where nx is a parameter, and accesses all=

> of its elements.
>
> For example:
>
> f[M_?(Function[v,VectorQ[v,IntegerQ]]]:=Module[{i,j,k},
> ...
> ]
>
> If M={3,4} then f would do something like:
> For [i=1,i<3,i++,
> For [j=1,j<4,j++,
> Print[i*j];
> ]
> ]
>
> If M={3,4,5} then:
> For [i=1,i<3,i++,
> For [j=1,j<4,j++,
> For [k=1,k<5,j++,
> Print[i*j*k];
> ]
> ]
> ]
> ]
>
>
> I wonder if this is doable in Mathematica, and/or what would be a way =
to  =

> do it?
>
> Thanks a lot,
> Hoa
>
>



-- =

DrMajorBob at bigfoot.com


  • Prev by Date: Re: Extra spacing in GraphicsGrid
  • Next by Date: Re: Solving Tanh[x]=Tanh[a]Tanh[b x + c]
  • Previous by thread: Re: Variable-length list?
  • Next by thread: Re: Variable-length list?