Skip to content

Instantly share code, notes, and snippets.

@iwillspeak
Created October 25, 2015 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iwillspeak/26b3f4199999f7e908ce to your computer and use it in GitHub Desktop.
Save iwillspeak/26b3f4199999f7e908ce to your computer and use it in GitHub Desktop.
Another Implementation of the Solution to Project Euler 12
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