Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
953 B
3
Indexable
Never
def day_seven():
    with open('input7.txt') as f:
        txt = f.readlines()
        directory = []
        direc = [0]
        i = 0
        size = 0
        control = 0
        for x in txt[::-1]:

            if x[0].isdigit():
                direc[0] += int(x.split(" ")[0])
            elif x[0:4] == "$ ls":
                control = 1
            elif x[0:3] == "dir":
                for b in directory:
                    if b[0] == x.split(" ")[1].rstrip("\n"):
                        direc[0] += b[1]
            elif x[0:4] == "$ cd" and control == 1:
                direc.insert(0, x.split(" ")[2].rstrip("\n"))
                directory.append(direc)
                direc = [0]
                control = 0
            else:
                continue

    sum1 = 0
    for i in directory:
        if i[1] <= 100000:
            print(i[1])
            sum1 += i[1]

    return f"Day 7: part 1 - {sum1}"