Breaking a Toy Hash Function
twistedoakstudios.com
twistedoakstudios.com
The PL geek in me really likes this nice demonstration of the power of higher order functions, as opposed to C-style for loops, when it comes to getting things done.
Wikipedia explains it better than I could http://en.wikipedia.org/wiki/Higher-order_function
However don't let the seemingly chained methods fool you! The great thing about LINQ is that is defers execution, by building an expression tree [1], meaning the code is lazily executed only when needed. And the expression tree means that everything (filtering, projection etc) is done in a single for loop [2]. e.g.
var results = collection.Select(item => item.Foo).Where(foo => foo < 3);
This builds an expression tree, but no work has been undertaken on our collection. When we attempt to enumerate the results, the expression tree is converted to code (again, as a single for loop, not multiple iterations as the code might seem): results.ToList();
It's extremely cool to work with and highly expressive. One of my favourite features of C#[1] http://blogs.msdn.com/b/charlie/archive/2007/12/09/deferred-...
[2] http://stackoverflow.com/questions/7324033/what-are-the-bene...
LINQ is incredibly awesome, expressive, and powerful. I generally prefer the lambda syntax to the more verbal syntax the author has used here, but both are really great and miles ahead of what's available in other, similar languages.
The monadic interfaces can get much more powerful, such as the Logic Monad in Haskell which embeds Prolog-like search.
1: http://www.matasano.com/articles/crypto-challenges/ 2: https://www.coursera.org/course/crypto
- Can't be seeded.
- Fails to use all possible outputs in range.
- Causes philosophical thoughts.
Ce n'est pas une grosse surprise de trouver des gens de wc3c sur HN parce que les deux sont des communautés de programmeurs.