Created
September 4, 2012 21:49
-
-
Save mpickering/3627034 to your computer and use it in GitHub Desktop.
fountain
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
#fountin | |
import random, math, itertools | |
def randomN(n): | |
while True: | |
yield random.randint(1,0.5*n*(n+1)) | |
def stream(w): | |
rand = randomN(len(w)) | |
while True: | |
yield (len(w) - math.ceil((-1+math.sqrt(1+(8*rand.next())))*0.5))+1 | |
def update(e): | |
for d in e[1]: | |
if processed[d]: | |
e[0] ^= processed[d] | |
e[1].remove(d) | |
if len(e[1]) == 1: | |
processed[e[1][0]] = e[0] | |
hold.remove(e) | |
for d in hold: | |
if e[1][0] in d[1]: | |
update(d) | |
src = 'ashok thinks he is big man because he don't like the python' | |
ords = [ord(x) for x in src] | |
source = stream(src) | |
for x in range(1000): | |
hold = [] | |
processed = [None] * len(src) | |
while not all(processed): | |
i+=1 | |
selection = random.sample(range(len(src)),int(source.next())) | |
payload = [reduce(lambda x,y: x ^ y, [ords[i] for i in selection])] + selection | |
payload = [payload[0],payload[1:]] | |
hold.append(payload) | |
update(payload) | |
print [chr(x) for x in processed] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment