add solved pages to interrupt db

This commit is contained in:
relikd
2021-01-21 02:49:57 +01:00
parent 8932ed8fc3
commit 6bd82e83ea
3 changed files with 33 additions and 16 deletions

View File

@@ -14,12 +14,15 @@ class InterruptDB(object):
def make(self, keylen):
def fn(x):
return Probability.IC_w_keylen(x, keylen)
score, intrpts = self.iguess.sequential(fn, startAt=0, maxdepth=99)
# score, intrpts = self.iguess.genetic(fn, topDown=False, maxdepth=4)
# score, intrpts = fn(self.iguess.join()), [[]] # without interrupts
for i, skips in enumerate(intrpts):
intrpts[i] = self.iguess.to_occurrence_index(skips)
return score, intrpts
if keylen == 0:
keylen = 1
score, skips = fn(self.iguess.join()), [[]] # without interrupts
else:
score, skips = self.iguess.sequential(fn, startAt=0, maxdepth=99)
# score, skips = self.iguess.genetic(fn, topDown=False, maxdepth=4)
for i, interrupts in enumerate(skips):
skips[i] = self.iguess.to_occurrence_index(interrupts)
return score, skips
@staticmethod
def load():
@@ -48,19 +51,20 @@ class InterruptDB(object):
f.write(t)
def populate_db(irp_chars=range(1), startkeylen=1, maxkeylen=32):
def populate_db(irp_chars=range(1), startkeylen=1, maxkeylen=32, max_irp=20):
oldDB = InterruptDB.load()
oldValues = {k: set((a, b, c) for a, _, b, c, _ in v)
for k, v in oldDB.items()}
for name in [
# '0_welcome', 'jpg107-167', '0_warning', '0_wisdom',
# '0_warning', '0_welcome', '0_wisdom', '0_koan_1', 'jpg107-167',
# '0_loss_of_divinity', 'jpg229', 'p56_an_end', 'p57_parable',
'p0-2', 'p3-7', 'p8-14', 'p15-22', 'p23-26',
'p27-32', 'p33-39', 'p40-53', 'p54-55'
]:
fname = f'pages/{name}.txt'
print('load:', fname)
for irp in irp_chars: # interrupt rune index
data = load_indices(fname, irp, maxinterrupt=20)
data = load_indices(fname, irp, maxinterrupt=max_irp)
db = InterruptDB(data, irp)
irp_count = db.stop_count
print('analyze interrupt:', irp, 'count:', irp_count)
@@ -72,3 +76,6 @@ def populate_db(irp_chars=range(1), startkeylen=1, maxkeylen=32):
print(f'{keylen}: {score:.4f}, solutions: {len(interrupts)}')
for x in interrupts:
InterruptDB.write(name, score, irp, irp_count, keylen, x)
# populate_db(startkeylen=0, maxkeylen=0, max_irp=None)