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: |
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 |
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
# -*- coding: utf-8 -*- | |
# Este script extrai, para cada unidade federativa, todas as coligações | |
# partidárias para deputados estaduais e federais das eleições brasileiras | |
# de 2010. | |
# | |
# Por André Lima | |
# Email: andre (ponto) lima (arroba) gmail (ponto) com | |
# Twitter: @andlima | |
# | |
# Licença: é permitido a qualquer um usar, distribuir e modificar livremente |
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
import math | |
import time | |
import ossaudiodev | |
import random | |
# Simple ear training script - by Andre Lima | |
# | |
# This program is based on code from: | |
# | |
# tone.py - Single / Dual Tone Generator |
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
X=$1; | |
while [[ $X ]]; do | |
echo $X; | |
X=$(echo $X | python prefix.py); | |
done; |
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
primes_list = [2, 3] | |
def primes(maximum): | |
for p in primes_list: | |
if p > maximum: | |
return | |
yield p | |
for m in range(primes_list[-1] + 2, maximum + 1, 2): | |
sqrt_m = int(m ** 0.5) | |
if all(m % p != 0 for p in primes(sqrt_m)): | |
primes_list.append(m) |
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 primes(maximum): | |
discarded = set() | |
was_discarded = discarded.__contains__ | |
discard_all = discarded.update | |
limit = maximum + 1 | |
yield 2 | |
for m in xrange(3, limit, 2): | |
if not was_discarded(m): | |
yield m | |
discard_all(xrange(m * 2, limit, m)) |
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
#include <stdio.h> | |
#include <stdlib.h> | |
typedef unsigned long long int t_item; | |
#define BITS sizeof(t_item) | |
void init(t_item *bitset, int maximum) { | |
int p = maximum / BITS; | |
int i; |
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
#include <stdio.h> | |
#include <stdlib.h> | |
typedef unsigned long long int t_item; | |
static t_item all_true = ~0LL; | |
#define BITS sizeof(t_item) | |
void init_with_true(t_item *bitset, int maximum) { |
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<n-1; i++) { | |
if (v[i] < pivot) { | |
swap(v[i], v[store++]); | |
} |
OlderNewer