Click here to Skip to main content
15,894,825 members
Home / Discussions / C#
   

C#

 
GeneralRe: Sending a command to an IEnumerable method Pin
harold aptroot23-Oct-09 11:19
harold aptroot23-Oct-09 11:19 
GeneralRe: Sending a command to an IEnumerable method Pin
Ian Shlasko23-Oct-09 12:12
Ian Shlasko23-Oct-09 12:12 
GeneralRe: Sending a command to an IEnumerable method Pin
harold aptroot23-Oct-09 12:23
harold aptroot23-Oct-09 12:23 
GeneralRe: Sending a command to an IEnumerable method Pin
Ian Shlasko23-Oct-09 12:27
Ian Shlasko23-Oct-09 12:27 
GeneralRe: Sending a command to an IEnumerable method Pin
Lutosław23-Oct-09 23:55
Lutosław23-Oct-09 23:55 
GeneralRe: Sending a command to an IEnumerable method Pin
Lutosław24-Oct-09 1:18
Lutosław24-Oct-09 1:18 
GeneralRe: Sending a command to an IEnumerable method Pin
Lutosław24-Oct-09 1:04
Lutosław24-Oct-09 1:04 
Answer[SOLVED] Sending a command to an IEnumerable method Pin
Lutosław23-Oct-09 23:51
Lutosław23-Oct-09 23:51 
OK, I have given up my algoritm and have been using an implementation posted by harold (thanks mate). I have added two methods:
// Gets the fist permutation of given order which starts with a given beginning.
public void First(int[] beginning, int order)
{
    var check = new bool[order];
    for (int i = 0; i < beginning.Length; i++)
    {
        check[beginning[i]] = true;
        data[i] = beginning[i];
    }
    int checkI = 0;
    for (int i = beginning.Length; i < order; i++)
    {
        while (check[checkI]) 
            checkI++;
        data[i] = checkI;
        checkI++;
    }
}

and
public static IEnumerable<Permutation> GetPermutations(int order)
{
    var permutation = new Permutation(order);
    while ((permutation = permutation.GetSuccessor()) != null)
        yield return permutation;
}

And the usage:
var perm = new Permutation(5);
var beginning = new[] { 1 };
foreach (Permutation permutation in Permutation.GetPermutations(5))
{
    if (permutation.StartsWith(beginning))
    {
        permutation.First(new [] { 2}, perm.Order);
    }
    Console.WriteLine("{0} {1} {2} {3} {4}", permutation[0], permutation[1], permutation[2], permutation[3], permutation[4]);
}

The code above skips all permutations in form [1....].
Thanks!

Greetings - Jacek

GeneralRe: [SOLVED] Sending a command to an IEnumerable method Pin
harold aptroot24-Oct-09 1:22
harold aptroot24-Oct-09 1:22 
QuestionWhere to write application files on Vista/W7 Pin
BRShroyer23-Oct-09 8:05
BRShroyer23-Oct-09 8:05 
AnswerRe: Where to write application files on Vista/W7 Pin
Ian Shlasko23-Oct-09 8:13
Ian Shlasko23-Oct-09 8:13 
GeneralRe: Where to write application files on Vista/W7 Pin
BRShroyer23-Oct-09 8:19
BRShroyer23-Oct-09 8:19 
GeneralRe: Where to write application files on Vista/W7 Pin
Ian Shlasko23-Oct-09 8:46
Ian Shlasko23-Oct-09 8:46 
QuestionHow to control speakers individually? Pin
Gedon_Sarep23-Oct-09 8:03
Gedon_Sarep23-Oct-09 8:03 
QuestionAutomated save as webpage completed by C# Pin
Nguyễn Đức Thiện23-Oct-09 6:51
Nguyễn Đức Thiện23-Oct-09 6:51 
AnswerRe: Automated save as webpage completed by C# Pin
Not Active23-Oct-09 7:05
mentorNot Active23-Oct-09 7:05 
GeneralRe: Automated save as webpage completed by C# Pin
Nguyễn Đức Thiện23-Oct-09 7:12
Nguyễn Đức Thiện23-Oct-09 7:12 
AnswerMessage Closed Pin
23-Oct-09 7:45
stancrm23-Oct-09 7:45 
GeneralRe: Automated save as webpage completed by C# Pin
Nguyễn Đức Thiện23-Oct-09 15:31
Nguyễn Đức Thiện23-Oct-09 15:31 
QuestionBeginner in need of help Pin
Darren Shields23-Oct-09 6:04
Darren Shields23-Oct-09 6:04 
AnswerRe: Beginner in need of help Pin
Henry Minute23-Oct-09 6:16
Henry Minute23-Oct-09 6:16 
GeneralRe: Beginner in need of help Pin
Darren Shields23-Oct-09 6:30
Darren Shields23-Oct-09 6:30 
GeneralRe: Beginner in need of help Pin
Henry Minute23-Oct-09 6:44
Henry Minute23-Oct-09 6:44 
AnswerRe: Beginner in need of help Pin
ely_bob23-Oct-09 6:43
professionalely_bob23-Oct-09 6:43 
GeneralRe: Beginner in need of help Pin
Not Active23-Oct-09 7:02
mentorNot Active23-Oct-09 7:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.