More Project Euler! Here's 53: how many, not necessarily distinct, values of nCr, for 1 ≤ n ≤ 100, are greater than one-million?
This ended up being much, much easier than I expected! I felt this was so simple it may not have even deserved an accompanying blog post.
We are given an equation for nCr, so I simply wrote a function to implement it, as well as a recursive function for the factorial, n!. (Does Haskell have one? I bet it does….)
Wrote a simple list comprehension that passed n from 1 to 100 and r from 1 to n into nCr, kept the result around if it was greater than one–million, and then counted those up with length! The hardest part was making sure I had the right amount of zeroes in one–million ;P
No comments:
Post a Comment