Skip to content

Instantly share code, notes, and snippets.

View MagallanesFito's full-sized avatar

Adolfo Fragoso Magallanes MagallanesFito

View GitHub Profile
@MagallanesFito
MagallanesFito / multiplication.java
Last active September 12, 2019 21:34
Karatsuba Algorithm for efficiently multiplication of integers VS Naive Multiplication Algorithm
/*This is a helper function, returns 10**exp
*/
public static int power_ten(int exp){
if(exp == 0) return 1;
else return 10*power_ten(exp-1);
}
/*
Given two strings, representing integers, calculate their product.
This works approximately quadratic time, considering the number of digits in both s1 and s2 are equal.
*/
public static int[] firstQPrimes(int q) {
/*
* Write your code here.
*/
// Generar primeros q numeros primos con la criba de atkin
//hay 1229 numeros primos entre 1 y 10000
int limit = q;
boolean sieve[] = new boolean[limit];
if(limit > 2) sieve[2] = true;
if(limit > 3) sieve[3] = true;
@MagallanesFito
MagallanesFito / feature extraction plus ml algorithm.py
Created May 31, 2019 05:41
VGG16 Feature exctraction and training on medica dataset
# -*- coding: utf-8 -*-
''' Importar bibliotecas'''
import keras
from keras.preprocessing import image
from keras.applications.vgg16 import VGG16
from keras.applications.vgg16 import preprocess_input
from sklearn.model_selection import train_test_split
import numpy as np
from keras.models import Sequential
@MagallanesFito
MagallanesFito / circles.java
Last active May 2, 2019 02:56
Max Circle Queries | Hackerrank Union-Find
static int find(int x,HashMap<Integer,Integer> parent){
if(parent.get(x) == x) return x;
return find(parent.get(x),parent);
}
static int union(int x,int y,HashMap<Integer,Integer> parent, HashMap<Integer,Integer> size,int max1) {
int x_p = find(x,parent);
int y_p = find(y,parent);
int max = max1;
if(x_p != y_p){
if(size.get(x_p) > size.get(y_p)){
@MagallanesFito
MagallanesFito / xor.java
Last active May 2, 2019 00:24
Maximum Xor | Hackerrank Trie
class TrieNode {
//left y right
TrieNode[] children = new TrieNode[2];
public void add_(int s,int bits){
add(s,bits-1);
}
public TrieNode getNode(int pos){
return children[pos];
@MagallanesFito
MagallanesFito / contracts.java
Created May 1, 2019 02:00
Trie contracts problem. Hackerrank
class TrieNode{
public static int ALPHABET_SIZE = 26;
TrieNode[] children = new TrieNode[ALPHABET_SIZE];
int size = 0;
public int charIndex(char c){
return c - 'a';
}
public TrieNode getNode(char c){
return children[charIndex(c)];
@MagallanesFito
MagallanesFito / naive bayes.py
Created March 22, 2019 06:37
Simple naive bayes implementation
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#Operaciones sobre diccionarios
import operator
from random import randint
#Importa el dataframe y lo guarda en un diccionario
def load_data(filename):
@MagallanesFito
MagallanesFito / dataset.csv
Created March 22, 2019 06:35
Play Tennis dataset in Spanish
Dia Cielo Temperatura Humedad Viento Jugar_tenis
1 Sol Alta Alta Debil No
2 Sol Alta Alta Fuerte No
3 Nubes Alta Alta Debil Si
4 Lluvia Suave Alta Debil Si
5 Lluvia Baja Normal Debil Si
6 Lluvia Baja Normal Fuerte No
7 Nubes Baja Normal Fuerte Si
8 Sol Suave Alta Debil No
9 Sol Baja Normal Debil Si
@MagallanesFito
MagallanesFito / Multi-Objective Genetic Algorithm.py
Created March 11, 2019 01:20
Genetic Algorithm for solving multi-objective optimization (MOGA)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import random
DOMAIN = [-10,10]
MAX_GENERATIONS = 100
PROB_MUTATE = 0.05
POP_SIZE = 100
@MagallanesFito
MagallanesFito / hobbies_list.txt
Created December 9, 2018 22:57
A list of most common hobbies in spanish and english
3D Printing
Abejas
Acolchado
Acrobacias Con Bicicletas
Acting
Actividades De La Iglesia
Actividades Informáticas
Actuacion
Actuar En Teatro
Acuarios