Compare commits

...

11 Commits

  1. 32
      2022/3.py
  2. 18
      2022/4.py
  3. 30
      2022/5.py
  4. 9
      2022/6.py
  5. 36
      2022/7.py
  6. 25
      2023/2.py

@ -2,14 +2,34 @@ lines = [i for i in open("input.txt", 'r').read().splitlines()]
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
sum = 0
sum2 = 0
for l in lines:
for i in range(len(lines)):
l = lines[i]
found = False
for c in l[:int(len(l)/2)]:
for d in l[int(len(l)/2):]:
if c == d:
if not found:
sum += letters.index(c)+1
found = True
print(sum)
sum += letters.index(c)+1
found = True
break
if found:
break
found = False
if i % 3 == 0:
for c in l:
for d in lines[i+1]:
if c == d:
for e in lines[i+2]:
if d == e:
sum2 += letters.index(c)+1
found = True
break
if found:
break
if found:
break
print(sum)
print(sum2)

@ -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…
Cancel
Save