Created
October 22, 2013 08:32
-
-
Save recuraki/7097140 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import random | |
def RandomCharByString(stInput = None): | |
if stInput == None: | |
yield False | |
liInput = list(stInput) | |
while True: | |
inIndex = random.randint(0, len(liInput) - 1) | |
yield liInput[inIndex] | |
stCandidate = "hoge" | |
stTargetString = "hoge" | |
stBuffer, inMatchCount = "", 0 | |
stRandomBuffer = RandomCharByString(stCandidate) | |
inTryCounter = 0 | |
while True: | |
inTryCounter += 1 | |
stCurrentChar = stRandomBuffer.next() | |
stBuffer = stBuffer + stCurrentChar | |
print stCurrentChar, | |
if stCurrentChar == stTargetString[inMatchCount]: | |
inMatchCount += 1 | |
if inMatchCount == len(stTargetString): | |
break | |
else: | |
inMatchCount = 0 | |
print "MATCH" | |
print "Count: " + str(inTryCounter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment