Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 252713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:42:04+00:00 2026-05-11T21:42:04+00:00

If I have a sequence as follows (let’s say it’s an IEnumerable<T> ): [A,

  • 0

If I have a sequence as follows (let’s say it’s an IEnumerable<T>):

[A, B, C, D, E]

Then what’s the cleanest way to compute all possible (continuous and non-continuous) subsequences of a given length? Ordering of the results in the result set isn’t important, but it shouldn’t include duplicates.

e.g. If I want to compute all possible subsequences of length 3 the result set would be:

[A, B, C]
[A, B, D]
[A, B, E]
[A, C, D]
[A, C, E]
[A, D, E]
[B, C, D]
[B, C, E]
[B, D, E]
[C, D, E]

For the record, the accepted answer below gave me a good starting point, and here’s the code I’ve gone with that is updated to use some of the new .NET 3.5 extension methods:

public static IEnumerable<IEnumerable<T>> Subsequences<T>(
    this IEnumerable<T> source, 
    int count)
{
    if (count == 0)
    {
        yield return Enumerable.Empty<T>();
    }
    else
    {
        var skip = 1;
        foreach (var first in source)
        {
            foreach (var rest in source.Skip(skip).Subsequences(count - 1))
            {
                yield return Enumerable.Repeat(first, 1).Concat(rest);
            }

            skip++;
        }
    }
}
  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:42:04+00:00Added an answer on May 11, 2026 at 9:42 pm

    I’ve had success with IanG’s PermuteUtils class:

    char[] items = new char[] { 'A', 'B', 'C', 'D', 'E' };
    
    foreach (IEnumerable<char> permutation in PermuteUtils.Permute(items, 3)) {
        Console.Write("[");
        foreach (char c in permutation) {
            Console.Write(" " + c);
        }
        Console.WriteLine(" ]");
    }
    

    Results in:

    [ A B C ]
    [ A B D ]
    [ A B E ]
    [ A C B ]
    [ A C D ]
    [ A C E ]
    [ A D B ]
    [ A D C ]
    [ A D E ]
    [ A E B ]
    [ A E C ]
    [ A E D ]
    [ B A C ]
    [ B A D ]
    [ B A E ]
    [ B C A ]
    [ B C D ]
    [ B C E ]
    [ B D A ]
    [ B D C ]
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

suppose i have a sequence, called TEST_SEQ what would be the correct way of
Suppose I have a sequence x1,x2,x3.....xn, and I want to find the longest continuous
I was wondering if this was possible... I have a sequence of variables that
Let say if I have a queue of integer (or any class T), can
Good day all, I have an html file as follows, which displays a Google
Hi all i have my XML file as follows Name of XML XMLFile2.xml <?xml
I have text file (seq.fasta) which contains sequence as follows M1 MPMILGYWNVRGLTHPIRMLLEYTDSSYDEKRYTMGDAPDFDRSQWLNEKFKLGLDFPNL PYLIDGSHKITQSNAILRYLARKHHLDGETEEERIRADIVENQVMDTRMQLIMLCYNPDF EKQKPEFLKTIPEKMKLYSEFLGKRPWFAGDKVTYVDFLAYDILDQYRMFEPKCLDAFPN
Say I have an index defined as follows: CREATE NONCLUSTERED INDEX [IX_Marker] ON [dbo].[Marker]
I have a sequence of forms that follows the following algorithm: Form #1 Prompt
I have written a makefile in which the sequence of commands is as follows

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.