Compare commits
No commits in common. 'd1a0dfae3c9529471a3737c786ff1f3a78b17bcf' and '91441a623116558fa38578e44d93d89eab280ac5' have entirely different histories.
d1a0dfae3c
...
91441a6231
6 changed files with 6 additions and 144 deletions
@ -1,18 +0,0 @@ |
|||||||
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) |
|
@ -1,30 +0,0 @@ |
|||||||
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])) |
|
@ -1,9 +0,0 @@ |
|||||||
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)) |
|
@ -1,36 +0,0 @@ |
|||||||
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) |
|
@ -1,25 +0,0 @@ |
|||||||
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