Group Abstract Group Abstract

Message Boards Message Boards

0
|
8.5K Views
|
8 Replies
|
6 Total Likes
View groups...
Share
Share this post:

[?] Generate all sequences of n integer that range from 1 to n?

Hi everyone,

I am searching for a way to generate all sequences of n integers that range from 1 to n. In other words, for example with n = 2, something like

{{1,1},{1,2},{2,1},{2,2}}

Does anyone know an easy way to build such a function depending only on n?

Thanks! Clément

POSTED BY: Clément Justin
8 Replies

Thank you everybody! :)

Clément

POSTED BY: Clément Justin
POSTED BY: Sander Huisman
POSTED BY: Henrik Schachner

Standard anwer (I am sure somebody will come up with a shorter one):

tuples2[n_Integer] := Tuples[Range[n], 2]

@Paul: Sorry, I did not see your anwer in time ...

POSTED BY: Henrik Schachner

@Henrik Schachner I doubt shorter! Faster: possibly!

List~Array~{n,n} 

is two characters shorter, but the output is in a slightly different form.

POSTED BY: Sander Huisman
Posted 9 years ago
POSTED BY: Paul Cleary

Well thank you, the function Tuples was exactly what I was looking for. But I couldn't find the right tag words to find it in the documentation... Didn't think about typing "tuples" haha!

Thanks a lot! Clément

POSTED BY: Clément Justin
POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard