samskivert: Euler 53

01 January 2010

Problem 053:

object Euler53 extends Application {
  def fact (n :BigInt) :BigInt = if (n < 2) 1 else n * fact(n-1)
  def choose (n :BigInt, r :BigInt) = fact(n)/(fact(r)*fact(n-r))
  println((for (n <- 1 to 100; r <- 1 to n; if (choose(n, r) > 1000000)) yield 1).sum)
}

Another simple brute force solution. Enumerate and count. BigInt lets us avoid any serious thinking.

©1999–2022 Michael Bayne