Created
January 2, 2012 20:57
-
-
Save anonymous/1552077 to your computer and use it in GitHub Desktop.
Crude MIU System Simulator
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/python -tt | |
import sys | |
def rule1(s): | |
if s[-1:] == 'i': | |
return [s + 'u'] | |
return [s] | |
def rule2(s): | |
if s[0:1] == 'm': | |
return ['m' + s[1:] + s[1:]] | |
return [s] | |
def rule3(s): | |
stack = '' | |
results = [s] | |
for i,c in enumerate(s): | |
stack = stack + c | |
if stack[-3:] == 'iii': | |
results.append(s[:i-2] + 'u' + s[i+1:]) | |
return results | |
def rule4(s): | |
stack = '' | |
results = [s] | |
for i,c in enumerate(s): | |
stack = stack + c | |
if stack[-2:] == 'uu': | |
results.append(s[:i-1] + s[i+1:]) | |
return results | |
def main(): | |
rules = [rule1, rule2, rule3, rule4] | |
ours = set(['mi']) | |
while True: | |
initial_size = len(ours) | |
for r in rules: | |
new = [r(x) for x in ours] | |
for n in new: | |
[ours.add(x) for x in n] | |
for x in n: | |
if len(x) <= 4: | |
print(x) | |
if 'mu' in n: | |
print('generated mu') | |
break | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment