Paul Dundon’s Weblog

Icon

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
Advertisements

Filed under: Tech

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

You are commenting using your Google+ 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 13 other followers

My Bookshelf

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

My del.icio.us links

%d bloggers like this: