Jump to content

Typing Monkey


chair jockey

Recommended Posts

"Tory crow hack cute inti flab agu. Puce xian bol. Owls bras alla fun. Chew gaga posh pavo ste. Jean fore voce zoom risk klan yaw. Shog tret spot cuba sur."

The above was produce by my program Typing Monkey, which simulates the proverbial monkey on a keyboard, except with a human looking over the monkey's shoulder, checking the words the monkey types against a dictionary and recording the ones that are real words, then formatting the resultant text into sentences. This monkey loves hitting the spacebar, so it types only short words, and it gets tired quickly so it has to take a break and get its reward treat after only a few sentences. But I still like the monkey typing "Owls bras alla fun." :D

(For programmers and computer scientists: what really happened is that a more liberal configuration of the program caused it to run for more than an hour without completing, so I severely restricted its parameters. I also used a wordlist that contains only about 16,000 words. If you're intereted, it's a Python 3.,4 script, and I've pasted it below.)

#! /usr/bin/env python3

import string, random

class Text:

def __init__(self, passage):
self.s = passage

def read_text(self):
return self.s

def grow(self, sentence):
self.s = self.s + sentence.s

class Sentence(Text):

def __init__(self, sentence):
Text.__init__(self, sentence)
self.s = sentence

def format(self):
self.s = self.s[:1].title() + self.s[1:len(self.s)-1] + ". "

class Word(Sentence):

def __init__(self, word):
Sentence.__init__(self, word)
self.s = word

def is_word(word, dict):
return word.s in dict

def add_space(self):
self.s = self.s + " "

class Char(Word):

def __init__(self, char):
Word.__init__(self, char)
self.s = char

def get_char():
return Char(string.ascii_lowercase[random.randrange(0,26)])

def get_dict():
file = open("wordlist.txt")
list = file.read()
dict = list.split()
file.close()
return dict

def build_word():
word = Word(get_char().s)
for x in range(random.randrange(3, 7)):
word.grow(get_char())
return word

def vet_word(dict):
word = build_word()
while word.s not in dict:
word = build_word()
return word

def build_sentence(dict):
word = vet_word(dict)
word.add_space()
sentence = Sentence(word.s)
for x in range(random.randrange(1, 6)):
word = vet_word(dict)
word.add_space()
sentence.grow(word)
sentence.grow(vet_word(dict))
sentence.format()
return sentence

def build_text(dict):
text = Text(build_sentence(dict).s)
for x in range(5):
text.grow(build_sentence(dict))
return text

def main():
dict = get_dict()
text = build_text(dict)
print(text.s)

if __name__=="__main__":
main()

Link to post
Share on other sites
Squirrel Combat

akj sn cksan d fsd fs askdolisadlvksadflvkl dv fdv.

Cool! :twisted:

Link to post
Share on other sites

akj sn cksan d fsd fs askdolisadlvksadflvkl dv fdv.

Cool! :twisted:

The script shouldn't output that if you've got the word index file, and if you don't then it should exit with an exception of file not found.

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...