Now that with F# (and .NET 4.0 in general) we have support for big integers through the
Project Euler problem 13 has become a trivial one:
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
Solution (note that I have removed most of the input numbers to improve readability):
Using Linq, it's easy to compute the solution with a simple aggregation. Note that I couldn't
Sum function directly because it does not have an overload for
Without support for such big numbers, one could have reasoned that, in order to calculate the first 10 digits
of the result, only the first 11 digits of each number are relevant. With this intuition, the problem
would have been tractable using simple
Problem 13 is a classical problem that can be resolved using parallel aggregation: it can be decomposed into many independent sub-tasks (each calculating the sum of 10 numbers, as an example) and the final result can be obtained aggregating the results from each of them.
AsParallel, scaling this problem on multiple cores is trivial:
Of course, with such a trivial problem, you should not expect big performance improvements with a parallel version (indeed, the overhead of splitting the work into different threads might usually lengthen the time it takes to get to the result).