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 7018697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:05:08+00:00 2026-05-27T23:05:08+00:00

i have two numbers 1,2 in one array.Now i want to generate all the

  • 0

i have two numbers 1,2 in one array.Now i want to generate all the possible combinations of arrays(of size=5) like

1,2,0,0,0 ||
2,1,0,0,0 ||
1,0,2,0,0
.
.
.
.
.

I tried to write a recursive function but its not working

Now I want to solve this using LINQ because the code will be considerably small.

Please help me

  • 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-05-27T23:05:09+00:00Added an answer on May 27, 2026 at 11:05 pm

    LINQ is excellent for searching; it’s much worse at generating, so it is a wrong tool for the job. So is recursion (although it is a better choice than LINQ). What you need is two nested loops, like this:

    var elements = new [] {1, 2};
    for (var i = 0 ; i != 5 ; i++) {
        for (int j = 0 ; j != 5 ; j++) {
            if (i == j) continue;
            var data = new int[5];
            data[i] = elements[0];
            data[j] = elements[1];
            ProcessCombination(data);
        }
    }
    

    Here is what the code does: at each iteration of the inner loop it places the first and the second element from the elements array at distinct positions i and j. Nested loops go from 0 to 5, making sure all position combinations are covered.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two arrays a={a,b,c,d} b={1,2,3,4} now I want to create a 3rd array
I have two pair of arrays. In each pair one array contains the index
I have two forms. First one is to decide button numbers by using jslider.
I have the following code to generate two random numbers var attackRoll = Math.floor((Math.random()*6)+1);
I have two set of arrays in different MYSQL table. This what I want
I have an array $test = array('one', 'two', 'three', 'four', 'five'); I unset two
I have two tables: one is ip_group_city from ipinfodb.com containing ip_start numbers for determining
I know, I know, now I have two problems 'n all that, but regex
Say I have two files where there is one number per line File 1
I have two tables, one contains the page/heading number and the heading text, the

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.