#!/usr/bin/env python # mu.py # an automated MIU solver by aLT 08 from random import randint def intro(): print "\nThe game of the MU MU!!" print "Your starting string will be " print "You must try and derive the axiom by applying four procedural rules\n" print "RULE 1: If the string ends in you may append a " print "RULE 2: If you have you may make it - X equals any string" print "RULE 3: If occurrs you may substitute in it's place" print "RULE 4: If occurs you may drop it" print "Good luck. Have you sunk it?\n" start = raw_input("Begin?") def double(str): str = str + str[1 : len(str)+1] countI(str) print str return str def countI(str): tally = 0 for z in str: if z == "I": tally += 1 print tally def countU(str): tally = 0 for z in str: if z == "U": tally += 1 print tally def addU(str): str = str + "U" print str return str def swapI(str, amt): tally = 0 mark = 0 count = 0 for z in str: mark += 1 if count >= amt: break elif z == "I": tally += 1 if tally == 3: str = str[0:mark-3] + "U" + str[mark:len(str)] tally = 0 mark = mark - 2 count += 1 else: tally = 0 print str countU(str) return str def dropU(str): tally = 0 mark = 0 for z in str: mark += 1 if z == "U": tally += 1 if tally == 2: str = str[0:mark-2] + str[mark:len(str)] tally = 0 mark = mark - 2 else: tally = 0 print str return str def main(): #intro() muStr = "MI" muStr = double(muStr) muStr = double(muStr) muStr = double(muStr) muStr = double(muStr) muStr = swapI(muStr, 2) muStr = dropU(muStr) muStr = double(muStr) muStr = double(muStr) muStr = double(muStr) muStr = double(muStr) muStr = swapI(muStr, 34) muStr = addU(muStr) muStr = swapI(muStr, 19) muStr = dropU(muStr) print muStr if __name__ == '__main__': main()