It seems to be popular, so I tried it with Python as the Nth brew.
# -*- coding: utf-8 -*-
from collections import deque
import random
z = u'Dung'
d = u'Doco'
zzzzd = (z, z, z, z, d, )
kys = u'Ki yo shi!'
#Infinite Zundco Generator
def zd():
while True:
w = random.choice((z, d, ))
print w
yield w
def zndkkys():
q = deque()
#Skip to the 4th character that never matches
for i, w in enumerate(zd()):
q.append(w)
if i == 3:
break
#Check each time after the 5th character and discard unnecessary characters
for w in zd():
q.append(w)
if all((zzzzd[i] == p for i, p in enumerate(q))):
print kys
return
q.popleft()
if __name__ == '__main__':
zndkkys()
You can go with this generator alone, right? That is version 2 below
# -*- coding: utf-8 -*-
from collections import deque
import random
z = u'Dung'
d = u'Doco'
kys = u'Ki yo shi!'
def zndkkys2():
state = 0
while True:
num = random.choice((0, 1, ))
#Count up for Zun
if num:
yield z
state += 1
else:
yield d
#If there are four or more consecutive dungs in front of the doko, it's ki yo shi!
if state >= 4:
yield kys
return
#Initialize the count if the dung in front of the doco is 3 times or less
else:
state = 0
if __name__ == '__main__':
print ''.join(zndkkys2())
Recommended Posts