Created
November 23, 2012 12:20
-
-
Save daiksy/4135381 to your computer and use it in GitHub Desktop.
Project Euler Problem 12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * http://projecteuler.net/problem=12 | |
| * http://odz.sakura.ne.jp/projecteuler/index.php?cmd=read&page=Problem%2012 | |
| */ | |
| def numbers(n: Long): Stream[Long] = n #:: numbers(n + 1L) | |
| val triangle = numbers(2L).scanLeft(1L){(a,b) => a + b } | |
| val divisors = (n: Long) => { | |
| (1L to n / 2).filter(n % _ == 0) :+ n | |
| } | |
| val ret = triangle.find(divisors(_).size >= 501).getOrElse(0L) | |
| println(ret) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment