Skip to content

Instantly share code, notes, and snippets.

@rodrigoSaladoAnaya
Last active June 24, 2020 20:55
Show Gist options
  • Save rodrigoSaladoAnaya/d6f4f90d06210c1343f5d0345b5853b3 to your computer and use it in GitHub Desktop.
Save rodrigoSaladoAnaya/d6f4f90d06210c1343f5d0345b5853b3 to your computer and use it in GitHub Desktop.
// https://oeis.org/A054554
// https://www.youtube.com/watch?v=iFuR97YcSLM
for(int x = 2; x < 10; x++) {
//4n^2-2n+1
def N = 4 * Math.pow(x, 2) - 2 * x + 1
//ᒪ√((n+√(n-4)) / 4)ᒧ
def U = Math.floor(Math.sqrt((N + Math.sqrt(N - 4)) / 4));
assert x == U
def u = U+1 // +1 para que se vea igual a https://oeis.org/A054554/b054554.txt
println String.format("%.0f -> %.0f", u, N)
}
//Comprobación
for(int x = 2; x < 9999; x++) {
def N = 4 * Math.pow(x, 2) - 2 * x + 1
assert N == 4 * Math.pow(x, 2) - 2 * x + 1
assert N - 1 == 4 * Math.pow(x, 2) - 2 * x
assert N - 1 == 2 * (2 * Math.pow(x, 2) - x)
assert (N - 1) / 2 == 2 * Math.pow(x, 2) - x
assert (N - 1) / 2 == x * (2 * x - 1)
//No se una mejor forma de despejar (-1), así que se busca su equivaliente en función de N; x=f(N)
assert (N - 1) / 2 != x * (2 * x)
assert ((N - 1) / 2) + (Math.sqrt(N)) != x * (2 * x)
assert ((N - 1) / 2) + (N + Math.sqrt(N)) != x * (2 * x)
assert ((N - 1) / 2) + ((N + Math.sqrt(N)) / 4) != x * (2 * x)
assert ((N - 1) / 2) + Math.sqrt((N + Math.sqrt(N)) / 4) != x * (2 * x)
assert ((N - 1) / 2) + Math.floor(Math.sqrt((N + Math.sqrt(N)) / 4)) == x * (2 * x)
assert ((N - 1) / 2) + Math.floor(Math.sqrt((N + Math.sqrt(N)) / 4)) == x * 2 * x
assert ((N - 1) / 2) + Math.floor(Math.sqrt((N + Math.sqrt(N)) / 4)) == Math.pow(x, 2) * 2
assert (((N - 1) / 2) + Math.floor(Math.sqrt((N + Math.sqrt(N)) / 4))) / 2 == Math.pow(x, 2)
assert Math.sqrt((((N - 1) / 2) + Math.floor(Math.sqrt((N + Math.sqrt(N)) / 4))) / 2) == x
//La versión más corta que tengo
assert Math.floor(Math.sqrt((N + Math.sqrt(N - 4)) / 4)) == x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment