Created
August 9, 2011 01:20
-
-
Save luizfonseca/1133223 to your computer and use it in GitHub Desktop.
Google Developer Day (Python script)
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
#! /usr/bin/python | |
class ReadableGooglon: | |
vocabulary = list('wnzpkgrdqbfjlxvhcsmt') | |
foo_letters = list('vkcjq') | |
mapped = list('0123456789abcdefghij') | |
not_prep = 'l' | |
prep_length = 3 | |
verb_length = 6 #greater than 6 | |
base_pretty = 20 | |
min_pretty_num = 404169 | |
div_pretty_num = 5 | |
def __init__(self, strg): | |
string = strg.split(' ') | |
def num_prepositions(self, string): | |
return [st.count(self.not_prep) for st in string if len(st) == self.prep_length and st[-1] | |
not in self.foo_letters].count(0) | |
def num_verbs(self, string): | |
return [st for st in string if len(st) > self.verb_length | |
and st[-1] not in self.foo_letters] | |
def num_fst_verbs(self, lst): | |
return [st for st in lst if st[0] not in self.foo_letters] | |
def normalize(self, strg): | |
return ''.join(map(lambda x: self.mapped[self.vocabulary.index(x)], strg)) | |
def vocabulary_order(self, string): | |
return sorted(string, key = lambda x: self.normalize(x)) | |
def to_number(self, string, base): | |
strg = list(string) | |
strg.reverse() | |
return int(self.normalize(strg), self.base_pretty) | |
def pretty_numbers(self, string): | |
return [st for st in string if self.to_number(st, 20) >= self.min_pretty_num | |
and self.to_number(st, 20) % self.div_pretty_num == 0] | |
txt = open("text_b.txt").read() | |
googlon_str = ReadableGooglon(txt) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment