A replacement for NextPermutation in CombinatoricaPermutations[Range[12]] produces an error instead of a listThe locations of (row-wise) minimum elements in a listHow to split a list with respect to its nested sublists?Convert Integer to Numeric with Replacement rulesDuplicate-free results of permutations + constant listhow to generate all list combinations from a listHow to generate all involutive permutations?How to delete lists that contain sublists of different sizes?Replacement Rule for “flattening” list whilst adding attributesImport files AppendTo and ToExpression
What is it called when you use wrong but smart arguments?
Why are Starfleet vessels designed with nacelles so far away from the hull?
Is it realistic that an advanced species isn't good at war?
Ginger Baker dead: Why is he been called the most dangerous drummer?
What is the fastest algorithm for finding the natural logarithm of a big number?
How much income am I getting by renting my house?
Sanitize and build data structure from Consul configuration
Why does this route work with a slash and not a dash?
Legality of creating a SE replica using SE's content
What is the German word for: "It only works when I try to show you how it does not work"?
Paper status "Accept with Shepherd". What does it really mean?
Is there a historical explanation as to why the USA people are so litigious compared to France?
Rule of thumb: how far before changing my chain to prevent cassette wear
Why "come" instead of "go"?
When to use Slots vs Public Properties vs Getter Properties in LWC exactly?
A replacement for NextPermutation in Combinatorica
Possible omission of a relative pronoun in the beginning of a clause?
Displaying characteristics of the Hero in a console game
Is it OK to use internal pull-down as part of voltage divider?
Source for "no Yetzer Harah when a Torah Scroll is opened/read"?
Is a light year a different distance if measured from a moving object?
What does the British parliament hope to achieve by requesting a third Brexit extension?
SSD or HDD for server
Is it reasonable to ask candidates to create a profile on Google Scholar?
A replacement for NextPermutation in Combinatorica
Permutations[Range[12]] produces an error instead of a listThe locations of (row-wise) minimum elements in a listHow to split a list with respect to its nested sublists?Convert Integer to Numeric with Replacement rulesDuplicate-free results of permutations + constant listhow to generate all list combinations from a listHow to generate all involutive permutations?How to delete lists that contain sublists of different sizes?Replacement Rule for “flattening” list whilst adding attributesImport files AppendTo and ToExpression
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty
margin-bottom:0;
.everyonelovesstackoverflowposition:absolute;height:1px;width:1px;opacity:0;top:0;left:0;pointer-events:none;
$begingroup$
Does anyone know of a replacement for NextPermutation
in Combinatorica? The problem with loading Combinatorica is that it interferes with new functionality which I also want to use. I need to generate all the permutations of a list in lexicographic order one by one. Thanks for your help.
list-manipulation discrete
$endgroup$
|
show 1 more comment
$begingroup$
Does anyone know of a replacement for NextPermutation
in Combinatorica? The problem with loading Combinatorica is that it interferes with new functionality which I also want to use. I need to generate all the permutations of a list in lexicographic order one by one. Thanks for your help.
list-manipulation discrete
$endgroup$
$begingroup$
If you want all permutations in canonical order just usePermutations
Forperm = Permutations[a, b, c, d, e, f, g];
thenOrderedQ[perm]
evaluates toTrue
$endgroup$
– Bob Hanlon
8 hours ago
$begingroup$
@BobHanlon The problem with this approach is that you get all the permutations at once in memory, which I want to avoid ... I want to access them one by one, else there are too many ... there are close to 40 M permutations with lists that have 11 members, too many to have in memory, but it is possible with some time to look at each one of them and seek the property I want ... does this make sense?
$endgroup$
– EGME
8 hours ago
$begingroup$
Can you explain more about what do you need to do? (Not all people here might be familiar with theCombinatorica
package).
$endgroup$
– TumbiSapichu
8 hours ago
$begingroup$
@TumbiSapichu Right: I would like to access each and all of the permutations of a list, one at a time. A function like Permutations that returns all the permutations is of no use, given the large number of permutations that I need to inspect. The logical way make sure you access each and every permutation is to do so in some order, say, the lexicographic order. Does this make sense? So the function NextPermutation applied to the list 1,2,3 would return 1,3,2 ... essentially I want a function that implements this ... it used to exist, in the Combinatorica package ... contd.
$endgroup$
– EGME
8 hours ago
$begingroup$
@TumbiSapichu The problem with loading Combinatorica is that it overlaps with functionality that has replaced some of what is in there ...
$endgroup$
– EGME
8 hours ago
|
show 1 more comment
$begingroup$
Does anyone know of a replacement for NextPermutation
in Combinatorica? The problem with loading Combinatorica is that it interferes with new functionality which I also want to use. I need to generate all the permutations of a list in lexicographic order one by one. Thanks for your help.
list-manipulation discrete
$endgroup$
Does anyone know of a replacement for NextPermutation
in Combinatorica? The problem with loading Combinatorica is that it interferes with new functionality which I also want to use. I need to generate all the permutations of a list in lexicographic order one by one. Thanks for your help.
list-manipulation discrete
list-manipulation discrete
edited 5 hours ago
Szabolcs
172k18 gold badges468 silver badges1004 bronze badges
172k18 gold badges468 silver badges1004 bronze badges
asked 12 hours ago
EGMEEGME
1565 bronze badges
1565 bronze badges
$begingroup$
If you want all permutations in canonical order just usePermutations
Forperm = Permutations[a, b, c, d, e, f, g];
thenOrderedQ[perm]
evaluates toTrue
$endgroup$
– Bob Hanlon
8 hours ago
$begingroup$
@BobHanlon The problem with this approach is that you get all the permutations at once in memory, which I want to avoid ... I want to access them one by one, else there are too many ... there are close to 40 M permutations with lists that have 11 members, too many to have in memory, but it is possible with some time to look at each one of them and seek the property I want ... does this make sense?
$endgroup$
– EGME
8 hours ago
$begingroup$
Can you explain more about what do you need to do? (Not all people here might be familiar with theCombinatorica
package).
$endgroup$
– TumbiSapichu
8 hours ago
$begingroup$
@TumbiSapichu Right: I would like to access each and all of the permutations of a list, one at a time. A function like Permutations that returns all the permutations is of no use, given the large number of permutations that I need to inspect. The logical way make sure you access each and every permutation is to do so in some order, say, the lexicographic order. Does this make sense? So the function NextPermutation applied to the list 1,2,3 would return 1,3,2 ... essentially I want a function that implements this ... it used to exist, in the Combinatorica package ... contd.
$endgroup$
– EGME
8 hours ago
$begingroup$
@TumbiSapichu The problem with loading Combinatorica is that it overlaps with functionality that has replaced some of what is in there ...
$endgroup$
– EGME
8 hours ago
|
show 1 more comment
$begingroup$
If you want all permutations in canonical order just usePermutations
Forperm = Permutations[a, b, c, d, e, f, g];
thenOrderedQ[perm]
evaluates toTrue
$endgroup$
– Bob Hanlon
8 hours ago
$begingroup$
@BobHanlon The problem with this approach is that you get all the permutations at once in memory, which I want to avoid ... I want to access them one by one, else there are too many ... there are close to 40 M permutations with lists that have 11 members, too many to have in memory, but it is possible with some time to look at each one of them and seek the property I want ... does this make sense?
$endgroup$
– EGME
8 hours ago
$begingroup$
Can you explain more about what do you need to do? (Not all people here might be familiar with theCombinatorica
package).
$endgroup$
– TumbiSapichu
8 hours ago
$begingroup$
@TumbiSapichu Right: I would like to access each and all of the permutations of a list, one at a time. A function like Permutations that returns all the permutations is of no use, given the large number of permutations that I need to inspect. The logical way make sure you access each and every permutation is to do so in some order, say, the lexicographic order. Does this make sense? So the function NextPermutation applied to the list 1,2,3 would return 1,3,2 ... essentially I want a function that implements this ... it used to exist, in the Combinatorica package ... contd.
$endgroup$
– EGME
8 hours ago
$begingroup$
@TumbiSapichu The problem with loading Combinatorica is that it overlaps with functionality that has replaced some of what is in there ...
$endgroup$
– EGME
8 hours ago
$begingroup$
If you want all permutations in canonical order just use
Permutations
For perm = Permutations[a, b, c, d, e, f, g];
then OrderedQ[perm]
evaluates to True
$endgroup$
– Bob Hanlon
8 hours ago
$begingroup$
If you want all permutations in canonical order just use
Permutations
For perm = Permutations[a, b, c, d, e, f, g];
then OrderedQ[perm]
evaluates to True
$endgroup$
– Bob Hanlon
8 hours ago
$begingroup$
@BobHanlon The problem with this approach is that you get all the permutations at once in memory, which I want to avoid ... I want to access them one by one, else there are too many ... there are close to 40 M permutations with lists that have 11 members, too many to have in memory, but it is possible with some time to look at each one of them and seek the property I want ... does this make sense?
$endgroup$
– EGME
8 hours ago
$begingroup$
@BobHanlon The problem with this approach is that you get all the permutations at once in memory, which I want to avoid ... I want to access them one by one, else there are too many ... there are close to 40 M permutations with lists that have 11 members, too many to have in memory, but it is possible with some time to look at each one of them and seek the property I want ... does this make sense?
$endgroup$
– EGME
8 hours ago
$begingroup$
Can you explain more about what do you need to do? (Not all people here might be familiar with the
Combinatorica
package).$endgroup$
– TumbiSapichu
8 hours ago
$begingroup$
Can you explain more about what do you need to do? (Not all people here might be familiar with the
Combinatorica
package).$endgroup$
– TumbiSapichu
8 hours ago
$begingroup$
@TumbiSapichu Right: I would like to access each and all of the permutations of a list, one at a time. A function like Permutations that returns all the permutations is of no use, given the large number of permutations that I need to inspect. The logical way make sure you access each and every permutation is to do so in some order, say, the lexicographic order. Does this make sense? So the function NextPermutation applied to the list 1,2,3 would return 1,3,2 ... essentially I want a function that implements this ... it used to exist, in the Combinatorica package ... contd.
$endgroup$
– EGME
8 hours ago
$begingroup$
@TumbiSapichu Right: I would like to access each and all of the permutations of a list, one at a time. A function like Permutations that returns all the permutations is of no use, given the large number of permutations that I need to inspect. The logical way make sure you access each and every permutation is to do so in some order, say, the lexicographic order. Does this make sense? So the function NextPermutation applied to the list 1,2,3 would return 1,3,2 ... essentially I want a function that implements this ... it used to exist, in the Combinatorica package ... contd.
$endgroup$
– EGME
8 hours ago
$begingroup$
@TumbiSapichu The problem with loading Combinatorica is that it overlaps with functionality that has replaced some of what is in there ...
$endgroup$
– EGME
8 hours ago
$begingroup$
@TumbiSapichu The problem with loading Combinatorica is that it overlaps with functionality that has replaced some of what is in there ...
$endgroup$
– EGME
8 hours ago
|
show 1 more comment
2 Answers
2
active
oldest
votes
$begingroup$
See page 57 of the book Computational Discrete Mathematics by Pemmaraju and Skiena.
NextPermutation[l_List] := Sort[l] /; (l === Reverse[Sort[l]])
NextPermutation[l_List] :=
Module[n = Length[l], i, j, t, nl = l,
i = n - 1;
While[Order[nl[[i]], nl[[i + 1]]] == -1, i--];
j = n;
While[Order[nl[[j]], nl[[i]]] == 1, j--];
nl[[i]], nl[[j]] = nl[[j]], nl[[i]];
Join[Take[nl, i], Reverse[Drop[nl, i]]]
]
For example:
NextPermutation[8, 7, 6, 5, 4, 3, 2, 1]
1, 2, 3, 4, 5, 6, 7, 8
NextPermutation[7, 12, 4, 1, 3, 10, 5, 6, 8, 11, 2, 9]
7, 12, 4, 1, 3, 10, 5, 6, 8, 11, 9, 2
$endgroup$
add a comment
|
$begingroup$
The best way for me to do what you are asking for is to, if I remember correctly from the last time I did something like this.
Open up Combinatorica.m in a fresh notebook. It contains what looks like Mathematica code and Mathematica is happy to do this. The last time I looked the Combinatorica.m file is still there buried down inside the installed Mathematica files. Try searching your entire file system for the name if you can't find it.
Scroll down and find the well written self contained definition of
NextPermutation
Scrape that definition into your clipboard
Close the notebook without changing Combinatorica.m
Open up your notebook
Paste the definition into your notebook, along with credits, where it came from and how to find it and do this again if you need to
and you are ready to go with your own personal copy of NextPermutation
in your notebook without any of the other definitions from combinatorica.m
$endgroup$
add a comment
|
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "387"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f207403%2fa-replacement-for-nextpermutation-in-combinatorica%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
See page 57 of the book Computational Discrete Mathematics by Pemmaraju and Skiena.
NextPermutation[l_List] := Sort[l] /; (l === Reverse[Sort[l]])
NextPermutation[l_List] :=
Module[n = Length[l], i, j, t, nl = l,
i = n - 1;
While[Order[nl[[i]], nl[[i + 1]]] == -1, i--];
j = n;
While[Order[nl[[j]], nl[[i]]] == 1, j--];
nl[[i]], nl[[j]] = nl[[j]], nl[[i]];
Join[Take[nl, i], Reverse[Drop[nl, i]]]
]
For example:
NextPermutation[8, 7, 6, 5, 4, 3, 2, 1]
1, 2, 3, 4, 5, 6, 7, 8
NextPermutation[7, 12, 4, 1, 3, 10, 5, 6, 8, 11, 2, 9]
7, 12, 4, 1, 3, 10, 5, 6, 8, 11, 9, 2
$endgroup$
add a comment
|
$begingroup$
See page 57 of the book Computational Discrete Mathematics by Pemmaraju and Skiena.
NextPermutation[l_List] := Sort[l] /; (l === Reverse[Sort[l]])
NextPermutation[l_List] :=
Module[n = Length[l], i, j, t, nl = l,
i = n - 1;
While[Order[nl[[i]], nl[[i + 1]]] == -1, i--];
j = n;
While[Order[nl[[j]], nl[[i]]] == 1, j--];
nl[[i]], nl[[j]] = nl[[j]], nl[[i]];
Join[Take[nl, i], Reverse[Drop[nl, i]]]
]
For example:
NextPermutation[8, 7, 6, 5, 4, 3, 2, 1]
1, 2, 3, 4, 5, 6, 7, 8
NextPermutation[7, 12, 4, 1, 3, 10, 5, 6, 8, 11, 2, 9]
7, 12, 4, 1, 3, 10, 5, 6, 8, 11, 9, 2
$endgroup$
add a comment
|
$begingroup$
See page 57 of the book Computational Discrete Mathematics by Pemmaraju and Skiena.
NextPermutation[l_List] := Sort[l] /; (l === Reverse[Sort[l]])
NextPermutation[l_List] :=
Module[n = Length[l], i, j, t, nl = l,
i = n - 1;
While[Order[nl[[i]], nl[[i + 1]]] == -1, i--];
j = n;
While[Order[nl[[j]], nl[[i]]] == 1, j--];
nl[[i]], nl[[j]] = nl[[j]], nl[[i]];
Join[Take[nl, i], Reverse[Drop[nl, i]]]
]
For example:
NextPermutation[8, 7, 6, 5, 4, 3, 2, 1]
1, 2, 3, 4, 5, 6, 7, 8
NextPermutation[7, 12, 4, 1, 3, 10, 5, 6, 8, 11, 2, 9]
7, 12, 4, 1, 3, 10, 5, 6, 8, 11, 9, 2
$endgroup$
See page 57 of the book Computational Discrete Mathematics by Pemmaraju and Skiena.
NextPermutation[l_List] := Sort[l] /; (l === Reverse[Sort[l]])
NextPermutation[l_List] :=
Module[n = Length[l], i, j, t, nl = l,
i = n - 1;
While[Order[nl[[i]], nl[[i + 1]]] == -1, i--];
j = n;
While[Order[nl[[j]], nl[[i]]] == 1, j--];
nl[[i]], nl[[j]] = nl[[j]], nl[[i]];
Join[Take[nl, i], Reverse[Drop[nl, i]]]
]
For example:
NextPermutation[8, 7, 6, 5, 4, 3, 2, 1]
1, 2, 3, 4, 5, 6, 7, 8
NextPermutation[7, 12, 4, 1, 3, 10, 5, 6, 8, 11, 2, 9]
7, 12, 4, 1, 3, 10, 5, 6, 8, 11, 9, 2
answered 6 hours ago
KennyColnagoKennyColnago
12.7k20 silver badges55 bronze badges
12.7k20 silver badges55 bronze badges
add a comment
|
add a comment
|
$begingroup$
The best way for me to do what you are asking for is to, if I remember correctly from the last time I did something like this.
Open up Combinatorica.m in a fresh notebook. It contains what looks like Mathematica code and Mathematica is happy to do this. The last time I looked the Combinatorica.m file is still there buried down inside the installed Mathematica files. Try searching your entire file system for the name if you can't find it.
Scroll down and find the well written self contained definition of
NextPermutation
Scrape that definition into your clipboard
Close the notebook without changing Combinatorica.m
Open up your notebook
Paste the definition into your notebook, along with credits, where it came from and how to find it and do this again if you need to
and you are ready to go with your own personal copy of NextPermutation
in your notebook without any of the other definitions from combinatorica.m
$endgroup$
add a comment
|
$begingroup$
The best way for me to do what you are asking for is to, if I remember correctly from the last time I did something like this.
Open up Combinatorica.m in a fresh notebook. It contains what looks like Mathematica code and Mathematica is happy to do this. The last time I looked the Combinatorica.m file is still there buried down inside the installed Mathematica files. Try searching your entire file system for the name if you can't find it.
Scroll down and find the well written self contained definition of
NextPermutation
Scrape that definition into your clipboard
Close the notebook without changing Combinatorica.m
Open up your notebook
Paste the definition into your notebook, along with credits, where it came from and how to find it and do this again if you need to
and you are ready to go with your own personal copy of NextPermutation
in your notebook without any of the other definitions from combinatorica.m
$endgroup$
add a comment
|
$begingroup$
The best way for me to do what you are asking for is to, if I remember correctly from the last time I did something like this.
Open up Combinatorica.m in a fresh notebook. It contains what looks like Mathematica code and Mathematica is happy to do this. The last time I looked the Combinatorica.m file is still there buried down inside the installed Mathematica files. Try searching your entire file system for the name if you can't find it.
Scroll down and find the well written self contained definition of
NextPermutation
Scrape that definition into your clipboard
Close the notebook without changing Combinatorica.m
Open up your notebook
Paste the definition into your notebook, along with credits, where it came from and how to find it and do this again if you need to
and you are ready to go with your own personal copy of NextPermutation
in your notebook without any of the other definitions from combinatorica.m
$endgroup$
The best way for me to do what you are asking for is to, if I remember correctly from the last time I did something like this.
Open up Combinatorica.m in a fresh notebook. It contains what looks like Mathematica code and Mathematica is happy to do this. The last time I looked the Combinatorica.m file is still there buried down inside the installed Mathematica files. Try searching your entire file system for the name if you can't find it.
Scroll down and find the well written self contained definition of
NextPermutation
Scrape that definition into your clipboard
Close the notebook without changing Combinatorica.m
Open up your notebook
Paste the definition into your notebook, along with credits, where it came from and how to find it and do this again if you need to
and you are ready to go with your own personal copy of NextPermutation
in your notebook without any of the other definitions from combinatorica.m
edited 7 hours ago
answered 7 hours ago
BillBill
7,4437 silver badges9 bronze badges
7,4437 silver badges9 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Mathematica Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f207403%2fa-replacement-for-nextpermutation-in-combinatorica%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
If you want all permutations in canonical order just use
Permutations
Forperm = Permutations[a, b, c, d, e, f, g];
thenOrderedQ[perm]
evaluates toTrue
$endgroup$
– Bob Hanlon
8 hours ago
$begingroup$
@BobHanlon The problem with this approach is that you get all the permutations at once in memory, which I want to avoid ... I want to access them one by one, else there are too many ... there are close to 40 M permutations with lists that have 11 members, too many to have in memory, but it is possible with some time to look at each one of them and seek the property I want ... does this make sense?
$endgroup$
– EGME
8 hours ago
$begingroup$
Can you explain more about what do you need to do? (Not all people here might be familiar with the
Combinatorica
package).$endgroup$
– TumbiSapichu
8 hours ago
$begingroup$
@TumbiSapichu Right: I would like to access each and all of the permutations of a list, one at a time. A function like Permutations that returns all the permutations is of no use, given the large number of permutations that I need to inspect. The logical way make sure you access each and every permutation is to do so in some order, say, the lexicographic order. Does this make sense? So the function NextPermutation applied to the list 1,2,3 would return 1,3,2 ... essentially I want a function that implements this ... it used to exist, in the Combinatorica package ... contd.
$endgroup$
– EGME
8 hours ago
$begingroup$
@TumbiSapichu The problem with loading Combinatorica is that it overlaps with functionality that has replaced some of what is in there ...
$endgroup$
– EGME
8 hours ago