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
import numpy as np | |
def mcd(x, y): | |
while y != 0: | |
x, y = y, x % y | |
return x | |
def equiv(A, m, n): |
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
// 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) |
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
for(double N = 9; N < 199999; N+=2) { | |
def U = Math.sqrt((N + Math.sqrt(N - 4)) / 4); | |
def L = Math.floor(U - 1) | |
def signature = [] | |
def isOddComNum | |
double i = 0 | |
for(; i <= L && !isOddComNum; i++) { | |
def B = (i * 4) + 6; | |
def Q = (N / B) % 0.5; | |
isOddComNum = Q == 0 |
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
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; |
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
for(double N = 9; N < 10000000; N+=2) { | |
println "${N} ${isPrime(N) ? '' :'__prime__'}" | |
} | |
def isPrime(double N) { | |
def L = Math.ceil(N / 6) - 1; | |
def t = false; | |
for(i = 0; i < L; i++) { | |
def B = (i * 4) + 6; | |
def Q = (N / B) % 0.5; |
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
public static <V> V getSafe(Supplier<V> func) { | |
V res = null; | |
try { | |
res = func.get(); | |
} catch (java.lang.NullPointerException e) { } | |
return res; | |
} | |
log.info("C: {}", getSafe(() -> a.getA().getC())); |
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
import rx.Observable | |
def numbers = Observable.range(1, 100) | |
def fizz = numbers.map { n -> n % 3 == 0 ? 'Fizz' : '' } | |
def buzz = numbers.map { n -> n % 5 == 0 ? 'Buzz' : '' } | |
Observable.zip(fizz, buzz, numbers) { fz, bz, n -> fz || bz ? fz+bz : n } | |
.subscribe { println it } |
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
def get_atmos_list = { input -> | |
def time_start = System.currentTimeMillis() | |
def atoms = [2, 3] | |
def fill_list = { n -> | |
def sqrt = Math.sqrt(n) as int | |
def is_atom = true | |
for(i = 0; i <= sqrt - 1; i++) { | |
if(n % atoms[i] == 0) { | |
is_atom = false | |
return |
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
class C { | |
def str1 = 'Hola' | |
def x = { nestedClosures -> | |
def str2 = 'mundo' | |
nestedClosures() | |
} | |
} | |
def clozure = { | |
x { |
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
def regs = [a:0, b:0] | |
def instr = [ | |
hlf: { params -> | |
def r = params.r/2 | |
def output | |
if(r.remainder(1) == 0) { | |
output = [reg_val:r, jump_to: params.i+=1] | |
} else { | |
output = [reg_val:params.r, jump_to: params.i+=1] |
NewerOlder