US States Puzzle

By at May 16, 2009 11:51
Filed Under: Widgets

Originally taken from

http://interviewpattern.com/post/Puzzles-and-Riddles-on-the-interview-(Part-e28093-I).aspx

Take the names of two U.S. States, mix them all together, then rearrange the letters to form the names of two other U.S. States.

What states are these?

using our Combinatorics library 

using System;
using System;
using System.Collections.Generic;
using System.Linq;

namespace StatePuzzle
{
internal class Program
{
    private static void Main(string[] args)
    {
        var listStates = new List
            {
            "Alabama","Alaska","AmericanSamoa","Arizona","Arkansas","California",
            "Colorado","Connecticut","Delaware","DistrictofColumbia","Florida",
            "Georgia","Guam","Hawaii","Idaho","Illinois","Indiana","Iowa",
            "Kansas","Kentucky","Louisiana","Maine","Maryland","Massachusetts",
            "Michigan","Minnesota","Mississippi","Missouri","Montana","Nebraska",
            "Nevada","NewHampshire","NewJersey","NewMexico","NewYork","NorthCarolina",
            "NorthDakota","Ohio","Oklahoma","Oregon","Pennsylvania",
            "PuertoRico","RhodeIsland","SouthCarolina","SouthDakota","Tennessee",
            "Texas","Utah","Vermont","Virginia","VirginIslands","Washington",
            "WestVirginia","Wisconsin","Wyoming"
            };

        foreach (var statePair in Combinatorics.Combinations(listStates, 2))
        {

            var chars = string.Join(string.Empty, statePair.ToArray())
                        .ToLower()
                        .ToCharArray()
                        .OrderBy(c => c);

            var toSearch = listStates.Except(statePair).ToList();

            foreach (var statePairSeach in Combinatorics.Combinations(toSearch, 2))
            {

                var charsSearch = string.Join(string.Empty, statePairSeach.ToArray())
                                .ToLower()
                                .ToCharArray()
                                .OrderBy(c => c);
                if( chars.Count() == charsSearch.Count() && 
                    chars.SequenceEqual(charsSearch))
                {
                    Console.Write("Letters that make up the States :");
                    Console.Write(string.Join(",", statePair.ToArray()));
                    Console.WriteLine("");
                    Console.Write("Can be re-arranged to read :");
                    Console.Write(string.Join(",", statePairSeach.ToArray()));
                    Console.WriteLine("");
                    Console.WriteLine("");
                }
            }
        }

        Console.ReadLine();
    }
}
}

Comments

3/9/2010 11:26:20 AM #

seo tools

Great to be stumbling up to your websiteblog again, it has been weeks for me. Anyway, this is the article that i've been waiting for so long. I can use this article to end my assignment in the school, and it has same topic as your article. Regards, excellent share.

seo tools Slovenia | Reply

3/14/2010 2:10:56 PM #

Steve

Yeh was having a chat with my girlfriend about this subject yesterday. I think Iv made my mind up after your post now Smile
Regards

Steve El Salvador | Reply

3/20/2010 11:35:45 PM #

cheap prom Dresses

it has been weeks for me. Anyway, this is the article that i've been waiting for so long. I can use this article to end my assignment in the school, and it has same topic as your article. Regards, excellent share.

cheap prom Dresses People's Republic of China | Reply

3/29/2010 10:03:33 AM #

notebook

I happen to enter your blog with the help of google search. To my sheer luck I got what I was searching for. Thanks

notebook United States | Reply

3/29/2010 3:24:17 PM #

notebook

I happen to enter your blog with the help of google search. To my sheer luck I got what I was searching for. Thanks

notebook United States | Reply

4/22/2010 11:49:41 AM #

Cloud Hosting

This is a really cool implementation of states.  I have not seen it done this way.  Having the right code is essential. Thanks for the post.

Cloud Hosting United States | Reply

4/27/2010 1:45:56 PM #

How to get ripped

Nice article, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again for sharing this free online and good luck!

How to get ripped United States | Reply

6/5/2010 4:50:13 AM #

How To Get Back An Ex

The next time I read a blog, I hope that it doesnt disappoint me as much as this one.  I mean, I know it was my choice to read, but I actually thought youd have something interesting to say.  All I hear is a bunch of whining about something that you could fix if you werent too busy looking for attention.

How To Get Back An Ex United States | Reply

6/16/2010 5:21:29 PM #

iphone 4 pricing

This is definitely a topic thats close to me so Im happy that you wrote about it.  Im also happy that you did the subject some justice.  Not only do you know a great deal about it, you know how to present in a way that people will want to read more.  Im so happy to know someone like you exists on the web.

iphone 4 pricing United States | Reply

6/18/2010 1:17:00 AM #

Magician London

You make a great point.  Got some great information here.  I think that if more people thought about it that way, theyd have a better time understanding the issue.  Your view is definitely something Id like to see more of.  Thanks for this blog.  Its fantastic and so is what youve got to say.

Magician London United States | Reply

7/9/2010 1:21:11 PM #

Felton Weisenberger

Just wanted to say that you have some awesome content on your website.

Felton Weisenberger Poland | Reply

8/19/2010 11:22:16 AM #

administracja ul

This is so great that I had to comment. I'm usually just a lurker, taking in knowledge and nodding my head in quiet approval at the good stuff.....this required written props. Theory rocks...thanks.

administracja ul Poland | Reply

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading