Group Abstract Group Abstract

Message Boards Message Boards

0
|
10.8K Views
|
4 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Generate a list with any number

Posted 11 years ago
POSTED BY: Camilo Pacheco
4 Replies

Taken literally it is

In[2]:= pachecoL[n_Integer?Positive] := 
 Block[{x = {{2, 1}, {3, 1}, {2, 2}, {5, 1}, {2, 1}, {3, 1}, {7, 1}, {2, 3}, {3, 2}, {2, 1}, {5, 1}, Missing[]}},
  If[n >= Length[x], x[[-1]], Take[x, n]]
]

In[3]:= pachecoL[5]
Out[3]= {{2, 1}, {3, 1}, {2, 2}, {5, 1}, {2, 1}}
POSTED BY: Udo Krause
Posted 11 years ago

For example I introduce number 5 in n and the number give a range of the list

n=5;

{{2, 1}, {3, 1}, {2, 2}, {5, 1}, {2, 1}}

POSTED BY: Camilo Pacheco
POSTED BY: Robert Hanlon

Hi Camilo,

I do not understand the question. What do you mean with next list with any number? Do you mean that you want to add another list of to numbers to that list. Something like:

list = {{2, 1}, {3, 1}, {2, 2}, {5, 1}, {2, 1}, {3, 1}, {7, 1}, {2, 3}, {3, 2}, {2, 1}, {5, 1}}

AppendTo[list, {RandomInteger[7], RandomInteger[7]}]

That would add one entry, i.e. a list of two numbers, to the outer list. Or do you want to add another list to that list like so:

Nest[Append[#, RandomInteger[7, Last[Dimensions /@ {list}]]] &, {list}, 3]

which would do the procedure 3 times and add an additional list of the same shape as the first one?

Cheers,

Marco

POSTED BY: Marco Thiel
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard