def main(argv): # Get command line options. opts, args = Filter_Option_Parser(argv, [("backsteps", int, None, True, True), ("limit", int, None, False, True)]) limit = opts["limit"] if limit is None: limit = opts["backsteps"] log_number = opts["log_number"] io = IO.IO(opts["infile"], opts["outfile"], log_number) next_entry = io.read_result() while next_entry: TTable = next_entry[6] # Run the simulator/filter on this machine results = backtrack_ttable(TTable, opts["backsteps"], limit) # Deal with result if results: next_entry = apply_results(results, next_entry, log_number) io.write_result_raw(*next_entry) next_entry = io.read_result()
# See if all halts cannot be reached for halt in halts: if not cannot_reach_halt(halt, to_state, to_symbol): return False # If all halt states cannot be reached: return Exit_Condition.INFINITE, "Reverse_Engineer" def apply_results(results, old_line, log_number): old_results = next[5] return next[0:5]+(results, next[6], log_number, old_results) if __name__ == "__main__": import sys from Option_Parser import Filter_Option_Parser # Get command line options. opts, args = Filter_Option_Parser(sys.argv, []) log_number = opts["log_number"] io = IO.IO(opts["infile"], opts["outfile"], log_number) next = io.read_result() while next: TTable = next[6] # Run the simulator/filter on this machine results = test(TTable) # Deal with result if results: next = apply_results(results, next, log_number) io.write_result_raw(*next) next = io.read_result()
from Option_Parser import Filter_Option_Parser import fcntl, termios, struct # Get terminal width, this is surprisingly hard to do :( # See: http://stackoverflow.com/questions/566746/how-to-get-console-window-width-in-python try: # This will be fooled if you pipe in stdin from somewhere else, but I don't # know why you would do that since this program doesn't read stdin. fd = 0 term_height, term_width = struct.unpack('hh', fcntl.ioctl(fd, termios.TIOCGWINSZ, '1234')) except: term_width = 80 opts, args = Filter_Option_Parser(sys.argv, [("brief" , None, None, False, False), ("width", int, term_width , False, True ), ("line_num" , int , 1 , False, True )], True) infile = opts["infile"] brief = opts["brief"] width = opts["width"] line_num = opts["line_num"] if opts["tape"] == None: tape = 10000000 else: tape = opts["tape"] if opts["steps"] == None:
from Common import Exit_Condition import IO import CTL1 import CTL2 import CTL3 import CTL4 from Option_Parser import Filter_Option_Parser from Alarm import ALARM, AlarmException # # Get command line options. # Form: (opt, type, def_val, req?, has_val?) opts, args = Filter_Option_Parser(sys.argv, [("block-size", int, 1, False, True), ("offset", int, 0, False, True), ("cutoff", int, 200, False, True), ("type", str, None, True, True), ("time", float, None, False, True)]) log_number = opts["log_number"] block_size = opts["block-size"] # Block size for macro machine offset = opts["offset"] # Offset for block size to resolve parity errors cutoff = opts[ "cutoff"] # Steps to run to get advanced config before trying CTL type = opts["type"] # CTL algorithm to run runtime = opts["time"] # Timer value
results, tape_length, max_steps, io, old_results=[]): """ Saves a busy beaver machine with the provided data information. """ io.write_result(machine_num, tape_length, max_steps, results, machine, old_results=old_results) # Default test code if __name__ == "__main__": import sys from Option_Parser import Filter_Option_Parser # Get command line options. opts, args = Filter_Option_Parser(sys.argv, [("size", int, None, True, True)]) io = IO(opts["infile"], opts["outfile"], opts["log_number"]) next = io.read_result() Macro_Machine_Run(opts["states"], opts["symbols"], opts["size"], opts["tape"], opts["steps"], next, io)
sys.stdout.flush() return (num_syms, num_steps) # # Simulate a Turing machine on a tape that is initially blank # if __name__ == "__main__": from Option_Parser import Filter_Option_Parser opts, args = Filter_Option_Parser(sys.argv, [("brief", None, None, False, False), ("visual", None, None, False, False), ("width", int, 80, False, True), ("old", None, None, False, False)], True) infile = opts["infile"] brief = opts["brief"] visual = opts["visual"] width = opts["width"] old = opts["old"] if opts["tape"] == None: tape = 10000000 else: tape = opts["tape"]