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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:03:35+00:00 2026-05-27T00:03:35+00:00

I was bored and decided to try my hand at using Linq to solve

  • 0

I was bored and decided to try my hand at using Linq to solve a logic puzzle. I found a puzzle here.

The linq I created is as follows:

  IEnumerable<int> values = Enumerable.Range(1, 9);

  var result = from A in values
               from B in values
               from C in values
               from D in values
               from E in values
               from F in values
               from G in values
               from H in values
               from I in values
               where A != B && A != C && A != D && A != E && A != F && A != G && A != H && A != I
               where B != C && B != D && B != E && B != F && B != G && B != H && B != I
               where C != D && C != E && C != F && C != G && C != H && C != I
               where D != E && D != F && D != G && D != H && D != I
               where E != F && E != G && E != H && E != I
               where F != G && F != H && F != I
               where G != H && G != I
               where H != I
               where A + B == 11
               where B + C + D == 11
               where D + E + F == 11
               where F + G + H == 11
               where H + I == 11
               select new { A, B, C, D, E, F, G, H, I };

  result.ToList().ForEach(x => Console.WriteLine("A: {0}, B: {1}, C: {2}, D: {3}, E: {4}, F: {5}, G: {6}, H: {7}, I: {8}", x.A, x.B, x.C, x.D, x.E, x.F, x.G, x.H, x.I));

I expected this to print all the answers fairly easily, but it just seems to calculate forever. If I was to write this the standard way then it would take microseconds to calculate the answer. Why is it so slow in linq?

  • 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-27T00:03:36+00:00Added an answer on May 27, 2026 at 12:03 am

    Well for one thing, you’re only filtering after you’ve generated the whole set of 9 values. You can make it more efficient like this:

    from A in values
    from B in values
    where B != A
    where A + B == 11
    from C in values
    where C != A && C != B
    from D in values
    where D != A && D != B && D != C
    where B + C + D == 11
    from E in values
    where E != A && E != B && E != C && E != D
    from F in values
    where F != A && F != B && F != C && F != D && F != E
    where D + E + F == 11
    from G in values
    where G != A && G != B && G != C && G != D && G != E && G != F
    from H in values
    where H != A && H != B && H != C && H != D && H != E && H != F && H != G
    where F + G + H == 11
    from I in values
    where I != A && I != B && I != C && I != D && I != E && I != F && I != G && H != I
    where H + I == 11
    select new { A, B, C, D, E, F, G, H, I };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm bored with surrounding code with try catch like this.. try { //some boring
In class, we are all 'studying' databases, and everyone is using Access. Bored with
I'v been bored so I created a small console minesweeper game and while writting
Maybe it's something I'm doing wrong. I'm just learning Linq because I'm bored. And
I'm pretty bored this weekend. I've decided to build a morse code application where
I was getting bored with my XP box one day, so I decided to
I've been sick for the past week and terribly bored, so I decided to
I was bored one rainy afternoon and came up with this: int ia_array[5][5][5]; //interger
So I was feeling bored and decided I wanted to make a hangman game.
I got bored during the holiday season this year and randomly decided to write

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.