One misstatement and some clarifications on my previous post:
dom =: 1<;.2 (49 2$(,7 7#:i.49){dice)
NB. This statement creates all the possible combinations of dominoes with
NB. up to 6 dots (including blank) using the odometer function. It creates 49
NB. dominoes, but the set contains several mirror duplicates, which must be
NB. removed.
NB. This function creates a triangular matrix:
>/[email protected]
0 0 0 0 0 0 0
1 0 0 0 0 0 0
1 1 0 0 0 0 0
1 1 1 0 0 0 0
1 1 1 1 0 0 0
1 1 1 1 1 0 0
1 1 1 1 1 1 0
NB. Raveling and inverting the triangular matrix creates a duplication mask:
dupm =: -. , >/[email protected]
NB. So to remove dups, just apply the mask to the list of 49 dominoes:
final =: dupm # dom
$ dupm # dom
28
Skip Cave
Cave Consulting LLC
On Sun, Oct 5, 2014 at 10:31 PM, Skip Cave <[email protected]> wrote:
> Ooops, you're right! Forgot about the dups.
>
> 1<;.2 (49 2$(,7 7#:i.49){dice) NB. This gives all 28 unique dominoes
>
> -.,>/[email protected] NB. This is the dup mask
>
> (-.,>/[email protected]) # 1<;.2 (49 2$(,7 7#:i.49){dice) NB. All dominos with dups
> removed
>
> 4 7$ (-.,>/[email protected]) # 1<;.2 (49 2$(,7 7#:i.49){dice) NB. All dominoes in a
> nice box.
>
> Skip
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm