import re


def compare(asm_simulation_output, asm_correct_outputs):
    """
    Compare the student's circuit output with the correct one
    :param asm_simulation_output: File containing the simulated outputs
    :param asm_correct_outputs: File containing the correct outputs
    :return: Percentage of correctness
    """
    correct_outputs = list()
    pattern = re.compile("^(Outputs:\s)?([0-1].+)$")
    with open(asm_correct_outputs, "r") as infile:
        for line in infile:
            if pattern.match(line):
                correct_outputs.append(line.lstrip("Outputs: ").replace(" ", "").strip())
    match = 0
    i = 0
    with open(asm_simulation_output, "r") as infile:
        for line in infile:
            if pattern.match(line):
                if line.lstrip("Outputs: ").replace(" ", "").strip() == correct_outputs[i]:
                    match += 1
                i += 1
    return float(match) / float(i) * 100.0