4
$\begingroup$

I want to make a list of dominoes. My attempt is as follows.

Subsets[#, {2}]~Join~Thread[{#, #}] &@Range[0, 6] 

{{0,1},{0,2},{0,3},{0,4},{0,5},{0,6},{1,2},{1,3},{1,4},{1,5},{1,6},{2,3},{2,4},{2,5},{2,6},{3,4},{3,5},{3,6},{4,5},{4,6},{5,6},{0,0},{1,1},{2,2},{3,3},{4,4},{5,5},{6,6}}

Is there any simpler way to generate dominoes?

$\endgroup$
0

2 Answers 2

6
$\begingroup$
0~Range~6~Subsets~{1, 2} /. {a_} :> {a, a} 
{{0, 0}, {1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {2, 3}, {2, 4}, {2, 5}, {2, 6}, {3, 4}, {3, 5}, {3, 6}, {4, 5}, {4, 6}, {5, 6}} 

Also

 0~Range~6~Tuples~2//Map@Sort//Union 
{{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}, {1, 1}, {1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {2, 2}, {2, 3}, {2, 4}, {2, 5}, {2, 6}, {3, 3}, {3, 4}, {3, 5}, {3, 6}, {4, 4}, {4, 5}, {4, 6}, {5, 5}, {5, 6}, {6, 6}} 

and

f = If[# <= #2, {##}, Nothing] &; Join @@ Array[f, {7, 7}, 0] 

same result

$\endgroup$
2
  • 1
    $\begingroup$ I believe you will provide me with more than one solution as usual. $\endgroup$ Commented Aug 16, 2021 at 20:08
  • 1
    $\begingroup$ As an alternative to //Map@Sort//Union you could also use //DeleteDuplicatesBy@Sort $\endgroup$ Commented Aug 16, 2021 at 21:16
4
$\begingroup$

A Table-full way:

Flatten[Table[{j, i}, {i, 0, 6}, {j, 0, i}], 1] // Sort 
$\endgroup$
1
  • 1
    $\begingroup$ Catenate@Table[{r, k}, {r, 0, 6}, {k, r, 6}] $\endgroup$ Commented Aug 16, 2021 at 23:19

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.