Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
2 added 46 characters in body
source | link

MATL, 1515 12 bytes

3 bytes saved thanks to @Giuseppe

[]invin:"G1@&"G@:)]Xh

Try it at MATL OnlineMATL Online.

Due to the way that MATL displays the output, you can't explicitly see the empty array in the cell array. HereHere is a version that shows the output a little more explicitly.

Explanation

[]v       # ExplicitlyVertically pushconcatenate anthe (empty) arraystack ontoto create the stackarray []
i       # Explicitly grab the input
n       # Compute the number of elements in the input (N)
:       # Create an array from [1, ..., N]
"       # Loop through this array
  G     # For each of these numbers, M
  1@&@:    # Create an array from [1, ..., M]
  )     # Use this to index into the initial array
]       # End of the for loop
Xh      # Concatenate the entire stack into a cell array

MATL, 15 bytes

[]in:"G1@&:)]Xh

Try it at MATL Online.

Due to the way that MATL displays the output, you can't explicitly see the empty array in the cell array. Here is a version that shows the output a little more explicitly.

Explanation

[]      # Explicitly push an empty array onto the stack
i       # Explicitly grab the input
n       # Compute the number of elements in the input (N)
:       # Create an array from [1, ..., N]
"       # Loop through this array
  G     # For each of these numbers, M
  1@&:  # Create an array from [1, ..., M]
  )     # Use this to index into the initial array
]       # End of the for loop
Xh      # Concatenate the entire stack into a cell array

MATL, 15 12 bytes

3 bytes saved thanks to @Giuseppe

vin:"G@:)]Xh

Try it at MATL Online.

Due to the way that MATL displays the output, you can't explicitly see the empty array in the cell array. Here is a version that shows the output a little more explicitly.

Explanation

v       # Vertically concatenate the (empty) stack to create the array []
i       # Explicitly grab the input
n       # Compute the number of elements in the input (N)
:       # Create an array from [1, ..., N]
"       # Loop through this array
  G     # For each of these numbers, M
  @:    # Create an array from [1, ..., M]
  )     # Use this to index into the initial array
]       # End of the for loop
Xh      # Concatenate the entire stack into a cell array
1
source | link

MATL, 15 bytes

[]in:"G1@&:)]Xh

Try it at MATL Online.

Due to the way that MATL displays the output, you can't explicitly see the empty array in the cell array. Here is a version that shows the output a little more explicitly.

Explanation

[]      # Explicitly push an empty array onto the stack
i       # Explicitly grab the input
n       # Compute the number of elements in the input (N)
:       # Create an array from [1, ..., N]
"       # Loop through this array
  G     # For each of these numbers, M
  1@&:  # Create an array from [1, ..., M]
  )     # Use this to index into the initial array
]       # End of the for loop
Xh      # Concatenate the entire stack into a cell array