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
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$ Aug 16 at 20:08
  • 1
    $\begingroup$ As an alternative to //Map@Sort//Union you could also use //DeleteDuplicatesBy@Sort $\endgroup$
    – Lukas Lang
    Aug 16 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$
    – Alan
    Aug 16 at 23:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.