{{ message }}

Instantly share code, notes, and snippets.

# André Lima andlima

• Rio de Janeiro, Brazil
Last active Feb 4, 2020
Princípios de Modelagem Preditiva
Last active Apr 19, 2019
View Expectation–maximization algorithm.ipynb
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Last active Aug 29, 2015
Mersenne Twister 19937 PRNG
View mersenne_twister.rs
This file contains 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
 fn initialize_generator(mt: &mut [uint], index: &mut uint, seed: uint) { mt[0] = seed; *index = 0; for i in range(1, 624) { mt[i] = ( ( 1812433253 * (mt[i-1] ^ (mt[i-1] >> 30)) ) + i
Last active Aug 29, 2015
View trie.py
This file contains 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
 from __future__ import print_function class Trie(object): '''Implementation of a trie.''' def __init__(self, collection=None): self.ends = False self.children = {} if collection is not None:
Last active Dec 16, 2015
Google Code Jam 2013 - Qualification Round - Problem C
View problem_c.py
This file contains 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
 from bisect import bisect_left, bisect_right def solve(numbers, a, b): answer = bisect_right(numbers, b) - bisect_left(numbers, a) return answer if answer > 0 else 0 def main(): numbers = [1, 4, 9] previous = ('012', [''])
Created Jun 5, 2012
MST - Kruskal
View gist:2872210
This file contains 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 distance(points, i, j): x1, y1 = points[i] x2, y2 = points[j] return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 def find_root(height_and_parent, i): hi, pi = height_and_parent[i] if pi is None: return i return find_root(height_and_parent, pi)
Created May 27, 2012
Solução do P2 - 2016
View p2.py
This file contains 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 distance(points, i, j): x1, y1 = points[i] x2, y2 = points[j] return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 def merge_root(root, i, j): good, bad = sorted([root[i], root[j]]) bad_keys = [k for k, v in root.iteritems() if v == bad] for key in bad_keys: root[key] = good
Created Apr 7, 2012
Scrape letras.terra.com.br
View scrape_letras_terra.py
This file contains 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
 """ A short script that, given an artist, scrapes all his/her/their songs from 'http://letras.terra.com.br' Dependence: BeautifulSoup, to parse the lyrics from each song page. Author: Andre Lima - http://github.com/andlima Licensed under MIT License
Created Feb 9, 2012
Quick selection algorithm
View gist:1776496
This file contains 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
 int quick_find_kth(int *v, int n, int k) { if (n == 1 && k == 0) return v[0]; int pivot = v[n-1]; int store = 0; for (int i=0; i
Created Feb 8, 2012
Median of medians selection algorithm
View gist:1774060
This file contains 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
 int find_kth(int *v, int n, int k) { if (n == 1 && k == 0) return v[0]; int m = (n + 4)/5; int *medians = new int[m]; for (int i=0; i