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
# BlueBook code decryption | |
import sys | |
def sieve(n): | |
# Compute primes using sieve of Eratosthenes | |
x = [1] * n | |
x[1] = 0 | |
for i in range(2,n//2): | |
j = 2 * i | |
while j < n: | |
x[j] = 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
#traduzido e adaptado de http://blog.trinket.io/writing-poetry-in-python/ | |
from random import choice, randint | |
adjetivos = '''compreensivo temperamental confiável confiável honesto desonesto | |
interessante chato carinhoso simpático amigável generoso ciumento invejoso | |
inseguro ambicioso ansioso bondoso sensato sensível teimoso preguiçoso | |
trabalhador calmo paciente inteligente esperto espirituoso astuto neurótico | |
ousado apático cínico sarcástico irônico cético alegre conservador pessimista | |
otimista tolerante corajoso educado mal-educado determinado sociável | |
solidário arrogante maldoso desajeitado burro independente confiável dependente |
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
#versão Python 3 de http://pastebin.com/uRnDZaTz (Vinicius Marangoni) | |
import urllib.request | |
import json | |
url = 'http://divulga.tse.jus.br/2014/divulgacao/oficial/143/dadosdivweb/br/br-0001-e001431-w.js' | |
def main(): | |
resp = urllib.request.urlopen(url).read() | |
resp = json.loads(resp.decode('utf-8')) | |
candidatos = resp['cand'] |
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
from heapq import heappush, heappop | |
def heapsort(v): | |
h = [] | |
for x in v: | |
heappush(h, x) | |
return [heappop(h) for i in range(len(h))] | |
from random import shuffle | |
v = list(range(8)) | |
shuffle(v) |
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 merge(p, q, r, v): | |
w = [] | |
i, j = p, q | |
while i < q and j < r: | |
if v[i] <= v[j]: | |
w.append(v[i]) | |
i += 1 | |
else: | |
w.append(v[j]) | |
j += 1 |
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 merge(e, d): | |
r = [] | |
i, j = 0, 0 | |
while i < len(e) and j < len(d): | |
if e[i] <= d[j]: | |
r.append(e[i]) | |
i += 1 | |
else: | |
r.append(d[j]) | |
j += 1 |
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 dec2bin(n): | |
b = '' | |
while n != 0: | |
b = b + str(n % 2) | |
n = int(n / 2) | |
return b[::-1] | |
def d2b(n): | |
if n == 0: | |
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
#@gwidion code | |
print"".join(u"\x1b[%dm%c%s"%((42+y%2^y>>3&1),((1,3,2,-1,0,2,3,1)+(4,)*8+32*(-9781,)+8*(10,)+(7,9,8,5,6,8,9,7))[y]+9813,(y+1)%8and" "or" \x1b[48m\n")for y in range(64)) |
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 requests | |
jogos = requests.get('http://worldcup.sfg.io/matches').json() | |
for jogo in jogos: | |
if jogo['status'] in ('completed', 'in progress'): | |
print (jogo['home_team']['country'], jogo['home_team']['goals'], 'x', | |
jogo['away_team']['country'], jogo['away_team']['goals']) |
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 int42(int): | |
def __init__(self, n): | |
int.__init__(n) | |
def __add__(a, b): | |
return 42 | |
def __str__(n): | |
return '42' |