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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:28:44+00:00 2026-05-15T09:28:44+00:00

I’m building a word anagram program that uses a database which contains one simple

  • 0

I’m building a word anagram program that uses a database which contains one simple table:

Words
---------------------
varchar(15) alphagram
varchar(15) anagram
(other fields omitted for brevity)

An alphagram is the letters of a word arranged in alphabetical order. For example, the alphagram for OVERFLOW would be EFLOORVW. Every Alphagram in my database has one or more Anagrams. Here’s a sample data dump of my table:

Alphagram   Anagram  
EINORST     NORITES
EINORST     OESTRIN
EINORST     ORIENTS
EINORST     STONIER
ADEINRT     ANTIRED
ADEINRT     DETRAIN
ADEINRT     TRAINED

I’m trying to build a LINQ query that would return a list of Alphagrams along with their associated Anagrams. Is this possible?


UPDATE: Here’s my solution based on the suggestions below! Thanks all!

using (LexiconEntities ctx = new LexiconEntities())
{
    var words = ctx.words;

    var query =
        from word in words
        where word.alphagram == "AEINRST"
        group word by word.alphagram into alphagramGroup
        select new { Alphagram = alphagramGroup.Key, Anagrams = alphagramGroup };

    foreach (var alphagramGroup in query)
    {
        Console.WriteLine("Alphagram: {0}", alphagramGroup.Alphagram);
        foreach (var anagram in alphagramGroup.Anagrams)
        {
            Console.WriteLine("Anagram: {0}", anagram.word1);
        }
    }
}
  • 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-15T09:28:44+00:00Added an answer on May 15, 2026 at 9:28 am

    var list = anagrams.Select( 
        a => new {  
               Alphagram = a.ToCharArray().OrderBy(s => s).ToString(),  
               Anagram = a  
           }).toList(); 
    

    A totally new answer…

    You seem to need a groupby query look at How to: Group Data (Entity Framework).

    this should accomplish what you want…

    I did a testy with LINQ and this works…

        var words = new List<Word>() 
        { 
            new ConsoleApplication1.Word("EINORST", "NORITES"), 
            new ConsoleApplication1.Word("EINORST", "OESTRIN"), 
            new ConsoleApplication1.Word("EINORST", "STONIER"), 
            new ConsoleApplication1.Word("ADEINRT", "ANTIRED"), 
            new ConsoleApplication1.Word("ADEINRT", "DETRAIN"), 
            new ConsoleApplication1.Word("ADEINRT", "TRAINED")
        };
    
        var q = words.GroupBy(w => w.Alphagram).Select(w => new { Alphagram = w.Key, Anagrams = w.Select(p => p.Anagram).ToList() }).ToList();
    
        foreach (var item in q)
        {
            Console.WriteLine("Alphagram : {0}, Anagrams = {1}", item.Alphagram, String.Join(",", item.Anagrams));
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.