Compare commits
11 Commits
91441a6231
...
d1a0dfae3c
Author | SHA1 | Date |
---|---|---|
kwout | d1a0dfae3c | 1 year ago |
kwout | e592f3d931 | 1 year ago |
kwout | 3a7a4fbfd1 | 1 year ago |
kwout | 7ec4a41581 | 1 year ago |
kwout | 31e10c67da | 1 year ago |
kwout | 50ac55afd1 | 1 year ago |
kwout | 093374f208 | 1 year ago |
kwout | 09cf02722d | 1 year ago |
kwout | e2a6b4ac0e | 1 year ago |
kwout | 2f52587ab8 | 1 year ago |
kwout | 2805c3ae78 | 1 year ago |
6 changed files with 144 additions and 6 deletions
@ -0,0 +1,18 @@ |
|||||||
|
pairs = [[[int(n) for n in m.split("-")] for m in l.split(",")] for l in open("input.txt", 'r').read().splitlines()] |
||||||
|
|
||||||
|
sum = 0 |
||||||
|
sum2 = 0 |
||||||
|
|
||||||
|
for p in pairs: |
||||||
|
if p[0][0] <= p[1][0] and p[0][1] >= p[1][1]: |
||||||
|
sum += 1 |
||||||
|
elif p[0][0] >= p[1][0] and p[0][1] <= p[1][1]: |
||||||
|
sum += 1 |
||||||
|
|
||||||
|
if p[0][0] <= p[1][1] and p[0][1] >= p[1][0]: |
||||||
|
sum2 += 1 |
||||||
|
elif p[1][0] <= p[0][1] and p[1][1] >= p[0][0]: |
||||||
|
sum2 += 1 |
||||||
|
|
||||||
|
print(sum) |
||||||
|
print(sum2) |
@ -0,0 +1,30 @@ |
|||||||
|
from copy import deepcopy |
||||||
|
|
||||||
|
data = open("input.txt", 'r').read() |
||||||
|
|
||||||
|
stacks, instructions = data.split("\n\n") |
||||||
|
stacks = stacks.splitlines() |
||||||
|
instructions = [i.split(" ") for i in instructions.splitlines()] |
||||||
|
s = [] |
||||||
|
|
||||||
|
for i in range(int(stacks[-1][-2])): |
||||||
|
s.append([]) |
||||||
|
for j in range(len(stacks)-1): |
||||||
|
crate = stacks[-j-2][i*4+1] |
||||||
|
if crate != " ": |
||||||
|
s[i].append(crate) |
||||||
|
|
||||||
|
s2 = deepcopy(s) |
||||||
|
|
||||||
|
for i in instructions: |
||||||
|
destination = int(i[5])-1 |
||||||
|
origin = int(i[3])-1 |
||||||
|
quantity = int(i[1]) |
||||||
|
s2[destination] += s2[origin][-quantity:] |
||||||
|
for j in range(quantity): |
||||||
|
s[destination].append(s[origin].pop()) |
||||||
|
s2[origin].pop() |
||||||
|
|
||||||
|
|
||||||
|
print("".join([t.pop() for t in s])) |
||||||
|
print("".join([t.pop() for t in s2])) |
@ -0,0 +1,9 @@ |
|||||||
|
line = open("input.txt", 'r').read() |
||||||
|
|
||||||
|
def findFirstValidSequence(length): |
||||||
|
for i in range(len(line)-length): |
||||||
|
if len(set(line[i:i+length])) == length: |
||||||
|
return(i+length) |
||||||
|
|
||||||
|
print(findFirstValidSequence(4)) |
||||||
|
print(findFirstValidSequence(14)) |
@ -0,0 +1,36 @@ |
|||||||
|
lines = [[l.split(" ") for l in m.splitlines()] for m in open("input.txt", 'r').read().split("$ ")][1:] |
||||||
|
|
||||||
|
path = ["/"] |
||||||
|
sizes = {"/":0} |
||||||
|
sum = 0 |
||||||
|
|
||||||
|
for l in lines: |
||||||
|
if l[0][0] == "cd": |
||||||
|
if l[0][1] == "/": |
||||||
|
path = ["/"] |
||||||
|
elif l[0][1] == "..": |
||||||
|
path.pop() |
||||||
|
else: |
||||||
|
path.append(l[0][1]+"/") |
||||||
|
elif l[0][0] == "ls": |
||||||
|
for i in range(1,len(l)): |
||||||
|
if l[i][0] == "dir": |
||||||
|
sizes["".join(path) + l[i][1]+"/"] = 0 |
||||||
|
else: |
||||||
|
sofar = "" |
||||||
|
for p in path: |
||||||
|
sofar += p |
||||||
|
sizes[sofar] += int(l[i][0]) |
||||||
|
|
||||||
|
min = sizes["/"] + 30000000 - 70000000 |
||||||
|
smallest = sizes["/"] |
||||||
|
|
||||||
|
for s in sizes: |
||||||
|
size = sizes[s] |
||||||
|
if size <= 100000: |
||||||
|
sum += size |
||||||
|
if size >= min and size < smallest: |
||||||
|
smallest = size |
||||||
|
|
||||||
|
print(sum) |
||||||
|
print(smallest) |
@ -0,0 +1,25 @@ |
|||||||
|
lines = [i for i in open("input.txt", 'r').read().splitlines()] |
||||||
|
|
||||||
|
sum = 0 |
||||||
|
sum2 = 0 |
||||||
|
|
||||||
|
for l in lines: |
||||||
|
sets = [[j.split(" ") for j in i.split(', ')] for i in l.split(": ")[1].split('; ')] |
||||||
|
highest = {} |
||||||
|
valid = True |
||||||
|
for set in sets: |
||||||
|
for cubes in set: |
||||||
|
cubes[0] = int(cubes[0]) |
||||||
|
if (cubes[1] == "red" and cubes[0] > 12) or (cubes[1] == "green" and cubes[0] > 13) or (cubes[1] == "blue" and cubes[0] > 14): |
||||||
|
valid = False |
||||||
|
if cubes[1] not in highest or cubes[0] > highest[cubes[1]]: |
||||||
|
highest[cubes[1]] = cubes[0] |
||||||
|
if valid: |
||||||
|
sum += int(l.split(": ")[0].split(" ")[1]) |
||||||
|
add = 1 |
||||||
|
for h in highest: |
||||||
|
add *= highest[h] |
||||||
|
sum2 += add |
||||||
|
|
||||||
|
print(sum) |
||||||
|
print(sum2) |
Loading…
Reference in new issue