Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Get permutations of the key-value pairs in an Association
ResourceFunction["AssociationPermutations"][assoc] generates a list of all possible permutations of the key-value elements in the Association assoc. | |
ResourceFunction["AssociationPermutations"][assoc,len] gives permutations of the specified lengths. |
n | permutations containing at most n key-value pairs |
{n} | permutations containing exactly n key-value pairs |
All | permutations of all lengths |
{min,max} | permutations of length between min and max |
{min,max,d} | lengths from min to max in steps of d |
Get all full-length permutations of an Association with three values:
In[1]:= |
Out[1]= |
Get permutations of length two:
In[2]:= |
Out[2]= |
Get permutations of all lengths, shortest ones first:
In[3]:= |
Out[3]= |
Lengths from one to two:
In[4]:= |
Out[4]= |
Lengths from one to three with step size two:
In[5]:= |
Out[5]= |
Kids love Yahtzee, but they always lose the dice. None of these kids have the requisite six dice to play:
In[6]:= |
Out[6]= |
Luckily, they can play together. Find the groups of kids that have at least six dice:
In[7]:= |
Out[7]= |
Permutations does not support Association:
In[8]:= |
Out[9]= |
Use AssociationPermuations instead:
In[10]:= |
Out[10]= |
The result is equivalent to using Permutations on the Keys:
In[11]:= |
Out[11]= |
AssociationPermutations does not evaluate delayed values:
In[12]:= |
Out[12]= |
This work is licensed under a Creative Commons Attribution 4.0 International License