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
#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 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 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 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 |