Created
October 25, 2015 10:43
-
-
Save iwillspeak/26b3f4199999f7e908ce to your computer and use it in GitHub Desktop.
Another Implementation of the Solution to Project Euler 12
This file contains 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
class Euler12 { | |
construct new(cutoff) { | |
_cutoff = cutoff | |
} | |
find_divisors(n) { | |
var nod = 0 | |
var sqrt = n.sqrt.floor | |
for (i in 1..sqrt) { | |
if (n % i == 0) { | |
nod = nod + 2 | |
} | |
} | |
if ((sqrt * sqrt) == n) { | |
nod = nod - 1 | |
} | |
return nod | |
} | |
find() { | |
var n = 0 | |
var i = 1 | |
while (find_divisors(n) < _cutoff) { | |
n = n + i | |
i = i + 1 | |
} | |
return n | |
} | |
} | |
System.print(Euler12.new(500).find()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment