Commit 6106b3bf authored by Trevor Cappallo's avatar Trevor Cappallo
Browse files

add timer

parent 2a43a300
import random
import copy
import time
MAGIC_NUMBER = -12345
MAX_PROG_SIZE = 100
......@@ -23,6 +23,7 @@ ENABLED = [
'PEEK', 'SKIP', 'LAND', 'LOR', 'IFDO',
'IFF', 'NOT', 'MOD',
]
ENABLED = ENABLED_FIB
TIMEOUT = 250
def make_program(length):
......@@ -156,12 +157,15 @@ def run_program(prog, model_in, model_out, timeout=TIMEOUT, trace=False):
timeout = total = redundant = successes = counter = degen = exact = length = 0
lower_bound, upper_bound = 5, 8
lower_bound, upper_bound = 5, 5
model_in = []
model_out = [1, 1, 2, 3, 5, 8, 13]
#model_out = [0, 1, 2, 3, 4, 5]
wins = 0
wins_needed = 100
solutions = set()
time_start = time.time()
while (True):
prog = make_program(random.randint(lower_bound, upper_bound))
output = [MAGIC_NUMBER] + [0] * 99
......@@ -203,6 +207,19 @@ while (True):
break
if match == len(model_out):
run_program(prog, model_in, model_out, trace=True)
print "---VICTORY--- total =", total
break
wins += 1
pretty_prog = " ".join([INSTRUCTIONS[op] for op in prog])
solutions.add(pretty_prog)
if wins == wins_needed:
time_end = time.time()
time_elapsed = time_end - time_start
#run_program(prog, model_in, model_out, trace=True)
print "---VICTORY---"
print "total =", total
if wins > 1:
print "average =", total / wins
print "mean solution time: {:.2f} s".format(time_elapsed)
print "\n{} solutions:".format(len(solutions))
for prog in solutions:
print prog
break
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment