optimisticninja / liberprimus-tool

Python tool/libraray for evolving solutions toward the Liber Primus from Cicada 3301
1 stars 1 forks source link

bug: invalid index in get_entities after mutation #18

Closed optimisticninja closed 1 month ago

optimisticninja commented 2 months ago

This is likely happening when mode mutates and nums isn't updated as well, need to investigate. Semi-infrequent.

d4v1-sudo commented 2 months ago
def get_entities(nums, delimiter):
    texts = []
    with open("./data/transcription.txt") as lp:
        text = lp.read()
        ends = list(find(text, delimiter))
        for num in nums:
            if num < 0 or num >= len(ends):
                print(f"Warning: Entity index {num} is out of range.")
                texts.append("") 
            else:
                texts.append(text[0 if num == 0 else ends[num-1]:ends[num]])
    return texts
optimisticninja commented 2 months ago
def get_entities(nums, delimiter):
    texts = []
    with open("./data/transcription.txt") as lp:
        text = lp.read()
        ends = list(find(text, delimiter))
        for num in nums:
            if num < 0 or num >= len(ends):
                print(f"Warning: Entity index {num} is out of range.")
                texts.append("") 
            else:
                texts.append(text[0 if num == 0 else ends[num-1]:ends[num]])
    return texts

A nice way to warn on the issue, but it doesn't actually fix it. This would have too be fixed where it is being mutated.