More fun with LINQ

"Standing on a bridge, watch the water passing under me
It must’ve been much harder when there was no bridge just water..."
("Funny the Way it is", Dave Matthews Band, 2009)

Ayer se publicó en el área de Community Content de MSDN mi artículo corto "Solving Combinatory Problems with LINQ", un divertimento basado en LINQ al estilo de otros que ya he publicado tanto en "C# 3.0 y LINQ" como aquí. Estos puzzles siempre me traen a la memoria los problemas que poníamos a nuestros alumnos hace veintitantos años en la Universidad de La Habana, y me hacen pensar en cómo el progreso hace fácil lo que un tiempo atrás era bastante más difícil, que es precisamente a lo que se hace alusión en la referencia musical de hoy.


Pop/Rock tip: De entre los grupos contemporáneos de música popular, uno de los que más me gustan por su calidad, originalidad y eclecticismo es Dave Matthews Band. Su música es una interesante combinación de rock, jazz, soul, bluegrass e incluso música clásica, y en sus conciertos acostumbran a improvisar alrededor de sus canciones al estilo de las jam sessions tan típicas del jazz. "Funny the Way it is" fue el primer single del disco "Big Whiskey and the GrooGrux King" (2009), que vi por primera vez (y no dejé escapar :-) en un Starbucks, a mediados del año pasado.

Published 8/4/2010 8:01 por Octavio Hernández
Archivado en: ,,
Comparte este post:

Comentarios

Thursday, April 08, 2010 10:53 AM por Vicente García Diez

# re: More fun with LINQ

Como siempre, un gran trabajo. Un abrazo maestro.

Thursday, April 08, 2010 7:22 PM por Octavio Hernández

# re: More fun with LINQ

Gracias, Vicente!

Un abrazo - OH

Wednesday, April 14, 2010 12:51 AM por Niek

# re: More fun with LINQ

Apply a little recursiveness, and things get way easier...

IEnumerable<int> satisfies(int n)

{

  return n == 1

    ? new int [] {1,2,3,4,5,6,7,8,9}

    : from shorterNumber in satisfies(n-1)

      from extension in satisfies(1)

      let number = shorterNumber*10 + extension

      where number% n == 0 && !shorterNumber.ToString().Any(i => i==extension.ToString()[0])

      select number;

}