FullArrayIndexSet

By Xah Lee. Date:

Here's another tree related recreational prograMing problem. In this message, a solution to a given problem is given. Reader is asked to supply alternative approches.

The problem:

Write a function FullArrayIndexSet such that FullArrayIndexSet[{i1,i2,…},(Heads->False)] returns a complete index set for an array of given dimensions {i1,i2,…}. The option Heads→True will consider Heads as parts of the array (and generate their indexes).

Description: Suppose {a,b,c} is the given index, and we have Heads→True. We want to generate all the following: {0,0,0}≤({i},{i,j},{i,j,k})≤{a,b,c}.

```{{0},{1},{2},{0,0},{0,1},{0,2},{1,0},{1,1},{1,2},{2,0},{2,1},{2,2},
{0,0,0},{0,0,1},{0,0,2},{0,1,0},{0,1,1},{0,1,2},{0,2,0},{0,2,1},{0,2,2},
{1,0,0},{1,0,1},{1,0,2},{1,1,0},{1,1,1},{1,1,2},{1,2,0},{1,2,1},{1,2,2},
{2,0,0},{2,0,1},{2,0,2},{2,1,0},{2,1,1},{2,1,2},{2,2,0},{2,2,1},{2,2,2}}```

(not necessarily in that order, but let's suppose this is the order we want.)

The result of FullArrayIndexSet[indexes,Heads->False] can be specified neatly in terms of FullArrayIndexSet[indexes,Heads->True] by the definition:

```FullArrayIndexSet[indexes_List, Heads->False]:=
(DeleteCases[#,{___,0,__},{1,-1}]&)@
```

One Solution:

```Clear[FullArrayIndexSet];
FullArrayIndexSet::"usage"=
returns a complete index set for an array of given dimensions {i1,i2,...}.
(and generate their indexes). Example: