def collatz(n:BigInt):Stream[BigInt] =That was a fun little diversion!
if (n == 1) {
Stream(1);
} else {
def next(n:BigInt):BigInt = if ((n % 2) == 0) (n / 2) else (n * 3 + 1);
Stream.cons(n, collatz(next(n)));
}
Friday, March 5, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment