Created
August 29, 2010 00:06
-
-
Save itsbth/555740 to your computer and use it in GitHub Desktop.
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 re | |
from random import randint | |
RANK = 10 | |
RE = re.compile("[\w']+") | |
dct = dict() | |
def _tuples(arr, r): | |
return [(tuple([arr[i + t] for t in range(0, r - 1)]), arr[i + r - 1]) for i in range(len(arr) - (r - 1))] | |
#open("h2g2.txt").read().lower() | |
for k, v in _tuples(RE.findall(open("h2g2.txt").read().lower()), RANK): | |
dct.setdefault(k, []).append(v) | |
#print dct | |
k = dct.keys() | |
start = k[randint(0, len(k) - 1)] | |
for i in range(32): | |
lst = dct[start] | |
next = lst[randint(0, len(lst) - 1)] | |
print next, | |
sl = list(start) | |
sl.pop(0) | |
sl.append(next) | |
start = tuple(sl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment