def run(gates_list, clock: Signal = None, n_pulse=None, display=None):
        if n_pulse is None:
            n_pulse = -1
        if clock is None:
            depend = []
            for gate in gates_list:
                gate.logic(depend)

            if display:
                for lst in display:
                    if type(lst[0]) in CircuitRunner.NOT_GATE:
                        print("".join([str(r.output.output) for r in lst]))
                    else:
                        print("".join([str(r.output) for r in lst]))
        else:
            while not n_pulse == 0:
                n_pulse -= 1
                clock.pulse()

                depend = []
                for gate in gates_list:
                    gate.logic(depend)

                if display:
                    for lst in display:
                        if type(lst[0]) in CircuitRunner.NOT_GATE:
                            print("".join([str(r.output.output) for r in lst]))
                        else:
                            print("".join([str(r.output) for r in lst]))
def test2():
    clock = Signal()
    d1 = D_FlipFlop(clock, None, "d1")
    not1 = Not(d1, "not")
    d1.set_input(not1)
    d1.set()

    for _ in range(20):
        clock.pulse()
        d1.logic()
        print(d1)
def johnson_counter(n=100):
    clock = Signal()
    bits = [D_FlipFlop(clock, None, f"d{i}") for i in range(n)]
    for i in range(1, n):
        bits[i].set_input(bits[i - 1])
        bits[i].reset()

    bits[0].set_input(Not(bits[-1], "not"))
    bits[0].reset()

    for _ in range(4 * n):
        clock.pulse()
        bits[0].logic()
        print("".join([str(b.q()) for b in bits]))