Paul Dundon’s Weblog


A little cheese and a little whine

Beautiful LINQ

I was playing hangman recently, and wondered how successful you would be playing it just by guessing letters in order of their frequency in the language. It struck me that there would be an elegant LINQ query which would calculate the number of guesses required for a given word. It turns out there is:

(Aggregate i In (From c As Char In word _
Select "etaionshrdlcumwfgypbvkjxqz".IndexOf(c)) Into Max(i)) + 1

Filed under: Tech

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 14 other followers

My Bookshelf

The Golden Bough
The Value of Nothing
The Fire
A Wolf at the Table
Devil Bones

My links

%d bloggers like this: