Skip to content

Instantly share code, notes, and snippets.

@xtotdam
Last active February 26, 2017 19:34
Show Gist options
  • Select an option

  • Save xtotdam/b8677bcec1af96fc95cd502bed55be02 to your computer and use it in GitHub Desktop.

Select an option

Save xtotdam/b8677bcec1af96fc95cd502bed55be02 to your computer and use it in GitHub Desktop.
from random import choice, random
class Annoyer():
counts_default = [1, 1]
parts = [
['bdt', 'dbt'],
['n', 'ntn', 'nbtn']
]
head = 'gh'
result = ''
def __init__(self):
self.counts = self.counts_default
def load(self, fn='counts.txt'):
with open(fn, 'r') as f:
s = filter(bool, f.read().strip().split(' '))
self.counts = map(int, s)
def dump(self, fn='counts.txt'):
s = ' '.join(map(str, self.counts))
with open(fn, 'w') as f:
f.write(s)
def __repr__(self):
return str(self.counts)
def __str__(self):
return self.result
def construct(self):
result = self.head
for p, c in zip(self.parts, self.counts):
for _ in xrange(c):
result += choice(p)
self.result = result
def increment(self):
counts = []
for c in self.counts:
if random() > 0.7:
c += 1
counts.append(c)
self.counts = counts
if __name__ == '__main__':
a = Annoyer()
a.load()
a.construct()
a.increment()
print a
a.dump()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment