Skip to content

Instantly share code, notes, and snippets.

View mvallebr's full-sized avatar

Marcelo Elias Del Valle mvallebr

View GitHub Profile
@mvallebr
mvallebr / merge.py
Last active February 4, 2016 10:47 — forked from renzon/merge.py
Code to merge two ordered iterables
def _le(left, right):
return left if left <= right else right
def merge(left, right, cmp=_le):
"""
Merges two ordered iterables (left and right) keeping result ordered according to cmp.
:param left: iterable
:param right: iterable
:param cmp: callable which receive one element from left and another from right and returns the on to be merged.
def primes_up_to(N):
sieve = N*[True]
for i in range(2, N):
if not sieve[i]: continue
yield i
for j in range(i*i, N, i):
sieve[j] = False
@mvallebr
mvallebr / binConverter.py
Last active June 22, 2017 12:19 — forked from echiesse/binConverter.py
Exemplo de conversão de decimal para binário
num = int(input("Escolha um número decimal para transformar em binario: "))
result = []
zero = '0'
while num > 0:
num, bit = divmod(num, 2)
result.append(bit)
zero = ''
# Imprimir em ordem inversa