I am just getting started with Wolfram Mathematica 9, and am trying to learn how to use the Outer function. I have a problem where I want to generate a list containing all possible outcomes from rolling two dice. I have the following list to start with.

numbers = { 1, 2, 3, 4, 5, 6 }

The list I want to generate should be on the following form.

{ { 1, 1 }, { 1, 2 }, { 1, 3 }, ..., { 6, 6 } }

I have tried things like

Outer[Times, numbers, numbers]

to no avail. How do I solve this problem?

Thank you in advance!

有帮助吗?

解决方案

If you want to stick to Outer try Outer[List,numbers,numbers].

其他提示

As alluded to, there is another way to do this. Consider Subsets[Range[1, 6], {2}]

You can also use Join by Outer[{#1}~Join~{#2},numbers,numbers].

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top