2020/13.py
def part2_old():
    """
    This was my first attempt. It is a brute-force algorithm, which clearly doesn't work
    because the input is to big. It does solve the samples, though.
    """
    busses = []
    gaps = [0]
    for b in lines[1].split(","):
        if b == "x":
            gaps[-1] += 1
            continue
        else:
            gaps.append(1)
            busses.append(int(b))

    i = busses[0]
    k = 0
    while True:
        if k % 100000 == 0:
            print(i)
        ok = True
        for j, b in enumerate(busses[1:]):
            if i % b != b - sum(gaps[: j + 2]):
                ok = False
                break
        if ok:
            return i

        k += 1
        i += busses[0]

    This was my first attempt. It is a brute-force algorithm, which clearly doesn't work
    because the input is to big. It does solve the samples, though.
    
This was my first attempt. It is a brute-force algorithm, which clearly doesn't work
because the input is to big. It does solve the samples, though.
This was my first attempt . It is a brute - force algorithm which clearly doesn ' t work because the input is to big . It does solve the samples though .
def part2_old():
    busses = []
    gaps = [0]
    for b in lines[1].split(","):
        if b == "x":
            gaps[-1] += 1
            continue
        else:
            gaps.append(1)
            busses.append(int(b))
    i = busses[0]
    k = 0
    while True:
        if k % 100000 == 0:
            print(i)
        ok = True
        for j, b in enumerate(busses[1:]):
            if i % b != b - sum(gaps[: j + 2]):
                ok = False
                break
        if ok:
            return i
        k += 1
        i += busses[0]
def part2_old ( ) : busses = [ ] gaps = [ 0 ] for b in lines [ 1 ] . split ( "," ) : if b == "x" : gaps [ - 1 ] += 1 continue else : gaps . append ( 1 ) busses . append ( int ( b ) ) i = busses [ 0 ] k = 0 while True : if k % 100000 == 0 : print ( i ) ok = True for j , b in enumerate ( busses [ 1 : ] ) : if i % b != b - sum ( gaps [ : j + 2 ] ) : ok = False break if ok : return i k += 1 i += busses [ 0 ]
This was my first attempt.
This was my first attempt .
"""
    This was my first attempt. It is a brute-force algorithm, which clearly doesn't work
    because the input is to big. It does solve the samples, though.
    """