Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rodrigoSaladoAnaya/ffecfffff553707ca474fec0e3490e92 to your computer and use it in GitHub Desktop.
Save rodrigoSaladoAnaya/ffecfffff553707ca474fec0e3490e92 to your computer and use it in GitHub Desktop.
primes with ulam spiral corner limit
def init = System.currentTimeMillis()
for(N = 9; N < 530; N+=2) {
println "${N} -> ${isOddCompositeNumber(N) ? '' : '__prime__'}"
}
def isOddCompositeNumber(double N) {
def U = Math.floor(Math.sqrt((N - 1 + Math.floor(Math.sqrt(N - 4) + 1)) / 4) - 1)
def t = false;
for(i = 0; i <= U; i++) {
def B = (i * 4) + 6;
def Q = (N / B) % 0.5;
t = Q == 0
if(t) {
break
}
}
return t;
}
def end = System.currentTimeMillis()
println "T: ${(end - init) / 1000}s"
/*
for(x = 2; x < 10000; x++) {
//4x2 - 2x + 1
def a = 4
def b = - 2
def c = 1
def y = a * Math.pow(x, 2) + b * x + c
assert y - c == a * Math.pow(x, 2) + b * x
assert y - c == (a * Math.pow(x, 2) + b * x)
assert y - c == x * ((a * x) + b)
assert y - c == x * ((a * x) + b)
def p1 = Math.sqrt((y - 1 + Math.floor(Math.sqrt(y - 4) + 1)) / 4)
def p2 = x
assert p1 == p2
//println " *** ${p1} == ${p2} ?? ${p1 - p2}"
println "${y} -> [${x}]"
}
/**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment