How to use the Runs function in Version 13.3
How to use the Runs function in Version 13.3
I had used the Runs function years ago when doing some randomness testing. When I recently attempted to use it again, it was no longer accessible. This is from the Wolfram reference site:
| p |
Touse,youfirstneedtoloadtheusing["Combinatorica`"]
However, in version 13.3.1, the Combinatorica package can no longer be loaded:
In[]:=
Needs["Combinatorica`"]
Support explained that "Since many of the functions within the 'Combinatorica' package have been added to the base version of Mathematica, Mathematica throws an error message telling you that the function definitions within that package are being shadowed."In short, I was then advised that the best option might be to use an earlier version of Mathematica. However, it struck me that I could go directly to the Combinatorica.m file to search for the Runs function. Here is the code with a slight modification of the pattern test:
In[]:=
Runs[p_?PermutationListQ]:= Map (Apply[Take,{p,{#[[1]]+1,#[[2]]}}])&, Partition Join {0}, Select[Range[Length[p]-1],(p[[#]]>p[[#+1]])&], {Length[p]} , 2, 1 /;(Length[p]>0)Runs[{}]:={}
Happy to say, it works like a charm:
Happy to say, it works like a charm:
In[]:=
perm=PermutationList[RandomPermutation[16]]Runs[perm]
Out[]=
{4,2,1,10,3,5,6,13,12,9,15,11,7,8,14}
Out[]=
{{4},{2},{1,10},{3,5,6,13},{12},{9,15},{11},{7,8,14}}
