Dear Sander,
nice! Obviously Tuples works fastest - in accordance with the general rule to use tailored build in functions whenever possible. But I always learn something from your code - thank you!
Tuples
Best regards -- Henrik
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 ...
@Henrik Schachner I doubt shorter! Faster: possibly!
List~Array~{n,n}
is two characters shorter, but the output is in a slightly different form.
Is this what you are looking for?
n = 2; Tuples[Range[n], {2}]
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
Hi Clément,
when looking for a specific function (a typical task!) I always try to find a "similar" one, i.e. one inside the same "topical orbit": Then in the documentation under "See Also" one most likely finds the one needed. E.g. looking up for Permutations one gets the hint for Tuples. This is in general an excellent way of exploring the wealth of functions in Mathematica.
Permutations
Regards -- Henrik