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

  • SEARCH
  • Home
  • 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 8651755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:08:53+00:00 2026-06-12T14:08:53+00:00

Possible Duplicate: Generating permutations of a set (most efficiently) I was looking at an

  • 0

Possible Duplicate:
Generating permutations of a set (most efficiently)

I was looking at an old programming challenge, and I was trying to come up with a solution.
The challenge is expired, and years old, and I’m doing it just to build skill at this point.

I need to generate numbers in the following pattern:

  • 123456789
  • 123456798
  • 123456879
  • 123456897
  • 123456978
  • 123456987

Continuing onward, always using the same 9 numbers, never duplicating them, and always grabbing the next one in line.

I’ve been wracking my brain for the last 2 hours, and can’t figure out a good programming pattern to tackle this.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 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-06-12T14:08:54+00:00Added an answer on June 12, 2026 at 2:08 pm

    How about this as a solution:

    var numerals = Enumerable.Range(1, 9).ToArray();
    
    var query =
        from n1 in numerals
        from n2 in numerals.Except(new [] { n1, })
        from n3 in numerals.Except(new [] { n1, n2, })
        from n4 in numerals.Except(new [] { n1, n2, n3, })
        from n5 in numerals.Except(new [] { n1, n2, n3, n4, })
        from n6 in numerals.Except(new [] { n1, n2, n3, n4, n5, })
        from n7 in numerals.Except(new [] { n1, n2, n3, n4, n5, n6, })
        from n8 in numerals.Except(new [] { n1, n2, n3, n4, n5, n6, n7, })
        from n9 in numerals.Except(new [] { n1, n2, n3, n4, n5, n6, n7, n8, })
        select n1 * 100000000
            + n2 * 10000000
            + n3 * 1000000
            + n4 * 100000
            + n5 * 10000
            + n6 * 1000
            + n7 * 100
            + n8 * 10
            + n9;
    

    This turns out to be quite fast producing all of the results in 864 milliseconds on my computer.

    Here are the first 10 results:

    123456789 
    123456798 
    123456879 
    123456897 
    123456978 
    123456987 
    123457689 
    123457698 
    123457869 
    123457896 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Generating all Possible Combinations I'm trying to do a little algorithm in
Possible Duplicate: generating random enums I'm looking for the best way to select a
Possible Duplicate: Generating all permutations of a given string Given a length n=4, and
Possible Duplicate: Reliable way of generating unique hardware ID Am trying to generate an
Possible Duplicate: generating random numbers from skewed normal distribution i expect a long array
Possible Duplicate: Generating an Excel file in ASP.NET Here's my question: How do you
Possible Duplicate: Algorithm for generating a random number is posible to generate a random
Possible Duplicate: PHP: Script for generating Crossword game? Does anyone know any PHP-based simple
Possible Duplicate: Developing for Android in Eclipse: R.java not generating what to do if
Possible Duplicate: Generating a list of which files changed between hg versions hg diff

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.