#!/usr/bin/python3
import gzip, tqdm

with (open('bbchallenge-deciders/decider-finite-automata-reduction/output/finite_automata_reduction.index', 'rb') as idx,
      gzip.open('ctl_decided.txt.gz', 'wt') as dec, gzip.open('ctl_undecided.txt.gz', 'wt') as und, gzip.open('bb.6x2.unknown.txt.gz', 'rt') as dsc):
    idx_set = set()
    while (seed := idx.read(4)):
        idx_set.add(int.from_bytes(seed, 'big'))
    for i, line in enumerate(tqdm.tqdm(dsc, unit=' beavers')):
        (dec if i in idx_set else und).write(line)
print('Wrote ctl_decided.txt.gz, ctl_undecided.txt.gz')
