Commit 3847cfd0 authored by Trevor Cappallo's avatar Trevor Cappallo
Browse files

tight instructions for adds

parent 859230b8
......@@ -94,7 +94,7 @@ class Skython(object):
print "{}".format(output[i]),
print ")"
while (True):
while True:
if pc >= len(prog) or pc < 0:
break
......@@ -300,7 +300,7 @@ class Skython(object):
wins_needed = 5
solutions = set()
time_start = time.time()
while (True):
while True:
prog = self.make_program(random.randint(bound * 2 // 3, bound))
output = [self.MAGIC_NUMBER] + [0] * (self.MAX_PROG_SIZE - 1)
for i in range(1, len(model_in) + 1):
......@@ -325,10 +325,10 @@ class Skython(object):
degen += 1
continue
if exact and r != len(model_out):
continue
elif not exact and r < len(model_out):
continue
#if exact and r != len(model_out):
# continue
#elif not exact and r < len(model_out):
# continue
match = 0
for i in range(len(model_out)):
......@@ -368,94 +368,98 @@ class Skython(object):
print '\n'
break
if __name__ == '__main__':
skyt = Skython()
# EXPLORE = True
EXPLORE = True
skyt.INSTRUCTIONS3 = [
'SWAB',
'PUSH', 'INC',
'ADD',
'NEG', 'XOR', #'LOCO_2', #'SWBC',
'PEEK',
#'IFF', #'LOCO_0',
'JNE', #'JGTE',
]
skyt.ENABLED_CODES = [skyt.OP_CODE[x] for x in skyt.INSTRUCTIONS3] # random.sample(range(30), random.randint(12, 26))
model_in = [1, 3, -5, 2, 20, 0, 6, 9, 7, -5]
model_out = [4, -3, 20, 15, 2]
#model_out = [1, 1, 2, 3, 5, 8, 13]
#model_out = [0, 1, 2, 3, 4, 5]
#model_out = [1, 2, 4, 8, 16, 32]
#model_in = []
#model_out = [1, 3, 9, 27, 81]
if EXPLORE:
iterations = 10**6
skyt.TRIM = 10
results, progs = skyt.explore(iterations=iterations, max_steps=256, bound=32)
inverted = {}
for k, v in results.items():
if v not in inverted:
inverted[v] = []
inverted[v].append(k)
keys = sorted(inverted.keys(), reverse=False)
for k in keys:
print "{:.5%}\n\t{}\n\n".format(1.0 * k / iterations, '\n\t'.join(inverted[k]))
print len(keys), len(results), [skyt.INSTRUCTIONS[x] for x in sorted(skyt.ENABLED_CODES)]
print "-" * 50
q = []
for i in range(30):
n = 0
sum_percent = 0.0
for k in keys:
if k < 100:
for pat in inverted[k]:
n += progs[pat][i] #progs[inverted[k]][i]
#sum_percent += progs[inverted[k]][i] * (1.0 * k / iterations)
sum_percent += progs[pat][i] * (1.0 * k / iterations)
if n:
q += [(sum_percent / n, "{:02} {:<6}: {:6.4%} (based on {})".format(
i, skyt.INSTRUCTIONS[i], sum_percent / n, n))]
for p, r in sorted(q):
print r
print "-" * 50
q2 = []
for i in range(30):
n = 0
sum_percent = 0.0
def main(self):
EXPLORE = False
# EXPLORE = True
self.INSTRUCTIONS3 = [
'SWAB', 'MULT', #'IFF', 'JGTE',
'PUSH', 'INC', 'INS',
'ADD',
'NEG', #'XOR', #'LOCO_2', #'SWBC',
'POP', #'PEEK',
#'IFF', #'LOCO_0',
'JNE', #'JGTE',
]
self.ENABLED_CODES = [self.OP_CODE[x] for x in self.INSTRUCTIONS3] # random.sample(range(30), random.randint(12, 26))
model_in = [1, 3, -5, 2, 20, 0, 6, 9, 7, -5]
model_out = [4, -3, 20, 15, 2]
#model_out = [2, 15, 20, -3, 4]
#model_in = []
#model_out = [1, 1, 2, 3, 5, 8, 13]
#model_out = [0, 1, 2, 3, 4, 5]
#model_out = [1, 2, 4, 8, 16, 32]
#model_out = [1, 3, 9, 27, 81]
if EXPLORE:
iterations = 10**6
self.TRIM = 10
results, progs = self.explore(iterations=iterations, max_steps=256, bound=32)
inverted = {}
for k, v in results.items():
if v not in inverted:
inverted[v] = []
inverted[v].append(k)
keys = sorted(inverted.keys(), reverse=False)
for k in keys:
for pat in inverted[k]:
n += progs[pat][i] #progs[inverted[k]][i]
#sum_percent += progs[inverted[k]][i] * (1.0 * k / iterations)
sum_percent += progs[pat][i] * (1.0 * k / iterations)
if n:
q2 += [(sum_percent / n, "{:02} {:<6}: {:6.4%} (based on {})".format(
i, skyt.INSTRUCTIONS[i], sum_percent / n, n))]
for p, r in sorted(q2):
print r
print "-" * 50
q3 = []
for i in range(30):
n = 0
sum_percent = 0.0
for k in keys:
if k > 10000:
print "{:.5%}\n\t{}\n\n".format(1.0 * k / iterations, '\n\t'.join(inverted[k]))
print len(keys), len(results), [self.INSTRUCTIONS[x] for x in sorted(self.ENABLED_CODES)]
print "-" * 50
q = []
for i in range(30):
n = 0
sum_percent = 0.0
for k in keys:
if k < 100:
for pat in inverted[k]:
n += progs[pat][i] #progs[inverted[k]][i]
#sum_percent += progs[inverted[k]][i] * (1.0 * k / iterations)
sum_percent += progs[pat][i] * (1.0 * k / iterations)
if n:
q += [(sum_percent / n, "{:02} {:<6}: {:6.4%} (based on {})".format(
i, self.INSTRUCTIONS[i], sum_percent / n, n))]
for p, r in sorted(q):
print r
print "-" * 50
q2 = []
for i in range(30):
n = 0
sum_percent = 0.0
for k in keys:
for pat in inverted[k]:
n += progs[pat][i] #progs[inverted[k]][i]
#sum_percent += progs[inverted[k]][i] * (1.0 * k / iterations)
sum_percent += progs[pat][i] * (1.0 * k / iterations)
if n:
q3 += [(sum_percent / n, "{:02} {:<6}: {:6.4%} (based on {})".format(
i, skyt.INSTRUCTIONS[i], sum_percent / n, n))]
for p, r in sorted(q3):
print r
else:
print [skyt.INSTRUCTIONS[x] for x in sorted(skyt.ENABLED_CODES)]
#skyt.run(model_out=[1,2,3,3,4,5], model_in=[4,3,1,3,5,2], bound=30)
#skyt.run(model_out=[19,23,37,37,42], model_in=[23,37,42,37,19], bound=35)
skyt.run(model_out=model_out, model_in=model_in, bound=15)
if n:
q2 += [(sum_percent / n, "{:02} {:<6}: {:6.4%} (based on {})".format(
i, self.INSTRUCTIONS[i], sum_percent / n, n))]
for p, r in sorted(q2):
print r
print "-" * 50
q3 = []
for i in range(30):
n = 0
sum_percent = 0.0
for k in keys:
if k > 10000:
for pat in inverted[k]:
n += progs[pat][i] #progs[inverted[k]][i]
#sum_percent += progs[inverted[k]][i] * (1.0 * k / iterations)
sum_percent += progs[pat][i] * (1.0 * k / iterations)
if n:
q3 += [(sum_percent / n, "{:02} {:<6}: {:6.4%} (based on {})".format(
i, self.INSTRUCTIONS[i], sum_percent / n, n))]
for p, r in sorted(q3):
print r
else:
print [self.INSTRUCTIONS[x] for x in sorted(self.ENABLED_CODES)]
#self.run(model_out=[1,2,3,3,4,5], model_in=[4,3,1,3,5,2], bound=30)
#self.run(model_out=[19,23,37,37,42], model_in=[23,37,42,37,19], bound=35)
self.run(model_out=model_out, model_in=model_in, bound=15)
if __name__ == '__main__':
Skython().main()
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